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