| Index: ui/views/controls/label_unittest.cc
|
| diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc
|
| index 5f370f8ee4d72b751cdf24d8fd34d2c4afd27a46..4ab2c6da05bfe2776993fc50efc021406aa45fc1 100644
|
| --- a/ui/views/controls/label_unittest.cc
|
| +++ b/ui/views/controls/label_unittest.cc
|
| @@ -23,6 +23,7 @@
|
| #include "ui/gfx/switches.h"
|
| #include "ui/strings/grit/ui_strings.h"
|
| #include "ui/views/border.h"
|
| +#include "ui/views/controls/link.h"
|
| #include "ui/views/test/focus_manager_test.h"
|
| #include "ui/views/test/views_test_base.h"
|
| #include "ui/views/widget/widget.h"
|
| @@ -785,30 +786,57 @@ TEST_F(LabelTest, NoSchedulePaintInOnPaint) {
|
|
|
| TEST_F(LabelTest, FocusBounds) {
|
| label()->SetText(ASCIIToUTF16("Example"));
|
| - gfx::Size normal_size = label()->GetPreferredSize();
|
| + Link concrete_link(ASCIIToUTF16("Example"));
|
| + Label* link = &concrete_link; // Allow LabelTest to call methods as friend.
|
| + link->SetFocusBehavior(View::FocusBehavior::NEVER);
|
|
|
| + label()->SizeToPreferredSize();
|
| + link->SizeToPreferredSize();
|
| +
|
| + // A regular label never draws a focus ring, so it should exactly match the
|
| + // font height (assuming no glyphs came from fallback fonts).
|
| + EXPECT_EQ(label()->font_list().GetHeight(),
|
| + label()->GetFocusRingBounds().height());
|
| +
|
| + // The test starts by setting the link unfocusable, so it should also match.
|
| + EXPECT_EQ(link->font_list().GetHeight(), link->GetFocusRingBounds().height());
|
| + EXPECT_EQ(link->GetFocusRingBounds(), label()->GetFocusRingBounds());
|
| +
|
| + // Labels are not focusable unless they are links, so don't change size when
|
| + // the focus behavior changes.
|
| + gfx::Size normal_label_size = label()->GetPreferredSize();
|
| label()->SetFocusBehavior(View::FocusBehavior::ALWAYS);
|
| + EXPECT_EQ(normal_label_size, label()->GetPreferredSize());
|
| +
|
| + // But links get bigger in order to paint the focus rectangle.
|
| + gfx::Size normal_link_size = link->GetPreferredSize();
|
| + link->SetFocusBehavior(View::FocusBehavior::ALWAYS);
|
| + gfx::Size focusable_link_size = link->GetPreferredSize();
|
| + EXPECT_NE(normal_link_size, focusable_link_size);
|
| + EXPECT_GT(focusable_link_size.width(), normal_link_size.width());
|
| + EXPECT_GT(focusable_link_size.height(), normal_link_size.height());
|
| +
|
| + // Requesting focus doesn't change the preferred size since that would mess up
|
| + // layout.
|
| label()->RequestFocus();
|
| - gfx::Size focusable_size = label()->GetPreferredSize();
|
| - // Focusable label requires larger size to paint the focus rectangle.
|
| - EXPECT_GT(focusable_size.width(), normal_size.width());
|
| - EXPECT_GT(focusable_size.height(), normal_size.height());
|
| + EXPECT_EQ(focusable_link_size, link->GetPreferredSize());
|
|
|
| label()->SizeToPreferredSize();
|
| - gfx::Rect focus_bounds = label()->GetFocusBounds();
|
| + gfx::Rect focus_bounds = label()->GetFocusRingBounds();
|
| EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString());
|
|
|
| + gfx::Size focusable_size = normal_label_size;
|
| label()->SetBounds(
|
| 0, 0, focusable_size.width() * 2, focusable_size.height() * 2);
|
| label()->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| - focus_bounds = label()->GetFocusBounds();
|
| + focus_bounds = label()->GetFocusRingBounds();
|
| EXPECT_EQ(0, focus_bounds.x());
|
| EXPECT_LT(0, focus_bounds.y());
|
| EXPECT_GT(label()->bounds().bottom(), focus_bounds.bottom());
|
| EXPECT_EQ(focusable_size.ToString(), focus_bounds.size().ToString());
|
|
|
| label()->SetHorizontalAlignment(gfx::ALIGN_RIGHT);
|
| - focus_bounds = label()->GetFocusBounds();
|
| + focus_bounds = label()->GetFocusRingBounds();
|
| EXPECT_LT(0, focus_bounds.x());
|
| EXPECT_EQ(label()->bounds().right(), focus_bounds.right());
|
| EXPECT_LT(0, focus_bounds.y());
|
| @@ -818,7 +846,7 @@ TEST_F(LabelTest, FocusBounds) {
|
| label()->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| label()->SetElideBehavior(gfx::FADE_TAIL);
|
| label()->SetBounds(0, 0, focusable_size.width() / 2, focusable_size.height());
|
| - focus_bounds = label()->GetFocusBounds();
|
| + focus_bounds = label()->GetFocusRingBounds();
|
| EXPECT_EQ(0, focus_bounds.x());
|
| EXPECT_EQ(focusable_size.width() / 2, focus_bounds.width());
|
| }
|
| @@ -828,9 +856,13 @@ TEST_F(LabelTest, EmptyLabel) {
|
| label()->RequestFocus();
|
| label()->SizeToPreferredSize();
|
|
|
| - gfx::Rect focus_bounds = label()->GetFocusBounds();
|
| - EXPECT_FALSE(focus_bounds.IsEmpty());
|
| - EXPECT_LT(label()->font_list().GetHeight(), focus_bounds.height());
|
| + Link concrete_link((base::string16()));
|
| + Label* link = &concrete_link; // Allow LabelTest to call methods as friend.
|
| +
|
| + // With no text, neither links nor labels are focusable, and have no size in
|
| + // any dimension.
|
| + EXPECT_EQ(gfx::Rect(), label()->GetFocusRingBounds());
|
| + EXPECT_EQ(gfx::Rect(), link->GetFocusRingBounds());
|
| }
|
|
|
| TEST_F(LabelSelectionTest, Selectable) {
|
|
|