OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/styled_label.h" | 5 #include "ui/views/controls/styled_label.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <string> | 10 #include <string> |
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 gfx::Size label_preferred_size = label.GetPreferredSize(); | 193 gfx::Size label_preferred_size = label.GetPreferredSize(); |
194 int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); | 194 int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); |
195 EXPECT_EQ(label_preferred_size.height() * 2, | 195 EXPECT_EQ(label_preferred_size.height() * 2, |
196 pref_height - styled()->GetInsets().height()); | 196 pref_height - styled()->GetInsets().height()); |
197 | 197 |
198 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); | 198 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
199 styled()->Layout(); | 199 styled()->Layout(); |
200 ASSERT_EQ(2, styled()->child_count()); | 200 ASSERT_EQ(2, styled()->child_count()); |
201 // The label has no focus border while the link (and thus overall styled | 201 // The label has no focus border while the link (and thus overall styled |
202 // label) does, so the label should be inset by the width of the focus border. | 202 // label) does, so the label should be inset by the width of the focus border. |
203 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(0)->x()); | 203 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x()); |
204 EXPECT_EQ(0, styled()->child_at(1)->x()); | 204 EXPECT_EQ(0, styled()->child_at(1)->x()); |
205 } | 205 } |
206 | 206 |
207 TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) { | 207 TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) { |
208 const std::string text("This is a test block of text, "); | 208 const std::string text("This is a test block of text, "); |
209 const std::string unbreakable_text("and this should not be broken"); | 209 const std::string unbreakable_text("and this should not be broken"); |
210 InitStyledLabel(text + unbreakable_text); | 210 InitStyledLabel(text + unbreakable_text); |
211 StyledLabel::RangeStyleInfo style_info; | 211 StyledLabel::RangeStyleInfo style_info; |
212 style_info.disable_line_wrapping = true; | 212 style_info.disable_line_wrapping = true; |
213 styled()->AddStyleRange( | 213 styled()->AddStyleRange( |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 | 402 |
403 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); | 403 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
404 styled()->Layout(); | 404 styled()->Layout(); |
405 | 405 |
406 EXPECT_EQ(label_preferred_size.width(), styled()->width()); | 406 EXPECT_EQ(label_preferred_size.width(), styled()->width()); |
407 | 407 |
408 ASSERT_EQ(5, styled()->child_count()); | 408 ASSERT_EQ(5, styled()->child_count()); |
409 // The labels have no focus border while the link (and thus overall styled | 409 // The labels have no focus border while the link (and thus overall styled |
410 // label) does, so the labels should be inset by the width of the focus | 410 // label) does, so the labels should be inset by the width of the focus |
411 // border. | 411 // border. |
412 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(0)->x()); | 412 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x()); |
413 EXPECT_EQ(styled()->child_at(0)->bounds().right(), | 413 EXPECT_EQ(styled()->child_at(0)->bounds().right(), |
414 styled()->child_at(1)->x()); | 414 styled()->child_at(1)->x()); |
415 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(2)->x()); | 415 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(2)->x()); |
416 EXPECT_EQ(styled()->child_at(2)->bounds().right(), | 416 EXPECT_EQ(styled()->child_at(2)->bounds().right(), |
417 styled()->child_at(3)->x()); | 417 styled()->child_at(3)->x()); |
418 EXPECT_EQ(0, styled()->child_at(4)->x()); | 418 EXPECT_EQ(0, styled()->child_at(4)->x()); |
419 | 419 |
420 base::string16 tooltip; | 420 base::string16 tooltip; |
421 EXPECT_TRUE( | 421 EXPECT_TRUE( |
422 styled()->child_at(1)->GetTooltipText(gfx::Point(1, 1), &tooltip)); | 422 styled()->child_at(1)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
423 EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); | 423 EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); |
424 EXPECT_TRUE( | 424 EXPECT_TRUE( |
425 styled()->child_at(2)->GetTooltipText(gfx::Point(1, 1), &tooltip)); | 425 styled()->child_at(2)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
499 // all controls should be recreated | 499 // all controls should be recreated |
500 styled()->SetText(another_text); | 500 styled()->SetText(another_text); |
501 int updated_height = styled()->GetHeightForWidth(styled()->width()); | 501 int updated_height = styled()->GetHeightForWidth(styled()->width()); |
502 EXPECT_NE(updated_height, real_height); | 502 EXPECT_NE(updated_height, real_height); |
503 View* first_child_after_text_update = styled()->has_children() ? | 503 View* first_child_after_text_update = styled()->has_children() ? |
504 styled()->child_at(0) : nullptr; | 504 styled()->child_at(0) : nullptr; |
505 EXPECT_NE(first_child_after_text_update, first_child_after_layout); | 505 EXPECT_NE(first_child_after_text_update, first_child_after_layout); |
506 } | 506 } |
507 | 507 |
508 } // namespace views | 508 } // namespace views |
OLD | NEW |