| 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 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 OverlayScrollBarThumb::~OverlayScrollBarThumb() { | 55 OverlayScrollBarThumb::~OverlayScrollBarThumb() { |
| 56 } | 56 } |
| 57 | 57 |
| 58 gfx::Size OverlayScrollBarThumb::GetPreferredSize() { | 58 gfx::Size OverlayScrollBarThumb::GetPreferredSize() { |
| 59 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); | 59 return gfx::Size(kThumbMinimumSize, kThumbMinimumSize); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) { | 62 void OverlayScrollBarThumb::OnPaint(gfx::Canvas* canvas) { |
| 63 gfx::Rect local_bounds(GetLocalBounds()); | 63 gfx::Rect local_bounds(GetLocalBounds()); |
| 64 SkPaint paint; | 64 SkPaint paint; |
| 65 int alpha = (GetState() == CustomButton::STATE_HOVERED || | 65 int alpha = kThumbDefaultAlpha * animation_opacity_; |
| 66 GetState() == CustomButton::STATE_PRESSED) ? | 66 if (GetState() == CustomButton::STATE_HOVERED) { |
| 67 kThumbHoverAlpha : kThumbDefaultAlpha; | 67 alpha = kThumbHoverAlpha * animation_opacity_; |
| 68 alpha *= animation_opacity_; | 68 } else if(GetState() == CustomButton::STATE_PRESSED) { |
| 69 // If we are in pressed state, no need to worry about animation, |
| 70 // just display the deeper color. |
| 71 alpha = kThumbHoverAlpha; |
| 72 } |
| 73 |
| 69 paint.setStyle(SkPaint::kFill_Style); | 74 paint.setStyle(SkPaint::kFill_Style); |
| 70 paint.setColor(SkColorSetARGB(alpha, 0, 0, 0)); | 75 paint.setColor(SkColorSetARGB(alpha, 0, 0, 0)); |
| 71 canvas->DrawRoundRect(local_bounds, kThumbCornerRadius, paint); | 76 canvas->DrawRoundRect(local_bounds, kThumbCornerRadius, paint); |
| 72 } | 77 } |
| 73 | 78 |
| 74 void OverlayScrollBarThumb::AnimationProgressed( | 79 void OverlayScrollBarThumb::AnimationProgressed( |
| 75 const ui::Animation* animation) { | 80 const ui::Animation* animation) { |
| 76 animation_opacity_ = animation->GetCurrentValue(); | 81 animation_opacity_ = animation->GetCurrentValue(); |
| 77 SchedulePaint(); | 82 SchedulePaint(); |
| 78 } | 83 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 112 } | 117 } |
| 113 | 118 |
| 114 void OverlayScrollBar::OnMouseEnteredScrollView(const ui::MouseEvent& event) { | 119 void OverlayScrollBar::OnMouseEnteredScrollView(const ui::MouseEvent& event) { |
| 115 animation_.Show(); | 120 animation_.Show(); |
| 116 } | 121 } |
| 117 | 122 |
| 118 void OverlayScrollBar::OnMouseExitedScrollView(const ui::MouseEvent& event) { | 123 void OverlayScrollBar::OnMouseExitedScrollView(const ui::MouseEvent& event) { |
| 119 animation_.Hide(); | 124 animation_.Hide(); |
| 120 } | 125 } |
| 121 | 126 |
| 127 void OverlayScrollBar::OnGestureEvent(ui::GestureEvent* event) { |
| 128 switch (event->type()) { |
| 129 case ui::ET_GESTURE_SCROLL_BEGIN: |
| 130 animation_.Show(); |
| 131 break; |
| 132 case ui::ET_GESTURE_SCROLL_END: |
| 133 case ui::ET_SCROLL_FLING_START: |
| 134 case ui::ET_GESTURE_END: |
| 135 animation_.Hide(); |
| 136 break; |
| 137 default: |
| 138 break; |
| 139 } |
| 140 BaseScrollBar::OnGestureEvent(event); |
| 141 } |
| 142 |
| 122 gfx::Size OverlayScrollBar::GetPreferredSize() { | 143 gfx::Size OverlayScrollBar::GetPreferredSize() { |
| 123 return gfx::Size(); | 144 return gfx::Size(); |
| 124 } | 145 } |
| 125 | 146 |
| 126 void OverlayScrollBar::Layout() { | 147 void OverlayScrollBar::Layout() { |
| 127 gfx::Rect thumb_bounds = GetTrackBounds(); | 148 gfx::Rect thumb_bounds = GetTrackBounds(); |
| 128 BaseScrollBarThumb* thumb = GetThumb(); | 149 BaseScrollBarThumb* thumb = GetThumb(); |
| 129 if (IsHorizontal()) { | 150 if (IsHorizontal()) { |
| 130 thumb_bounds.set_x(thumb->x()); | 151 thumb_bounds.set_x(thumb->x()); |
| 131 thumb_bounds.set_width(thumb->width()); | 152 thumb_bounds.set_width(thumb->width()); |
| 132 } else { | 153 } else { |
| 133 thumb_bounds.set_y(thumb->y()); | 154 thumb_bounds.set_y(thumb->y()); |
| 134 thumb_bounds.set_height(thumb->height()); | 155 thumb_bounds.set_height(thumb->height()); |
| 135 } | 156 } |
| 136 thumb->SetBoundsRect(thumb_bounds); | 157 thumb->SetBoundsRect(thumb_bounds); |
| 137 } | 158 } |
| 138 | 159 |
| 139 void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) { | 160 void OverlayScrollBar::OnPaint(gfx::Canvas* canvas) { |
| 140 } | 161 } |
| 141 | 162 |
| 142 } // namespace views | 163 } // namespace views |
| OLD | NEW |