Roll leveldb to r78 / 1.15.
[chromium-blink-merge.git] / webkit / renderer / compositor_bindings / scrollbar_impl.cc
blobfb60cd89a5e043450cb80b796de9f8029e342ad8
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.
5 #include "webkit/renderer/compositor_bindings/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 webkit {
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()) {}
23 ScrollbarImpl::~ScrollbarImpl() {}
25 cc::ScrollbarOrientation ScrollbarImpl::Orientation() const {
26 if (scrollbar_->orientation() == WebScrollbar::Horizontal)
27 return cc::HORIZONTAL;
28 return cc::VERTICAL;
31 bool ScrollbarImpl::IsLeftSideVerticalScrollbar() const {
32 return scrollbar_->isLeftSideVerticalScrollbar();
35 bool ScrollbarImpl::HasThumb() const {
36 return geometry_->hasThumb(scrollbar_.get());
39 bool ScrollbarImpl::IsOverlay() const {
40 return scrollbar_->isOverlay();
43 gfx::Point ScrollbarImpl::Location() const {
44 return scrollbar_->location();
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();
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();
61 gfx::Rect ScrollbarImpl::TrackRect() const {
62 return geometry_->trackRect(scrollbar_.get());
65 void ScrollbarImpl::PaintPart(
66 SkCanvas* canvas, cc::ScrollbarPart part, gfx::Rect content_rect) {
67 if (part == cc::THUMB) {
68 painter_.paintThumb(canvas, content_rect);
69 return;
72 // The following is a simplification of ScrollbarThemeComposite::paint.
73 painter_.paintScrollbarBackground(canvas, content_rect);
75 if (geometry_->hasButtons(scrollbar_.get())) {
76 gfx::Rect back_button_start_paint_rect =
77 geometry_->backButtonStartRect(scrollbar_.get());
78 painter_.paintBackButtonStart(canvas, back_button_start_paint_rect);
80 gfx::Rect back_button_end_paint_rect =
81 geometry_->backButtonEndRect(scrollbar_.get());
82 painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect);
84 gfx::Rect forward_button_start_paint_rect =
85 geometry_->forwardButtonStartRect(scrollbar_.get());
86 painter_.paintForwardButtonStart(canvas,
87 forward_button_start_paint_rect);
89 gfx::Rect forward_button_end_paint_rect =
90 geometry_->forwardButtonEndRect(scrollbar_.get());
91 painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect);
94 gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get());
95 painter_.paintTrackBackground(canvas, track_paint_rect);
97 bool thumb_present = geometry_->hasThumb(scrollbar_.get());
98 if (thumb_present) {
99 painter_.paintForwardTrackPart(canvas, track_paint_rect);
100 painter_.paintBackTrackPart(canvas, track_paint_rect);
103 painter_.paintTickmarks(canvas, track_paint_rect);
106 } // namespace webkit