Home | History | Annotate | Download | only in compositor_bindings
      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, gfx::Rect content_rect) {
     67   if (part == cc::THUMB) {
     68     painter_.paintThumb(canvas, content_rect);
     69     return;
     70   }
     71 
     72   // The following is a simplification of ScrollbarThemeComposite::paint.
     73   painter_.paintScrollbarBackground(canvas, content_rect);
     74 
     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);
     79 
     80     gfx::Rect back_button_end_paint_rect =
     81         geometry_->backButtonEndRect(scrollbar_.get());
     82     painter_.paintBackButtonEnd(canvas, back_button_end_paint_rect);
     83 
     84     gfx::Rect forward_button_start_paint_rect =
     85         geometry_->forwardButtonStartRect(scrollbar_.get());
     86     painter_.paintForwardButtonStart(canvas,
     87                                       forward_button_start_paint_rect);
     88 
     89     gfx::Rect forward_button_end_paint_rect =
     90         geometry_->forwardButtonEndRect(scrollbar_.get());
     91     painter_.paintForwardButtonEnd(canvas, forward_button_end_paint_rect);
     92   }
     93 
     94   gfx::Rect track_paint_rect = geometry_->trackRect(scrollbar_.get());
     95   painter_.paintTrackBackground(canvas, track_paint_rect);
     96 
     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);
    101   }
    102 
    103   painter_.paintTickmarks(canvas, track_paint_rect);
    104 }
    105 
    106 }  // namespace webkit
    107