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 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
584 source_type = ui::MENU_SOURCE_TOUCH; | 584 source_type = ui::MENU_SOURCE_TOUCH; |
585 ShowDropDownMenu(source_type); | 585 ShowDropDownMenu(source_type); |
586 } | 586 } |
587 } | 587 } |
588 | 588 |
589 void Combobox::UpdateFromModel() { | 589 void Combobox::UpdateFromModel() { |
590 const gfx::FontList& font_list = Combobox::GetFontList(); | 590 const gfx::FontList& font_list = Combobox::GetFontList(); |
591 | 591 |
592 MenuItemView* menu = new MenuItemView(this); | 592 MenuItemView* menu = new MenuItemView(this); |
593 // MenuRunner owns |menu|. | 593 // MenuRunner owns |menu|. |
594 dropdown_list_menu_runner_.reset(new MenuRunner(menu)); | 594 dropdown_list_menu_runner_.reset(new MenuRunner(menu, MenuRunner::COMBOBOX)); |
595 | 595 |
596 int num_items = model()->GetItemCount(); | 596 int num_items = model()->GetItemCount(); |
597 int width = 0; | 597 int width = 0; |
598 bool text_item_appended = false; | 598 bool text_item_appended = false; |
599 for (int i = 0; i < num_items; ++i) { | 599 for (int i = 0; i < num_items; ++i) { |
600 // When STYLE_ACTION is used, the first item and the following separators | 600 // When STYLE_ACTION is used, the first item and the following separators |
601 // are not added to the dropdown menu. It is assumed that the first item is | 601 // are not added to the dropdown menu. It is assumed that the first item is |
602 // always selected and rendered on the top of the action button. | 602 // always selected and rendered on the top of the action button. |
603 if (model()->IsItemSeparatorAt(i)) { | 603 if (model()->IsItemSeparatorAt(i)) { |
604 if (text_item_appended || style_ != STYLE_ACTION) | 604 if (text_item_appended || style_ != STYLE_ACTION) |
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
775 gfx::Rect bounds(menu_position, lb.size()); | 775 gfx::Rect bounds(menu_position, lb.size()); |
776 | 776 |
777 Button::ButtonState original_state = Button::STATE_NORMAL; | 777 Button::ButtonState original_state = Button::STATE_NORMAL; |
778 if (arrow_button_) { | 778 if (arrow_button_) { |
779 original_state = arrow_button_->state(); | 779 original_state = arrow_button_->state(); |
780 arrow_button_->SetState(Button::STATE_PRESSED); | 780 arrow_button_->SetState(Button::STATE_PRESSED); |
781 } | 781 } |
782 dropdown_open_ = true; | 782 dropdown_open_ = true; |
783 MenuAnchorPosition anchor_position = | 783 MenuAnchorPosition anchor_position = |
784 style_ == STYLE_ACTION ? MENU_ANCHOR_TOPRIGHT : MENU_ANCHOR_TOPLEFT; | 784 style_ == STYLE_ACTION ? MENU_ANCHOR_TOPRIGHT : MENU_ANCHOR_TOPLEFT; |
785 if (dropdown_list_menu_runner_->RunMenuAt(GetWidget(), NULL, bounds, | 785 if (dropdown_list_menu_runner_->RunMenuAt( |
786 anchor_position, source_type, | 786 GetWidget(), NULL, bounds, anchor_position, source_type) == |
787 MenuRunner::COMBOBOX) == | |
788 MenuRunner::MENU_DELETED) { | 787 MenuRunner::MENU_DELETED) { |
789 return; | 788 return; |
790 } | 789 } |
791 dropdown_open_ = false; | 790 dropdown_open_ = false; |
792 if (arrow_button_) | 791 if (arrow_button_) |
793 arrow_button_->SetState(original_state); | 792 arrow_button_->SetState(original_state); |
794 closed_time_ = base::Time::Now(); | 793 closed_time_ = base::Time::Now(); |
795 | 794 |
796 // Need to explicitly clear mouse handler so that events get sent | 795 // Need to explicitly clear mouse handler so that events get sent |
797 // properly after the menu finishes running. If we don't do this, then | 796 // properly after the menu finishes running. If we don't do this, then |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
854 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); | 853 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); |
855 #endif | 854 #endif |
856 | 855 |
857 ui::NativeTheme::ExtraParams ignored; | 856 ui::NativeTheme::ExtraParams ignored; |
858 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, | 857 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, |
859 ui::NativeTheme::kNormal, | 858 ui::NativeTheme::kNormal, |
860 ignored); | 859 ignored); |
861 } | 860 } |
862 | 861 |
863 } // namespace views | 862 } // namespace views |
OLD | NEW |