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/image_button.h" | 5 #include "ui/views/controls/button/image_button.h" |
| 6 | 6 |
| 7 #include <utility> | 7 #include <utility> |
| 8 | 8 |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "ui/accessibility/ax_node_data.h" | 10 #include "ui/accessibility/ax_node_data.h" |
| 11 #include "ui/gfx/animation/throb_animation.h" | 11 #include "ui/gfx/animation/throb_animation.h" |
| 12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
| 13 #include "ui/gfx/image/image_skia_operations.h" | 13 #include "ui/gfx/image/image_skia_operations.h" |
| 14 #include "ui/gfx/paint_vector_icon.h" | |
| 14 #include "ui/gfx/scoped_canvas.h" | 15 #include "ui/gfx/scoped_canvas.h" |
| 16 #include "ui/gfx/vector_icon_types.h" | |
| 17 #include "ui/views/border.h" | |
| 15 #include "ui/views/painter.h" | 18 #include "ui/views/painter.h" |
| 16 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
| 17 | 20 |
| 18 namespace views { | 21 namespace views { |
| 19 | 22 |
| 20 // Default button size if no image is set. This is ignored if there is an image, | 23 // Default button size if no image is set. This is ignored if there is an image, |
| 21 // and exists for historical reasons (any number of clients could depend on this | 24 // and exists for historical reasons (any number of clients could depend on this |
| 22 // behaviour). | 25 // behaviour). |
| 23 static const int kDefaultWidth = 16; | 26 static const int kDefaultWidth = 16; |
| 24 static const int kDefaultHeight = 14; | 27 static const int kDefaultHeight = 14; |
| (...skipping 261 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 286 // Use the visual pressed image as a cue for making this control into an | 289 // Use the visual pressed image as a cue for making this control into an |
| 287 // accessible toggle button. | 290 // accessible toggle button. |
| 288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || | 291 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || |
| 289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { | 292 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { |
| 290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | 293 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| 291 if (toggled_) | 294 if (toggled_) |
| 292 node_data->AddStateFlag(ui::AX_STATE_PRESSED); | 295 node_data->AddStateFlag(ui::AX_STATE_PRESSED); |
| 293 } | 296 } |
| 294 } | 297 } |
| 295 | 298 |
| 299 //////////////////////////////////////////////////////////////////////////////// | |
| 300 // ImageButton, utilities: | |
| 301 | |
| 302 void SetImageFromVectorIcon(ImageButton* button, | |
| 303 const gfx::VectorIcon& icon, | |
| 304 SkColor base_color) { | |
| 305 button->SetInkDropMode(CustomButton::InkDropMode::ON); | |
|
bruthig
2017/03/16 18:26:07
I'm not sure I would couple the ink drop behavior
Evan Stade
2017/03/16 18:49:13
for now, all call sites want it. To me that sugges
bruthig
2017/03/16 19:11:23
I'm not sure I would agree that all call sites wan
| |
| 306 button->set_has_ink_drop_action_on_click(true); | |
| 307 button->SetImageAlignment(ImageButton::ALIGN_CENTER, | |
| 308 ImageButton::ALIGN_MIDDLE); | |
| 309 button->SetFocusPainter(nullptr); | |
| 310 if (!button->border()) | |
| 311 button->SetBorder(CreateEmptyBorder(gfx::Insets(4))); | |
| 312 | |
| 313 const SkColor icon_color = color_utils::DeriveDefaultIconColor(base_color); | |
| 314 const SkColor disabled_color = SkColorSetA(icon_color, 0xff / 2); | |
| 315 button->SetImage(CustomButton::STATE_NORMAL, | |
| 316 gfx::CreateVectorIcon(icon, icon_color)); | |
| 317 button->SetImage(CustomButton::STATE_DISABLED, | |
| 318 gfx::CreateVectorIcon(icon, disabled_color)); | |
| 319 button->set_ink_drop_base_color(icon_color); | |
| 320 } | |
| 321 | |
| 296 } // namespace views | 322 } // namespace views |
| OLD | NEW |