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