| 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/label_button_border.h" | 5 #include "ui/views/controls/button/label_button_border.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
| 9 #include "third_party/skia/include/core/SkPaint.h" | 9 #include "third_party/skia/include/core/SkPaint.h" |
| 10 #include "third_party/skia/include/effects/SkLerpXfermode.h" | 10 #include "third_party/skia/include/effects/SkLerpXfermode.h" |
| (...skipping 13 matching lines...) Expand all Loading... |
| 24 namespace { | 24 namespace { |
| 25 | 25 |
| 26 // Insets for the unified button images. This assumes that the images | 26 // Insets for the unified button images. This assumes that the images |
| 27 // are of a 9 grid, of 5x5 size each. | 27 // are of a 9 grid, of 5x5 size each. |
| 28 const int kButtonInsets = 5; | 28 const int kButtonInsets = 5; |
| 29 | 29 |
| 30 // The text-button hot and pushed image IDs; normal is unadorned by default. | 30 // The text-button hot and pushed image IDs; normal is unadorned by default. |
| 31 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); | 31 const int kTextHoveredImages[] = IMAGE_GRID(IDR_TEXTBUTTON_HOVER); |
| 32 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); | 32 const int kTextPressedImages[] = IMAGE_GRID(IDR_TEXTBUTTON_PRESSED); |
| 33 | 33 |
| 34 Button::ButtonState GetButtonState(ui::NativeTheme::State state) { | |
| 35 switch (state) { | |
| 36 case ui::NativeTheme::kDisabled: return Button::STATE_DISABLED; | |
| 37 case ui::NativeTheme::kHovered: return Button::STATE_HOVERED; | |
| 38 case ui::NativeTheme::kNormal: return Button::STATE_NORMAL; | |
| 39 case ui::NativeTheme::kPressed: return Button::STATE_PRESSED; | |
| 40 case ui::NativeTheme::kMaxState: NOTREACHED() << "Unknown state: " << state; | |
| 41 } | |
| 42 return Button::STATE_NORMAL; | |
| 43 } | |
| 44 | |
| 45 // A helper function to paint the appropriate broder images. | 34 // A helper function to paint the appropriate broder images. |
| 46 void PaintHelper(LabelButtonBorder* border, | 35 void PaintHelper(LabelButtonBorder* border, |
| 47 gfx::Canvas* canvas, | 36 gfx::Canvas* canvas, |
| 48 ui::NativeTheme::State state, | 37 ui::NativeTheme::State state, |
| 49 const gfx::Rect& rect, | 38 const gfx::Rect& rect, |
| 50 const ui::NativeTheme::ExtraParams& extra) { | 39 const ui::NativeTheme::ExtraParams& extra) { |
| 51 Painter* painter = | 40 Painter* painter = |
| 52 border->GetPainter(extra.button.is_focused, GetButtonState(state)); | 41 border->GetPainter(extra.button.is_focused, |
| 42 Button::GetButtonStateFrom(state)); |
| 53 // Paint any corresponding unfocused painter if there is no focused painter. | 43 // Paint any corresponding unfocused painter if there is no focused painter. |
| 54 if (!painter && extra.button.is_focused) | 44 if (!painter && extra.button.is_focused) |
| 55 painter = border->GetPainter(false, GetButtonState(state)); | 45 painter = border->GetPainter(false, Button::GetButtonStateFrom(state)); |
| 56 if (painter) | 46 if (painter) |
| 57 Painter::PaintPainterAt(canvas, painter, rect); | 47 Painter::PaintPainterAt(canvas, painter, rect); |
| 58 } | 48 } |
| 59 | 49 |
| 60 } // namespace | 50 } // namespace |
| 61 | 51 |
| 62 LabelButtonBorder::LabelButtonBorder(Button::ButtonStyle style) | 52 LabelButtonBorder::LabelButtonBorder(Button::ButtonStyle style) |
| 63 : style_(style) { | 53 : style_(style) { |
| 64 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 54 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 65 const gfx::Insets insets(kButtonInsets, | 55 const gfx::Insets insets(kButtonInsets, |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 return painters_[focused ? 1 : 0][state].get(); | 144 return painters_[focused ? 1 : 0][state].get(); |
| 155 } | 145 } |
| 156 | 146 |
| 157 void LabelButtonBorder::SetPainter(bool focused, | 147 void LabelButtonBorder::SetPainter(bool focused, |
| 158 Button::ButtonState state, | 148 Button::ButtonState state, |
| 159 Painter* painter) { | 149 Painter* painter) { |
| 160 painters_[focused ? 1 : 0][state].reset(painter); | 150 painters_[focused ? 1 : 0][state].reset(painter); |
| 161 } | 151 } |
| 162 | 152 |
| 163 } // namespace views | 153 } // namespace views |
| OLD | NEW |