Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(565)

Unified Diff: ui/views/controls/label_unittest.cc

Issue 1018463004: Fix focus rectangle for label. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« ui/views/controls/label.cc ('K') | « ui/views/controls/label.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/label_unittest.cc
diff --git a/ui/views/controls/label_unittest.cc b/ui/views/controls/label_unittest.cc
index 636740953545967e55470427d9dd28710c0e7936..294cf6d1ab96f4ee67983212d55599441eb36c61 100644
--- a/ui/views/controls/label_unittest.cc
+++ b/ui/views/controls/label_unittest.cc
@@ -11,6 +11,7 @@
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/canvas.h"
#include "ui/views/border.h"
+#include "ui/views/test/focus_manager_test.h"
#include "ui/views/test/views_test_base.h"
#include "ui/views/widget/widget.h"
@@ -20,6 +21,24 @@ namespace views {
typedef ViewsTestBase LabelTest;
+class LabelFocusTest : public FocusManagerTest {
+ public:
+ LabelFocusTest() {}
+ ~LabelFocusTest() override {}
+
+ protected:
+ views::Label* label() { return label_; }
+
+ private:
+ // FocusManagerTest:
+ void InitContentView() override {
+ label_ = new views::Label();
+ GetContentsView()->AddChildView(label_);
+ }
+
+ views::Label* label_;
+};
+
// All text sizing measurements (width and height) should be greater than this.
const int kMinTextDimension = 4;
@@ -548,4 +567,38 @@ TEST_F(LabelTest, MultilineSupportedRenderText) {
}
#endif
+TEST_F(LabelFocusTest, FocusBounds) {
+ label()->SetText(ASCIIToUTF16("Example"));
+ gfx::Size normal_size = label()->GetPreferredSize();
+
+ label()->SetFocusable(true);
+ 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());
+
+ label()->SizeToPreferredSize();
+ gfx::Canvas canvas;
+ gfx::Rect focus_bounds = label()->PaintText(&canvas);
+ EXPECT_EQ(label()->GetLocalBounds().ToString(), focus_bounds.ToString());
+
+ label()->SetBounds(
+ 0, 0, focusable_size.width() * 2, focusable_size.height() * 2);
+ label()->SetHorizontalAlignment(gfx::ALIGN_LEFT);
+ focus_bounds = label()->PaintText(&canvas);
+ 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()->PaintText(&canvas);
+ EXPECT_LT(0, focus_bounds.x());
+ EXPECT_EQ(label()->bounds().right(), focus_bounds.right());
+ EXPECT_LT(0, focus_bounds.y());
+ EXPECT_GT(label()->bounds().bottom(), focus_bounds.bottom());
+ EXPECT_EQ(focusable_size.ToString(), focus_bounds.size().ToString());
+}
+
} // namespace views
« ui/views/controls/label.cc ('K') | « ui/views/controls/label.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698