OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "core/layout/LayoutObject.h" | 5 #include "core/layout/LayoutObject.h" |
6 #include "core/layout/LayoutTestHelper.h" | 6 #include "core/layout/LayoutTestHelper.h" |
7 #include "testing/gtest/include/gtest/gtest.h" | 7 #include "testing/gtest/include/gtest/gtest.h" |
8 | 8 |
9 namespace blink { | 9 namespace blink { |
10 | |
11 class TextAutosizerTest : public RenderingTest { | 10 class TextAutosizerTest : public RenderingTest { |
12 private: | 11 private: |
13 void SetUp() override { | 12 void SetUp() override { |
14 RenderingTest::SetUp(); | 13 RenderingTest::SetUp(); |
15 document().settings()->setTextAutosizingEnabled(true); | 14 document().settings()->setTextAutosizingEnabled(true); |
16 document().settings()->setTextAutosizingWindowSizeOverride( | 15 document().settings()->setTextAutosizingWindowSizeOverride( |
17 IntSize(320, 480)); | 16 IntSize(320, 480)); |
18 } | 17 } |
19 }; | 18 }; |
20 | 19 |
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
480 autosized->layoutObject()->style()->specifiedFontSize()); | 479 autosized->layoutObject()->style()->specifiedFontSize()); |
481 // (device scale adjustment = 1.5) * (specified font-size = 16px) * | 480 // (device scale adjustment = 1.5) * (specified font-size = 16px) * |
482 // (viewport width = 800px) / (window width = 320px) = 60px. | 481 // (viewport width = 800px) / (window width = 320px) = 60px. |
483 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); | 482 EXPECT_FLOAT_EQ(60.f, autosized->layoutObject()->style()->computedFontSize()); |
484 } | 483 } |
485 | 484 |
486 TEST_F(TextAutosizerTest, ChangingSuperClusterFirstText) { | 485 TEST_F(TextAutosizerTest, ChangingSuperClusterFirstText) { |
487 setBodyInnerHTML( | 486 setBodyInnerHTML( |
488 "<meta name='viewport' content='width=800'>" | 487 "<meta name='viewport' content='width=800'>" |
489 "<style>" | 488 "<style>" |
490 " html { font-size: 16px; }" | 489 " html { font-size: 16px; }" |
491 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 490 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
492 " .supercluster { width:560px; }" | 491 " .supercluster { width:560px; }" |
493 "</style>" | 492 "</style>" |
494 "<div class='supercluster'>" | 493 "<div class='supercluster'>" |
495 " <div id='longText'>short blah blah</div>" | 494 " <div id='longText'>short blah blah</div>" |
496 "</div>" | 495 "</div>" |
497 "<div class='supercluster'>" | 496 "<div class='supercluster'>" |
498 " <div id='shortText'>short blah blah</div>" | 497 " <div id='shortText'>short blah blah</div>" |
499 "</div>"); | 498 "</div>"); |
500 document().view()->updateAllLifecyclePhases(); | 499 document().view()->updateAllLifecyclePhases(); |
501 | 500 |
502 Element* longTextElement = document().getElementById("longText"); | 501 Element* longTextElement = document().getElementById("longText"); |
503 longTextElement->setInnerHTML( | 502 longTextElement->setInnerHTML( |
504 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " | 503 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " |
505 "do eiusmod tempor" | 504 "do eiusmod tempor" |
506 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 505 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
507 "veniam, quis nostrud" | 506 "veniam, quis nostrud" |
508 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " | 507 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " |
(...skipping 15 matching lines...) Expand all Loading... |
524 LayoutObject* shortText = | 523 LayoutObject* shortText = |
525 document().getElementById("shortText")->layoutObject(); | 524 document().getElementById("shortText")->layoutObject(); |
526 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); | 525 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); |
527 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); | 526 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); |
528 } | 527 } |
529 | 528 |
530 TEST_F(TextAutosizerTest, ChangingSuperClusterSecondText) { | 529 TEST_F(TextAutosizerTest, ChangingSuperClusterSecondText) { |
531 setBodyInnerHTML( | 530 setBodyInnerHTML( |
532 "<meta name='viewport' content='width=800'>" | 531 "<meta name='viewport' content='width=800'>" |
533 "<style>" | 532 "<style>" |
534 " html { font-size: 16px; }" | 533 " html { font-size: 16px; }" |
535 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 534 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
536 " .supercluster { width:560px; }" | 535 " .supercluster { width:560px; }" |
537 "</style>" | 536 "</style>" |
538 "<div class='supercluster'>" | 537 "<div class='supercluster'>" |
539 " <div id='shortText'>short blah blah</div>" | 538 " <div id='shortText'>short blah blah</div>" |
540 "</div>" | 539 "</div>" |
541 "<div class='supercluster'>" | 540 "<div class='supercluster'>" |
542 " <div id='longText'>short blah blah</div>" | 541 " <div id='longText'>short blah blah</div>" |
543 "</div>"); | 542 "</div>"); |
544 document().view()->updateAllLifecyclePhases(); | 543 document().view()->updateAllLifecyclePhases(); |
545 | 544 |
546 Element* longTextElement = document().getElementById("longText"); | 545 Element* longTextElement = document().getElementById("longText"); |
547 longTextElement->setInnerHTML( | 546 longTextElement->setInnerHTML( |
548 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " | 547 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " |
549 "do eiusmod tempor" | 548 "do eiusmod tempor" |
550 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 549 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
551 "veniam, quis nostrud" | 550 "veniam, quis nostrud" |
552 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " | 551 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " |
(...skipping 15 matching lines...) Expand all Loading... |
568 LayoutObject* shortText = | 567 LayoutObject* shortText = |
569 document().getElementById("shortText")->layoutObject(); | 568 document().getElementById("shortText")->layoutObject(); |
570 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); | 569 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); |
571 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); | 570 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); |
572 } | 571 } |
573 | 572 |
574 TEST_F(TextAutosizerTest, AddingSuperCluster) { | 573 TEST_F(TextAutosizerTest, AddingSuperCluster) { |
575 setBodyInnerHTML( | 574 setBodyInnerHTML( |
576 "<meta name='viewport' content='width=800'>" | 575 "<meta name='viewport' content='width=800'>" |
577 "<style>" | 576 "<style>" |
578 " html { font-size: 16px; }" | 577 " html { font-size: 16px; }" |
579 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 578 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
580 " .supercluster { width:560px; }" | 579 " .supercluster { width:560px; }" |
581 "</style>" | 580 "</style>" |
582 "<div>" | 581 "<div>" |
583 " <div class='supercluster' id='shortText'>" | 582 " <div class='supercluster' id='shortText'>" |
584 " short blah blah" | 583 " short blah blah" |
585 " </div>" | 584 " </div>" |
586 "</div>" | 585 "</div>" |
587 "<div id='container'></div>"); | 586 "<div id='container'></div>"); |
588 document().view()->updateAllLifecyclePhases(); | 587 document().view()->updateAllLifecyclePhases(); |
589 | 588 |
590 Element* container = document().getElementById("container"); | 589 Element* container = document().getElementById("container"); |
591 container->setInnerHTML( | 590 container->setInnerHTML( |
592 "<div class='supercluster' id='longText'>" | 591 "<div class='supercluster' id='longText'>" |
593 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " | 592 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " |
594 "do eiusmod tempor" | 593 "do eiusmod tempor" |
595 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 594 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
(...skipping 18 matching lines...) Expand all Loading... |
614 LayoutObject* shortText = | 613 LayoutObject* shortText = |
615 document().getElementById("shortText")->layoutObject(); | 614 document().getElementById("shortText")->layoutObject(); |
616 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); | 615 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); |
617 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); | 616 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); |
618 } | 617 } |
619 | 618 |
620 TEST_F(TextAutosizerTest, ChangingInheritedClusterTextInsideSuperCluster) { | 619 TEST_F(TextAutosizerTest, ChangingInheritedClusterTextInsideSuperCluster) { |
621 setBodyInnerHTML( | 620 setBodyInnerHTML( |
622 "<meta name='viewport' content='width=800'>" | 621 "<meta name='viewport' content='width=800'>" |
623 "<style>" | 622 "<style>" |
624 " html { font-size: 16px; }" | 623 " html { font-size: 16px; }" |
625 " body { width: 800px; margin: 0; overflow-y: hidden; }" | 624 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
626 " .supercluster { width:560px; }" | 625 " .supercluster { width:560px; }" |
627 " .cluster{width:560px;}" | 626 " .cluster{width:560px;}" |
628 "</style>" | 627 "</style>" |
629 "<div class='supercluster'>" | 628 "<div class='supercluster'>" |
630 " <div class='cluster' id='longText'>short blah blah</div>" | 629 " <div class='cluster' id='longText'>short blah blah</div>" |
631 "</div>" | 630 "</div>" |
632 "<div class='supercluster'>" | 631 "<div class='supercluster'>" |
633 " <div class='cluster' id='shortText'>short blah blah</div>" | 632 " <div class='cluster' id='shortText'>short blah blah</div>" |
634 "</div>"); | 633 "</div>"); |
635 document().view()->updateAllLifecyclePhases(); | 634 document().view()->updateAllLifecyclePhases(); |
636 | 635 |
637 Element* longTextElement = document().getElementById("longText"); | 636 Element* longTextElement = document().getElementById("longText"); |
638 longTextElement->setInnerHTML( | 637 longTextElement->setInnerHTML( |
639 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " | 638 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed " |
640 "do eiusmod tempor" | 639 "do eiusmod tempor" |
641 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " | 640 " incididunt ut labore et dolore magna aliqua. Ut enim ad minim " |
642 "veniam, quis nostrud" | 641 "veniam, quis nostrud" |
643 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " | 642 " exercitation ullamco laboris nisi ut aliquip ex ea commodo " |
(...skipping 10 matching lines...) Expand all Loading... |
654 document().getElementById("longText")->layoutObject(); | 653 document().getElementById("longText")->layoutObject(); |
655 EXPECT_FLOAT_EQ(16.f, longText->style()->specifiedFontSize()); | 654 EXPECT_FLOAT_EQ(16.f, longText->style()->specifiedFontSize()); |
656 //(specified font-size = 16px) * (block width = 560px) / | 655 //(specified font-size = 16px) * (block width = 560px) / |
657 // (window width = 320px) = 28px. | 656 // (window width = 320px) = 28px. |
658 EXPECT_FLOAT_EQ(28.f, longText->style()->computedFontSize()); | 657 EXPECT_FLOAT_EQ(28.f, longText->style()->computedFontSize()); |
659 LayoutObject* shortText = | 658 LayoutObject* shortText = |
660 document().getElementById("shortText")->layoutObject(); | 659 document().getElementById("shortText")->layoutObject(); |
661 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); | 660 EXPECT_FLOAT_EQ(16.f, shortText->style()->specifiedFontSize()); |
662 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); | 661 EXPECT_FLOAT_EQ(28.f, shortText->style()->computedFontSize()); |
663 } | 662 } |
| 663 |
| 664 TEST_F(TextAutosizerTest, AutosizeInnerContentOfRuby) { |
| 665 setBodyInnerHTML( |
| 666 "<meta name='viewport' content='width=800'>" |
| 667 "<style>" |
| 668 " html { font-size: 16px; }" |
| 669 " body { width: 800px; margin: 0; overflow-y: hidden; }" |
| 670 "</style>" |
| 671 "<div id='autosized'>" |
| 672 " 東京特許許可局許可局長 今日" |
| 673 " <ruby>" |
| 674 " <rb id='rubyInline'>急遽</rb>" |
| 675 " <rp>(</rp>" |
| 676 " <rt>きゅうきょ</rt>" |
| 677 " <rp>)</rp>" |
| 678 " </ruby>" |
| 679 " 許可却下、<br><br>" |
| 680 " <span>" |
| 681 " Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec " |
| 682 " sed diam facilisis, elementum elit at, elementum sem. Aliquam " |
| 683 " consectetur leo at nisi fermentum, vitae maximus libero " |
| 684 "sodales. Sed " |
| 685 " laoreet congue ipsum, at tincidunt ante tempor sed. Cras eget " |
| 686 "erat " |
| 687 " mattis urna vestibulum porta. Sed tempus vitae dui et suscipit. " |
| 688 " Curabitur laoreet accumsan pharetra. Nunc facilisis, elit sit " |
| 689 "amet " |
| 690 " sollicitudin condimentum, ipsum velit ultricies mi, eget " |
| 691 "dapibus nunc " |
| 692 " nulla nec sapien. Fusce dictum imperdiet aliquet." |
| 693 " </span>" |
| 694 " <ruby style='display:block'>" |
| 695 " <rb id='rubyBlock'>拼音</rb>" |
| 696 " <rt>pin yin</rt>" |
| 697 " </ruby>" |
| 698 "</div>"); |
| 699 document().view()->updateAllLifecyclePhases(); |
| 700 |
| 701 Element* rubyInline = document().getElementById("rubyInline"); |
| 702 EXPECT_FLOAT_EQ(16.f, |
| 703 rubyInline->layoutObject()->style()->specifiedFontSize()); |
| 704 // (specified font-size = 16px) * (viewport width = 800px) / |
| 705 // (window width = 320px) = 40px. |
| 706 EXPECT_FLOAT_EQ(40.f, |
| 707 rubyInline->layoutObject()->style()->computedFontSize()); |
| 708 |
| 709 Element* rubyBlock = document().getElementById("rubyBlock"); |
| 710 EXPECT_FLOAT_EQ(16.f, |
| 711 rubyBlock->layoutObject()->style()->specifiedFontSize()); |
| 712 // (specified font-size = 16px) * (viewport width = 800px) / |
| 713 // (window width = 320px) = 40px. |
| 714 EXPECT_FLOAT_EQ(40.f, rubyBlock->layoutObject()->style()->computedFontSize()); |
| 715 } |
| 716 |
| 717 TEST_F(TextAutosizerTest, ResizeAndGlyphOverflowChanged) { |
| 718 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(360, 640)); |
| 719 Element* html = document().body()->parentElement(); |
| 720 html->setInnerHTML( |
| 721 "<head>" |
| 722 " <meta name='viewport' content='800'>" |
| 723 " <style>" |
| 724 " html { font-size:16px; font-family:'Times New Roman';}" |
| 725 " </style>" |
| 726 "</head>" |
| 727 "<body>" |
| 728 " <span id='autosized' style='font-size:10px'>" |
| 729 " Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do" |
| 730 " eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim" |
| 731 " ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut" |
| 732 " aliquip ex ea commodo consequat. Duis aute irure dolor in" |
| 733 " reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla" |
| 734 " pariatur. Excepteur sint occaecat cupidatat non proident, sunt in" |
| 735 " culpa qui officia deserunt mollit anim id est laborum." |
| 736 " </span>" |
| 737 " <span style='font-size:8px'>n</span>" |
| 738 " <span style='font-size:9px'>n</span>" |
| 739 " <span style='font-size:10px'>n</span>" |
| 740 " <span style='font-size:11px'>n</span>" |
| 741 " <span style='font-size:12px'>n</span>" |
| 742 " <span style='font-size:13px'>n</span>" |
| 743 " <span style='font-size:14px'>n</span>" |
| 744 " <span style='font-size:15px'>n</span>" |
| 745 "</body>", |
| 746 ASSERT_NO_EXCEPTION); |
| 747 document().view()->updateAllLifecyclePhases(); |
| 748 |
| 749 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(640, 360)); |
| 750 document().view()->updateAllLifecyclePhases(); |
| 751 |
| 752 document().settings()->setTextAutosizingWindowSizeOverride(IntSize(360, 640)); |
| 753 document().view()->updateAllLifecyclePhases(); |
| 754 } |
664 } // namespace blink | 755 } // namespace blink |
OLD | NEW |