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 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 |
197 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; | 188 SkAlpha thumb_alpha = SK_AlphaTRANSPARENT; |
198 const bool overlay = use_overlay_scrollbars_; | |
199 switch (state) { | |
200 case NativeTheme::kDisabled: | |
201 thumb_alpha = SK_AlphaTRANSPARENT; | |
202 break; | |
203 case NativeTheme::kHovered: | |
204 thumb_alpha = overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | |
205 break; | |
206 case NativeTheme::kNormal: | |
207 thumb_alpha = overlay ? kOverlayScrollbarAlphaNormal : 0x33; | |
208 break; | |
209 case NativeTheme::kPressed: | |
210 thumb_alpha = overlay ? kOverlayScrollbarAlphaPressed : 0x80; | |
211 break; | |
212 case NativeTheme::kNumStates: | |
213 NOTREACHED(); | |
214 break; | |
215 } | |
216 | |
217 gfx::Rect thumb_rect(rect); | 189 gfx::Rect thumb_rect(rect); |
218 SkColor thumb_color; | 190 SkColor thumb_color; |
219 if (overlay) { | 191 |
| 192 if (use_overlay_scrollbars_) { |
| 193 // Constants used for painting overlay scrollbar thumb. |
| 194 constexpr SkAlpha kOverlayScrollbarFillAlphaNormal = 0x4D; |
| 195 constexpr SkAlpha kOverlayScrollbarFillAlphaHovered = 0x80; |
| 196 constexpr SkAlpha kOverlayScrollbarFillAlphaPressed = 0x80; |
| 197 constexpr SkAlpha kOverlayScrollbarStrokeAlphaNormal = 0x4D; |
| 198 constexpr SkAlpha kOverlayScrollbarStrokeAlphaHovered = 0x58; |
| 199 constexpr SkAlpha kOverlayScrollbarStrokeAlphaPressed = 0x80; |
| 200 |
| 201 // Indexed by ScrollbarOverlayColorTheme. |
| 202 constexpr SkColor kOverlayScrollbarThumbColor[] = {SK_ColorBLACK, |
| 203 SK_ColorWHITE}; |
| 204 constexpr SkColor kOverlayScrollbarStrokeColor[] = {SK_ColorWHITE, |
| 205 SK_ColorBLACK}; |
| 206 |
220 thumb_color = kOverlayScrollbarThumbColor[theme]; | 207 thumb_color = kOverlayScrollbarThumbColor[theme]; |
221 | 208 |
| 209 SkAlpha stroke_alpha = SK_AlphaTRANSPARENT; |
| 210 switch (state) { |
| 211 case NativeTheme::kDisabled: |
| 212 thumb_alpha = SK_AlphaTRANSPARENT; |
| 213 stroke_alpha = SK_AlphaTRANSPARENT; |
| 214 break; |
| 215 case NativeTheme::kHovered: |
| 216 thumb_alpha = kOverlayScrollbarFillAlphaHovered; |
| 217 stroke_alpha = kOverlayScrollbarStrokeAlphaHovered; |
| 218 break; |
| 219 case NativeTheme::kNormal: |
| 220 thumb_alpha = kOverlayScrollbarFillAlphaNormal; |
| 221 stroke_alpha = kOverlayScrollbarStrokeAlphaNormal; |
| 222 break; |
| 223 case NativeTheme::kPressed: |
| 224 thumb_alpha = kOverlayScrollbarFillAlphaPressed; |
| 225 stroke_alpha = kOverlayScrollbarStrokeAlphaPressed; |
| 226 break; |
| 227 case NativeTheme::kNumStates: |
| 228 NOTREACHED(); |
| 229 break; |
| 230 } |
| 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); |
237 } else { | 247 } else { |
| 248 switch (state) { |
| 249 case NativeTheme::kDisabled: |
| 250 thumb_alpha = SK_AlphaTRANSPARENT; |
| 251 break; |
| 252 case NativeTheme::kHovered: |
| 253 thumb_alpha = 0x4D; |
| 254 break; |
| 255 case NativeTheme::kNormal: |
| 256 thumb_alpha = 0x33; |
| 257 break; |
| 258 case NativeTheme::kPressed: |
| 259 thumb_alpha = 0x80; |
| 260 break; |
| 261 case NativeTheme::kNumStates: |
| 262 NOTREACHED(); |
| 263 break; |
| 264 } |
238 // If there are no scrollbuttons then provide some padding so that the thumb | 265 // If there are no scrollbuttons then provide some padding so that the thumb |
239 // doesn't touch the top of the track. | 266 // doesn't touch the top of the track. |
240 const int kThumbPadding = 2; | 267 const int kThumbPadding = 2; |
241 const int extra_padding = | 268 const int extra_padding = |
242 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 269 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
243 if (part == NativeTheme::kScrollbarVerticalThumb) | 270 if (part == NativeTheme::kScrollbarVerticalThumb) |
244 thumb_rect.Inset(kThumbPadding, extra_padding); | 271 thumb_rect.Inset(kThumbPadding, extra_padding); |
245 else | 272 else |
246 thumb_rect.Inset(extra_padding, kThumbPadding); | 273 thumb_rect.Inset(extra_padding, kThumbPadding); |
247 | 274 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 // scrollbars isn't asking for part sizes that don't exist. | 309 // scrollbars isn't asking for part sizes that don't exist. |
283 // crbug.com/657159. | 310 // crbug.com/657159. |
284 break; | 311 break; |
285 } | 312 } |
286 } | 313 } |
287 | 314 |
288 return NativeThemeBase::GetPartSize(part, state, extra); | 315 return NativeThemeBase::GetPartSize(part, state, extra); |
289 } | 316 } |
290 | 317 |
291 } // namespace ui | 318 } // namespace ui |
OLD | NEW |