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/combo_box.h" | 5 #include "chrome/views/combo_box.h" |
6 | 6 |
7 #include "base/gfx/native_theme.h" | 7 #include "base/gfx/native_theme.h" |
8 #include "base/gfx/rect.h" | 8 #include "base/gfx/rect.h" |
9 #include "chrome/common/gfx/chrome_canvas.h" | 9 #include "chrome/common/gfx/chrome_canvas.h" |
10 #include "chrome/common/gfx/chrome_font.h" | 10 #include "chrome/common/gfx/chrome_font.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 GetComboBoxInfo(hwnd, &cbi); | 44 GetComboBoxInfo(hwnd, &cbi); |
45 gfx::Rect rect_item(cbi.rcItem); | 45 gfx::Rect rect_item(cbi.rcItem); |
46 gfx::Rect rect_button(cbi.rcButton); | 46 gfx::Rect rect_button(cbi.rcButton); |
47 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( | 47 gfx::Size border = gfx::NativeTheme::instance()->GetThemeBorderSize( |
48 gfx::NativeTheme::MENULIST); | 48 gfx::NativeTheme::MENULIST); |
49 | 49 |
50 // The padding value of '3' is the xy offset from the corner of the control | 50 // The padding value of '3' is the xy offset from the corner of the control |
51 // to the corner of rcItem. It does not seem to be queryable from the theme. | 51 // to the corner of rcItem. It does not seem to be queryable from the theme. |
52 // It is consistent on all versions of Windows from 2K to Vista, and is | 52 // It is consistent on all versions of Windows from 2K to Vista, and is |
53 // invariant with respect to the combobox border size. We could conceivably | 53 // invariant with respect to the combobox border size. We could conceivably |
54 // get this number from rect_item.x, but it seems fragile to depend on positio
n | 54 // get this number from rect_item.x, but it seems fragile to depend on |
55 // here, inside of the layout code. | 55 // position here, inside of the layout code. |
56 const int kItemOffset = 3; | 56 const int kItemOffset = 3; |
57 int item_to_button_distance = std::max(kItemOffset - border.width(), 0); | 57 int item_to_button_distance = std::max(kItemOffset - border.width(), 0); |
58 | 58 |
59 // The cx computation can be read as measuring from left to right. | 59 // The cx computation can be read as measuring from left to right. |
60 int pref_width = std::max(kItemOffset + content_width_ + | 60 int pref_width = std::max(kItemOffset + content_width_ + |
61 kComboboxExtraPaddingX + | 61 kComboboxExtraPaddingX + |
62 item_to_button_distance + rect_button.width() + | 62 item_to_button_distance + rect_button.width() + |
63 border.width(), kMinComboboxWidth); | 63 border.width(), kMinComboboxWidth); |
64 // The two arguments to ::max below should be typically be equal. | 64 // The two arguments to ::max below should be typically be equal. |
65 int pref_height = std::max(rect_item.height() + 2 * kItemOffset, | 65 int pref_height = std::max(rect_item.height() + 2 * kItemOffset, |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
158 // CB_SELECTSTRING does). | 158 // CB_SELECTSTRING does). |
159 ::SendMessage(hwnd, CB_SETCURSEL, selected_item_, 0); | 159 ::SendMessage(hwnd, CB_SETCURSEL, selected_item_, 0); |
160 } | 160 } |
161 | 161 |
162 int ComboBox::GetSelectedItem() { | 162 int ComboBox::GetSelectedItem() { |
163 return selected_item_; | 163 return selected_item_; |
164 } | 164 } |
165 | 165 |
166 } // namespace views | 166 } // namespace views |
167 | 167 |
OLD | NEW |