OLD | NEW |
---|---|
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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
105 ui::ScrollEvent* event) { | 105 ui::ScrollEvent* event) { |
106 DCHECK_NE(ui::TouchSelectionController::INACTIVE, | 106 DCHECK_NE(ui::TouchSelectionController::INACTIVE, |
107 selection_controller_->active_status()); | 107 selection_controller_->active_status()); |
108 | 108 |
109 selection_controller_->HideAndDisallowShowingAutomatically(); | 109 selection_controller_->HideAndDisallowShowingAutomatically(); |
110 } | 110 } |
111 | 111 |
112 TouchSelectionControllerClientAura::TouchSelectionControllerClientAura( | 112 TouchSelectionControllerClientAura::TouchSelectionControllerClientAura( |
113 RenderWidgetHostViewAura* rwhva) | 113 RenderWidgetHostViewAura* rwhva) |
114 : rwhva_(rwhva), | 114 : rwhva_(rwhva), |
115 internal_client_(rwhva), | |
116 active_client_(&internal_client_), | |
117 active_menu_client_(this), | |
115 quick_menu_timer_( | 118 quick_menu_timer_( |
116 FROM_HERE, | 119 FROM_HERE, |
117 base::TimeDelta::FromMilliseconds(kQuickMenuDelayInMs), | 120 base::TimeDelta::FromMilliseconds(kQuickMenuDelayInMs), |
118 base::Bind(&TouchSelectionControllerClientAura::ShowQuickMenu, | 121 base::Bind(&TouchSelectionControllerClientAura::ShowQuickMenu, |
119 base::Unretained(this)), | 122 base::Unretained(this)), |
120 false), | 123 false), |
121 quick_menu_requested_(false), | 124 quick_menu_requested_(false), |
122 touch_down_(false), | 125 touch_down_(false), |
123 scroll_in_progress_(false), | 126 scroll_in_progress_(false), |
124 handle_drag_in_progress_(false), | 127 handle_drag_in_progress_(false), |
125 show_quick_menu_immediately_for_test_(false) { | 128 show_quick_menu_immediately_for_test_(false) { |
126 DCHECK(rwhva_); | 129 DCHECK(rwhva_); |
127 } | 130 } |
128 | 131 |
129 TouchSelectionControllerClientAura::~TouchSelectionControllerClientAura() { | 132 TouchSelectionControllerClientAura::~TouchSelectionControllerClientAura() { |
133 for (auto& observer : observers_) | |
134 observer.OnManagerWillDestroy(this); | |
130 } | 135 } |
131 | 136 |
132 void TouchSelectionControllerClientAura::OnWindowMoved() { | 137 void TouchSelectionControllerClientAura::OnWindowMoved() { |
133 UpdateQuickMenu(); | 138 UpdateQuickMenu(); |
134 } | 139 } |
135 | 140 |
136 void TouchSelectionControllerClientAura::OnTouchDown() { | 141 void TouchSelectionControllerClientAura::OnTouchDown() { |
137 touch_down_ = true; | 142 touch_down_ = true; |
138 UpdateQuickMenu(); | 143 UpdateQuickMenu(); |
139 } | 144 } |
(...skipping 22 matching lines...) Expand all Loading... | |
162 params.selection_text.empty() && | 167 params.selection_text.empty() && |
163 IsQuickMenuAvailable()) { | 168 IsQuickMenuAvailable()) { |
164 quick_menu_requested_ = true; | 169 quick_menu_requested_ = true; |
165 UpdateQuickMenu(); | 170 UpdateQuickMenu(); |
166 return true; | 171 return true; |
167 } | 172 } |
168 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); | 173 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); |
169 return false; | 174 return false; |
170 } | 175 } |
171 | 176 |
177 void TouchSelectionControllerClientAura::UpdateClientSelectionBounds( | |
178 const gfx::SelectionBound& start, | |
179 const gfx::SelectionBound& end) { | |
180 UpdateClientSelectionBounds(start, end, &internal_client_, this); | |
181 } | |
182 | |
183 void TouchSelectionControllerClientAura::UpdateClientSelectionBounds( | |
184 const gfx::SelectionBound& start, | |
185 const gfx::SelectionBound& end, | |
186 ui::TouchSelectionControllerClient* client, | |
187 ui::TouchSelectionMenuClient* menu_client) { | |
188 if (client != active_client_ && | |
189 (start.type() == gfx::SelectionBound::EMPTY || !start.visible()) && | |
190 (end.type() == gfx::SelectionBound::EMPTY || !end.visible()) && | |
191 (manager_selection_start_.type() != gfx::SelectionBound::EMPTY || | |
192 manager_selection_end_.type() != gfx::SelectionBound::EMPTY)) { | |
193 return; | |
194 } | |
195 | |
196 active_client_ = client; | |
197 active_menu_client_ = menu_client; | |
198 manager_selection_start_ = start; | |
199 manager_selection_end_ = end; | |
200 // Notify TouchSelectionController if anything should change here. Only | |
201 // udate if the client is different and not making a change to empty, or | |
Charlie Reis
2017/05/25 02:29:43
nit: update
wjmaclean
2017/05/25 14:04:35
Done.
| |
202 // is the same client. | |
203 GetTouchSelectionController()->OnSelectionBoundsChanged(start, end); | |
204 } | |
205 | |
206 void TouchSelectionControllerClientAura::InvalidateClient( | |
207 ui::TouchSelectionControllerClient* client) { | |
208 DCHECK(client != &internal_client_); | |
209 if (client == active_client_) { | |
210 active_client_ = &internal_client_; | |
211 active_menu_client_ = this; | |
212 } | |
213 } | |
214 | |
215 ui::TouchSelectionController* | |
216 TouchSelectionControllerClientAura::GetTouchSelectionController() { | |
217 return rwhva_->selection_controller(); | |
218 } | |
219 | |
220 void TouchSelectionControllerClientAura::AddObserver( | |
221 TouchSelectionControllerClientManager::Observer* observer) { | |
222 observers_.AddObserver(observer); | |
223 } | |
224 | |
225 void TouchSelectionControllerClientAura::RemoveObserver( | |
226 TouchSelectionControllerClientManager::Observer* observer) { | |
227 observers_.RemoveObserver(observer); | |
228 } | |
229 | |
172 bool TouchSelectionControllerClientAura::IsQuickMenuAvailable() const { | 230 bool TouchSelectionControllerClientAura::IsQuickMenuAvailable() const { |
173 return ui::TouchSelectionMenuRunner::GetInstance() && | 231 return ui::TouchSelectionMenuRunner::GetInstance() && |
174 ui::TouchSelectionMenuRunner::GetInstance()->IsMenuAvailable(this); | 232 ui::TouchSelectionMenuRunner::GetInstance()->IsMenuAvailable( |
233 active_menu_client_); | |
175 } | 234 } |
176 | 235 |
177 void TouchSelectionControllerClientAura::ShowQuickMenu() { | 236 void TouchSelectionControllerClientAura::ShowQuickMenu() { |
178 if (!ui::TouchSelectionMenuRunner::GetInstance()) | 237 if (!ui::TouchSelectionMenuRunner::GetInstance()) |
179 return; | 238 return; |
180 | 239 |
181 gfx::RectF rect = rwhva_->selection_controller()->GetRectBetweenBounds(); | 240 gfx::RectF rect = rwhva_->selection_controller()->GetRectBetweenBounds(); |
182 | 241 |
183 // Clip rect, which is in |rwhva_|'s window's coordinate space, to client | 242 // Clip rect, which is in |rwhva_|'s window's coordinate space, to client |
184 // bounds. | 243 // bounds. |
(...skipping 10 matching lines...) Expand all Loading... | |
195 gfx::RectF anchor_rect(origin, size); | 254 gfx::RectF anchor_rect(origin, size); |
196 | 255 |
197 // Calculate maximum handle image size; | 256 // Calculate maximum handle image size; |
198 gfx::SizeF max_handle_size = | 257 gfx::SizeF max_handle_size = |
199 rwhva_->selection_controller()->GetStartHandleRect().size(); | 258 rwhva_->selection_controller()->GetStartHandleRect().size(); |
200 max_handle_size.SetToMax( | 259 max_handle_size.SetToMax( |
201 rwhva_->selection_controller()->GetEndHandleRect().size()); | 260 rwhva_->selection_controller()->GetEndHandleRect().size()); |
202 | 261 |
203 aura::Window* parent = rwhva_->GetNativeView(); | 262 aura::Window* parent = rwhva_->GetNativeView(); |
204 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( | 263 ui::TouchSelectionMenuRunner::GetInstance()->OpenMenu( |
205 this, ConvertRectToScreen(parent, anchor_rect), | 264 active_menu_client_, ConvertRectToScreen(parent, anchor_rect), |
206 gfx::ToRoundedSize(max_handle_size), parent->GetToplevelWindow()); | 265 gfx::ToRoundedSize(max_handle_size), parent->GetToplevelWindow()); |
207 } | 266 } |
208 | 267 |
209 void TouchSelectionControllerClientAura::UpdateQuickMenu() { | 268 void TouchSelectionControllerClientAura::UpdateQuickMenu() { |
210 bool menu_is_showing = | 269 bool menu_is_showing = |
211 ui::TouchSelectionMenuRunner::GetInstance() && | 270 ui::TouchSelectionMenuRunner::GetInstance() && |
212 ui::TouchSelectionMenuRunner::GetInstance()->IsRunning(); | 271 ui::TouchSelectionMenuRunner::GetInstance()->IsRunning(); |
213 | 272 |
214 // Hide the quick menu if there is any. This should happen even if the menu | 273 // Hide the quick menu if there is any. This should happen even if the menu |
215 // should be shown again, in order to update its location or content. | 274 // should be shown again, in order to update its location or content. |
216 if (menu_is_showing) | 275 if (menu_is_showing) |
217 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); | 276 ui::TouchSelectionMenuRunner::GetInstance()->CloseMenu(); |
218 else | 277 else |
219 quick_menu_timer_.Stop(); | 278 quick_menu_timer_.Stop(); |
220 | 279 |
221 bool should_show_menu = quick_menu_requested_ && !touch_down_ && | 280 bool should_show_menu = quick_menu_requested_ && !touch_down_ && |
222 !scroll_in_progress_ && !handle_drag_in_progress_ && | 281 !scroll_in_progress_ && !handle_drag_in_progress_ && |
223 IsQuickMenuAvailable(); | 282 IsQuickMenuAvailable(); |
224 | 283 |
225 // Start timer to show quick menu if necessary. | 284 // Start timer to show quick menu if necessary. |
226 if (should_show_menu) { | 285 if (should_show_menu) { |
227 if (show_quick_menu_immediately_for_test_) | 286 if (show_quick_menu_immediately_for_test_) |
228 ShowQuickMenu(); | 287 ShowQuickMenu(); |
229 else | 288 else |
230 quick_menu_timer_.Reset(); | 289 quick_menu_timer_.Reset(); |
231 } | 290 } |
232 } | 291 } |
233 | 292 |
234 bool TouchSelectionControllerClientAura::SupportsAnimation() const { | 293 bool TouchSelectionControllerClientAura::SupportsAnimation() const { |
294 // We don't pass this to the active client, since it is assumed it will have | |
295 // the same behaviour as the Aura client. | |
235 return false; | 296 return false; |
236 } | 297 } |
237 | 298 |
299 bool TouchSelectionControllerClientAura::InternalClient::SupportsAnimation() | |
300 const { | |
301 NOTREACHED(); | |
302 return false; | |
303 } | |
304 | |
238 void TouchSelectionControllerClientAura::SetNeedsAnimate() { | 305 void TouchSelectionControllerClientAura::SetNeedsAnimate() { |
239 NOTREACHED(); | 306 NOTREACHED(); |
240 } | 307 } |
241 | 308 |
309 void TouchSelectionControllerClientAura::InternalClient::SetNeedsAnimate() { | |
310 NOTREACHED(); | |
311 } | |
312 | |
242 void TouchSelectionControllerClientAura::MoveCaret( | 313 void TouchSelectionControllerClientAura::MoveCaret( |
243 const gfx::PointF& position) { | 314 const gfx::PointF& position) { |
315 active_client_->MoveCaret(position); | |
316 } | |
317 | |
318 void TouchSelectionControllerClientAura::InternalClient::MoveCaret( | |
319 const gfx::PointF& position) { | |
244 RenderWidgetHostImpl* host = | 320 RenderWidgetHostImpl* host = |
245 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); | 321 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); |
246 host->MoveCaret(gfx::ToRoundedPoint(position)); | 322 host->MoveCaret(gfx::ToRoundedPoint(position)); |
247 } | 323 } |
248 | 324 |
249 void TouchSelectionControllerClientAura::MoveRangeSelectionExtent( | 325 void TouchSelectionControllerClientAura::MoveRangeSelectionExtent( |
250 const gfx::PointF& extent) { | 326 const gfx::PointF& extent) { |
327 active_client_->MoveRangeSelectionExtent(extent); | |
328 } | |
329 | |
330 void TouchSelectionControllerClientAura::InternalClient:: | |
331 MoveRangeSelectionExtent(const gfx::PointF& extent) { | |
251 RenderWidgetHostDelegate* host_delegate = | 332 RenderWidgetHostDelegate* host_delegate = |
252 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); | 333 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); |
253 if (host_delegate) | 334 if (host_delegate) |
254 host_delegate->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); | 335 host_delegate->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); |
255 } | 336 } |
256 | 337 |
257 void TouchSelectionControllerClientAura::SelectBetweenCoordinates( | 338 void TouchSelectionControllerClientAura::SelectBetweenCoordinates( |
258 const gfx::PointF& base, | 339 const gfx::PointF& base, |
259 const gfx::PointF& extent) { | 340 const gfx::PointF& extent) { |
341 active_client_->SelectBetweenCoordinates(base, extent); | |
342 } | |
343 | |
344 void TouchSelectionControllerClientAura::InternalClient:: | |
345 SelectBetweenCoordinates(const gfx::PointF& base, | |
346 const gfx::PointF& extent) { | |
260 RenderWidgetHostDelegate* host_delegate = | 347 RenderWidgetHostDelegate* host_delegate = |
261 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); | 348 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); |
262 if (host_delegate) { | 349 if (host_delegate) { |
263 host_delegate->SelectRange(gfx::ToRoundedPoint(base), | 350 host_delegate->SelectRange(gfx::ToRoundedPoint(base), |
264 gfx::ToRoundedPoint(extent)); | 351 gfx::ToRoundedPoint(extent)); |
265 } | 352 } |
266 } | 353 } |
267 | 354 |
268 void TouchSelectionControllerClientAura::OnSelectionEvent( | 355 void TouchSelectionControllerClientAura::OnSelectionEvent( |
269 ui::SelectionEventType event) { | 356 ui::SelectionEventType event) { |
357 // This function (implicitly) uses active_menu_client_, so we don't go to the | |
358 // active view for this. | |
270 switch (event) { | 359 switch (event) { |
271 case ui::SELECTION_HANDLES_SHOWN: | 360 case ui::SELECTION_HANDLES_SHOWN: |
272 quick_menu_requested_ = true; | 361 quick_menu_requested_ = true; |
273 // Fall through. | 362 // Fall through. |
274 case ui::INSERTION_HANDLE_SHOWN: | 363 case ui::INSERTION_HANDLE_SHOWN: |
275 UpdateQuickMenu(); | 364 UpdateQuickMenu(); |
276 env_pre_target_handler_.reset(new EnvPreTargetHandler( | 365 env_pre_target_handler_.reset(new EnvPreTargetHandler( |
277 rwhva_->selection_controller(), rwhva_->GetNativeView())); | 366 rwhva_->selection_controller(), rwhva_->GetNativeView())); |
278 break; | 367 break; |
279 case ui::SELECTION_HANDLES_CLEARED: | 368 case ui::SELECTION_HANDLES_CLEARED: |
(...skipping 16 matching lines...) Expand all Loading... | |
296 case ui::INSERTION_HANDLE_MOVED: | 385 case ui::INSERTION_HANDLE_MOVED: |
297 UpdateQuickMenu(); | 386 UpdateQuickMenu(); |
298 break; | 387 break; |
299 case ui::INSERTION_HANDLE_TAPPED: | 388 case ui::INSERTION_HANDLE_TAPPED: |
300 quick_menu_requested_ = !quick_menu_requested_; | 389 quick_menu_requested_ = !quick_menu_requested_; |
301 UpdateQuickMenu(); | 390 UpdateQuickMenu(); |
302 break; | 391 break; |
303 }; | 392 }; |
304 } | 393 } |
305 | 394 |
395 void TouchSelectionControllerClientAura::InternalClient::OnSelectionEvent( | |
396 ui::SelectionEventType event) { | |
397 NOTREACHED(); | |
398 } | |
399 | |
306 std::unique_ptr<ui::TouchHandleDrawable> | 400 std::unique_ptr<ui::TouchHandleDrawable> |
307 TouchSelectionControllerClientAura::CreateDrawable() { | 401 TouchSelectionControllerClientAura::CreateDrawable() { |
402 // This function is purely related to the top-level view's window, so it | |
403 // is always handled here and never in | |
404 // TouchSelectionControllerClientChildFrame. | |
308 return std::unique_ptr<ui::TouchHandleDrawable>( | 405 return std::unique_ptr<ui::TouchHandleDrawable>( |
309 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView())); | 406 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView())); |
310 } | 407 } |
311 | 408 |
409 std::unique_ptr<ui::TouchHandleDrawable> | |
410 TouchSelectionControllerClientAura::InternalClient::CreateDrawable() { | |
411 NOTREACHED(); | |
412 return nullptr; | |
413 } | |
414 | |
312 bool TouchSelectionControllerClientAura::IsCommandIdEnabled( | 415 bool TouchSelectionControllerClientAura::IsCommandIdEnabled( |
313 int command_id) const { | 416 int command_id) const { |
314 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; | 417 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; |
315 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD; | 418 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD; |
316 gfx::Range selection_range; | 419 gfx::Range selection_range; |
317 rwhva_->GetSelectionRange(&selection_range); | 420 rwhva_->GetSelectionRange(&selection_range); |
318 bool has_selection = !selection_range.is_empty(); | 421 bool has_selection = !selection_range.is_empty(); |
319 switch (command_id) { | 422 switch (command_id) { |
320 case IDS_APP_CUT: | 423 case IDS_APP_CUT: |
321 return editable && readable && has_selection; | 424 return editable && readable && has_selection; |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
367 ui::MENU_SOURCE_TOUCH_EDIT_MENU, | 470 ui::MENU_SOURCE_TOUCH_EDIT_MENU, |
368 gfx::ToRoundedPoint(anchor_point))); | 471 gfx::ToRoundedPoint(anchor_point))); |
369 | 472 |
370 // Hide selection handles after getting rect-between-bounds from touch | 473 // Hide selection handles after getting rect-between-bounds from touch |
371 // selection controller; otherwise, rect would be empty and the above | 474 // selection controller; otherwise, rect would be empty and the above |
372 // calculations would be invalid. | 475 // calculations would be invalid. |
373 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); | 476 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); |
374 } | 477 } |
375 | 478 |
376 } // namespace content | 479 } // namespace content |
OLD | NEW |