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/combobox.h" | 5 #include "ui/views/controls/combobox/combobox.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/message_loop/message_loop_proxy.h" | 9 #include "base/message_loop/message_loop_proxy.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 gfx::Canvas* canvas, | 211 gfx::Canvas* canvas, |
212 const std::vector<const gfx::ImageSkia*>& arrow_button_images, | 212 const std::vector<const gfx::ImageSkia*>& arrow_button_images, |
213 int x, int height) { | 213 int x, int height) { |
214 PaintImagesVertically(canvas, | 214 PaintImagesVertically(canvas, |
215 *arrow_button_images[0], | 215 *arrow_button_images[0], |
216 *arrow_button_images[1], | 216 *arrow_button_images[1], |
217 *arrow_button_images[2], | 217 *arrow_button_images[2], |
218 x, 0, arrow_button_images[0]->width(), height); | 218 x, 0, arrow_button_images[0]->width(), height); |
219 } | 219 } |
220 | 220 |
221 // Returns the size of the disclosure arrow. | |
222 gfx::Size ArrowSize(const ui::NativeTheme* native_theme) { | |
223 ui::NativeTheme::ExtraParams ignored; | |
224 return native_theme->GetPartSize(ui::NativeTheme::kComboboxArrow, | |
225 ui::NativeTheme::kNormal, | |
226 ignored); | |
227 } | |
228 | |
229 } // namespace | 221 } // namespace |
230 | 222 |
231 // static | 223 // static |
232 const char Combobox::kViewClassName[] = "views/Combobox"; | 224 const char Combobox::kViewClassName[] = "views/Combobox"; |
233 | 225 |
234 //////////////////////////////////////////////////////////////////////////////// | 226 //////////////////////////////////////////////////////////////////////////////// |
235 // Combobox, public: | 227 // Combobox, public: |
236 | 228 |
237 Combobox::Combobox(ui::ComboboxModel* model) | 229 Combobox::Combobox(ui::ComboboxModel* model) |
238 : model_(model), | 230 : model_(model), |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 int text_button_width = 0; | 346 int text_button_width = 0; |
355 int arrow_button_width = 0; | 347 int arrow_button_width = 0; |
356 | 348 |
357 switch (style_) { | 349 switch (style_) { |
358 case STYLE_NORMAL: { | 350 case STYLE_NORMAL: { |
359 arrow_button_width = width(); | 351 arrow_button_width = width(); |
360 break; | 352 break; |
361 } | 353 } |
362 case STYLE_ACTION: { | 354 case STYLE_ACTION: { |
363 arrow_button_width = GetDisclosureArrowLeftPadding() + | 355 arrow_button_width = GetDisclosureArrowLeftPadding() + |
364 ArrowSize(GetNativeTheme()).width() + | 356 ArrowSize().width() + |
365 GetDisclosureArrowRightPadding(); | 357 GetDisclosureArrowRightPadding(); |
366 text_button_width = width() - arrow_button_width; | 358 text_button_width = width() - arrow_button_width; |
367 break; | 359 break; |
368 } | 360 } |
369 } | 361 } |
370 | 362 |
371 int arrow_button_x = std::max(0, text_button_width); | 363 int arrow_button_x = std::max(0, text_button_width); |
372 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); | 364 text_button_->SetBounds(0, 0, std::max(0, text_button_width), height()); |
373 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); | 365 arrow_button_->SetBounds(arrow_button_x, 0, arrow_button_width, height()); |
374 } | 366 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
412 | 404 |
413 //////////////////////////////////////////////////////////////////////////////// | 405 //////////////////////////////////////////////////////////////////////////////// |
414 // Combobox, View overrides: | 406 // Combobox, View overrides: |
415 | 407 |
416 gfx::Size Combobox::GetPreferredSize() const { | 408 gfx::Size Combobox::GetPreferredSize() const { |
417 // The preferred size will drive the local bounds which in turn is used to set | 409 // The preferred size will drive the local bounds which in turn is used to set |
418 // the minimum width for the dropdown list. | 410 // the minimum width for the dropdown list. |
419 gfx::Insets insets = GetInsets(); | 411 gfx::Insets insets = GetInsets(); |
420 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + | 412 int total_width = std::max(kMinComboboxWidth, content_size_.width()) + |
421 insets.width() + GetDisclosureArrowLeftPadding() + | 413 insets.width() + GetDisclosureArrowLeftPadding() + |
422 ArrowSize(GetNativeTheme()).width() + GetDisclosureArrowRightPadding(); | 414 ArrowSize().width() + GetDisclosureArrowRightPadding(); |
423 return gfx::Size(total_width, content_size_.height() + insets.height()); | 415 return gfx::Size(total_width, content_size_.height() + insets.height()); |
424 } | 416 } |
425 | 417 |
426 const char* Combobox::GetClassName() const { | 418 const char* Combobox::GetClassName() const { |
427 return kViewClassName; | 419 return kViewClassName; |
428 } | 420 } |
429 | 421 |
430 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { | 422 bool Combobox::SkipDefaultKeyEventProcessing(const ui::KeyEvent& e) { |
431 // Escape should close the drop down list when it is active, not host UI. | 423 // Escape should close the drop down list when it is active, not host UI. |
432 if (e.key_code() != ui::VKEY_ESCAPE || | 424 if (e.key_code() != ui::VKEY_ESCAPE || |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
656 int text_height = height() - insets.height(); | 648 int text_height = height() - insets.height(); |
657 SkColor text_color = GetNativeTheme()->GetSystemColor( | 649 SkColor text_color = GetNativeTheme()->GetSystemColor( |
658 ui::NativeTheme::kColorId_LabelEnabledColor); | 650 ui::NativeTheme::kColorId_LabelEnabledColor); |
659 | 651 |
660 DCHECK_GE(selected_index_, 0); | 652 DCHECK_GE(selected_index_, 0); |
661 DCHECK_LT(selected_index_, model()->GetItemCount()); | 653 DCHECK_LT(selected_index_, model()->GetItemCount()); |
662 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) | 654 if (selected_index_ < 0 || selected_index_ > model()->GetItemCount()) |
663 selected_index_ = 0; | 655 selected_index_ = 0; |
664 base::string16 text = model()->GetItemAt(selected_index_); | 656 base::string16 text = model()->GetItemAt(selected_index_); |
665 | 657 |
666 gfx::Size arrow_size = ArrowSize(GetNativeTheme()); | 658 gfx::Size arrow_size = ArrowSize(); |
667 int disclosure_arrow_offset = width() - arrow_size.width() - | 659 int disclosure_arrow_offset = width() - arrow_size.width() - |
668 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); | 660 GetDisclosureArrowLeftPadding() - GetDisclosureArrowRightPadding(); |
669 | 661 |
670 const gfx::FontList& font_list = Combobox::GetFontList(); | 662 const gfx::FontList& font_list = Combobox::GetFontList(); |
671 int text_width = gfx::GetStringWidth(text, font_list); | 663 int text_width = gfx::GetStringWidth(text, font_list); |
672 if ((text_width + insets.width()) > disclosure_arrow_offset) | 664 if ((text_width + insets.width()) > disclosure_arrow_offset) |
673 text_width = disclosure_arrow_offset - insets.width(); | 665 text_width = disclosure_arrow_offset - insets.width(); |
674 | 666 |
675 gfx::Rect text_bounds(x, y, text_width, text_height); | 667 gfx::Rect text_bounds(x, y, text_width, text_height); |
676 AdjustBoundsForRTLUI(&text_bounds); | 668 AdjustBoundsForRTLUI(&text_bounds); |
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
843 switch (style_) { | 835 switch (style_) { |
844 case STYLE_NORMAL: | 836 case STYLE_NORMAL: |
845 return kDisclosureArrowRightPadding; | 837 return kDisclosureArrowRightPadding; |
846 case STYLE_ACTION: | 838 case STYLE_ACTION: |
847 return kDisclosureArrowButtonRightPadding; | 839 return kDisclosureArrowButtonRightPadding; |
848 } | 840 } |
849 NOTREACHED(); | 841 NOTREACHED(); |
850 return 0; | 842 return 0; |
851 } | 843 } |
852 | 844 |
| 845 gfx::Size Combobox::ArrowSize() const { |
| 846 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) |
| 847 // TODO(estade): hack alert! This should always use GetNativeTheme(). For now |
| 848 // STYLE_ACTION isn't properly themed so we have to override the NativeTheme |
| 849 // behavior. See crbug.com/384071 |
| 850 const ui::NativeTheme* native_theme_for_arrow = style_ == STYLE_ACTION ? |
| 851 ui::NativeTheme::instance() : |
| 852 GetNativeTheme(); |
| 853 #else |
| 854 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); |
| 855 #endif |
| 856 |
| 857 ui::NativeTheme::ExtraParams ignored; |
| 858 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, |
| 859 ui::NativeTheme::kNormal, |
| 860 ignored); |
| 861 } |
| 862 |
853 } // namespace views | 863 } // namespace views |
OLD | NEW |