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/gfx/chrome_canvas.h" |
9 #include "chrome/common/l10n_util.h" | 9 #include "chrome/common/l10n_util.h" |
10 #include "chrome/common/resource_bundle.h" | 10 #include "chrome/common/resource_bundle.h" |
(...skipping 15 matching lines...) Expand all Loading... |
26 } | 26 } |
27 | 27 |
28 void NativeButton::SetListener(Listener *l) { | 28 void NativeButton::SetListener(Listener *l) { |
29 listener_ = l; | 29 listener_ = l; |
30 } | 30 } |
31 | 31 |
32 void NativeButton::SetPadding(CSize size) { | 32 void NativeButton::SetPadding(CSize size) { |
33 padding_ = size; | 33 padding_ = size; |
34 } | 34 } |
35 | 35 |
36 void NativeButton::GetPreferredSize(CSize *out) { | 36 gfx::Size NativeButton::GetPreferredSize() { |
37 HWND hwnd = GetNativeControlHWND(); | 37 HWND hwnd = GetNativeControlHWND(); |
38 if (hwnd) { | 38 if (hwnd) { |
39 SIZE sz = {0, 0}; | 39 SIZE sz = {0, 0}; |
40 ::SendMessage(hwnd, | 40 ::SendMessage(hwnd, |
41 BCM_GETIDEALSIZE, | 41 BCM_GETIDEALSIZE, |
42 0, | 42 0, |
43 reinterpret_cast<LPARAM>(&sz)); | 43 reinterpret_cast<LPARAM>(&sz)); |
44 sz.cx += 2 * padding_.cx; | 44 sz.cx += 2 * padding_.cx; |
45 sz.cy += 2 * padding_.cy; | 45 sz.cy += 2 * padding_.cy; |
46 | 46 |
47 if (enforce_dlu_min_size_) { | 47 if (enforce_dlu_min_size_) { |
48 if (min_dlu_size_.width()) { | 48 if (min_dlu_size_.width()) { |
49 sz.cx = | 49 sz.cx = |
50 std::max(static_cast<int>(sz.cx), | 50 std::max(static_cast<int>(sz.cx), |
51 font_.horizontal_dlus_to_pixels(min_dlu_size_.width())); | 51 font_.horizontal_dlus_to_pixels(min_dlu_size_.width())); |
52 } | 52 } |
53 if (min_dlu_size_.height()) | 53 if (min_dlu_size_.height()) |
54 sz.cy = std::max(static_cast<int>(sz.cy), | 54 sz.cy = std::max(static_cast<int>(sz.cy), |
55 font_.vertical_dlus_to_pixels(min_dlu_size_.height())); | 55 font_.vertical_dlus_to_pixels(min_dlu_size_.height())); |
56 } | 56 } |
57 *out = sz; | 57 return gfx::Size(sz.cx, sz.cy); |
58 } | 58 } |
| 59 return gfx::Size(); |
59 } | 60 } |
60 | 61 |
61 void NativeButton::SetLabel(const std::wstring& l) { | 62 void NativeButton::SetLabel(const std::wstring& l) { |
62 // Even though we create a flipped HWND for a native button when the locale | 63 // Even though we create a flipped HWND for a native button when the locale |
63 // is right-to-left, Windows does not render text for the button using a | 64 // is right-to-left, Windows does not render text for the button using a |
64 // right-to-left context (perhaps because the parent HWND is not flipped). | 65 // right-to-left context (perhaps because the parent HWND is not flipped). |
65 // The result is that RTL strings containing punctuation marks are not | 66 // The result is that RTL strings containing punctuation marks are not |
66 // displayed properly. For example, the string "...ABC" (where A, B and C are | 67 // displayed properly. For example, the string "...ABC" (where A, B and C are |
67 // Hebrew characters) is displayed as "ABC..." which is incorrect. | 68 // Hebrew characters) is displayed as "ABC..." which is incorrect. |
68 // | 69 // |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 186 |
186 bool NativeButton::OnKeyDown(int virtual_key_code) { | 187 bool NativeButton::OnKeyDown(int virtual_key_code) { |
187 if (virtual_key_code == VK_RETURN) { | 188 if (virtual_key_code == VK_RETURN) { |
188 Clicked(); | 189 Clicked(); |
189 return true; | 190 return true; |
190 } | 191 } |
191 return false; | 192 return false; |
192 } | 193 } |
193 | 194 |
194 } | 195 } |
OLD | NEW |