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

Unified Diff: ui/touch_selection/touch_selection_controller.cc

Issue 481683003: Support for Adaptive Handle Orientation (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Separated viewport changed notification Created 5 years, 9 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
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 2e18037c658c9b0f7fc02d66e5a8471e8589d0a2..b1f1f47f313b384e3a71e895d8114718a90e0e67 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -59,6 +59,7 @@ TouchSelectionController::TouchSelectionController(
selection_empty_(false),
selection_editable_(false),
temporarily_hidden_(false),
+ viewport_size_changed_(false),
selection_handle_dragged_(false) {
DCHECK(client_);
}
@@ -66,16 +67,26 @@ TouchSelectionController::TouchSelectionController(
TouchSelectionController::~TouchSelectionController() {
}
+void TouchSelectionController::OnViewportChanged(
+ const gfx::RectF viewport_rect) {
+ if (viewport_rect_ == viewport_rect)
+ return;
+ viewport_size_changed_ = true;
+ viewport_rect_ = viewport_rect;
+}
+
void TouchSelectionController::OnSelectionBoundsChanged(
const SelectionBound& start,
const SelectionBound& end) {
- if (start == start_ && end_ == end)
+ if (start == start_ && end_ == end && !viewport_size_changed_)
return;
start_ = start;
end_ = end;
start_orientation_ = ToTouchHandleOrientation(start_.type());
end_orientation_ = ToTouchHandleOrientation(end_.type());
+ SetInvertedOrientation();
+ viewport_size_changed_ = false;
if (!activate_selection_automatically_ &&
!activate_insertion_automatically_) {
@@ -429,13 +440,70 @@ void TouchSelectionController::ResetCachedValuesIfInactive() {
}
const gfx::PointF& TouchSelectionController::GetStartPosition() const {
+ bool top_handle =
+ start_orientation_ == TouchHandleOrientation::LEFT_INVERTED ||
jdduke (slow) 2015/03/19 18:56:39 Why does the position change depending on the orie
jdduke (slow) 2015/03/23 21:05:31 Nevermind, it sounds like if we mirror the handle
AviD 2015/03/26 14:53:11 Right, it is to position the handles above the tex
+ start_orientation_ == TouchHandleOrientation::LEFT_FLIPPED_INVERTED;
+ if (top_handle)
+ return start_.edge_top();
return start_.edge_bottom();
}
const gfx::PointF& TouchSelectionController::GetEndPosition() const {
+ bool top_handle =
+ end_orientation_ == TouchHandleOrientation::RIGHT_INVERTED ||
+ end_orientation_ == TouchHandleOrientation::RIGHT_FLIPPED_INVERTED;
+ if (top_handle)
+ return end_.edge_top();
return end_.edge_bottom();
}
+void TouchSelectionController::SetInvertedOrientation() {
+ if (!start_selection_handle_ || !end_selection_handle_)
+ return;
+
+ TouchHandleOrientation old_start_orientation = start_orientation_;
+ TouchHandleOrientation old_end_orientation = end_orientation_;
+
+ gfx::RectF start_size = start_selection_handle_->GetHandleBounds();
+ gfx::RectF end_size = end_selection_handle_->GetHandleBounds();
+
+ int start_handle_state = 0;
+ int end_handle_state = 0;
+
+ if (start_.edge_bottom().y() + start_size.height() >
+ viewport_rect_.height()) {
+ start_orientation_ = TouchHandleOrientation::LEFT_INVERTED;
+ start_handle_state++;
+ }
+
+ if (end_.edge_bottom().y() + end_size.height() > viewport_rect_.height()) {
+ end_orientation_ = TouchHandleOrientation::RIGHT_INVERTED;
+ end_handle_state++;
+ }
+
+ if (start_.edge_top().x() - end_size.width() < viewport_rect_.x()) {
+ start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED;
+ start_handle_state++;
+ }
+
+ if (end_.edge_top().x() + start_size.width() > viewport_rect_.width()) {
+ end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED;
+ end_handle_state++;
+ }
+
+ if (start_handle_state == 2) {
jdduke (slow) 2015/03/19 18:56:39 Flipped vs inverted is confusing. What if, instea
jdduke (slow) 2015/03/23 21:05:31 I wonder if it's worth having the TouchHandle be r
AviD 2015/03/26 14:53:10 I will try this approach with the next patch.
+ start_orientation_ = TouchHandleOrientation::LEFT_FLIPPED_INVERTED;
+ } else if (start_handle_state == 0) {
+ start_orientation_ = old_start_orientation;
+ }
+
+ if (end_handle_state == 2) {
+ end_orientation_ = TouchHandleOrientation::RIGHT_FLIPPED_INVERTED;
+ } else if (end_handle_state == 0) {
+ end_orientation_ = old_end_orientation;
+ }
+}
+
gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
return ComputeLineOffsetFromBottom(start_);
}
« no previous file with comments | « ui/touch_selection/touch_selection_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698