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

Unified Diff: ui/native_theme/native_theme_aura.cc

Issue 2421913002: Change Aura overlay scrollbars from solid color to painted scrollbars. (Closed)
Patch Set: Move ad-hoc MD scrollbar constants into central location. Created 4 years, 2 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 side-by-side diff with in-line comments
Download patch
Index: ui/native_theme/native_theme_aura.cc
diff --git a/ui/native_theme/native_theme_aura.cc b/ui/native_theme/native_theme_aura.cc
index b6f47d402f4dc490dfe68bef799182ec07f9ac7e..6afcbb25bcd330d34559247033c324c832650dd3 100644
--- a/ui/native_theme/native_theme_aura.cc
+++ b/ui/native_theme/native_theme_aura.cc
@@ -20,6 +20,7 @@
#include "ui/gfx/path.h"
#include "ui/gfx/skia_util.h"
#include "ui/native_theme/common_theme.h"
+#include "ui/native_theme/material_design_constants.h"
#include "ui/native_theme/native_theme_switches.h"
namespace ui {
@@ -32,11 +33,11 @@ SkAlpha ThumbAlphaForState(NativeTheme::State state) {
case NativeTheme::kDisabled:
return 0x00;
case NativeTheme::kHovered:
- return overlay ? 0xB2 : 0x4D;
+ return overlay ? kMDScrollbarAlphaHovered : 0x4D;
case NativeTheme::kNormal:
- return overlay ? 0x8C : 0x33;
+ return overlay ? kMDScrollbarAlphaNormal : 0x33;
case NativeTheme::kPressed:
- return overlay ? 0xB2 : 0x80;
+ return overlay ? kMDScrollbarAlphaPressed : 0x80;
case NativeTheme::kNumStates:
break;
}
@@ -51,10 +52,11 @@ SkAlpha ThumbStrokeAlphaForState(NativeTheme::State state) {
case NativeTheme::kDisabled:
return 0x00;
case NativeTheme::kHovered:
+ return kMDScrollbarAlphaHovered;
case NativeTheme::kPressed:
- return 0x33;
+ return kMDScrollbarAlphaPressed;
case NativeTheme::kNormal:
- return 0x26;
+ return kMDScrollbarAlphaNormal;
case NativeTheme::kNumStates:
break;
}
@@ -84,6 +86,11 @@ NativeThemeAura::NativeThemeAura() {
set_scrollbar_button_length(0);
#endif
+ if (IsOverlayScrollbarEnabled()) {
+ scrollbar_width_ =
+ kMDScrollbarThumbWidthPressed + kMDScrollbarStrokeWidth * 2;
+ }
+
// Images and alphas declarations assume the following order.
static_assert(kDisabled == 0, "states unexpectedly changed");
static_assert(kHovered == 1, "states unexpectedly changed");
@@ -197,19 +204,28 @@ void NativeThemeAura::PaintScrollbarThumbStateTransition(
double progress,
const gfx::Rect& rect) const {
gfx::Rect thumb_rect(rect);
+ SkColor thumb_color;
if (IsOverlayScrollbarEnabled()) {
// In overlay mode, draw a stroke (border).
- const int kStrokeWidth = 1;
+ const int kStrokeWidth = kMDScrollbarStrokeWidth;
Peter Kasting 2016/10/17 19:10:25 Nit: Can be constexpr
bokan 2016/10/17 23:21:03 Done.
SkAlpha stroke_alpha = gfx::Tween::IntValueBetween(
progress, ThumbStrokeAlphaForState(start_state),
ThumbStrokeAlphaForState(end_state));
SkPaint paint;
- paint.setColor(SkColorSetA(SK_ColorWHITE, stroke_alpha));
+ paint.setColor(SkColorSetA(kMDScrollbarStrokeColor, stroke_alpha));
paint.setStyle(SkPaint::kStroke_Style);
paint.setStrokeWidth(kStrokeWidth);
+
+ // When stroking in skia, there's some surprising behavior so we need to
+ // inset the right and bottom edges first. See the discussion here:
+ // https://groups.google.com/forum/#!topic/skia-discuss/HGZcc3Z7w1Q
Peter Kasting 2016/10/17 19:10:25 I'm concerned about this code. Looking at the ref
bokan 2016/10/17 23:21:03 You're right, I misunderstood the discussion in th
+ thumb_rect.Inset(0, 0, kStrokeWidth, kStrokeWidth);
canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
- thumb_rect.Inset(kStrokeWidth, kStrokeWidth, kStrokeWidth, kStrokeWidth);
+ // Inset the top and left edges for filling in the stroke below.
+ thumb_rect.Inset(kStrokeWidth, kStrokeWidth, 0, 0);
+
+ thumb_color = kMDScrollbarThumbColor;
} else {
// If there are no scrollbuttons then provide some padding so that the thumb
// doesn't touch the top of the track.
@@ -220,12 +236,14 @@ void NativeThemeAura::PaintScrollbarThumbStateTransition(
thumb_rect.Inset(kThumbPadding, extra_padding);
else
thumb_rect.Inset(extra_padding, kThumbPadding);
+
+ thumb_color = SK_ColorBLACK;
}
SkPaint paint;
SkAlpha alpha = gfx::Tween::IntValueBetween(
progress, ThumbAlphaForState(start_state), ThumbAlphaForState(end_state));
- paint.setColor(SkColorSetA(SK_ColorBLACK, alpha));
+ paint.setColor(SkColorSetA(thumb_color, alpha));
canvas->drawIRect(gfx::RectToSkIRect(thumb_rect), paint);
}
@@ -239,4 +257,36 @@ void NativeThemeAura::PaintScrollbarCorner(SkCanvas* canvas,
canvas->drawIRect(RectToSkIRect(rect), paint);
}
+gfx::Size NativeThemeAura::GetPartSize(Part part,
+ State state,
+ const ExtraParams& extra) const {
+ if (!IsOverlayScrollbarEnabled())
Peter Kasting 2016/10/17 19:10:24 Nit: This conditional effectively results in dupli
bokan 2016/10/17 23:21:04 Done.
+ return NativeThemeBase::GetPartSize(part, state, extra);
Peter Kasting 2016/10/17 19:10:24 Nit: 2 spaces
bokan 2016/10/17 23:21:03 Done.
+
+ // Aura overlay scrollbars need a slight tweak from the base sizes.
+ switch (part) {
+ case kScrollbarDownArrow:
+ case kScrollbarUpArrow:
+ case kScrollbarLeftArrow:
+ case kScrollbarRightArrow:
+ case kScrollbarHorizontalTrack:
+ case kScrollbarVerticalTrack:
+ case kScrollbarHorizontalGripper:
+ case kScrollbarVerticalGripper:
+ // Aura overlay scrollbars only have a thumb.
+ NOTREACHED();
Peter Kasting 2016/10/17 19:10:25 Is NOTREACHED really correct here, or should we ju
bokan 2016/10/17 23:21:04 I leaned towards forcing a runtime failure since I
bokan 2016/10/18 21:39:48 Ok, I found a case where this did get tripped. Whe
+ break;
+ case kScrollbarHorizontalThumb:
+ return gfx::Size(kMDScrollbarMinimumLength + 2 * kMDScrollbarStrokeWidth,
Peter Kasting 2016/10/17 19:10:24 Nit: You can factor this out to a constant above t
bokan 2016/10/17 23:21:04 Done.
+ scrollbar_width_);
+ case kScrollbarVerticalThumb:
+ return gfx::Size(scrollbar_width_,
+ kMDScrollbarMinimumLength + 2 * kMDScrollbarStrokeWidth);
+ default:
+ break;
+ }
+
+ return NativeThemeBase::GetPartSize(part, state, extra);
+}
+
} // namespace ui

Powered by Google App Engine
This is Rietveld 408576698