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

Side by Side Diff: content/browser/renderer_host/input/touch_selection_controller_client_aura.cc

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixing clear handles Created 4 years, 1 month 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
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h" 5 #include "content/browser/renderer_host/input/touch_selection_controller_client_ aura.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "content/browser/renderer_host/render_widget_host_delegate.h" 8 #include "content/browser/renderer_host/render_widget_host_delegate.h"
9 #include "content/browser/renderer_host/render_widget_host_impl.h" 9 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/browser/renderer_host/render_widget_host_view_aura.h" 10 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
(...skipping 29 matching lines...) Expand all
40 screen_position_client->ConvertPointToScreen(window, &origin); 40 screen_position_client->ConvertPointToScreen(window, &origin);
41 screen_position_client->ConvertPointToScreen(window, &bottom_right); 41 screen_position_client->ConvertPointToScreen(window, &bottom_right);
42 } 42 }
43 } 43 }
44 return gfx::Rect(origin.x(), origin.y(), bottom_right.x() - origin.x(), 44 return gfx::Rect(origin.x(), origin.y(), bottom_right.x() - origin.x(),
45 bottom_right.y() - origin.y()); 45 bottom_right.y() - origin.y());
46 } 46 }
47 47
48 } // namespace 48 } // namespace
49 49
50 // A pre-target event handler for aura::Env which deactivates touch selection on
51 // mouse and keyboard events.
52 class TouchSelectionControllerClientAura::EnvPreTargetHandler
53 : public ui::EventHandler {
54 public:
55 EnvPreTargetHandler(ui::TouchSelectionController* selection_controller,
56 aura::Window* window);
57 ~EnvPreTargetHandler() override;
58
59 private:
60 // EventHandler:
61 void OnKeyEvent(ui::KeyEvent* event) override;
62 void OnMouseEvent(ui::MouseEvent* event) override;
63 void OnScrollEvent(ui::ScrollEvent* event) override;
64
65 ui::TouchSelectionController* selection_controller_;
66 aura::Window* window_;
67
68 DISALLOW_COPY_AND_ASSIGN(EnvPreTargetHandler);
69 };
70
71 TouchSelectionControllerClientAura::EnvPreTargetHandler::EnvPreTargetHandler(
72 ui::TouchSelectionController* selection_controller,
73 aura::Window* window)
74 : selection_controller_(selection_controller), window_(window) {
75 aura::Env::GetInstance()->AddPreTargetHandler(this);
76 }
77
78 TouchSelectionControllerClientAura::EnvPreTargetHandler::
79 ~EnvPreTargetHandler() {
80 aura::Env::GetInstance()->RemovePreTargetHandler(this);
81 }
82
83 void TouchSelectionControllerClientAura::EnvPreTargetHandler::OnKeyEvent(
84 ui::KeyEvent* event) {
85 DCHECK_NE(ui::TouchSelectionController::INACTIVE,
86 selection_controller_->active_status());
87
88 selection_controller_->HideAndDisallowShowingAutomatically();
89 }
90
91 void TouchSelectionControllerClientAura::EnvPreTargetHandler::OnMouseEvent(
92 ui::MouseEvent* event) {
93 DCHECK_NE(ui::TouchSelectionController::INACTIVE,
94 selection_controller_->active_status());
95
96 // If mouse events are not enabled, this mouse event is synthesized from a
97 // touch event in which case we don't want to deactivate touch selection.
98 aura::client::CursorClient* cursor_client =
99 aura::client::GetCursorClient(window_->GetRootWindow());
100 if (!cursor_client || cursor_client->IsMouseEventsEnabled())
101 selection_controller_->HideAndDisallowShowingAutomatically();
102 }
103
104 void TouchSelectionControllerClientAura::EnvPreTargetHandler::OnScrollEvent(
105 ui::ScrollEvent* event) {
106 DCHECK_NE(ui::TouchSelectionController::INACTIVE,
107 selection_controller_->active_status());
108
109 selection_controller_->HideAndDisallowShowingAutomatically();
110 }
111
112 TouchSelectionControllerClientAura::TouchSelectionControllerClientAura( 50 TouchSelectionControllerClientAura::TouchSelectionControllerClientAura(
113 RenderWidgetHostViewAura* rwhva) 51 RenderWidgetHostViewAura* rwhva)
114 : rwhva_(rwhva), 52 : rwhva_(rwhva),
115 quick_menu_timer_( 53 quick_menu_timer_(
116 FROM_HERE, 54 FROM_HERE,
117 base::TimeDelta::FromMilliseconds(kQuickMenuDelayInMs), 55 base::TimeDelta::FromMilliseconds(kQuickMenuDelayInMs),
118 base::Bind(&TouchSelectionControllerClientAura::ShowQuickMenu, 56 base::Bind(&TouchSelectionControllerClientAura::ShowQuickMenu,
119 base::Unretained(this)), 57 base::Unretained(this)),
120 false), 58 false),
121 quick_menu_requested_(false), 59 quick_menu_requested_(false),
(...skipping 28 matching lines...) Expand all
150 88
151 void TouchSelectionControllerClientAura::OnScrollCompleted() { 89 void TouchSelectionControllerClientAura::OnScrollCompleted() {
152 scroll_in_progress_ = false; 90 scroll_in_progress_ = false;
153 rwhva_->selection_controller()->SetTemporarilyHidden(false); 91 rwhva_->selection_controller()->SetTemporarilyHidden(false);
154 UpdateQuickMenu(); 92 UpdateQuickMenu();
155 } 93 }
156 94
157 bool TouchSelectionControllerClientAura::HandleContextMenu( 95 bool TouchSelectionControllerClientAura::HandleContextMenu(
158 const ContextMenuParams& params) { 96 const ContextMenuParams& params) {
159 if (params.source_type == ui::MENU_SOURCE_LONG_PRESS && 97 if (params.source_type == ui::MENU_SOURCE_LONG_PRESS &&
160 rwhva_->selection_controller()->insertion_active_or_requested() && 98 params.is_editable &&
99 params.selection_text.empty() &&
161 IsQuickMenuAvailable()) { 100 IsQuickMenuAvailable()) {
162 DCHECK(params.is_editable);
163 DCHECK(params.selection_text.empty());
164 quick_menu_requested_ = true; 101 quick_menu_requested_ = true;
165 UpdateQuickMenu(); 102 UpdateQuickMenu();
166 return true; 103 return true;
167 } 104 }
168 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); 105 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically();
169 return false; 106 return false;
170 } 107 }
171 108
172 bool TouchSelectionControllerClientAura::IsQuickMenuAvailable() const { 109 bool TouchSelectionControllerClientAura::IsQuickMenuAvailable() const {
173 return ui::TouchSelectionMenuRunner::GetInstance() && 110 return ui::TouchSelectionMenuRunner::GetInstance() &&
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 } 203 }
267 204
268 void TouchSelectionControllerClientAura::OnSelectionEvent( 205 void TouchSelectionControllerClientAura::OnSelectionEvent(
269 ui::SelectionEventType event) { 206 ui::SelectionEventType event) {
270 switch (event) { 207 switch (event) {
271 case ui::SELECTION_HANDLES_SHOWN: 208 case ui::SELECTION_HANDLES_SHOWN:
272 quick_menu_requested_ = true; 209 quick_menu_requested_ = true;
273 // Fall through. 210 // Fall through.
274 case ui::INSERTION_HANDLE_SHOWN: 211 case ui::INSERTION_HANDLE_SHOWN:
275 UpdateQuickMenu(); 212 UpdateQuickMenu();
276 env_pre_target_handler_.reset(new EnvPreTargetHandler(
277 rwhva_->selection_controller(), rwhva_->GetNativeView()));
278 break; 213 break;
279 case ui::SELECTION_HANDLES_CLEARED: 214 case ui::SELECTION_HANDLES_CLEARED:
280 case ui::INSERTION_HANDLE_CLEARED: 215 case ui::INSERTION_HANDLE_CLEARED:
281 env_pre_target_handler_.reset();
282 quick_menu_requested_ = false; 216 quick_menu_requested_ = false;
283 UpdateQuickMenu(); 217 UpdateQuickMenu();
284 break; 218 break;
285 case ui::SELECTION_HANDLE_DRAG_STARTED: 219 case ui::SELECTION_HANDLE_DRAG_STARTED:
286 case ui::INSERTION_HANDLE_DRAG_STARTED: 220 case ui::INSERTION_HANDLE_DRAG_STARTED:
287 handle_drag_in_progress_ = true; 221 handle_drag_in_progress_ = true;
288 UpdateQuickMenu(); 222 UpdateQuickMenu();
289 break; 223 break;
290 case ui::SELECTION_HANDLE_DRAG_STOPPED: 224 case ui::SELECTION_HANDLE_DRAG_STOPPED:
291 case ui::INSERTION_HANDLE_DRAG_STOPPED: 225 case ui::INSERTION_HANDLE_DRAG_STOPPED:
292 handle_drag_in_progress_ = false; 226 handle_drag_in_progress_ = false;
293 UpdateQuickMenu(); 227 UpdateQuickMenu();
294 break; 228 break;
295 case ui::SELECTION_HANDLES_MOVED: 229 case ui::SELECTION_HANDLES_MOVED:
296 case ui::INSERTION_HANDLE_MOVED: 230 case ui::INSERTION_HANDLE_MOVED:
297 UpdateQuickMenu(); 231 UpdateQuickMenu();
298 break; 232 break;
299 case ui::INSERTION_HANDLE_TAPPED: 233 case ui::INSERTION_HANDLE_TAPPED:
300 quick_menu_requested_ = !quick_menu_requested_; 234 quick_menu_requested_ = !quick_menu_requested_;
301 UpdateQuickMenu(); 235 UpdateQuickMenu();
302 break; 236 break;
303 case ui::SELECTION_ESTABLISHED:
304 case ui::SELECTION_DISSOLVED:
305 break;
306 }; 237 };
307 } 238 }
308 239
309 std::unique_ptr<ui::TouchHandleDrawable> 240 std::unique_ptr<ui::TouchHandleDrawable>
310 TouchSelectionControllerClientAura::CreateDrawable() { 241 TouchSelectionControllerClientAura::CreateDrawable() {
311 return std::unique_ptr<ui::TouchHandleDrawable>( 242 return std::unique_ptr<ui::TouchHandleDrawable>(
312 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView())); 243 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView()));
313 } 244 }
314 245
315 bool TouchSelectionControllerClientAura::IsCommandIdEnabled( 246 bool TouchSelectionControllerClientAura::IsCommandIdEnabled(
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 ui::MENU_SOURCE_TOUCH_EDIT_MENU, 301 ui::MENU_SOURCE_TOUCH_EDIT_MENU,
371 gfx::ToRoundedPoint(anchor_point))); 302 gfx::ToRoundedPoint(anchor_point)));
372 303
373 // Hide selection handles after getting rect-between-bounds from touch 304 // Hide selection handles after getting rect-between-bounds from touch
374 // selection controller; otherwise, rect would be empty and the above 305 // selection controller; otherwise, rect would be empty and the above
375 // calculations would be invalid. 306 // calculations would be invalid.
376 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); 307 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically();
377 } 308 }
378 309
379 } // namespace content 310 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698