Add ICU message format support
[chromium-blink-merge.git] / ui / views / controls / scrollbar / kennedy_scroll_bar.cc
blobbd4e0a060fada704fce4edfdc239eec046c94e6e
1 // Copyright (c) 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 "ui/views/controls/scrollbar/kennedy_scroll_bar.h"
7 #include "third_party/skia/include/core/SkColor.h"
8 #include "third_party/skia/include/core/SkXfermode.h"
9 #include "ui/gfx/canvas.h"
10 #include "ui/views/background.h"
11 #include "ui/views/border.h"
12 #include "ui/views/controls/scrollbar/base_scroll_bar_thumb.h"
14 namespace views {
15 namespace {
17 const int kScrollbarWidth = 10;
18 const int kThumbMinimumSize = kScrollbarWidth * 2;
19 const SkColor kBorderColor = SkColorSetARGB(32, 0, 0, 0);
20 const SkColor kThumbHoverColor = SkColorSetARGB(128, 0, 0, 0);
21 const SkColor kThumbDefaultColor = SkColorSetARGB(64, 0, 0, 0);
22 const SkColor kTrackHoverColor = SkColorSetARGB(32, 0, 0, 0);
24 class KennedyScrollBarThumb : public BaseScrollBarThumb {
25 public:
26 explicit KennedyScrollBarThumb(BaseScrollBar* scroll_bar);
27 ~KennedyScrollBarThumb() override;
29 protected:
30 // View overrides:
31 gfx::Size GetPreferredSize() const override;
32 void OnPaint(gfx::Canvas* canvas) override;
34 private:
35 DISALLOW_COPY_AND_ASSIGN(KennedyScrollBarThumb);
38 KennedyScrollBarThumb::KennedyScrollBarThumb(BaseScrollBar* scroll_bar)
39 : BaseScrollBarThumb(scroll_bar) {
42 KennedyScrollBarThumb::~KennedyScrollBarThumb() {
45 gfx::Size KennedyScrollBarThumb::GetPreferredSize() const {
46 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize);
49 void KennedyScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
50 gfx::Rect local_bounds(GetLocalBounds());
51 canvas->FillRect(local_bounds,
52 (GetState() == CustomButton::STATE_HOVERED ||
53 GetState() == CustomButton::STATE_PRESSED) ?
54 kThumbHoverColor : kThumbDefaultColor);
55 canvas->DrawRect(local_bounds, kBorderColor);
58 } // namespace
60 KennedyScrollBar::KennedyScrollBar(bool horizontal)
61 : BaseScrollBar(horizontal, new KennedyScrollBarThumb(this)) {
62 set_notify_enter_exit_on_child(true);
65 KennedyScrollBar::~KennedyScrollBar() {
68 gfx::Rect KennedyScrollBar::GetTrackBounds() const {
69 gfx::Rect local_bounds(GetLocalBounds());
70 gfx::Size track_size = local_bounds.size();
71 track_size.SetToMax(GetThumb()->size());
72 local_bounds.set_size(track_size);
73 return local_bounds;
76 int KennedyScrollBar::GetLayoutSize() const {
77 return kScrollbarWidth;
80 gfx::Size KennedyScrollBar::GetPreferredSize() const {
81 return GetTrackBounds().size();
84 void KennedyScrollBar::Layout() {
85 gfx::Rect thumb_bounds = GetTrackBounds();
86 BaseScrollBarThumb* thumb = GetThumb();
87 if (IsHorizontal()) {
88 thumb_bounds.set_x(thumb->x());
89 thumb_bounds.set_width(thumb->width());
90 } else {
91 thumb_bounds.set_y(thumb->y());
92 thumb_bounds.set_height(thumb->height());
94 thumb->SetBoundsRect(thumb_bounds);
97 void KennedyScrollBar::OnPaint(gfx::Canvas* canvas) {
98 CustomButton::ButtonState state = GetThumbTrackState();
99 if ((state == CustomButton::STATE_HOVERED) ||
100 (state == CustomButton::STATE_PRESSED)) {
101 gfx::Rect local_bounds(GetLocalBounds());
102 canvas->FillRect(local_bounds, kTrackHoverColor);
103 canvas->DrawRect(local_bounds, kBorderColor);
107 } // namespace views