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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_event_handler.h

Issue 2317333002: Refactor EventHandler out of RenderWidgetHostViewAura (Closed)
Patch Set: Fix popups Created 4 years, 3 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 unified diff | Download patch
OLDNEW
(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 "ui/aura/window_tracker.h"
13 #include "ui/events/event_handler.h"
14 #include "ui/events/gestures/motion_event_aura.h"
15 #include "ui/events/latency_info.h"
16
17 namespace aura {
18
19 namespace client {
20 class ScopedTooltipDisabler;
21 } // namespace client
22
23 class Window;
24
25 } // namespace aura
26
27 namespace blink {
28
29 class WebMouseEvent;
30 class WebMouseWheelEvent;
31 class WebTouchEvent;
32
33 } // namespace blink
34
35 namespace content {
36 #if defined(OS_WIN)
37 struct ContextMenuParams;
38 #endif // defined(OS_WIN)
39 class RenderViewHost;
40 class RenderViewHostDelegateView;
41 class RenderWidgetHostImpl;
42 class RenderWidgetHostViewAura;
43
44 class CONTENT_EXPORT RenderWidgetHostViewEventHandler
45 : public ui::EventHandler {
46 public:
47 RenderWidgetHostViewEventHandler(RenderWidgetHostImpl* host,
48 RenderWidgetHostViewAura* host_view);
sadrul 2016/09/13 15:39:46 Use a delegate interface instead?
jonross 2016/09/15 16:39:59 I've split this into a RWHVBase and a Delegate.
49 ~RenderWidgetHostViewEventHandler() override;
50
51 void SetPopupChildHostView(RenderWidgetHostViewAura* popup_child_host_view);
52 void TrackHost(aura::Window* reference_window);
53 #if defined(OS_WIN)
54 void SetContextMenuParams(const ContextMenuParams& params);
55
56 // Updates the cursor clip region. Used for mouse locking.
57 void UpdateMouseLockRegion();
58 #endif // defined(OS_WIN)
59
60 bool accept_return_character() { return accept_return_character_; }
61 void disable_input_event_router_for_testing() {
62 disable_input_event_router_for_testing_ = true;
63 }
64 bool mouse_locked() { return mouse_locked_; }
65 const ui::MotionEventAura& pointer_state() const { return pointer_state_; }
66 void set_focus_on_mouse_down_or_key_event(
67 bool focus_on_mouse_down_or_key_event) {
68 set_focus_on_mouse_down_or_key_event_ = focus_on_mouse_down_or_key_event;
69 }
70 void set_window(aura::Window* window) { window_ = window; }
71
72 // RenderWidgetHostViewBase
73 bool LockMouse();
74 void UnlockMouse();
75
76 // ui::EventHandler:
77 void OnKeyEvent(ui::KeyEvent* event) override;
78 void OnMouseEvent(ui::MouseEvent* event) override;
79 void OnScrollEvent(ui::ScrollEvent* event) override;
80 void OnTouchEvent(ui::TouchEvent* event) override;
81 void OnGestureEvent(ui::GestureEvent* event) override;
82
83 private:
84 FRIEND_TEST_ALL_PREFIXES(InputMethodResultAuraTest,
85 FinishImeCompositionSession);
86 // Returns true if the |event| passed in can be forwarded to the renderer.
87 bool CanRendererHandleEvent(const ui::MouseEvent* event,
88 bool mouse_locked,
89 bool selection_popup) const;
90
91 // Confirm existing composition text in the webpage and ask the input method
92 // to cancel its ongoing composition session.
93 void FinishImeCompositionSession();
94
95 // Forwards a mouse event to this view's parent window delegate.
96 void ForwardMouseEventToParent(ui::MouseEvent* event);
97
98 // Returns the RenderViewHostDelegateView instance for |host_|. Returns
99 // nullptr on failure.
100 RenderViewHostDelegateView* GetRenderViewHostDelegateView();
101
102 // Performs gesture handling needed for touch text selection. Sets event as
103 // handled if it should not be further processed.
104 void HandleGestureForTouchSelection(ui::GestureEvent* event);
105
106 // This method computes movementX/Y and keeps track of mouse location for
107 // mouse lock on all mouse move events.
108 void ModifyEventMovementAndCoords(blink::WebMouseEvent* event);
109
110 // Helper function to set keyboard focus to the main window.
111 void SetKeyboardFocus();
112
113 // Helper method to determine if, in mouse locked mode, the cursor should be
114 // moved to center.
115 bool ShouldMoveToCenter();
116
117 // Returns true when we can do SurfaceHitTesting for the event type.
118 bool ShouldRouteEvent(const ui::Event* event) const;
119
120 // RenderWidgetHostViewBase
121 void ProcessMouseEvent(const blink::WebMouseEvent& event,
122 const ui::LatencyInfo& latency);
123 void ProcessMouseWheelEvent(const blink::WebMouseWheelEvent& event,
124 const ui::LatencyInfo& latency); // override;
125 void ProcessTouchEvent(const blink::WebTouchEvent& event,
126 const ui::LatencyInfo& latency);
127
128 // Whether return characters should be passed on to the RenderWidgetHostImpl.
129 bool accept_return_character_;
130
131 // Allows tests to send gesture events for testing without first sending a
132 // corresponding touch sequence, as would be required by
133 // RenderWidgetHostInputEventRouter.
134 bool disable_input_event_router_for_testing_;
135
136 // While the mouse is locked, the cursor is hidden from the user. Mouse events
137 // are still generated. However, the position they report is the last known
138 // mouse position just as mouse lock was entered; the movement they report
139 // indicates what the change in position of the mouse would be had it not been
140 // locked.
141 bool mouse_locked_;
142
143 // Whether pinch-to-zoom should be enabled and pinch events forwarded to the
144 // renderer.
145 bool pinch_zoom_enabled_;
146
147 // This flag when set ensures that we send over a notification to blink that
148 // the current view has focus. Defaults to false.
149 bool set_focus_on_mouse_down_or_key_event_;
150
151 // Used to track the state of the window we're created from. Only used when
152 // created fullscreen.
153 std::unique_ptr<aura::WindowTracker> host_tracker_;
154
155 std::unique_ptr<aura::client::ScopedTooltipDisabler> tooltip_disabler_;
156
157 // Used to record the last position of the mouse.
158 // While the mouse is locked, they store the last known position just as mouse
159 // lock was entered.
160 // Relative to the upper-left corner of the view.
161 gfx::Point unlocked_mouse_position_;
162 // Relative to the upper-left corner of the screen.
163 gfx::Point unlocked_global_mouse_position_;
164 // Last cursor position relative to screen. Used to compute movementX/Y.
165 gfx::Point global_mouse_position_;
166 // In mouse locked mode, we synthetically move the mouse cursor to the center
167 // of the window when it reaches the window borders to avoid it going outside.
168 // This flag is used to differentiate between these synthetic mouse move
169 // events vs. normal mouse move events.
170 bool synthetic_move_sent_;
171 // Stores the current state of the active pointers targeting this
172 // object.
173 ui::MotionEventAura pointer_state_;
174
175 #if defined(OS_WIN)
176 // Contains a copy of the last context menu request parameters. Only set when
177 // we receive a request to show the context menu on a long press.
178 std::unique_ptr<ContextMenuParams> last_context_menu_params_;
179 #endif // defined(OS_WIN)
180
181 // Not owned/
182 RenderWidgetHostImpl* const host_;
183 RenderWidgetHostViewAura* host_view_;
184 RenderWidgetHostViewAura* popup_child_host_view_;
185 aura::Window* window_;
186
187 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewEventHandler);
188 };
189
190 } // namespace content
191
192 #endif // CONTENT_BROWSER_RENDERER_HOST_RENDER_WIDGET_HOST_VIEW_EVENT_HANDLER_H _
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698