| 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" |
| 11 #include "ui/accessibility/ax_view_state.h" | 11 #include "ui/accessibility/ax_view_state.h" |
| 12 #include "ui/base/ime/input_method.h" |
| 12 #include "ui/base/models/combobox_model.h" | 13 #include "ui/base/models/combobox_model.h" |
| 13 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 14 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 15 #include "ui/events/keycodes/keyboard_codes.h" | 16 #include "ui/events/keycodes/keyboard_codes.h" |
| 16 #include "ui/gfx/animation/throb_animation.h" | 17 #include "ui/gfx/animation/throb_animation.h" |
| 17 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
| 18 #include "ui/gfx/image/image.h" | 19 #include "ui/gfx/image/image.h" |
| 19 #include "ui/gfx/scoped_canvas.h" | 20 #include "ui/gfx/scoped_canvas.h" |
| 20 #include "ui/gfx/text_utils.h" | 21 #include "ui/gfx/text_utils.h" |
| 21 #include "ui/native_theme/common_theme.h" | 22 #include "ui/native_theme/common_theme.h" |
| 22 #include "ui/native_theme/native_theme.h" | 23 #include "ui/native_theme/native_theme.h" |
| 23 #include "ui/resources/grit/ui_resources.h" | 24 #include "ui/resources/grit/ui_resources.h" |
| 24 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
| 25 #include "ui/views/color_constants.h" | 26 #include "ui/views/color_constants.h" |
| 26 #include "ui/views/controls/button/custom_button.h" | 27 #include "ui/views/controls/button/custom_button.h" |
| 27 #include "ui/views/controls/button/label_button.h" | 28 #include "ui/views/controls/button/label_button.h" |
| 28 #include "ui/views/controls/combobox/combobox_listener.h" | 29 #include "ui/views/controls/combobox/combobox_listener.h" |
| 29 #include "ui/views/controls/focusable_border.h" | 30 #include "ui/views/controls/focusable_border.h" |
| 30 #include "ui/views/controls/menu/menu_item_view.h" | 31 #include "ui/views/controls/menu/menu_item_view.h" |
| 31 #include "ui/views/controls/menu/menu_runner.h" | 32 #include "ui/views/controls/menu/menu_runner.h" |
| 32 #include "ui/views/controls/menu/menu_runner_handler.h" | 33 #include "ui/views/controls/menu/menu_runner_handler.h" |
| 33 #include "ui/views/controls/menu/submenu_view.h" | 34 #include "ui/views/controls/menu/submenu_view.h" |
| 34 #include "ui/views/controls/prefix_selector.h" | 35 #include "ui/views/controls/prefix_selector.h" |
| 35 #include "ui/views/controls/textfield/textfield.h" | 36 #include "ui/views/controls/textfield/textfield.h" |
| 36 #include "ui/views/ime/input_method.h" | |
| 37 #include "ui/views/mouse_constants.h" | 37 #include "ui/views/mouse_constants.h" |
| 38 #include "ui/views/painter.h" | 38 #include "ui/views/painter.h" |
| 39 #include "ui/views/widget/widget.h" | 39 #include "ui/views/widget/widget.h" |
| 40 | 40 |
| 41 namespace views { | 41 namespace views { |
| 42 | 42 |
| 43 namespace { | 43 namespace { |
| 44 | 44 |
| 45 // Menu border widths | 45 // Menu border widths |
| 46 const int kMenuBorderWidthLeft = 1; | 46 const int kMenuBorderWidthLeft = 1; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 text_button_->SetVisible(true); | 266 text_button_->SetVisible(true); |
| 267 arrow_button_->SetVisible(true); | 267 arrow_button_->SetVisible(true); |
| 268 text_button_->SetFocusable(false); | 268 text_button_->SetFocusable(false); |
| 269 arrow_button_->SetFocusable(false); | 269 arrow_button_->SetFocusable(false); |
| 270 AddChildView(text_button_); | 270 AddChildView(text_button_); |
| 271 AddChildView(arrow_button_); | 271 AddChildView(arrow_button_); |
| 272 } | 272 } |
| 273 | 273 |
| 274 Combobox::~Combobox() { | 274 Combobox::~Combobox() { |
| 275 model_->RemoveObserver(this); | 275 model_->RemoveObserver(this); |
| 276 if (GetTextInputClient() && GetInputMethod()) |
| 277 GetInputMethod()->DetachTextInputClient(GetTextInputClient()); |
| 276 } | 278 } |
| 277 | 279 |
| 278 // static | 280 // static |
| 279 const gfx::FontList& Combobox::GetFontList() { | 281 const gfx::FontList& Combobox::GetFontList() { |
| 280 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 282 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 281 return rb.GetFontList(ui::ResourceBundle::BaseFont); | 283 return rb.GetFontList(ui::ResourceBundle::BaseFont); |
| 282 } | 284 } |
| 283 | 285 |
| 284 void Combobox::SetStyle(Style style) { | 286 void Combobox::SetStyle(Style style) { |
| 285 if (style_ == style) | 287 if (style_ == style) |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 533 } | 535 } |
| 534 case STYLE_ACTION: { | 536 case STYLE_ACTION: { |
| 535 PaintButtons(canvas); | 537 PaintButtons(canvas); |
| 536 PaintText(canvas); | 538 PaintText(canvas); |
| 537 break; | 539 break; |
| 538 } | 540 } |
| 539 } | 541 } |
| 540 } | 542 } |
| 541 | 543 |
| 542 void Combobox::OnFocus() { | 544 void Combobox::OnFocus() { |
| 543 GetInputMethod()->OnFocus(); | 545 if (GetTextInputClient() && GetInputMethod()) |
| 546 GetInputMethod()->SetFocusedTextInputClient(GetTextInputClient()); |
| 547 |
| 544 View::OnFocus(); | 548 View::OnFocus(); |
| 545 // Border renders differently when focused. | 549 // Border renders differently when focused. |
| 546 SchedulePaint(); | 550 SchedulePaint(); |
| 547 } | 551 } |
| 548 | 552 |
| 549 void Combobox::OnBlur() { | 553 void Combobox::OnBlur() { |
| 550 GetInputMethod()->OnBlur(); | 554 if (GetTextInputClient() && GetInputMethod()) |
| 555 GetInputMethod()->DetachTextInputClient(GetTextInputClient()); |
| 556 |
| 551 if (selector_) | 557 if (selector_) |
| 552 selector_->OnViewBlur(); | 558 selector_->OnViewBlur(); |
| 553 // Border renders differently when focused. | 559 // Border renders differently when focused. |
| 554 SchedulePaint(); | 560 SchedulePaint(); |
| 555 } | 561 } |
| 556 | 562 |
| 557 void Combobox::GetAccessibleState(ui::AXViewState* state) { | 563 void Combobox::GetAccessibleState(ui::AXViewState* state) { |
| 558 state->role = ui::AX_ROLE_COMBO_BOX; | 564 state->role = ui::AX_ROLE_COMBO_BOX; |
| 559 state->name = accessible_name_; | 565 state->name = accessible_name_; |
| 560 state->value = model_->GetItemAt(selected_index_); | 566 state->value = model_->GetItemAt(selected_index_); |
| (...skipping 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 859 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); | 865 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); |
| 860 #endif | 866 #endif |
| 861 | 867 |
| 862 ui::NativeTheme::ExtraParams ignored; | 868 ui::NativeTheme::ExtraParams ignored; |
| 863 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, | 869 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, |
| 864 ui::NativeTheme::kNormal, | 870 ui::NativeTheme::kNormal, |
| 865 ignored); | 871 ignored); |
| 866 } | 872 } |
| 867 | 873 |
| 868 } // namespace views | 874 } // namespace views |
| OLD | NEW |