Chromium Code Reviews| 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/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 1061 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1072 EXPECT_EQ(Range(5), render_text->selection()); | 1072 EXPECT_EQ(Range(5), render_text->selection()); |
| 1073 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1073 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 1074 EXPECT_EQ(Range(4), render_text->selection()); | 1074 EXPECT_EQ(Range(4), render_text->selection()); |
| 1075 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1075 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); |
| 1076 EXPECT_EQ(Range(4, 5), render_text->selection()); | 1076 EXPECT_EQ(Range(4, 5), render_text->selection()); |
| 1077 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); | 1077 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_LEFT, true); |
| 1078 EXPECT_EQ(Range(4, 6), render_text->selection()); | 1078 EXPECT_EQ(Range(4, 6), render_text->selection()); |
| 1079 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); | 1079 render_text->MoveCursor(CHARACTER_BREAK, CURSOR_RIGHT, false); |
| 1080 EXPECT_EQ(Range(4), render_text->selection()); | 1080 EXPECT_EQ(Range(4), render_text->selection()); |
| 1081 } | 1081 } |
| 1082 | |
| 1083 TEST_F(RenderTextTest, DisplayOffsetForCenteredTextChangingAtEnds) { | |
|
msw
2014/07/22 22:00:27
nit: consider CenteredDisplayOffset or similar.
mohsen
2014/07/22 23:38:35
Done.
| |
| 1084 scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); | |
| 1085 render_text->SetText(ASCIIToUTF16("abcdefghij")); | |
| 1086 render_text->SetHorizontalAlignment(ALIGN_CENTER); | |
| 1087 | |
| 1088 const int kEnlargement = 10; | |
| 1089 const int content_width = render_text->GetContentWidth(); | |
| 1090 Rect display_rect(0, 0, content_width / 2, | |
| 1091 render_text->font_list().GetHeight()); | |
| 1092 render_text->SetDisplayRect(display_rect); | |
| 1093 | |
| 1094 // Move the cursor to the beginning of the text and, by checking the cursor | |
| 1095 // bounds, make sure no empty space is to the left of the text. | |
| 1096 render_text->SetCursorPosition(0); | |
| 1097 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x()); | |
| 1098 | |
| 1099 // Widen the display rect and, by checking the cursor bounds, make sure no | |
| 1100 // empty space is introduced to the left of the text. | |
| 1101 display_rect.Inset(0, 0, -kEnlargement, 0); | |
| 1102 render_text->SetDisplayRect(display_rect); | |
| 1103 EXPECT_EQ(display_rect.x(), render_text->GetUpdatedCursorBounds().x()); | |
| 1104 | |
| 1105 // Move the cursor to the end of the text and, by checking the cursor bounds, | |
| 1106 // make sure no empty space is to the right of the text. | |
| 1107 render_text->SetCursorPosition(render_text->text().length()); | |
| 1108 EXPECT_EQ(display_rect.right(), | |
| 1109 render_text->GetUpdatedCursorBounds().right()); | |
| 1110 | |
| 1111 // Widen the display rect and, by checking the cursor bounds, make sure not | |
|
msw
2014/07/22 22:00:27
nit: s/not/no
mohsen
2014/07/22 23:38:35
Done.
| |
| 1112 // empty space is introduced to the right of the text. | |
| 1113 display_rect.Inset(0, 0, -kEnlargement, 0); | |
| 1114 render_text->SetDisplayRect(display_rect); | |
| 1115 EXPECT_EQ(display_rect.right(), | |
| 1116 render_text->GetUpdatedCursorBounds().right()); | |
| 1117 } | |
| 1082 #endif // !defined(OS_MACOSX) | 1118 #endif // !defined(OS_MACOSX) |
| 1083 | 1119 |
| 1084 // TODO(xji): Make these work on Windows. | 1120 // TODO(xji): Make these work on Windows. |
| 1085 #if defined(OS_LINUX) | 1121 #if defined(OS_LINUX) |
| 1086 void MoveLeftRightByWordVerifier(RenderText* render_text, | 1122 void MoveLeftRightByWordVerifier(RenderText* render_text, |
| 1087 const wchar_t* str) { | 1123 const wchar_t* str) { |
| 1088 render_text->SetText(WideToUTF16(str)); | 1124 render_text->SetText(WideToUTF16(str)); |
| 1089 | 1125 |
| 1090 // Test moving by word from left ro right. | 1126 // Test moving by word from left ro right. |
| 1091 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); | 1127 render_text->MoveCursor(LINE_BREAK, CURSOR_LEFT, false); |
| (...skipping 460 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1552 // [-kEnlargement, 0]. | 1588 // [-kEnlargement, 0]. |
| 1553 { ALIGN_LEFT, -2 * kEnlargement, -kEnlargement }, | 1589 { ALIGN_LEFT, -2 * kEnlargement, -kEnlargement }, |
| 1554 { ALIGN_LEFT, -kEnlargement / 2, -kEnlargement / 2 }, | 1590 { ALIGN_LEFT, -kEnlargement / 2, -kEnlargement / 2 }, |
| 1555 { ALIGN_LEFT, kEnlargement, 0 }, | 1591 { ALIGN_LEFT, kEnlargement, 0 }, |
| 1556 // When text is right-aligned, display offset can be in range | 1592 // When text is right-aligned, display offset can be in range |
| 1557 // [0, kEnlargement]. | 1593 // [0, kEnlargement]. |
| 1558 { ALIGN_RIGHT, -kEnlargement, 0 }, | 1594 { ALIGN_RIGHT, -kEnlargement, 0 }, |
| 1559 { ALIGN_RIGHT, kEnlargement / 2, kEnlargement / 2 }, | 1595 { ALIGN_RIGHT, kEnlargement / 2, kEnlargement / 2 }, |
| 1560 { ALIGN_RIGHT, 2 * kEnlargement, kEnlargement }, | 1596 { ALIGN_RIGHT, 2 * kEnlargement, kEnlargement }, |
| 1561 // When text is center-aligned, display offset can be in range | 1597 // When text is center-aligned, display offset can be in range |
| 1562 // [-kEnlargement / 2, kEnlargement / 2]. | 1598 // [-kEnlargement / 2 - 1, (kEnlargement - 1) / 2]. |
| 1563 { ALIGN_CENTER, -kEnlargement, -kEnlargement / 2 }, | 1599 { ALIGN_CENTER, -kEnlargement, -kEnlargement / 2 - 1 }, |
| 1564 { ALIGN_CENTER, -kEnlargement / 4, -kEnlargement / 4 }, | 1600 { ALIGN_CENTER, -kEnlargement / 4, -kEnlargement / 4 }, |
| 1565 { ALIGN_CENTER, kEnlargement / 4, kEnlargement / 4 }, | 1601 { ALIGN_CENTER, kEnlargement / 4, kEnlargement / 4 }, |
| 1566 { ALIGN_CENTER, kEnlargement, kEnlargement / 2 }, | 1602 { ALIGN_CENTER, kEnlargement, (kEnlargement - 1) / 2 }, |
| 1567 }; | 1603 }; |
| 1568 | 1604 |
| 1569 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(large_content_cases); i++) { | 1605 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(large_content_cases); i++) { |
| 1570 render_text->SetHorizontalAlignment(large_content_cases[i].alignment); | 1606 render_text->SetHorizontalAlignment(large_content_cases[i].alignment); |
| 1571 render_text->SetDisplayOffset(large_content_cases[i].offset); | 1607 render_text->SetDisplayOffset(large_content_cases[i].offset); |
| 1572 EXPECT_EQ(large_content_cases[i].expected_offset, | 1608 EXPECT_EQ(large_content_cases[i].expected_offset, |
| 1573 render_text->GetUpdatedDisplayOffset().x()); | 1609 render_text->GetUpdatedDisplayOffset().x()); |
| 1574 } | 1610 } |
| 1575 } | 1611 } |
| 1576 | 1612 |
| (...skipping 543 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2120 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { | 2156 for (size_t i = 0; i < arraysize(kTestStrings); ++i) { |
| 2121 render_text->SetText(WideToUTF16(kTestStrings[i])); | 2157 render_text->SetText(WideToUTF16(kTestStrings[i])); |
| 2122 render_text->EnsureLayout(); | 2158 render_text->EnsureLayout(); |
| 2123 | 2159 |
| 2124 for (size_t j = 0; j < render_text->text().length(); ++j) | 2160 for (size_t j = 0; j < render_text->text().length(); ++j) |
| 2125 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); | 2161 EXPECT_FALSE(render_text->GetGlyphBounds(j).is_empty()); |
| 2126 } | 2162 } |
| 2127 } | 2163 } |
| 2128 | 2164 |
| 2129 } // namespace gfx | 2165 } // namespace gfx |
| OLD | NEW |