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 14 matching lines...) Expand all Loading... | |
25 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" | 25 #include "ui/native_theme/overlay_scrollbar_constants_aura.h" |
26 | 26 |
27 namespace ui { | 27 namespace ui { |
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; | |
36 constexpr SkAlpha kOverlayScrollbarAlphaHovered = 0x80; | |
37 constexpr SkAlpha kOverlayScrollbarAlphaPressed = 0x80; | |
38 | |
39 // Indexed by ScrollbarOverlayColorTheme. | |
40 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | |
41 SK_ColorWHITE}; | |
42 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | |
43 SK_ColorBLACK}; | |
44 | 35 |
45 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); | 36 const SkColor kTrackColor = SkColorSetRGB(0xF1, 0xF1, 0xF1); |
46 | 37 |
47 } // namespace | 38 } // namespace |
48 | 39 |
49 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
50 // NativeTheme: | 41 // NativeTheme: |
51 | 42 |
52 // static | 43 // static |
53 NativeTheme* NativeTheme::GetInstanceForWeb() { | 44 NativeTheme* NativeTheme::GetInstanceForWeb() { |
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
187 Part part, | 178 Part part, |
188 State state, | 179 State state, |
189 const gfx::Rect& rect, | 180 const gfx::Rect& rect, |
190 ScrollbarOverlayColorTheme theme) const { | 181 ScrollbarOverlayColorTheme theme) const { |
191 // Do not paint if state is disabled. | 182 // Do not paint if state is disabled. |
192 if (state == kDisabled) | 183 if (state == kDisabled) |
193 return; | 184 return; |
194 | 185 |
195 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); | 186 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumb"); |
196 | 187 |
188 // Constants used for painting overlay scrollbar thumb. | |
189 constexpr SkAlpha kOverlayScrollbarFillAlphaNormal = 0x4D; | |
190 constexpr SkAlpha kOverlayScrollbarFillAlphaHovered = 0x80; | |
191 constexpr SkAlpha kOverlayScrollbarFillAlphaPressed = 0x80; | |
192 constexpr SkAlpha kOverlayScrollbarStrokeAlphaNormal = 0x4D; | |
193 constexpr SkAlpha kOverlayScrollbarStrokeAlphaHovered = 0x58; | |
194 constexpr SkAlpha kOverlayScrollbarStrokeAlphaPressed = 0x80; | |
195 | |
196 // Indexed by ScrollbarOverlayColorTheme. | |
197 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, | |
198 SK_ColorWHITE}; | |
199 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, | |
200 SK_ColorBLACK}; | |
201 | |
197 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | 202 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
203 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; | |
198 const bool overlay = use_overlay_scrollbars_; | 204 const bool overlay = use_overlay_scrollbars_; |
199 switch (state) { | 205 switch (state) { |
200 case NativeTheme::kDisabled: | 206 case NativeTheme::kDisabled: |
201 thumb_alpha = SK_AlphaTRANSPARENT; | 207 thumb_alpha = SK_AlphaTRANSPARENT; |
208 stroke_alpha = SK_AlphaTRANSPARENT; | |
202 break; | 209 break; |
203 case NativeTheme::kHovered: | 210 case NativeTheme::kHovered: |
204 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 211 thumb_alpha = overlay ? kOverlayScrollbarFillAlphaHovered : 0x4D; |
212 stroke_alpha = overlay ? kOverlayScrollbarStrokeAlphaHovered : 0x4D; | |
205 break; | 213 break; |
206 case NativeTheme::kNormal: | 214 case NativeTheme::kNormal: |
207 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; | 215 thumb_alpha = overlay ? kOverlayScrollbarFillAlphaNormal : 0x33; |
216 stroke_alpha = overlay ? kOverlayScrollbarStrokeAlphaNormal : 0x33; | |
208 break; | 217 break; |
209 case NativeTheme::kPressed: | 218 case NativeTheme::kPressed: |
210 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; | 219 thumb_alpha = overlay ? kOverlayScrollbarFillAlphaPressed : 0x80; |
220 stroke_alpha = overlay ? kOverlayScrollbarStrokeAlphaPressed : 0x80; | |
Evan Stade
2016/12/19 16:06:56
this ternary still doesn't make sense to me becaus
sahel
2016/12/19 17:57:26
You are right, it's only used for overlay case. I
| |
211 break; | 221 break; |
212 case NativeTheme::kNumStates: | 222 case NativeTheme::kNumStates: |
213 NOTREACHED(); | 223 NOTREACHED(); |
214 break; | 224 break; |
215 } | 225 } |
216 | 226 |
217 gfx::Rect thumb_rect(rect); | 227 gfx::Rect thumb_rect(rect); |
218 SkColor thumb_color; | 228 SkColor thumb_color; |
219 if (overlay) { | 229 if (overlay) { |
220 thumb_color = kOverlayScrollbarThumbColor[theme]; | 230 thumb_color = kOverlayScrollbarThumbColor[theme]; |
221 | 231 |
222 // In overlay mode, draw a stroke (border). | 232 // In overlay mode, draw a stroke (border). |
223 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 233 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
224 SkPaint paint; | 234 SkPaint paint; |
225 paint.setColor( | 235 paint.setColor( |
226 SkColorSetA(kOverlayScrollbarStrokeColor[theme], thumb_alpha)); | 236 SkColorSetA(kOverlayScrollbarStrokeColor[theme], stroke_alpha)); |
227 paint.setStyle(SkPaint::kStroke_Style); | 237 paint.setStyle(SkPaint::kStroke_Style); |
228 paint.setStrokeWidth(kStrokeWidth); | 238 paint.setStrokeWidth(kStrokeWidth); |
229 | 239 |
230 gfx::RectF stroke_rect(thumb_rect); | 240 gfx::RectF stroke_rect(thumb_rect); |
231 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 241 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
232 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 242 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
233 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 243 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
234 | 244 |
235 // Inset the all the edges edges so we fill-in the stroke below. | 245 // Inset the all the edges edges so we fill-in the stroke below. |
236 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 246 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
282 // scrollbars isn't asking for part sizes that don't exist. | 292 // scrollbars isn't asking for part sizes that don't exist. |
283 // crbug.com/657159. | 293 // crbug.com/657159. |
284 break; | 294 break; |
285 } | 295 } |
286 } | 296 } |
287 | 297 |
288 return NativeThemeBase::GetPartSize(part, state, extra); | 298 return NativeThemeBase::GetPartSize(part, state, extra); |
289 } | 299 } |
290 | 300 |
291 } // namespace ui | 301 } // namespace ui |
OLD | NEW |