OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/views/touchui/touch_selection_controller_impl.h" | 5 #include "ui/views/touchui/touch_selection_controller_impl.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/time.h" | 8 #include "base/time.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "ui/base/ui_base_switches.h" | 10 #include "ui/base/ui_base_switches.h" |
(...skipping 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return client_view_->IsCommandIdEnabled(command_id); | 290 return client_view_->IsCommandIdEnabled(command_id); |
291 } | 291 } |
292 | 292 |
293 void TouchSelectionControllerImpl::ExecuteCommand(int command_id) { | 293 void TouchSelectionControllerImpl::ExecuteCommand(int command_id) { |
294 HideContextMenu(); | 294 HideContextMenu(); |
295 client_view_->ExecuteCommand(command_id); | 295 client_view_->ExecuteCommand(command_id); |
296 } | 296 } |
297 | 297 |
298 void TouchSelectionControllerImpl::OpenContextMenu() { | 298 void TouchSelectionControllerImpl::OpenContextMenu() { |
299 gfx::Point anchor = context_menu_->anchor_point(); | 299 gfx::Point anchor = context_menu_->anchor_point(); |
| 300 anchor.Offset(0, kContextMenuVerticalOffset); |
300 HideContextMenu(); | 301 HideContextMenu(); |
301 client_view_->OpenContextMenu(anchor); | 302 client_view_->OpenContextMenu(anchor); |
302 } | 303 } |
303 | 304 |
304 void TouchSelectionControllerImpl::OnMenuClosed(TouchEditingMenuView* menu) { | 305 void TouchSelectionControllerImpl::OnMenuClosed(TouchEditingMenuView* menu) { |
305 if (menu == context_menu_) | 306 if (menu == context_menu_) |
306 context_menu_ = NULL; | 307 context_menu_ = NULL; |
307 } | 308 } |
308 | 309 |
309 void TouchSelectionControllerImpl::OnWidgetClosing(Widget* widget) { | 310 void TouchSelectionControllerImpl::OnWidgetClosing(Widget* widget) { |
310 DCHECK_EQ(client_widget_, widget); | 311 DCHECK_EQ(client_widget_, widget); |
311 client_widget_ = NULL; | 312 client_widget_ = NULL; |
312 } | 313 } |
313 | 314 |
314 void TouchSelectionControllerImpl::OnWidgetBoundsChanged( | 315 void TouchSelectionControllerImpl::OnWidgetBoundsChanged( |
315 Widget* widget, | 316 Widget* widget, |
316 const gfx::Rect& new_bounds) { | 317 const gfx::Rect& new_bounds) { |
317 DCHECK_EQ(client_widget_, widget); | 318 DCHECK_EQ(client_widget_, widget); |
318 HideContextMenu(); | 319 HideContextMenu(); |
319 SelectionChanged(); | 320 SelectionChanged(); |
320 } | 321 } |
321 | 322 |
322 void TouchSelectionControllerImpl::ContextMenuTimerFired() { | 323 void TouchSelectionControllerImpl::ContextMenuTimerFired() { |
323 // Get selection end points in client_view's space. | 324 // Get selection end points in client_view's space. |
324 gfx::Rect r1, r2; | 325 gfx::Rect r1, r2; |
325 client_view_->GetSelectionEndPoints(&r1, &r2); | 326 client_view_->GetSelectionEndPoints(&r1, &r2); |
326 | 327 |
327 // if selection is completely inside the view, we display the context menu | 328 // if selection is completely inside the view, we display the context menu |
328 // in the middle of the end points on the top. Else, we show the menu on the | 329 // in the middle of the end points on the top. Else, we show it above the |
329 // top border of the view in the center. | 330 // visible handle. If no handle is visible, we do not show the menu. |
330 gfx::Point menu_pos; | 331 gfx::Point menu_pos; |
331 gfx::Rect client_bounds = client_view_->GetBounds(); | 332 gfx::Rect client_bounds = client_view_->GetBounds(); |
332 if (client_bounds.Contains(r1.origin()) && | 333 if (client_bounds.Contains(r1.origin()) && |
333 client_bounds.Contains(r2.origin())) { | 334 client_bounds.Contains(r2.origin())) { |
334 menu_pos.set_x((r1.origin().x() + r2.origin().x()) / 2); | 335 menu_pos.set_x((r1.origin().x() + r2.origin().x()) / 2); |
335 menu_pos.set_y(std::min(r1.y(), r2.y()) - kContextMenuVerticalOffset); | 336 menu_pos.set_y(std::min(r1.y(), r2.y())); |
| 337 } else if (client_bounds.Contains(r1.origin())) { |
| 338 menu_pos = r1.origin(); |
| 339 } else if (client_bounds.Contains(r2.origin())) { |
| 340 menu_pos = r2.origin(); |
336 } else { | 341 } else { |
337 menu_pos.set_x(client_bounds.x() + client_bounds.width() / 2); | 342 return; |
338 menu_pos.set_y(client_bounds.y()); | |
339 } | 343 } |
340 | 344 |
| 345 menu_pos.Offset(0, -kContextMenuVerticalOffset); |
341 client_view_->ConvertPointToScreen(&menu_pos); | 346 client_view_->ConvertPointToScreen(&menu_pos); |
342 | 347 |
343 DCHECK(!context_menu_); | 348 DCHECK(!context_menu_); |
344 context_menu_ = new TouchEditingMenuView(this, menu_pos, | 349 context_menu_ = new TouchEditingMenuView(this, menu_pos, |
345 client_view_->GetNativeView()); | 350 client_view_->GetNativeView()); |
346 } | 351 } |
347 | 352 |
348 void TouchSelectionControllerImpl::StartContextMenuTimer() { | 353 void TouchSelectionControllerImpl::StartContextMenuTimer() { |
349 if (context_menu_timer_.IsRunning()) | 354 if (context_menu_timer_.IsRunning()) |
350 return; | 355 return; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
400 ui::TouchEditable* client_view) { | 405 ui::TouchEditable* client_view) { |
401 #if defined(OS_CHROMEOS) | 406 #if defined(OS_CHROMEOS) |
402 if (CommandLine::ForCurrentProcess()->HasSwitch( | 407 if (CommandLine::ForCurrentProcess()->HasSwitch( |
403 switches::kEnableTouchEditing)) | 408 switches::kEnableTouchEditing)) |
404 return new views::TouchSelectionControllerImpl(client_view); | 409 return new views::TouchSelectionControllerImpl(client_view); |
405 #endif | 410 #endif |
406 return NULL; | 411 return NULL; |
407 } | 412 } |
408 | 413 |
409 } // namespace views | 414 } // namespace views |
OLD | NEW |