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 "webkit/renderer/compositor_bindings/scrollbar_impl.h" | |
6 | |
7 #include "base/logging.h" | |
8 #include "third_party/WebKit/public/platform/WebScrollbar.h" | |
9 #include "third_party/WebKit/public/platform/WebScrollbarThemeGeometry.h" | |
10 | |
11 using blink::WebScrollbar; | |
12 | |
13 namespace webkit { | |
14 | |
15 ScrollbarImpl::ScrollbarImpl( | |
16 scoped_ptr<WebScrollbar> scrollbar, | |
17 blink::WebScrollbarThemePainter painter, | |
18 scoped_ptr<blink::WebScrollbarThemeGeometry> geometry) | |
19 : scrollbar_(scrollbar.Pass()), | |
20 painter_(painter), | |
21 geometry_(geometry.Pass()) {} | |
22 | |
23 ScrollbarImpl::~ScrollbarImpl() {} | |
24 | |
25 cc::ScrollbarOrientation ScrollbarImpl::Orientation() const { | |
26 if (scrollbar_->orientation() == WebScrollbar::Horizontal) | |
27 return cc::HORIZONTAL; | |
28 return cc::VERTICAL; | |
29 } | |
30 | |
31 bool ScrollbarImpl::IsLeftSideVerticalScrollbar() const { | |
32 return scrollbar_->isLeftSideVerticalScrollbar(); | |
33 } | |
34 | |
35 bool ScrollbarImpl::HasThumb() const { | |
36 return geometry_->hasThumb(scrollbar_.get()); | |
37 } | |
38 | |
39 bool ScrollbarImpl::IsOverlay() const { | |
40 return scrollbar_->isOverlay(); | |
41 } | |
42 | |
43 gfx::Point ScrollbarImpl::Location() const { | |
44 return scrollbar_->location(); | |
45 } | |
46 | |
47 int ScrollbarImpl::ThumbThickness() const { | |
48 gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get()); | |
49 if (scrollbar_->orientation() == WebScrollbar::Horizontal) | |
50 return thumb_rect.height(); | |
51 return thumb_rect.width(); | |
52 } | |
53 | |
54 int ScrollbarImpl::ThumbLength() const { | |
55 gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get()); | |
56 if (scrollbar_->orientation() == WebScrollbar::Horizontal) | |
57 return thumb_rect.width(); | |
58 return thumb_rect.height(); | |
59 } | |
60 | |
61 gfx::Rect ScrollbarImpl::TrackRect() const { | |
62 return geometry_->trackRect(scrollbar_.get()); | |
63 } | |
64 | |
65 void ScrollbarImpl::PaintPart( | |
66 SkCanvas* canvas, cc::ScrollbarPart part, | |
67 const gfx::Rect& content_rect) { | |
68 if (part == cc::THUMB) { | |
69 painter_.paintThumb(canvas, content_rect); | |
70 return; | |
71 } | |
72 | |
73 // The following is a simplification of ScrollbarThemeComposite::paint. | |
74 painter_.paintScrollbarBackground(canvas, content_rect); | |
75 | |
76 if (geometry_->hasButtons(scrollbar_.get())) { | |
77 gfx::Rect back_button_start_paint_rect = | |
78 geometry_->backButtonStartRect(scrollbar_.get()); | |
79 painter_.paintBackButtonStart(canvas, back_button_start_paint_rect); | |
80 | |
81 gfx::Rect back_button_end_paint_rect = | |
82 geometry_->backButtonEndRect(scrollbar_.get()); | |
83 painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect); | |
84 | |
85 gfx::Rect forward_button_start_paint_rect = | |
86 geometry_->forwardButtonStartRect(scrollbar_.get()); | |
87 painter_.paintForwardButtonStart(canvas, | |
88 forward_button_start_paint_rect); | |
89 | |
90 gfx::Rect forward_button_end_paint_rect = | |
91 geometry_->forwardButtonEndRect(scrollbar_.get()); | |
92 painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect); | |
93 } | |
94 | |
95 gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get()); | |
96 painter_.paintTrackBackground(canvas, track_paint_rect); | |
97 | |
98 bool thumb_present = geometry_->hasThumb(scrollbar_.get()); | |
99 if (thumb_present) { | |
100 painter_.paintForwardTrackPart(canvas, track_paint_rect); | |
101 painter_.paintBackTrackPart(canvas, track_paint_rect); | |
102 } | |
103 | |
104 painter_.paintTickmarks(canvas, track_paint_rect); | |
105 } | |
106 | |
107 } // namespace webkit | |
OLD | NEW |