Chromium Code Reviews| 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 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 265 | 265 |
| 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); |
|
sky
2015/06/29 02:17:41
Here you don't detach from ime, but you do in ~Tex
Shu Chen
2015/06/29 02:56:34
Textfield is a TextInputClient, while Combobox is
sky
2015/06/29 17:03:49
As I mentioned, it is unusual that PrefixSelector
Shu Chen
2015/06/30 00:54:06
Done. I've added the DCHECK here.
| |
| 276 } | 276 } |
| 277 | 277 |
| 278 // static | 278 // static |
| 279 const gfx::FontList& Combobox::GetFontList() { | 279 const gfx::FontList& Combobox::GetFontList() { |
| 280 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 280 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 281 return rb.GetFontList(ui::ResourceBundle::BaseFont); | 281 return rb.GetFontList(ui::ResourceBundle::BaseFont); |
| 282 } | 282 } |
| 283 | 283 |
| 284 void Combobox::SetStyle(Style style) { | 284 void Combobox::SetStyle(Style style) { |
| 285 if (style_ == style) | 285 if (style_ == style) |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 328 void Combobox::SetInvalid(bool invalid) { | 328 void Combobox::SetInvalid(bool invalid) { |
| 329 if (invalid == invalid_) | 329 if (invalid == invalid_) |
| 330 return; | 330 return; |
| 331 | 331 |
| 332 invalid_ = invalid; | 332 invalid_ = invalid; |
| 333 | 333 |
| 334 UpdateBorder(); | 334 UpdateBorder(); |
| 335 SchedulePaint(); | 335 SchedulePaint(); |
| 336 } | 336 } |
| 337 | 337 |
| 338 ui::TextInputClient* Combobox::GetTextInputClient() { | |
| 339 if (!selector_) | |
| 340 selector_.reset(new PrefixSelector(this)); | |
| 341 return selector_.get(); | |
| 342 } | |
| 343 | |
| 344 void Combobox::Layout() { | 338 void Combobox::Layout() { |
| 345 PrefixDelegate::Layout(); | 339 PrefixDelegate::Layout(); |
| 346 | 340 |
| 347 gfx::Insets insets = GetInsets(); | 341 gfx::Insets insets = GetInsets(); |
| 348 int text_button_width = 0; | 342 int text_button_width = 0; |
| 349 int arrow_button_width = 0; | 343 int arrow_button_width = 0; |
| 350 | 344 |
| 351 switch (style_) { | 345 switch (style_) { |
| 352 case STYLE_NORMAL: { | 346 case STYLE_NORMAL: { |
| 353 arrow_button_width = width(); | 347 arrow_button_width = width(); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 533 } | 527 } |
| 534 case STYLE_ACTION: { | 528 case STYLE_ACTION: { |
| 535 PaintButtons(canvas); | 529 PaintButtons(canvas); |
| 536 PaintText(canvas); | 530 PaintText(canvas); |
| 537 break; | 531 break; |
| 538 } | 532 } |
| 539 } | 533 } |
| 540 } | 534 } |
| 541 | 535 |
| 542 void Combobox::OnFocus() { | 536 void Combobox::OnFocus() { |
| 543 GetInputMethod()->OnFocus(); | 537 if (GetInputMethod()) |
| 538 GetInputMethod()->SetFocusedTextInputClient(GetPrefixSelector()); | |
| 539 | |
| 544 View::OnFocus(); | 540 View::OnFocus(); |
| 545 // Border renders differently when focused. | 541 // Border renders differently when focused. |
| 546 SchedulePaint(); | 542 SchedulePaint(); |
| 547 } | 543 } |
| 548 | 544 |
| 549 void Combobox::OnBlur() { | 545 void Combobox::OnBlur() { |
| 550 GetInputMethod()->OnBlur(); | 546 if (GetInputMethod()) |
| 547 GetInputMethod()->DetachTextInputClient(GetPrefixSelector()); | |
| 548 | |
| 551 if (selector_) | 549 if (selector_) |
| 552 selector_->OnViewBlur(); | 550 selector_->OnViewBlur(); |
| 553 // Border renders differently when focused. | 551 // Border renders differently when focused. |
| 554 SchedulePaint(); | 552 SchedulePaint(); |
| 555 } | 553 } |
| 556 | 554 |
| 557 void Combobox::GetAccessibleState(ui::AXViewState* state) { | 555 void Combobox::GetAccessibleState(ui::AXViewState* state) { |
| 558 state->role = ui::AX_ROLE_COMBO_BOX; | 556 state->role = ui::AX_ROLE_COMBO_BOX; |
| 559 state->name = accessible_name_; | 557 state->name = accessible_name_; |
| 560 state->value = model_->GetItemAt(selected_index_); | 558 state->value = model_->GetItemAt(selected_index_); |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 858 #else | 856 #else |
| 859 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); | 857 const ui::NativeTheme* native_theme_for_arrow = GetNativeTheme(); |
| 860 #endif | 858 #endif |
| 861 | 859 |
| 862 ui::NativeTheme::ExtraParams ignored; | 860 ui::NativeTheme::ExtraParams ignored; |
| 863 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, | 861 return native_theme_for_arrow->GetPartSize(ui::NativeTheme::kComboboxArrow, |
| 864 ui::NativeTheme::kNormal, | 862 ui::NativeTheme::kNormal, |
| 865 ignored); | 863 ignored); |
| 866 } | 864 } |
| 867 | 865 |
| 866 PrefixSelector* Combobox::GetPrefixSelector() { | |
| 867 if (!selector_) | |
| 868 selector_.reset(new PrefixSelector(this)); | |
| 869 return selector_.get(); | |
| 870 } | |
| 871 | |
| 868 } // namespace views | 872 } // namespace views |
| OLD | NEW |