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_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/views/animation/ink_drop_impl.h" | 17 #include "ui/views/animation/ink_drop_impl.h" |
| 18 #include "ui/views/animation/ink_drop_ripple.h" | 18 #include "ui/views/animation/ink_drop_ripple.h" |
| 19 #include "ui/views/animation/square_ink_drop_ripple.h" | |
| 20 #include "ui/views/controls/button/label_button_border.h" | 19 #include "ui/views/controls/button/label_button_border.h" |
| 21 #include "ui/views/painter.h" | 20 #include "ui/views/painter.h" |
| 22 #include "ui/views/resources/grit/views_resources.h" | 21 #include "ui/views/resources/grit/views_resources.h" |
| 23 #include "ui/views/style/platform_style.h" | 22 #include "ui/views/style/platform_style.h" |
| 24 #include "ui/views/vector_icons.h" | 23 #include "ui/views/vector_icons.h" |
| 25 | 24 |
| 26 namespace views { | 25 namespace views { |
| 27 | 26 |
| 28 // static | 27 // static |
| 29 const char Checkbox::kViewClassName[] = "Checkbox"; | 28 const char Checkbox::kViewClassName[] = "Checkbox"; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 139 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 138 void Checkbox::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 140 LabelButton::OnNativeThemeChanged(theme); | 139 LabelButton::OnNativeThemeChanged(theme); |
| 141 if (UseMd()) | 140 if (UseMd()) |
| 142 UpdateImage(); | 141 UpdateImage(); |
| 143 } | 142 } |
| 144 | 143 |
| 145 std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() { | 144 std::unique_ptr<InkDrop> Checkbox::CreateInkDrop() { |
| 146 // Completely removes the highlight. | 145 // Completely removes the highlight. |
| 147 std::unique_ptr<InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); | 146 std::unique_ptr<InkDropImpl> ink_drop = CreateDefaultInkDropImpl(); |
| 148 ink_drop->SetShowHighlightOnHover(false); | 147 ink_drop->SetShowHighlightOnHover(false); |
| 149 ink_drop->SetAutoHighlightMode(views::InkDropImpl::AutoHighlightMode::NONE); | 148 ink_drop->SetAutoHighlightMode(InkDropImpl::AutoHighlightMode::NONE); |
| 150 return ink_drop; | 149 return ink_drop; |
| 151 } | 150 } |
| 152 | 151 |
| 153 std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const { | 152 std::unique_ptr<InkDropRipple> Checkbox::CreateInkDropRipple() const { |
| 154 // The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp. | 153 // The "small" size is 21dp, the large size is 1.33 * 21dp = 28dp. |
| 155 const gfx::Size size(21, 21); | 154 return CreateDefaultInkDropRipple(image()->GetMirroredBounds().CenterPoint(), |
|
tapted
2017/06/29 10:20:05
This is https://cs.chromium.org/chromium/src/ui/vi
| |
| 156 std::unique_ptr<InkDropRipple> ripple(new SquareInkDropRipple( | 155 gfx::Size(21, 21)); |
| 157 CalculateLargeInkDropSize(size), kInkDropLargeCornerRadius, size, | |
| 158 kInkDropSmallCornerRadius, image()->GetMirroredBounds().CenterPoint(), | |
| 159 GetInkDropBaseColor(), ink_drop_visible_opacity())); | |
| 160 return ripple; | |
| 161 } | 156 } |
| 162 | 157 |
| 163 SkColor Checkbox::GetInkDropBaseColor() const { | 158 SkColor Checkbox::GetInkDropBaseColor() const { |
| 164 return GetNativeTheme()->GetSystemColor( | 159 return GetNativeTheme()->GetSystemColor( |
| 165 ui::NativeTheme::kColorId_ButtonEnabledColor); | 160 ui::NativeTheme::kColorId_LabelEnabledColor); |
| 166 } | 161 } |
| 167 | 162 |
| 168 void Checkbox::PaintButtonContents(gfx::Canvas* canvas) { | 163 void Checkbox::PaintButtonContents(gfx::Canvas* canvas) { |
| 169 if (!UseMd() || !HasFocus()) | 164 if (!UseMd() || !HasFocus()) |
| 170 return; | 165 return; |
| 171 | 166 |
| 172 cc::PaintFlags focus_flags; | 167 cc::PaintFlags focus_flags; |
| 173 focus_flags.setAntiAlias(true); | 168 focus_flags.setAntiAlias(true); |
| 174 focus_flags.setColor( | 169 focus_flags.setColor( |
| 175 SkColorSetA(GetNativeTheme()->GetSystemColor( | 170 SkColorSetA(GetNativeTheme()->GetSystemColor( |
| 176 ui::NativeTheme::kColorId_FocusedBorderColor), | 171 ui::NativeTheme::kColorId_FocusedBorderColor), |
| 177 0x66)); | 172 0x66)); |
| 178 focus_flags.setStyle(cc::PaintFlags::kStroke_Style); | 173 focus_flags.setStyle(cc::PaintFlags::kStroke_Style); |
| 179 focus_flags.setStrokeWidth(2); | 174 focus_flags.setStrokeWidth(2); |
| 180 PaintFocusRing(canvas, focus_flags); | 175 PaintFocusRing(canvas, focus_flags); |
| 181 } | 176 } |
| 182 | 177 |
| 183 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { | 178 gfx::ImageSkia Checkbox::GetImage(ButtonState for_state) const { |
| 184 if (UseMd()) { | 179 if (UseMd()) { |
| 185 return gfx::CreateVectorIcon( | 180 return gfx::CreateVectorIcon( |
| 186 GetVectorIcon(), 16, | 181 GetVectorIcon(), 16, |
| 187 // When not checked, the icon color matches the button text color. | 182 // When not checked, the icon color matches the button text color. |
| 188 GetNativeTheme()->GetSystemColor( | 183 GetNativeTheme()->GetSystemColor( |
| 189 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor | 184 checked_ ? ui::NativeTheme::kColorId_FocusedBorderColor |
| 190 : ui::NativeTheme::kColorId_ButtonEnabledColor)); | 185 : ui::NativeTheme::kColorId_LabelEnabledColor)); |
| 191 } | 186 } |
| 192 | 187 |
| 193 const size_t checked_index = checked_ ? 1 : 0; | 188 const size_t checked_index = checked_ ? 1 : 0; |
| 194 const size_t focused_index = HasFocus() ? 1 : 0; | 189 const size_t focused_index = HasFocus() ? 1 : 0; |
| 195 if (for_state != STATE_NORMAL && | 190 if (for_state != STATE_NORMAL && |
| 196 images_[checked_index][focused_index][for_state].isNull()) | 191 images_[checked_index][focused_index][for_state].isNull()) |
| 197 return images_[checked_index][focused_index][STATE_NORMAL]; | 192 return images_[checked_index][focused_index][STATE_NORMAL]; |
| 198 return images_[checked_index][focused_index][for_state]; | 193 return images_[checked_index][focused_index][for_state]; |
| 199 } | 194 } |
| 200 | 195 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 226 ui::NativeTheme::Part Checkbox::GetThemePart() const { | 221 ui::NativeTheme::Part Checkbox::GetThemePart() const { |
| 227 return ui::NativeTheme::kCheckbox; | 222 return ui::NativeTheme::kCheckbox; |
| 228 } | 223 } |
| 229 | 224 |
| 230 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { | 225 void Checkbox::GetExtraParams(ui::NativeTheme::ExtraParams* params) const { |
| 231 LabelButton::GetExtraParams(params); | 226 LabelButton::GetExtraParams(params); |
| 232 params->button.checked = checked_; | 227 params->button.checked = checked_; |
| 233 } | 228 } |
| 234 | 229 |
| 235 } // namespace views | 230 } // namespace views |
| OLD | NEW |