| 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 <limits.h> | 7 #include <limits.h> |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <stdint.h> | 9 #include <stdint.h> |
| 10 | 10 |
| (...skipping 516 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 const Font& font, | 527 const Font& font, |
| 528 const FontRenderParams& params, | 528 const FontRenderParams& params, |
| 529 internal::TextRunHarfBuzz* run) { | 529 internal::TextRunHarfBuzz* run) { |
| 530 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); | 530 return GetRenderTextHarfBuzz()->ShapeRunWithFont(text, font, params, run); |
| 531 } | 531 } |
| 532 | 532 |
| 533 int GetCursorYForTesting(int line_num = 0) { | 533 int GetCursorYForTesting(int line_num = 0) { |
| 534 return GetRenderText()->GetLineOffset(line_num).y() + 1; | 534 return GetRenderText()->GetLineOffset(line_num).y() + 1; |
| 535 } | 535 } |
| 536 | 536 |
| 537 // Do not use this function to ensure layout. This is only used to run a |
| 538 // subset of the EnsureLayout functionality and check intermediate state. |
| 539 void EnsureLayoutRunList() { GetRenderTextHarfBuzz()->EnsureLayoutRunList(); } |
| 540 |
| 537 private: | 541 private: |
| 538 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); | 542 DISALLOW_COPY_AND_ASSIGN(RenderTextHarfBuzzTest); |
| 539 }; | 543 }; |
| 540 | 544 |
| 541 #if defined(OS_MACOSX) | 545 #if defined(OS_MACOSX) |
| 542 // Test fixture class. Use for tests which are only to be run for RenderTextMac. | 546 // Test fixture class. Use for tests which are only to be run for RenderTextMac. |
| 543 class RenderTextMacTest : public RenderTextTest { | 547 class RenderTextMacTest : public RenderTextTest { |
| 544 public: | 548 public: |
| 545 RenderTextMacTest() {} | 549 RenderTextMacTest() {} |
| 546 | 550 |
| (...skipping 3409 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3956 static_cast<size_t>(CTLineGetGlyphCount(GetCoreTextLine()))); | 3960 static_cast<size_t>(CTLineGetGlyphCount(GetCoreTextLine()))); |
| 3957 | 3961 |
| 3958 render_text->SetElideBehavior(ELIDE_TAIL); | 3962 render_text->SetElideBehavior(ELIDE_TAIL); |
| 3959 string_size.set_width(string_size.width() / 2); | 3963 string_size.set_width(string_size.width() / 2); |
| 3960 render_text->SetDisplayRect(Rect(string_size)); | 3964 render_text->SetDisplayRect(Rect(string_size)); |
| 3961 test_api()->EnsureLayout(); | 3965 test_api()->EnsureLayout(); |
| 3962 CFIndex glyph_count = CTLineGetGlyphCount(GetCoreTextLine()); | 3966 CFIndex glyph_count = CTLineGetGlyphCount(GetCoreTextLine()); |
| 3963 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); | 3967 EXPECT_GT(text.size(), static_cast<size_t>(glyph_count)); |
| 3964 EXPECT_NE(0, glyph_count); | 3968 EXPECT_NE(0, glyph_count); |
| 3965 } | 3969 } |
| 3970 |
| 3971 TEST_P(RenderTextMacTest, LinesInvalidationOnElideBehaviorChange) { |
| 3972 RenderTextMac* render_text = GetRenderTextMac(); |
| 3973 render_text->SetText(ASCIIToUTF16("This is an example")); |
| 3974 test_api()->EnsureLayout(); |
| 3975 EXPECT_TRUE(GetCoreTextLine()); |
| 3976 |
| 3977 // Lines are cleared when elide behavior changes. |
| 3978 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
| 3979 EXPECT_FALSE(GetCoreTextLine()); |
| 3980 } |
| 3966 #endif // defined(OS_MACOSX) | 3981 #endif // defined(OS_MACOSX) |
| 3967 | 3982 |
| 3968 // Ensure color changes are picked up by the RenderText implementation. | 3983 // Ensure color changes are picked up by the RenderText implementation. |
| 3969 TEST_P(RenderTextTest, ColorChange) { | 3984 TEST_P(RenderTextTest, ColorChange) { |
| 3970 RenderText* render_text = GetRenderText(); | 3985 RenderText* render_text = GetRenderText(); |
| 3971 render_text->SetText(ASCIIToUTF16("x")); | 3986 render_text->SetText(ASCIIToUTF16("x")); |
| 3972 DrawVisualText(); | 3987 DrawVisualText(); |
| 3973 | 3988 |
| 3974 std::vector<TestSkiaTextRenderer::TextLog> text_log; | 3989 std::vector<TestSkiaTextRenderer::TextLog> text_log; |
| 3975 renderer()->GetTextLogAndReset(&text_log); | 3990 renderer()->GetTextLogAndReset(&text_log); |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4402 #endif | 4417 #endif |
| 4403 const std::string font_name = "invalid_font"; | 4418 const std::string font_name = "invalid_font"; |
| 4404 const int kFontSize = 13; | 4419 const int kFontSize = 13; |
| 4405 RenderText* render_text = GetRenderText(); | 4420 RenderText* render_text = GetRenderText(); |
| 4406 render_text->SetFontList(FontList(Font(font_name, kFontSize))); | 4421 render_text->SetFontList(FontList(Font(font_name, kFontSize))); |
| 4407 render_text->SetText(ASCIIToUTF16("abc")); | 4422 render_text->SetText(ASCIIToUTF16("abc")); |
| 4408 | 4423 |
| 4409 DrawVisualText(); | 4424 DrawVisualText(); |
| 4410 } | 4425 } |
| 4411 | 4426 |
| 4427 TEST_P(RenderTextHarfBuzzTest, LinesInvalidationOnElideBehaviorChange) { |
| 4428 RenderTextHarfBuzz* render_text = GetRenderTextHarfBuzz(); |
| 4429 render_text->SetText(ASCIIToUTF16("This is an example")); |
| 4430 test_api()->EnsureLayout(); |
| 4431 EXPECT_FALSE(test_api()->lines().empty()); |
| 4432 |
| 4433 // Lines are cleared when elide behavior changes. |
| 4434 render_text->SetElideBehavior(gfx::ELIDE_TAIL); |
| 4435 EnsureLayoutRunList(); |
| 4436 EXPECT_TRUE(test_api()->lines().empty()); |
| 4437 } |
| 4438 |
| 4412 // Ensures that text is centered vertically and consistently when either the | 4439 // Ensures that text is centered vertically and consistently when either the |
| 4413 // display rectangle height changes, or when the minimum line height changes. | 4440 // display rectangle height changes, or when the minimum line height changes. |
| 4414 // The difference between the two is the selection rectangle, which should match | 4441 // The difference between the two is the selection rectangle, which should match |
| 4415 // the line height. | 4442 // the line height. |
| 4416 TEST_P(RenderTextHarfBuzzTest, BaselineWithLineHeight) { | 4443 TEST_P(RenderTextHarfBuzzTest, BaselineWithLineHeight) { |
| 4417 RenderText* render_text = GetRenderText(); | 4444 RenderText* render_text = GetRenderText(); |
| 4418 const int font_height = render_text->font_list().GetHeight(); | 4445 const int font_height = render_text->font_list().GetHeight(); |
| 4419 render_text->SetDisplayRect(Rect(500, font_height)); | 4446 render_text->SetDisplayRect(Rect(500, font_height)); |
| 4420 render_text->SetText(ASCIIToUTF16("abc")); | 4447 render_text->SetText(ASCIIToUTF16("abc")); |
| 4421 | 4448 |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4521 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4548 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4522 PrintRenderTextBackend()); | 4549 PrintRenderTextBackend()); |
| 4523 #endif | 4550 #endif |
| 4524 | 4551 |
| 4525 INSTANTIATE_TEST_CASE_P(, | 4552 INSTANTIATE_TEST_CASE_P(, |
| 4526 RenderTextHarfBuzzTest, | 4553 RenderTextHarfBuzzTest, |
| 4527 ::testing::Values(RENDER_TEXT_HARFBUZZ), | 4554 ::testing::Values(RENDER_TEXT_HARFBUZZ), |
| 4528 PrintRenderTextBackend()); | 4555 PrintRenderTextBackend()); |
| 4529 | 4556 |
| 4530 } // namespace gfx | 4557 } // namespace gfx |
| OLD | NEW |