Index: content/browser/renderer_host/render_widget_host_view_event_handler.h |
diff --git a/content/browser/renderer_host/render_widget_host_view_event_handler.h b/content/browser/renderer_host/render_widget_host_view_event_handler.h |
new file mode 100644 |
index 0000000000000000000000000000000000000000..317d7699ddb9ce809d319a8f2bee86fcd83317a7 |
--- /dev/null |
+++ b/content/browser/renderer_host/render_widget_host_view_event_handler.h |
@@ -0,0 +1,252 @@ |
+// Copyright 2016 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_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H_ |
+#define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H_ |
+ |
+#include <memory> |
+ |
+#include "base/macros.h" |
+#include "content/common/content_export.h" |
+#include "content/public/browser/native_web_keyboard_event.h" |
+#include "ui/aura/window_tracker.h" |
+#include "ui/events/event_handler.h" |
+#include "ui/events/gestures/motion_event_aura.h" |
+#include "ui/events/latency_info.h" |
+ |
+namespace aura { |
+class Window; |
+} // namespace aura |
+ |
+namespace blink { |
+ |
tdresser
2016/09/23 13:54:09
Remove newlines
jonross
2016/10/05 15:37:58
Done.
|
+class WebMouseEvent; |
+class WebMouseWheelEvent; |
+class WebTouchEvent; |
+ |
+} // namespace blink |
+ |
+namespace ui { |
+class TextInputClient; |
+class TouchSelectionController; |
+} |
+ |
+namespace content { |
+#if defined(OS_WIN) |
+struct ContextMenuParams; |
+#endif // defined(OS_WIN) |
+class OverscrollController; |
+class RenderFrameHostImpl; |
+class RenderViewHost; |
+class RenderViewHostDelegateView; |
+class RenderWidgetHostImpl; |
+class RenderWidgetHostViewBase; |
+class TouchSelectionControllerClientAura; |
+ |
+// Provides an implementation of ui::EventHandler for use with |
+// RenderWidgetHostViewBase. A delegate is required in order to provide platform |
tdresser
2016/09/23 13:54:09
Is this comment right? Isn't it for use with Rende
jonross
2016/10/05 15:37:58
We will also being using this with RenderWidgetHos
|
+// specific functionality. |
+// |
+// After processing events they will be forwarded to the provided |
+// RenderWidgetHostImpl. |
+class CONTENT_EXPORT RenderWidgetHostViewEventHandler |
tdresser
2016/09/23 13:54:09
I'd prefer if this naming indicated that it was Au
jonross
2016/10/05 15:37:58
We have been maintaining a distinction of Aura/Mus
sadrul
2016/10/05 15:46:17
How about RenderWidgetHostUIEventHandler: handles
|
+ : public ui::EventHandler { |
+ public: |
+ // An interface to provide additional functionality needed for event handling. |
tdresser
2016/09/23 13:54:09
If we're calling this an interface, perhaps we sho
tdresser
2016/09/23 13:54:09
Mention that the delegate is for platform specific
jonross
2016/10/05 15:37:58
I'd also be fine not calling this an interface, as
jonross
2016/10/05 15:37:58
Done.
|
+ class Delegate { |
+ public: |
+ Delegate(); |
+ |
+ // Converts |rect| from window coordinate to screen coordinate. |
+ virtual gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const = 0; |
+ // Call keybindings handler against the event and send matched edit commands |
+ // to the renderer instead. |
+ virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event) = 0; |
+ virtual RenderFrameHostImpl* GetFocusedFrame() = 0; |
+ // Returns whether the widget needs to grab mouse capture to work properly. |
+ virtual bool NeedsMouseCapture() = 0; |
+ virtual void SetTooltipsEnabled(bool enable) = 0; |
+ // Sends shutdown request. |
+ virtual void Shutdown() = 0; |
+ |
+ ui::TouchSelectionController* selection_controller() const { |
+ return selection_controller_.get(); |
+ } |
+ |
+ TouchSelectionControllerClientAura* selection_controller_client() const { |
+ return selection_controller_client_.get(); |
+ } |
+ |
+ OverscrollController* overscroll_controller() const { |
+ return overscroll_controller_.get(); |
+ } |
+ |
+ protected: |
+ virtual ~Delegate(); |
+ |
+ std::unique_ptr<TouchSelectionControllerClientAura> |
+ selection_controller_client_; |
+ std::unique_ptr<ui::TouchSelectionController> selection_controller_; |
+ std::unique_ptr<OverscrollController> overscroll_controller_; |
+ }; |
+ |
+ RenderWidgetHostViewEventHandler(RenderWidgetHostImpl* host, |
+ RenderWidgetHostViewBase* host_view, |
+ Delegate* delegate); |
+ ~RenderWidgetHostViewEventHandler() override; |
+ |
+ // Set child popups host view, and event handler, in order to redirect input. |
tdresser
2016/09/23 13:54:09
popup's
jonross
2016/10/05 15:37:58
Done.
|
+ void SetPopupChild(RenderWidgetHostViewBase* popup_child_host_view, |
+ ui::EventHandler* popup_child_event_handler); |
+ // Begin tracking a host window, such as when RenderWidgetHostViewBase is |
+ // fullscreen. |
+ void TrackHost(aura::Window* reference_window); |
+ |
+#if defined(OS_WIN) |
+ // Sets the ContextMenuParams when a context menu is triggered. Required for |
+ // subsequent event processing. |
+ void SetContextMenuParams(const ContextMenuParams& params); |
+ |
+ // Updates the cursor clip region. Used for mouse locking. |
+ void UpdateMouseLockRegion(); |
+#endif // defined(OS_WIN) |
+ |
+ bool accept_return_character() { return accept_return_character_; } |
+ void disable_input_event_router_for_testing() { |
+ disable_input_event_router_for_testing_ = true; |
+ } |
+ bool mouse_locked() { return mouse_locked_; } |
+ const ui::MotionEventAura& pointer_state() const { return pointer_state_; } |
+ void set_focus_on_mouse_down_or_key_event( |
+ bool focus_on_mouse_down_or_key_event) { |
+ set_focus_on_mouse_down_or_key_event_ = focus_on_mouse_down_or_key_event; |
+ } |
+ void set_window(aura::Window* window) { window_ = window; } |
+ |
+ // Provides an implementation for RenderWidgetHostView, locking future mouse |
tdresser
2016/09/23 13:54:09
This comment is no longer correct.
jonross
2016/10/05 15:37:58
Done.
|
+ // events. |
+ bool LockMouse(); |
+ void UnlockMouse(); |
+ |
+ // ui::EventHandler: |
+ void OnKeyEvent(ui::KeyEvent* event) override; |
+ void OnMouseEvent(ui::MouseEvent* event) override; |
+ void OnScrollEvent(ui::ScrollEvent* event) override; |
+ void OnTouchEvent(ui::TouchEvent* event) override; |
+ void OnGestureEvent(ui::GestureEvent* event) override; |
+ |
+ private: |
+ FRIEND_TEST_ALL_PREFIXES(InputMethodResultAuraTest, |
+ FinishImeCompositionSession); |
+ // Returns true if the |event| passed in can be forwarded to the renderer. |
+ bool CanRendererHandleEvent(const ui::MouseEvent* event, |
+ bool mouse_locked, |
+ bool selection_popup) const; |
+ |
+ // Confirm existing composition text in the webpage and ask the input method |
+ // to cancel its ongoing composition session. |
+ void FinishImeCompositionSession(); |
+ |
+ // Forwards a mouse event to this view's parent window delegate. |
+ void ForwardMouseEventToParent(ui::MouseEvent* event); |
+ |
+ // Returns the RenderViewHostDelegateView instance for |host_|. Returns |
+ // nullptr on failure. |
+ RenderViewHostDelegateView* GetRenderViewHostDelegateView(); |
+ |
+ // Performs gesture handling needed for touch text selection. Sets event as |
+ // handled if it should not be further processed. |
+ void HandleGestureForTouchSelection(ui::GestureEvent* event); |
+ |
+ // Handles mouse event handling while the mouse is locked via LockMouse. |
+ void HandleMouseEventWhileLocked(ui::MouseEvent* event); |
+ |
+ // This method computes movementX/Y and keeps track of mouse location for |
+ // mouse lock on all mouse move events. |
+ void ModifyEventMovementAndCoords(blink::WebMouseEvent* event); |
+ |
+ // Helper function to set keyboard focus to the main window. |
+ void SetKeyboardFocus(); |
+ |
+ // Helper method to determine if, in mouse locked mode, the cursor should be |
+ // moved to center. |
+ bool ShouldMoveToCenter(); |
+ |
+ // Returns true when we can do SurfaceHitTesting for the event type. |
+ bool ShouldRouteEvent(const ui::Event* event) const; |
+ |
+ // Provides and implementation for RenderWidgetHostViewBase, directing the |
+ // events to the |host_|. |
tdresser
2016/09/23 13:54:09
This comment isn't correct anymore.
jonross
2016/10/05 15:37:58
Done.
|
+ void ProcessMouseEvent(const blink::WebMouseEvent& event, |
+ const ui::LatencyInfo& latency); |
+ void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent& event, |
+ const ui::LatencyInfo& latency); // override; |
+ void ProcessTouchEvent(const blink::WebTouchEvent& event, |
+ const ui::LatencyInfo& latency); |
+ |
+ // Whether return characters should be passed on to the RenderWidgetHostImpl. |
+ bool accept_return_character_; |
+ |
+ // Allows tests to send gesture events for testing without first sending a |
+ // corresponding touch sequence, as would be required by |
+ // RenderWidgetHostInputEventRouter. |
+ bool disable_input_event_router_for_testing_; |
+ |
+ // While the mouse is locked, the cursor is hidden from the user. Mouse events |
+ // are still generated. However, the position they report is the last known |
+ // mouse position just as mouse lock was entered; the movement they report |
+ // indicates what the change in position of the mouse would be had it not been |
+ // locked. |
+ bool mouse_locked_; |
+ |
+ // Whether pinch-to-zoom should be enabled and pinch events forwarded to the |
+ // renderer. |
+ bool pinch_zoom_enabled_; |
+ |
+ // This flag when set ensures that we send over a notification to blink that |
+ // the current view has focus. Defaults to false. |
+ bool set_focus_on_mouse_down_or_key_event_; |
+ |
+ // Used to track the state of the window we're created from. Only used when |
+ // created fullscreen. |
+ std::unique_ptr<aura::WindowTracker> host_tracker_; |
+ |
+ // Used to record the last position of the mouse. |
+ // While the mouse is locked, they store the last known position just as mouse |
+ // lock was entered. |
+ // Relative to the upper-left corner of the view. |
+ gfx::Point unlocked_mouse_position_; |
+ // Relative to the upper-left corner of the screen. |
+ gfx::Point unlocked_global_mouse_position_; |
+ // Last cursor position relative to screen. Used to compute movementX/Y. |
+ gfx::Point global_mouse_position_; |
+ // In mouse locked mode, we synthetically move the mouse cursor to the center |
+ // of the window when it reaches the window borders to avoid it going outside. |
+ // This flag is used to differentiate between these synthetic mouse move |
+ // events vs. normal mouse move events. |
+ bool synthetic_move_sent_; |
+ // Stores the current state of the active pointers targeting this |
+ // object. |
+ ui::MotionEventAura pointer_state_; |
+ |
+#if defined(OS_WIN) |
+ // Contains a copy of the last context menu request parameters. Only set when |
+ // we receive a request to show the context menu on a long press. |
+ std::unique_ptr<ContextMenuParams> last_context_menu_params_; |
+#endif // defined(OS_WIN) |
+ |
+ // Not owned/ |
tdresser
2016/09/23 13:54:09
Replace trailing / with .
tdresser
2016/09/23 13:54:09
For some of these, it might be worth talking about
jonross
2016/10/05 15:37:58
Updated with more info. In general, aside from two
|
+ RenderWidgetHostImpl* const host_; |
+ RenderWidgetHostViewBase* const host_view_; |
+ RenderWidgetHostViewBase* popup_child_host_view_; |
+ ui::EventHandler* popup_child_event_handler_; |
+ Delegate* const delegate_; |
+ aura::Window* window_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEventHandler); |
+}; |
+ |
+} // namespace content |
+ |
+#endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H_ |