Chromium Code Reviews| 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 29068794dbb3af6d1e21b7a28e38b2caa80d3674..2b8f13fb2b333d4ebeb8991bd73b68a4914547d1 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), |
| @@ -91,9 +90,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. |
| @@ -126,12 +125,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()) |
| @@ -142,10 +141,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; |
| @@ -159,7 +158,7 @@ void TouchSelectionController::OnLongPressEvent() { |
| } |
| void TouchSelectionController::AllowShowingFromCurrentSelection() { |
| - if (is_selection_active_ || is_insertion_active_) |
| + if (active_status_ != INACTIVE) |
| return; |
| activate_selection_automatically_ = true; |
| @@ -194,12 +193,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) { |
| @@ -218,11 +217,18 @@ void TouchSelectionController::OnSelectionEmpty(bool empty) { |
| ResetCachedValuesIfInactive(); |
| } |
| +void TouchSelectionController::OnNativeViewMoved() { |
| + if (active_status_ == SELECTION_ACTIVE) |
| + client_->OnSelectionEvent(SELECTION_MOVED); |
|
jdduke (slow)
2015/05/07 20:38:15
Have we come to a conclusion on whether this is st
mohsen
2015/05/07 21:21:55
This is here for the case where user drags a windo
|
| + else if (active_status_ == INSERTION_ACTIVE) |
| + client_->OnSelectionEvent(INSERTION_MOVED); |
| +} |
| + |
| 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; |
| @@ -233,7 +239,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()) |
| @@ -247,17 +253,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(); |
| } |
| @@ -300,11 +306,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) { |
| @@ -361,9 +366,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); |
| @@ -379,8 +384,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); |
| @@ -394,30 +399,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_)); |
| @@ -436,12 +441,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; |
| @@ -450,19 +456,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(); |