Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1189)

Unified Diff: content/browser/renderer_host/render_widget_host.cc

Issue 7863003: Mouse lock implementation, including the renderer side and the Windows version of the browser side. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove two tab chars. Created 9 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: content/browser/renderer_host/render_widget_host.cc
diff --git a/content/browser/renderer_host/render_widget_host.cc b/content/browser/renderer_host/render_widget_host.cc
index e370fe45b793bd636b9a2228d866e01f9fd1089a..2e4db6cfea31e133e32fe283d429c4cd96e573ae 100644
--- a/content/browser/renderer_host/render_widget_host.cc
+++ b/content/browser/renderer_host/render_widget_host.cc
@@ -183,6 +183,8 @@ bool RenderWidgetHost::OnMessageReceived(const IPC::Message &msg) {
OnMsgImeCancelComposition)
IPC_MESSAGE_HANDLER(ViewHostMsg_DidActivateAcceleratedCompositing,
OnMsgDidActivateAcceleratedCompositing)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_LockMouse, OnMsgLockMouse)
+ IPC_MESSAGE_HANDLER(ViewHostMsg_UnlockMouse, OnMsgUnlockMouse)
#if defined(OS_POSIX)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetScreenInfo, OnMsgGetScreenInfo)
IPC_MESSAGE_HANDLER(ViewHostMsg_GetWindowRect, OnMsgGetWindowRect)
@@ -365,6 +367,9 @@ void RenderWidgetHost::Focus() {
}
void RenderWidgetHost::Blur() {
+ if (IsMouseLocked())
+ view_->UnlockMouse();
+
Send(new ViewMsg_SetFocus(routing_id_, false));
}
@@ -372,7 +377,14 @@ void RenderWidgetHost::LostCapture() {
Send(new ViewMsg_MouseCaptureLost(routing_id_));
}
+void RenderWidgetHost::LostMouseLock() {
+ Send(new ViewMsg_MouseLockLost(routing_id_));
+}
+
void RenderWidgetHost::ViewDestroyed() {
+ if (IsMouseLocked())
+ view_->UnlockMouse();
+
// TODO(evanm): tracking this may no longer be necessary;
// eliminate this function if so.
SetView(NULL);
@@ -511,7 +523,16 @@ void RenderWidgetHost::ForwardMouseEvent(const WebMouseEvent& mouse_event) {
// more WM_MOUSEMOVE events than we wish to send to the renderer.
if (mouse_event.type == WebInputEvent::MouseMove) {
if (mouse_move_pending_) {
- next_mouse_move_.reset(new WebMouseEvent(mouse_event));
+ if (!next_mouse_move_.get()) {
+ next_mouse_move_.reset(new WebMouseEvent(mouse_event));
+ } else {
+ // Accumulate movement deltas.
+ int x = next_mouse_move_->movementX;
+ int y = next_mouse_move_->movementY;
+ *next_mouse_move_ = mouse_event;
+ next_mouse_move_->movementX += x;
+ next_mouse_move_->movementY += y;
+ }
return;
}
mouse_move_pending_ = true;
@@ -766,6 +787,10 @@ void RenderWidgetHost::ImeCancelComposition() {
std::vector<WebKit::WebCompositionUnderline>(), 0, 0));
}
+bool RenderWidgetHost::IsMouseLocked() const {
+ return view_ ? view_->mouse_locked() : false;
+}
+
void RenderWidgetHost::Destroy() {
NotificationService::current()->Notify(
content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED,
@@ -1111,6 +1136,21 @@ void RenderWidgetHost::OnMsgDidActivateAcceleratedCompositing(bool activated) {
#endif
}
+void RenderWidgetHost::OnMsgLockMouse() {
+ // TODO(yzshen): Only allow to lock the mouse when in fullscreen mode, and
+ // make sure that the mouse is unlocked when leaving fullscreen mode.
+ if (!view_ || !view_->HasFocus() || !view_->LockMouse()) {
+ Send(new ViewMsg_LockMouse_ACK(routing_id_, false));
+ } else {
+ Send(new ViewMsg_LockMouse_ACK(routing_id_, true));
+ }
+}
+
+void RenderWidgetHost::OnMsgUnlockMouse() {
+ if (IsMouseLocked())
+ view_->UnlockMouse();
+}
+
#if defined(OS_POSIX)
void RenderWidgetHost::OnMsgGetScreenInfo(gfx::NativeViewId window_id,
WebKit::WebScreenInfo* results) {

Powered by Google App Engine
This is Rietveld 408576698