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

Unified Diff: ui/touch_selection/touch_selection_controller.cc

Issue 2201853002: Blink handle selection handle visibility (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fixed contextual search test function Created 4 years, 2 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.cc
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc
index 80fa76fde4e8008e91c4f9e8d2a7a0a0721de3b0..bee90e8d75feedfa69f882954a0b4df594730b9a 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -56,15 +56,10 @@ TouchSelectionController::TouchSelectionController(
const Config& config)
: client_(client),
config_(config),
- force_next_update_(false),
response_pending_input_event_(INPUT_EVENT_TYPE_NONE),
mohsen 2016/10/15 03:49:36 Is |response_pending_input_event_| variable still
amaralp 2016/10/19 04:26:38 I don't think it is needed. If it's OK with you I'
mohsen 2016/10/19 16:08:34 Sure. Maybe just add a TODO.
start_orientation_(TouchHandleOrientation::UNDEFINED),
end_orientation_(TouchHandleOrientation::UNDEFINED),
active_status_(INACTIVE),
- activate_insertion_automatically_(false),
- activate_selection_automatically_(false),
- selection_empty_(false),
- selection_editable_(false),
temporarily_hidden_(false),
anchor_drag_to_selection_start_(false),
longpress_drag_selector_(this),
@@ -79,16 +74,13 @@ TouchSelectionController::~TouchSelectionController() {
void TouchSelectionController::OnSelectionBoundsChanged(
const gfx::SelectionBound& start,
const gfx::SelectionBound& end) {
- if (!force_next_update_ && start == start_ && end_ == end)
+ if (start == start_ && end_ == end)
return;
- // Notify if selection bounds have just been established or dissolved.
- if (start.type() != gfx::SelectionBound::EMPTY &&
- start_.type() == gfx::SelectionBound::EMPTY) {
- client_->OnSelectionEvent(SELECTION_ESTABLISHED);
- } else if (start.type() == gfx::SelectionBound::EMPTY &&
- start_.type() != gfx::SelectionBound::EMPTY) {
- client_->OnSelectionEvent(SELECTION_DISSOLVED);
+ if (start.type() == gfx::SelectionBound::EMPTY
+ || end.type() == gfx::SelectionBound::EMPTY) {
mohsen 2016/10/15 03:49:36 nit: putting || at the end of the previous line wo
amaralp 2016/10/19 04:26:38 done
+ HideAndDisallowShowingAutomatically();
+ return;
}
// Swap the Handles when the start and end selection points cross each other.
@@ -105,14 +97,6 @@ void TouchSelectionController::OnSelectionBoundsChanged(
end_ = end;
start_orientation_ = ToTouchHandleOrientation(start_.type());
end_orientation_ = ToTouchHandleOrientation(end_.type());
- force_next_update_ = false;
-
- if (!activate_selection_automatically_ &&
- !activate_insertion_automatically_) {
- DCHECK_EQ(INACTIVE, active_status_);
- DCHECK_EQ(INPUT_EVENT_TYPE_NONE, response_pending_input_event_);
- return;
- }
// Ensure that |response_pending_input_event_| is cleared after the method
// completes, while also making its current value available for the duration
@@ -143,8 +127,7 @@ void TouchSelectionController::OnSelectionBoundsChanged(
return;
}
- if (start_orientation_ == TouchHandleOrientation::CENTER &&
- selection_editable_) {
+ if (start_orientation_ == TouchHandleOrientation::CENTER) {
OnInsertionChanged();
return;
}
@@ -191,38 +174,20 @@ bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) {
return handled || consume_touch_sequence_;
}
-bool TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location,
+void TouchSelectionController::WillHandleTapEvent(const gfx::PointF& location,
int tap_count) {
- if (WillHandleTapOrLongPress(location))
- return true;
-
if (tap_count > 1) {
response_pending_input_event_ = REPEATED_TAP;
- ShowSelectionHandlesAutomatically();
} else {
response_pending_input_event_ = TAP;
- if (active_status_ != SELECTION_ACTIVE)
- activate_selection_automatically_ = false;
}
- ShowInsertionHandleAutomatically();
- if (selection_empty_)
- DeactivateInsertion();
- ForceNextUpdateIfInactive();
- return false;
}
-bool TouchSelectionController::WillHandleLongPressEvent(
+void TouchSelectionController::WillHandleLongPressEvent(
base::TimeTicks event_time,
const gfx::PointF& location) {
- if (WillHandleTapOrLongPress(location))
- return true;
-
longpress_drag_selector_.OnLongPressEvent(event_time, location);
response_pending_input_event_ = LONG_PRESS;
- ShowSelectionHandlesAutomatically();
- ShowInsertionHandleAutomatically();
- ForceNextUpdateIfInactive();
- return false;
}
void TouchSelectionController::OnScrollBeginEvent() {
@@ -237,32 +202,16 @@ void TouchSelectionController::OnScrollBeginEvent() {
// the cause of a selection change (see https://crbug.com/571897).
longpress_drag_selector_.OnScrollBeginEvent();
response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
- if (active_status_ == INACTIVE) {
- activate_insertion_automatically_ = false;
- activate_selection_automatically_ = false;
- }
-}
-
-void TouchSelectionController::AllowShowingFromCurrentSelection() {
- if (active_status_ != INACTIVE)
- return;
-
- activate_selection_automatically_ = true;
- activate_insertion_automatically_ = true;
- if (GetStartPosition() != GetEndPosition()) {
- OnSelectionChanged();
- } else if (start_orientation_ == TouchHandleOrientation::CENTER &&
- selection_editable_) {
- OnInsertionChanged();
- }
}
void TouchSelectionController::HideAndDisallowShowingAutomatically() {
response_pending_input_event_ = INPUT_EVENT_TYPE_NONE;
DeactivateInsertion();
DeactivateSelection();
- activate_insertion_automatically_ = false;
- activate_selection_automatically_ = false;
+ start_ = gfx::SelectionBound();
+ end_ = gfx::SelectionBound();
+ start_orientation_ = ToTouchHandleOrientation(start_.type());
+ end_orientation_ = ToTouchHandleOrientation(end_.type());
}
void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
@@ -272,22 +221,6 @@ void TouchSelectionController::SetTemporarilyHidden(bool hidden) {
RefreshHandleVisibility();
}
-void TouchSelectionController::OnSelectionEditable(bool editable) {
- if (selection_editable_ == editable)
- return;
- selection_editable_ = editable;
- ForceNextUpdateIfInactive();
- if (!selection_editable_)
- DeactivateInsertion();
-}
-
-void TouchSelectionController::OnSelectionEmpty(bool empty) {
- if (selection_empty_ == empty)
- return;
- selection_empty_ = empty;
- ForceNextUpdateIfInactive();
-}
-
bool TouchSelectionController::Animate(base::TimeTicks frame_time) {
if (active_status_ == INSERTION_ACTIVE)
return insertion_handle_->Animate(frame_time);
@@ -476,49 +409,9 @@ gfx::PointF TouchSelectionController::GetSelectionEnd() const {
return GetEndPosition();
}
-void TouchSelectionController::ShowInsertionHandleAutomatically() {
- if (activate_insertion_automatically_)
- return;
- activate_insertion_automatically_ = true;
- ForceNextUpdateIfInactive();
-}
-
-void TouchSelectionController::ShowSelectionHandlesAutomatically() {
- if (activate_selection_automatically_)
- return;
- activate_selection_automatically_ = true;
- ForceNextUpdateIfInactive();
-}
-
-bool TouchSelectionController::WillHandleTapOrLongPress(
- const gfx::PointF& location) {
- // If there is an active selection that was not triggered by a user gesture,
- // allow showing the handles for that selection if a gesture occurs within
- // the selection rect. Note that this hit test is at best a crude
- // approximation, and may swallow taps that actually fall outside the
- // real selection.
- if (active_status_ == INACTIVE &&
- GetStartPosition() != GetEndPosition() &&
- RectFBetweenSelectionBounds(start_, end_).Contains(location)) {
- AllowShowingFromCurrentSelection();
- return true;
- }
- return false;
-}
-
void TouchSelectionController::OnInsertionChanged() {
DeactivateSelection();
- if ((response_pending_input_event_ == TAP ||
- response_pending_input_event_ == REPEATED_TAP) &&
- selection_empty_) {
- HideAndDisallowShowingAutomatically();
- return;
- }
-
- if (!activate_insertion_automatically_)
- return;
-
const bool activated = ActivateInsertionIfNecessary();
const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated);
@@ -534,9 +427,6 @@ void TouchSelectionController::OnInsertionChanged() {
void TouchSelectionController::OnSelectionChanged() {
DeactivateInsertion();
- if (!activate_selection_automatically_)
- return;
-
const bool activated = ActivateSelectionIfNecessary();
const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated);
@@ -635,17 +525,6 @@ void TouchSelectionController::DeactivateSelection() {
client_->OnSelectionEvent(SELECTION_HANDLES_CLEARED);
}
-void TouchSelectionController::ForceNextUpdateIfInactive() {
- // Only force the update if the reported selection is non-empty but still
- // considered "inactive", i.e., it wasn't preceded by a user gesture or
- // the handles have since been explicitly hidden.
- if (active_status_ == INACTIVE &&
- start_.type() != gfx::SelectionBound::EMPTY &&
- end_.type() != gfx::SelectionBound::EMPTY) {
- force_next_update_ = true;
- }
-}
-
void TouchSelectionController::UpdateHandleLayoutIfNecessary() {
if (active_status_ == INSERTION_ACTIVE) {
DCHECK(insertion_handle_);

Powered by Google App Engine
This is Rietveld 408576698