| 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 "ui/gfx/render_text.h" | 5 #include "ui/gfx/render_text.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/i18n/break_iterator.h" | 10 #include "base/i18n/break_iterator.h" |
| (...skipping 1349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1360 for (int k = 0; k < j; ++k) | 1360 for (int k = 0; k < j; ++k) |
| 1361 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); | 1361 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, false); |
| 1362 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1362 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 1363 EXPECT_EQ(end, render_text->selection_model()); | 1363 EXPECT_EQ(end, render_text->selection_model()); |
| 1364 } | 1364 } |
| 1365 } | 1365 } |
| 1366 } | 1366 } |
| 1367 | 1367 |
| 1368 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 | 1368 // TODO(asvitkine): RenderTextMac cursor movements. http://crbug.com/131618 |
| 1369 #if !defined(OS_MACOSX) | 1369 #if !defined(OS_MACOSX) |
| 1370 // TODO(msw): Make these work on Windows. | |
| 1371 #if !defined(OS_WIN) | |
| 1372 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { | 1370 TEST_F(RenderTextTest, MoveLeftRightByWordInBidiText) { |
| 1373 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1371 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1374 | 1372 |
| 1375 // For testing simplicity, each word is a 3-character word. | 1373 // For testing simplicity, each word is a 3-character word. |
| 1376 std::vector<const wchar_t*> test; | 1374 std::vector<const wchar_t*> test; |
| 1377 test.push_back(L"abc"); | 1375 test.push_back(L"abc"); |
| 1378 test.push_back(L"abc def"); | 1376 test.push_back(L"abc def"); |
| 1379 test.push_back(L"\x05E1\x05E2\x05E3"); | 1377 test.push_back(L"\x05E1\x05E2\x05E3"); |
| 1380 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"); | 1378 test.push_back(L"\x05E1\x05E2\x05E3 \x05E4\x05E5\x05E6"); |
| 1381 test.push_back(L"abc \x05E1\x05E2\x05E3"); | 1379 test.push_back(L"abc \x05E1\x05E2\x05E3"); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1441 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1439 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1442 render_text->SetText(WideToUTF16(L"abc def")); | 1440 render_text->SetText(WideToUTF16(L"abc def")); |
| 1443 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1441 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
| 1444 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1442 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 1445 EXPECT_EQ(11U, render_text->cursor_position()); | 1443 EXPECT_EQ(11U, render_text->cursor_position()); |
| 1446 | 1444 |
| 1447 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); | 1445 render_text->MoveCursorTo(SelectionModel(5, CURSOR_FORWARD)); |
| 1448 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); | 1446 render_text->MoveCursor(WORD_BREAK, CURSOR_LEFT, false); |
| 1449 EXPECT_EQ(0U, render_text->cursor_position()); | 1447 EXPECT_EQ(0U, render_text->cursor_position()); |
| 1450 } | 1448 } |
| 1451 #endif // !defined(OS_WIN) | |
| 1452 | 1449 |
| 1453 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { | 1450 TEST_F(RenderTextTest, MoveLeftRightByWordInChineseText) { |
| 1454 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | 1451 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); |
| 1455 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); | 1452 render_text->SetText(WideToUTF16(L"\x6211\x4EEC\x53BB\x516C\x56ED\x73A9")); |
| 1456 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1453 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| 1457 EXPECT_EQ(0U, render_text->cursor_position()); | 1454 EXPECT_EQ(0U, render_text->cursor_position()); |
| 1458 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1455 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 1459 EXPECT_EQ(2U, render_text->cursor_position()); | 1456 EXPECT_EQ(2U, render_text->cursor_position()); |
| 1460 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); | 1457 render_text->MoveCursor(WORD_BREAK, CURSOR_RIGHT, false); |
| 1461 EXPECT_EQ(3U, render_text->cursor_position()); | 1458 EXPECT_EQ(3U, render_text->cursor_position()); |
| (...skipping 1479 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2941 string_size.set_width(string_size.width() / 2); | 2938 string_size.set_width(string_size.width() / 2); |
| 2942 render_text.SetDisplayRect(gfx::Rect(string_size)); | 2939 render_text.SetDisplayRect(gfx::Rect(string_size)); |
| 2943 render_text.EnsureLayout(); | 2940 render_text.EnsureLayout(); |
| 2944 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); | 2941 CFIndex glyph_count = CTLineGetGlyphCount(render_text.line_); |
| 2945 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 2942 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
| 2946 EXPECT_NE(0, glyph_count); | 2943 EXPECT_NE(0, glyph_count); |
| 2947 } | 2944 } |
| 2948 #endif | 2945 #endif |
| 2949 | 2946 |
| 2950 } // namespace gfx | 2947 } // namespace gfx |
| OLD | NEW |