| 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/command_line.h" | 5 #include "base/command_line.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "grit/ui_resources.h" | 7 #include "grit/ui_resources.h" |
| 8 #include "ui/aura/client/screen_position_client.h" | 8 #include "ui/aura/client/screen_position_client.h" |
| 9 #include "ui/aura/test/event_generator.h" | 9 #include "ui/aura/test/event_generator.h" |
| 10 #include "ui/aura/window.h" | 10 #include "ui/aura/window.h" |
| 11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
| 12 #include "ui/base/touch/touch_editing_controller.h" | 12 #include "ui/base/touch/touch_editing_controller.h" |
| 13 #include "ui/base/ui_base_switches.h" | 13 #include "ui/base/ui_base_switches.h" |
| 14 #include "ui/gfx/canvas.h" | 14 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
| 16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
| 17 #include "ui/gfx/render_text.h" | 17 #include "ui/gfx/render_text.h" |
| 18 #include "ui/views/controls/textfield/textfield.h" | 18 #include "ui/views/controls/textfield/textfield.h" |
| 19 #include "ui/views/controls/textfield/textfield_test_api.h" |
| 19 #include "ui/views/test/views_test_base.h" | 20 #include "ui/views/test/views_test_base.h" |
| 20 #include "ui/views/touchui/touch_selection_controller_impl.h" | 21 #include "ui/views/touchui/touch_selection_controller_impl.h" |
| 21 #include "ui/views/views_touch_selection_controller_factory.h" | 22 #include "ui/views/views_touch_selection_controller_factory.h" |
| 22 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
| 23 | 24 |
| 24 using base::ASCIIToUTF16; | 25 using base::ASCIIToUTF16; |
| 25 using base::UTF16ToUTF8; | 26 using base::UTF16ToUTF8; |
| 26 using base::WideToUTF16; | 27 using base::WideToUTF16; |
| 27 | 28 |
| 28 namespace { | 29 namespace { |
| (...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 textfield_widget_->Init(params); | 91 textfield_widget_->Init(params); |
| 91 View* container = new View(); | 92 View* container = new View(); |
| 92 textfield_widget_->SetContentsView(container); | 93 textfield_widget_->SetContentsView(container); |
| 93 container->AddChildView(textfield_); | 94 container->AddChildView(textfield_); |
| 94 | 95 |
| 95 textfield_->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); | 96 textfield_->SetBoundsRect(gfx::Rect(0, 0, 200, 20)); |
| 96 textfield_->set_id(1); | 97 textfield_->set_id(1); |
| 97 textfield_widget_->Show(); | 98 textfield_widget_->Show(); |
| 98 | 99 |
| 99 textfield_->RequestFocus(); | 100 textfield_->RequestFocus(); |
| 101 |
| 102 textfield_test_api_.reset(new TextfieldTestApi(textfield_)); |
| 100 } | 103 } |
| 101 | 104 |
| 102 void CreateWidget() { | 105 void CreateWidget() { |
| 103 widget_ = new Widget; | 106 widget_ = new Widget; |
| 104 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); | 107 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); |
| 105 params.bounds = gfx::Rect(0, 0, 200, 200); | 108 params.bounds = gfx::Rect(0, 0, 200, 200); |
| 106 widget_->Init(params); | 109 widget_->Init(params); |
| 107 widget_->Show(); | 110 widget_->Show(); |
| 108 } | 111 } |
| 109 | 112 |
| 110 protected: | 113 protected: |
| 111 static bool IsCursorHandleVisibleFor( | 114 static bool IsCursorHandleVisibleFor( |
| 112 ui::TouchSelectionController* controller) { | 115 ui::TouchSelectionController* controller) { |
| 113 TouchSelectionControllerImpl* impl = | 116 TouchSelectionControllerImpl* impl = |
| 114 static_cast<TouchSelectionControllerImpl*>(controller); | 117 static_cast<TouchSelectionControllerImpl*>(controller); |
| 115 return impl->IsCursorHandleVisible(); | 118 return impl->IsCursorHandleVisible(); |
| 116 } | 119 } |
| 117 | 120 |
| 118 gfx::Rect GetCursorRect(const gfx::SelectionModel& sel) { | 121 gfx::Rect GetCursorRect(const gfx::SelectionModel& sel) { |
| 119 return textfield_->GetRenderText()->GetCursorBounds(sel, true); | 122 return textfield_test_api_->GetRenderText()->GetCursorBounds(sel, true); |
| 120 } | 123 } |
| 121 | 124 |
| 122 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { | 125 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { |
| 123 gfx::Rect cursor_bounds = GetCursorRect(sel); | 126 gfx::Rect cursor_bounds = GetCursorRect(sel); |
| 124 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); | 127 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); |
| 125 } | 128 } |
| 126 | 129 |
| 127 TouchSelectionControllerImpl* GetSelectionController() { | 130 TouchSelectionControllerImpl* GetSelectionController() { |
| 128 return static_cast<TouchSelectionControllerImpl*>( | 131 return static_cast<TouchSelectionControllerImpl*>( |
| 129 textfield_->touch_selection_controller_.get()); | 132 textfield_test_api_->touch_selection_controller()); |
| 130 } | 133 } |
| 131 | 134 |
| 132 void StartTouchEditing() { | 135 void StartTouchEditing() { |
| 133 textfield_->CreateTouchSelectionControllerAndNotifyIt(); | 136 textfield_test_api_->CreateTouchSelectionControllerAndNotifyIt(); |
| 134 } | 137 } |
| 135 | 138 |
| 136 void EndTouchEditing() { | 139 void EndTouchEditing() { |
| 137 textfield_->touch_selection_controller_.reset(); | 140 textfield_test_api_->ResetTouchSelectionController(); |
| 138 } | 141 } |
| 139 | 142 |
| 140 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { | 143 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { |
| 141 TouchSelectionControllerImpl* controller = GetSelectionController(); | 144 TouchSelectionControllerImpl* controller = GetSelectionController(); |
| 142 // Do the work of OnMousePressed(). | 145 // Do the work of OnMousePressed(). |
| 143 if (selection_handle == 1) | 146 if (selection_handle == 1) |
| 144 controller->SetDraggingHandle(controller->selection_handle_1_.get()); | 147 controller->SetDraggingHandle(controller->selection_handle_1_.get()); |
| 145 else | 148 else |
| 146 controller->SetDraggingHandle(controller->selection_handle_2_.get()); | 149 controller->SetDraggingHandle(controller->selection_handle_2_.get()); |
| 147 | 150 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 176 | 179 |
| 177 bool IsSelectionHandle2Visible() { | 180 bool IsSelectionHandle2Visible() { |
| 178 return GetSelectionController()->IsSelectionHandle2Visible(); | 181 return GetSelectionController()->IsSelectionHandle2Visible(); |
| 179 } | 182 } |
| 180 | 183 |
| 181 bool IsCursorHandleVisible() { | 184 bool IsCursorHandleVisible() { |
| 182 return GetSelectionController()->IsCursorHandleVisible(); | 185 return GetSelectionController()->IsCursorHandleVisible(); |
| 183 } | 186 } |
| 184 | 187 |
| 185 gfx::RenderText* GetRenderText() { | 188 gfx::RenderText* GetRenderText() { |
| 186 return textfield_->GetRenderText(); | 189 return textfield_test_api_->GetRenderText(); |
| 187 } | 190 } |
| 188 | 191 |
| 189 gfx::Point GetCursorHandleDragPoint() { | 192 gfx::Point GetCursorHandleDragPoint() { |
| 190 gfx::Point point = GetCursorHandlePosition(); | 193 gfx::Point point = GetCursorHandlePosition(); |
| 191 const gfx::SelectionModel& sel = textfield_->GetSelectionModel(); | 194 const gfx::SelectionModel& sel = textfield_->GetSelectionModel(); |
| 192 int cursor_height = GetCursorRect(sel).height(); | 195 int cursor_height = GetCursorRect(sel).height(); |
| 193 point.Offset(GetHandleImageSize().width() / 2 + kPadding, | 196 point.Offset(GetHandleImageSize().width() / 2 + kPadding, |
| 194 GetHandleImageSize().height() / 2 + cursor_height); | 197 GetHandleImageSize().height() / 2 + cursor_height); |
| 195 return point; | 198 return point; |
| 196 } | 199 } |
| 197 | 200 |
| 198 Widget* textfield_widget_; | 201 Widget* textfield_widget_; |
| 199 Widget* widget_; | 202 Widget* widget_; |
| 200 | 203 |
| 201 Textfield* textfield_; | 204 Textfield* textfield_; |
| 205 scoped_ptr<TextfieldTestApi> textfield_test_api_; |
| 202 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; | 206 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; |
| 203 | 207 |
| 204 private: | 208 private: |
| 205 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); | 209 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); |
| 206 }; | 210 }; |
| 207 | 211 |
| 208 // If textfield has selection, this macro verifies that the selection handles | 212 // If textfield has selection, this macro verifies that the selection handles |
| 209 // are visible and at the correct positions (at the end points of selection). | 213 // are visible and at the correct positions (at the end points of selection). |
| 210 // |cursor_at_selection_handle_1| is used to decide whether selection | 214 // |cursor_at_selection_handle_1| is used to decide whether selection |
| 211 // handle 1's position is matched against the start of selection or the end. | 215 // handle 1's position is matched against the start of selection or the end. |
| (...skipping 623 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 835 // Start touch editing; then press a key and ensure it deactivates touch | 839 // Start touch editing; then press a key and ensure it deactivates touch |
| 836 // selection. | 840 // selection. |
| 837 StartTouchEditing(); | 841 StartTouchEditing(); |
| 838 EXPECT_TRUE(GetSelectionController()); | 842 EXPECT_TRUE(GetSelectionController()); |
| 839 generator.PressKey(ui::VKEY_A, 0); | 843 generator.PressKey(ui::VKEY_A, 0); |
| 840 RunPendingMessages(); | 844 RunPendingMessages(); |
| 841 EXPECT_FALSE(GetSelectionController()); | 845 EXPECT_FALSE(GetSelectionController()); |
| 842 } | 846 } |
| 843 | 847 |
| 844 } // namespace views | 848 } // namespace views |
| OLD | NEW |