| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this | 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. Use of this |
| 2 // source code is governed by a BSD-style license that can be found in the | 2 // source code is governed by a BSD-style license that can be found in the |
| 3 // LICENSE file. | 3 // LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/views/controls/button/native_button.h" | 5 #include "chrome/views/controls/button/native_button.h" |
| 6 | 6 |
| 7 #if defined(OS_LINUX) |
| 8 #include <gdk/gdkkeysyms.h> |
| 9 #endif |
| 10 |
| 7 #include "app/l10n_util.h" | 11 #include "app/l10n_util.h" |
| 8 #include "base/logging.h" | 12 #include "base/logging.h" |
| 9 | 13 |
| 10 namespace views { | 14 namespace views { |
| 11 | 15 |
| 12 static int kButtonBorderHWidth = 8; | 16 static int kButtonBorderHWidth = 8; |
| 13 | 17 |
| 14 // static | 18 // static |
| 15 const char NativeButton::kViewClassName[] = "chrome/views/NativeButton"; | 19 const char NativeButton::kViewClassName[] = "chrome/views/NativeButton"; |
| 16 | 20 |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 if (l10n_util::AdjustStringForLocaleDirection(label_, &localized_label)) | 66 if (l10n_util::AdjustStringForLocaleDirection(label_, &localized_label)) |
| 63 label_ = localized_label; | 67 label_ = localized_label; |
| 64 | 68 |
| 65 if (native_wrapper_) | 69 if (native_wrapper_) |
| 66 native_wrapper_->UpdateLabel(); | 70 native_wrapper_->UpdateLabel(); |
| 67 } | 71 } |
| 68 | 72 |
| 69 void NativeButton::SetIsDefault(bool is_default) { | 73 void NativeButton::SetIsDefault(bool is_default) { |
| 70 if (is_default == is_default_) | 74 if (is_default == is_default_) |
| 71 return; | 75 return; |
| 76 #if defined(OS_WIN) |
| 77 int return_code = VK_RETURN; |
| 78 #else |
| 79 int return_code = GDK_Return; |
| 80 #endif |
| 72 if (is_default) | 81 if (is_default) |
| 73 AddAccelerator(Accelerator(VK_RETURN, false, false, false)); | 82 AddAccelerator(Accelerator(return_code, false, false, false)); |
| 74 else | 83 else |
| 75 RemoveAccelerator(Accelerator(VK_RETURN, false, false, false)); | 84 RemoveAccelerator(Accelerator(return_code, false, false, false)); |
| 76 SetAppearsAsDefault(is_default); | 85 SetAppearsAsDefault(is_default); |
| 77 } | 86 } |
| 78 | 87 |
| 79 void NativeButton::SetAppearsAsDefault(bool appears_as_default) { | 88 void NativeButton::SetAppearsAsDefault(bool appears_as_default) { |
| 80 is_default_ = appears_as_default; | 89 is_default_ = appears_as_default; |
| 81 if (native_wrapper_) | 90 if (native_wrapper_) |
| 82 native_wrapper_->UpdateDefault(); | 91 native_wrapper_->UpdateDefault(); |
| 83 } | 92 } |
| 84 | 93 |
| 85 void NativeButton::ButtonPressed() { | 94 void NativeButton::ButtonPressed() { |
| (...skipping 13 matching lines...) Expand all Loading... |
| 99 gfx::Size sz = native_wrapper_->GetView()->GetPreferredSize(); | 108 gfx::Size sz = native_wrapper_->GetView()->GetPreferredSize(); |
| 100 | 109 |
| 101 // Add in the border size. (Do this before clamping the minimum size in case | 110 // Add in the border size. (Do this before clamping the minimum size in case |
| 102 // that clamping causes an increase in size that would include the borders. | 111 // that clamping causes an increase in size that would include the borders. |
| 103 gfx::Insets border = GetInsets(); | 112 gfx::Insets border = GetInsets(); |
| 104 sz.set_width(sz.width() + border.left() + border.right()); | 113 sz.set_width(sz.width() + border.left() + border.right()); |
| 105 sz.set_height(sz.height() + border.top() + border.bottom()); | 114 sz.set_height(sz.height() + border.top() + border.bottom()); |
| 106 | 115 |
| 107 // Clamp the size returned to at least the minimum size. | 116 // Clamp the size returned to at least the minimum size. |
| 108 if (!ignore_minimum_size_) { | 117 if (!ignore_minimum_size_) { |
| 118 #if defined(OS_WIN) |
| 109 if (minimum_size_.width()) { | 119 if (minimum_size_.width()) { |
| 110 int min_width = font_.horizontal_dlus_to_pixels(minimum_size_.width()); | 120 int min_width = font_.horizontal_dlus_to_pixels(minimum_size_.width()); |
| 111 sz.set_width(std::max(static_cast<int>(sz.width()), min_width)); | 121 sz.set_width(std::max(static_cast<int>(sz.width()), min_width)); |
| 112 } | 122 } |
| 113 if (minimum_size_.height()) { | 123 if (minimum_size_.height()) { |
| 114 int min_height = font_.vertical_dlus_to_pixels(minimum_size_.height()); | 124 int min_height = font_.vertical_dlus_to_pixels(minimum_size_.height()); |
| 115 sz.set_height(std::max(static_cast<int>(sz.height()), min_height)); | 125 sz.set_height(std::max(static_cast<int>(sz.height()), min_height)); |
| 116 } | 126 } |
| 127 #else |
| 128 if (minimum_size_.width() || minimum_size_.height()) |
| 129 NOTIMPLEMENTED(); |
| 130 #endif |
| 117 } | 131 } |
| 118 | 132 |
| 119 return sz; | 133 return sz; |
| 120 } | 134 } |
| 121 | 135 |
| 122 void NativeButton::Layout() { | 136 void NativeButton::Layout() { |
| 123 if (native_wrapper_) { | 137 if (native_wrapper_) { |
| 124 native_wrapper_->GetView()->SetBounds(0, 0, width(), height()); | 138 native_wrapper_->GetView()->SetBounds(0, 0, width(), height()); |
| 125 native_wrapper_->GetView()->Layout(); | 139 native_wrapper_->GetView()->Layout(); |
| 126 } | 140 } |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 native_wrapper_->UpdateLabel(); | 183 native_wrapper_->UpdateLabel(); |
| 170 native_wrapper_->UpdateEnabled(); | 184 native_wrapper_->UpdateEnabled(); |
| 171 } | 185 } |
| 172 | 186 |
| 173 void NativeButton::InitBorder() { | 187 void NativeButton::InitBorder() { |
| 174 set_border(Border::CreateEmptyBorder(0, kButtonBorderHWidth, 0, | 188 set_border(Border::CreateEmptyBorder(0, kButtonBorderHWidth, 0, |
| 175 kButtonBorderHWidth)); | 189 kButtonBorderHWidth)); |
| 176 } | 190 } |
| 177 | 191 |
| 178 } // namespace views | 192 } // namespace views |
| OLD | NEW |