| Index: ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| diff --git a/ui/views/touchui/touch_selection_controller_impl_unittest.cc b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| index 729e20f774d942664c11b5a1695b2bbee2ea7b00..67882bf926b7891d8c798e63c7407af8bec6bcc8 100644
|
| --- a/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| +++ b/ui/views/touchui/touch_selection_controller_impl_unittest.cc
|
| @@ -8,10 +8,10 @@
|
| #include "ui/base/resource/resource_bundle.h"
|
| #include "ui/base/touch/touch_editing_controller.h"
|
| #include "ui/base/ui_base_switches.h"
|
| -#include "ui/gfx/canvas.h"
|
| #include "ui/gfx/point.h"
|
| #include "ui/gfx/rect.h"
|
| #include "ui/gfx/render_text.h"
|
| +#include "ui/views/controls/textfield/native_textfield_views.h"
|
| #include "ui/views/controls/textfield/textfield.h"
|
| #include "ui/views/test/views_test_base.h"
|
| #include "ui/views/touchui/touch_selection_controller_impl.h"
|
| @@ -51,6 +51,7 @@
|
| TouchSelectionControllerImplTest()
|
| : widget_(NULL),
|
| textfield_(NULL),
|
| + textfield_view_(NULL),
|
| views_tsc_factory_(new ViewsTouchSelectionControllerFactory) {
|
| CommandLine::ForCurrentProcess()->AppendSwitch(
|
| switches::kEnableTouchEditing);
|
| @@ -77,23 +78,26 @@
|
| widget_->SetContentsView(container);
|
| container->AddChildView(textfield_);
|
|
|
| + textfield_view_ = textfield_->GetTextfieldViewForTesting();
|
| textfield_->SetBoundsRect(params.bounds);
|
| + textfield_view_->SetBoundsRect(params.bounds);
|
| textfield_->set_id(1);
|
| widget_->Show();
|
|
|
| + DCHECK(textfield_view_);
|
| textfield_->RequestFocus();
|
| }
|
|
|
| protected:
|
| gfx::Point GetCursorPosition(const gfx::SelectionModel& sel) {
|
| - gfx::RenderText* render_text = textfield_->GetRenderText();
|
| + gfx::RenderText* render_text = textfield_view_->GetRenderText();
|
| gfx::Rect cursor_bounds = render_text->GetCursorBounds(sel, true);
|
| return gfx::Point(cursor_bounds.x(), cursor_bounds.y());
|
| }
|
|
|
| TouchSelectionControllerImpl* GetSelectionController() {
|
| return static_cast<TouchSelectionControllerImpl*>(
|
| - textfield_->touch_selection_controller_.get());
|
| + textfield_view_->touch_selection_controller_.get());
|
| }
|
|
|
| void SimulateSelectionHandleDrag(gfx::Point p, int selection_handle) {
|
| @@ -138,12 +142,13 @@
|
| }
|
|
|
| gfx::RenderText* GetRenderText() {
|
| - return textfield_->GetRenderText();
|
| + return textfield_view_->GetRenderText();
|
| }
|
|
|
| Widget* widget_;
|
|
|
| Textfield* textfield_;
|
| + NativeTextfieldViews* textfield_view_;
|
| scoped_ptr<ViewsTouchSelectionControllerFactory> views_tsc_factory_;
|
|
|
| private:
|
| @@ -156,7 +161,7 @@
|
| // handle 1's position is matched against the start of selection or the end.
|
| #define VERIFY_HANDLE_POSITIONS(cursor_at_selection_handle_1) \
|
| { \
|
| - gfx::SelectionModel sel = textfield_->GetSelectionModel(); \
|
| + gfx::SelectionModel sel = textfield_view_->GetSelectionModel(); \
|
| if (textfield_->HasSelection()) { \
|
| EXPECT_TRUE(IsSelectionHandle1Visible()); \
|
| EXPECT_TRUE(IsSelectionHandle2Visible()); \
|
| @@ -195,7 +200,7 @@
|
| // Tap the textfield to invoke touch selection.
|
| ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
|
| ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
|
|
| // Test selecting a range.
|
| textfield_->SelectRange(gfx::Range(3, 7));
|
| @@ -216,7 +221,7 @@
|
| // Test with focus re-gained.
|
| widget_->GetFocusManager()->SetFocusedView(textfield_);
|
| EXPECT_FALSE(GetSelectionController());
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
| VERIFY_HANDLE_POSITIONS(false);
|
| }
|
|
|
| @@ -227,7 +232,7 @@
|
| // Tap the textfield to invoke touch selection.
|
| ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
|
| ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
|
|
| // Test cursor at run boundary and with empty selection.
|
| textfield_->SelectSelectionModel(
|
| @@ -275,15 +280,15 @@
|
| // Tap the textfield to invoke touch selection.
|
| ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
|
| ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
| textfield_->SelectRange(gfx::Range(3, 7));
|
|
|
| EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfie");
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 2 to right by 3 chars.
|
| - const gfx::FontList& font_list = textfield_->GetFontList();
|
| - int x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("ld "), font_list);
|
| + const gfx::Font& font = textfield_->GetPrimaryFont();
|
| + int x = font.GetStringWidth(ASCIIToUTF16("ld "));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
|
| EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "tfield ");
|
| VERIFY_HANDLE_POSITIONS(false);
|
| @@ -295,13 +300,13 @@
|
| VERIFY_HANDLE_POSITIONS(true);
|
|
|
| // Drag selection handle 1 across selection handle 2.
|
| - x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("textfield with "), font_list);
|
| + x = font.GetStringWidth(ASCIIToUTF16("textfield with "));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
|
| EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "with ");
|
| VERIFY_HANDLE_POSITIONS(true);
|
|
|
| // Drag selection handle 2 across selection handle 1.
|
| - x = gfx::Canvas::GetStringWidth(ASCIIToUTF16("with selected "), font_list);
|
| + x = font.GetStringWidth(ASCIIToUTF16("with selected "));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
|
| EXPECT_EQ(UTF16ToUTF8(textfield_->GetSelectedText()), "selected ");
|
| VERIFY_HANDLE_POSITIONS(false);
|
| @@ -313,7 +318,7 @@
|
| // Tap the textfield to invoke touch selection.
|
| ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
|
| ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
|
|
| // Select [c] from left to right.
|
| textfield_->SelectRange(gfx::Range(2, 3));
|
| @@ -321,14 +326,14 @@
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 2 to right by 1 char.
|
| - const gfx::FontList& font_list = textfield_->GetFontList();
|
| - int x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
|
| + const gfx::Font& font = textfield_->GetPrimaryFont();
|
| + int x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 1 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"b"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
| @@ -339,13 +344,13 @@
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 1 to right by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e3"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"\x05e3"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
|
|
| // Drag selection handle 2 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"b"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"b"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"bc\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
| @@ -364,14 +369,14 @@
|
| Need further investigation on whether this is a bug in Pango and how to
|
| work around it.
|
| // Drag selection handle 2 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
| */
|
|
|
| // Drag selection handle 1 to right by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"d"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
| @@ -383,14 +388,14 @@
|
|
|
| /* TODO(xji): see detail of above commented out test case.
|
| // Drag selection handle 1 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
| */
|
|
|
| // Drag selection handle 2 to right by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"d"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"d"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"\x05e2\x05e3" L"d"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
| @@ -401,13 +406,13 @@
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 2 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"c"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 1 to right by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
| @@ -418,13 +423,13 @@
|
| VERIFY_HANDLE_POSITIONS(false);
|
|
|
| // Drag selection handle 1 to left by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"c"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"c"));
|
| SimulateSelectionHandleDrag(gfx::Point(-x, 0), 1);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1\x05e2"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(true);
|
|
|
| // Drag selection handle 2 to right by 1 char.
|
| - x = gfx::Canvas::GetStringWidth(WideToUTF16(L"\x05e2"), font_list);
|
| + x = font.GetStringWidth(WideToUTF16(L"\x05e2"));
|
| SimulateSelectionHandleDrag(gfx::Point(x, 0), 2);
|
| EXPECT_EQ(WideToUTF16(L"c\x05e1"), textfield_->GetSelectedText());
|
| VERIFY_HANDLE_POSITIONS(false);
|
| @@ -442,7 +447,7 @@
|
| // Tap the textfield to invoke selection.
|
| ui::GestureEvent tap(ui::ET_GESTURE_TAP, 0, 0, 0, base::TimeDelta(),
|
| ui::GestureEventDetails(ui::ET_GESTURE_TAP, 1.0f, 0.0f), 0);
|
| - textfield_->OnGestureEvent(&tap);
|
| + textfield_view_->OnGestureEvent(&tap);
|
|
|
| // Select some text such that one handle is hidden.
|
| textfield_->SelectRange(gfx::Range(10, textfield_text.length()));
|
|
|