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 kOverlayScrollbarStrokeColor = SK_ColorWHITE; | 39 constexpr SkColor kOverlayScrollbarThumbLightColor = SK_ColorWHITE; |
| 40 constexpr SkColor kOverlayScrollbarStrokeDefaultColor = SK_ColorWHITE; |
| 41 constexpr SkColor kOverlayScrollbarStrokeLightColor = SK_ColorBLACK; |
| 42 |
40 | 43 |
41 SkAlpha ThumbAlphaForState(NativeTheme::State state) { | 44 SkAlpha ThumbAlphaForState(NativeTheme::State state) { |
42 bool overlay = IsOverlayScrollbarEnabled(); | 45 bool overlay = IsOverlayScrollbarEnabled(); |
43 switch (state) { | 46 switch (state) { |
44 case NativeTheme::kDisabled: | 47 case NativeTheme::kDisabled: |
45 return 0x00; | 48 return 0x00; |
46 case NativeTheme::kHovered: | 49 case NativeTheme::kHovered: |
47 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; | 50 return overlay ? kOverlayScrollbarAlphaHovered : 0x4D; |
48 case NativeTheme::kNormal: | 51 case NativeTheme::kNormal: |
49 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; | 52 return overlay ? kOverlayScrollbarAlphaNormal : 0x33; |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
170 State state, | 173 State state, |
171 const ScrollbarTrackExtraParams& extra_params, | 174 const ScrollbarTrackExtraParams& extra_params, |
172 const gfx::Rect& rect) const { | 175 const gfx::Rect& rect) const { |
173 // Overlay Scrollbar should never paint a scrollbar track. | 176 // Overlay Scrollbar should never paint a scrollbar track. |
174 DCHECK(!IsOverlayScrollbarEnabled()); | 177 DCHECK(!IsOverlayScrollbarEnabled()); |
175 SkPaint paint; | 178 SkPaint paint; |
176 paint.setColor(kTrackColor); | 179 paint.setColor(kTrackColor); |
177 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); | 180 canvas->drawIRect(gfx::RectToSkIRect(rect), paint); |
178 } | 181 } |
179 | 182 |
180 void NativeThemeAura::PaintScrollbarThumb(SkCanvas* canvas, | 183 void NativeThemeAura::PaintScrollbarThumb( |
181 Part part, | 184 SkCanvas* canvas, |
182 State state, | 185 Part part, |
183 const gfx::Rect& rect) const { | 186 State state, |
| 187 const gfx::Rect& rect, |
| 188 ScrollbarOverlayColorTheme theme) const { |
184 // Do not paint if state is disabled. | 189 // Do not paint if state is disabled. |
185 if (state == kDisabled) | 190 if (state == kDisabled) |
186 return; | 191 return; |
187 | 192 |
188 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect); | 193 PaintScrollbarThumbStateTransition(canvas, part, state, state, 1.0, rect, |
| 194 theme); |
189 } | 195 } |
190 | 196 |
191 void NativeThemeAura::PaintScrollbarThumbStateTransition( | 197 void NativeThemeAura::PaintScrollbarThumbStateTransition( |
192 SkCanvas* canvas, | 198 SkCanvas* canvas, |
193 Part part, | 199 Part part, |
194 State start_state, | 200 State start_state, |
195 State end_state, | 201 State end_state, |
196 double progress, | 202 double progress, |
197 const gfx::Rect& rect) const { | 203 const gfx::Rect& rect, |
| 204 ScrollbarOverlayColorTheme theme) const { |
198 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); | 205 TRACE_EVENT0("blink", "NativeThemeAura::PaintScrollbarThumbStateTransition"); |
199 gfx::Rect thumb_rect(rect); | 206 gfx::Rect thumb_rect(rect); |
200 SkColor thumb_color; | 207 SkColor thumb_color; |
201 if (IsOverlayScrollbarEnabled()) { | 208 if (IsOverlayScrollbarEnabled()) { |
| 209 SkColor stroke_color; |
| 210 if (theme == ScrollbarOverlayColorThemeLight) { |
| 211 thumb_color = kOverlayScrollbarThumbLightColor; |
| 212 stroke_color = kOverlayScrollbarStrokeLightColor; |
| 213 } else { |
| 214 thumb_color = kOverlayScrollbarThumbDefaultColor; |
| 215 stroke_color = kOverlayScrollbarStrokeDefaultColor; |
| 216 } |
| 217 |
202 // In overlay mode, draw a stroke (border). | 218 // In overlay mode, draw a stroke (border). |
203 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; | 219 constexpr int kStrokeWidth = kOverlayScrollbarStrokeWidth; |
204 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( | 220 SkAlpha stroke_alpha = gfx::Tween::IntValueBetween( |
205 progress, ThumbAlphaForState(start_state), | 221 progress, ThumbAlphaForState(start_state), |
206 ThumbAlphaForState(end_state)); | 222 ThumbAlphaForState(end_state)); |
| 223 |
207 SkPaint paint; | 224 SkPaint paint; |
208 paint.setColor(SkColorSetA(kOverlayScrollbarStrokeColor, stroke_alpha)); | 225 paint.setColor(SkColorSetA(stroke_color, stroke_alpha)); |
209 paint.setStyle(SkPaint::kStroke_Style); | 226 paint.setStyle(SkPaint::kStroke_Style); |
210 paint.setStrokeWidth(kStrokeWidth); | 227 paint.setStrokeWidth(kStrokeWidth); |
211 | 228 |
212 gfx::RectF stroke_rect(thumb_rect); | 229 gfx::RectF stroke_rect(thumb_rect); |
213 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; | 230 constexpr float kHalfStrokeWidth = kStrokeWidth / 2.f; |
214 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); | 231 stroke_rect.Inset(kHalfStrokeWidth, kHalfStrokeWidth); |
215 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); | 232 canvas->drawRect(gfx::RectFToSkRect(stroke_rect), paint); |
216 | 233 |
217 // Inset the all the edges edges so we fill-in the stroke below. | 234 // Inset the all the edges edges so we fill-in the stroke below. |
218 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); | 235 thumb_rect.Inset(kStrokeWidth, kStrokeWidth); |
219 thumb_color = kOverlayScrollbarThumbColor; | 236 |
220 } else { | 237 } else { |
221 // If there are no scrollbuttons then provide some padding so that the thumb | 238 // If there are no scrollbuttons then provide some padding so that the thumb |
222 // doesn't touch the top of the track. | 239 // doesn't touch the top of the track. |
223 const int kThumbPadding = 2; | 240 const int kThumbPadding = 2; |
224 const int extra_padding = | 241 const int extra_padding = |
225 (scrollbar_button_length() == 0) ? kThumbPadding : 0; | 242 (scrollbar_button_length() == 0) ? kThumbPadding : 0; |
226 if (part == NativeTheme::kScrollbarVerticalThumb) | 243 if (part == NativeTheme::kScrollbarVerticalThumb) |
227 thumb_rect.Inset(kThumbPadding, extra_padding); | 244 thumb_rect.Inset(kThumbPadding, extra_padding); |
228 else | 245 else |
229 thumb_rect.Inset(extra_padding, kThumbPadding); | 246 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. | 286 // branch return 0 for parts that don't exist or assert NOTREACHED. |
270 // crbug.com/657159. | 287 // crbug.com/657159. |
271 break; | 288 break; |
272 } | 289 } |
273 } | 290 } |
274 | 291 |
275 return NativeThemeBase::GetPartSize(part, state, extra); | 292 return NativeThemeBase::GetPartSize(part, state, extra); |
276 } | 293 } |
277 | 294 |
278 } // namespace ui | 295 } // namespace ui |
OLD | NEW |