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 SkAlpha kOverlayStrokeAlphaNormal = 0x4D; | |
Evan Stade
2016/12/15 22:02:49
nit: the naming on these constants is a little inc
bokan
2016/12/15 22:05:30
Agreed on naming. Personally, I like having named
| |
39 constexpr SkAlpha kOverlayStrokeAlphaHovered = 0x58; | |
40 constexpr SkAlpha kOverlayStrokeAlphaPressed = 0x80; | |
38 | 41 |
39 // Indexed by ScrollbarOverlayColorTheme. | 42 // Indexed by ScrollbarOverlayColorTheme. |
40 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | 43 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
41 SK_ColorWHITE}; | 44 SK_ColorWHITE}; |
42 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | 45 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
43 SK_ColorBLACK}; | 46 SK_ColorBLACK}; |
44 | 47 |
45 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | 48 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
46 | 49 |
47 } // namespace | 50 } // namespace |
(...skipping 140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 State state, | 191 State state, |
189 const gfx::Rect& rect, | 192 const gfx::Rect& rect, |
190 ScrollbarOverlayColorTheme theme) const { | 193 ScrollbarOverlayColorTheme theme) const { |
191 // Do not paint if state is disabled. | 194 // Do not paint if state is disabled. |
192 if (state == kDisabled) | 195 if (state == kDisabled) |
193 return; | 196 return; |
194 | 197 |
195 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
196 | 199 |
197 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | 200 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
201 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; | |
198 const bool overlay = use_overlay_scrollbars_; | 202 const bool overlay = use_overlay_scrollbars_; |
199 switch (state) { | 203 switch (state) { |
200 case NativeTheme::kDisabled: | 204 case NativeTheme::kDisabled: |
201 thumb_alpha = SK_AlphaTRANSPARENT; | 205 thumb_alpha = SK_AlphaTRANSPARENT; |
206 stroke_alpha = SK_AlphaTRANSPARENT; | |
202 break; | 207 break; |
203 case NativeTheme::kHovered: | 208 case NativeTheme::kHovered: |
204 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 209 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
210 stroke_alpha = overlay ? kOverlayStrokeAlphaHovered : 0x4D; | |
205 break; | 211 break; |
206 case NativeTheme::kNormal: | 212 case NativeTheme::kNormal: |
207 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; | 213 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
214 stroke_alpha = overlay ? kOverlayStrokeAlphaNormal : 0x33; | |
208 break; | 215 break; |
209 case NativeTheme::kPressed: | 216 case NativeTheme::kPressed: |
210 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; | 217 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; |
218 stroke_alpha = overlay ? kOverlayStrokeAlphaPressed : 0x80; | |
Evan Stade
2016/12/15 22:02:49
stroke_alpha is unused when !overlay
| |
211 break; | 219 break; |
212 case NativeTheme::kNumStates: | 220 case NativeTheme::kNumStates: |
213 NOTREACHED(); | 221 NOTREACHED(); |
214 break; | 222 break; |
215 } | 223 } |
216 | 224 |
217 gfx::Rect thumb_rect(rect); | 225 gfx::Rect thumb_rect(rect); |
218 SkColor thumb_color; | 226 SkColor thumb_color; |
219 if (overlay) { | 227 if (overlay) { |
220 thumb_color = kOverlayScrollbarThumbColor[theme]; | 228 thumb_color = kOverlayScrollbarThumbColor[theme]; |
221 | 229 |
222 // In overlay mode, draw a stroke (border). | 230 // In overlay mode, draw a stroke (border). |
223 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 231 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
224 SkPaint paint; | 232 SkPaint paint; |
225 paint.setColor( | 233 paint.setColor( |
226 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); | 234 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); |
227 paint.setStyle(SkPaint::kStroke_Style); | 235 paint.setStyle(SkPaint::kStroke_Style); |
228 paint.setStrokeWidth(kStrokeWidth); | 236 paint.setStrokeWidth(kStrokeWidth); |
229 | 237 |
230 gfx::RectF stroke_rect(thumb_rect); | 238 gfx::RectF stroke_rect(thumb_rect); |
231 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 239 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
232 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 240 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
233 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 241 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
234 | 242 |
235 // Inset the all the edges edges so we fill-in the stroke below. | 243 // Inset the all the edges edges so we fill-in the stroke below. |
236 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 244 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
Evan Stade
2016/12/15 22:02:49
nit: you can do Inset(gfx::Insets(kStrokeWidth));
| |
237 } else { | 245 } else { |
238 // If there are no scrollbuttons then provide some padding so that the thumb | 246 // If there are no scrollbuttons then provide some padding so that the thumb |
239 // doesn't touch the top of the track. | 247 // doesn't touch the top of the track. |
240 const int kThumbPadding = 2; | 248 const int kThumbPadding = 2; |
241 const int extra_padding = | 249 const int extra_padding = |
242 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 250 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
243 if (part == NativeTheme::kScrollbarVerticalThumb) | 251 if (part == NativeTheme::kScrollbarVerticalThumb) |
244 thumb_rect.Inset(kThumbPadding, extra_padding); | 252 thumb_rect.Inset(kThumbPadding, extra_padding); |
245 else | 253 else |
246 thumb_rect.Inset(extra_padding, kThumbPadding); | 254 thumb_rect.Inset(extra_padding, kThumbPadding); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 // scrollbars isn't asking for part sizes that don't exist. | 290 // scrollbars isn't asking for part sizes that don't exist. |
283 // crbug.com/657159. | 291 // crbug.com/657159. |
284 break; | 292 break; |
285 } | 293 } |
286 } | 294 } |
287 | 295 |
288 return NativeThemeBase::GetPartSize(part, state, extra); | 296 return NativeThemeBase::GetPartSize(part, state, extra); |
289 } | 297 } |
290 | 298 |
291 } // namespace ui | 299 } // namespace ui |
OLD | NEW |