Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(263)

Side by Side Diff: ui/views/touchui/touch_selection_controller_impl_unittest.cc

Issue 177173007: Change type of touch selection handles to POPUP (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased after r263384 Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 widget_ = new Widget; 96 widget_ = new Widget;
97 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP); 97 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_POPUP);
98 params.bounds = gfx::Rect(0, 0, 200, 200); 98 params.bounds = gfx::Rect(0, 0, 200, 200);
99 widget_->Init(params); 99 widget_->Init(params);
100 widget_->Show(); 100 widget_->Show();
101 } 101 }
102 102
103 protected: 103 protected:
104 static bool IsCursorHandleVisibleFor( 104 static bool IsCursorHandleVisibleFor(
105 ui::TouchSelectionController* controller) { 105 ui::TouchSelectionController* controller) {
106 return static_cast<TouchSelectionControllerImpl*>( 106 TouchSelectionControllerImpl* impl =
107 controller)->IsCursorHandleVisible(); 107 static_cast<TouchSelectionControllerImpl*>(controller);
108 return impl->IsCursorHandleVisible();
109 }
110
111 gfx::Rect GetCursorRect(const gfx::SelectionModel& sel) {
112 return textfield_->GetRenderText()->GetCursorBounds(sel, true);
108 } 113 }
109 114
110 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) { 115 gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) {
111 gfx::RenderText* render_text = textfield_->GetRenderText(); 116 gfx::Rect cursor_bounds = GetCursorRect(sel);
112 gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true);
113 return gfx::Point(cursor_bounds.x(), cursor_bounds.y()); 117 return gfx::Point(cursor_bounds.x(), cursor_bounds.y());
114 } 118 }
115 119
116 TouchSelectionControllerImpl* GetSelectionController() { 120 TouchSelectionControllerImpl* GetSelectionController() {
117 return static_cast<TouchSelectionControllerImpl*>( 121 return static_cast<TouchSelectionControllerImpl*>(
118 textfield_->touch_selection_controller_.get()); 122 textfield_->touch_selection_controller_.get());
119 } 123 }
120 124
125 void StartTouchEditing() {
126 textfield_->CreateTouchSelectionControllerAndNotifyIt();
127 }
128
129 void EndTouchEditing() {
130 textfield_->touch_selection_controller_.reset();
131 }
132
121 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) { 133 void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) {
122 TouchSelectionControllerImpl* controller = GetSelectionController(); 134 TouchSelectionControllerImpl* controller = GetSelectionController();
123 // Do the work of OnMousePressed(). 135 // Do the work of OnMousePressed().
124 if (selection_handle == 1) 136 if (selection_handle == 1)
125 controller->SetDraggingHandle(controller->selection_handle_1_.get()); 137 controller->SetDraggingHandle(controller->selection_handle_1_.get());
126 else 138 else
127 controller->SetDraggingHandle(controller->selection_handle_2_.get()); 139 controller->SetDraggingHandle(controller->selection_handle_2_.get());
128 140
129 // Offset the drag position by the selection handle radius since it is 141 // Offset the drag position by the selection handle radius since it is
130 // supposed to be in the coordinate system of the handle. 142 // supposed to be in the coordinate system of the handle.
131 p.Offset(GetHandleImageSize().width() / 2 + kPadding, 0); 143 p.Offset(GetHandleImageSize().width() / 2 + kPadding, 0);
132 controller->SelectionHandleDragged(p); 144 controller->SelectionHandleDragged(p);
133 145
134 // Do the work of OnMouseReleased(). 146 // Do the work of OnMouseReleased().
135 controller->dragging_handle_ = NULL; 147 controller->dragging_handle_ = NULL;
136 } 148 }
137 149
150 gfx::NativeView GetCursorHandleNativeView() {
151 return GetSelectionController()->GetCursorHandleNativeView();
152 }
153
138 gfx::Point GetSelectionHandle1Position() { 154 gfx::Point GetSelectionHandle1Position() {
139 return GetSelectionController()->GetSelectionHandle1Position(); 155 return GetSelectionController()->GetSelectionHandle1Position();
140 } 156 }
141 157
142 gfx::Point GetSelectionHandle2Position() { 158 gfx::Point GetSelectionHandle2Position() {
143 return GetSelectionController()->GetSelectionHandle2Position(); 159 return GetSelectionController()->GetSelectionHandle2Position();
144 } 160 }
145 161
146 gfx::Point GetCursorHandlePosition() { 162 gfx::Point GetCursorHandlePosition() {
147 return GetSelectionController()->GetCursorHandlePosition(); 163 return GetSelectionController()->GetCursorHandlePosition();
148 } 164 }
149 165
150 bool IsSelectionHandle1Visible() { 166 bool IsSelectionHandle1Visible() {
151 return GetSelectionController()->IsSelectionHandle1Visible(); 167 return GetSelectionController()->IsSelectionHandle1Visible();
152 } 168 }
153 169
154 bool IsSelectionHandle2Visible() { 170 bool IsSelectionHandle2Visible() {
155 return GetSelectionController()->IsSelectionHandle2Visible(); 171 return GetSelectionController()->IsSelectionHandle2Visible();
156 } 172 }
157 173
158 bool IsCursorHandleVisible() { 174 bool IsCursorHandleVisible() {
159 return GetSelectionController()->IsCursorHandleVisible(); 175 return GetSelectionController()->IsCursorHandleVisible();
160 } 176 }
161 177
162 gfx::RenderText* GetRenderText() { 178 gfx::RenderText* GetRenderText() {
163 return textfield_->GetRenderText(); 179 return textfield_->GetRenderText();
164 } 180 }
165 181
182 gfx::Point GetCursorHandleDragPoint() {
183 gfx::Point point = GetCursorHandlePosition();
184 const gfx::SelectionModel& sel = textfield_->GetSelectionModel();
185 int cursor_height = GetCursorRect(sel).height();
186 point.Offset(GetHandleImageSize().width() / 2 + kPadding,
187 GetHandleImageSize().height() / 2 + cursor_height);
188 return point;
189 }
190
166 Widget* textfield_widget_; 191 Widget* textfield_widget_;
167 Widget* widget_; 192 Widget* widget_;
168 193
169 Textfield* textfield_; 194 Textfield* textfield_;
170 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_; 195 scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
171 196
172 private: 197 private:
173 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest); 198 DISALLOW_COPY_AND_ASSIGN(TouchSelectionControllerImplTest);
174 }; 199 };
175 200
(...skipping 461 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 662
638 // Move the cursor down such that more than |kBarBottomAllowance| pixels are 663 // Move the cursor down such that more than |kBarBottomAllowance| pixels are
639 // out of the client bounds. Handle should be hidden. 664 // out of the client bounds. Handle should be hidden.
640 touch_editable.set_cursor_rect(gfx::Rect(2, kBarBottomAllowance + 1, 1, 20)); 665 touch_editable.set_cursor_rect(gfx::Rect(2, kBarBottomAllowance + 1, 1, 20));
641 touch_selection_controller->SelectionChanged(); 666 touch_selection_controller->SelectionChanged();
642 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get())); 667 EXPECT_FALSE(IsCursorHandleVisibleFor(touch_selection_controller.get()));
643 668
644 touch_selection_controller.reset(); 669 touch_selection_controller.reset();
645 } 670 }
646 671
672 TEST_F(TouchSelectionControllerImplTest, HandlesStackAboveParent) {
673 ui::EventTarget* root = GetContext();
674 ui::EventTargeter* targeter = root->GetEventTargeter();
675
676 // Create the first window containing a Views::Textfield.
677 CreateTextfield();
678 aura::Window* window1 = textfield_widget_->GetNativeView();
679
680 // Start touch editing, check that the handle is above the first window, and
681 // end touch editing.
682 StartTouchEditing();
683 gfx::Point test_point = GetCursorHandleDragPoint();
684 ui::MouseEvent test_event1(ui::ET_MOUSE_MOVED, test_point, test_point,
685 ui::EF_NONE, ui::EF_NONE);
686 EXPECT_EQ(GetCursorHandleNativeView(),
687 targeter->FindTargetForEvent(root, &test_event1));
688 EndTouchEditing();
689
690 // Create the second (empty) window over the first one.
691 CreateWidget();
692 aura::Window* window2 = widget_->GetNativeView();
693
694 // Start touch editing (in the first window) and check that the handle is not
695 // above the second window.
696 StartTouchEditing();
697 ui::MouseEvent test_event2(ui::ET_MOUSE_MOVED, test_point, test_point,
698 ui::EF_NONE, ui::EF_NONE);
699 EXPECT_EQ(window2, targeter->FindTargetForEvent(root, &test_event2));
700
701 // Move the first window to top and check that the handle is kept above the
702 // first window.
703 window1->GetRootWindow()->StackChildAtTop(window1);
704 ui::MouseEvent test_event3(ui::ET_MOUSE_MOVED, test_point, test_point,
705 ui::EF_NONE, ui::EF_NONE);
706 EXPECT_EQ(GetCursorHandleNativeView(),
707 targeter->FindTargetForEvent(root, &test_event3));
708 }
709
647 } // namespace views 710 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/touchui/touch_selection_controller_impl.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698