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

Unified Diff: ui/touch_selection/touch_selection_controller_aura.cc

Issue 1046783002: wip: Aura-specific implementation of unified touch selection: touch_selection (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Moving the responsibility for showing the menu into the client. Created 5 years, 8 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..cfce32d186b85780f5c0f977de0a3ce5df0730ff
--- /dev/null
+++ b/ui/touch_selection/touch_selection_controller_aura.cc
@@ -0,0 +1,149 @@
+// Copyright 2015 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/client/screen_position_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"
+#include "ui/touch_selection/touch_selection_controller_aura_test_api.h"
+
+namespace ui {
+
+class TouchSelectionControllerAura::EnvPreTargetHandler : public EventHandler {
+ public:
+ EnvPreTargetHandler(TouchSelectionControllerAura* selection_controller);
+ ~EnvPreTargetHandler() override;
+
+ private:
+ // EventHandler:
+ void OnKeyEvent(KeyEvent* event) override;
+ void OnMouseEvent(MouseEvent* event) override;
+ void OnScrollEvent(ScrollEvent* event) override;
+
+ TouchSelectionControllerAura* selection_controller_;
+};
+
+TouchSelectionControllerAura::EnvPreTargetHandler::EnvPreTargetHandler(
+ TouchSelectionControllerAura* selection_controller)
+ : selection_controller_(selection_controller) {
+ aura::Env::GetInstance()->AddPreTargetHandler(this);
+}
+
+TouchSelectionControllerAura::EnvPreTargetHandler::~EnvPreTargetHandler() {
+ aura::Env::GetInstance()->RemovePreTargetHandler(this);
+}
+
+void TouchSelectionControllerAura::EnvPreTargetHandler::OnKeyEvent(
+ KeyEvent* event) {
+ DCHECK(selection_controller_->is_insertion_active() ||
+ selection_controller_->is_selection_active());
+
+ selection_controller_->HideAndDisallowShowingAutomatically();
+}
+
+void TouchSelectionControllerAura::EnvPreTargetHandler::OnMouseEvent(
+ MouseEvent* event) {
+ DCHECK(selection_controller_->is_insertion_active() ||
+ selection_controller_->is_selection_active());
+ aura::client::CursorClient* cursor_client = aura::client::GetCursorClient(
+ selection_controller_->client()->GetNativeView()->GetRootWindow());
+ if (!cursor_client || cursor_client->IsMouseEventsEnabled())
+ selection_controller_->HideAndDisallowShowingAutomatically();
+}
+
+void TouchSelectionControllerAura::EnvPreTargetHandler::OnScrollEvent(
+ ScrollEvent* event) {
+ DCHECK(selection_controller_->is_insertion_active() ||
+ selection_controller_->is_selection_active());
+
+ selection_controller_->HideAndDisallowShowingAutomatically();
+}
+
+TouchSelectionControllerAura::TouchSelectionControllerAura(
+ TouchSelectionControllerClient* client,
+ base::TimeDelta tap_timeout,
+ float tap_slop,
+ bool show_on_tap_for_empty_editable)
+ : TouchSelectionControllerImpl(client,
+ tap_timeout,
+ tap_slop,
+ show_on_tap_for_empty_editable),
+ motion_event_(new MotionEventAura),
+ test_api_(nullptr) {
+ DCHECK(client);
+ client->GetNativeView()->AddPreTargetHandler(this);
+}
+
+TouchSelectionControllerAura::~TouchSelectionControllerAura() {
+ client()->GetNativeView()->RemovePreTargetHandler(this);
+}
+
+void TouchSelectionControllerAura::ActivateInsertion() {
+ if (!is_insertion_active())
+ env_pre_target_handler_.reset(new EnvPreTargetHandler(this));
+ TouchSelectionControllerImpl::ActivateInsertion();
+}
+
+void TouchSelectionControllerAura::DeactivateInsertion() {
+ env_pre_target_handler_.reset();
+ TouchSelectionControllerImpl::DeactivateInsertion();
+}
+
+void TouchSelectionControllerAura::ActivateSelection() {
+ if (!is_selection_active())
+ env_pre_target_handler_.reset(new EnvPreTargetHandler(this));
+ TouchSelectionControllerImpl::ActivateSelection();
+}
+
+void TouchSelectionControllerAura::DeactivateSelection() {
+ env_pre_target_handler_.reset();
+ TouchSelectionControllerImpl::DeactivateSelection();
+}
+
+void TouchSelectionControllerAura::OnTouchEvent(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 (WillHandleTouchEvent(*motion_event_))
+ event->SetHandled();
+ motion_event_->CleanupRemovedTouchPoints(*event);
+}
+
+void TouchSelectionControllerAura::OnGestureEvent(GestureEvent* event) {
+ switch (event->type()) {
+ case ET_GESTURE_LONG_PRESS:
+ OnLongPressEvent();
+ break;
+ case ET_GESTURE_TAP:
+ if (RectBetweenSelectionBounds(start(), end()).Contains(event->x(),
+ event->y())) {
+ if (!is_insertion_active() && ! is_selection_active()) {
+ AllowShowingFromCurrentSelection();
+ event->SetHandled();
+ } else if (!is_selection_editable()) {
+ event->SetHandled();
+ }
+ }
+ if (!event->handled())
+ OnTapEvent();
+ break;
+ default:
+ break;
+ }
+}
+
+} // namespace ui
« no previous file with comments | « ui/touch_selection/touch_selection_controller_aura.h ('k') | ui/touch_selection/touch_selection_controller_aura_test_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698