| 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/views/controls/button/chrome_style.h" | 5 #include "ui/views/controls/button/chrome_style.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" | 9 #include "third_party/skia/include/effects/SkBlurMaskFilter.h" |
| 10 #include "ui/gfx/canvas.h" | 10 #include "ui/gfx/canvas.h" |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 55 const SkColor kTextShadowColor = SkColorSetRGB(0xf0, 0xf0, 0xf0); | 55 const SkColor kTextShadowColor = SkColorSetRGB(0xf0, 0xf0, 0xf0); |
| 56 const int kTextShadowOffsetX = 0; | 56 const int kTextShadowOffsetX = 0; |
| 57 const int kTextShadowOffsetY = 1; | 57 const int kTextShadowOffsetY = 1; |
| 58 | 58 |
| 59 const int kBorderWidth = 1; | 59 const int kBorderWidth = 1; |
| 60 const int kBorderRadius = 2; | 60 const int kBorderRadius = 2; |
| 61 const SkColor kBorderNormalColor = SkColorSetARGB(0x3f, 0x0, 0x0, 0x0); | 61 const SkColor kBorderNormalColor = SkColorSetARGB(0x3f, 0x0, 0x0, 0x0); |
| 62 const SkColor kBorderActiveColor = SkColorSetARGB(0x4b, 0x0, 0x0, 0x0); | 62 const SkColor kBorderActiveColor = SkColorSetARGB(0x4b, 0x0, 0x0, 0x0); |
| 63 const SkColor kBorderDisabledColor = SkColorSetARGB(0x1d, 0x0, 0x0, 0x0); | 63 const SkColor kBorderDisabledColor = SkColorSetARGB(0x1d, 0x0, 0x0, 0x0); |
| 64 | 64 |
| 65 const int kFocusRingWidth = 2; | 65 const int kFocusRingWidth = 1; |
| 66 const int kFocusRingRadius = 2; | 66 const int kFocusRingRadius = 2; |
| 67 const SkColor kFocusRingColor = SkColorSetARGB(0x7f, 0xe5, 0x97, 0x00); | 67 const SkColor kFocusRingColor = SkColorSetRGB(0x4d, 0x90, 0xfe); |
| 68 | 68 |
| 69 // Returns the uniform inset of the button from its local bounds. | 69 // Returns the uniform inset of the button from its local bounds. |
| 70 int GetButtonInset() { | 70 int GetButtonInset() { |
| 71 return std::max(kBorderWidth, kFocusRingWidth); | 71 return std::max(kBorderWidth, kFocusRingWidth); |
| 72 } | 72 } |
| 73 | 73 |
| 74 class ChromeStyleTextButtonBackgroundPainter : public Painter { | 74 class ChromeStyleTextButtonBackgroundPainter : public Painter { |
| 75 public: | 75 public: |
| 76 ChromeStyleTextButtonBackgroundPainter() | 76 ChromeStyleTextButtonBackgroundPainter() |
| 77 : gradient_painter_(NULL), | 77 : gradient_painter_(NULL), |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 255 | 255 |
| 256 DISALLOW_COPY_AND_ASSIGN(ChromeStyleTextButtonBorder); | 256 DISALLOW_COPY_AND_ASSIGN(ChromeStyleTextButtonBorder); |
| 257 }; | 257 }; |
| 258 | 258 |
| 259 class ChromeStyleFocusBorder : public views::FocusBorder { | 259 class ChromeStyleFocusBorder : public views::FocusBorder { |
| 260 public: | 260 public: |
| 261 ChromeStyleFocusBorder() {} | 261 ChromeStyleFocusBorder() {} |
| 262 | 262 |
| 263 // Overriden from Border | 263 // Overriden from Border |
| 264 virtual void Paint(const View& view, gfx::Canvas* canvas) const { | 264 virtual void Paint(const View& view, gfx::Canvas* canvas) const { |
| 265 gfx::Rect rect(view.GetLocalBounds()); | |
| 266 SkScalar inset = SkFloatToScalar(GetButtonInset() - kFocusRingWidth / 2.0f); | |
| 267 rect.Inset(inset, inset); | |
| 268 SkPaint paint; | 265 SkPaint paint; |
| 269 paint.setStyle(SkPaint::kStroke_Style); | 266 paint.setStyle(SkPaint::kStroke_Style); |
| 270 paint.setStrokeWidth(SkIntToScalar(kFocusRingWidth)); | 267 paint.setStrokeWidth(SkIntToScalar(kFocusRingWidth)); |
| 271 paint.setColor(kFocusRingColor); | 268 paint.setColor(kFocusRingColor); |
| 272 canvas->DrawRoundRect(rect, SkIntToScalar(kFocusRingRadius), paint); | 269 |
| 270 SkScalar inset = SkFloatToScalar(GetButtonInset() - kFocusRingWidth / 2.0f); |
| 271 gfx::Rect view_bounds(view.GetLocalBounds()); |
| 272 SkRect rect = SkRect::MakeLTRB( |
| 273 SkIntToScalar(view_bounds.x()) + inset, |
| 274 SkIntToScalar(view_bounds.y()) + inset, |
| 275 SkIntToScalar(view_bounds.width()) - inset, |
| 276 SkIntToScalar(view_bounds.height()) - inset); |
| 277 canvas->sk_canvas()->drawRoundRect(rect, SkIntToScalar(kFocusRingRadius), |
| 278 SkIntToScalar(kFocusRingRadius), paint); |
| 273 } | 279 } |
| 274 | 280 |
| 275 private: | 281 private: |
| 276 DISALLOW_COPY_AND_ASSIGN(ChromeStyleFocusBorder); | 282 DISALLOW_COPY_AND_ASSIGN(ChromeStyleFocusBorder); |
| 277 }; | 283 }; |
| 278 | 284 |
| 279 class ChromeStyleStateChangedUpdater | 285 class ChromeStyleStateChangedUpdater |
| 280 : public CustomButtonStateChangedDelegate { | 286 : public CustomButtonStateChangedDelegate { |
| 281 public: | 287 public: |
| 282 // The background and border may be NULL. | 288 // The background and border may be NULL. |
| (...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 435 | 441 |
| 436 button->set_focus_border(new ChromeStyleFocusBorder); | 442 button->set_focus_border(new ChromeStyleFocusBorder); |
| 437 | 443 |
| 438 ChromeStyleStateChangedUpdater* state_changed_updater = | 444 ChromeStyleStateChangedUpdater* state_changed_updater = |
| 439 new ChromeStyleStateChangedUpdater(button, background, border); | 445 new ChromeStyleStateChangedUpdater(button, background, border); |
| 440 | 446 |
| 441 button->set_state_changed_delegate(state_changed_updater); | 447 button->set_state_changed_delegate(state_changed_updater); |
| 442 } | 448 } |
| 443 | 449 |
| 444 } // namespace views | 450 } // namespace views |
| OLD | NEW |