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

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: Cleanup 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
« no previous file with comments | « ui/touch_selection/touch_handle.h ('k') | ui/touch_selection/touch_selection_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 21 matching lines...) Expand all
111 animate_deferred_fade_ = animate; 113 animate_deferred_fade_ = animate;
112 return; 114 return;
113 } 115 }
114 116
115 if (animate) 117 if (animate)
116 BeginFade(); 118 BeginFade();
117 else 119 else
118 EndFade(); 120 EndFade();
119 } 121 }
120 122
121 void TouchHandle::SetPosition(const gfx::PointF& position) { 123 void TouchHandle::UpdatePosition() {
122 DCHECK(enabled_); 124 gfx::PointF position = mirror_vertical_ ? focus_top_ : focus_bottom_;
125
123 if (position_ == position) 126 if (position_ == position)
124 return; 127 return;
125 position_ = position; 128 position_ = position;
126 // Suppress repositioning a handle while invisible or fading out to prevent it 129 // 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 130 // from "ghosting" outside the visible bounds. The position will be pushed to
128 // the drawable when the handle regains visibility (see |SetVisible()|). 131 // the drawable when the handle regains visibility (see |SetVisible()|).
129 if (is_visible_) 132 if (is_visible_)
130 drawable_->SetFocus(position_); 133 drawable_->SetFocus(position_);
131 } 134 }
132 135
136 void TouchHandle::SetFocus(const gfx::PointF& top, const gfx::PointF& bottom) {
137 if (focus_top_ == top && focus_bottom_ == bottom)
138 return;
139
140 focus_top_ = top;
141 focus_bottom_ = bottom;
jdduke (slow) 2015/04/24 21:42:25 OK, so there are 3 inputs here that can impact the
142 }
143
144 void TouchHandle::SetViewportRect(const gfx::RectF viewport_rect) {
145 if (viewport_rect_ == viewport_rect)
146 return;
147
148 viewport_rect_ = viewport_rect;
149 }
150
133 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { 151 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) {
134 DCHECK(enabled_); 152 DCHECK(enabled_);
135 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED); 153 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
136 if (is_dragging_) { 154 if (is_dragging_) {
137 deferred_orientation_ = orientation; 155 deferred_orientation_ = orientation;
138 return; 156 return;
139 } 157 }
140 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED); 158 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED);
141 if (orientation_ == orientation) 159
160 bool mirror_state_changed = SetMirrorParameters();
161 if (orientation_ == orientation && !mirror_state_changed)
142 return; 162 return;
143 163
144 orientation_ = orientation; 164 orientation_ = orientation;
145 drawable_->SetOrientation(orientation); 165 drawable_->SetOrientation(orientation, mirror_vertical_, mirror_horizontal_);
166 }
167
168 bool TouchHandle::SetMirrorParameters() {
169 bool mirror_vertical = false;
170 bool mirror_horizontal = false;
171 bool mirror_state_changed = false;
172 gfx::RectF handle_bounds = drawable_->GetVisibleBounds();
173
174 if (focus_bottom_.y() + handle_bounds.height() > viewport_rect_.bottom()) {
175 mirror_vertical = true;
176 }
177
178 if (orientation_ == TouchHandleOrientation::LEFT &&
179 focus_bottom_.x() - handle_bounds.width() < viewport_rect_.x()) {
180 mirror_horizontal = true;
181 }
182
183 if (orientation_ == TouchHandleOrientation::RIGHT &&
184 focus_bottom_.x() + handle_bounds.width() > viewport_rect_.right()) {
185 mirror_horizontal = true;
186 }
187
188 mirror_state_changed = mirror_vertical_ != mirror_vertical ||
189 mirror_horizontal_ != mirror_horizontal;
190 mirror_vertical_ = mirror_vertical;
191 mirror_horizontal_ = mirror_horizontal;
192 return mirror_state_changed;
146 } 193 }
147 194
148 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { 195 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) {
149 if (!enabled_) 196 if (!enabled_)
150 return false; 197 return false;
151 198
152 if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN) 199 if (!is_dragging_ && event.GetAction() != MotionEvent::ACTION_DOWN)
153 return false; 200 return false;
154 201
155 switch (event.GetAction()) { 202 switch (event.GetAction()) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
244 return; 291 return;
245 292
246 is_dragging_ = false; 293 is_dragging_ = false;
247 is_drag_within_tap_region_ = false; 294 is_drag_within_tap_region_ = false;
248 client_->OnHandleDragEnd(*this); 295 client_->OnHandleDragEnd(*this);
249 296
250 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) { 297 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
251 TouchHandleOrientation deferred_orientation = deferred_orientation_; 298 TouchHandleOrientation deferred_orientation = deferred_orientation_;
252 deferred_orientation_ = TouchHandleOrientation::UNDEFINED; 299 deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
253 SetOrientation(deferred_orientation); 300 SetOrientation(deferred_orientation);
301 UpdatePosition();
254 } 302 }
255 303
256 if (animate_deferred_fade_) { 304 if (animate_deferred_fade_) {
257 BeginFade(); 305 BeginFade();
258 } else { 306 } else {
259 // As drawable visibility assignment is deferred while dragging, push the 307 // As drawable visibility assignment is deferred while dragging, push the
260 // change by forcing fade completion. 308 // change by forcing fade completion.
261 EndFade(); 309 EndFade();
262 } 310 }
263 } 311 }
(...skipping 24 matching lines...) Expand all
288 336
289 void TouchHandle::SetAlpha(float alpha) { 337 void TouchHandle::SetAlpha(float alpha) {
290 alpha = std::max(0.f, std::min(1.f, alpha)); 338 alpha = std::max(0.f, std::min(1.f, alpha));
291 if (alpha_ == alpha) 339 if (alpha_ == alpha)
292 return; 340 return;
293 alpha_ = alpha; 341 alpha_ = alpha;
294 drawable_->SetAlpha(alpha); 342 drawable_->SetAlpha(alpha);
295 } 343 }
296 344
297 } // namespace ui 345 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_handle.h ('k') | ui/touch_selection/touch_selection_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698