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

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

Issue 2883653002: Implement TouchSelectionEditing controls for OOPIF. (Closed)
Patch Set: Mark manager's observer as CONTENT_EXPORT. Created 3 years, 7 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
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
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
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
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
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 return active_client_->SupportsAnimation();
295 }
296
297 bool TouchSelectionControllerClientAura::InternalClient::SupportsAnimation()
298 const {
235 return false; 299 return false;
236 } 300 }
237 301
238 void TouchSelectionControllerClientAura::SetNeedsAnimate() { 302 void TouchSelectionControllerClientAura::SetNeedsAnimate() {
303 active_client_->SetNeedsAnimate();
304 }
305
306 void TouchSelectionControllerClientAura::InternalClient::SetNeedsAnimate() {
239 NOTREACHED(); 307 NOTREACHED();
240 } 308 }
241 309
242 void TouchSelectionControllerClientAura::MoveCaret( 310 void TouchSelectionControllerClientAura::MoveCaret(
243 const gfx::PointF& position) { 311 const gfx::PointF& position) {
312 active_client_->MoveCaret(position);
313 }
314
315 void TouchSelectionControllerClientAura::InternalClient::MoveCaret(
316 const gfx::PointF& position) {
244 RenderWidgetHostImpl* host = 317 RenderWidgetHostImpl* host =
245 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost()); 318 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost());
246 host->MoveCaret(gfx::ToRoundedPoint(position)); 319 host->MoveCaret(gfx::ToRoundedPoint(position));
247 } 320 }
248 321
249 void TouchSelectionControllerClientAura::MoveRangeSelectionExtent( 322 void TouchSelectionControllerClientAura::MoveRangeSelectionExtent(
250 const gfx::PointF& extent) { 323 const gfx::PointF& extent) {
324 active_client_->MoveRangeSelectionExtent(extent);
325 }
326
327 void TouchSelectionControllerClientAura::InternalClient::
328 MoveRangeSelectionExtent(const gfx::PointF& extent) {
251 RenderWidgetHostDelegate* host_delegate = 329 RenderWidgetHostDelegate* host_delegate =
252 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); 330 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate();
253 if (host_delegate) 331 if (host_delegate)
254 host_delegate->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent)); 332 host_delegate->MoveRangeSelectionExtent(gfx::ToRoundedPoint(extent));
255 } 333 }
256 334
257 void TouchSelectionControllerClientAura::SelectBetweenCoordinates( 335 void TouchSelectionControllerClientAura::SelectBetweenCoordinates(
258 const gfx::PointF& base, 336 const gfx::PointF& base,
259 const gfx::PointF& extent) { 337 const gfx::PointF& extent) {
338 active_client_->SelectBetweenCoordinates(base, extent);
339 }
340
341 void TouchSelectionControllerClientAura::InternalClient::
342 SelectBetweenCoordinates(const gfx::PointF& base,
343 const gfx::PointF& extent) {
260 RenderWidgetHostDelegate* host_delegate = 344 RenderWidgetHostDelegate* host_delegate =
261 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate(); 345 RenderWidgetHostImpl::From(rwhva_->GetRenderWidgetHost())->delegate();
262 if (host_delegate) { 346 if (host_delegate) {
263 host_delegate->SelectRange(gfx::ToRoundedPoint(base), 347 host_delegate->SelectRange(gfx::ToRoundedPoint(base),
264 gfx::ToRoundedPoint(extent)); 348 gfx::ToRoundedPoint(extent));
265 } 349 }
266 } 350 }
267 351
268 void TouchSelectionControllerClientAura::OnSelectionEvent( 352 void TouchSelectionControllerClientAura::OnSelectionEvent(
269 ui::SelectionEventType event) { 353 ui::SelectionEventType event) {
354 // This function (implicitly) uses active_menu_client_, so we don't go to the
355 // active view for this.
270 switch (event) { 356 switch (event) {
271 case ui::SELECTION_HANDLES_SHOWN: 357 case ui::SELECTION_HANDLES_SHOWN:
272 quick_menu_requested_ = true; 358 quick_menu_requested_ = true;
273 // Fall through. 359 // Fall through.
274 case ui::INSERTION_HANDLE_SHOWN: 360 case ui::INSERTION_HANDLE_SHOWN:
275 UpdateQuickMenu(); 361 UpdateQuickMenu();
276 env_pre_target_handler_.reset(new EnvPreTargetHandler( 362 env_pre_target_handler_.reset(new EnvPreTargetHandler(
277 rwhva_->selection_controller(), rwhva_->GetNativeView())); 363 rwhva_->selection_controller(), rwhva_->GetNativeView()));
278 break; 364 break;
279 case ui::SELECTION_HANDLES_CLEARED: 365 case ui::SELECTION_HANDLES_CLEARED:
(...skipping 16 matching lines...) Expand all
296 case ui::INSERTION_HANDLE_MOVED: 382 case ui::INSERTION_HANDLE_MOVED:
297 UpdateQuickMenu(); 383 UpdateQuickMenu();
298 break; 384 break;
299 case ui::INSERTION_HANDLE_TAPPED: 385 case ui::INSERTION_HANDLE_TAPPED:
300 quick_menu_requested_ = !quick_menu_requested_; 386 quick_menu_requested_ = !quick_menu_requested_;
301 UpdateQuickMenu(); 387 UpdateQuickMenu();
302 break; 388 break;
303 }; 389 };
304 } 390 }
305 391
392 void TouchSelectionControllerClientAura::InternalClient::OnSelectionEvent(
393 ui::SelectionEventType event) {
394 NOTREACHED();
395 }
396
306 std::unique_ptr<ui::TouchHandleDrawable> 397 std::unique_ptr<ui::TouchHandleDrawable>
307 TouchSelectionControllerClientAura::CreateDrawable() { 398 TouchSelectionControllerClientAura::CreateDrawable() {
399 // This function is purely related to the top-level view's window, so it
400 // is always handled here and never in
401 // TouchSelectionControllerClientChildFrame.
308 return std::unique_ptr<ui::TouchHandleDrawable>( 402 return std::unique_ptr<ui::TouchHandleDrawable>(
309 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView())); 403 new ui::TouchHandleDrawableAura(rwhva_->GetNativeView()));
310 } 404 }
311 405
406 std::unique_ptr<ui::TouchHandleDrawable>
407 TouchSelectionControllerClientAura::InternalClient::CreateDrawable() {
408 NOTREACHED();
409 return nullptr;
410 }
411
312 bool TouchSelectionControllerClientAura::IsCommandIdEnabled( 412 bool TouchSelectionControllerClientAura::IsCommandIdEnabled(
313 int command_id) const { 413 int command_id) const {
314 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE; 414 bool editable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
315 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD; 415 bool readable = rwhva_->GetTextInputType() != ui::TEXT_INPUT_TYPE_PASSWORD;
316 gfx::Range selection_range; 416 gfx::Range selection_range;
317 rwhva_->GetSelectionRange(&selection_range); 417 rwhva_->GetSelectionRange(&selection_range);
318 bool has_selection = !selection_range.is_empty(); 418 bool has_selection = !selection_range.is_empty();
319 switch (command_id) { 419 switch (command_id) {
320 case IDS_APP_CUT: 420 case IDS_APP_CUT:
321 return editable && readable && has_selection; 421 return editable && readable && has_selection;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
367 ui::MENU_SOURCE_TOUCH_EDIT_MENU, 467 ui::MENU_SOURCE_TOUCH_EDIT_MENU,
368 gfx::ToRoundedPoint(anchor_point))); 468 gfx::ToRoundedPoint(anchor_point)));
369 469
370 // Hide selection handles after getting rect-between-bounds from touch 470 // Hide selection handles after getting rect-between-bounds from touch
371 // selection controller; otherwise, rect would be empty and the above 471 // selection controller; otherwise, rect would be empty and the above
372 // calculations would be invalid. 472 // calculations would be invalid.
373 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically(); 473 rwhva_->selection_controller()->HideAndDisallowShowingAutomatically();
374 } 474 }
375 475
376 } // namespace content 476 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698