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/combobox/native_combobox_views.h" | 5 #include "ui/views/controls/combobox/native_combobox_views.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 | 153 |
154 void NativeComboboxViews::OnBlur() { | 154 void NativeComboboxViews::OnBlur() { |
155 NOTREACHED(); | 155 NOTREACHED(); |
156 } | 156 } |
157 | 157 |
158 ///////////////////////////////////////////////////////////////// | 158 ///////////////////////////////////////////////////////////////// |
159 // NativeComboboxViews, NativeComboboxWrapper overrides: | 159 // NativeComboboxViews, NativeComboboxWrapper overrides: |
160 | 160 |
161 void NativeComboboxViews::UpdateFromModel() { | 161 void NativeComboboxViews::UpdateFromModel() { |
162 int max_width = 0; | 162 int max_width = 0; |
163 const gfx::Font &font = GetFont(); | 163 const gfx::Font& font = Combobox::GetFont(); |
164 | 164 |
165 MenuItemView* menu = new MenuItemView(this); | 165 MenuItemView* menu = new MenuItemView(this); |
166 // MenuRunner owns |menu|. | 166 // MenuRunner owns |menu|. |
167 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); | 167 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); |
168 | 168 |
169 int num_items = combobox_->model()->GetItemCount(); | 169 int num_items = combobox_->model()->GetItemCount(); |
170 for (int i = 0; i < num_items; ++i) { | 170 for (int i = 0; i < num_items; ++i) { |
171 string16 text = combobox_->model()->GetItemAt(i); | 171 string16 text = combobox_->model()->GetItemAt(i); |
172 | 172 |
173 // Inserting the Unicode formatting characters if necessary so that the | 173 // Inserting the Unicode formatting characters if necessary so that the |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
261 SchedulePaint(); | 261 SchedulePaint(); |
262 } | 262 } |
263 | 263 |
264 bool NativeComboboxViews::GetAccelerator(int id, ui::Accelerator* accel) { | 264 bool NativeComboboxViews::GetAccelerator(int id, ui::Accelerator* accel) { |
265 return false; | 265 return false; |
266 } | 266 } |
267 | 267 |
268 ///////////////////////////////////////////////////////////////// | 268 ///////////////////////////////////////////////////////////////// |
269 // NativeComboboxViews private methods: | 269 // NativeComboboxViews private methods: |
270 | 270 |
271 const gfx::Font& NativeComboboxViews::GetFont() const { | |
272 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | |
273 return rb.GetFont(ResourceBundle::BaseFont); | |
274 } | |
275 | |
276 void NativeComboboxViews::AdjustBoundsForRTLUI(gfx::Rect* rect) const { | 271 void NativeComboboxViews::AdjustBoundsForRTLUI(gfx::Rect* rect) const { |
277 rect->set_x(GetMirroredXForRect(*rect)); | 272 rect->set_x(GetMirroredXForRect(*rect)); |
278 } | 273 } |
279 | 274 |
280 void NativeComboboxViews::PaintText(gfx::Canvas* canvas) { | 275 void NativeComboboxViews::PaintText(gfx::Canvas* canvas) { |
281 gfx::Insets insets = GetInsets(); | 276 gfx::Insets insets = GetInsets(); |
282 | 277 |
283 canvas->Save(); | 278 canvas->Save(); |
284 canvas->ClipRect(GetContentsBounds()); | 279 canvas->ClipRect(GetContentsBounds()); |
285 | 280 |
286 int x = insets.left(); | 281 int x = insets.left(); |
287 int y = insets.top(); | 282 int y = insets.top(); |
288 int text_height = height() - insets.height(); | 283 int text_height = height() - insets.height(); |
289 SkColor text_color = kTextColor; | 284 SkColor text_color = kTextColor; |
290 | 285 |
291 int index = GetSelectedItem(); | 286 int index = GetSelectedItem(); |
292 if (index < 0 || index > combobox_->model()->GetItemCount()) | 287 if (index < 0 || index > combobox_->model()->GetItemCount()) |
293 index = 0; | 288 index = 0; |
294 string16 text = combobox_->model()->GetItemAt(index); | 289 string16 text = combobox_->model()->GetItemAt(index); |
295 | 290 |
296 int disclosure_arrow_offset = width() - disclosure_arrow_->width() | 291 int disclosure_arrow_offset = width() - disclosure_arrow_->width() |
297 - kDisclosureArrowLeftPadding - kDisclosureArrowRightPadding; | 292 - kDisclosureArrowLeftPadding - kDisclosureArrowRightPadding; |
298 | 293 |
299 const gfx::Font& font = GetFont(); | 294 const gfx::Font& font = Combobox::GetFont(); |
300 int text_width = font.GetStringWidth(text); | 295 int text_width = font.GetStringWidth(text); |
301 if ((text_width + insets.width()) > disclosure_arrow_offset) | 296 if ((text_width + insets.width()) > disclosure_arrow_offset) |
302 text_width = disclosure_arrow_offset - insets.width(); | 297 text_width = disclosure_arrow_offset - insets.width(); |
303 | 298 |
304 gfx::Rect text_bounds(x, y, text_width, text_height); | 299 gfx::Rect text_bounds(x, y, text_width, text_height); |
305 AdjustBoundsForRTLUI(&text_bounds); | 300 AdjustBoundsForRTLUI(&text_bounds); |
306 canvas->DrawStringInt(text, font, text_color, text_bounds); | 301 canvas->DrawStringInt(text, font, text_color, text_bounds); |
307 | 302 |
308 gfx::Rect arrow_bounds(disclosure_arrow_offset + kDisclosureArrowLeftPadding, | 303 gfx::Rect arrow_bounds(disclosure_arrow_offset + kDisclosureArrowLeftPadding, |
309 height() / 2 - disclosure_arrow_->height() / 2, | 304 height() / 2 - disclosure_arrow_->height() / 2, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
356 | 351 |
357 #if defined(USE_AURA) | 352 #if defined(USE_AURA) |
358 // static | 353 // static |
359 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( | 354 NativeComboboxWrapper* NativeComboboxWrapper::CreateWrapper( |
360 Combobox* combobox) { | 355 Combobox* combobox) { |
361 return new NativeComboboxViews(combobox); | 356 return new NativeComboboxViews(combobox); |
362 } | 357 } |
363 #endif | 358 #endif |
364 | 359 |
365 } // namespace views | 360 } // namespace views |
OLD | NEW |