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 1c42ea0f522c402b75cdc2464580b368046a9811..983f5306024e1ca56213658ffa617838630937de 100644 |
--- a/ui/touch_selection/touch_selection_controller.cc |
+++ b/ui/touch_selection/touch_selection_controller.cc |
@@ -43,9 +43,9 @@ TouchHandleOrientation ToTouchHandleOrientation(SelectionBound::Type type) { |
TouchSelectionController::Config::Config() |
: tap_timeout(base::TimeDelta::FromMilliseconds(100)), |
tap_slop(8), |
+ enable_adaptive_handle_orientation(false), |
enable_longpress_drag_selection(false), |
- show_on_tap_for_empty_editable(false) { |
-} |
+ show_on_tap_for_empty_editable(false) {} |
TouchSelectionController::Config::~Config() { |
} |
@@ -144,6 +144,46 @@ void TouchSelectionController::OnSelectionBoundsChanged( |
HideAndDisallowShowingAutomatically(); |
} |
+void TouchSelectionController::OnViewportChanged( |
+ const gfx::RectF viewport_rect) { |
+ // Trigger a force update if the viewport is changed, so that |
+ // it triggers a call to change the mirror values if required. |
+ if (viewport_rect_ == viewport_rect) { |
jdduke (slow)
2015/08/17 17:20:53
I don't think we should rely on the |OnViewportCha
AviD
2015/08/18 13:56:14
Done.
|
+ UpdateHandleLayoutIfRequired(); |
+ return; |
+ } |
+ |
+ viewport_rect_ = viewport_rect; |
+ |
+ if (active_status_ == INACTIVE) |
+ return; |
+ |
+ if (active_status_ == INSERTION_ACTIVE) { |
+ DCHECK(insertion_handle_); |
+ insertion_handle_->SetViewportRect(viewport_rect); |
+ } else if (active_status_ == SELECTION_ACTIVE) { |
+ DCHECK(start_selection_handle_); |
+ DCHECK(end_selection_handle_); |
+ start_selection_handle_->SetViewportRect(viewport_rect); |
+ end_selection_handle_->SetViewportRect(viewport_rect); |
+ } |
+ |
+ // Update handle layout once per frame update if necessary. |
+ UpdateHandleLayoutIfRequired(); |
+} |
+ |
+void TouchSelectionController::UpdateHandleLayoutIfRequired() { |
jdduke (slow)
2015/08/17 17:20:53
Nit: Move the definition down into the same order
AviD
2015/08/18 13:56:14
Done.
|
+ if (active_status_ == INSERTION_ACTIVE) { |
+ DCHECK(insertion_handle_); |
+ insertion_handle_->UpdateHandleLayout(); |
+ } else if (active_status_ == SELECTION_ACTIVE) { |
+ DCHECK(start_selection_handle_); |
+ DCHECK(end_selection_handle_); |
+ start_selection_handle_->UpdateHandleLayout(); |
+ end_selection_handle_->UpdateHandleLayout(); |
+ } |
+} |
+ |
bool TouchSelectionController::WillHandleTouchEvent(const MotionEvent& event) { |
if (config_.enable_longpress_drag_selection && |
longpress_drag_selector_.WillHandleTouchEvent(event)) { |
@@ -382,6 +422,10 @@ base::TimeDelta TouchSelectionController::GetTapTimeout() const { |
return config_.tap_timeout; |
} |
+bool TouchSelectionController::IsEnabledAdaptiveHandleOrientation() const { |
+ return config_.enable_adaptive_handle_orientation; |
+} |
+ |
void TouchSelectionController::OnLongPressDragActiveStateChanged() { |
// The handles should remain hidden for the duration of a longpress drag, |
// including the time between a longpress and the start of drag motion. |
@@ -441,8 +485,8 @@ void TouchSelectionController::OnInsertionChanged() { |
const bool activated = ActivateInsertionIfNecessary(); |
const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated); |
+ insertion_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
insertion_handle_->SetVisible(GetStartVisible(), animation); |
- insertion_handle_->SetPosition(GetStartPosition()); |
client_->OnSelectionEvent(activated ? INSERTION_HANDLE_SHOWN |
: INSERTION_HANDLE_MOVED); |
@@ -457,10 +501,15 @@ void TouchSelectionController::OnSelectionChanged() { |
const bool activated = ActivateSelectionIfNecessary(); |
const TouchHandle::AnimationStyle animation = GetAnimationStyle(!activated); |
+ |
+ start_selection_handle_->SetFocus(start_.edge_top(), start_.edge_bottom()); |
+ end_selection_handle_->SetFocus(end_.edge_top(), end_.edge_bottom()); |
+ |
+ start_selection_handle_->SetOrientation(start_orientation_); |
+ end_selection_handle_->SetOrientation(end_orientation_); |
+ |
start_selection_handle_->SetVisible(GetStartVisible(), animation); |
end_selection_handle_->SetVisible(GetEndVisible(), animation); |
- start_selection_handle_->SetPosition(GetStartPosition()); |
- end_selection_handle_->SetPosition(GetEndPosition()); |
client_->OnSelectionEvent(activated ? SELECTION_HANDLES_SHOWN |
: SELECTION_HANDLES_MOVED); |
@@ -471,11 +520,12 @@ bool TouchSelectionController::ActivateInsertionIfNecessary() { |
if (!insertion_handle_) { |
insertion_handle_.reset( |
- new TouchHandle(this, TouchHandleOrientation::CENTER)); |
+ new TouchHandle(this, TouchHandleOrientation::CENTER, viewport_rect_)); |
} |
if (active_status_ == INACTIVE) { |
active_status_ = INSERTION_ACTIVE; |
+ insertion_handle_->SetViewportRect(viewport_rect_); |
insertion_handle_->SetEnabled(true); |
return true; |
} |
@@ -495,17 +545,19 @@ bool TouchSelectionController::ActivateSelectionIfNecessary() { |
DCHECK_NE(INSERTION_ACTIVE, active_status_); |
if (!start_selection_handle_) { |
- start_selection_handle_.reset(new TouchHandle(this, start_orientation_)); |
+ start_selection_handle_.reset( |
+ new TouchHandle(this, start_orientation_, viewport_rect_)); |
} else { |
+ start_selection_handle_->SetViewportRect(viewport_rect_); |
start_selection_handle_->SetEnabled(true); |
- start_selection_handle_->SetOrientation(start_orientation_); |
} |
if (!end_selection_handle_) { |
- end_selection_handle_.reset(new TouchHandle(this, end_orientation_)); |
+ end_selection_handle_.reset( |
+ new TouchHandle(this, end_orientation_, viewport_rect_)); |
} else { |
+ end_selection_handle_->SetViewportRect(viewport_rect_); |
end_selection_handle_->SetEnabled(true); |
- end_selection_handle_->SetOrientation(end_orientation_); |
} |
// As a long press received while a selection is already active may trigger |
@@ -560,6 +612,7 @@ void TouchSelectionController::RefreshHandleVisibility() { |
} |
if (active_status_ == INSERTION_ACTIVE) |
insertion_handle_->SetVisible(GetStartVisible(), animation_style); |
+ UpdateHandleLayoutIfRequired(); |
jdduke (slow)
2015/08/17 17:20:53
I don't think this is necessary.
AviD
2015/08/18 13:56:14
Right. If I move UpdateHandleLayoutIfRequired() to
|
} |
gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const { |