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

Unified Diff: content/renderer/mouse_lock_dispatcher.h

Issue 8970016: refactoring mouse lock to support pepper and WebKit (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Refactor LockTarget interface & Tests Created 8 years, 11 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/renderer/mouse_lock_dispatcher.h
diff --git a/content/renderer/mouse_lock_dispatcher.h b/content/renderer/mouse_lock_dispatcher.h
new file mode 100644
index 0000000000000000000000000000000000000000..945ade80e028ba0f60e00c06e9019d37f602b08e
--- /dev/null
+++ b/content/renderer/mouse_lock_dispatcher.h
@@ -0,0 +1,90 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
+#define CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_
+#pragma once
+
+#include "base/basictypes.h"
+#include "content/public/renderer/render_view_observer.h"
+
+class RenderViewImpl;
+
+namespace WebKit {
+class WebMouseEvent;
+class WebWidget;
+} // namespace WebKit
+
+namespace webkit{
+namespace ppapi {
+class PluginInstance;
+} // namespace ppapi
+} // namespace webkit
+
+// MouseLockDispatcher is owned by RenderViewImpl.
+class MouseLockDispatcher : public content::RenderViewObserver {
+ public:
+ explicit MouseLockDispatcher(RenderViewImpl* render_view_impl);
+ virtual ~MouseLockDispatcher();
+
+ class LockTarget {
yzshen1 2012/01/24 18:56:08 Please define a virtual destructor.
scheib 2012/01/25 00:27:11 Done.
+ public:
+ // A mouse lock request was pending and this reports success or failure.
+ virtual void OnLockMouseACK(bool succeeded) = 0;
+ // A mouse lock was in place, but has been lost.
+ virtual void OnMouseLockLost() = 0;
+ // A mouse lock is enabled and mouse events are being delievered.
+ virtual bool HandleMouseLockedInputEvent(
+ const WebKit::WebMouseEvent& event) = 0;
+ };
+
+ static LockTarget* CreateLockTarget(webkit::ppapi::PluginInstance* plugin);
yzshen1 2012/01/24 18:56:08 Please comment about the ownership of the returned
scheib 2012/01/25 00:27:11 Done.
+ static LockTarget* CreateLockTarget(WebKit::WebWidget* webwidget);
+
+ // Lock the mouse to the |target|. If true is returned, an asynchronous
yzshen1 2012/01/24 18:56:08 Lock -> Locks. (And some other places.)
scheib 2012/01/25 00:27:11 Done. er.. but I'm not sure if we have a preferred
yzshen1 2012/01/25 18:10:01 According to our code style, the second one is pre
+ // response to target->OnLockMouseACK() will follow.
+ bool LockMouse(LockTarget* target);
+ // Request to unlock the mouse. An asynchronous
yzshen1 2012/01/24 18:56:08 Fit as many words in one line as possible. (And so
scheib 2012/01/25 00:27:11 Done.
+ // response to target->OnMouseLockLost() will follow.
+ void UnlockMouse(LockTarget* target);
+ // Request to unlock and clear references to the target, the pointer is no
+ // longer valid. The pointer will not be accessed again..
yzshen1 2012/01/24 18:56:08 .. -> .
scheib 2012/01/25 00:27:11 Done.
+ void UnlockMouseAndClearTarget(LockTarget* target);
+ bool IsMouseLockedTo(LockTarget* target);
+
+ // Allow lock target to consumed a mouse event, if it does returns true.
yzshen1 2012/01/24 18:56:08 returns -> return.
scheib 2012/01/25 00:27:11 Done.
+ bool WillHandleMouseEvent(const WebKit::WebMouseEvent& event);
+
+ private:
+ // RenderView::Observer implementation.
+ virtual bool OnMessageReceived(const IPC::Message& message) OVERRIDE;
+
+ // IPC handlers.
+ void OnLockMouseACK(bool succeeded);
+ void OnMouseLockLost();
+
+ bool MouseLockedOrPendingAction() const {
+ return mouse_locked_ || pending_lock_request_ || pending_unlock_request_;
+ }
+
+ RenderViewImpl* render_view_impl_;
+
+ bool mouse_locked_;
+ // If both |pending_lock_request_| and |pending_unlock_request_| are true,
+ // it means a lock request was sent before an unlock request and we haven't
+ // received responses for them.
+ // The logic in LockMouse() makes sure that a lock request won't be sent when
+ // there is a pending unlock request.
+ bool pending_lock_request_;
+ bool pending_unlock_request_;
+
+ // |target_| is the pending or current owner of mouse lock. We retain a
+ // non owning reference here that must be cleared by
+ // |UnlockMouseAndClearTarget| when it is destroyed.
+ LockTarget* target_;
+
+ DISALLOW_COPY_AND_ASSIGN(MouseLockDispatcher);
+};
+
+#endif // CONTENT_RENDERER_MOUSE_LOCK_DISPATCHER_H_

Powered by Google App Engine
This is Rietveld 408576698