OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ui/views/controls/scrollbar/kennedy_scroll_bar.h" | 5 #include "ui/views/controls/scrollbar/kennedy_scroll_bar.h" |
6 | 6 |
7 #include "third_party/skia/include/core/SkColor.h" | 7 #include "third_party/skia/include/core/SkColor.h" |
8 #include "third_party/skia/include/core/SkXfermode.h" | 8 #include "third_party/skia/include/core/SkXfermode.h" |
9 #include "ui/gfx/canvas.h" | 9 #include "ui/gfx/canvas.h" |
10 #include "ui/views/background.h" | 10 #include "ui/views/background.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 const SkColor kThumbDefaultColor = SkColorSetARGB(64, 0, 0, 0); | 21 const SkColor kThumbDefaultColor = SkColorSetARGB(64, 0, 0, 0); |
22 const SkColor kTrackHoverColor = SkColorSetARGB(32, 0, 0, 0); | 22 const SkColor kTrackHoverColor = SkColorSetARGB(32, 0, 0, 0); |
23 | 23 |
24 class KennedyScrollBarThumb : public BaseScrollBarThumb { | 24 class KennedyScrollBarThumb : public BaseScrollBarThumb { |
25 public: | 25 public: |
26 explicit KennedyScrollBarThumb(BaseScrollBar* scroll_bar); | 26 explicit KennedyScrollBarThumb(BaseScrollBar* scroll_bar); |
27 virtual ~KennedyScrollBarThumb(); | 27 virtual ~KennedyScrollBarThumb(); |
28 | 28 |
29 protected: | 29 protected: |
30 // View overrides: | 30 // View overrides: |
31 virtual gfx::Size GetPreferredSize() OVERRIDE; | 31 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
32 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 32 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
33 | 33 |
34 private: | 34 private: |
35 DISALLOW_COPY_AND_ASSIGN(KennedyScrollBarThumb); | 35 DISALLOW_COPY_AND_ASSIGN(KennedyScrollBarThumb); |
36 }; | 36 }; |
37 | 37 |
38 KennedyScrollBarThumb::KennedyScrollBarThumb(BaseScrollBar* scroll_bar) | 38 KennedyScrollBarThumb::KennedyScrollBarThumb(BaseScrollBar* scroll_bar) |
39 : BaseScrollBarThumb(scroll_bar) { | 39 : BaseScrollBarThumb(scroll_bar) { |
40 } | 40 } |
41 | 41 |
42 KennedyScrollBarThumb::~KennedyScrollBarThumb() { | 42 KennedyScrollBarThumb::~KennedyScrollBarThumb() { |
43 } | 43 } |
44 | 44 |
45 gfx::Size KennedyScrollBarThumb::GetPreferredSize() { | 45 gfx::Size KennedyScrollBarThumb::GetPreferredSize() const { |
46 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); | 46 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); |
47 } | 47 } |
48 | 48 |
49 void KennedyScrollBarThumb::OnPaint(gfx::Canvas* canvas) { | 49 void KennedyScrollBarThumb::OnPaint(gfx::Canvas* canvas) { |
50 gfx::Rect local_bounds(GetLocalBounds()); | 50 gfx::Rect local_bounds(GetLocalBounds()); |
51 canvas->FillRect(local_bounds, | 51 canvas->FillRect(local_bounds, |
52 (GetState() == CustomButton::STATE_HOVERED || | 52 (GetState() == CustomButton::STATE_HOVERED || |
53 GetState() == CustomButton::STATE_PRESSED) ? | 53 GetState() == CustomButton::STATE_PRESSED) ? |
54 kThumbHoverColor : kThumbDefaultColor); | 54 kThumbHoverColor : kThumbDefaultColor); |
55 canvas->DrawRect(local_bounds, kBorderColor); | 55 canvas->DrawRect(local_bounds, kBorderColor); |
(...skipping 14 matching lines...) Expand all Loading... |
70 gfx::Size track_size = local_bounds.size(); | 70 gfx::Size track_size = local_bounds.size(); |
71 track_size.SetToMax(GetThumb()->size()); | 71 track_size.SetToMax(GetThumb()->size()); |
72 local_bounds.set_size(track_size); | 72 local_bounds.set_size(track_size); |
73 return local_bounds; | 73 return local_bounds; |
74 } | 74 } |
75 | 75 |
76 int KennedyScrollBar::GetLayoutSize() const { | 76 int KennedyScrollBar::GetLayoutSize() const { |
77 return kScrollbarWidth; | 77 return kScrollbarWidth; |
78 } | 78 } |
79 | 79 |
80 gfx::Size KennedyScrollBar::GetPreferredSize() { | 80 gfx::Size KennedyScrollBar::GetPreferredSize() const { |
81 return GetTrackBounds().size(); | 81 return GetTrackBounds().size(); |
82 } | 82 } |
83 | 83 |
84 void KennedyScrollBar::Layout() { | 84 void KennedyScrollBar::Layout() { |
85 gfx::Rect thumb_bounds = GetTrackBounds(); | 85 gfx::Rect thumb_bounds = GetTrackBounds(); |
86 BaseScrollBarThumb* thumb = GetThumb(); | 86 BaseScrollBarThumb* thumb = GetThumb(); |
87 if (IsHorizontal()) { | 87 if (IsHorizontal()) { |
88 thumb_bounds.set_x(thumb->x()); | 88 thumb_bounds.set_x(thumb->x()); |
89 thumb_bounds.set_width(thumb->width()); | 89 thumb_bounds.set_width(thumb->width()); |
90 } else { | 90 } else { |
91 thumb_bounds.set_y(thumb->y()); | 91 thumb_bounds.set_y(thumb->y()); |
92 thumb_bounds.set_height(thumb->height()); | 92 thumb_bounds.set_height(thumb->height()); |
93 } | 93 } |
94 thumb->SetBoundsRect(thumb_bounds); | 94 thumb->SetBoundsRect(thumb_bounds); |
95 } | 95 } |
96 | 96 |
97 void KennedyScrollBar::OnPaint(gfx::Canvas* canvas) { | 97 void KennedyScrollBar::OnPaint(gfx::Canvas* canvas) { |
98 CustomButton::ButtonState state = GetThumbTrackState(); | 98 CustomButton::ButtonState state = GetThumbTrackState(); |
99 if ((state == CustomButton::STATE_HOVERED) || | 99 if ((state == CustomButton::STATE_HOVERED) || |
100 (state == CustomButton::STATE_PRESSED)) { | 100 (state == CustomButton::STATE_PRESSED)) { |
101 gfx::Rect local_bounds(GetLocalBounds()); | 101 gfx::Rect local_bounds(GetLocalBounds()); |
102 canvas->FillRect(local_bounds, kTrackHoverColor); | 102 canvas->FillRect(local_bounds, kTrackHoverColor); |
103 canvas->DrawRect(local_bounds, kBorderColor); | 103 canvas->DrawRect(local_bounds, kBorderColor); |
104 } | 104 } |
105 } | 105 } |
106 | 106 |
107 } // namespace views | 107 } // namespace views |
OLD | NEW |