OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/time.h" | 7 #include "base/time.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "grit/ui_strings.h" | 9 #include "grit/ui_strings.h" |
10 #include "third_party/skia/include/effects/SkGradientShader.h" | 10 #include "third_party/skia/include/effects/SkGradientShader.h" |
11 #include "ui/base/l10n/l10n_util.h" | 11 #include "ui/base/l10n/l10n_util.h" |
12 #include "ui/base/resource/resource_bundle.h" | 12 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
14 #include "ui/gfx/canvas_skia.h" | 14 #include "ui/gfx/canvas_skia.h" |
15 #include "ui/gfx/path.h" | |
16 #include "ui/gfx/rect.h" | 15 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/screen.h" | 16 #include "ui/gfx/screen.h" |
18 #include "ui/gfx/size.h" | 17 #include "ui/gfx/size.h" |
19 #include "ui/gfx/transform.h" | 18 #include "ui/gfx/transform.h" |
20 #include "ui/views/background.h" | 19 #include "ui/views/background.h" |
21 #include "ui/views/controls/button/button.h" | 20 #include "ui/views/controls/button/button.h" |
22 #include "ui/views/controls/button/custom_button.h" | 21 #include "ui/views/controls/button/custom_button.h" |
23 #include "ui/views/controls/button/text_button.h" | 22 #include "ui/views/controls/button/text_button.h" |
24 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
25 #include "ui/views/controls/menu/menu_config.h" | 24 #include "ui/views/controls/menu/menu_config.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
65 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; | 64 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; |
66 widget->Init(params); | 65 widget->Init(params); |
67 return widget; | 66 return widget; |
68 } | 67 } |
69 | 68 |
70 void PaintCircle(const Circle& circle, gfx::Canvas* canvas) { | 69 void PaintCircle(const Circle& circle, gfx::Canvas* canvas) { |
71 SkPaint paint; | 70 SkPaint paint; |
72 paint.setAntiAlias(true); | 71 paint.setAntiAlias(true); |
73 paint.setStyle(SkPaint::kFill_Style); | 72 paint.setStyle(SkPaint::kFill_Style); |
74 paint.setColor(circle.color); | 73 paint.setColor(circle.color); |
75 gfx::Path path; | 74 SkPath path; |
76 gfx::Rect bounds(circle.center.x() - circle.radius, | 75 gfx::Rect bounds(circle.center.x() - circle.radius, |
77 circle.center.y() - circle.radius, | 76 circle.center.y() - circle.radius, |
78 circle.radius * 2, | 77 circle.radius * 2, |
79 circle.radius * 2); | 78 circle.radius * 2); |
80 SkRect rect; | |
81 rect.set(SkIntToScalar(bounds.x()), SkIntToScalar(bounds.y()), | |
82 SkIntToScalar(bounds.right()), SkIntToScalar(bounds.bottom())); | |
83 SkScalar radius = SkIntToScalar(circle.radius); | 79 SkScalar radius = SkIntToScalar(circle.radius); |
84 path.addRoundRect(rect, radius, radius); | 80 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius); |
85 canvas->GetSkCanvas()->drawPath(path, paint); | 81 canvas->GetSkCanvas()->drawPath(path, paint); |
86 } | 82 } |
87 | 83 |
88 // The points may not match exactly, since the selection range computation may | 84 // The points may not match exactly, since the selection range computation may |
89 // introduce some floating point errors. So check for a minimum size to decide | 85 // introduce some floating point errors. So check for a minimum size to decide |
90 // whether or not there is any selection. | 86 // whether or not there is any selection. |
91 bool IsEmptySelection(const gfx::Point& p1, const gfx::Point& p2) { | 87 bool IsEmptySelection(const gfx::Point& p1, const gfx::Point& p2) { |
92 int delta_x = p2.x() - p1.x(); | 88 int delta_x = p2.x() - p1.x(); |
93 int delta_y = p2.y() - p1.y(); | 89 int delta_y = p2.y() - p1.y(); |
94 return (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize); | 90 return (abs(delta_x) < kMinSelectionSize && abs(delta_y) < kMinSelectionSize); |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
255 SK_ColorWHITE, | 251 SK_ColorWHITE, |
256 SkColorSetRGB(0xF0, 0xF0, 0xF0) | 252 SkColorSetRGB(0xF0, 0xF0, 0xF0) |
257 }; | 253 }; |
258 | 254 |
259 static const SkScalar kGradientPoints[2] = { | 255 static const SkScalar kGradientPoints[2] = { |
260 SkIntToScalar(0), | 256 SkIntToScalar(0), |
261 SkIntToScalar(1) | 257 SkIntToScalar(1) |
262 }; | 258 }; |
263 | 259 |
264 SkPoint points[2]; | 260 SkPoint points[2]; |
265 points[0].set(SkIntToScalar(0), SkIntToScalar(0)); | 261 points[0].iset(0, 0); |
266 points[1].set(SkIntToScalar(0), SkIntToScalar(height())); | 262 points[1].iset(0, height()); |
267 | 263 |
268 SkShader* shader = SkGradientShader::CreateLinear(points, | 264 SkShader* shader = SkGradientShader::CreateLinear(points, |
269 kGradientColors, kGradientPoints, arraysize(kGradientPoints), | 265 kGradientColors, kGradientPoints, arraysize(kGradientPoints), |
270 SkShader::kRepeat_TileMode); | 266 SkShader::kRepeat_TileMode); |
271 DCHECK(shader); | 267 DCHECK(shader); |
272 | 268 |
273 SkPaint paint; | 269 SkPaint paint; |
274 paint.setShader(shader); | 270 paint.setShader(shader); |
275 shader->unref(); | 271 shader->unref(); |
276 | 272 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { | 496 bool TouchSelectionControllerImpl::IsSelectionHandle2Visible() { |
501 return selection_handle_2_->visible(); | 497 return selection_handle_2_->visible(); |
502 } | 498 } |
503 | 499 |
504 TouchSelectionController* TouchSelectionController::create( | 500 TouchSelectionController* TouchSelectionController::create( |
505 TouchSelectionClientView* client_view) { | 501 TouchSelectionClientView* client_view) { |
506 return new TouchSelectionControllerImpl(client_view); | 502 return new TouchSelectionControllerImpl(client_view); |
507 } | 503 } |
508 | 504 |
509 } // namespace views | 505 } // namespace views |
OLD | NEW |