| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 369 Label label(base::ASCIIToUTF16("Example")); | 369 Label label(base::ASCIIToUTF16("Example")); |
| 370 gfx::Size preferred_size = label.GetPreferredSize(); | 370 gfx::Size preferred_size = label.GetPreferredSize(); |
| 371 | 371 |
| 372 label.SetMultiLine(true); | 372 label.SetMultiLine(true); |
| 373 label.SetAllowCharacterBreak(true); | 373 label.SetAllowCharacterBreak(true); |
| 374 EXPECT_EQ(preferred_size, label.GetPreferredSize()); | 374 EXPECT_EQ(preferred_size, label.GetPreferredSize()); |
| 375 } | 375 } |
| 376 | 376 |
| 377 TEST_F(LabelTest, MultiLineSizing) { | 377 TEST_F(LabelTest, MultiLineSizing) { |
| 378 Label label; | 378 Label label; |
| 379 label.SetFocusable(false); | 379 label.SetFocusBehavior(views::View::FocusBehavior::NEVER); |
| 380 label.SetText( | 380 label.SetText( |
| 381 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); | 381 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!")); |
| 382 label.SetMultiLine(true); | 382 label.SetMultiLine(true); |
| 383 | 383 |
| 384 // GetPreferredSize | 384 // GetPreferredSize |
| 385 gfx::Size required_size = label.GetPreferredSize(); | 385 gfx::Size required_size = label.GetPreferredSize(); |
| 386 EXPECT_GT(required_size.height(), kMinTextDimension); | 386 EXPECT_GT(required_size.height(), kMinTextDimension); |
| 387 EXPECT_GT(required_size.width(), kMinTextDimension); | 387 EXPECT_GT(required_size.width(), kMinTextDimension); |
| 388 | 388 |
| 389 // SizeToFit with unlimited width. | 389 // SizeToFit with unlimited width. |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 454 EXPECT_EQ(required_size_with_border.width(), | 454 EXPECT_EQ(required_size_with_border.width(), |
| 455 required_size.width() + border.width()); | 455 required_size.width() + border.width()); |
| 456 } | 456 } |
| 457 | 457 |
| 458 // Verifies if the combination of text eliding and multiline doesn't cause | 458 // Verifies if the combination of text eliding and multiline doesn't cause |
| 459 // any side effects of size / layout calculation. | 459 // any side effects of size / layout calculation. |
| 460 TEST_F(LabelTest, MultiLineSizingWithElide) { | 460 TEST_F(LabelTest, MultiLineSizingWithElide) { |
| 461 const base::string16 text = | 461 const base::string16 text = |
| 462 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"); | 462 ASCIIToUTF16("A random string\nwith multiple lines\nand returns!"); |
| 463 Label label; | 463 Label label; |
| 464 label.SetFocusable(false); | 464 label.SetFocusBehavior(views::View::FocusBehavior::NEVER); |
| 465 label.SetText(text); | 465 label.SetText(text); |
| 466 label.SetMultiLine(true); | 466 label.SetMultiLine(true); |
| 467 | 467 |
| 468 gfx::Size required_size = label.GetPreferredSize(); | 468 gfx::Size required_size = label.GetPreferredSize(); |
| 469 EXPECT_GT(required_size.height(), kMinTextDimension); | 469 EXPECT_GT(required_size.height(), kMinTextDimension); |
| 470 EXPECT_GT(required_size.width(), kMinTextDimension); | 470 EXPECT_GT(required_size.width(), kMinTextDimension); |
| 471 label.SetBoundsRect(gfx::Rect(required_size)); | 471 label.SetBoundsRect(gfx::Rect(required_size)); |
| 472 | 472 |
| 473 label.SetElideBehavior(gfx::ELIDE_TAIL); | 473 label.SetElideBehavior(gfx::ELIDE_TAIL); |
| 474 EXPECT_EQ(required_size.ToString(), label.GetPreferredSize().ToString()); | 474 EXPECT_EQ(required_size.ToString(), label.GetPreferredSize().ToString()); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 605 | 605 |
| 606 // There's only one 'line', RenderText itself supports multiple lines. | 606 // There's only one 'line', RenderText itself supports multiple lines. |
| 607 EXPECT_EQ(1u, label.lines_.size()); | 607 EXPECT_EQ(1u, label.lines_.size()); |
| 608 } | 608 } |
| 609 #endif | 609 #endif |
| 610 | 610 |
| 611 TEST_F(LabelFocusTest, FocusBounds) { | 611 TEST_F(LabelFocusTest, FocusBounds) { |
| 612 label()->SetText(ASCIIToUTF16("Example")); | 612 label()->SetText(ASCIIToUTF16("Example")); |
| 613 gfx::Size normal_size = label()->GetPreferredSize(); | 613 gfx::Size normal_size = label()->GetPreferredSize(); |
| 614 | 614 |
| 615 label()->SetFocusable(true); | 615 label()->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 616 label()->RequestFocus(); | 616 label()->RequestFocus(); |
| 617 gfx::Size focusable_size = label()->GetPreferredSize(); | 617 gfx::Size focusable_size = label()->GetPreferredSize(); |
| 618 // Focusable label requires larger size to paint the focus rectangle. | 618 // Focusable label requires larger size to paint the focus rectangle. |
| 619 EXPECT_GT(focusable_size.width(), normal_size.width()); | 619 EXPECT_GT(focusable_size.width(), normal_size.width()); |
| 620 EXPECT_GT(focusable_size.height(), normal_size.height()); | 620 EXPECT_GT(focusable_size.height(), normal_size.height()); |
| 621 | 621 |
| 622 label()->SizeToPreferredSize(); | 622 label()->SizeToPreferredSize(); |
| 623 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 623 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 624 EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString()); | 624 EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString()); |
| 625 | 625 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 642 | 642 |
| 643 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 643 label()->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 644 label()->SetElideBehavior(gfx::FADE_TAIL); | 644 label()->SetElideBehavior(gfx::FADE_TAIL); |
| 645 label()->SetBounds(0, 0, focusable_size.width() / 2, focusable_size.height()); | 645 label()->SetBounds(0, 0, focusable_size.width() / 2, focusable_size.height()); |
| 646 focus_bounds = label()->GetFocusBounds(); | 646 focus_bounds = label()->GetFocusBounds(); |
| 647 EXPECT_EQ(0, focus_bounds.x()); | 647 EXPECT_EQ(0, focus_bounds.x()); |
| 648 EXPECT_EQ(focusable_size.width() / 2, focus_bounds.width()); | 648 EXPECT_EQ(focusable_size.width() / 2, focus_bounds.width()); |
| 649 } | 649 } |
| 650 | 650 |
| 651 TEST_F(LabelFocusTest, EmptyLabel) { | 651 TEST_F(LabelFocusTest, EmptyLabel) { |
| 652 label()->SetFocusable(true); | 652 label()->SetFocusBehavior(views::View::FocusBehavior::ALWAYS); |
| 653 label()->RequestFocus(); | 653 label()->RequestFocus(); |
| 654 label()->SizeToPreferredSize(); | 654 label()->SizeToPreferredSize(); |
| 655 | 655 |
| 656 gfx::Rect focus_bounds = label()->GetFocusBounds(); | 656 gfx::Rect focus_bounds = label()->GetFocusBounds(); |
| 657 EXPECT_FALSE(focus_bounds.IsEmpty()); | 657 EXPECT_FALSE(focus_bounds.IsEmpty()); |
| 658 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); | 658 EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height()); |
| 659 } | 659 } |
| 660 | 660 |
| 661 } // namespace views | 661 } // namespace views |
| OLD | NEW |