Roll src/third_party/WebKit d9c6159:8139f33 (svn 201974:201975)
[chromium-blink-merge.git] / cc / blink / scrollbar_impl.cc
blobe7c21b8ad1f11a6feb80c19c6fa2e0c6b5da1bbc
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
3 // found in the LICENSE file.
5 #include "cc/blink/scrollbar_impl.h"
7 #include "base/logging.h"
8 #include "third_party/WebKit/public/platform/WebScrollbar.h"
9 #include "third_party/WebKit/public/platform/WebScrollbarThemeGeometry.h"
11 using blink::WebScrollbar;
13 namespace cc_blink {
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()) {
24 ScrollbarImpl::~ScrollbarImpl() {
27 cc::ScrollbarOrientation ScrollbarImpl::Orientation() const {
28 if (scrollbar_->orientation() == WebScrollbar::Horizontal)
29 return cc::HORIZONTAL;
30 return cc::VERTICAL;
33 bool ScrollbarImpl::IsLeftSideVerticalScrollbar() const {
34 return scrollbar_->isLeftSideVerticalScrollbar();
37 bool ScrollbarImpl::HasThumb() const {
38 return geometry_->hasThumb(scrollbar_.get());
41 bool ScrollbarImpl::IsOverlay() const {
42 return scrollbar_->isOverlay();
45 gfx::Point ScrollbarImpl::Location() const {
46 return scrollbar_->location();
49 int ScrollbarImpl::ThumbThickness() const {
50 gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get());
51 if (scrollbar_->orientation() == WebScrollbar::Horizontal)
52 return thumb_rect.height();
53 return thumb_rect.width();
56 int ScrollbarImpl::ThumbLength() const {
57 gfx::Rect thumb_rect = geometry_->thumbRect(scrollbar_.get());
58 if (scrollbar_->orientation() == WebScrollbar::Horizontal)
59 return thumb_rect.width();
60 return thumb_rect.height();
63 gfx::Rect ScrollbarImpl::TrackRect() const {
64 return geometry_->trackRect(scrollbar_.get());
67 void ScrollbarImpl::PaintPart(SkCanvas* canvas,
68 cc::ScrollbarPart part,
69 const gfx::Rect& content_rect) {
70 if (part == cc::THUMB) {
71 painter_.paintThumb(canvas, content_rect);
72 return;
75 // The following is a simplification of ScrollbarThemeComposite::paint.
76 painter_.paintScrollbarBackground(canvas, content_rect);
78 if (geometry_->hasButtons(scrollbar_.get())) {
79 gfx::Rect back_button_start_paint_rect =
80 geometry_->backButtonStartRect(scrollbar_.get());
81 painter_.paintBackButtonStart(canvas, back_button_start_paint_rect);
83 gfx::Rect back_button_end_paint_rect =
84 geometry_->backButtonEndRect(scrollbar_.get());
85 painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect);
87 gfx::Rect forward_button_start_paint_rect =
88 geometry_->forwardButtonStartRect(scrollbar_.get());
89 painter_.paintForwardButtonStart(canvas, forward_button_start_paint_rect);
91 gfx::Rect forward_button_end_paint_rect =
92 geometry_->forwardButtonEndRect(scrollbar_.get());
93 painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect);
96 gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get());
97 painter_.paintTrackBackground(canvas, track_paint_rect);
99 bool thumb_present = geometry_->hasThumb(scrollbar_.get());
100 if (thumb_present) {
101 painter_.paintForwardTrackPart(canvas, track_paint_rect);
102 painter_.paintBackTrackPart(canvas, track_paint_rect);
105 painter_.paintTickmarks(canvas, track_paint_rect);
108 } // namespace cc_blink