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

Side by Side Diff: ui/touch_selection/touch_handle.cc

Issue 701823002: Separate out Touch Selection Orientation enum (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: review comments Created 5 years, 10 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_handle_orientation.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 26 matching lines...) Expand all
37 gfx::PointF closest_point_in_rect(circle_center); 37 gfx::PointF closest_point_in_rect(circle_center);
38 closest_point_in_rect.SetToMax(rect.origin()); 38 closest_point_in_rect.SetToMax(rect.origin());
39 closest_point_in_rect.SetToMin(rect.bottom_right()); 39 closest_point_in_rect.SetToMin(rect.bottom_right());
40 40
41 gfx::Vector2dF distance = circle_center - closest_point_in_rect; 41 gfx::Vector2dF distance = circle_center - closest_point_in_rect;
42 return distance.LengthSquared() < (circle_radius * circle_radius); 42 return distance.LengthSquared() < (circle_radius * circle_radius);
43 } 43 }
44 44
45 } // namespace 45 } // namespace
46 46
47 // TODO(AviD): Remove this once logging(DCHECK) supports enum class.
48 std::ostream& operator<<(std::ostream& os,
jdduke (slow) 2015/02/26 16:50:54 Thanks, let's make this static. Also, there's only
AviD 2015/02/27 10:02:27 Done.
49 const TouchHandleOrientation& orientation) {
50 return os << static_cast<int>(orientation);
51 }
52
47 // Responsible for rendering a selection or insertion handle for text editing. 53 // Responsible for rendering a selection or insertion handle for text editing.
48 TouchHandle::TouchHandle(TouchHandleClient* client, 54 TouchHandle::TouchHandle(TouchHandleClient* client,
49 TouchHandleOrientation orientation) 55 TouchHandleOrientation orientation)
50 : drawable_(client->CreateDrawable()), 56 : drawable_(client->CreateDrawable()),
51 client_(client), 57 client_(client),
52 orientation_(orientation), 58 orientation_(orientation),
53 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 59 deferred_orientation_(TouchHandleOrientation::UNDEFINED),
54 alpha_(0.f), 60 alpha_(0.f),
55 animate_deferred_fade_(false), 61 animate_deferred_fade_(false),
56 enabled_(true), 62 enabled_(true),
57 is_visible_(false), 63 is_visible_(false),
58 is_dragging_(false), 64 is_dragging_(false),
59 is_drag_within_tap_region_(false) { 65 is_drag_within_tap_region_(false) {
60 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 66 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
61 drawable_->SetEnabled(enabled_); 67 drawable_->SetEnabled(enabled_);
62 drawable_->SetOrientation(orientation_); 68 drawable_->SetOrientation(orientation_);
63 drawable_->SetAlpha(alpha_); 69 drawable_->SetAlpha(alpha_);
64 drawable_->SetFocus(position_); 70 drawable_->SetFocus(position_);
65 } 71 }
66 72
67 TouchHandle::~TouchHandle() { 73 TouchHandle::~TouchHandle() {
68 } 74 }
69 75
70 void TouchHandle::SetEnabled(bool enabled) { 76 void TouchHandle::SetEnabled(bool enabled) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 position_ = position; 114 position_ = position;
109 // Suppress repositioning a handle while invisible or fading out to prevent it 115 // Suppress repositioning a handle while invisible or fading out to prevent it
110 // from "ghosting" outside the visible bounds. The position will be pushed to 116 // from "ghosting" outside the visible bounds. The position will be pushed to
111 // the drawable when the handle regains visibility (see |SetVisible()|). 117 // the drawable when the handle regains visibility (see |SetVisible()|).
112 if (is_visible_) 118 if (is_visible_)
113 drawable_->SetFocus(position_); 119 drawable_->SetFocus(position_);
114 } 120 }
115 121
116 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { 122 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) {
117 DCHECK(enabled_); 123 DCHECK(enabled_);
118 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 124 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
119 if (is_dragging_) { 125 if (is_dragging_) {
120 deferred_orientation_ = orientation; 126 deferred_orientation_ = orientation;
121 return; 127 return;
122 } 128 }
123 DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 129 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED);
124 if (orientation_ == orientation) 130 if (orientation_ == orientation)
125 return; 131 return;
126 132
127 orientation_ = orientation; 133 orientation_ = orientation;
128 drawable_->SetOrientation(orientation); 134 drawable_->SetOrientation(orientation);
129 } 135 }
130 136
131 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { 137 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) {
132 if (!enabled_) 138 if (!enabled_)
133 return false; 139 return false;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 229
224 void TouchHandle::EndDrag() { 230 void TouchHandle::EndDrag() {
225 DCHECK(enabled_); 231 DCHECK(enabled_);
226 if (!is_dragging_) 232 if (!is_dragging_)
227 return; 233 return;
228 234
229 is_dragging_ = false; 235 is_dragging_ = false;
230 is_drag_within_tap_region_ = false; 236 is_drag_within_tap_region_ = false;
231 client_->OnHandleDragEnd(*this); 237 client_->OnHandleDragEnd(*this);
232 238
233 if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { 239 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
234 TouchHandleOrientation deferred_orientation = deferred_orientation_; 240 TouchHandleOrientation deferred_orientation = deferred_orientation_;
235 deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 241 deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
236 SetOrientation(deferred_orientation); 242 SetOrientation(deferred_orientation);
237 } 243 }
238 244
239 if (animate_deferred_fade_) { 245 if (animate_deferred_fade_) {
240 BeginFade(); 246 BeginFade();
241 } else { 247 } else {
242 // As drawable visibility assignment is deferred while dragging, push the 248 // As drawable visibility assignment is deferred while dragging, push the
243 // change by forcing fade completion. 249 // change by forcing fade completion.
244 EndFade(); 250 EndFade();
245 } 251 }
(...skipping 25 matching lines...) Expand all
271 277
272 void TouchHandle::SetAlpha(float alpha) { 278 void TouchHandle::SetAlpha(float alpha) {
273 alpha = std::max(0.f, std::min(1.f, alpha)); 279 alpha = std::max(0.f, std::min(1.f, alpha));
274 if (alpha_ == alpha) 280 if (alpha_ == alpha)
275 return; 281 return;
276 alpha_ = alpha; 282 alpha_ = alpha;
277 drawable_->SetAlpha(alpha); 283 drawable_->SetAlpha(alpha);
278 } 284 }
279 285
280 } // namespace ui 286 } // namespace ui
OLDNEW
« no previous file with comments | « ui/touch_selection/touch_handle.h ('k') | ui/touch_selection/touch_handle_orientation.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698