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

Unified Diff: ui/touch_selection/touch_selection_controller_impl.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_impl.cc
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller_impl.cc
similarity index 69%
rename from ui/touch_selection/touch_selection_controller.cc
rename to ui/touch_selection/touch_selection_controller_impl.cc
index 2e18037c658c9b0f7fc02d66e5a8471e8589d0a2..92288e0d36cf948246a33f616b44d500f95abcd4 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller_impl.cc
@@ -2,15 +2,19 @@
// 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.h"
+#include "ui/touch_selection/touch_selection_controller_impl.h"
#include "base/auto_reset.h"
#include "base/logging.h"
#include "base/metrics/histogram_macros.h"
+#include "ui/gfx/geometry/rect.h"
namespace ui {
namespace {
+// Delay before showing the quick menu, in milliseconds.
+//const int kQuickMenuDelayInMs = 100;
+
gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) {
gfx::Vector2dF line_offset =
gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f);
@@ -38,9 +42,21 @@ TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) {
return TouchHandleOrientation::UNDEFINED;
}
+void ClipPoint(gfx::PointF* point, const gfx::Rect& clip_rect) {
+ point->SetToMax(clip_rect.origin());
+ point->SetToMin(clip_rect.bottom_right());
+}
+
+void ClipSelectionBound(SelectionBound* bound, const gfx::Rect& clip_rect) {
+ gfx::PointF edge_top = bound->edge_top();
+ gfx::PointF edge_bottom = bound->edge_bottom();
+ ClipPoint(&edge_top, clip_rect);
+ ClipPoint(&edge_bottom, clip_rect);
+ bound->SetEdge(edge_top, edge_bottom);
+}
} // namespace
-TouchSelectionController::TouchSelectionController(
+TouchSelectionControllerImpl::TouchSelectionControllerImpl(
TouchSelectionControllerClient* client,
base::TimeDelta tap_timeout,
float tap_slop,
@@ -59,18 +75,18 @@ TouchSelectionController::TouchSelectionController(
selection_empty_(false),
selection_editable_(false),
temporarily_hidden_(false),
- selection_handle_dragged_(false) {
+ selection_handle_was_dragged_(false) {
DCHECK(client_);
}
-TouchSelectionController::~TouchSelectionController() {
+TouchSelectionControllerImpl::~TouchSelectionControllerImpl() {
}
-void TouchSelectionController::OnSelectionBoundsChanged(
+bool TouchSelectionControllerImpl::OnSelectionBoundsUpdated(
const SelectionBound& start,
const SelectionBound& end) {
if (start == start_ && end_ == end)
- return;
+ return false;
start_ = start;
end_ = end;
@@ -80,7 +96,7 @@ void TouchSelectionController::OnSelectionBoundsChanged(
if (!activate_selection_automatically_ &&
!activate_insertion_automatically_) {
DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
- return;
+ return false;
}
// Ensure that |response_pending_input_event_| is cleared after the method
@@ -113,19 +129,20 @@ void TouchSelectionController::OnSelectionBoundsChanged(
start_orientation_ != TouchHandleOrientation::UNDEFINED &&
end_orientation_ != TouchHandleOrientation::UNDEFINED)) {
OnSelectionChanged();
- return;
+ return true;
}
if (start_orientation_ == TouchHandleOrientation::CENTER &&
selection_editable_) {
OnInsertionChanged();
- return;
+ return true;
}
HideAndDisallowShowingAutomatically();
+ return true;
}
-bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
+bool TouchSelectionControllerImpl::WillHandleTouchEvent(const MotionEvent& event) {
if (is_insertion_active_) {
DCHECK(insertion_handle_);
return insertion_handle_->WillHandleTouchEvent(event);
@@ -151,14 +168,14 @@ bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
return false;
}
-void TouchSelectionController::OnLongPressEvent() {
+void TouchSelectionControllerImpl::OnLongPressEvent() {
response_pending_input_event_ = LONG_PRESS;
ShowSelectionHandlesAutomatically();
ShowInsertionHandleAutomatically();
ResetCachedValuesIfInactive();
}
-void TouchSelectionController::AllowShowingFromCurrentSelection() {
+void TouchSelectionControllerImpl::AllowShowingFromCurrentSelection() {
if (is_selection_active_ || is_insertion_active_)
return;
@@ -171,7 +188,7 @@ void TouchSelectionController::AllowShowingFromCurrentSelection() {
OnInsertionChanged();
}
-void TouchSelectionController::OnTapEvent() {
+void TouchSelectionControllerImpl::OnTapEvent() {
response_pending_input_event_ = TAP;
ShowInsertionHandleAutomatically();
if (selection_empty_ && !show_on_tap_for_empty_editable_)
@@ -179,15 +196,16 @@ void TouchSelectionController::OnTapEvent() {
ResetCachedValuesIfInactive();
}
-void TouchSelectionController::HideAndDisallowShowingAutomatically() {
+void TouchSelectionControllerImpl::HideAndDisallowShowingAutomatically() {
response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
DeactivateInsertion();
DeactivateSelection();
activate_insertion_automatically_ = false;
activate_selection_automatically_ = false;
+ //UpdateQuickMenu(); - DOn't think this is needed
}
-void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
+void TouchSelectionControllerImpl::SetTemporarilyHidden(bool hidden) {
if (temporarily_hidden_ == hidden)
return;
temporarily_hidden_ = hidden;
@@ -201,7 +219,7 @@ void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
insertion_handle_->SetVisible(GetStartVisible(), animation_style);
}
-void TouchSelectionController::OnSelectionEditable(bool editable) {
+void TouchSelectionControllerImpl::OnSelectionEditable(bool editable) {
if (selection_editable_ == editable)
return;
selection_editable_ = editable;
@@ -210,14 +228,14 @@ void TouchSelectionController::OnSelectionEditable(bool editable) {
DeactivateInsertion();
}
-void TouchSelectionController::OnSelectionEmpty(bool empty) {
+void TouchSelectionControllerImpl::OnSelectionEmpty(bool empty) {
if (selection_empty_ == empty)
return;
selection_empty_ = empty;
ResetCachedValuesIfInactive();
}
-bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
+bool TouchSelectionControllerImpl::Animate(base::TimeTicks frame_time) {
if (is_insertion_active_)
return insertion_handle_->Animate(frame_time);
@@ -230,9 +248,50 @@ bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
return false;
}
-void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
+gfx::Rect TouchSelectionControllerImpl::GetRectBetweenBounds() const {
+ // Short-circuit for efficiency
+ if (!is_insertion_active_ && !is_selection_active_)
+ return gfx::Rect();
+
+ SelectionBound clipped_start = start();
+ SelectionBound clipped_end = end();
+ const gfx::Rect& client_size = client_->GetClientSize();
+ if (clipped_start.visible())
+ ClipSelectionBound(&clipped_start, client_size);
+ if (clipped_end.visible())
+ ClipSelectionBound(&clipped_end, client_size);
+
+ if (clipped_start.visible() && clipped_end.visible())
+ return RectBetweenSelectionBounds(clipped_start, clipped_end);
+ if (clipped_start.visible()) {
+ return gfx::BoundingRect(clipped_start.edge_top_rounded(),
+ clipped_start.edge_bottom_rounded());
+ }
+ if (clipped_end.visible()) {
+ return gfx::BoundingRect(clipped_end.edge_top_rounded(),
+ clipped_end.edge_bottom_rounded());
+ }
+ return gfx::Rect();
+}
+
+void TouchSelectionControllerImpl::OnNativeViewMoved() {
+ if (is_selection_active_)
+ client_->OnSelectionEvent(SELECTION_MOVED);
+ else if (is_insertion_active_)
+ client_->OnSelectionEvent(INSERTION_MOVED);
+}
+
+void TouchSelectionControllerImpl::OnOverscrollStarted() {
+ client_->OnSelectionEvent(NATIVE_VIEW_OVERSCROLL_STARTED);
+}
+
+void TouchSelectionControllerImpl::OnOverscrollCompleted() {
+ client_->OnSelectionEvent(NATIVE_VIEW_OVERSCROLL_STOPPED);
+}
+
+void TouchSelectionControllerImpl::OnHandleDragBegin(const TouchHandle& handle) {
if (&handle == insertion_handle_.get()) {
- client_->OnSelectionEvent(INSERTION_DRAG_STARTED, handle.position());
+ client_->OnSelectionEvent(INSERTION_DRAG_STARTED);
return;
}
@@ -244,16 +303,16 @@ void TouchSelectionController::OnHandleDragBegin(const TouchHandle& handle) {
base = start_selection_handle_->position() + GetStartLineOffset();
extent = end_selection_handle_->position() + GetEndLineOffset();
}
- selection_handle_dragged_ = true;
+ selection_handle_was_dragged_ = true;
// When moving the handle we want to move only the extent point. Before doing
// so we must make sure that the base point is set correctly.
client_->SelectBetweenCoordinates(base, extent);
- client_->OnSelectionEvent(SELECTION_DRAG_STARTED, handle.position());
+ client_->OnSelectionEvent(SELECTION_DRAG_STARTED);
}
-void TouchSelectionController::OnHandleDragUpdate(const TouchHandle& handle,
+void TouchSelectionControllerImpl::OnHandleDragUpdate(const TouchHandle& handle,
const gfx::PointF& position) {
// As the position corresponds to the bottom left point of the selection
// bound, offset it by half the corresponding line height.
@@ -261,56 +320,55 @@ 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) {
+void TouchSelectionControllerImpl::OnHandleDragEnd(const TouchHandle& handle) {
if (&handle == insertion_handle_.get())
- client_->OnSelectionEvent(INSERTION_DRAG_STOPPED, handle.position());
+ client_->OnSelectionEvent(INSERTION_DRAG_STOPPED);
else
- client_->OnSelectionEvent(SELECTION_DRAG_STOPPED, handle.position());
+ client_->OnSelectionEvent(SELECTION_DRAG_STOPPED);
}
-void TouchSelectionController::OnHandleTapped(const TouchHandle& handle) {
+void TouchSelectionControllerImpl::OnHandleTapped(const TouchHandle& handle) {
if (insertion_handle_ && &handle == insertion_handle_.get())
- client_->OnSelectionEvent(INSERTION_TAPPED, handle.position());
+ client_->OnSelectionEvent(INSERTION_TAPPED);
}
-void TouchSelectionController::SetNeedsAnimate() {
+void TouchSelectionControllerImpl::SetNeedsAnimate() {
client_->SetNeedsAnimate();
}
-scoped_ptr<TouchHandleDrawable> TouchSelectionController::CreateDrawable() {
+scoped_ptr<TouchHandleDrawable> TouchSelectionControllerImpl::CreateDrawable() {
return client_->CreateDrawable();
}
-base::TimeDelta TouchSelectionController::GetTapTimeout() const {
+base::TimeDelta TouchSelectionControllerImpl::GetTapTimeout() const {
return tap_timeout_;
}
-float TouchSelectionController::GetTapSlop() const {
+float TouchSelectionControllerImpl::GetTapSlop() const {
return tap_slop_;
}
-void TouchSelectionController::ShowInsertionHandleAutomatically() {
+void TouchSelectionControllerImpl::ShowInsertionHandleAutomatically() {
if (activate_insertion_automatically_)
return;
activate_insertion_automatically_ = true;
ResetCachedValuesIfInactive();
}
-void TouchSelectionController::ShowSelectionHandlesAutomatically() {
+void TouchSelectionControllerImpl::ShowSelectionHandlesAutomatically() {
if (activate_selection_automatically_)
return;
activate_selection_automatically_ = true;
ResetCachedValuesIfInactive();
}
-void TouchSelectionController::OnInsertionChanged() {
+void TouchSelectionControllerImpl::OnInsertionChanged() {
DeactivateSelection();
if (response_pending_input_event_ == TAP && selection_empty_ &&
@@ -327,21 +385,22 @@ void TouchSelectionController::OnInsertionChanged() {
if (!is_insertion_active_)
ActivateInsertion();
else
- client_->OnSelectionEvent(INSERTION_MOVED, position);
+ client_->OnSelectionEvent(INSERTION_MOVED);
insertion_handle_->SetVisible(GetStartVisible(),
GetAnimationStyle(was_active));
insertion_handle_->SetPosition(position);
}
-void TouchSelectionController::OnSelectionChanged() {
+void TouchSelectionControllerImpl::OnSelectionChanged() {
DeactivateInsertion();
if (!activate_selection_automatically_)
return;
const bool was_active = is_selection_active_;
- ActivateSelection();
+ if (!was_active)
+ ActivateSelection();
const TouchHandle::AnimationStyle animation = GetAnimationStyle(was_active);
start_selection_handle_->SetVisible(GetStartVisible(), animation);
@@ -349,9 +408,11 @@ void TouchSelectionController::OnSelectionChanged() {
start_selection_handle_->SetPosition(GetStartPosition());
end_selection_handle_->SetPosition(GetEndPosition());
+ if (was_active)
+ client_->OnSelectionEvent(SELECTION_MOVED);
}
-void TouchSelectionController::ActivateInsertion() {
+void TouchSelectionControllerImpl::ActivateInsertion() {
DCHECK(!is_selection_active_);
if (!insertion_handle_)
@@ -361,20 +422,20 @@ void TouchSelectionController::ActivateInsertion() {
if (!is_insertion_active_) {
is_insertion_active_ = true;
insertion_handle_->SetEnabled(true);
- client_->OnSelectionEvent(INSERTION_SHOWN, GetStartPosition());
+ client_->OnSelectionEvent(INSERTION_SHOWN);
}
}
-void TouchSelectionController::DeactivateInsertion() {
+void TouchSelectionControllerImpl::DeactivateInsertion() {
if (!is_insertion_active_)
return;
DCHECK(insertion_handle_);
is_insertion_active_ = false;
insertion_handle_->SetEnabled(false);
- client_->OnSelectionEvent(INSERTION_CLEARED, gfx::PointF());
+ client_->OnSelectionEvent(INSERTION_CLEARED);
}
-void TouchSelectionController::ActivateSelection() {
+void TouchSelectionControllerImpl::ActivateSelection() {
DCHECK(!is_insertion_active_);
if (!start_selection_handle_) {
@@ -400,14 +461,14 @@ void TouchSelectionController::ActivateSelection() {
LogSelectionEnd();
}
is_selection_active_ = true;
- selection_handle_dragged_ = false;
+ selection_handle_was_dragged_ = false;
selection_start_time_ = base::TimeTicks::Now();
response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
- client_->OnSelectionEvent(SELECTION_SHOWN, GetStartPosition());
+ client_->OnSelectionEvent(SELECTION_SHOWN);
}
}
-void TouchSelectionController::DeactivateSelection() {
+void TouchSelectionControllerImpl::DeactivateSelection() {
if (!is_selection_active_)
return;
DCHECK(start_selection_handle_);
@@ -416,10 +477,10 @@ void TouchSelectionController::DeactivateSelection() {
start_selection_handle_->SetEnabled(false);
end_selection_handle_->SetEnabled(false);
is_selection_active_ = false;
- client_->OnSelectionEvent(SELECTION_CLEARED, gfx::PointF());
+ client_->OnSelectionEvent(SELECTION_CLEARED);
}
-void TouchSelectionController::ResetCachedValuesIfInactive() {
+void TouchSelectionControllerImpl::ResetCachedValuesIfInactive() {
if (is_selection_active_ || is_insertion_active_)
return;
start_ = SelectionBound();
@@ -428,43 +489,43 @@ void TouchSelectionController::ResetCachedValuesIfInactive() {
end_orientation_ = TouchHandleOrientation::UNDEFINED;
}
-const gfx::PointF& TouchSelectionController::GetStartPosition() const {
+const gfx::PointF& TouchSelectionControllerImpl::GetStartPosition() const {
return start_.edge_bottom();
}
-const gfx::PointF& TouchSelectionController::GetEndPosition() const {
+const gfx::PointF& TouchSelectionControllerImpl::GetEndPosition() const {
return end_.edge_bottom();
}
-gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
+gfx::Vector2dF TouchSelectionControllerImpl::GetStartLineOffset() const {
return ComputeLineOffsetFromBottom(start_);
}
-gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const {
+gfx::Vector2dF TouchSelectionControllerImpl::GetEndLineOffset() const {
return ComputeLineOffsetFromBottom(end_);
}
-bool TouchSelectionController::GetStartVisible() const {
+bool TouchSelectionControllerImpl::GetStartVisible() const {
return start_.visible() && !temporarily_hidden_;
}
-bool TouchSelectionController::GetEndVisible() const {
+bool TouchSelectionControllerImpl::GetEndVisible() const {
return end_.visible() && !temporarily_hidden_;
}
-TouchHandle::AnimationStyle TouchSelectionController::GetAnimationStyle(
+TouchHandle::AnimationStyle TouchSelectionControllerImpl::GetAnimationStyle(
bool was_active) const {
return was_active && client_->SupportsAnimation()
? TouchHandle::ANIMATION_SMOOTH
: TouchHandle::ANIMATION_NONE;
}
-void TouchSelectionController::LogSelectionEnd() {
+void TouchSelectionControllerImpl::LogSelectionEnd() {
// TODO(mfomitchev): Once we are able to tell the difference between
// 'successful' and 'unsuccessful' selections - log
// Event.TouchSelection.Duration instead and get rid of
// Event.TouchSelectionD.WasDraggeduration.
- if (selection_handle_dragged_) {
+ if (selection_handle_was_dragged_) {
base::TimeDelta duration = base::TimeTicks::Now() - selection_start_time_;
UMA_HISTOGRAM_CUSTOM_TIMES("Event.TouchSelection.WasDraggedDuration",
duration,
« no previous file with comments | « ui/touch_selection/touch_selection_controller_impl.h ('k') | ui/touch_selection/touch_selection_controller_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698