| 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/checkbox.h" | 5 #include "ui/views/controls/button/checkbox.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <utility> | 9 #include <utility> |
| 10 | 10 |
| 11 #include "ui/accessibility/ax_node_data.h" | 11 #include "ui/accessibility/ax_node_data.h" |
| 12 #include "ui/base/material_design/material_design_controller.h" | 12 #include "ui/base/material_design/material_design_controller.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/color_utils.h" | 15 #include "ui/gfx/color_utils.h" |
| 16 #include "ui/gfx/paint_vector_icon.h" | 16 #include "ui/gfx/paint_vector_icon.h" |
| 17 #include "ui/gfx/vector_icons_public.h" | |
| 18 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" |
| 19 #include "ui/views/animation/ink_drop_ripple.h" | 18 #include "ui/views/animation/ink_drop_ripple.h" |
| 20 #include "ui/views/animation/square_ink_drop_ripple.h" | 19 #include "ui/views/animation/square_ink_drop_ripple.h" |
| 21 #include "ui/views/controls/button/label_button_border.h" | 20 #include "ui/views/controls/button/label_button_border.h" |
| 22 #include "ui/views/painter.h" | 21 #include "ui/views/painter.h" |
| 23 #include "ui/views/resources/grit/views_resources.h" | 22 #include "ui/views/resources/grit/views_resources.h" |
| 23 #include "ui/views/resources/vector_icons/vector_icons.h" |
| 24 #include "ui/views/style/platform_style.h" | 24 #include "ui/views/style/platform_style.h" |
| 25 | 25 |
| 26 namespace views { | 26 namespace views { |
| 27 | 27 |
| 28 // static | 28 // static |
| 29 const char Checkbox::kViewClassName[] = "Checkbox"; | 29 const char Checkbox::kViewClassName[] = "Checkbox"; |
| 30 | 30 |
| 31 Checkbox::Checkbox(const base::string16& label) | 31 Checkbox::Checkbox(const base::string16& label) |
| 32 : LabelButton(NULL, label), | 32 : LabelButton(NULL, label), |
| 33 checked_(false) { | 33 checked_(false) { |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 } | 182 } |
| 183 | 183 |
| 184 SkColor Checkbox::GetInkDropBaseColor() const { | 184 SkColor Checkbox::GetInkDropBaseColor() const { |
| 185 return GetNativeTheme()->GetSystemColor( | 185 return GetNativeTheme()->GetSystemColor( |
| 186 ui::NativeTheme::kColorId_ButtonEnabledColor); | 186 ui::NativeTheme::kColorId_ButtonEnabledColor); |
| 187 } | 187 } |
| 188 | 188 |
| 189 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { | 189 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { |
| 190 if (UseMd()) { | 190 if (UseMd()) { |
| 191 return gfx::CreateVectorIcon( | 191 return gfx::CreateVectorIcon( |
| 192 GetVectorIconId(), 16, | 192 GetVectorIcon(), 16, |
| 193 // When not checked, the icon color matches the button text color. | 193 // When not checked, the icon color matches the button text color. |
| 194 GetNativeTheme()->GetSystemColor( | 194 GetNativeTheme()->GetSystemColor( |
| 195 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor | 195 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor |
| 196 : ui::NativeTheme::kColorId_ButtonEnabledColor)); | 196 : ui::NativeTheme::kColorId_ButtonEnabledColor)); |
| 197 } | 197 } |
| 198 | 198 |
| 199 const size_t checked_index = checked_ ? 1 : 0; | 199 const size_t checked_index = checked_ ? 1 : 0; |
| 200 const size_t focused_index = HasFocus() ? 1 : 0; | 200 const size_t focused_index = HasFocus() ? 1 : 0; |
| 201 if (for_state != STATE_NORMAL && | 201 if (for_state != STATE_NORMAL && |
| 202 images_[checked_index][focused_index][for_state].isNull()) | 202 images_[checked_index][focused_index][for_state].isNull()) |
| 203 return images_[checked_index][focused_index][STATE_NORMAL]; | 203 return images_[checked_index][focused_index][STATE_NORMAL]; |
| 204 return images_[checked_index][focused_index][for_state]; | 204 return images_[checked_index][focused_index][for_state]; |
| 205 } | 205 } |
| 206 | 206 |
| 207 void Checkbox::SetCustomImage(bool checked, | 207 void Checkbox::SetCustomImage(bool checked, |
| 208 bool focused, | 208 bool focused, |
| 209 ButtonState for_state, | 209 ButtonState for_state, |
| 210 const gfx::ImageSkia& image) { | 210 const gfx::ImageSkia& image) { |
| 211 const size_t checked_index = checked ? 1 : 0; | 211 const size_t checked_index = checked ? 1 : 0; |
| 212 const size_t focused_index = focused ? 1 : 0; | 212 const size_t focused_index = focused ? 1 : 0; |
| 213 images_[checked_index][focused_index][for_state] = image; | 213 images_[checked_index][focused_index][for_state] = image; |
| 214 UpdateImage(); | 214 UpdateImage(); |
| 215 } | 215 } |
| 216 | 216 |
| 217 void Checkbox::PaintFocusRing(gfx::Canvas* canvas, const SkPaint& paint) { | 217 void Checkbox::PaintFocusRing(gfx::Canvas* canvas, const SkPaint& paint) { |
| 218 gfx::RectF focus_rect(image()->bounds()); | 218 gfx::RectF focus_rect(image()->bounds()); |
| 219 canvas->DrawRoundRect(focus_rect, 2.f, paint); | 219 canvas->DrawRoundRect(focus_rect, 2.f, paint); |
| 220 } | 220 } |
| 221 | 221 |
| 222 gfx::VectorIconId Checkbox::GetVectorIconId() const { | 222 const gfx::VectorIcon& Checkbox::GetVectorIcon() const { |
| 223 return checked() ? gfx::VectorIconId::CHECKBOX_ACTIVE | 223 return checked() ? kCheckboxActiveIcon : kCheckboxNormalIcon; |
| 224 : gfx::VectorIconId::CHECKBOX_NORMAL; | |
| 225 } | 224 } |
| 226 | 225 |
| 227 void Checkbox::NotifyClick(const ui::Event& event) { | 226 void Checkbox::NotifyClick(const ui::Event& event) { |
| 228 SetChecked(!checked()); | 227 SetChecked(!checked()); |
| 229 LabelButton::NotifyClick(event); | 228 LabelButton::NotifyClick(event); |
| 230 } | 229 } |
| 231 | 230 |
| 232 ui::NativeTheme::Part Checkbox::GetThemePart() const { | 231 ui::NativeTheme::Part Checkbox::GetThemePart() const { |
| 233 return ui::NativeTheme::kCheckbox; | 232 return ui::NativeTheme::kCheckbox; |
| 234 } | 233 } |
| 235 | 234 |
| 236 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { | 235 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| 237 LabelButton::GetExtraParams(params); | 236 LabelButton::GetExtraParams(params); |
| 238 params->button.checked = checked_; | 237 params->button.checked = checked_; |
| 239 } | 238 } |
| 240 | 239 |
| 241 } // namespace views | 240 } // namespace views |
| OLD | NEW |