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 "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "ui/base/event.h" |
6 #include "ui/base/keycodes/keyboard_codes.h" | 7 #include "ui/base/keycodes/keyboard_codes.h" |
7 #include "ui/base/models/combobox_model.h" | 8 #include "ui/base/models/combobox_model.h" |
8 #include "ui/views/controls/combobox/combobox.h" | 9 #include "ui/views/controls/combobox/combobox.h" |
9 #include "ui/views/controls/combobox/native_combobox_views.h" | 10 #include "ui/views/controls/combobox/native_combobox_views.h" |
10 #include "ui/views/ime/mock_input_method.h" | 11 #include "ui/views/ime/mock_input_method.h" |
11 #include "ui/views/test/views_test_base.h" | 12 #include "ui/views/test/views_test_base.h" |
12 #include "ui/views/widget/native_widget_private.h" | 13 #include "ui/views/widget/native_widget_private.h" |
13 #include "ui/views/widget/widget.h" | 14 #include "ui/views/widget/widget.h" |
14 | 15 |
15 namespace { | 16 namespace { |
16 | 17 |
17 // A wrapper of Combobox to intercept the result of OnKeyPressed() and | 18 // A wrapper of Combobox to intercept the result of OnKeyPressed() and |
18 // OnKeyReleased() methods. | 19 // OnKeyReleased() methods. |
19 class TestCombobox : public views::Combobox { | 20 class TestCombobox : public views::Combobox { |
20 public: | 21 public: |
21 explicit TestCombobox(ui::ComboboxModel* model) | 22 explicit TestCombobox(ui::ComboboxModel* model) |
22 : Combobox(model), | 23 : Combobox(model), |
23 key_handled_(false), | 24 key_handled_(false), |
24 key_received_(false) { | 25 key_received_(false) { |
25 } | 26 } |
26 | 27 |
27 virtual bool OnKeyPressed(const views::KeyEvent& e) OVERRIDE { | 28 virtual bool OnKeyPressed(const ui::KeyEvent& e) OVERRIDE { |
28 key_received_ = true; | 29 key_received_ = true; |
29 key_handled_ = views::Combobox::OnKeyPressed(e); | 30 key_handled_ = views::Combobox::OnKeyPressed(e); |
30 return key_handled_; | 31 return key_handled_; |
31 } | 32 } |
32 | 33 |
33 virtual bool OnKeyReleased(const views::KeyEvent& e) OVERRIDE { | 34 virtual bool OnKeyReleased(const ui::KeyEvent& e) OVERRIDE { |
34 key_received_ = true; | 35 key_received_ = true; |
35 key_handled_ = views::Combobox::OnKeyReleased(e); | 36 key_handled_ = views::Combobox::OnKeyReleased(e); |
36 return key_handled_; | 37 return key_handled_; |
37 } | 38 } |
38 | 39 |
39 bool key_handled() const { return key_handled_; } | 40 bool key_handled() const { return key_handled_; } |
40 bool key_received() const { return key_received_; } | 41 bool key_received() const { return key_received_; } |
41 | 42 |
42 void clear() { | 43 void clear() { |
43 key_received_ = key_handled_ = false; | 44 key_received_ = key_handled_ = false; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 widget_->ReplaceInputMethod(input_method_); | 117 widget_->ReplaceInputMethod(input_method_); |
117 | 118 |
118 // Assumes the Widget is always focused. | 119 // Assumes the Widget is always focused. |
119 input_method_->OnFocus(); | 120 input_method_->OnFocus(); |
120 | 121 |
121 combobox_->RequestFocus(); | 122 combobox_->RequestFocus(); |
122 } | 123 } |
123 | 124 |
124 protected: | 125 protected: |
125 void SendKeyEvent(ui::KeyboardCode key_code) { | 126 void SendKeyEvent(ui::KeyboardCode key_code) { |
126 KeyEvent event(ui::ET_KEY_PRESSED, key_code, 0); | 127 ui::KeyEvent event(ui::ET_KEY_PRESSED, key_code, 0); |
127 input_method_->DispatchKeyEvent(event); | 128 input_method_->DispatchKeyEvent(event); |
128 } | 129 } |
129 | 130 |
130 View* GetFocusedView() { | 131 View* GetFocusedView() { |
131 return widget_->GetFocusManager()->GetFocusedView(); | 132 return widget_->GetFocusManager()->GetFocusedView(); |
132 } | 133 } |
133 | 134 |
134 // We need widget to populate wrapper class. | 135 // We need widget to populate wrapper class. |
135 Widget* widget_; | 136 Widget* widget_; |
136 | 137 |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
186 widget_->SetContentsView(container); | 187 widget_->SetContentsView(container); |
187 container->AddChildView(combobox_); | 188 container->AddChildView(combobox_); |
188 | 189 |
189 combobox_view_ = static_cast<NativeComboboxViews*>( | 190 combobox_view_ = static_cast<NativeComboboxViews*>( |
190 combobox_->GetNativeWrapperForTesting()); | 191 combobox_->GetNativeWrapperForTesting()); |
191 ASSERT_TRUE(combobox_view_); | 192 ASSERT_TRUE(combobox_view_); |
192 ASSERT_FALSE(combobox_view_->enabled()); | 193 ASSERT_FALSE(combobox_view_->enabled()); |
193 } | 194 } |
194 | 195 |
195 } // namespace views | 196 } // namespace views |
OLD | NEW |