| 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/views/controls/label.h" | 5 #include "ui/views/controls/label.h" |
| 6 | 6 |
| 7 #include "base/i18n/rtl.h" | 7 #include "base/i18n/rtl.h" |
| 8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "ui/accessibility/ax_view_state.h" | 10 #include "ui/accessibility/ax_view_state.h" |
| (...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 521 int flags; | 521 int flags; |
| 522 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 522 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 523 EXPECT_EQ(test_text, paint_text); | 523 EXPECT_EQ(test_text, paint_text); |
| 524 EXPECT_EQ(extra.width() / 2, text_bounds.x()); | 524 EXPECT_EQ(extra.width() / 2, text_bounds.x()); |
| 525 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 525 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 526 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 526 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 527 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 527 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 528 int expected_flags = gfx::Canvas::MULTI_LINE | | 528 int expected_flags = gfx::Canvas::MULTI_LINE | |
| 529 gfx::Canvas::TEXT_ALIGN_CENTER | | 529 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 530 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 530 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 531 #if defined(OS_WIN) | 531 #if !defined(OS_WIN) |
| 532 EXPECT_EQ(expected_flags, flags); | 532 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 533 #else | |
| 534 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 535 #endif | 533 #endif |
| 534 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 536 gfx::Rect center_bounds(text_bounds); | 535 gfx::Rect center_bounds(text_bounds); |
| 537 | 536 |
| 538 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 537 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 539 paint_text.clear(); | 538 paint_text.clear(); |
| 540 text_bounds.SetRect(0, 0, 0, 0); | 539 text_bounds.SetRect(0, 0, 0, 0); |
| 541 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 540 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 542 EXPECT_EQ(test_text, paint_text); | 541 EXPECT_EQ(test_text, paint_text); |
| 543 EXPECT_EQ(0, text_bounds.x()); | 542 EXPECT_EQ(0, text_bounds.x()); |
| 544 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 543 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 545 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 544 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 546 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 545 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 547 expected_flags = gfx::Canvas::MULTI_LINE | | 546 expected_flags = gfx::Canvas::MULTI_LINE | |
| 548 gfx::Canvas::TEXT_ALIGN_LEFT | | 547 gfx::Canvas::TEXT_ALIGN_LEFT | |
| 549 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 548 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 550 #if defined(OS_WIN) | 549 #if !defined(OS_WIN) |
| 551 EXPECT_EQ(expected_flags, flags); | 550 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 552 #else | |
| 553 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 554 #endif | 551 #endif |
| 552 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 555 | 553 |
| 556 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 554 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 557 paint_text.clear(); | 555 paint_text.clear(); |
| 558 text_bounds.SetRect(0, 0, 0, 0); | 556 text_bounds.SetRect(0, 0, 0, 0); |
| 559 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 557 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 560 EXPECT_EQ(test_text, paint_text); | 558 EXPECT_EQ(test_text, paint_text); |
| 561 EXPECT_EQ(extra.width(), text_bounds.x()); | 559 EXPECT_EQ(extra.width(), text_bounds.x()); |
| 562 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 560 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 563 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 561 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 564 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 562 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 565 expected_flags = gfx::Canvas::MULTI_LINE | | 563 expected_flags = gfx::Canvas::MULTI_LINE | |
| 566 gfx::Canvas::TEXT_ALIGN_RIGHT | | 564 gfx::Canvas::TEXT_ALIGN_RIGHT | |
| 567 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 565 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 568 #if defined(OS_WIN) | 566 #if !defined(OS_WIN) |
| 569 EXPECT_EQ(expected_flags, flags); | 567 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 570 #else | |
| 571 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 572 #endif | 568 #endif |
| 569 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 573 | 570 |
| 574 // Test multiline drawing with a border. | 571 // Test multiline drawing with a border. |
| 575 gfx::Insets border(19, 92, 23, 2); | 572 gfx::Insets border(19, 92, 23, 2); |
| 576 label.SetBorder(Border::CreateEmptyBorder( | 573 label.SetBorder(Border::CreateEmptyBorder( |
| 577 border.top(), border.left(), border.bottom(), border.right())); | 574 border.top(), border.left(), border.bottom(), border.right())); |
| 578 label.SizeToFit(0); | 575 label.SizeToFit(0); |
| 579 label.SetBounds(label.x(), | 576 label.SetBounds(label.x(), |
| 580 label.y(), | 577 label.y(), |
| 581 label.width() + extra.width(), | 578 label.width() + extra.width(), |
| 582 label.height() + extra.height()); | 579 label.height() + extra.height()); |
| 583 | 580 |
| 584 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 581 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 585 paint_text.clear(); | 582 paint_text.clear(); |
| 586 text_bounds.SetRect(0, 0, 0, 0); | 583 text_bounds.SetRect(0, 0, 0, 0); |
| 587 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 584 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 588 EXPECT_EQ(test_text, paint_text); | 585 EXPECT_EQ(test_text, paint_text); |
| 589 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); | 586 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); |
| 590 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 587 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 591 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 588 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 592 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 589 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 593 expected_flags = gfx::Canvas::MULTI_LINE | | 590 expected_flags = gfx::Canvas::MULTI_LINE | |
| 594 gfx::Canvas::TEXT_ALIGN_CENTER | | 591 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 595 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 592 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 596 #if defined(OS_WIN) | 593 #if !defined(OS_WIN) |
| 597 EXPECT_EQ(expected_flags, flags); | 594 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 598 #else | |
| 599 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 600 #endif | 595 #endif |
| 596 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 601 | 597 |
| 602 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 598 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 603 paint_text.clear(); | 599 paint_text.clear(); |
| 604 text_bounds.SetRect(0, 0, 0, 0); | 600 text_bounds.SetRect(0, 0, 0, 0); |
| 605 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 601 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 606 EXPECT_EQ(test_text, paint_text); | 602 EXPECT_EQ(test_text, paint_text); |
| 607 EXPECT_EQ(border.left(), text_bounds.x()); | 603 EXPECT_EQ(border.left(), text_bounds.x()); |
| 608 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 604 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 609 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 605 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 610 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 606 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 611 expected_flags = gfx::Canvas::MULTI_LINE | | 607 expected_flags = gfx::Canvas::MULTI_LINE | |
| 612 gfx::Canvas::TEXT_ALIGN_LEFT | | 608 gfx::Canvas::TEXT_ALIGN_LEFT | |
| 613 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 609 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 614 #if defined(OS_WIN) | 610 #if !defined(OS_WIN) |
| 615 EXPECT_EQ(expected_flags, flags); | 611 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 616 #else | |
| 617 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 618 #endif | 612 #endif |
| 613 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 619 | 614 |
| 620 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 615 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 621 paint_text.clear(); | 616 paint_text.clear(); |
| 622 text_bounds.SetRect(0, 0, 0, 0); | 617 text_bounds.SetRect(0, 0, 0, 0); |
| 623 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 618 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 624 EXPECT_EQ(test_text, paint_text); | 619 EXPECT_EQ(test_text, paint_text); |
| 625 EXPECT_EQ(extra.width() + border.left(), text_bounds.x()); | 620 EXPECT_EQ(extra.width() + border.left(), text_bounds.x()); |
| 626 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 621 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 627 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 622 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 628 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 623 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 629 expected_flags = gfx::Canvas::MULTI_LINE | | 624 expected_flags = gfx::Canvas::MULTI_LINE | |
| 630 gfx::Canvas::TEXT_ALIGN_RIGHT | | 625 gfx::Canvas::TEXT_ALIGN_RIGHT | |
| 631 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 626 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 632 #if defined(OS_WIN) | 627 #if !defined(OS_WIN) |
| 633 EXPECT_EQ(expected_flags, flags); | 628 expected_flags |= gfx::Canvas::NO_ELLIPSIS; |
| 634 #else | |
| 635 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | |
| 636 #endif | 629 #endif |
| 630 EXPECT_EQ(expected_flags, expected_flags & flags); |
| 637 } | 631 } |
| 638 | 632 |
| 639 TEST(LabelTest, DrawSingleLineStringInRTL) { | 633 TEST(LabelTest, DrawSingleLineStringInRTL) { |
| 640 Label label; | 634 Label label; |
| 641 label.SetFocusable(false); | 635 label.SetFocusable(false); |
| 642 | 636 |
| 643 std::string locale = l10n_util::GetApplicationLocale(""); | 637 std::string locale = l10n_util::GetApplicationLocale(""); |
| 644 base::i18n::SetICUDefaultLocale("he"); | 638 base::i18n::SetICUDefaultLocale("he"); |
| 645 | 639 |
| 646 base::string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); | 640 base::string16 test_text(ASCIIToUTF16("Here's a string with no returns.")); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 794 // Do some basic verifications for all three alignments. | 788 // Do some basic verifications for all three alignments. |
| 795 base::string16 paint_text; | 789 base::string16 paint_text; |
| 796 gfx::Rect text_bounds; | 790 gfx::Rect text_bounds; |
| 797 int flags; | 791 int flags; |
| 798 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 792 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 799 EXPECT_EQ(test_text, paint_text); | 793 EXPECT_EQ(test_text, paint_text); |
| 800 EXPECT_EQ(extra.width() / 2, text_bounds.x()); | 794 EXPECT_EQ(extra.width() / 2, text_bounds.x()); |
| 801 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 795 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 802 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 796 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 803 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 797 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 804 #if defined(OS_WIN) | 798 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 805 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 799 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_CENTER & flags); |
| 806 #else | 800 #if !defined(OS_WIN) |
| 807 EXPECT_EQ( | 801 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 808 gfx::Canvas::MULTI_LINE | | |
| 809 gfx::Canvas::TEXT_ALIGN_CENTER | | |
| 810 gfx::Canvas::NO_ELLIPSIS, | |
| 811 flags); | |
| 812 #endif | 802 #endif |
| 813 gfx::Rect center_bounds(text_bounds); | 803 gfx::Rect center_bounds(text_bounds); |
| 814 | 804 |
| 815 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 805 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 816 paint_text.clear(); | 806 paint_text.clear(); |
| 817 text_bounds.SetRect(0, 0, 0, 0); | 807 text_bounds.SetRect(0, 0, 0, 0); |
| 818 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 808 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 819 EXPECT_EQ(test_text, paint_text); | 809 EXPECT_EQ(test_text, paint_text); |
| 820 EXPECT_EQ(extra.width(), text_bounds.x()); | 810 EXPECT_EQ(extra.width(), text_bounds.x()); |
| 821 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 811 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 822 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 812 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 823 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 813 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 824 #if defined(OS_WIN) | 814 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 825 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 815 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_RIGHT & flags); |
| 826 #else | 816 #if !defined(OS_WIN) |
| 827 EXPECT_EQ( | 817 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 828 gfx::Canvas::MULTI_LINE | | |
| 829 gfx::Canvas::TEXT_ALIGN_RIGHT | | |
| 830 gfx::Canvas::NO_ELLIPSIS, | |
| 831 flags); | |
| 832 #endif | 818 #endif |
| 833 | 819 |
| 834 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 820 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 835 paint_text.clear(); | 821 paint_text.clear(); |
| 836 text_bounds.SetRect(0, 0, 0, 0); | 822 text_bounds.SetRect(0, 0, 0, 0); |
| 837 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 823 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 838 EXPECT_EQ(test_text, paint_text); | 824 EXPECT_EQ(test_text, paint_text); |
| 839 EXPECT_EQ(0, text_bounds.x()); | 825 EXPECT_EQ(0, text_bounds.x()); |
| 840 EXPECT_EQ(extra.height() / 2, text_bounds.y()); | 826 EXPECT_EQ(extra.height() / 2, text_bounds.y()); |
| 841 EXPECT_GT(text_bounds.width(), kMinTextDimension); | 827 EXPECT_GT(text_bounds.width(), kMinTextDimension); |
| 842 EXPECT_GT(text_bounds.height(), kMinTextDimension); | 828 EXPECT_GT(text_bounds.height(), kMinTextDimension); |
| 843 #if defined(OS_WIN) | 829 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 844 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 830 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_LEFT & flags); |
| 845 #else | 831 #if !defined(OS_WIN) |
| 846 EXPECT_EQ( | 832 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 847 gfx::Canvas::MULTI_LINE | | |
| 848 gfx::Canvas::TEXT_ALIGN_LEFT | | |
| 849 gfx::Canvas::NO_ELLIPSIS, | |
| 850 flags); | |
| 851 #endif | 833 #endif |
| 852 | 834 |
| 853 // Test multiline drawing with a border. | 835 // Test multiline drawing with a border. |
| 854 gfx::Insets border(19, 92, 23, 2); | 836 gfx::Insets border(19, 92, 23, 2); |
| 855 label.SetBorder(Border::CreateEmptyBorder( | 837 label.SetBorder(Border::CreateEmptyBorder( |
| 856 border.top(), border.left(), border.bottom(), border.right())); | 838 border.top(), border.left(), border.bottom(), border.right())); |
| 857 label.SizeToFit(0); | 839 label.SizeToFit(0); |
| 858 label.SetBounds(label.x(), | 840 label.SetBounds(label.x(), |
| 859 label.y(), | 841 label.y(), |
| 860 label.width() + extra.width(), | 842 label.width() + extra.width(), |
| 861 label.height() + extra.height()); | 843 label.height() + extra.height()); |
| 862 | 844 |
| 863 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 845 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| 864 paint_text.clear(); | 846 paint_text.clear(); |
| 865 text_bounds.SetRect(0, 0, 0, 0); | 847 text_bounds.SetRect(0, 0, 0, 0); |
| 866 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 848 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 867 EXPECT_EQ(test_text, paint_text); | 849 EXPECT_EQ(test_text, paint_text); |
| 868 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); | 850 EXPECT_EQ(border.left() + extra.width() / 2, text_bounds.x()); |
| 869 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 851 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 870 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 852 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 871 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 853 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 872 #if defined(OS_WIN) | 854 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 873 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_CENTER, flags); | 855 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_CENTER & flags); |
| 874 #else | 856 #if !defined(OS_WIN) |
| 875 EXPECT_EQ( | 857 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 876 gfx::Canvas::MULTI_LINE | | |
| 877 gfx::Canvas::TEXT_ALIGN_CENTER | | |
| 878 gfx::Canvas::NO_ELLIPSIS, | |
| 879 flags); | |
| 880 #endif | 858 #endif |
| 881 | 859 |
| 882 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); | 860 label.SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 883 paint_text.clear(); | 861 paint_text.clear(); |
| 884 text_bounds.SetRect(0, 0, 0, 0); | 862 text_bounds.SetRect(0, 0, 0, 0); |
| 885 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 863 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 886 EXPECT_EQ(test_text, paint_text); | 864 EXPECT_EQ(test_text, paint_text); |
| 887 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); | 865 EXPECT_EQ(border.left() + extra.width(), text_bounds.x()); |
| 888 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 866 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 889 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 867 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 890 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 868 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 891 #if defined(OS_WIN) | 869 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 892 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_RIGHT, flags); | 870 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_RIGHT & flags); |
| 893 #else | 871 #if !defined(OS_WIN) |
| 894 EXPECT_EQ( | 872 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 895 gfx::Canvas::MULTI_LINE | | |
| 896 gfx::Canvas::TEXT_ALIGN_RIGHT | | |
| 897 gfx::Canvas::NO_ELLIPSIS, | |
| 898 flags); | |
| 899 #endif | 873 #endif |
| 900 | 874 |
| 901 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); | 875 label.SetHorizontalAlignment(gfx::ALIGN_RIGHT); |
| 902 paint_text.clear(); | 876 paint_text.clear(); |
| 903 text_bounds.SetRect(0, 0, 0, 0); | 877 text_bounds.SetRect(0, 0, 0, 0); |
| 904 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); | 878 label.CalculateDrawStringParams(&paint_text, &text_bounds, &flags); |
| 905 EXPECT_EQ(test_text, paint_text); | 879 EXPECT_EQ(test_text, paint_text); |
| 906 EXPECT_EQ(border.left(), text_bounds.x()); | 880 EXPECT_EQ(border.left(), text_bounds.x()); |
| 907 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); | 881 EXPECT_EQ(border.top() + extra.height() / 2, text_bounds.y()); |
| 908 EXPECT_EQ(center_bounds.width(), text_bounds.width()); | 882 EXPECT_EQ(center_bounds.width(), text_bounds.width()); |
| 909 EXPECT_EQ(center_bounds.height(), text_bounds.height()); | 883 EXPECT_EQ(center_bounds.height(), text_bounds.height()); |
| 910 #if defined(OS_WIN) | 884 EXPECT_TRUE(gfx::Canvas::MULTI_LINE & flags); |
| 911 EXPECT_EQ(gfx::Canvas::MULTI_LINE | gfx::Canvas::TEXT_ALIGN_LEFT, flags); | 885 EXPECT_TRUE(gfx::Canvas::TEXT_ALIGN_LEFT & flags); |
| 912 #else | 886 #if !defined(OS_WIN) |
| 913 EXPECT_EQ( | 887 EXPECT_TRUE(gfx::Canvas::NO_ELLIPSIS & flags); |
| 914 gfx::Canvas::MULTI_LINE | | |
| 915 gfx::Canvas::TEXT_ALIGN_LEFT | | |
| 916 gfx::Canvas::NO_ELLIPSIS, | |
| 917 flags); | |
| 918 #endif | 888 #endif |
| 919 | 889 |
| 920 // Reset Locale | 890 // Reset Locale |
| 921 base::i18n::SetICUDefaultLocale(locale); | 891 base::i18n::SetICUDefaultLocale(locale); |
| 922 } | 892 } |
| 923 | 893 |
| 924 // Check that we disable subpixel rendering when a transparent background is | 894 // Check that we disable subpixel rendering when a transparent background is |
| 925 // being used. | 895 // being used. |
| 926 TEST(LabelTest, DisableSubpixelRendering) { | 896 TEST(LabelTest, DisableSubpixelRendering) { |
| 927 Label label; | 897 Label label; |
| (...skipping 30 matching lines...) Expand all Loading... |
| 958 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 928 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 959 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 929 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 960 | 930 |
| 961 // GetTooltipHandlerForPoint works should work in child bounds. | 931 // GetTooltipHandlerForPoint works should work in child bounds. |
| 962 label.SetBounds(2, 2, 10, 10); | 932 label.SetBounds(2, 2, 10, 10); |
| 963 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 933 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 964 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 934 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 965 } | 935 } |
| 966 | 936 |
| 967 } // namespace views | 937 } // namespace views |
| OLD | NEW |