Chromium Code Reviews| Index: content/renderer/render_view_impl.cc |
| diff --git a/content/renderer/render_view_impl.cc b/content/renderer/render_view_impl.cc |
| index c2aeec494f76dffeca59b8f22ce432cb2ffb699e..90cec78309d21921d7c9079f58a9ed6222d9abae 100644 |
| --- a/content/renderer/render_view_impl.cc |
| +++ b/content/renderer/render_view_impl.cc |
| @@ -86,6 +86,7 @@ |
| #include "ppapi/c/private/ppb_flash_net_connector.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebAccessibilityObject.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h" |
| +#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebDataSource.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" |
| #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebDragData.h" |
| @@ -366,7 +367,12 @@ RenderViewImpl::RenderViewImpl( |
| #if defined(OS_WIN) |
| focused_plugin_id_(-1), |
| #endif |
| - ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)) { |
| + ALLOW_THIS_IN_INITIALIZER_LIST(pepper_delegate_(this)), |
| + mouse_locked_(false), |
| + pending_lock_request_(false), |
| + pending_unlock_request_(false), |
| + mouse_lock_webwidget_owner_(NULL), |
| + mouse_lock_pinstance_owner_(NULL) { |
| routing_id_ = routing_id; |
| if (opener_id != MSG_ROUTING_NONE) |
| opener_id_ = opener_id; |
| @@ -1878,6 +1884,28 @@ void RenderViewImpl::exitFullScreen() { |
| Send(new ViewHostMsg_ToggleFullscreen(routing_id_, false)); |
| } |
| +void RenderViewImpl::lockPointer() { |
| + // HACK |
| + bool succeeded = true; |
| + mouse_locked_ = succeeded; |
| + if (webview()) { |
| + fprintf(stderr, "RenderViewImpl::lockPointer() webview()->lockPointerAck();\n"); |
| + webview()->OnLockMouseACK2(succeeded); |
| + } else { |
| + fprintf(stderr, "RenderViewImpl::lockPointer() NULL webview();\n"); |
| + } |
| +} |
| + |
| +void RenderViewImpl::unlockPointer() { |
| + // HACK |
| + OnMouseLockLost(); |
| +} |
| + |
| +bool RenderViewImpl::isPointerLocked() { |
| + fprintf(stderr, "RenderViewImpl::isPointerLocked()\n"); |
| + return mouse_locked_; |
| +} |
| + |
| // WebKit::WebFrameClient ----------------------------------------------------- |
| WebPlugin* RenderViewImpl::createPlugin(WebFrame* frame, |
| @@ -4283,7 +4311,23 @@ void RenderViewImpl::DidHandleKeyEvent() { |
| } |
| bool RenderViewImpl::WillHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| - return pepper_delegate_.HandleMouseEvent(event); |
| + pepper_delegate_.WillHandleMouseEvent(); |
| + |
| + if (mouse_locked_) { |
| + // |cursor_info| is ignored since it is hidden when the mouse is locked. |
| + WebKit::WebCursorInfo cursor_info; |
| + |
| + DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); |
| + if (mouse_lock_webwidget_owner_) |
| + mouse_lock_webwidget_owner_->HandleMouseLockedInputEvent(event); |
| + if (mouse_lock_pinstance_owner_) |
| + mouse_lock_pinstance_owner_->HandleMouseLockedInputEvent(event); |
| + |
| + // If the mouse is locked, only the current owner of the mouse lock can |
| + // process mouse events. |
| + return true; |
| + } |
| + return false; |
| } |
| void RenderViewImpl::DidHandleMouseEvent(const WebKit::WebMouseEvent& event) { |
| @@ -4771,6 +4815,53 @@ void RenderViewImpl::OnEnableViewSourceMode() { |
| main_frame->enableViewSourceMode(true); |
| } |
| +bool RenderViewImpl::LockMouseInternal(WebKit::WebWidget* webwidget, |
| + webkit::ppapi::PluginInstance* pinstance) { |
| + DCHECK(!(webwidget && pinstance)); // Only one mouse lock target at a time. |
| + fprintf(stderr, "RenderViewImpl::LockMouseInternal(%s, %s) ", webwidget ? "webwidget" : "NULL", pinstance ? "pinstance" : "NULL"); |
| + |
| + if (MouseLockedOrPendingAction()) |
| + { |
| + fprintf(stderr, "return false; // (locked or pending)\n"); |
| + return false; |
| + } |
| + |
| + pending_lock_request_ = true; |
| + DCHECK(!mouse_lock_webwidget_owner_ && !mouse_lock_pinstance_owner_); |
| + mouse_lock_webwidget_owner_ = webwidget; |
| + mouse_lock_pinstance_owner_ = pinstance; |
| + |
| + Send(new ViewHostMsg_LockMouse(routing_id())); |
| + fprintf(stderr, "return true;\n"); |
| + return true; |
| +} |
| + |
| +void RenderViewImpl::UnlockMouseInternal(WebKit::WebWidget* webwidget, |
| + webkit::ppapi::PluginInstance* pinstance) { |
| + fprintf(stderr, "RenderViewImpl::UnlockMouseInternal(%s, %s) \n", webwidget ? "webwidget" : "NULL", pinstance ? "pinstance" : "NULL"); |
| + if (!MouseLockedOrPendingAction()) |
| + { |
| + fprintf(stderr, "RenderViewImpl::LockMouseInternal() if (!MouseLockedOrPendingAction()) return\n"); |
| + return; |
| + } |
| + if (pending_unlock_request_) |
|
yzshen1
2012/01/04 00:50:00
nit: It seems better to put this in the if-block o
|
| + { |
| + fprintf(stderr, "RenderViewImpl::LockMouseInternal() if (pending_unlock_request_) return\n"); |
| + return; |
| + } |
| + |
| + // Ignore unless the unlock request is for the current lock holder. |
| + if (webwidget == mouse_lock_webwidget_owner_ || |
| + pinstance == mouse_lock_pinstance_owner_) { |
| + pending_unlock_request_ = true; |
| + Send(new ViewHostMsg_UnlockMouse(routing_id())); |
| + } |
| + else |
| + { |
| + fprintf(stderr, "RenderViewImpl::LockMouseInternal() not the current target\n"); |
| + } |
| +} |
| + |
| void RenderViewImpl::OnLockMouseACK(bool succeeded) { |
| // Mouse Lock removes the system cursor and provides all mouse motion as |
| // .movementX/Y values on events all sent to a fixed target. This requires |
| @@ -4781,11 +4872,64 @@ void RenderViewImpl::OnLockMouseACK(bool succeeded) { |
| if (succeeded) |
| OnMouseCaptureLost(); |
| - pepper_delegate_.OnLockMouseACK(succeeded); |
| + //scheibXXX |
| + // was: pepper_delegate_.OnLockMouseACK(succeeded); |
| + DCHECK(!mouse_locked_ && pending_lock_request_); |
| + |
| + mouse_locked_ = succeeded; |
| + pending_lock_request_ = false; |
| + if (pending_unlock_request_ && !succeeded) { |
| + // We have sent an unlock request after the lock request. However, since |
| + // the lock request has failed, the unlock request will be ignored by the |
| + // browser side and there won't be any response to it. |
| + pending_unlock_request_ = false; |
| + } |
| + |
| + if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) { |
| + WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_; |
| + webkit::ppapi::PluginInstance* last_pinstance_owner = |
| + mouse_lock_pinstance_owner_; |
| + |
| + if (!succeeded) { |
| + // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so |
| + // that if OnLockMouseACK() results in calls to any mouse lock method |
| + // (e.g., LockMouse()), the method will see consistent internal state. |
| + mouse_lock_webwidget_owner_ = NULL; |
| + mouse_lock_pinstance_owner_ = NULL; |
| + } |
| + |
| + DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); |
| + if (last_webwidget_owner) |
| + last_webwidget_owner->OnLockMouseACK2(succeeded); |
| + if (last_pinstance_owner) |
| + last_pinstance_owner->OnLockMouseACK2(succeeded); |
| + } |
| + //scheibXXX |
| + // end was: pepper_delegate_.OnLockMouseACK(succeeded); |
| } |
| void RenderViewImpl::OnMouseLockLost() { |
| - pepper_delegate_.OnMouseLockLost(); |
| + DCHECK(mouse_locked_ && !pending_lock_request_); |
| + |
| + mouse_locked_ = false; |
| + pending_unlock_request_ = false; |
| + if (mouse_lock_webwidget_owner_ || mouse_lock_pinstance_owner_) { |
| + WebKit::WebWidget* last_webwidget_owner = mouse_lock_webwidget_owner_; |
| + webkit::ppapi::PluginInstance* last_pinstance_owner = |
| + mouse_lock_pinstance_owner_; |
| + |
| + // Reset mouse lock owner to NULL before calling OnLockMouseACK(), so |
| + // that if OnLockMouseACK() results in calls to any mouse lock method |
| + // (e.g., LockMouse()), the method will see consistent internal state. |
| + mouse_lock_webwidget_owner_ = NULL; |
| + mouse_lock_pinstance_owner_ = NULL; |
| + |
| + DCHECK(!mouse_lock_webwidget_owner_ || !mouse_lock_pinstance_owner_); |
| + if (last_webwidget_owner) |
| + last_webwidget_owner->OnMouseLockLost2(); |
| + if (last_pinstance_owner) |
| + last_pinstance_owner->OnMouseLockLost2(); |
| + } |
| } |
| bool RenderViewImpl::WebWidgetHandlesCompositorScheduling() const { |