| 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 <string> | 5 #include <string> |
| 6 #include <vector> | 6 #include <vector> |
| 7 | 7 |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
| (...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 } | 165 } |
| 166 | 166 |
| 167 void InitTextfields(Textfield::StyleFlags style, int count) { | 167 void InitTextfields(Textfield::StyleFlags style, int count) { |
| 168 // Append kEnableViewsTextfield to use NativeTextfieldViews on Windows. | 168 // Append kEnableViewsTextfield to use NativeTextfieldViews on Windows. |
| 169 CommandLine* command_line = CommandLine::ForCurrentProcess(); | 169 CommandLine* command_line = CommandLine::ForCurrentProcess(); |
| 170 command_line->AppendSwitch(switches::kEnableViewsTextfield); | 170 command_line->AppendSwitch(switches::kEnableViewsTextfield); |
| 171 | 171 |
| 172 ASSERT_FALSE(textfield_); | 172 ASSERT_FALSE(textfield_); |
| 173 textfield_ = new TestTextfield(style); | 173 textfield_ = new TestTextfield(style); |
| 174 textfield_->SetController(this); | 174 textfield_->SetController(this); |
| 175 widget_ = new Widget; | 175 widget_ = new Widget(); |
| 176 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 176 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 177 params.bounds = gfx::Rect(100, 100, 100, 100); | 177 params.bounds = gfx::Rect(100, 100, 100, 100); |
| 178 widget_->Init(params); | 178 widget_->Init(params); |
| 179 View* container = new View(); | 179 View* container = new View(); |
| 180 widget_->SetContentsView(container); | 180 widget_->SetContentsView(container); |
| 181 container->AddChildView(textfield_); | 181 container->AddChildView(textfield_); |
| 182 | 182 |
| 183 textfield_view_ = static_cast<NativeTextfieldViews*>( | 183 textfield_view_ = static_cast<NativeTextfieldViews*>( |
| 184 textfield_->GetNativeWrapperForTesting()); | 184 textfield_->GetNativeWrapperForTesting()); |
| 185 textfield_view_->SetBoundsRect(params.bounds); | 185 textfield_view_->SetBoundsRect(params.bounds); |
| 186 textfield_->set_id(1); | 186 textfield_->set_id(1); |
| 187 | 187 |
| 188 for (int i = 1; i < count; i++) { | 188 for (int i = 1; i < count; i++) { |
| 189 Textfield* textfield = new Textfield(style); | 189 Textfield* textfield = new Textfield(style); |
| 190 container->AddChildView(textfield); | 190 container->AddChildView(textfield); |
| 191 textfield->set_id(i + 1); | 191 textfield->set_id(i + 1); |
| 192 } | 192 } |
| 193 | 193 |
| 194 DCHECK(textfield_view_); | 194 DCHECK(textfield_view_); |
| 195 model_ = textfield_view_->model_.get(); | 195 model_ = textfield_view_->model_.get(); |
| 196 model_->ClearEditHistory(); | 196 model_->ClearEditHistory(); |
| 197 | 197 |
| 198 input_method_ = new MockInputMethod(); | 198 input_method_ = new MockInputMethod(); |
| 199 widget_->ReplaceInputMethod(input_method_); | 199 widget_->ReplaceInputMethod(input_method_); |
| 200 | 200 |
| 201 // Assumes the Widget is always focused. | 201 // Activate the widget and focus the textfield for input handling. |
| 202 input_method_->OnFocus(); | 202 widget_->Activate(); |
| 203 | |
| 204 // TODO(msw): Determine why this requires two calls to work on Windows. | |
| 205 textfield_->RequestFocus(); | |
| 206 textfield_->RequestFocus(); | 203 textfield_->RequestFocus(); |
| 207 } | 204 } |
| 208 | 205 |
| 209 ui::MenuModel* GetContextMenuModel() { | 206 ui::MenuModel* GetContextMenuModel() { |
| 210 textfield_view_->UpdateContextMenu(); | 207 textfield_view_->UpdateContextMenu(); |
| 211 return textfield_view_->context_menu_contents_.get(); | 208 return textfield_view_->context_menu_contents_.get(); |
| 212 } | 209 } |
| 213 | 210 |
| 214 ui::TouchSelectionController* GetTouchSelectionController() { | 211 ui::TouchSelectionController* GetTouchSelectionController() { |
| 215 return textfield_view_->touch_selection_controller_.get(); | 212 return textfield_view_->touch_selection_controller_.get(); |
| (...skipping 1556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1772 textfield_view_->OnGestureEvent(&tap_down); | 1769 textfield_view_->OnGestureEvent(&tap_down); |
| 1773 // Create a new long press event since the previous one is not marked handled. | 1770 // Create a new long press event since the previous one is not marked handled. |
| 1774 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); | 1771 GestureEventForTest long_press2(ui::ET_GESTURE_LONG_PRESS, eventX, eventY, 0); |
| 1775 textfield_view_->OnGestureEvent(&long_press2); | 1772 textfield_view_->OnGestureEvent(&long_press2); |
| 1776 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); | 1773 EXPECT_STR_EQ("hello", textfield_->GetSelectedText()); |
| 1777 EXPECT_FALSE(GetTouchSelectionController()); | 1774 EXPECT_FALSE(GetTouchSelectionController()); |
| 1778 } | 1775 } |
| 1779 #endif | 1776 #endif |
| 1780 | 1777 |
| 1781 } // namespace views | 1778 } // namespace views |
| OLD | NEW |