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

Unified Diff: ui/touch_selection/touch_selection_controller_aura.cc

Issue 698253004: Reland: Implement Aura side of unified touch text selection for contents (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed overrides in TouchHandleDrawableAura Created 5 years, 11 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 side-by-side diff with in-line comments
Download patch
Index: ui/touch_selection/touch_selection_controller_aura.cc
diff --git a/ui/touch_selection/touch_selection_controller_aura.cc b/ui/touch_selection/touch_selection_controller_aura.cc
new file mode 100644
index 0000000000000000000000000000000000000000..7f590629311bb183a226dcc9fceb67b8f072959a
--- /dev/null
+++ b/ui/touch_selection/touch_selection_controller_aura.cc
@@ -0,0 +1,314 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "ui/touch_selection/touch_selection_controller_aura.h"
+
+#include "ui/aura/client/cursor_client.h"
+#include "ui/aura/env.h"
+#include "ui/aura/window.h"
+#include "ui/events/event.h"
+#include "ui/events/gesture_detection/gesture_configuration.h"
+#include "ui/events/gestures/motion_event_aura.h"
+#include "ui/touch_selection/touch_handle_drawable_aura.h"
+
+
+namespace ui {
+
+TouchSelectionControllerAura::TouchSelectionControllerAura(
+ TouchSelectionControllerAuraClient* client)
+ : client_(client),
+ motion_event_(new MotionEventAura),
+ scroll_in_progress_(false),
+ overscroll_in_progress_(false),
+ handle_drag_in_progress_(false) {
+ int tap_timeout_ms =
+ GestureConfiguration::GetInstance()->show_press_delay_in_ms();
+ int touch_slop =
+ GestureConfiguration::GetInstance()->max_touch_move_in_pixels_for_click();
+ controller_.reset(new TouchSelectionController(
+ this,
+ base::TimeDelta::FromMilliseconds(tap_timeout_ms),
+ touch_slop,
+ true));
jdduke (slow) 2015/01/28 16:35:32 The side-effetcs of |true| are a little unclear un
mohsen 2015/02/22 23:23:09 Done.
+}
+
+TouchSelectionControllerAura::~TouchSelectionControllerAura() {
+}
+
+void TouchSelectionControllerAura::OnSelectionEditable(bool editable) {
+ controller_->OnSelectionEditable(editable);
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::OnSelectionEmpty(bool empty) {
+ controller_->OnSelectionEmpty(empty);
+ UpdateQuickMenu();
+}
+
+
+void TouchSelectionControllerAura::OnSelectionBoundsUpdated(
+ const SelectionBound& start,
+ const SelectionBound& end) {
+ if (controller_->start() == start && controller_->end() == end)
jdduke (slow) 2015/01/28 16:35:32 Don't love this early exit, one alternative would
mohsen 2015/02/22 23:23:09 Done.
+ return;
+
+ controller_->OnSelectionBoundsUpdated(start, end);
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::HandleGestureEvent(GestureEvent* event) {
+ switch (event->type()) {
+ case ET_GESTURE_LONG_PRESS:
+ controller_->OnLongPressEvent();
+ break;
+ case ET_GESTURE_TAP:
+ if (!controller_->is_insertion_active() &&
+ !controller_->is_selection_active() &&
+ RectBetweenSelectionBounds(
+ controller_->start(),
+ controller_->end()).Contains(event->x(), event->y())) {
+ // TODO: also check for editability
+ controller_->TryActivateSelection();
+ event->SetHandled();
+ } else {
+ controller_->OnTapEvent();
+ }
+ break;
+ case ET_GESTURE_SCROLL_BEGIN:
+ scroll_in_progress_ = true;
+ UpdateQuickMenu();
+ break;
+ case ET_GESTURE_SCROLL_END:
+ scroll_in_progress_ = false;
+ UpdateQuickMenu();
+ break;
+ default:
+ break;
+ }
+}
+
+void TouchSelectionControllerAura::HandleTouchEvent(TouchEvent* event) {
+ const int index = motion_event_->FindPointerIndexOfId(event->touch_id());
+ const bool pointer_id_is_active = index != -1;
+
+ if (event->type() != ET_TOUCH_PRESSED && !pointer_id_is_active)
+ return;
+
+ if (event->type() == ET_TOUCH_PRESSED && pointer_id_is_active)
+ motion_event_.reset(new MotionEventAura);
+
+ motion_event_->OnTouch(*event);
+ if (controller_->WillHandleTouchEvent(*motion_event_))
+ event->SetHandled();
+ motion_event_->CleanupRemovedTouchPoints(*event);
+}
+
+void TouchSelectionControllerAura::HideAndDisallowShowingAutomatically() {
+ controller_->HideAndDisallowShowingAutomatically();
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::OnWindowMoved() {
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::OnOverscrollStarted() {
+ overscroll_in_progress_ = true;
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::OnOverscrollCompleted() {
+ overscroll_in_progress_ = false;
+ UpdateQuickMenu();
+}
+
+void TouchSelectionControllerAura::OnFlingCompleted() {
+ scroll_in_progress_ = false;
+ UpdateQuickMenu();
+}
+
+gfx::Rect TouchSelectionControllerAura::GetAnchorRect() const {
+ // TODO: Crop to view bounds
+ const SelectionBound& start = controller_->start();
+ const SelectionBound& end = controller_->end();
+
+ if (start.visible() && end.visible())
+ return RectBetweenSelectionBounds(start, end);
+ if (start.visible())
+ return gfx::BoundingRect(start.edge_top_rounded(),
+ start.edge_bottom_rounded());
+ return gfx::BoundingRect(end.edge_top_rounded(), end.edge_bottom_rounded());
+}
+
+void TouchSelectionControllerAura::ShowQuickMenu() {
+ DCHECK(controller_->is_insertion_active() ||
+ controller_->is_selection_active());
+
+ if (!controller_->start().visible() && !controller_->end().visible())
+ return;
+
+ if (TouchSelectionMenuRunner::GetInstance()) {
+ TouchSelectionMenuRunner::GetInstance()->RunMenu(
+ this,
+ client_->ConvertRectToScreen(GetAnchorRect()),
+ TouchHandleDrawableAura::GetMaxHandleImageSize(),
+ client_->GetParentWindow()->GetToplevelWindow());
+ }
+}
+
+void TouchSelectionControllerAura::UpdateQuickMenu() {
+ // Hide quick menu if there is any.
+ if (TouchSelectionMenuRunner::GetInstance() &&
+ TouchSelectionMenuRunner::GetInstance()->IsRunning()) {
+ TouchSelectionMenuRunner::GetInstance()->CloseMenu();
+ } else {
+ quick_menu_timer_.Stop();
+ }
+
+ // Start timer to show quick menu if necessary.
+ if (!controller_->is_insertion_active() &&
+ !controller_->is_selection_active())
+ return;
+
+ if (!IsQuickMenuAllowed())
+ return;
+
+ if (immediate_quick_menu_for_testing_) {
+ ShowQuickMenu();
+ } else {
+ quick_menu_timer_.Start(
+ FROM_HERE,
+ base::TimeDelta::FromMilliseconds(100),
+ this,
+ &TouchSelectionControllerAura::ShowQuickMenu);
+ }
+}
+
+bool TouchSelectionControllerAura::IsQuickMenuAllowed() const {
+ return !scroll_in_progress_ && !overscroll_in_progress_ &&
+ !handle_drag_in_progress_;
+}
+
+bool TouchSelectionControllerAura::SupportsAnimation() const {
+ return false;
+}
+
+void TouchSelectionControllerAura::SetNeedsAnimate() {
+ NOTREACHED();
+}
+
+void TouchSelectionControllerAura::MoveCaret(const gfx::PointF& position) {
+ client_->MoveCaret(position);
+}
+
+void TouchSelectionControllerAura::MoveRangeSelectionExtent(
+ const gfx::PointF& extent) {
+ client_->MoveRangeSelectionExtent(extent);
+}
+
+void TouchSelectionControllerAura::SelectBetweenCoordinates(
+ const gfx::PointF& base,
+ const gfx::PointF& extent) {
+ client_->SelectBetweenCoordinates(base, extent);
+}
+
+void TouchSelectionControllerAura::OnSelectionEvent(
+ SelectionEventType event,
+ const gfx::PointF& position) {
+ switch (event) {
+ case SELECTION_SHOWN:
+ UpdateQuickMenu();
+ aura::Env::GetInstance()->RemovePreTargetHandler(this);
+ aura::Env::GetInstance()->AddPreTargetHandler(this);
+ break;
+ case SELECTION_CLEARED:
+ aura::Env::GetInstance()->RemovePreTargetHandler(this);
+ UpdateQuickMenu();
+ break;
+ case SELECTION_DRAG_STARTED:
+ handle_drag_in_progress_ = true;
+ UpdateQuickMenu();
+ break;
+ case SELECTION_DRAG_STOPPED:
+ handle_drag_in_progress_ = false;
+ UpdateQuickMenu();
+ break;
+ case INSERTION_SHOWN:
+ UpdateQuickMenu();
+ aura::Env::GetInstance()->RemovePreTargetHandler(this);
+ aura::Env::GetInstance()->AddPreTargetHandler(this);
+ break;
+ case INSERTION_MOVED:
+ break;
+ case INSERTION_TAPPED:
+ //UpdateQuickMenu();
+ break;
+ case INSERTION_CLEARED:
+ aura::Env::GetInstance()->RemovePreTargetHandler(this);
+ UpdateQuickMenu();
+ break;
+ case INSERTION_DRAG_STARTED:
+ handle_drag_in_progress_ = true;
+ UpdateQuickMenu();
+ break;
+ case INSERTION_DRAG_STOPPED:
+ handle_drag_in_progress_ = false;
+ UpdateQuickMenu();
+ break;
+ };
+}
+
+scoped_ptr<TouchHandleDrawable> TouchSelectionControllerAura::CreateDrawable() {
+ return scoped_ptr<TouchHandleDrawable>(
+ new TouchHandleDrawableAura(client_->GetParentWindow()));
+}
+
+bool TouchSelectionControllerAura::IsCommandIdEnabled(int command_id) const {
+ return client_->IsCommandIdEnabled(command_id);
+}
+
+void TouchSelectionControllerAura::ExecuteCommand(int command_id,
+ int event_flags) {
+ HideAndDisallowShowingAutomatically();
+ client_->ExecuteCommand(command_id, event_flags);
+}
+
+void TouchSelectionControllerAura::OpenContextMenu() {
+ HideAndDisallowShowingAutomatically();
+ gfx::Rect anchor_rect = GetAnchorRect();
+ client_->OpenContextMenu(gfx::Point(anchor_rect.CenterPoint().x(),
+ anchor_rect.y()));
+}
+
+void TouchSelectionControllerAura::OnKeyEvent(KeyEvent* event) {
+ LOG(ERROR) << "KeyEvent: " << event->name();
+
+ DCHECK(controller_->is_insertion_active() ||
+ controller_->is_selection_active());
+
+ HideAndDisallowShowingAutomatically();
+}
+
+void TouchSelectionControllerAura::OnMouseEvent(MouseEvent* event) {
+ LOG(ERROR) << "MouseEvent: " << event->name();
+
+ DCHECK(controller_->is_insertion_active() ||
+ controller_->is_selection_active());
+
+ aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(
+ client_->GetParentWindow()->GetRootWindow());
+ if (!cursor_client || cursor_client->IsMouseEventsEnabled())
+ HideAndDisallowShowingAutomatically();
+}
+
+void TouchSelectionControllerAura::OnScrollEvent(ScrollEvent* event) {
+ LOG(ERROR) << "ScrollEvent: " << event->name();
+
+ DCHECK(controller_->is_insertion_active() ||
+ controller_->is_selection_active());
+
+ HideAndDisallowShowingAutomatically();
+}
+
+} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698