OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #ifndef CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H_ | |
6 #define CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H_ | |
7 | |
8 #include <memory> | |
9 | |
10 #include "base/macros.h" | |
11 #include "content/common/content_export.h" | |
12 #include "content/public/browser/native_web_keyboard_event.h" | |
13 #include "ui/aura/window_tracker.h" | |
14 #include "ui/events/event_handler.h" | |
15 #include "ui/events/gestures/motion_event_aura.h" | |
16 #include "ui/events/latency_info.h" | |
17 | |
18 namespace aura { | |
19 class Window; | |
20 } // namespace aura | |
21 | |
22 namespace blink { | |
23 | |
tdresser
2016/09/23 13:54:09
Remove newlines
jonross
2016/10/05 15:37:58
Done.
| |
24 class WebMouseEvent; | |
25 class WebMouseWheelEvent; | |
26 class WebTouchEvent; | |
27 | |
28 } // namespace blink | |
29 | |
30 namespace ui { | |
31 class TextInputClient; | |
32 class TouchSelectionController; | |
33 } | |
34 | |
35 namespace content { | |
36 #if defined(OS_WIN) | |
37 struct ContextMenuParams; | |
38 #endif // defined(OS_WIN) | |
39 class OverscrollController; | |
40 class RenderFrameHostImpl; | |
41 class RenderViewHost; | |
42 class RenderViewHostDelegateView; | |
43 class RenderWidgetHostImpl; | |
44 class RenderWidgetHostViewBase; | |
45 class TouchSelectionControllerClientAura; | |
46 | |
47 // Provides an implementation of ui::EventHandler for use with | |
48 // 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
| |
49 // specific functionality. | |
50 // | |
51 // After processing events they will be forwarded to the provided | |
52 // RenderWidgetHostImpl. | |
53 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
| |
54 : public ui::EventHandler { | |
55 public: | |
56 // 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.
| |
57 class Delegate { | |
58 public: | |
59 Delegate(); | |
60 | |
61 // Converts |rect| from window coordinate to screen coordinate. | |
62 virtual gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const = 0; | |
63 // Call keybindings handler against the event and send matched edit commands | |
64 // to the renderer instead. | |
65 virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event) = 0; | |
66 virtual RenderFrameHostImpl* GetFocusedFrame() = 0; | |
67 // Returns whether the widget needs to grab mouse capture to work properly. | |
68 virtual bool NeedsMouseCapture() = 0; | |
69 virtual void SetTooltipsEnabled(bool enable) = 0; | |
70 // Sends shutdown request. | |
71 virtual void Shutdown() = 0; | |
72 | |
73 ui::TouchSelectionController* selection_controller() const { | |
74 return selection_controller_.get(); | |
75 } | |
76 | |
77 TouchSelectionControllerClientAura* selection_controller_client() const { | |
78 return selection_controller_client_.get(); | |
79 } | |
80 | |
81 OverscrollController* overscroll_controller() const { | |
82 return overscroll_controller_.get(); | |
83 } | |
84 | |
85 protected: | |
86 virtual ~Delegate(); | |
87 | |
88 std::unique_ptr<TouchSelectionControllerClientAura> | |
89 selection_controller_client_; | |
90 std::unique_ptr<ui::TouchSelectionController> selection_controller_; | |
91 std::unique_ptr<OverscrollController> overscroll_controller_; | |
92 }; | |
93 | |
94 RenderWidgetHostViewEventHandler(RenderWidgetHostImpl* host, | |
95 RenderWidgetHostViewBase* host_view, | |
96 Delegate* delegate); | |
97 ~RenderWidgetHostViewEventHandler() override; | |
98 | |
99 // 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.
| |
100 void SetPopupChild(RenderWidgetHostViewBase* popup_child_host_view, | |
101 ui::EventHandler* popup_child_event_handler); | |
102 // Begin tracking a host window, such as when RenderWidgetHostViewBase is | |
103 // fullscreen. | |
104 void TrackHost(aura::Window* reference_window); | |
105 | |
106 #if defined(OS_WIN) | |
107 // Sets the ContextMenuParams when a context menu is triggered. Required for | |
108 // subsequent event processing. | |
109 void SetContextMenuParams(const ContextMenuParams& params); | |
110 | |
111 // Updates the cursor clip region. Used for mouse locking. | |
112 void UpdateMouseLockRegion(); | |
113 #endif // defined(OS_WIN) | |
114 | |
115 bool accept_return_character() { return accept_return_character_; } | |
116 void disable_input_event_router_for_testing() { | |
117 disable_input_event_router_for_testing_ = true; | |
118 } | |
119 bool mouse_locked() { return mouse_locked_; } | |
120 const ui::MotionEventAura& pointer_state() const { return pointer_state_; } | |
121 void set_focus_on_mouse_down_or_key_event( | |
122 bool focus_on_mouse_down_or_key_event) { | |
123 set_focus_on_mouse_down_or_key_event_ = focus_on_mouse_down_or_key_event; | |
124 } | |
125 void set_window(aura::Window* window) { window_ = window; } | |
126 | |
127 // 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.
| |
128 // events. | |
129 bool LockMouse(); | |
130 void UnlockMouse(); | |
131 | |
132 // ui::EventHandler: | |
133 void OnKeyEvent(ui::KeyEvent* event) override; | |
134 void OnMouseEvent(ui::MouseEvent* event) override; | |
135 void OnScrollEvent(ui::ScrollEvent* event) override; | |
136 void OnTouchEvent(ui::TouchEvent* event) override; | |
137 void OnGestureEvent(ui::GestureEvent* event) override; | |
138 | |
139 private: | |
140 FRIEND_TEST_ALL_PREFIXES(InputMethodResultAuraTest, | |
141 FinishImeCompositionSession); | |
142 // Returns true if the |event| passed in can be forwarded to the renderer. | |
143 bool CanRendererHandleEvent(const ui::MouseEvent* event, | |
144 bool mouse_locked, | |
145 bool selection_popup) const; | |
146 | |
147 // Confirm existing composition text in the webpage and ask the input method | |
148 // to cancel its ongoing composition session. | |
149 void FinishImeCompositionSession(); | |
150 | |
151 // Forwards a mouse event to this view's parent window delegate. | |
152 void ForwardMouseEventToParent(ui::MouseEvent* event); | |
153 | |
154 // Returns the RenderViewHostDelegateView instance for |host_|. Returns | |
155 // nullptr on failure. | |
156 RenderViewHostDelegateView* GetRenderViewHostDelegateView(); | |
157 | |
158 // Performs gesture handling needed for touch text selection. Sets event as | |
159 // handled if it should not be further processed. | |
160 void HandleGestureForTouchSelection(ui::GestureEvent* event); | |
161 | |
162 // Handles mouse event handling while the mouse is locked via LockMouse. | |
163 void HandleMouseEventWhileLocked(ui::MouseEvent* event); | |
164 | |
165 // This method computes movementX/Y and keeps track of mouse location for | |
166 // mouse lock on all mouse move events. | |
167 void ModifyEventMovementAndCoords(blink::WebMouseEvent* event); | |
168 | |
169 // Helper function to set keyboard focus to the main window. | |
170 void SetKeyboardFocus(); | |
171 | |
172 // Helper method to determine if, in mouse locked mode, the cursor should be | |
173 // moved to center. | |
174 bool ShouldMoveToCenter(); | |
175 | |
176 // Returns true when we can do SurfaceHitTesting for the event type. | |
177 bool ShouldRouteEvent(const ui::Event* event) const; | |
178 | |
179 // Provides and implementation for RenderWidgetHostViewBase, directing the | |
180 // 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.
| |
181 void ProcessMouseEvent(const blink::WebMouseEvent& event, | |
182 const ui::LatencyInfo& latency); | |
183 void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent& event, | |
184 const ui::LatencyInfo& latency); // override; | |
185 void ProcessTouchEvent(const blink::WebTouchEvent& event, | |
186 const ui::LatencyInfo& latency); | |
187 | |
188 // Whether return characters should be passed on to the RenderWidgetHostImpl. | |
189 bool accept_return_character_; | |
190 | |
191 // Allows tests to send gesture events for testing without first sending a | |
192 // corresponding touch sequence, as would be required by | |
193 // RenderWidgetHostInputEventRouter. | |
194 bool disable_input_event_router_for_testing_; | |
195 | |
196 // While the mouse is locked, the cursor is hidden from the user. Mouse events | |
197 // are still generated. However, the position they report is the last known | |
198 // mouse position just as mouse lock was entered; the movement they report | |
199 // indicates what the change in position of the mouse would be had it not been | |
200 // locked. | |
201 bool mouse_locked_; | |
202 | |
203 // Whether pinch-to-zoom should be enabled and pinch events forwarded to the | |
204 // renderer. | |
205 bool pinch_zoom_enabled_; | |
206 | |
207 // This flag when set ensures that we send over a notification to blink that | |
208 // the current view has focus. Defaults to false. | |
209 bool set_focus_on_mouse_down_or_key_event_; | |
210 | |
211 // Used to track the state of the window we're created from. Only used when | |
212 // created fullscreen. | |
213 std::unique_ptr<aura::WindowTracker> host_tracker_; | |
214 | |
215 // Used to record the last position of the mouse. | |
216 // While the mouse is locked, they store the last known position just as mouse | |
217 // lock was entered. | |
218 // Relative to the upper-left corner of the view. | |
219 gfx::Point unlocked_mouse_position_; | |
220 // Relative to the upper-left corner of the screen. | |
221 gfx::Point unlocked_global_mouse_position_; | |
222 // Last cursor position relative to screen. Used to compute movementX/Y. | |
223 gfx::Point global_mouse_position_; | |
224 // In mouse locked mode, we synthetically move the mouse cursor to the center | |
225 // of the window when it reaches the window borders to avoid it going outside. | |
226 // This flag is used to differentiate between these synthetic mouse move | |
227 // events vs. normal mouse move events. | |
228 bool synthetic_move_sent_; | |
229 // Stores the current state of the active pointers targeting this | |
230 // object. | |
231 ui::MotionEventAura pointer_state_; | |
232 | |
233 #if defined(OS_WIN) | |
234 // Contains a copy of the last context menu request parameters. Only set when | |
235 // we receive a request to show the context menu on a long press. | |
236 std::unique_ptr<ContextMenuParams> last_context_menu_params_; | |
237 #endif // defined(OS_WIN) | |
238 | |
239 // 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
| |
240 RenderWidgetHostImpl* const host_; | |
241 RenderWidgetHostViewBase* const host_view_; | |
242 RenderWidgetHostViewBase* popup_child_host_view_; | |
243 ui::EventHandler* popup_child_event_handler_; | |
244 Delegate* const delegate_; | |
245 aura::Window* window_; | |
246 | |
247 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEventHandler); | |
248 }; | |
249 | |
250 } // namespace content | |
251 | |
252 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H _ | |
OLD | NEW |