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

Side by Side Diff: ui/views/touchui/touch_selection_controller_impl.cc

Issue 13817012: Add method to TouchSelectionController to check if a handle is currently being (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: patch Created 7 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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/views/touchui/touch_selection_controller_impl.h" 5 #include "ui/views/touchui/touch_selection_controller_impl.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/time.h" 8 #include "base/time.h"
9 #include "grit/ui_strings.h" 9 #include "grit/ui_strings.h"
10 #include "ui/base/ui_base_switches.h" 10 #include "ui/base/ui_base_switches.h"
11 #include "ui/gfx/canvas.h" 11 #include "ui/gfx/canvas.h"
12 #include "ui/gfx/rect.h" 12 #include "ui/gfx/rect.h"
13 #include "ui/gfx/screen.h" 13 #include "ui/gfx/screen.h"
14 #include "ui/gfx/size.h" 14 #include "ui/gfx/size.h"
15 #include "ui/views/corewm/shadow_types.h"
15 #include "ui/views/widget/widget.h" 16 #include "ui/views/widget/widget.h"
16 17
17 namespace { 18 namespace {
18 19
19 // Constants defining the visual attributes of selection handles 20 // Constants defining the visual attributes of selection handles
20 const int kSelectionHandleRadius = 10; 21 const int kSelectionHandleRadius = 10;
21 const int kSelectionHandleAlpha = 0x7F; 22 const int kSelectionHandleAlpha = 0x7F;
22 const SkColor kSelectionHandleColor = 23 const SkColor kSelectionHandleColor =
23 SkColorSetA(SK_ColorBLACK, kSelectionHandleAlpha); 24 SkColorSetA(SK_ColorBLACK, kSelectionHandleAlpha);
24 25
25 // The minimum selection size to trigger selection controller. 26 // The minimum selection size to trigger selection controller.
26 const int kMinSelectionSize = 4; 27 const int kMinSelectionSize = 4;
27 28
28 const int kContextMenuTimoutMs = 500; 29 const int kContextMenuTimoutMs = 500;
29 30
30 // Convenience struct to represent a circle shape. 31 // Convenience struct to represent a circle shape.
31 struct Circle { 32 struct Circle {
32 int radius; 33 int radius;
33 gfx::Point center; 34 gfx::Point center;
34 SkColor color; 35 SkColor color;
35 }; 36 };
36 37
37 // Creates a widget to host SelectionHandleView. 38 // Creates a widget to host SelectionHandleView.
38 views::Widget* CreateTouchSelectionPopupWidget(gfx::NativeView context) { 39 views::Widget* CreateTouchSelectionPopupWidget(gfx::NativeView context) {
39 views::Widget* widget = new views::Widget; 40 views::Widget* widget = new views::Widget;
40 views::Widget::InitParams params(views::Widget::InitParams::TYPE_POPUP); 41 views::Widget::InitParams params(views::Widget::InitParams::TYPE_TOOLTIP);
sadrul 2013/04/12 01:34:31 Why do you need this change?
varunjain 2013/04/17 02:46:14 Removed.
41 params.can_activate = false; 42 params.can_activate = false;
42 params.transparent = true; 43 params.transparent = true;
43 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 44 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
44 params.context = context; 45 params.context = context;
45 widget->Init(params); 46 widget->Init(params);
47 SetShadowType(widget->GetNativeView(), views::corewm::SHADOW_TYPE_NONE);
46 return widget; 48 return widget;
47 } 49 }
48 50
49 void PaintCircle(const Circle& circle, gfx::Canvas* canvas) { 51 void PaintCircle(const Circle& circle, gfx::Canvas* canvas) {
50 SkPaint paint; 52 SkPaint paint;
51 paint.setAntiAlias(true); 53 paint.setAntiAlias(true);
52 paint.setStyle(SkPaint::kFill_Style); 54 paint.setStyle(SkPaint::kFill_Style);
53 paint.setColor(circle.color); 55 paint.setColor(circle.color);
54 canvas->DrawCircle(circle.center, circle.radius, paint); 56 canvas->DrawCircle(circle.center, circle.radius, paint);
55 } 57 }
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
238 240
239 if (client_view_->GetBounds().Contains(r2.origin())) { 241 if (client_view_->GetBounds().Contains(r2.origin())) {
240 selection_handle_2_->SetSelectionRectInScreen(screen_rect_2); 242 selection_handle_2_->SetSelectionRectInScreen(screen_rect_2);
241 selection_handle_2_->SetVisible(true); 243 selection_handle_2_->SetVisible(true);
242 } else { 244 } else {
243 selection_handle_2_->SetVisible(false); 245 selection_handle_2_->SetVisible(false);
244 } 246 }
245 } 247 }
246 } 248 }
247 249
250 bool TouchSelectionControllerImpl::IsHandleDragInProgress() {
251 return !!dragging_handle_;
252 }
253
248 void TouchSelectionControllerImpl::SetDraggingHandle( 254 void TouchSelectionControllerImpl::SetDraggingHandle(
249 EditingHandleView* handle) { 255 EditingHandleView* handle) {
250 dragging_handle_ = handle; 256 dragging_handle_ = handle;
251 if (dragging_handle_) 257 if (dragging_handle_)
252 HideContextMenu(); 258 HideContextMenu();
253 else 259 else
254 StartContextMenuTimer(); 260 StartContextMenuTimer();
255 } 261 }
256 262
257 void TouchSelectionControllerImpl::SelectionHandleDragged( 263 void TouchSelectionControllerImpl::SelectionHandleDragged(
258 const gfx::Point& drag_pos) { 264 const gfx::Point& drag_pos) {
259 // We do not want to show the context menu while dragging. 265 // We do not want to show the context menu while dragging.
260 HideContextMenu(); 266 HideContextMenu();
261 267
262 DCHECK(dragging_handle_); 268 DCHECK(dragging_handle_);
263 269
270 gfx::Point offset_drag_pos(drag_pos.x(),
271 drag_pos.y() - dragging_handle_->cursor_height() / 2 -
272 2 * kSelectionHandleRadius);
273 ConvertPointToClientView(dragging_handle_, &offset_drag_pos);
264 if (dragging_handle_ == cursor_handle_.get()) { 274 if (dragging_handle_ == cursor_handle_.get()) {
265 gfx::Point p(drag_pos.x() + kSelectionHandleRadius, drag_pos.y()); 275 client_view_->MoveCaretTo(offset_drag_pos);
266 ConvertPointToClientView(dragging_handle_, &p);
267 client_view_->MoveCaretTo(p);
268 return; 276 return;
269 } 277 }
270 278
271 // Find the stationary selection handle. 279 // Find the stationary selection handle.
272 EditingHandleView* fixed_handle = selection_handle_1_.get(); 280 EditingHandleView* fixed_handle = selection_handle_1_.get();
273 if (fixed_handle == dragging_handle_) 281 if (fixed_handle == dragging_handle_)
274 fixed_handle = selection_handle_2_.get(); 282 fixed_handle = selection_handle_2_.get();
275 283
276 // Find selection end points in client_view's coordinate system. 284 // Find selection end points in client_view's coordinate system.
277 gfx::Point p1(drag_pos.x() + kSelectionHandleRadius, drag_pos.y());
278 ConvertPointToClientView(dragging_handle_, &p1);
279
280 gfx::Point p2(kSelectionHandleRadius, fixed_handle->cursor_height() / 2); 285 gfx::Point p2(kSelectionHandleRadius, fixed_handle->cursor_height() / 2);
281 ConvertPointToClientView(fixed_handle, &p2); 286 ConvertPointToClientView(fixed_handle, &p2);
282 287
283 // Instruct client_view to select the region between p1 and p2. The position 288 // Instruct client_view to select the region between p1 and p2. The position
284 // of |fixed_handle| is the start and that of |dragging_handle| is the end 289 // of |fixed_handle| is the start and that of |dragging_handle| is the end
285 // of selection. 290 // of selection.
286 client_view_->SelectRect(p2, p1); 291 client_view_->SelectRect(p2, offset_drag_pos);
287 } 292 }
288 293
289 void TouchSelectionControllerImpl::ConvertPointToClientView( 294 void TouchSelectionControllerImpl::ConvertPointToClientView(
290 EditingHandleView* source, gfx::Point* point) { 295 EditingHandleView* source, gfx::Point* point) {
291 View::ConvertPointToScreen(source, point); 296 View::ConvertPointToScreen(source, point);
292 client_view_->ConvertPointFromScreen(point); 297 client_view_->ConvertPointFromScreen(point);
293 } 298 }
294 299
295 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const { 300 bool TouchSelectionControllerImpl::IsCommandIdEnabled(int command_id) const {
296 return client_view_->IsCommandIdEnabled(command_id); 301 return client_view_->IsCommandIdEnabled(command_id);
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 ui::TouchEditable* client_view) { 420 ui::TouchEditable* client_view) {
416 #if defined(OS_CHROMEOS) 421 #if defined(OS_CHROMEOS)
417 if (CommandLine::ForCurrentProcess()->HasSwitch( 422 if (CommandLine::ForCurrentProcess()->HasSwitch(
418 switches::kEnableTouchEditing)) 423 switches::kEnableTouchEditing))
419 return new views::TouchSelectionControllerImpl(client_view); 424 return new views::TouchSelectionControllerImpl(client_view);
420 #endif 425 #endif
421 return NULL; 426 return NULL;
422 } 427 }
423 428
424 } // namespace views 429 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl.h ('k') | ui/views/touchui/touch_selection_controller_impl_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698