| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include "content/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 content { | |
| 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 | |
| 24 ScrollbarImpl::~ScrollbarImpl() { | |
| 25 } | |
| 26 | |
| 27 cc::ScrollbarOrientation ScrollbarImpl::Orientation() const { | |
| 28 if (scrollbar_->orientation() == WebScrollbar::Horizontal) | |
| 29 return cc::HORIZONTAL; | |
| 30 return cc::VERTICAL; | |
| 31 } | |
| 32 | |
| 33 bool ScrollbarImpl::IsLeftSideVerticalScrollbar() const { | |
| 34 return scrollbar_->isLeftSideVerticalScrollbar(); | |
| 35 } | |
| 36 | |
| 37 bool ScrollbarImpl::HasThumb() const { | |
| 38 return geometry_->hasThumb(scrollbar_.get()); | |
| 39 } | |
| 40 | |
| 41 bool ScrollbarImpl::IsOverlay() const { | |
| 42 return scrollbar_->isOverlay(); | |
| 43 } | |
| 44 | |
| 45 gfx::Point ScrollbarImpl::Location() const { | |
| 46 return scrollbar_->location(); | |
| 47 } | |
| 48 | |
| 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(); | |
| 54 } | |
| 55 | |
| 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(); | |
| 61 } | |
| 62 | |
| 63 gfx::Rect ScrollbarImpl::TrackRect() const { | |
| 64 return geometry_->trackRect(scrollbar_.get()); | |
| 65 } | |
| 66 | |
| 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; | |
| 73 } | |
| 74 | |
| 75 // The following is a simplification of ScrollbarThemeComposite::paint. | |
| 76 painter_.paintScrollbarBackground(canvas, content_rect); | |
| 77 | |
| 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); | |
| 82 | |
| 83 gfx::Rect back_button_end_paint_rect = | |
| 84 geometry_->backButtonEndRect(scrollbar_.get()); | |
| 85 painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect); | |
| 86 | |
| 87 gfx::Rect forward_button_start_paint_rect = | |
| 88 geometry_->forwardButtonStartRect(scrollbar_.get()); | |
| 89 painter_.paintForwardButtonStart(canvas, forward_button_start_paint_rect); | |
| 90 | |
| 91 gfx::Rect forward_button_end_paint_rect = | |
| 92 geometry_->forwardButtonEndRect(scrollbar_.get()); | |
| 93 painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect); | |
| 94 } | |
| 95 | |
| 96 gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get()); | |
| 97 painter_.paintTrackBackground(canvas, track_paint_rect); | |
| 98 | |
| 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); | |
| 103 } | |
| 104 | |
| 105 painter_.paintTickmarks(canvas, track_paint_rect); | |
| 106 } | |
| 107 | |
| 108 } // namespace content | |
| 109 | |
| OLD | NEW |