summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormohsen <mohsen@chromium.org>2015-05-11 11:17:25 -0700
committerCommit bot <commit-bot@chromium.org>2015-05-11 18:18:52 +0000
commit9143361454a599ac0882abcbd846b25ad7ce7945 (patch)
treec63d815c157c2f711f55e90bcdb3e60a8fdbd43a
parentb06ff5fb120d3cd900f48304c2cc4bb415f957ac (diff)
downloadchromium_src-9143361454a599ac0882abcbd846b25ad7ce7945.zip
chromium_src-9143361454a599ac0882abcbd846b25ad7ce7945.tar.gz
chromium_src-9143361454a599ac0882abcbd846b25ad7ce7945.tar.bz2
Add Aura handles to be used in unified touch selection
This patch is part of Aura side of unified touch selection. It adds an implementation of touch handle drawables to be used on Aura. It also adds some functions to the public interface of ui::TouchSelectionController needed for unified touch selection. COLLABORATOR=mfomitchev BUG=399721 Review URL: https://codereview.chromium.org/996373002 Cr-Commit-Position: refs/heads/master@{#329191}
-rw-r--r--ui/resources/ui_resources.grd8
-rw-r--r--ui/touch_selection/BUILD.gn20
-rw-r--r--ui/touch_selection/DEPS5
-rw-r--r--ui/touch_selection/touch_handle_drawable_aura.cc162
-rw-r--r--ui/touch_selection/touch_handle_drawable_aura.h59
-rw-r--r--ui/touch_selection/touch_selection_controller.cc91
-rw-r--r--ui/touch_selection/touch_selection_controller.h15
-rw-r--r--ui/touch_selection/touch_selection_controller_unittest.cc5
-rw-r--r--ui/touch_selection/ui_touch_selection.gyp20
9 files changed, 330 insertions, 55 deletions
diff --git a/ui/resources/ui_resources.grd b/ui/resources/ui_resources.grd
index 788bd56..cc547b0 100644
--- a/ui/resources/ui_resources.grd
+++ b/ui/resources/ui_resources.grd
@@ -500,6 +500,9 @@
<structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP" file="common/aura_scrollbar_thumb_base_pressed_top.png" />
<structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP_LEFT" file="common/aura_scrollbar_thumb_base_pressed_top_left.png" />
<structure type="chrome_scaled_image" name="IDR_SCROLLBAR_THUMB_BASE_PRESSED_TOP_RIGHT" file="common/aura_scrollbar_thumb_base_pressed_top_right.png" />
+ <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_CENTER" file="common/text_selection_handle_center.png" />
+ <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_LEFT" file="common/text_selection_handle_left.png" />
+ <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_RIGHT" file="common/text_selection_handle_right.png" />
</if>
<if expr="toolkit_views">
<structure type="chrome_scaled_image" name="IDR_TEXTBUTTON_HOVER_BOTTOM" file="common/textbutton_hover_bottom.png" />
@@ -530,11 +533,6 @@
<structure type="chrome_scaled_image" name="IDR_TEXTBUTTON_RAISED_TOP_LEFT" file="common/textbutton_raised_top_left.png" />
<structure type="chrome_scaled_image" name="IDR_TEXTBUTTON_RAISED_TOP_RIGHT" file="common/textbutton_raised_top_right.png" />
</if>
- <if expr="toolkit_views">
- <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_CENTER" file="common/text_selection_handle_center.png" />
- <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_LEFT" file="common/text_selection_handle_left.png" />
- <structure type="chrome_scaled_image" name="IDR_TEXT_SELECTION_HANDLE_RIGHT" file="common/text_selection_handle_right.png" />
- </if>
<structure type="chrome_scaled_image" name="IDR_THROBBER" file="throbber.png" />
<if expr="toolkit_views">
<structure type="chrome_scaled_image" name="IDR_TOUCH_DRAG_TIP_COPY" file="common/drag_tip_copy.png" />
diff --git a/ui/touch_selection/BUILD.gn b/ui/touch_selection/BUILD.gn
index ede552f..c5bf894 100644
--- a/ui/touch_selection/BUILD.gn
+++ b/ui/touch_selection/BUILD.gn
@@ -16,6 +16,8 @@ component("touch_selection") {
"selection_event_type.h",
"touch_handle.cc",
"touch_handle.h",
+ "touch_handle_drawable_aura.cc",
+ "touch_handle_drawable_aura.h",
"touch_handle_orientation.h",
"touch_selection_controller.cc",
"touch_selection_controller.h",
@@ -26,11 +28,29 @@ component("touch_selection") {
deps = [
"//base:base",
+ "//ui/aura:aura",
+ "//ui/aura_extra:aura_extra",
"//ui/base:base",
+ "//ui/compositor:compositor",
"//ui/events:events",
"//ui/events:gesture_detection",
+ "//ui/gfx:gfx",
"//ui/gfx/geometry:geometry",
]
+
+ if (!use_aura) {
+ deps -= [
+ "//ui/aura:aura",
+ "//ui/aura_extra:aura_extra",
+ "//ui/compositor:compositor",
+ "//ui/gfx:gfx",
+ ]
+
+ sources -= [
+ "touch_handle_drawable_aura.cc",
+ "touch_handle_drawable_aura.h",
+ ]
+ }
}
test("ui_touch_selection_unittests") {
diff --git a/ui/touch_selection/DEPS b/ui/touch_selection/DEPS
index 00a6bb4..5b83034 100644
--- a/ui/touch_selection/DEPS
+++ b/ui/touch_selection/DEPS
@@ -1,5 +1,8 @@
include_rules = [
+ "+ui/aura",
+ "+ui/aura_extra",
"+ui/base",
"+ui/events",
- "+ui/gfx/geometry"
+ "+ui/gfx",
+ "+ui/resources"
]
diff --git a/ui/touch_selection/touch_handle_drawable_aura.cc b/ui/touch_selection/touch_handle_drawable_aura.cc
new file mode 100644
index 0000000..a353c59
--- /dev/null
+++ b/ui/touch_selection/touch_handle_drawable_aura.cc
@@ -0,0 +1,162 @@
+// 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_handle_drawable_aura.h"
+
+#include "ui/aura/window.h"
+#include "ui/aura/window_targeter.h"
+#include "ui/aura_extra/image_window_delegate.h"
+#include "ui/base/cursor/cursor.h"
+#include "ui/base/hit_test.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/events/event.h"
+#include "ui/gfx/canvas.h"
+#include "ui/gfx/geometry/rect_conversions.h"
+#include "ui/resources/grit/ui_resources.h"
+
+namespace ui {
+namespace {
+
+// The distance by which a handle image is offset from the focal point (i.e.
+// text baseline) downwards.
+const int kSelectionHandleVerticalVisualOffset = 2;
+
+// The padding around the selection handle image can be used to extend the
+// handle window so that touch events near the selection handle image are
+// targeted to the selection handle window.
+const int kSelectionHandlePadding = 0;
+
+// Epsilon value used to compare float values to zero.
+const float kEpsilon = 1e-8f;
+
+// Returns the appropriate handle image based on the handle orientation.
+gfx::Image* GetHandleImage(TouchHandleOrientation orientation) {
+ int resource_id = 0;
+ switch (orientation) {
+ case TouchHandleOrientation::LEFT:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_LEFT;
+ break;
+ case TouchHandleOrientation::CENTER:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_CENTER;
+ break;
+ case TouchHandleOrientation::RIGHT:
+ resource_id = IDR_TEXT_SELECTION_HANDLE_RIGHT;
+ break;
+ case TouchHandleOrientation::UNDEFINED:
+ NOTREACHED() << "Invalid touch handle bound type.";
+ return nullptr;
+ };
+ return &ResourceBundle::GetSharedInstance().GetImageNamed(resource_id);
+}
+
+bool IsNearlyZero(float value) {
+ return std::abs(value) < kEpsilon;
+}
+
+} // namespace
+
+TouchHandleDrawableAura::TouchHandleDrawableAura(aura::Window* parent)
+ : window_delegate_(new aura_extra::ImageWindowDelegate),
+ window_(new aura::Window(window_delegate_)),
+ enabled_(false),
+ alpha_(0),
+ orientation_(TouchHandleOrientation::UNDEFINED) {
+ window_delegate_->set_image_offset(gfx::Vector2d(kSelectionHandlePadding,
+ kSelectionHandlePadding));
+ window_delegate_->set_background_color(SK_ColorTRANSPARENT);
+ window_->SetTransparent(true);
+ window_->Init(LAYER_TEXTURED);
+ window_->set_owned_by_parent(false);
+ window_->set_ignore_events(true);
+ parent->AddChild(window_.get());
+}
+
+TouchHandleDrawableAura::~TouchHandleDrawableAura() {
+}
+
+void TouchHandleDrawableAura::UpdateBounds() {
+ gfx::RectF new_bounds = relative_bounds_;
+ new_bounds.Offset(focal_position_.x(), focal_position_.y());
+ window_->SetBounds(gfx::ToEnclosingRect(new_bounds));
+}
+
+bool TouchHandleDrawableAura::IsVisible() const {
+ return enabled_ && !IsNearlyZero(alpha_);
+}
+
+void TouchHandleDrawableAura::SetEnabled(bool enabled) {
+ if (enabled == enabled_)
+ return;
+
+ enabled_ = enabled;
+ if (IsVisible())
+ window_->Show();
+ else
+ window_->Hide();
+}
+
+void TouchHandleDrawableAura::SetOrientation(
+ TouchHandleOrientation orientation) {
+ if (orientation_ == orientation)
+ return;
+ orientation_ = orientation;
+ gfx::Image* image = GetHandleImage(orientation);
+ window_delegate_->SetImage(*image);
+
+ // Calculate the relative bounds.
+ gfx::Size image_size = image->Size();
+ int window_width = image_size.width() + 2 * kSelectionHandlePadding;
+ int window_height = image_size.height() + 2 * kSelectionHandlePadding;
+ // Due to the shape of the handle images, the window is aligned differently to
+ // the selection bound depending on the orientation.
+ int window_left = 0;
+ switch (orientation) {
+ case TouchHandleOrientation::LEFT:
+ window_left = -image_size.width() - kSelectionHandlePadding;
+ break;
+ case TouchHandleOrientation::RIGHT:
+ window_left = -kSelectionHandlePadding;
+ break;
+ case TouchHandleOrientation::CENTER:
+ window_left = -window_width / 2;
+ break;
+ case TouchHandleOrientation::UNDEFINED:
+ NOTREACHED() << "Undefined handle orientation.";
+ break;
+ };
+ relative_bounds_ = gfx::RectF(
+ window_left,
+ kSelectionHandleVerticalVisualOffset - kSelectionHandlePadding,
+ window_width,
+ window_height);
+ UpdateBounds();
+}
+
+void TouchHandleDrawableAura::SetAlpha(float alpha) {
+ if (alpha == alpha_)
+ return;
+
+ alpha_ = alpha;
+ window_->layer()->SetOpacity(alpha_);
+ if (IsVisible())
+ window_->Show();
+ else
+ window_->Hide();
+}
+
+void TouchHandleDrawableAura::SetFocus(const gfx::PointF& position) {
+ focal_position_ = position;
+ UpdateBounds();
+}
+
+gfx::RectF TouchHandleDrawableAura::GetVisibleBounds() const {
+ gfx::RectF bounds(window_->bounds());
+ bounds.Inset(kSelectionHandlePadding,
+ kSelectionHandlePadding + kSelectionHandleVerticalVisualOffset,
+ kSelectionHandlePadding,
+ kSelectionHandlePadding);
+ return bounds;
+}
+
+} // namespace ui
diff --git a/ui/touch_selection/touch_handle_drawable_aura.h b/ui/touch_selection/touch_handle_drawable_aura.h
new file mode 100644
index 0000000..cb9dc9c
--- /dev/null
+++ b/ui/touch_selection/touch_handle_drawable_aura.h
@@ -0,0 +1,59 @@
+// 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.
+
+#ifndef UI_TOUCH_SELECTION_TOUCH_HANDLE_DRAWABLE_AURA_H_
+#define UI_TOUCH_SELECTION_TOUCH_HANDLE_DRAWABLE_AURA_H_
+
+#include "ui/touch_selection/touch_handle.h"
+#include "ui/touch_selection/touch_handle_orientation.h"
+#include "ui/touch_selection/ui_touch_selection_export.h"
+
+namespace aura {
+class Window;
+}
+
+namespace aura_extra {
+class ImageWindowDelegate;
+}
+
+namespace ui {
+
+class UI_TOUCH_SELECTION_EXPORT TouchHandleDrawableAura
+ : public TouchHandleDrawable {
+ public:
+ explicit TouchHandleDrawableAura(aura::Window* parent);
+ ~TouchHandleDrawableAura() override;
+
+ private:
+ void UpdateBounds();
+
+ bool IsVisible() const;
+
+ // TouchHandleDrawable:
+ void SetEnabled(bool enabled) override;
+ void SetOrientation(TouchHandleOrientation orientation) override;
+ void SetAlpha(float alpha) override;
+ void SetFocus(const gfx::PointF& position) override;
+ gfx::RectF GetVisibleBounds() const override;
+
+ aura_extra::ImageWindowDelegate* window_delegate_;
+ scoped_ptr<aura::Window> window_;
+ bool enabled_;
+ float alpha_;
+ ui::TouchHandleOrientation orientation_;
+
+ // Focal position of the handle set via SetFocus (normally located on the
+ // intersection of the cursor line and the text base line), in coordinate
+ // space of selection controller client (i.e. handle's parent).
+ gfx::PointF focal_position_;
+
+ // Window bounds relative to the focal position.
+ gfx::RectF relative_bounds_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchHandleDrawableAura);
+};
+
+} // namespace ui
+
+#endif // UI_TOUCH_SELECTION_TOUCH_HANDLE_DRAWABLE_AURA_H_
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc
index 540dfee..1c8ceae 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -52,9 +52,8 @@ TouchSelectionController::TouchSelectionController(
response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
start_orientation_(TouchHandleOrientation::UNDEFINED),
end_orientation_(TouchHandleOrientation::UNDEFINED),
- is_insertion_active_(false),
+ active_status_(INACTIVE),
activate_insertion_automatically_(false),
- is_selection_active_(false),
activate_selection_automatically_(false),
selection_empty_(false),
selection_editable_(false),
@@ -79,8 +78,7 @@ void TouchSelectionController::OnSelectionBoundsChanged(
if (!activate_selection_automatically_ &&
!activate_insertion_automatically_) {
- DCHECK(!is_insertion_active_);
- DCHECK(!is_selection_active_);
+ DCHECK_EQ(INACTIVE, active_status_);
DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
return;
}
@@ -93,9 +91,9 @@ void TouchSelectionController::OnSelectionBoundsChanged(
base::AutoReset<InputEventType> auto_reset_response_pending_input_event(
&response_pending_input_event_, causal_input_event);
- const bool is_selection_dragging =
- is_selection_active_ && (start_selection_handle_->is_dragging() ||
- end_selection_handle_->is_dragging());
+ const bool is_selection_dragging = active_status_ == SELECTION_ACTIVE &&
+ (start_selection_handle_->is_dragging() ||
+ end_selection_handle_->is_dragging());
// It's possible that the bounds temporarily overlap while a selection handle
// is being dragged, incorrectly reporting a CENTER orientation.
@@ -128,12 +126,12 @@ void TouchSelectionController::OnSelectionBoundsChanged(
}
bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
- if (is_insertion_active_) {
+ if (active_status_ == INSERTION_ACTIVE) {
DCHECK(insertion_handle_);
return insertion_handle_->WillHandleTouchEvent(event);
}
- if (is_selection_active_) {
+ if (active_status_ == SELECTION_ACTIVE) {
DCHECK(start_selection_handle_);
DCHECK(end_selection_handle_);
if (start_selection_handle_->is_dragging())
@@ -144,10 +142,10 @@ bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
const gfx::PointF event_pos(event.GetX(), event.GetY());
if ((event_pos - GetStartPosition()).LengthSquared() <=
- (event_pos - GetEndPosition()).LengthSquared())
+ (event_pos - GetEndPosition()).LengthSquared()) {
return start_selection_handle_->WillHandleTouchEvent(event);
- else
- return end_selection_handle_->WillHandleTouchEvent(event);
+ }
+ return end_selection_handle_->WillHandleTouchEvent(event);
}
return false;
@@ -161,21 +159,22 @@ void TouchSelectionController::OnLongPressEvent() {
}
void TouchSelectionController::AllowShowingFromCurrentSelection() {
- if (is_selection_active_ || is_insertion_active_)
+ if (active_status_ != INACTIVE)
return;
activate_selection_automatically_ = true;
activate_insertion_automatically_ = true;
- if (GetStartPosition() != GetEndPosition())
+ if (GetStartPosition() != GetEndPosition()) {
OnSelectionChanged();
- else if (start_orientation_ == TouchHandleOrientation::CENTER &&
- selection_editable_)
+ } else if (start_orientation_ == TouchHandleOrientation::CENTER &&
+ selection_editable_) {
OnInsertionChanged();
+ }
}
void TouchSelectionController::OnTapEvent() {
response_pending_input_event_ = TAP;
- if (!is_selection_active_)
+ if (active_status_ != SELECTION_ACTIVE)
activate_selection_automatically_ = false;
ShowInsertionHandleAutomatically();
if (selection_empty_ && !show_on_tap_for_empty_editable_)
@@ -197,12 +196,12 @@ void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
temporarily_hidden_ = hidden;
TouchHandle::AnimationStyle animation_style = GetAnimationStyle(true);
- if (is_selection_active_) {
+ if (active_status_ == SELECTION_ACTIVE) {
start_selection_handle_->SetVisible(GetStartVisible(), animation_style);
end_selection_handle_->SetVisible(GetEndVisible(), animation_style);
- }
- if (is_insertion_active_)
+ } else if (active_status_ == INSERTION_ACTIVE) {
insertion_handle_->SetVisible(GetStartVisible(), animation_style);
+ }
}
void TouchSelectionController::OnSelectionEditable(bool editable) {
@@ -222,10 +221,10 @@ void TouchSelectionController::OnSelectionEmpty(bool empty) {
}
bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
- if (is_insertion_active_)
+ if (active_status_ == INSERTION_ACTIVE)
return insertion_handle_->Animate(frame_time);
- if (is_selection_active_) {
+ if (active_status_ == SELECTION_ACTIVE) {
bool needs_animate = start_selection_handle_->Animate(frame_time);
needs_animate |= end_selection_handle_->Animate(frame_time);
return needs_animate;
@@ -236,7 +235,7 @@ bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
gfx::RectF TouchSelectionController::GetRectBetweenBounds() const {
// Short-circuit for efficiency.
- if (!is_insertion_active_ && !is_selection_active_)
+ if (active_status_ == INACTIVE)
return gfx::RectF();
if (start_.visible() && !end_.visible())
@@ -250,17 +249,17 @@ gfx::RectF TouchSelectionController::GetRectBetweenBounds() const {
}
gfx::RectF TouchSelectionController::GetStartHandleRect() const {
- if (is_insertion_active_)
+ if (active_status_ == INSERTION_ACTIVE)
return insertion_handle_->GetVisibleBounds();
- if (is_selection_active_)
+ if (active_status_ == SELECTION_ACTIVE)
return start_selection_handle_->GetVisibleBounds();
return gfx::RectF();
}
gfx::RectF TouchSelectionController::GetEndHandleRect() const {
- if (is_insertion_active_)
+ if (active_status_ == INSERTION_ACTIVE)
return insertion_handle_->GetVisibleBounds();
- if (is_selection_active_)
+ if (active_status_ == SELECTION_ACTIVE)
return end_selection_handle_->GetVisibleBounds();
return gfx::RectF();
}
@@ -303,11 +302,10 @@ void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
? GetStartLineOffset()
: GetEndLineOffset();
gfx::PointF line_position = position + line_offset;
- if (&handle == insertion_handle_.get()) {
+ if (&handle == insertion_handle_.get())
client_->MoveCaret(line_position);
- } else {
+ else
client_->MoveRangeSelectionExtent(line_position);
- }
}
void TouchSelectionController::OnHandleDragEnd(const TouchHandle& handle) {
@@ -364,9 +362,9 @@ void TouchSelectionController::OnInsertionChanged() {
if (!activate_insertion_automatically_)
return;
- const bool was_active = is_insertion_active_;
+ const bool was_active = active_status_ == INSERTION_ACTIVE;
const gfx::PointF position = GetStartPosition();
- if (!is_insertion_active_)
+ if (!was_active)
ActivateInsertion();
else
client_->OnSelectionEvent(INSERTION_MOVED);
@@ -382,8 +380,8 @@ void TouchSelectionController::OnSelectionChanged() {
if (!activate_selection_automatically_)
return;
- const bool was_active = is_selection_active_;
- if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS)
+ const bool was_active = active_status_ == SELECTION_ACTIVE;
+ if (!was_active || response_pending_input_event_ == LONG_PRESS)
ActivateSelection();
else
client_->OnSelectionEvent(SELECTION_MOVED);
@@ -397,30 +395,30 @@ void TouchSelectionController::OnSelectionChanged() {
}
void TouchSelectionController::ActivateInsertion() {
- DCHECK(!is_selection_active_);
+ DCHECK_NE(SELECTION_ACTIVE, active_status_);
if (!insertion_handle_)
insertion_handle_.reset(
new TouchHandle(this, TouchHandleOrientation::CENTER));
- if (!is_insertion_active_) {
- is_insertion_active_ = true;
+ if (active_status_ == INACTIVE) {
+ active_status_ = INSERTION_ACTIVE;
insertion_handle_->SetEnabled(true);
client_->OnSelectionEvent(INSERTION_SHOWN);
}
}
void TouchSelectionController::DeactivateInsertion() {
- if (!is_insertion_active_)
+ if (active_status_ != INSERTION_ACTIVE)
return;
DCHECK(insertion_handle_);
- is_insertion_active_ = false;
+ active_status_ = INACTIVE;
insertion_handle_->SetEnabled(false);
client_->OnSelectionEvent(INSERTION_CLEARED);
}
void TouchSelectionController::ActivateSelection() {
- DCHECK(!is_insertion_active_);
+ DCHECK_NE(INSERTION_ACTIVE, active_status_);
if (!start_selection_handle_) {
start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
@@ -439,12 +437,13 @@ void TouchSelectionController::ActivateSelection() {
// As a long press received while a selection is already active may trigger
// an entirely new selection, notify the client but avoid sending an
// intervening SELECTION_CLEARED update to avoid unnecessary state changes.
- if (!is_selection_active_ || response_pending_input_event_ == LONG_PRESS) {
- if (is_selection_active_) {
+ if (active_status_ == INACTIVE ||
+ response_pending_input_event_ == LONG_PRESS) {
+ if (active_status_ == SELECTION_ACTIVE) {
// The active selection session finishes with the start of the new one.
LogSelectionEnd();
}
- is_selection_active_ = true;
+ active_status_ = SELECTION_ACTIVE;
selection_handle_dragged_ = false;
selection_start_time_ = base::TimeTicks::Now();
response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
@@ -453,19 +452,19 @@ void TouchSelectionController::ActivateSelection() {
}
void TouchSelectionController::DeactivateSelection() {
- if (!is_selection_active_)
+ if (active_status_ != SELECTION_ACTIVE)
return;
DCHECK(start_selection_handle_);
DCHECK(end_selection_handle_);
LogSelectionEnd();
start_selection_handle_->SetEnabled(false);
end_selection_handle_->SetEnabled(false);
- is_selection_active_ = false;
+ active_status_ = INACTIVE;
client_->OnSelectionEvent(SELECTION_CLEARED);
}
void TouchSelectionController::ResetCachedValuesIfInactive() {
- if (is_selection_active_ || is_insertion_active_)
+ if (active_status_ != INACTIVE)
return;
start_ = SelectionBound();
end_ = SelectionBound();
diff --git a/ui/touch_selection/touch_selection_controller.h b/ui/touch_selection/touch_selection_controller.h
index 115dd0d..f1a434d 100644
--- a/ui/touch_selection/touch_selection_controller.h
+++ b/ui/touch_selection/touch_selection_controller.h
@@ -36,6 +36,12 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionControllerClient {
class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
: public TouchHandleClient {
public:
+ enum ActiveStatus {
+ INACTIVE,
+ INSERTION_ACTIVE,
+ SELECTION_ACTIVE,
+ };
+
TouchSelectionController(TouchSelectionControllerClient* client,
base::TimeDelta tap_timeout,
float tap_slop,
@@ -97,6 +103,11 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
const gfx::PointF& GetStartPosition() const;
const gfx::PointF& GetEndPosition() const;
+ const SelectionBound& start() const { return start_; }
+ const SelectionBound& end() const { return end_; }
+
+ ActiveStatus active_status() const { return active_status_; }
+
private:
enum InputEventType { TAP, LONG_PRESS, INPUT_EVENT_TYPE_NONE };
@@ -146,13 +157,13 @@ class UI_TOUCH_SELECTION_EXPORT TouchSelectionController
TouchHandleOrientation start_orientation_;
TouchHandleOrientation end_orientation_;
+ ActiveStatus active_status_;
+
scoped_ptr<TouchHandle> insertion_handle_;
- bool is_insertion_active_;
bool activate_insertion_automatically_;
scoped_ptr<TouchHandle> start_selection_handle_;
scoped_ptr<TouchHandle> end_selection_handle_;
- bool is_selection_active_;
bool activate_selection_automatically_;
bool selection_empty_;
diff --git a/ui/touch_selection/touch_selection_controller_unittest.cc b/ui/touch_selection/touch_selection_controller_unittest.cc
index 247ed97..6a22b0e 100644
--- a/ui/touch_selection/touch_selection_controller_unittest.cc
+++ b/ui/touch_selection/touch_selection_controller_unittest.cc
@@ -36,6 +36,8 @@ class MockTouchHandleDrawable : public TouchHandleDrawable {
private:
bool* intersects_rect_;
+
+ DISALLOW_COPY_AND_ASSIGN(MockTouchHandleDrawable);
};
} // namespace
@@ -205,6 +207,8 @@ class TouchSelectionControllerTest : public testing::Test,
bool animation_enabled_;
bool dragging_enabled_;
scoped_ptr<TouchSelectionController> controller_;
+
+ DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerTest);
};
TEST_F(TouchSelectionControllerTest, InsertionBasic) {
@@ -433,7 +437,6 @@ TEST_F(TouchSelectionControllerTest, InsertionTapped) {
MockMotionEvent event(MockMotionEvent::ACTION_DOWN, event_time, 0, 0);
EXPECT_TRUE(controller().WillHandleTouchEvent(event));
- //TODO(AKV): this test case has to be modified once crbug.com/394093 is fixed.
EXPECT_THAT(GetAndResetEvents(), ElementsAre(INSERTION_DRAG_STARTED));
event = MockMotionEvent(MockMotionEvent::ACTION_UP, event_time, 0, 0);
diff --git a/ui/touch_selection/ui_touch_selection.gyp b/ui/touch_selection/ui_touch_selection.gyp
index 851c26f..a31bf3c 100644
--- a/ui/touch_selection/ui_touch_selection.gyp
+++ b/ui/touch_selection/ui_touch_selection.gyp
@@ -12,9 +12,13 @@
'type': '<(component)',
'dependencies': [
'../../base/base.gyp:base',
+ '../aura/aura.gyp:aura',
+ '../aura_extra/aura_extra.gyp:aura_extra',
'../base/ui_base.gyp:ui_base',
+ '../compositor/compositor.gyp:compositor',
'../events/events.gyp:events',
'../events/events.gyp:gesture_detection',
+ '../gfx/gfx.gyp:gfx',
'../gfx/gfx.gyp:gfx_geometry',
],
'defines': [
@@ -24,6 +28,8 @@
'selection_event_type.h',
'touch_handle.cc',
'touch_handle.h',
+ 'touch_handle_drawable_aura.cc',
+ 'touch_handle_drawable_aura.h',
'touch_handle_orientation.h',
'touch_selection_controller.cc',
'touch_selection_controller.h',
@@ -32,6 +38,20 @@
'include_dirs': [
'../..',
],
+ 'conditions': [
+ ['use_aura==0', {
+ 'dependencies!': [
+ '../aura/aura.gyp:aura',
+ '../aura_extra/aura_extra.gyp:aura_extra',
+ '../compositor/compositor.gyp:compositor',
+ '../gfx/gfx.gyp:gfx',
+ ],
+ 'sources!': [
+ 'touch_handle_drawable_aura.cc',
+ 'touch_handle_drawable_aura.h',
+ ],
+ }],
+ ],
},
{
'target_name': 'ui_touch_selection_unittests',