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 struct ContextMenuParams; |
| 35 class OverscrollController; |
| 36 class RenderFrameHostImpl; |
| 37 class RenderViewHost; |
| 38 class RenderViewHostDelegateView; |
| 39 class RenderWidgetHostImpl; |
| 40 class RenderWidgetHostViewBase; |
| 41 class TouchSelectionControllerClientAura; |
| 42 |
| 43 // Provides an implementation of ui::EventHandler for use with |
| 44 // RenderWidgetHostViewBase. A delegate is required in order to provide platform |
| 45 // specific functionality. |
| 46 // |
| 47 // After processing events they will be forwarded to the provided |
| 48 // RenderWidgetHostImpl. |
| 49 // |
| 50 // This does not implement ui::TextInputClient, which some |
| 51 // RenderWidgetHostViewBase classes do. |
| 52 // RenderWidgetHostViewEventHandler::Delegate implementations may have |
| 53 // overlapping functionality with the ui::TextInputClient. |
| 54 class CONTENT_EXPORT RenderWidgetHostViewEventHandler |
| 55 : public ui::EventHandler { |
| 56 public: |
| 57 // An interface to provide platform specific logic needed for event handling. |
| 58 class Delegate { |
| 59 public: |
| 60 Delegate(); |
| 61 |
| 62 // Converts |rect| from window coordinate to screen coordinate. |
| 63 virtual gfx::Rect ConvertRectToScreen(const gfx::Rect& rect) const = 0; |
| 64 // Call keybindings handler against the event and send matched edit commands |
| 65 // to the renderer instead. |
| 66 virtual void ForwardKeyboardEvent(const NativeWebKeyboardEvent& event) = 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 virtual void ShowContextMenu(const ContextMenuParams& params) = 0; |
| 71 // Sends shutdown request. |
| 72 virtual void Shutdown() = 0; |
| 73 |
| 74 ui::TouchSelectionController* selection_controller() const { |
| 75 return selection_controller_.get(); |
| 76 } |
| 77 |
| 78 TouchSelectionControllerClientAura* selection_controller_client() const { |
| 79 return selection_controller_client_.get(); |
| 80 } |
| 81 |
| 82 OverscrollController* overscroll_controller() const { |
| 83 return overscroll_controller_.get(); |
| 84 } |
| 85 |
| 86 protected: |
| 87 virtual ~Delegate(); |
| 88 |
| 89 std::unique_ptr<TouchSelectionControllerClientAura> |
| 90 selection_controller_client_; |
| 91 std::unique_ptr<ui::TouchSelectionController> selection_controller_; |
| 92 std::unique_ptr<OverscrollController> overscroll_controller_; |
| 93 |
| 94 private: |
| 95 DISALLOW_COPY_AND_ASSIGN(Delegate); |
| 96 }; |
| 97 |
| 98 RenderWidgetHostViewEventHandler(RenderWidgetHostImpl* host, |
| 99 RenderWidgetHostViewBase* host_view, |
| 100 Delegate* delegate); |
| 101 ~RenderWidgetHostViewEventHandler() override; |
| 102 |
| 103 // Set child popup's host view, and event handler, in order to redirect input. |
| 104 void SetPopupChild(RenderWidgetHostViewBase* popup_child_host_view, |
| 105 ui::EventHandler* popup_child_event_handler); |
| 106 // Begin tracking a host window, such as when RenderWidgetHostViewBase is |
| 107 // fullscreen. |
| 108 void TrackHost(aura::Window* reference_window); |
| 109 |
| 110 #if defined(OS_WIN) |
| 111 // Sets the ContextMenuParams when a context menu is triggered. Required for |
| 112 // subsequent event processing. |
| 113 void SetContextMenuParams(const ContextMenuParams& params); |
| 114 |
| 115 // Updates the cursor clip region. Used for mouse locking. |
| 116 void UpdateMouseLockRegion(); |
| 117 #endif // defined(OS_WIN) |
| 118 |
| 119 bool accept_return_character() { return accept_return_character_; } |
| 120 void disable_input_event_router_for_testing() { |
| 121 disable_input_event_router_for_testing_ = true; |
| 122 } |
| 123 bool mouse_locked() { return mouse_locked_; } |
| 124 const ui::MotionEventAura& pointer_state() const { return pointer_state_; } |
| 125 void set_focus_on_mouse_down_or_key_event( |
| 126 bool focus_on_mouse_down_or_key_event) { |
| 127 set_focus_on_mouse_down_or_key_event_ = focus_on_mouse_down_or_key_event; |
| 128 } |
| 129 void set_window(aura::Window* window) { window_ = window; } |
| 130 |
| 131 // Lock/Unlock processing of future mouse events. |
| 132 bool LockMouse(); |
| 133 void UnlockMouse(); |
| 134 |
| 135 // ui::EventHandler: |
| 136 void OnKeyEvent(ui::KeyEvent* event) override; |
| 137 void OnMouseEvent(ui::MouseEvent* event) override; |
| 138 void OnScrollEvent(ui::ScrollEvent* event) override; |
| 139 void OnTouchEvent(ui::TouchEvent* event) override; |
| 140 void OnGestureEvent(ui::GestureEvent* event) override; |
| 141 |
| 142 private: |
| 143 FRIEND_TEST_ALL_PREFIXES(InputMethodResultAuraTest, |
| 144 FinishImeCompositionSession); |
| 145 // Returns true if the |event| passed in can be forwarded to the renderer. |
| 146 bool CanRendererHandleEvent(const ui::MouseEvent* event, |
| 147 bool mouse_locked, |
| 148 bool selection_popup) const; |
| 149 |
| 150 // Confirm existing composition text in the webpage and ask the input method |
| 151 // to cancel its ongoing composition session. |
| 152 void FinishImeCompositionSession(); |
| 153 |
| 154 // Forwards a mouse event to this view's parent window delegate. |
| 155 void ForwardMouseEventToParent(ui::MouseEvent* event); |
| 156 |
| 157 // Performs gesture handling needed for touch text selection. Sets event as |
| 158 // handled if it should not be further processed. |
| 159 void HandleGestureForTouchSelection(ui::GestureEvent* event); |
| 160 |
| 161 // Handles mouse event handling while the mouse is locked via LockMouse. |
| 162 void HandleMouseEventWhileLocked(ui::MouseEvent* event); |
| 163 |
| 164 // This method computes movementX/Y and keeps track of mouse location for |
| 165 // mouse lock on all mouse move events. |
| 166 // |ui_mouse_event| contains the mouse event received. |
| 167 // |event| contains the WebMouseEvent being modified. |
| 168 void ModifyEventMovementAndCoords(const ui::MouseEvent& ui_mouse_event, |
| 169 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 |