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

Side by Side Diff: ui/touch_selection/touch_handle.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 unified diff | Download patch
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/touch_selection/touch_handle.h" 5 #include "ui/touch_selection/touch_handle.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 8
9 namespace ui { 9 namespace ui {
10 10
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 TouchHandleOrientation orientation) 66 TouchHandleOrientation orientation)
67 : drawable_(client->CreateDrawable()), 67 : drawable_(client->CreateDrawable()),
68 client_(client), 68 client_(client),
69 orientation_(orientation), 69 orientation_(orientation),
70 deferred_orientation_(TouchHandleOrientation::UNDEFINED), 70 deferred_orientation_(TouchHandleOrientation::UNDEFINED),
71 alpha_(0.f), 71 alpha_(0.f),
72 animate_deferred_fade_(false), 72 animate_deferred_fade_(false),
73 enabled_(true), 73 enabled_(true),
74 is_visible_(false), 74 is_visible_(false),
75 is_dragging_(false), 75 is_dragging_(false),
76 is_drag_within_tap_region_(false) { 76 is_drag_within_tap_region_(false),
77 mirror_vertical_(false),
78 mirror_horizontal_(false) {
77 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); 79 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
78 drawable_->SetEnabled(enabled_); 80 drawable_->SetEnabled(enabled_);
79 drawable_->SetOrientation(orientation_); 81 drawable_->SetOrientation(orientation_, false, false);
80 drawable_->SetAlpha(alpha_); 82 drawable_->SetAlpha(alpha_);
81 drawable_->SetFocus(position_); 83 drawable_->SetFocus(position_);
82 } 84 }
83 85
84 TouchHandle::~TouchHandle() { 86 TouchHandle::~TouchHandle() {
85 } 87 }
86 88
87 void TouchHandle::SetEnabled(bool enabled) { 89 void TouchHandle::SetEnabled(bool enabled) {
88 if (enabled_ == enabled) 90 if (enabled_ == enabled)
89 return; 91 return;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 if (position_ == position) 125 if (position_ == position)
124 return; 126 return;
125 position_ = position; 127 position_ = position;
126 // Suppress repositioning a handle while invisible or fading out to prevent it 128 // Suppress repositioning a handle while invisible or fading out to prevent it
127 // from "ghosting" outside the visible bounds. The position will be pushed to 129 // from "ghosting" outside the visible bounds. The position will be pushed to
128 // the drawable when the handle regains visibility (see |SetVisible()|). 130 // the drawable when the handle regains visibility (see |SetVisible()|).
129 if (is_visible_) 131 if (is_visible_)
130 drawable_->SetFocus(position_); 132 drawable_->SetFocus(position_);
131 } 133 }
132 134
133 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { 135 void TouchHandle::SetOrientation(TouchHandleOrientation orientation,
136 const gfx::RectF viewport_rect,
137 const gfx::PointF handle_bottom) {
134 DCHECK(enabled_); 138 DCHECK(enabled_);
135 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); 139 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
136 if (is_dragging_) { 140 if (is_dragging_) {
137 deferred_orientation_ = orientation; 141 deferred_orientation_ = orientation;
142 deferred_viewport_rect_ = viewport_rect;
143 deferred_handle_bottom_ = handle_bottom;
138 return; 144 return;
139 } 145 }
140 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED); 146 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED);
141 if (orientation_ == orientation) 147
148 bool mirror_state_changed =
149 SetInvertHandleParameters(viewport_rect, handle_bottom);
150 if (orientation_ == orientation && !mirror_state_changed)
142 return; 151 return;
143 152
144 orientation_ = orientation; 153 orientation_ = orientation;
145 drawable_->SetOrientation(orientation); 154 drawable_->SetOrientation(orientation, mirror_vertical_, mirror_horizontal_);
155 }
156
157 bool TouchHandle::SetInvertHandleParameters(const gfx::RectF viewport_rect,
158 const gfx::PointF handle_bottom) {
159 bool mirror_vertical = false;
160 bool mirror_horizontal = false;
161 bool mirror_state_changed = false;
162 gfx::RectF handle_bounds = drawable_->GetVisibleBounds();
163
164 if (handle_bottom.y() + handle_bounds.height() > viewport_rect.bottom()) {
165 mirror_vertical = true;
166 }
167
168 if (orientation_ == TouchHandleOrientation::LEFT &&
169 handle_bottom.x() - handle_bounds.width() < viewport_rect.x()) {
170 mirror_horizontal = true;
171 }
172
173 if (orientation_ == TouchHandleOrientation::RIGHT &&
174 handle_bottom.x() + handle_bounds.width() > viewport_rect.right()) {
175 mirror_horizontal = true;
176 }
177
178 mirror_state_changed = mirror_vertical_ != mirror_vertical ||
179 mirror_horizontal_ != mirror_horizontal;
180 mirror_vertical_ = mirror_vertical;
181 mirror_horizontal_ = mirror_horizontal;
182
183 return mirror_state_changed;
146 } 184 }
147 185
148 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { 186 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) {
149 if (!enabled_) 187 if (!enabled_)
150 return false; 188 return false;
151 189
152 if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN) 190 if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN)
153 return false; 191 return false;
154 192
155 switch (event.GetAction()) { 193 switch (event.GetAction()) {
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 if (!is_dragging_) 281 if (!is_dragging_)
244 return; 282 return;
245 283
246 is_dragging_ = false; 284 is_dragging_ = false;
247 is_drag_within_tap_region_ = false; 285 is_drag_within_tap_region_ = false;
248 client_->OnHandleDragEnd(*this); 286 client_->OnHandleDragEnd(*this);
249 287
250 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) { 288 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
251 TouchHandleOrientation deferred_orientation = deferred_orientation_; 289 TouchHandleOrientation deferred_orientation = deferred_orientation_;
252 deferred_orientation_ = TouchHandleOrientation::UNDEFINED; 290 deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
253 SetOrientation(deferred_orientation); 291 SetOrientation(deferred_orientation, deferred_viewport_rect_,
292 deferred_handle_bottom_);
254 } 293 }
255 294
256 if (animate_deferred_fade_) { 295 if (animate_deferred_fade_) {
257 BeginFade(); 296 BeginFade();
258 } else { 297 } else {
259 // As drawable visibility assignment is deferred while dragging, push the 298 // As drawable visibility assignment is deferred while dragging, push the
260 // change by forcing fade completion. 299 // change by forcing fade completion.
261 EndFade(); 300 EndFade();
262 } 301 }
263 } 302 }
(...skipping 23 matching lines...) Expand all
287 } 326 }
288 327
289 void TouchHandle::SetAlpha(float alpha) { 328 void TouchHandle::SetAlpha(float alpha) {
290 alpha = std::max(0.f, std::min(1.f, alpha)); 329 alpha = std::max(0.f, std::min(1.f, alpha));
291 if (alpha_ == alpha) 330 if (alpha_ == alpha)
292 return; 331 return;
293 alpha_ = alpha; 332 alpha_ = alpha;
294 drawable_->SetAlpha(alpha); 333 drawable_->SetAlpha(alpha);
295 } 334 }
296 335
336 gfx::RectF TouchHandle::GetHandleBounds() {
337 return drawable_->GetVisibleBounds();
338 }
339
297 } // namespace ui 340 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698