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 "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/gfx/break_list.h" | 10 #include "ui/gfx/break_list.h" |
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 // FindCursorPosition() should not return positions between a surrogate pair. | 278 // FindCursorPosition() should not return positions between a surrogate pair. |
279 render_text->SetDisplayRect(Rect(0, 0, 20, 20)); | 279 render_text->SetDisplayRect(Rect(0, 0, 20, 20)); |
280 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); | 280 EXPECT_EQ(render_text->FindCursorPosition(Point(0, 0)).caret_pos(), 0U); |
281 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); | 281 EXPECT_EQ(render_text->FindCursorPosition(Point(20, 0)).caret_pos(), 2U); |
282 for (int x = -1; x <= 20; ++x) { | 282 for (int x = -1; x <= 20; ++x) { |
283 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); | 283 SelectionModel selection = render_text->FindCursorPosition(Point(x, 0)); |
284 EXPECT_TRUE(selection.caret_pos() == 0U || selection.caret_pos() == 2U); | 284 EXPECT_TRUE(selection.caret_pos() == 0U || selection.caret_pos() == 2U); |
285 } | 285 } |
286 | 286 |
287 // GetGlyphBounds() should yield the entire string bounds for text index 0. | 287 // GetGlyphBounds() should yield the entire string bounds for text index 0. |
288 int height = 0; | |
289 ui::Range bounds; | |
290 render_text->GetGlyphBounds(0U, &bounds, &height); | |
291 EXPECT_EQ(render_text->GetStringSize().width(), | 288 EXPECT_EQ(render_text->GetStringSize().width(), |
292 static_cast<int>(bounds.length())); | 289 static_cast<int>(render_text->GetGlyphBounds(0U).length())); |
293 | 290 |
294 // Cursoring is independent of underlying characters when text is obscured. | 291 // Cursoring is independent of underlying characters when text is obscured. |
295 const wchar_t* const texts[] = { | 292 const wchar_t* const texts[] = { |
296 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, | 293 kWeak, kLtr, kLtrRtl, kLtrRtlLtr, kRtl, kRtlLtr, kRtlLtrRtl, |
297 L"hop on pop", // Check LTR word boundaries. | 294 L"hop on pop", // Check LTR word boundaries. |
298 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. | 295 L"\x05d0\x05d1 \x05d0\x05d2 \x05d1\x05d2", // Check RTL word boundaries. |
299 }; | 296 }; |
300 for (size_t i = 0; i < arraysize(texts); ++i) { | 297 for (size_t i = 0; i < arraysize(texts); ++i) { |
301 string16 text = WideToUTF16(texts[i]); | 298 string16 text = WideToUTF16(texts[i]); |
302 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); | 299 TestVisualCursorMotionInObscuredField(render_text.get(), text, false); |
(...skipping 1006 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1309 EXPECT_EQ(render_text->display_rect().width() - width - 1, | 1306 EXPECT_EQ(render_text->display_rect().width() - width - 1, |
1310 render_text->GetUpdatedCursorBounds().x()); | 1307 render_text->GetUpdatedCursorBounds().x()); |
1311 | 1308 |
1312 // Reset the application default text direction to LTR. | 1309 // Reset the application default text direction to LTR. |
1313 SetRTL(was_rtl); | 1310 SetRTL(was_rtl); |
1314 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); | 1311 EXPECT_EQ(was_rtl, base::i18n::IsRTL()); |
1315 } | 1312 } |
1316 #endif // !defined(OS_MACOSX) | 1313 #endif // !defined(OS_MACOSX) |
1317 | 1314 |
1318 } // namespace gfx | 1315 } // namespace gfx |
OLD | NEW |