Chromium Code Reviews| 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_view_state.h" | 11 #include "ui/accessibility/ax_view_state.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/paint_vector_icon.h" | 15 #include "ui/gfx/paint_vector_icon.h" |
| 16 #include "ui/gfx/vector_icons_public.h" | 16 #include "ui/gfx/vector_icons_public.h" |
| 17 #include "ui/resources/grit/ui_resources.h" | 17 #include "ui/resources/grit/ui_resources.h" |
| 18 #include "ui/views/animation/button_ink_drop_delegate.h" | |
| 19 #include "ui/views/animation/ink_drop_hover.h" | |
| 20 #include "ui/views/animation/ink_drop_ripple.h" | |
| 18 #include "ui/views/controls/button/label_button_border.h" | 21 #include "ui/views/controls/button/label_button_border.h" |
| 19 #include "ui/views/painter.h" | 22 #include "ui/views/painter.h" |
| 20 #include "ui/views/resources/grit/views_resources.h" | 23 #include "ui/views/resources/grit/views_resources.h" |
| 21 | 24 |
| 22 namespace views { | 25 namespace views { |
| 23 | 26 |
| 24 // static | 27 // static |
| 25 const char Checkbox::kViewClassName[] = "Checkbox"; | 28 const char Checkbox::kViewClassName[] = "Checkbox"; |
| 26 | 29 |
| 27 Checkbox::Checkbox(const base::string16& label) | 30 Checkbox::Checkbox(const base::string16& label) |
| 28 : LabelButton(NULL, label), | 31 : LabelButton(NULL, label), |
| 29 checked_(false) { | 32 checked_(false) { |
| 30 SetHorizontalAlignment(gfx::ALIGN_LEFT); | 33 SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 31 SetFocusForPlatform(); | 34 SetFocusForPlatform(); |
| 32 | 35 |
| 33 if (UseMd()) { | 36 if (UseMd()) { |
| 34 set_request_focus_on_press(false); | 37 set_request_focus_on_press(false); |
| 38 set_ink_drop_delegate( | |
| 39 base::WrapUnique(new ButtonInkDropDelegate(this, this))); | |
| 40 set_has_ink_drop_action_on_click(true); | |
| 41 // The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp. | |
| 42 set_ink_drop_size(gfx::Size(21, 21)); | |
| 35 } else { | 43 } else { |
| 36 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder()); | 44 std::unique_ptr<LabelButtonBorder> button_border(new LabelButtonBorder()); |
| 37 // Inset the trailing side by a couple pixels for the focus border. | 45 // Inset the trailing side by a couple pixels for the focus border. |
| 38 button_border->set_insets(gfx::Insets(0, 0, 0, 2)); | 46 button_border->set_insets(gfx::Insets(0, 0, 0, 2)); |
| 39 SetBorder(std::move(button_border)); | 47 SetBorder(std::move(button_border)); |
| 40 set_request_focus_on_press(true); | 48 set_request_focus_on_press(true); |
| 41 | 49 |
| 42 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 50 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 43 | 51 |
| 44 // Unchecked/Unfocused images. | 52 // Unchecked/Unfocused images. |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 if (!UseMd()) | 153 if (!UseMd()) |
| 146 UpdateImage(); | 154 UpdateImage(); |
| 147 } | 155 } |
| 148 | 156 |
| 149 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 157 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 150 LabelButton::OnNativeThemeChanged(theme); | 158 LabelButton::OnNativeThemeChanged(theme); |
| 151 if (UseMd()) | 159 if (UseMd()) |
| 152 UpdateImage(); | 160 UpdateImage(); |
| 153 } | 161 } |
| 154 | 162 |
| 163 std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const { | |
| 164 // Skip over the LabelButton override. | |
| 165 return InkDropHostView::CreateInkDropRipple(); | |
| 166 } | |
| 167 | |
| 168 std::unique_ptr<InkDropHover> Checkbox::CreateInkDropHover() const { | |
| 169 return nullptr; | |
| 170 } | |
| 171 | |
| 172 gfx::Point Checkbox::GetInkDropCenter() const { | |
| 173 return image()->bounds().CenterPoint(); | |
| 174 } | |
| 175 | |
| 176 SkColor Checkbox::GetInkDropBaseColor() const { | |
| 177 return GetNativeTheme()->GetSystemColor( | |
| 178 ui::NativeTheme::kColorId_UnfocusedBorderColor); | |
|
sky
2016/06/02 03:13:30
This seems like a weird choice for a base color. I
Evan Stade
2016/06/02 19:40:18
How so? It's the color of the checkbox square/radi
sky
2016/06/02 21:47:59
I didn't realize we use 'unfocused border color' i
| |
| 179 } | |
| 180 | |
| 155 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { | 181 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { |
| 156 if (UseMd()) { | 182 if (UseMd()) { |
| 157 return gfx::CreateVectorIcon( | 183 return gfx::CreateVectorIcon( |
| 158 checked_ ? gfx::VectorIconId::CHECKBOX_ACTIVE | 184 checked_ ? gfx::VectorIconId::CHECKBOX_ACTIVE |
| 159 : gfx::VectorIconId::CHECKBOX_NORMAL, | 185 : gfx::VectorIconId::CHECKBOX_NORMAL, |
| 160 16, GetNativeTheme()->GetSystemColor( | 186 16, GetNativeTheme()->GetSystemColor( |
| 161 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor | 187 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor |
| 162 : ui::NativeTheme::kColorId_UnfocusedBorderColor)); | 188 : ui::NativeTheme::kColorId_UnfocusedBorderColor)); |
| 163 } | 189 } |
| 164 | 190 |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 194 ui::NativeTheme::Part Checkbox::GetThemePart() const { | 220 ui::NativeTheme::Part Checkbox::GetThemePart() const { |
| 195 return ui::NativeTheme::kCheckbox; | 221 return ui::NativeTheme::kCheckbox; |
| 196 } | 222 } |
| 197 | 223 |
| 198 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { | 224 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| 199 LabelButton::GetExtraParams(params); | 225 LabelButton::GetExtraParams(params); |
| 200 params->button.checked = checked_; | 226 params->button.checked = checked_; |
| 201 } | 227 } |
| 202 | 228 |
| 203 } // namespace views | 229 } // namespace views |
| OLD | NEW |