| 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" |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 91 if (minimum_image_size_ == size) | 91 if (minimum_image_size_ == size) |
| 92 return; | 92 return; |
| 93 | 93 |
| 94 minimum_image_size_ = size; | 94 minimum_image_size_ = size; |
| 95 PreferredSizeChanged(); | 95 PreferredSizeChanged(); |
| 96 } | 96 } |
| 97 | 97 |
| 98 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
| 99 // ImageButton, View overrides: | 99 // ImageButton, View overrides: |
| 100 | 100 |
| 101 gfx::Size ImageButton::GetPreferredSize() const { | |
| 102 gfx::Size size(kDefaultWidth, kDefaultHeight); | |
| 103 if (!images_[STATE_NORMAL].isNull()) { | |
| 104 size = gfx::Size(images_[STATE_NORMAL].width(), | |
| 105 images_[STATE_NORMAL].height()); | |
| 106 } | |
| 107 | |
| 108 size.SetToMax(minimum_image_size_); | |
| 109 | |
| 110 gfx::Insets insets = GetInsets(); | |
| 111 size.Enlarge(insets.width(), insets.height()); | |
| 112 return size; | |
| 113 } | |
| 114 | |
| 115 const char* ImageButton::GetClassName() const { | 101 const char* ImageButton::GetClassName() const { |
| 116 return kViewClassName; | 102 return kViewClassName; |
| 117 } | 103 } |
| 118 | 104 |
| 119 void ImageButton::OnPaint(gfx::Canvas* canvas) { | 105 void ImageButton::OnPaint(gfx::Canvas* canvas) { |
| 120 // Call the base class first to paint any background/borders. | 106 // Call the base class first to paint any background/borders. |
| 121 View::OnPaint(canvas); | 107 View::OnPaint(canvas); |
| 122 | 108 |
| 123 // TODO(estade|tdanderson|bruthig): The ink drop layer should be positioned | 109 // TODO(estade|tdanderson|bruthig): The ink drop layer should be positioned |
| 124 // behind the button's image which means the image needs to be painted to its | 110 // behind the button's image which means the image needs to be painted to its |
| (...skipping 10 matching lines...) Expand all Loading... |
| 135 gfx::Point position = ComputeImagePaintPosition(img); | 121 gfx::Point position = ComputeImagePaintPosition(img); |
| 136 if (!background_image_.isNull()) | 122 if (!background_image_.isNull()) |
| 137 canvas->DrawImageInt(background_image_, position.x(), position.y()); | 123 canvas->DrawImageInt(background_image_, position.x(), position.y()); |
| 138 | 124 |
| 139 canvas->DrawImageInt(img, position.x(), position.y()); | 125 canvas->DrawImageInt(img, position.x(), position.y()); |
| 140 } | 126 } |
| 141 | 127 |
| 142 Painter::PaintFocusPainter(this, canvas, focus_painter()); | 128 Painter::PaintFocusPainter(this, canvas, focus_painter()); |
| 143 } | 129 } |
| 144 | 130 |
| 131 gfx::Size ImageButton::CalculatePreferredSize() const { |
| 132 gfx::Size size(kDefaultWidth, kDefaultHeight); |
| 133 if (!images_[STATE_NORMAL].isNull()) { |
| 134 size = gfx::Size(images_[STATE_NORMAL].width(), |
| 135 images_[STATE_NORMAL].height()); |
| 136 } |
| 137 |
| 138 size.SetToMax(minimum_image_size_); |
| 139 |
| 140 gfx::Insets insets = GetInsets(); |
| 141 size.Enlarge(insets.width(), insets.height()); |
| 142 return size; |
| 143 } |
| 144 |
| 145 //////////////////////////////////////////////////////////////////////////////// | 145 //////////////////////////////////////////////////////////////////////////////// |
| 146 // ImageButton, protected: | 146 // ImageButton, protected: |
| 147 | 147 |
| 148 void ImageButton::OnFocus() { | 148 void ImageButton::OnFocus() { |
| 149 CustomButton::OnFocus(); | 149 CustomButton::OnFocus(); |
| 150 if (focus_painter_.get()) | 150 if (focus_painter_.get()) |
| 151 SchedulePaint(); | 151 SchedulePaint(); |
| 152 } | 152 } |
| 153 | 153 |
| 154 void ImageButton::OnBlur() { | 154 void ImageButton::OnBlur() { |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 287 // accessible toggle button. | 287 // accessible toggle button. |
| 288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || | 288 if ((toggled_ && !images_[ButtonState::STATE_NORMAL].isNull()) || |
| 289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { | 289 (!toggled_ && !alternate_images_[ButtonState::STATE_NORMAL].isNull())) { |
| 290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; | 290 node_data->role = ui::AX_ROLE_TOGGLE_BUTTON; |
| 291 if (toggled_) | 291 if (toggled_) |
| 292 node_data->AddState(ui::AX_STATE_PRESSED); | 292 node_data->AddState(ui::AX_STATE_PRESSED); |
| 293 } | 293 } |
| 294 } | 294 } |
| 295 | 295 |
| 296 } // namespace views | 296 } // namespace views |
| OLD | NEW |