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 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 clipboard_writer.WriteText(ASCIIToUTF16(text)); | 250 clipboard_writer.WriteText(ASCIIToUTF16(text)); |
251 } | 251 } |
252 | 252 |
253 View* GetFocusedView() { | 253 View* GetFocusedView() { |
254 return widget_->GetFocusManager()->GetFocusedView(); | 254 return widget_->GetFocusManager()->GetFocusedView(); |
255 } | 255 } |
256 | 256 |
257 int GetCursorPositionX(int cursor_pos) { | 257 int GetCursorPositionX(int cursor_pos) { |
258 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 258 gfx::RenderText* render_text = textfield_view_->GetRenderText(); |
259 return render_text->GetCursorBounds( | 259 return render_text->GetCursorBounds( |
260 gfx::SelectionModel(cursor_pos), false).x(); | 260 gfx::SelectionModel(cursor_pos, gfx::CURSOR_FORWARD), false).x(); |
261 } | 261 } |
262 | 262 |
263 // Get the current cursor bounds. | 263 // Get the current cursor bounds. |
264 gfx::Rect GetCursorBounds() { | 264 gfx::Rect GetCursorBounds() { |
265 gfx::RenderText* render_text = textfield_view_->GetRenderText(); | 265 gfx::RenderText* render_text = textfield_view_->GetRenderText(); |
266 gfx::Rect bounds = render_text->GetUpdatedCursorBounds(); | 266 gfx::Rect bounds = render_text->GetUpdatedCursorBounds(); |
267 return bounds; | 267 return bounds; |
268 } | 268 } |
269 | 269 |
270 // Get the cursor bounds of |sel|. | 270 // Get the cursor bounds of |sel|. |
(...skipping 1079 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1350 // Reset locale. | 1350 // Reset locale. |
1351 base::i18n::SetICUDefaultLocale(locale); | 1351 base::i18n::SetICUDefaultLocale(locale); |
1352 } | 1352 } |
1353 | 1353 |
1354 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) { | 1354 TEST_F(NativeTextfieldViewsTest, HitInsideTextAreaTest) { |
1355 InitTextfield(Textfield::STYLE_DEFAULT); | 1355 InitTextfield(Textfield::STYLE_DEFAULT); |
1356 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); | 1356 textfield_->SetText(WideToUTF16(L"ab\x05E1\x5E2")); |
1357 std::vector<gfx::Rect> cursor_bounds; | 1357 std::vector<gfx::Rect> cursor_bounds; |
1358 | 1358 |
1359 // Save each cursor bound. | 1359 // Save each cursor bound. |
1360 gfx::SelectionModel sel(0, 0, gfx::SelectionModel::LEADING); | 1360 gfx::SelectionModel sel(0, gfx::CURSOR_FORWARD); |
1361 cursor_bounds.push_back(GetCursorBounds(sel)); | 1361 cursor_bounds.push_back(GetCursorBounds(sel)); |
1362 | 1362 |
1363 sel = gfx::SelectionModel(1, 0, gfx::SelectionModel::TRAILING); | 1363 sel = gfx::SelectionModel(1, gfx::CURSOR_BACKWARD); |
1364 gfx::Rect bound = GetCursorBounds(sel); | 1364 gfx::Rect bound = GetCursorBounds(sel); |
1365 sel = gfx::SelectionModel(1, 1, gfx::SelectionModel::LEADING); | 1365 sel = gfx::SelectionModel(1, gfx::CURSOR_FORWARD); |
1366 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); | 1366 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
1367 cursor_bounds.push_back(bound); | 1367 cursor_bounds.push_back(bound); |
1368 | 1368 |
1369 // Check that a cursor at the end of the Latin portion of the text is at the | 1369 // Check that a cursor at the end of the Latin portion of the text is at the |
1370 // same position as a cursor placed at the end of the RTL Hebrew portion. | 1370 // same position as a cursor placed at the end of the RTL Hebrew portion. |
1371 sel = gfx::SelectionModel(2, 1, gfx::SelectionModel::TRAILING); | 1371 sel = gfx::SelectionModel(2, gfx::CURSOR_BACKWARD); |
1372 bound = GetCursorBounds(sel); | 1372 bound = GetCursorBounds(sel); |
1373 sel = gfx::SelectionModel(4, 3, gfx::SelectionModel::TRAILING); | 1373 sel = gfx::SelectionModel(4, gfx::CURSOR_BACKWARD); |
1374 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); | 1374 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
1375 cursor_bounds.push_back(bound); | 1375 cursor_bounds.push_back(bound); |
1376 | 1376 |
1377 sel = gfx::SelectionModel(3, 2, gfx::SelectionModel::TRAILING); | 1377 sel = gfx::SelectionModel(3, gfx::CURSOR_BACKWARD); |
1378 bound = GetCursorBounds(sel); | 1378 bound = GetCursorBounds(sel); |
1379 sel = gfx::SelectionModel(3, 3, gfx::SelectionModel::LEADING); | 1379 sel = gfx::SelectionModel(3, gfx::CURSOR_FORWARD); |
1380 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); | 1380 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
1381 cursor_bounds.push_back(bound); | 1381 cursor_bounds.push_back(bound); |
1382 | 1382 |
1383 sel = gfx::SelectionModel(2, 2, gfx::SelectionModel::LEADING); | 1383 sel = gfx::SelectionModel(2, gfx::CURSOR_FORWARD); |
1384 bound = GetCursorBounds(sel); | 1384 bound = GetCursorBounds(sel); |
1385 sel = gfx::SelectionModel(4, 2, gfx::SelectionModel::LEADING); | 1385 sel = gfx::SelectionModel(4, gfx::CURSOR_FORWARD); |
1386 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); | 1386 EXPECT_EQ(bound.x(), GetCursorBounds(sel).x()); |
1387 cursor_bounds.push_back(bound); | 1387 cursor_bounds.push_back(bound); |
1388 | 1388 |
1389 // Expected cursor position when clicking left and right of each character. | 1389 // Expected cursor position when clicking left and right of each character. |
1390 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2}; | 1390 size_t cursor_pos_expected[] = {0, 1, 1, 2, 4, 3, 3, 2}; |
1391 | 1391 |
1392 int index = 0; | 1392 int index = 0; |
1393 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) { | 1393 for (int i = 0; i < static_cast<int>(cursor_bounds.size() - 1); ++i) { |
1394 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2; | 1394 int half_width = (cursor_bounds[i + 1].x() - cursor_bounds[i].x()) / 2; |
1395 MouseClick(cursor_bounds[i], half_width / 2); | 1395 MouseClick(cursor_bounds[i], half_width / 2); |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1575 #else | 1575 #else |
1576 EXPECT_EQ(500U, textfield_->GetCursorPosition()); | 1576 EXPECT_EQ(500U, textfield_->GetCursorPosition()); |
1577 #endif | 1577 #endif |
1578 #endif // !defined(OS_WIN) | 1578 #endif // !defined(OS_WIN) |
1579 | 1579 |
1580 // Reset locale. | 1580 // Reset locale. |
1581 base::i18n::SetICUDefaultLocale(locale); | 1581 base::i18n::SetICUDefaultLocale(locale); |
1582 } | 1582 } |
1583 | 1583 |
1584 } // namespace views | 1584 } // namespace views |
OLD | NEW |