Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(108)

Side by Side Diff: ui/views/controls/scrollbar/overlay_scroll_bar.cc

Issue 16171010: Introduces a new scrollbar for message_center. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: GetVisibleSize -> GetContentOverlapSize Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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.
4
5 #include "ui/views/controls/scrollbar/overlay_scroll_bar.h"
6
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"
13
14 namespace views {
15 namespace {
16
17 const int kScrollbarWidth = 10;
18 const int kThumbInsetInside = 3;
19 const int kThumbInsetFromEdge = 1;
20 const int kThumbCornerRadius = 2;
21 const int kThumbMinimumSize = kScrollbarWidth;
22 const int kThumbHoverAlpha = 128;
23 const int kThumbDefaultAlpha = 64;
24
25 class OverlayScrollBarThumb : public BaseScrollBarThumb,
26 public ui::AnimationDelegate {
27 public:
28 explicit OverlayScrollBarThumb(BaseScrollBar* scroll_bar);
29 virtual ~OverlayScrollBarThumb();
30
31 protected:
32 // View overrides:
33 virtual gfx::Size GetPreferredSize() OVERRIDE;
34 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
35
36 // ui::AnimationDelegate overrides:
37 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE;
38
39 private:
40 double animation_opacity_;
41 DISALLOW_COPY_AND_ASSIGN(OverlayScrollBarThumb);
42 };
43
44 OverlayScrollBarThumb::OverlayScrollBarThumb(BaseScrollBar* scroll_bar)
45 : BaseScrollBarThumb(scroll_bar),
46 animation_opacity_(0.0) {
47 if (get_use_acceleration_when_possible()) {
48 // This is necessary, otherwise the thumb will be rendered below the views
49 // if those views paint to their own layers.
50 SetPaintToLayer(true);
51 SetFillsBoundsOpaquely(false);
52 }
53 }
54
55 OverlayScrollBarThumb::~OverlayScrollBarThumb() {
56 }
57
58 gfx::Size OverlayScrollBarThumb::GetPreferredSize() {
59 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize);
60 }
61
62 void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) {
63 gfx::Rect local_bounds(GetLocalBounds());
64 SkPaint paint;
65 int alpha = (GetState() == CustomButton::STATE_HOVERED ||
66 GetState() == CustomButton::STATE_PRESSED) ?
67 kThumbHoverAlpha : kThumbDefaultAlpha;
68 alpha *= animation_opacity_;
69 paint.setStyle(SkPaint::kFill_Style);
70 paint.setColor(SkColorSetARGB(alpha, 0, 0, 0));
71 canvas->DrawRoundRect(local_bounds, kThumbCornerRadius, paint);
72 }
73
74 void OverlayScrollBarThumb::AnimationProgressed(
75 const ui::Animation* animation) {
76 animation_opacity_ = animation->GetCurrentValue();
77 SchedulePaint();
78 }
79
80 } // namespace
81
82 OverlayScrollBar::OverlayScrollBar(bool horizontal)
83 : BaseScrollBar(horizontal, new OverlayScrollBarThumb(this)),
84 animation_(static_cast<OverlayScrollBarThumb*>(GetThumb())) {
85 set_notify_enter_exit_on_child(true);
86 }
87
88 OverlayScrollBar::~OverlayScrollBar() {
89 }
90
91 gfx::Rect OverlayScrollBar::GetTrackBounds() const {
92 gfx::Rect local_bounds(GetLocalBounds());
93 if (IsHorizontal()) {
94 local_bounds.Inset(kThumbInsetFromEdge, kThumbInsetInside,
95 kThumbInsetFromEdge, kThumbInsetFromEdge);
96 } else {
97 local_bounds.Inset(kThumbInsetInside, kThumbInsetFromEdge,
98 kThumbInsetFromEdge, kThumbInsetFromEdge);
99 }
100 gfx::Size track_size = local_bounds.size();
101 track_size.SetToMax(GetThumb()->size());
102 local_bounds.set_size(track_size);
103 return local_bounds;
104 }
105
106 int OverlayScrollBar::GetLayoutSize() const {
107 return 0;
108 }
109
110 int OverlayScrollBar::GetContentOverlapSize() const {
111 return kScrollbarWidth;
112 }
113
114 void OverlayScrollBar::OnMouseEnteredScrollView(const ui::MouseEvent& event) {
115 if (GetThumb()->layer())
116 animation_.Show();
117 else
118 GetThumb()->SetVisible(true);
119 }
120
121 void OverlayScrollBar::OnMouseExitedScrollView(const ui::MouseEvent& event) {
122 if (GetThumb()->layer())
123 animation_.Hide();
124 else
125 GetThumb()->SetVisible(false);
126 }
127
128 gfx::Size OverlayScrollBar::GetPreferredSize() {
129 return gfx::Size();
130 }
131
132 void OverlayScrollBar::Layout() {
133 gfx::Rect thumb_bounds = GetTrackBounds();
134 BaseScrollBarThumb* thumb = GetThumb();
135 if (IsHorizontal()) {
136 thumb_bounds.set_x(thumb->x());
137 thumb_bounds.set_width(thumb->width());
138 } else {
139 thumb_bounds.set_y(thumb->y());
140 thumb_bounds.set_height(thumb->height());
141 }
142 thumb->SetBoundsRect(thumb_bounds);
143 }
144
145 void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) {
146 }
147
148 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/controls/scrollbar/overlay_scroll_bar.h ('k') | ui/views/controls/scrollbar/scroll_bar.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698