| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/overlay_scroll_bar.h" | 5 #include "ui/views/controls/scrollbar/overlay_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 12 matching lines...) Expand all Loading... |
| 23 const int kThumbDefaultAlpha = 64; | 23 const int kThumbDefaultAlpha = 64; |
| 24 | 24 |
| 25 class OverlayScrollBarThumb : public BaseScrollBarThumb, | 25 class OverlayScrollBarThumb : public BaseScrollBarThumb, |
| 26 public gfx::AnimationDelegate { | 26 public gfx::AnimationDelegate { |
| 27 public: | 27 public: |
| 28 explicit OverlayScrollBarThumb(BaseScrollBar* scroll_bar); | 28 explicit OverlayScrollBarThumb(BaseScrollBar* scroll_bar); |
| 29 virtual ~OverlayScrollBarThumb(); | 29 virtual ~OverlayScrollBarThumb(); |
| 30 | 30 |
| 31 protected: | 31 protected: |
| 32 // View overrides: | 32 // View overrides: |
| 33 virtual gfx::Size GetPreferredSize() OVERRIDE; | 33 virtual gfx::Size GetPreferredSize() const OVERRIDE; |
| 34 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; | 34 virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE; |
| 35 | 35 |
| 36 // gfx::AnimationDelegate overrides: | 36 // gfx::AnimationDelegate overrides: |
| 37 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; | 37 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
| 38 | 38 |
| 39 private: | 39 private: |
| 40 double animation_opacity_; | 40 double animation_opacity_; |
| 41 DISALLOW_COPY_AND_ASSIGN(OverlayScrollBarThumb); | 41 DISALLOW_COPY_AND_ASSIGN(OverlayScrollBarThumb); |
| 42 }; | 42 }; |
| 43 | 43 |
| 44 OverlayScrollBarThumb::OverlayScrollBarThumb(BaseScrollBar* scroll_bar) | 44 OverlayScrollBarThumb::OverlayScrollBarThumb(BaseScrollBar* scroll_bar) |
| 45 : BaseScrollBarThumb(scroll_bar), | 45 : BaseScrollBarThumb(scroll_bar), |
| 46 animation_opacity_(0.0) { | 46 animation_opacity_(0.0) { |
| 47 // This is necessary, otherwise the thumb will be rendered below the views if | 47 // This is necessary, otherwise the thumb will be rendered below the views if |
| 48 // those views paint to their own layers. | 48 // those views paint to their own layers. |
| 49 SetPaintToLayer(true); | 49 SetPaintToLayer(true); |
| 50 SetFillsBoundsOpaquely(false); | 50 SetFillsBoundsOpaquely(false); |
| 51 } | 51 } |
| 52 | 52 |
| 53 OverlayScrollBarThumb::~OverlayScrollBarThumb() { | 53 OverlayScrollBarThumb::~OverlayScrollBarThumb() { |
| 54 } | 54 } |
| 55 | 55 |
| 56 gfx::Size OverlayScrollBarThumb::GetPreferredSize() { | 56 gfx::Size OverlayScrollBarThumb::GetPreferredSize() const { |
| 57 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); | 57 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); |
| 58 } | 58 } |
| 59 | 59 |
| 60 void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) { | 60 void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) { |
| 61 gfx::Rect local_bounds(GetLocalBounds()); | 61 gfx::Rect local_bounds(GetLocalBounds()); |
| 62 SkPaint paint; | 62 SkPaint paint; |
| 63 int alpha = kThumbDefaultAlpha * animation_opacity_; | 63 int alpha = kThumbDefaultAlpha * animation_opacity_; |
| 64 if (GetState() == CustomButton::STATE_HOVERED) { | 64 if (GetState() == CustomButton::STATE_HOVERED) { |
| 65 alpha = kThumbHoverAlpha * animation_opacity_; | 65 alpha = kThumbHoverAlpha * animation_opacity_; |
| 66 } else if(GetState() == CustomButton::STATE_PRESSED) { | 66 } else if(GetState() == CustomButton::STATE_PRESSED) { |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 case ui::ET_SCROLL_FLING_START: | 131 case ui::ET_SCROLL_FLING_START: |
| 132 case ui::ET_GESTURE_END: | 132 case ui::ET_GESTURE_END: |
| 133 animation_.Hide(); | 133 animation_.Hide(); |
| 134 break; | 134 break; |
| 135 default: | 135 default: |
| 136 break; | 136 break; |
| 137 } | 137 } |
| 138 BaseScrollBar::OnGestureEvent(event); | 138 BaseScrollBar::OnGestureEvent(event); |
| 139 } | 139 } |
| 140 | 140 |
| 141 gfx::Size OverlayScrollBar::GetPreferredSize() { | 141 gfx::Size OverlayScrollBar::GetPreferredSize() const { |
| 142 return gfx::Size(); | 142 return gfx::Size(); |
| 143 } | 143 } |
| 144 | 144 |
| 145 void OverlayScrollBar::Layout() { | 145 void OverlayScrollBar::Layout() { |
| 146 gfx::Rect thumb_bounds = GetTrackBounds(); | 146 gfx::Rect thumb_bounds = GetTrackBounds(); |
| 147 BaseScrollBarThumb* thumb = GetThumb(); | 147 BaseScrollBarThumb* thumb = GetThumb(); |
| 148 if (IsHorizontal()) { | 148 if (IsHorizontal()) { |
| 149 thumb_bounds.set_x(thumb->x()); | 149 thumb_bounds.set_x(thumb->x()); |
| 150 thumb_bounds.set_width(thumb->width()); | 150 thumb_bounds.set_width(thumb->width()); |
| 151 } else { | 151 } else { |
| 152 thumb_bounds.set_y(thumb->y()); | 152 thumb_bounds.set_y(thumb->y()); |
| 153 thumb_bounds.set_height(thumb->height()); | 153 thumb_bounds.set_height(thumb->height()); |
| 154 } | 154 } |
| 155 thumb->SetBoundsRect(thumb_bounds); | 155 thumb->SetBoundsRect(thumb_bounds); |
| 156 } | 156 } |
| 157 | 157 |
| 158 void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) { | 158 void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) { |
| 159 } | 159 } |
| 160 | 160 |
| 161 } // namespace views | 161 } // namespace views |
| OLD | NEW |