OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "chrome/views/native_button.h" | 5 #include "chrome/views/native_button.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "chrome/common/gfx/chrome_canvas.h" |
8 #include "chrome/common/l10n_util.h" | 9 #include "chrome/common/l10n_util.h" |
9 #include "chrome/common/resource_bundle.h" | 10 #include "chrome/common/resource_bundle.h" |
10 #include "chrome/views/background.h" | 11 #include "chrome/views/background.h" |
11 | 12 |
12 namespace ChromeViews { | 13 namespace ChromeViews { |
13 | 14 |
14 NativeButton::NativeButton(const std::wstring& label) { | 15 NativeButton::NativeButton(const std::wstring& label) |
| 16 : enforce_dlu_min_size_(true) { |
15 Init(label, false); | 17 Init(label, false); |
16 } | 18 } |
17 | 19 |
18 NativeButton::NativeButton(const std::wstring& label, bool is_default) { | 20 NativeButton::NativeButton(const std::wstring& label, bool is_default) |
| 21 : enforce_dlu_min_size_(true) { |
19 Init(label, is_default); | 22 Init(label, is_default); |
20 } | 23 } |
21 | 24 |
22 NativeButton::~NativeButton() { | 25 NativeButton::~NativeButton() { |
23 } | 26 } |
24 | 27 |
25 void NativeButton::SetListener(Listener *l) { | 28 void NativeButton::SetListener(Listener *l) { |
26 listener_ = l; | 29 listener_ = l; |
27 } | 30 } |
28 | 31 |
29 void NativeButton::SetPadding(CSize size) { | 32 void NativeButton::SetPadding(CSize size) { |
30 padding_ = size; | 33 padding_ = size; |
31 } | 34 } |
32 | 35 |
33 void NativeButton::GetPreferredSize(CSize *out) { | 36 void NativeButton::GetPreferredSize(CSize *out) { |
34 HWND hwnd = GetNativeControlHWND(); | 37 HWND hwnd = GetNativeControlHWND(); |
35 if (hwnd) { | 38 if (hwnd) { |
36 SIZE sz = {0, 0}; | 39 SIZE sz = {0, 0}; |
37 ::SendMessage(hwnd, | 40 ::SendMessage(hwnd, |
38 BCM_GETIDEALSIZE, | 41 BCM_GETIDEALSIZE, |
39 0, | 42 0, |
40 reinterpret_cast<LPARAM>(&sz)); | 43 reinterpret_cast<LPARAM>(&sz)); |
41 sz.cx += 2 * padding_.cx; | 44 sz.cx += 2 * padding_.cx; |
42 sz.cy += 2 * padding_.cy; | 45 sz.cy += 2 * padding_.cy; |
43 | 46 |
44 if (min_dlu_size_.width()) | 47 if (enforce_dlu_min_size_) { |
45 sz.cx = std::max(static_cast<int>(sz.cx), | 48 if (min_dlu_size_.width()) { |
46 font_.horizontal_dlus_to_pixels(min_dlu_size_.width())); | 49 sz.cx = |
47 if (min_dlu_size_.height()) | 50 std::max(static_cast<int>(sz.cx), |
48 sz.cy = std::max(static_cast<int>(sz.cy), | 51 font_.horizontal_dlus_to_pixels(min_dlu_size_.width())); |
49 font_.vertical_dlus_to_pixels(min_dlu_size_.height())); | 52 } |
50 | 53 if (min_dlu_size_.height()) |
| 54 sz.cy = std::max(static_cast<int>(sz.cy), |
| 55 font_.vertical_dlus_to_pixels(min_dlu_size_.height())); |
| 56 } |
51 *out = sz; | 57 *out = sz; |
52 } | 58 } |
53 } | 59 } |
54 | 60 |
55 void NativeButton::SetLabel(const std::wstring& l) { | 61 void NativeButton::SetLabel(const std::wstring& l) { |
56 // Even though we create a flipped HWND for a native button when the locale | 62 // Even though we create a flipped HWND for a native button when the locale |
57 // is right-to-left, Windows does not render text for the button using a | 63 // is right-to-left, Windows does not render text for the button using a |
58 // right-to-left context (perhaps because the parent HWND is not flipped). | 64 // right-to-left context (perhaps because the parent HWND is not flipped). |
59 // The result is that RTL strings containing punctuation marks are not | 65 // The result is that RTL strings containing punctuation marks are not |
60 // displayed properly. For example, the string "...ABC" (where A, B and C are | 66 // displayed properly. For example, the string "...ABC" (where A, B and C are |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
179 | 185 |
180 bool NativeButton::OnKeyDown(int virtual_key_code) { | 186 bool NativeButton::OnKeyDown(int virtual_key_code) { |
181 if (virtual_key_code == VK_RETURN) { | 187 if (virtual_key_code == VK_RETURN) { |
182 Clicked(); | 188 Clicked(); |
183 return true; | 189 return true; |
184 } | 190 } |
185 return false; | 191 return false; |
186 } | 192 } |
187 | 193 |
188 } | 194 } |
189 | |
OLD | NEW |