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

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: 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.cc
diff --git a/ui/touch_selection/touch_selection_controller.cc b/ui/touch_selection/touch_selection_controller.cc
index 2e18037c658c9b0f7fc02d66e5a8471e8589d0a2..4c02867187a5ca59ad2c53f252b63db60504c67b 100644
--- a/ui/touch_selection/touch_selection_controller.cc
+++ b/ui/touch_selection/touch_selection_controller.cc
@@ -11,9 +11,12 @@
namespace ui {
namespace {
-gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound) {
- gfx::Vector2dF line_offset =
- gfx::ScaleVector2d(bound.edge_top() - bound.edge_bottom(), 0.5f);
+gfx::Vector2dF ComputeLineOffsetFromBottom(const SelectionBound& bound,
+ bool compute_from_top) {
+ gfx::Vector2dF vertical_offset =
+ compute_from_top ? (bound.edge_bottom() - bound.edge_top())
+ : (bound.edge_top() - bound.edge_bottom());
+ gfx::Vector2dF line_offset = gfx::ScaleVector2d(vertical_offset, 0.5f);
// An offset of 5 DIPs is sufficient for most line sizes. For small lines,
// using half the line height avoids synthesizing a point on a line above
// (or below) the intended line.
@@ -59,6 +62,7 @@ TouchSelectionController::TouchSelectionController(
selection_empty_(false),
selection_editable_(false),
temporarily_hidden_(false),
+ viewport_size_changed_(false),
selection_handle_dragged_(false) {
DCHECK(client_);
}
@@ -66,16 +70,25 @@ 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());
+ viewport_size_changed_ = false;
if (!activate_selection_automatically_ &&
!activate_insertion_automatically_) {
@@ -381,14 +394,16 @@ void TouchSelectionController::ActivateSelection() {
start_selection_handle_.reset(new TouchHandle(this, start_orientation_));
} else {
start_selection_handle_->SetEnabled(true);
- start_selection_handle_->SetOrientation(start_orientation_);
+ start_selection_handle_->SetOrientation(start_orientation_, viewport_rect_,
+ start_.edge_bottom());
}
if (!end_selection_handle_) {
end_selection_handle_.reset(new TouchHandle(this, end_orientation_));
} else {
end_selection_handle_->SetEnabled(true);
- end_selection_handle_->SetOrientation(end_orientation_);
+ end_selection_handle_->SetOrientation(end_orientation_, viewport_rect_,
+ end_.edge_bottom());
}
// As a long press received while a selection is already active may trigger
@@ -429,19 +444,27 @@ void TouchSelectionController::ResetCachedValuesIfInactive() {
}
const gfx::PointF& TouchSelectionController::GetStartPosition() const {
+ if (start_selection_handle_ && start_selection_handle_->is_inverted())
+ return start_.edge_top();
return start_.edge_bottom();
}
const gfx::PointF& TouchSelectionController::GetEndPosition() const {
+ if (end_selection_handle_ && end_selection_handle_->is_inverted())
+ return end_.edge_top();
return end_.edge_bottom();
}
gfx::Vector2dF TouchSelectionController::GetStartLineOffset() const {
- return ComputeLineOffsetFromBottom(start_);
+ DCHECK(start_selection_handle_);
+ bool compute_from_top = start_selection_handle_->is_inverted();
+ return ComputeLineOffsetFromBottom(start_, compute_from_top);
}
gfx::Vector2dF TouchSelectionController::GetEndLineOffset() const {
- return ComputeLineOffsetFromBottom(end_);
+ DCHECK(end_selection_handle_);
+ bool compute_from_top = end_selection_handle_->is_inverted();
+ return ComputeLineOffsetFromBottom(end_, compute_from_top);
}
bool TouchSelectionController::GetStartVisible() const {
« ui/touch_selection/touch_handle.h ('K') | « 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