Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(388)

Side by Side Diff: ui/views/controls/button/image_button.cc

Issue 2744463002: Add VectorIconButton functionality to ImageButton. (Closed)
Patch Set: WIP: use observer Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/scoped_canvas.h" 14 #include "ui/gfx/scoped_canvas.h"
15 #include "ui/views/border.h"
15 #include "ui/views/painter.h" 16 #include "ui/views/painter.h"
16 #include "ui/views/widget/widget.h" 17 #include "ui/views/widget/widget.h"
17 18
18 namespace views { 19 namespace views {
19 20
20 // Default button size if no image is set. This is ignored if there is an image, 21 // 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 22 // and exists for historical reasons (any number of clients could depend on this
22 // behaviour). 23 // behaviour).
23 static const int kDefaultWidth = 16; 24 static const int kDefaultWidth = 16;
24 static const int kDefaultHeight = 14; 25 static const int kDefaultHeight = 14;
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 } 89 }
89 90
90 void ImageButton::SetMinimumImageSize(const gfx::Size& size) { 91 void ImageButton::SetMinimumImageSize(const gfx::Size& size) {
91 if (minimum_image_size_ == size) 92 if (minimum_image_size_ == size)
92 return; 93 return;
93 94
94 minimum_image_size_ = size; 95 minimum_image_size_ = size;
95 PreferredSizeChanged(); 96 PreferredSizeChanged();
96 } 97 }
97 98
99 void ImageButton::SetPadding(const gfx::Insets& padding) {
Evan Stade 2017/03/15 15:04:02 What is the motivation to add this method instead
Bret 2017/03/15 23:39:19 I see a lot of places where we're doing SetBorder(
100 if (padding.IsEmpty())
101 SetBorder(NullBorder());
102 else
103 SetBorder(CreateEmptyBorder(padding));
104 }
105
98 //////////////////////////////////////////////////////////////////////////////// 106 ////////////////////////////////////////////////////////////////////////////////
99 // ImageButton, View overrides: 107 // ImageButton, View overrides:
100 108
101 gfx::Size ImageButton::GetPreferredSize() const { 109 gfx::Size ImageButton::GetPreferredSize() const {
102 gfx::Size size(kDefaultWidth, kDefaultHeight); 110 gfx::Size size(kDefaultWidth, kDefaultHeight);
103 if (!images_[STATE_NORMAL].isNull()) { 111 if (!images_[STATE_NORMAL].isNull()) {
104 size = gfx::Size(images_[STATE_NORMAL].width(), 112 size = gfx::Size(images_[STATE_NORMAL].width(),
105 images_[STATE_NORMAL].height()); 113 images_[STATE_NORMAL].height());
106 } 114 }
107 115
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 // accessible toggle button. 295 // accessible toggle button.
288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || 296 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) ||
289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { 297 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) {
290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; 298 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON;
291 if (toggled_) 299 if (toggled_)
292 node_data->AddStateFlag(ui::AX_STATE_PRESSED); 300 node_data->AddStateFlag(ui::AX_STATE_PRESSED);
293 } 301 }
294 } 302 }
295 303
296 } // namespace views 304 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698