This source file includes following definitions.
- target_
- LockMouse
- UnlockMouse
- OnLockTargetDestroyed
- IsMouseLockedTo
- WillHandleMouseEvent
- OnLockMouseACK
- OnMouseLockLost
#include "content/renderer/mouse_lock_dispatcher.h"
#include "base/logging.h"
#include "third_party/WebKit/public/web/WebInputEvent.h"
namespace content {
MouseLockDispatcher::MouseLockDispatcher() : mouse_locked_(false),
pending_lock_request_(false),
pending_unlock_request_(false),
unlocked_by_target_(false),
target_(NULL) {
}
MouseLockDispatcher::~MouseLockDispatcher() {
}
bool MouseLockDispatcher::LockMouse(LockTarget* target) {
if (MouseLockedOrPendingAction())
return false;
pending_lock_request_ = true;
target_ = target;
SendLockMouseRequest(unlocked_by_target_);
unlocked_by_target_ = false;
return true;
}
void MouseLockDispatcher::UnlockMouse(LockTarget* target) {
if (target && target == target_ && !pending_unlock_request_) {
pending_unlock_request_ = true;
if (!pending_lock_request_)
unlocked_by_target_ = true;
SendUnlockMouseRequest();
}
}
void MouseLockDispatcher::OnLockTargetDestroyed(LockTarget* target) {
if (target == target_) {
UnlockMouse(target);
target_ = NULL;
}
}
bool MouseLockDispatcher::IsMouseLockedTo(LockTarget* target) {
return mouse_locked_ && target_ == target;
}
bool MouseLockDispatcher::WillHandleMouseEvent(
const blink::WebMouseEvent& event) {
if (mouse_locked_ && target_)
return target_->HandleMouseLockedInputEvent(event);
return false;
}
void MouseLockDispatcher::OnLockMouseACK(bool succeeded) {
DCHECK(!mouse_locked_ && pending_lock_request_);
mouse_locked_ = succeeded;
pending_lock_request_ = false;
if (pending_unlock_request_ && !succeeded) {
pending_unlock_request_ = false;
}
LockTarget* last_target = target_;
if (!succeeded)
target_ = NULL;
if (last_target)
last_target->OnLockMouseACK(succeeded);
}
void MouseLockDispatcher::OnMouseLockLost() {
DCHECK(mouse_locked_ && !pending_lock_request_);
mouse_locked_ = false;
pending_unlock_request_ = false;
LockTarget* last_target = target_;
target_ = NULL;
if (last_target)
last_target->OnMouseLockLost();
}
}