OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "cc/input/viewport_scrollbar.h" | |
6 | |
7 #include "cc/layers/layer.h" | |
8 #include "third_party/skia/include/core/SkCanvas.h" | |
9 | |
10 namespace cc { | |
11 | |
12 ViewportScrollbar::ViewportScrollbar(scoped_refptr<Layer> scroll_layer, | |
13 ScrollbarOrientation orientation, | |
14 size_t thickness) | |
15 : scroll_layer_(scroll_layer), | |
16 orientation_(orientation), | |
17 thickness_(thickness) {} | |
18 | |
19 ViewportScrollbar::~ViewportScrollbar() {} | |
20 | |
21 ScrollbarOrientation ViewportScrollbar::Orientation() const { | |
22 return orientation_; | |
23 } | |
24 | |
25 gfx::Point ViewportScrollbar::Location() const { | |
26 return gfx::Point(); | |
27 } | |
28 | |
29 bool ViewportScrollbar::IsOverlay() const { | |
30 return true; | |
31 } | |
32 | |
33 bool ViewportScrollbar::HasThumb() const { | |
34 return true; | |
35 } | |
36 | |
37 int ViewportScrollbar::ThumbThickness() const { | |
38 return thickness_; | |
39 } | |
40 | |
41 int ViewportScrollbar::ThumbLength() const { | |
42 gfx::Rect track_rect = TrackRect(); | |
43 if (orientation_ == HORIZONTAL) { | |
44 float ratio = static_cast<float>(track_rect.width()) / | |
45 scroll_layer_->bounds().width(); | |
46 return track_rect.width() - ratio * scroll_layer_->max_scroll_offset().x(); | |
47 } else { | |
48 float ratio = static_cast<float>(track_rect.height()) / | |
49 scroll_layer_->bounds().height(); | |
50 return track_rect.height() - ratio * scroll_layer_->max_scroll_offset().y(); | |
51 } | |
52 } | |
53 | |
54 gfx::Rect ViewportScrollbar::TrackRect() const { | |
55 if (orientation_ == HORIZONTAL) | |
56 return gfx::Rect( | |
57 0, 0, scroll_layer_->bounds().width() - thickness_, thickness_); | |
58 else | |
59 return gfx::Rect( | |
60 0, 0, thickness_, scroll_layer_->bounds().height() - thickness_); | |
61 } | |
62 | |
63 void ViewportScrollbar::PaintPart(SkCanvas* canvas, | |
64 ScrollbarPart part, | |
65 gfx::Rect content_rect) { | |
66 if (part != THUMB) | |
67 return; | |
68 | |
69 canvas->clear(SkColorSetARGB(0, 0, 0, 0)); | |
70 | |
71 // TODO(wjmaclean): currently the pinch zoom overlay scrollbars are drawn as | |
enne (OOO)
2013/06/14 20:56:59
How are you going to differentiate this PaintPart
wjmaclean
2013/06/17 13:44:28
Based on my conversations with JamesR, the simples
enne (OOO)
2013/06/17 18:05:12
I'd prefer ViewportScrollbar having an empty imple
| |
72 // grey, but need to check this with UX design. | |
73 SkPaint paint; | |
74 paint.setColor(SkColorSetARGB(128, 32, 32, 32)); | |
75 | |
76 // If the scrollbar thickness is sufficient, provide a border around the thumb | |
77 // and round its corners. | |
78 const int min_thickness_for_borders = 8; | |
79 const SkScalar border = thickness_ >= min_thickness_for_borders ? 2 : 0; | |
80 const SkScalar corner_radius = | |
81 thickness_ >= min_thickness_for_borders ? 2 : 0; | |
82 | |
83 SkRect rect = SkRect::MakeXYWH(border, border, | |
84 content_rect.width() - 2 * border, | |
85 content_rect.height() - 2 * border); | |
86 canvas->drawRoundRect(rect, corner_radius, corner_radius, paint); | |
87 } | |
88 | |
89 } // namespace cc | |
OLD | NEW |