Chromium Code Reviews| Index: cc/input/viewport_scrollbar.cc |
| diff --git a/cc/input/viewport_scrollbar.cc b/cc/input/viewport_scrollbar.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..9441ae250065ed2b7ce0aac7a4444015de9e2686 |
| --- /dev/null |
| +++ b/cc/input/viewport_scrollbar.cc |
| @@ -0,0 +1,89 @@ |
| +// Copyright 2013 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "cc/input/viewport_scrollbar.h" |
| + |
| +#include "cc/layers/layer.h" |
| +#include "third_party/skia/include/core/SkCanvas.h" |
| + |
| +namespace cc { |
| + |
| +ViewportScrollbar::ViewportScrollbar(scoped_refptr<Layer> scroll_layer, |
| + ScrollbarOrientation orientation, |
| + size_t thickness) |
| + : scroll_layer_(scroll_layer), |
| + orientation_(orientation), |
| + thickness_(thickness) {} |
| + |
| +ViewportScrollbar::~ViewportScrollbar() {} |
| + |
| +ScrollbarOrientation ViewportScrollbar::Orientation() const { |
| + return orientation_; |
| +} |
| + |
| +gfx::Point ViewportScrollbar::Location() const { |
| + return gfx::Point(); |
| +} |
| + |
| +bool ViewportScrollbar::IsOverlay() const { |
| + return true; |
| +} |
| + |
| +bool ViewportScrollbar::HasThumb() const { |
| + return true; |
| +} |
| + |
| +int ViewportScrollbar::ThumbThickness() const { |
| + return thickness_; |
| +} |
| + |
| +int ViewportScrollbar::ThumbLength() const { |
| + gfx::Rect track_rect = TrackRect(); |
| + if (orientation_ == HORIZONTAL) { |
| + float ratio = static_cast<float>(track_rect.width()) / |
| + scroll_layer_->bounds().width(); |
| + return track_rect.width() - ratio * scroll_layer_->max_scroll_offset().x(); |
| + } else { |
| + float ratio = static_cast<float>(track_rect.height()) / |
| + scroll_layer_->bounds().height(); |
| + return track_rect.height() - ratio * scroll_layer_->max_scroll_offset().y(); |
| + } |
| +} |
| + |
| +gfx::Rect ViewportScrollbar::TrackRect() const { |
| + if (orientation_ == HORIZONTAL) |
| + return gfx::Rect( |
| + 0, 0, scroll_layer_->bounds().width() - thickness_, thickness_); |
| + else |
| + return gfx::Rect( |
| + 0, 0, thickness_, scroll_layer_->bounds().height() - thickness_); |
| +} |
| + |
| +void ViewportScrollbar::PaintPart(SkCanvas* canvas, |
| + ScrollbarPart part, |
| + gfx::Rect content_rect) { |
| + if (part != THUMB) |
| + return; |
| + |
| + canvas->clear(SkColorSetARGB(0, 0, 0, 0)); |
| + |
| + // TODO(wjmaclean): currently the pinch zoom overlay scrollbars are drawn as |
|
enne (OOO)
2013/06/14 20:56:59
How are you going to differentiate this PaintPart
wjmaclean
2013/06/17 13:44:28
Based on my conversations with JamesR, the simples
enne (OOO)
2013/06/17 18:05:12
I'd prefer ViewportScrollbar having an empty imple
|
| + // grey, but need to check this with UX design. |
| + SkPaint paint; |
| + paint.setColor(SkColorSetARGB(128, 32, 32, 32)); |
| + |
| + // If the scrollbar thickness is sufficient, provide a border around the thumb |
| + // and round its corners. |
| + const int min_thickness_for_borders = 8; |
| + const SkScalar border = thickness_ >= min_thickness_for_borders ? 2 : 0; |
| + const SkScalar corner_radius = |
| + thickness_ >= min_thickness_for_borders ? 2 : 0; |
| + |
| + SkRect rect = SkRect::MakeXYWH(border, border, |
| + content_rect.width() - 2 * border, |
| + content_rect.height() - 2 * border); |
| + canvas->drawRoundRect(rect, corner_radius, corner_radius, paint); |
| +} |
| + |
| +} // namespace cc |