| 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/base/accessibility/accessible_view_state.h" | 10 #include "ui/base/accessibility/accessible_view_state.h" |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 162 base::string16 test_text(ASCIIToUTF16("A not so random string in one line.")); | 162 base::string16 test_text(ASCIIToUTF16("A not so random string in one line.")); |
| 163 label.SetText(test_text); | 163 label.SetText(test_text); |
| 164 | 164 |
| 165 // GetPreferredSize | 165 // GetPreferredSize |
| 166 gfx::Size required_size = label.GetPreferredSize(); | 166 gfx::Size required_size = label.GetPreferredSize(); |
| 167 EXPECT_GT(required_size.height(), kMinTextDimension); | 167 EXPECT_GT(required_size.height(), kMinTextDimension); |
| 168 EXPECT_GT(required_size.width(), kMinTextDimension); | 168 EXPECT_GT(required_size.width(), kMinTextDimension); |
| 169 | 169 |
| 170 // Test everything with borders. | 170 // Test everything with borders. |
| 171 gfx::Insets border(10, 20, 30, 40); | 171 gfx::Insets border(10, 20, 30, 40); |
| 172 label.set_border(Border::CreateEmptyBorder(border.top(), | 172 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 173 border.left(), | 173 border.left(), |
| 174 border.bottom(), | 174 border.bottom(), |
| 175 border.right())); | 175 border.right())); |
| 176 | 176 |
| 177 // GetPreferredSize and borders. | 177 // GetPreferredSize and borders. |
| 178 label.SetBounds(0, 0, 0, 0); | 178 label.SetBounds(0, 0, 0, 0); |
| 179 gfx::Size required_size_with_border = label.GetPreferredSize(); | 179 gfx::Size required_size_with_border = label.GetPreferredSize(); |
| 180 EXPECT_EQ(required_size_with_border.height(), | 180 EXPECT_EQ(required_size_with_border.height(), |
| 181 required_size.height() + border.height()); | 181 required_size.height() + border.height()); |
| 182 EXPECT_EQ(required_size_with_border.width(), | 182 EXPECT_EQ(required_size_with_border.width(), |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 EXPECT_GT(height_for_constrained_width, required_height); | 243 EXPECT_GT(height_for_constrained_width, required_height); |
| 244 #endif | 244 #endif |
| 245 // Using the constrained width or the required_width - 1 should give the | 245 // Using the constrained width or the required_width - 1 should give the |
| 246 // same result for the height because the constrainted width is the tight | 246 // same result for the height because the constrainted width is the tight |
| 247 // width when given "required_width - 1" as the max width. | 247 // width when given "required_width - 1" as the max width. |
| 248 EXPECT_EQ(height_for_constrained_width, | 248 EXPECT_EQ(height_for_constrained_width, |
| 249 label.GetHeightForWidth(required_width - 1)); | 249 label.GetHeightForWidth(required_width - 1)); |
| 250 | 250 |
| 251 // Test everything with borders. | 251 // Test everything with borders. |
| 252 gfx::Insets border(10, 20, 30, 40); | 252 gfx::Insets border(10, 20, 30, 40); |
| 253 label.set_border(Border::CreateEmptyBorder(border.top(), | 253 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 254 border.left(), | 254 border.left(), |
| 255 border.bottom(), | 255 border.bottom(), |
| 256 border.right())); | 256 border.right())); |
| 257 | 257 |
| 258 // SizeToFit and borders. | 258 // SizeToFit and borders. |
| 259 label.SizeToFit(0); | 259 label.SizeToFit(0); |
| 260 int required_width_with_border = label.GetLocalBounds().width(); | 260 int required_width_with_border = label.GetLocalBounds().width(); |
| 261 EXPECT_EQ(required_width_with_border, required_width + border.width()); | 261 EXPECT_EQ(required_width_with_border, required_width + border.width()); |
| 262 | 262 |
| 263 // GetHeightForWidth and borders. | 263 // GetHeightForWidth and borders. |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 384 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); | 384 EXPECT_EQ(extra.height() / 2 , text_bounds.y()); |
| 385 EXPECT_EQ(required_size.width(), text_bounds.width()); | 385 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 386 EXPECT_EQ(required_size.height(), text_bounds.height()); | 386 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 387 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, | 387 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_RIGHT, |
| 388 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | | 388 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 389 gfx::Canvas::TEXT_ALIGN_CENTER | | 389 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 390 gfx::Canvas::TEXT_ALIGN_RIGHT)); | 390 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 391 | 391 |
| 392 // Test single line drawing with a border. | 392 // Test single line drawing with a border. |
| 393 gfx::Insets border(39, 34, 8, 96); | 393 gfx::Insets border(39, 34, 8, 96); |
| 394 label.set_border(Border::CreateEmptyBorder(border.top(), | 394 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 395 border.left(), | 395 border.left(), |
| 396 border.bottom(), | 396 border.bottom(), |
| 397 border.right())); | 397 border.right())); |
| 398 | 398 |
| 399 gfx::Size required_size_with_border(label.GetPreferredSize()); | 399 gfx::Size required_size_with_border(label.GetPreferredSize()); |
| 400 EXPECT_EQ(required_size.width() + border.width(), | 400 EXPECT_EQ(required_size.width() + border.width(), |
| 401 required_size_with_border.width()); | 401 required_size_with_border.width()); |
| 402 EXPECT_EQ(required_size.height() + border.height(), | 402 EXPECT_EQ(required_size.height() + border.height(), |
| 403 required_size_with_border.height()); | 403 required_size_with_border.height()); |
| 404 label.SetBounds(0, | 404 label.SetBounds(0, |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 527 gfx::Canvas::TEXT_ALIGN_RIGHT | | 527 gfx::Canvas::TEXT_ALIGN_RIGHT | |
| 528 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; | 528 gfx::Canvas::FORCE_LTR_DIRECTIONALITY; |
| 529 #if defined(OS_WIN) | 529 #if defined(OS_WIN) |
| 530 EXPECT_EQ(expected_flags, flags); | 530 EXPECT_EQ(expected_flags, flags); |
| 531 #else | 531 #else |
| 532 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); | 532 EXPECT_EQ(expected_flags | gfx::Canvas::NO_ELLIPSIS, flags); |
| 533 #endif | 533 #endif |
| 534 | 534 |
| 535 // Test multiline drawing with a border. | 535 // Test multiline drawing with a border. |
| 536 gfx::Insets border(19, 92, 23, 2); | 536 gfx::Insets border(19, 92, 23, 2); |
| 537 label.set_border(Border::CreateEmptyBorder(border.top(), | 537 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 538 border.left(), | 538 border.left(), |
| 539 border.bottom(), | 539 border.bottom(), |
| 540 border.right())); | 540 border.right())); |
| 541 label.SizeToFit(0); | 541 label.SizeToFit(0); |
| 542 label.SetBounds(label.x(), | 542 label.SetBounds(label.x(), |
| 543 label.y(), | 543 label.y(), |
| 544 label.width() + extra.width(), | 544 label.width() + extra.width(), |
| 545 label.height() + extra.height()); | 545 label.height() + extra.height()); |
| 546 | 546 |
| 547 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 547 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 661 EXPECT_EQ(required_size.width(), text_bounds.width()); | 661 EXPECT_EQ(required_size.width(), text_bounds.width()); |
| 662 EXPECT_EQ(required_size.height(), text_bounds.height()); | 662 EXPECT_EQ(required_size.height(), text_bounds.height()); |
| 663 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, | 663 EXPECT_EQ(gfx::Canvas::TEXT_ALIGN_LEFT, |
| 664 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | | 664 flags & (gfx::Canvas::TEXT_ALIGN_LEFT | |
| 665 gfx::Canvas::TEXT_ALIGN_CENTER | | 665 gfx::Canvas::TEXT_ALIGN_CENTER | |
| 666 gfx::Canvas::TEXT_ALIGN_RIGHT)); | 666 gfx::Canvas::TEXT_ALIGN_RIGHT)); |
| 667 | 667 |
| 668 | 668 |
| 669 // Test single line drawing with a border. | 669 // Test single line drawing with a border. |
| 670 gfx::Insets border(39, 34, 8, 96); | 670 gfx::Insets border(39, 34, 8, 96); |
| 671 label.set_border(Border::CreateEmptyBorder(border.top(), | 671 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 672 border.left(), | 672 border.left(), |
| 673 border.bottom(), | 673 border.bottom(), |
| 674 border.right())); | 674 border.right())); |
| 675 | 675 |
| 676 gfx::Size required_size_with_border(label.GetPreferredSize()); | 676 gfx::Size required_size_with_border(label.GetPreferredSize()); |
| 677 EXPECT_EQ(required_size.width() + border.width(), | 677 EXPECT_EQ(required_size.width() + border.width(), |
| 678 required_size_with_border.width()); | 678 required_size_with_border.width()); |
| 679 EXPECT_EQ(required_size.height() + border.height(), | 679 EXPECT_EQ(required_size.height() + border.height(), |
| 680 required_size_with_border.height()); | 680 required_size_with_border.height()); |
| 681 label.SetBounds(0, | 681 label.SetBounds(0, |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 810 #else | 810 #else |
| 811 EXPECT_EQ( | 811 EXPECT_EQ( |
| 812 gfx::Canvas::MULTI_LINE | | 812 gfx::Canvas::MULTI_LINE | |
| 813 gfx::Canvas::TEXT_ALIGN_LEFT | | 813 gfx::Canvas::TEXT_ALIGN_LEFT | |
| 814 gfx::Canvas::NO_ELLIPSIS, | 814 gfx::Canvas::NO_ELLIPSIS, |
| 815 flags); | 815 flags); |
| 816 #endif | 816 #endif |
| 817 | 817 |
| 818 // Test multiline drawing with a border. | 818 // Test multiline drawing with a border. |
| 819 gfx::Insets border(19, 92, 23, 2); | 819 gfx::Insets border(19, 92, 23, 2); |
| 820 label.set_border(Border::CreateEmptyBorder(border.top(), | 820 label.SetBorder(Border::CreateEmptyBorder(border.top(), |
| 821 border.left(), | 821 border.left(), |
| 822 border.bottom(), | 822 border.bottom(), |
| 823 border.right())); | 823 border.right())); |
| 824 label.SizeToFit(0); | 824 label.SizeToFit(0); |
| 825 label.SetBounds(label.x(), | 825 label.SetBounds(label.x(), |
| 826 label.y(), | 826 label.y(), |
| 827 label.width() + extra.width(), | 827 label.width() + extra.width(), |
| 828 label.height() + extra.height()); | 828 label.height() + extra.height()); |
| 829 | 829 |
| 830 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); | 830 label.SetHorizontalAlignment(gfx::ALIGN_CENTER); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 925 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); | 925 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(2, 51))); |
| 926 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); | 926 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(-1, 20))); |
| 927 | 927 |
| 928 // GetTooltipHandlerForPoint works should work in child bounds. | 928 // GetTooltipHandlerForPoint works should work in child bounds. |
| 929 label.SetBounds(2, 2, 10, 10); | 929 label.SetBounds(2, 2, 10, 10); |
| 930 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); | 930 EXPECT_EQ(&label, label.GetTooltipHandlerForPoint(gfx::Point(1, 5))); |
| 931 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); | 931 EXPECT_FALSE(label.GetTooltipHandlerForPoint(gfx::Point(3, 11))); |
| 932 } | 932 } |
| 933 | 933 |
| 934 } // namespace views | 934 } // namespace views |
| OLD | NEW |