OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/native_theme/native_theme_aura.h" | 5 #include "ui/native_theme/native_theme_aura.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 17 matching lines...) Expand all Loading... | |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
31 // Constants for painting overlay scrollbars. Other properties needed outside | 31 // Constants for painting overlay scrollbars. Other properties needed outside |
32 // this painting code are defined in overlay_scrollbar_constants_aura.h. | 32 // this painting code are defined in overlay_scrollbar_constants_aura.h. |
33 constexpr int kOverlayScrollbarStrokeWidth = 1; | 33 constexpr int kOverlayScrollbarStrokeWidth = 1; |
34 constexpr int kOverlayScrollbarMinimumLength = 12; | 34 constexpr int kOverlayScrollbarMinimumLength = 12; |
35 constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D; | 35 constexpr SkAlpha kOverlayScrollbarAlphaNormal = 0x4D; |
36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80; | 36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80; |
37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80; | 37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80; |
38 constexpr SkColor kOverlayScrollbarThumbColor = SK_ColorBLACK; | 38 constexpr SkColor kOverlayScrollbarThumbDefaultColor = SK_ColorBLACK; |
39 constexpr SkColor kOverlayScrollbarThumbLightColor = SK_ColorWHITE; | |
39 constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE; | 40 constexpr SkColor kOverlayScrollbarStrokeColor = SK_ColorWHITE; |
40 | 41 |
41 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | 42 SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
42 bool overlay = IsOverlayScrollbarEnabled(); | 43 bool overlay = IsOverlayScrollbarEnabled(); |
43 switch (state) { | 44 switch (state) { |
44 case NativeTheme::kDisabled: | 45 case NativeTheme::kDisabled: |
45 return 0x00; | 46 return 0x00; |
46 case NativeTheme::kHovered: | 47 case NativeTheme::kHovered: |
47 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 48 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
48 case NativeTheme::kNormal: | 49 case NativeTheme::kNormal: |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
170 State state, | 171 State state, |
171 const ScrollbarTrackExtraParams& extra_params, | 172 const ScrollbarTrackExtraParams& extra_params, |
172 const gfx::Rect& rect) const { | 173 const gfx::Rect& rect) const { |
173 // Overlay Scrollbar should never paint a scrollbar track. | 174 // Overlay Scrollbar should never paint a scrollbar track. |
174 DCHECK(!IsOverlayScrollbarEnabled()); | 175 DCHECK(!IsOverlayScrollbarEnabled()); |
175 SkPaint paint; | 176 SkPaint paint; |
176 paint.setColor(kTrackColor); | 177 paint.setColor(kTrackColor); |
177 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 178 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
178 } | 179 } |
179 | 180 |
180 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | 181 void NativeThemeAura::PaintScrollbarThumb( |
181 Part part, | 182 SkCanvas* canvas, |
182 State state, | 183 Part part, |
183 const gfx::Rect& rect) const { | 184 State state, |
185 const gfx::Rect& rect, | |
186 ScrollbarOverlayColorTheme theme) const { | |
184 // Do not paint if state is disabled. | 187 // Do not paint if state is disabled. |
185 if (state == kDisabled) | 188 if (state == kDisabled) |
186 return; | 189 return; |
187 | 190 |
188 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); | 191 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect, |
192 theme); | |
189 } | 193 } |
190 | 194 |
191 void NativeThemeAura::PaintScrollbarThumbStateTransition( | 195 void NativeThemeAura::PaintScrollbarThumbStateTransition( |
192 SkCanvas* canvas, | 196 SkCanvas* canvas, |
193 Part part, | 197 Part part, |
194 State start_state, | 198 State start_state, |
195 State end_state, | 199 State end_state, |
196 double progress, | 200 double progress, |
197 const gfx::Rect& rect) const { | 201 const gfx::Rect& rect, |
202 ScrollbarOverlayColorTheme theme) const { | |
198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); | 203 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); |
199 gfx::Rect thumb_rect(rect); | 204 gfx::Rect thumb_rect(rect); |
200 SkColor thumb_color; | 205 SkColor thumb_color; |
201 if (IsOverlayScrollbarEnabled()) { | 206 if (IsOverlayScrollbarEnabled()) { |
202 // In overlay mode, draw a stroke (border). | 207 // In overlay mode, draw a stroke (border). |
203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 208 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
204 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( | 209 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( |
205 progress, ThumbAlphaForState(start_state), | 210 progress, ThumbAlphaForState(start_state), |
206 ThumbAlphaForState(end_state)); | 211 ThumbAlphaForState(end_state)); |
207 SkPaint paint; | 212 SkPaint paint; |
208 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha)); | 213 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha)); |
bokan
2016/10/21 16:57:14
You'll need to do the same thing for the stroke co
| |
209 paint.setStyle(SkPaint::kStroke_Style); | 214 paint.setStyle(SkPaint::kStroke_Style); |
210 paint.setStrokeWidth(kStrokeWidth); | 215 paint.setStrokeWidth(kStrokeWidth); |
211 | 216 |
212 gfx::RectF stroke_rect(thumb_rect); | 217 gfx::RectF stroke_rect(thumb_rect); |
213 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 218 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
214 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 219 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
215 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 220 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
216 | 221 |
217 // Inset the all the edges edges so we fill-in the stroke below. | 222 // Inset the all the edges edges so we fill-in the stroke below. |
218 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 223 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
219 thumb_color = kOverlayScrollbarThumbColor; | 224 if (theme == ScrollbarOverlayColorThemeLight) |
225 thumb_color = kOverlayScrollbarThumbLightColor; | |
226 else | |
227 thumb_color = kOverlayScrollbarThumbDefaultColor; | |
220 } else { | 228 } else { |
221 // If there are no scrollbuttons then provide some padding so that the thumb | 229 // If there are no scrollbuttons then provide some padding so that the thumb |
222 // doesn't touch the top of the track. | 230 // doesn't touch the top of the track. |
223 const int kThumbPadding = 2; | 231 const int kThumbPadding = 2; |
224 const int extra_padding = | 232 const int extra_padding = |
225 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 233 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
226 if (part == NativeTheme::kScrollbarVerticalThumb) | 234 if (part == NativeTheme::kScrollbarVerticalThumb) |
227 thumb_rect.Inset(kThumbPadding, extra_padding); | 235 thumb_rect.Inset(kThumbPadding, extra_padding); |
228 else | 236 else |
229 thumb_rect.Inset(extra_padding, kThumbPadding); | 237 thumb_rect.Inset(extra_padding, kThumbPadding); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 // branch return 0 for parts that don't exist or assert NOTREACHED. | 277 // branch return 0 for parts that don't exist or assert NOTREACHED. |
270 // crbug.com/657159. | 278 // crbug.com/657159. |
271 break; | 279 break; |
272 } | 280 } |
273 } | 281 } |
274 | 282 |
275 return NativeThemeBase::GetPartSize(part, state, extra); | 283 return NativeThemeBase::GetPartSize(part, state, extra); |
276 } | 284 } |
277 | 285 |
278 } // namespace ui | 286 } // namespace ui |
OLD | NEW |