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

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: 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 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 static std::ostream& operator<<(std::ostream& os,
49 const TouchHandleOrientation& orientation) {
50 switch (orientation) {
51 case TouchHandleOrientation::LEFT:
52 return os << "LEFT";
53 case TouchHandleOrientation::RIGHT:
54 return os << "RIGHT";
55 case TouchHandleOrientation::CENTER:
56 return os << "CENTER";
57 case TouchHandleOrientation::UNDEFINED:
58 return os << "UNDEFINED";
59 default:
60 return os << "INVALID: " << static_cast<int>(orientation);
61 }
62 }
63
47 // Responsible for rendering a selection or insertion handle for text editing. 64 // Responsible for rendering a selection or insertion handle for text editing.
48 TouchHandle::TouchHandle(TouchHandleClient* client, 65 TouchHandle::TouchHandle(TouchHandleClient* client,
49 TouchHandleOrientation orientation) 66 TouchHandleOrientation orientation)
50 : drawable_(client->CreateDrawable()), 67 : drawable_(client->CreateDrawable()),
51 client_(client), 68 client_(client),
52 orientation_(orientation), 69 orientation_(orientation),
53 deferred_orientation_(TOUCH_HANDLE_ORIENTATION_UNDEFINED), 70 deferred_orientation_(TouchHandleOrientation::UNDEFINED),
54 alpha_(0.f), 71 alpha_(0.f),
55 animate_deferred_fade_(false), 72 animate_deferred_fade_(false),
56 enabled_(true), 73 enabled_(true),
57 is_visible_(false), 74 is_visible_(false),
58 is_dragging_(false), 75 is_dragging_(false),
59 is_drag_within_tap_region_(false) { 76 is_drag_within_tap_region_(false) {
60 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 77 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
61 drawable_->SetEnabled(enabled_); 78 drawable_->SetEnabled(enabled_);
62 drawable_->SetOrientation(orientation_); 79 drawable_->SetOrientation(orientation_);
63 drawable_->SetAlpha(alpha_); 80 drawable_->SetAlpha(alpha_);
64 drawable_->SetFocus(position_); 81 drawable_->SetFocus(position_);
65 } 82 }
66 83
67 TouchHandle::~TouchHandle() { 84 TouchHandle::~TouchHandle() {
68 } 85 }
69 86
70 void TouchHandle::SetEnabled(bool enabled) { 87 void TouchHandle::SetEnabled(bool enabled) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 position_ = position; 125 position_ = position;
109 // Suppress repositioning a handle while invisible or fading out to prevent it 126 // 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 127 // from "ghosting" outside the visible bounds. The position will be pushed to
111 // the drawable when the handle regains visibility (see |SetVisible()|). 128 // the drawable when the handle regains visibility (see |SetVisible()|).
112 if (is_visible_) 129 if (is_visible_)
113 drawable_->SetFocus(position_); 130 drawable_->SetFocus(position_);
114 } 131 }
115 132
116 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) { 133 void TouchHandle::SetOrientation(TouchHandleOrientation orientation) {
117 DCHECK(enabled_); 134 DCHECK(enabled_);
118 DCHECK_NE(orientation, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 135 DCHECK_NE(orientation, TouchHandleOrientation::UNDEFINED);
119 if (is_dragging_) { 136 if (is_dragging_) {
120 deferred_orientation_ = orientation; 137 deferred_orientation_ = orientation;
121 return; 138 return;
122 } 139 }
123 DCHECK_EQ(deferred_orientation_, TOUCH_HANDLE_ORIENTATION_UNDEFINED); 140 DCHECK_EQ(deferred_orientation_, TouchHandleOrientation::UNDEFINED);
124 if (orientation_ == orientation) 141 if (orientation_ == orientation)
125 return; 142 return;
126 143
127 orientation_ = orientation; 144 orientation_ = orientation;
128 drawable_->SetOrientation(orientation); 145 drawable_->SetOrientation(orientation);
129 } 146 }
130 147
131 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) { 148 bool TouchHandle::WillHandleTouchEvent(const MotionEvent& event) {
132 if (!enabled_) 149 if (!enabled_)
133 return false; 150 return false;
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 240
224 void TouchHandle::EndDrag() { 241 void TouchHandle::EndDrag() {
225 DCHECK(enabled_); 242 DCHECK(enabled_);
226 if (!is_dragging_) 243 if (!is_dragging_)
227 return; 244 return;
228 245
229 is_dragging_ = false; 246 is_dragging_ = false;
230 is_drag_within_tap_region_ = false; 247 is_drag_within_tap_region_ = false;
231 client_->OnHandleDragEnd(*this); 248 client_->OnHandleDragEnd(*this);
232 249
233 if (deferred_orientation_ != TOUCH_HANDLE_ORIENTATION_UNDEFINED) { 250 if (deferred_orientation_ != TouchHandleOrientation::UNDEFINED) {
234 TouchHandleOrientation deferred_orientation = deferred_orientation_; 251 TouchHandleOrientation deferred_orientation = deferred_orientation_;
235 deferred_orientation_ = TOUCH_HANDLE_ORIENTATION_UNDEFINED; 252 deferred_orientation_ = TouchHandleOrientation::UNDEFINED;
236 SetOrientation(deferred_orientation); 253 SetOrientation(deferred_orientation);
237 } 254 }
238 255
239 if (animate_deferred_fade_) { 256 if (animate_deferred_fade_) {
240 BeginFade(); 257 BeginFade();
241 } else { 258 } else {
242 // As drawable visibility assignment is deferred while dragging, push the 259 // As drawable visibility assignment is deferred while dragging, push the
243 // change by forcing fade completion. 260 // change by forcing fade completion.
244 EndFade(); 261 EndFade();
245 } 262 }
(...skipping 25 matching lines...) Expand all
271 288
272 void TouchHandle::SetAlpha(float alpha) { 289 void TouchHandle::SetAlpha(float alpha) {
273 alpha = std::max(0.f, std::min(1.f, alpha)); 290 alpha = std::max(0.f, std::min(1.f, alpha));
274 if (alpha_ == alpha) 291 if (alpha_ == alpha)
275 return; 292 return;
276 alpha_ = alpha; 293 alpha_ = alpha;
277 drawable_->SetAlpha(alpha); 294 drawable_->SetAlpha(alpha);
278 } 295 }
279 296
280 } // namespace ui 297 } // 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