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/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| 11 #include "ui/base/ime/input_method.h" |
11 #include "ui/base/models/combobox_model.h" | 12 #include "ui/base/models/combobox_model.h" |
12 #include "ui/base/resource/resource_bundle.h" | 13 #include "ui/base/resource/resource_bundle.h" |
13 #include "ui/events/event.h" | 14 #include "ui/events/event.h" |
14 #include "ui/events/keycodes/keyboard_codes.h" | 15 #include "ui/events/keycodes/keyboard_codes.h" |
15 #include "ui/gfx/animation/throb_animation.h" | 16 #include "ui/gfx/animation/throb_animation.h" |
16 #include "ui/gfx/canvas.h" | 17 #include "ui/gfx/canvas.h" |
17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
18 #include "ui/gfx/scoped_canvas.h" | 19 #include "ui/gfx/scoped_canvas.h" |
19 #include "ui/gfx/text_utils.h" | 20 #include "ui/gfx/text_utils.h" |
20 #include "ui/native_theme/common_theme.h" | 21 #include "ui/native_theme/common_theme.h" |
21 #include "ui/native_theme/native_theme.h" | 22 #include "ui/native_theme/native_theme.h" |
22 #include "ui/resources/grit/ui_resources.h" | 23 #include "ui/resources/grit/ui_resources.h" |
23 #include "ui/views/background.h" | 24 #include "ui/views/background.h" |
24 #include "ui/views/color_constants.h" | 25 #include "ui/views/color_constants.h" |
25 #include "ui/views/controls/button/custom_button.h" | 26 #include "ui/views/controls/button/custom_button.h" |
26 #include "ui/views/controls/button/label_button.h" | 27 #include "ui/views/controls/button/label_button.h" |
27 #include "ui/views/controls/combobox/combobox_listener.h" | 28 #include "ui/views/controls/combobox/combobox_listener.h" |
28 #include "ui/views/controls/focusable_border.h" | 29 #include "ui/views/controls/focusable_border.h" |
29 #include "ui/views/controls/menu/menu_item_view.h" | 30 #include "ui/views/controls/menu/menu_item_view.h" |
30 #include "ui/views/controls/menu/menu_runner.h" | 31 #include "ui/views/controls/menu/menu_runner.h" |
31 #include "ui/views/controls/menu/menu_runner_handler.h" | 32 #include "ui/views/controls/menu/menu_runner_handler.h" |
32 #include "ui/views/controls/menu/submenu_view.h" | 33 #include "ui/views/controls/menu/submenu_view.h" |
33 #include "ui/views/controls/prefix_selector.h" | 34 #include "ui/views/controls/prefix_selector.h" |
34 #include "ui/views/controls/textfield/textfield.h" | 35 #include "ui/views/controls/textfield/textfield.h" |
35 #include "ui/views/ime/input_method.h" | |
36 #include "ui/views/mouse_constants.h" | 36 #include "ui/views/mouse_constants.h" |
37 #include "ui/views/painter.h" | 37 #include "ui/views/painter.h" |
38 #include "ui/views/resources/grit/views_resources.h" | 38 #include "ui/views/resources/grit/views_resources.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 |
(...skipping 220 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 |
| 277 if (GetInputMethod() && selector_.get()) { |
| 278 // Combobox should have been blurred before destroy. |
| 279 DCHECK(selector_.get() != GetInputMethod()->GetTextInputClient()); |
| 280 } |
276 } | 281 } |
277 | 282 |
278 // static | 283 // static |
279 const gfx::FontList& Combobox::GetFontList() { | 284 const gfx::FontList& Combobox::GetFontList() { |
280 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 285 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
281 return rb.GetFontList(ui::ResourceBundle::BaseFont); | 286 return rb.GetFontList(ui::ResourceBundle::BaseFont); |
282 } | 287 } |
283 | 288 |
284 void Combobox::SetStyle(Style style) { | 289 void Combobox::SetStyle(Style style) { |
285 if (style_ == style) | 290 if (style_ == style) |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
328 void Combobox::SetInvalid(bool invalid) { | 333 void Combobox::SetInvalid(bool invalid) { |
329 if (invalid == invalid_) | 334 if (invalid == invalid_) |
330 return; | 335 return; |
331 | 336 |
332 invalid_ = invalid; | 337 invalid_ = invalid; |
333 | 338 |
334 UpdateBorder(); | 339 UpdateBorder(); |
335 SchedulePaint(); | 340 SchedulePaint(); |
336 } | 341 } |
337 | 342 |
338 ui::TextInputClient* Combobox::GetTextInputClient() { | |
339 if (!selector_) | |
340 selector_.reset(new PrefixSelector(this)); | |
341 return selector_.get(); | |
342 } | |
343 | |
344 void Combobox::Layout() { | 343 void Combobox::Layout() { |
345 PrefixDelegate::Layout(); | 344 PrefixDelegate::Layout(); |
346 | 345 |
347 gfx::Insets insets = GetInsets(); | 346 gfx::Insets insets = GetInsets(); |
348 int text_button_width = 0; | 347 int text_button_width = 0; |
349 int arrow_button_width = 0; | 348 int arrow_button_width = 0; |
350 | 349 |
351 switch (style_) { | 350 switch (style_) { |
352 case STYLE_NORMAL: { | 351 case STYLE_NORMAL: { |
353 arrow_button_width = width(); | 352 arrow_button_width = width(); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
533 } | 532 } |
534 case STYLE_ACTION: { | 533 case STYLE_ACTION: { |
535 PaintButtons(canvas); | 534 PaintButtons(canvas); |
536 PaintText(canvas); | 535 PaintText(canvas); |
537 break; | 536 break; |
538 } | 537 } |
539 } | 538 } |
540 } | 539 } |
541 | 540 |
542 void Combobox::OnFocus() { | 541 void Combobox::OnFocus() { |
543 GetInputMethod()->OnFocus(); | 542 if (GetInputMethod()) |
| 543 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); |
| 544 |
544 View::OnFocus(); | 545 View::OnFocus(); |
545 // Border renders differently when focused. | 546 // Border renders differently when focused. |
546 SchedulePaint(); | 547 SchedulePaint(); |
547 } | 548 } |
548 | 549 |
549 void Combobox::OnBlur() { | 550 void Combobox::OnBlur() { |
550 GetInputMethod()->OnBlur(); | 551 if (GetInputMethod()) |
| 552 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); |
| 553 |
551 if (selector_) | 554 if (selector_) |
552 selector_->OnViewBlur(); | 555 selector_->OnViewBlur(); |
553 // Border renders differently when focused. | 556 // Border renders differently when focused. |
554 SchedulePaint(); | 557 SchedulePaint(); |
555 } | 558 } |
556 | 559 |
557 void Combobox::GetAccessibleState(ui::AXViewState* state) { | 560 void Combobox::GetAccessibleState(ui::AXViewState* state) { |
558 state->role = ui::AX_ROLE_COMBO_BOX; | 561 state->role = ui::AX_ROLE_COMBO_BOX; |
559 state->name = accessible_name_; | 562 state->name = accessible_name_; |
560 state->value = model_->GetItemAt(selected_index_); | 563 state->value = model_->GetItemAt(selected_index_); |
(...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 #else | 861 #else |
859 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); | 862 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); |
860 #endif | 863 #endif |
861 | 864 |
862 ui::NativeTheme::ExtraParams ignored; | 865 ui::NativeTheme::ExtraParams ignored; |
863 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, | 866 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, |
864 ui::NativeTheme::kNormal, | 867 ui::NativeTheme::kNormal, |
865 ignored); | 868 ignored); |
866 } | 869 } |
867 | 870 |
| 871 PrefixSelector* Combobox::GetPrefixSelector() { |
| 872 if (!selector_) |
| 873 selector_.reset(new PrefixSelector(this)); |
| 874 return selector_.get(); |
| 875 } |
| 876 |
868 } // namespace views | 877 } // namespace views |
OLD | NEW |