| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #import "ui/views/controls/scrollbar/cocoa_scroll_bar.h" | 5 #import "ui/views/controls/scrollbar/cocoa_scroll_bar.h" |
| 6 | 6 |
| 7 #import "base/mac/sdk_forward_declarations.h" | 7 #import "base/mac/sdk_forward_declarations.h" |
| 8 #include "third_party/skia/include/core/SkColor.h" | 8 #include "third_party/skia/include/core/SkColor.h" |
| 9 #include "third_party/skia/include/effects/SkGradientShader.h" | 9 #include "third_party/skia/include/effects/SkGradientShader.h" |
| 10 #include "ui/compositor/layer.h" | 10 #include "ui/compositor/layer.h" |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 115 | 115 |
| 116 void CocoaScrollBarThumb::OnPaint(gfx::Canvas* canvas) { | 116 void CocoaScrollBarThumb::OnPaint(gfx::Canvas* canvas) { |
| 117 SkColor thumb_color = kScrollerDefaultThumbColor; | 117 SkColor thumb_color = kScrollerDefaultThumbColor; |
| 118 if (cocoa_scroll_bar()->GetScrollerStyle() == NSScrollerStyleOverlay || | 118 if (cocoa_scroll_bar()->GetScrollerStyle() == NSScrollerStyleOverlay || |
| 119 IsStateHovered() || | 119 IsStateHovered() || |
| 120 IsStatePressed()) { | 120 IsStatePressed()) { |
| 121 thumb_color = kScrollerHoverThumbColor; | 121 thumb_color = kScrollerHoverThumbColor; |
| 122 } | 122 } |
| 123 | 123 |
| 124 gfx::Rect local_bounds(GetLocalBounds()); | 124 gfx::Rect local_bounds(GetLocalBounds()); |
| 125 cc::PaintFlags paint; | 125 cc::PaintFlags flags; |
| 126 paint.setAntiAlias(true); | 126 flags.setAntiAlias(true); |
| 127 paint.setStyle(cc::PaintFlags::kFill_Style); | 127 flags.setStyle(cc::PaintFlags::kFill_Style); |
| 128 paint.setColor(thumb_color); | 128 flags.setColor(thumb_color); |
| 129 const SkScalar radius = | 129 const SkScalar radius = |
| 130 std::min(local_bounds.width(), local_bounds.height()); | 130 std::min(local_bounds.width(), local_bounds.height()); |
| 131 canvas->DrawRoundRect(local_bounds, radius, paint); | 131 canvas->DrawRoundRect(local_bounds, radius, flags); |
| 132 } | 132 } |
| 133 | 133 |
| 134 bool CocoaScrollBarThumb::OnMousePressed(const ui::MouseEvent& event) { | 134 bool CocoaScrollBarThumb::OnMousePressed(const ui::MouseEvent& event) { |
| 135 // Ignore the mouse press if the scrollbar is hidden. | 135 // Ignore the mouse press if the scrollbar is hidden. |
| 136 if (cocoa_scroll_bar()->IsScrollbarFullyHidden()) | 136 if (cocoa_scroll_bar()->IsScrollbarFullyHidden()) |
| 137 return false; | 137 return false; |
| 138 | 138 |
| 139 return BaseScrollBarThumb::OnMousePressed(event); | 139 return BaseScrollBarThumb::OnMousePressed(event); |
| 140 } | 140 } |
| 141 | 141 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 gradient_bounds[0].set(track_rect.x(), track_rect.y()); | 256 gradient_bounds[0].set(track_rect.x(), track_rect.y()); |
| 257 gradient_bounds[1].set(track_rect.right(), track_rect.y()); | 257 gradient_bounds[1].set(track_rect.right(), track_rect.y()); |
| 258 } | 258 } |
| 259 cc::PaintFlags gradient; | 259 cc::PaintFlags gradient; |
| 260 gradient.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( | 260 gradient.setShader(cc::WrapSkShader(SkGradientShader::MakeLinear( |
| 261 gradient_bounds, kScrollerTrackGradientColors, nullptr, | 261 gradient_bounds, kScrollerTrackGradientColors, nullptr, |
| 262 arraysize(kScrollerTrackGradientColors), SkShader::kClamp_TileMode))); | 262 arraysize(kScrollerTrackGradientColors), SkShader::kClamp_TileMode))); |
| 263 canvas->DrawRect(track_rect, gradient); | 263 canvas->DrawRect(track_rect, gradient); |
| 264 | 264 |
| 265 // Draw the inner border: top if horizontal, left if vertical. | 265 // Draw the inner border: top if horizontal, left if vertical. |
| 266 cc::PaintFlags paint; | 266 cc::PaintFlags flags; |
| 267 paint.setColor(kScrollerTrackInnerBorderColor); | 267 flags.setColor(kScrollerTrackInnerBorderColor); |
| 268 gfx::Rect inner_border(track_rect); | 268 gfx::Rect inner_border(track_rect); |
| 269 if (IsHorizontal()) | 269 if (IsHorizontal()) |
| 270 inner_border.set_height(kScrollerTrackBorderWidth); | 270 inner_border.set_height(kScrollerTrackBorderWidth); |
| 271 else | 271 else |
| 272 inner_border.set_width(kScrollerTrackBorderWidth); | 272 inner_border.set_width(kScrollerTrackBorderWidth); |
| 273 canvas->DrawRect(inner_border, paint); | 273 canvas->DrawRect(inner_border, flags); |
| 274 | 274 |
| 275 // Draw the outer border: bottom if horizontal, right if veritcal. | 275 // Draw the outer border: bottom if horizontal, right if veritcal. |
| 276 paint.setColor(kScrollerTrackOuterBorderColor); | 276 flags.setColor(kScrollerTrackOuterBorderColor); |
| 277 gfx::Rect outer_border(inner_border); | 277 gfx::Rect outer_border(inner_border); |
| 278 if (IsHorizontal()) | 278 if (IsHorizontal()) |
| 279 outer_border.set_y(track_rect.bottom()); | 279 outer_border.set_y(track_rect.bottom()); |
| 280 else | 280 else |
| 281 outer_border.set_x(track_rect.right()); | 281 outer_border.set_x(track_rect.right()); |
| 282 canvas->DrawRect(outer_border, paint); | 282 canvas->DrawRect(outer_border, flags); |
| 283 } | 283 } |
| 284 | 284 |
| 285 bool CocoaScrollBar::OnMousePressed(const ui::MouseEvent& event) { | 285 bool CocoaScrollBar::OnMousePressed(const ui::MouseEvent& event) { |
| 286 // Ignore the mouse press if the scrollbar is hidden. | 286 // Ignore the mouse press if the scrollbar is hidden. |
| 287 if (IsScrollbarFullyHidden()) | 287 if (IsScrollbarFullyHidden()) |
| 288 return false; | 288 return false; |
| 289 | 289 |
| 290 return BaseScrollBar::OnMousePressed(event); | 290 return BaseScrollBar::OnMousePressed(event); |
| 291 } | 291 } |
| 292 | 292 |
| (...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 536 CocoaScrollBarThumb* CocoaScrollBar::GetCocoaScrollBarThumb() const { | 536 CocoaScrollBarThumb* CocoaScrollBar::GetCocoaScrollBarThumb() const { |
| 537 return static_cast<CocoaScrollBarThumb*>(GetThumb()); | 537 return static_cast<CocoaScrollBarThumb*>(GetThumb()); |
| 538 } | 538 } |
| 539 | 539 |
| 540 // static | 540 // static |
| 541 base::Timer* BaseScrollBar::GetHideTimerForTest(BaseScrollBar* scroll_bar) { | 541 base::Timer* BaseScrollBar::GetHideTimerForTest(BaseScrollBar* scroll_bar) { |
| 542 return &static_cast<CocoaScrollBar*>(scroll_bar)->hide_scrollbar_timer_; | 542 return &static_cast<CocoaScrollBar*>(scroll_bar)->hide_scrollbar_timer_; |
| 543 } | 543 } |
| 544 | 544 |
| 545 } // namespace views | 545 } // namespace views |
| OLD | NEW |