Home | History | Annotate | Download | only in test
      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 "cc/test/fake_scrollbar.h"
      6 
      7 #include "third_party/skia/include/core/SkCanvas.h"
      8 #include "ui/gfx/skia_util.h"
      9 
     10 namespace cc {
     11 
     12 FakeScrollbar::FakeScrollbar()
     13     : paint_(false),
     14       has_thumb_(false),
     15       is_overlay_(false),
     16       thumb_thickness_(10),
     17       thumb_length_(5),
     18       track_rect_(0, 0, 100, 10),
     19       fill_color_(SK_ColorGREEN) {}
     20 
     21 FakeScrollbar::FakeScrollbar(bool paint, bool has_thumb, bool is_overlay)
     22     : paint_(paint),
     23       has_thumb_(has_thumb),
     24       is_overlay_(is_overlay),
     25       thumb_thickness_(10),
     26       thumb_length_(5),
     27       track_rect_(0, 0, 100, 10),
     28       fill_color_(SK_ColorGREEN) {}
     29 
     30 FakeScrollbar::~FakeScrollbar() {}
     31 
     32 ScrollbarOrientation FakeScrollbar::Orientation() const {
     33   return HORIZONTAL;
     34 }
     35 
     36 bool FakeScrollbar::IsLeftSideVerticalScrollbar() const {
     37   return false;
     38 }
     39 
     40 gfx::Point FakeScrollbar::Location() const { return location_; }
     41 
     42 bool FakeScrollbar::IsOverlay() const { return is_overlay_; }
     43 
     44 bool FakeScrollbar::HasThumb() const { return has_thumb_; }
     45 
     46 int FakeScrollbar::ThumbThickness() const {
     47   return thumb_thickness_;
     48 }
     49 
     50 int FakeScrollbar::ThumbLength() const {
     51   return thumb_length_;
     52 }
     53 
     54 gfx::Rect FakeScrollbar::TrackRect() const {
     55   return track_rect_;
     56 }
     57 
     58 void FakeScrollbar::PaintPart(SkCanvas* canvas,
     59                              ScrollbarPart part,
     60                              const gfx::Rect& content_rect) {
     61   if (!paint_)
     62     return;
     63 
     64   // Fill the scrollbar with a different color each time.
     65   fill_color_++;
     66   SkPaint paint;
     67   paint.setAntiAlias(false);
     68   paint.setColor(paint_fill_color());
     69   paint.setStyle(SkPaint::kFill_Style);
     70 
     71   // Emulate the how the real scrollbar works by using scrollbar's rect for
     72   // TRACK and the given content_rect for the THUMB
     73   SkRect rect = part == TRACK ? RectToSkRect(TrackRect())
     74                               : RectToSkRect(content_rect);
     75   canvas->drawRect(rect, paint);
     76 }
     77 
     78 }  // namespace cc
     79