| 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 gfx::Size label_preferred_size = label.GetPreferredSize(); | 243 gfx::Size label_preferred_size = label.GetPreferredSize(); |
| 244 int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); | 244 int pref_height = styled()->GetHeightForWidth(label_preferred_size.width()); |
| 245 EXPECT_EQ(label_preferred_size.height() * 2, | 245 EXPECT_EQ(label_preferred_size.height() * 2, |
| 246 pref_height - styled()->GetInsets().height()); | 246 pref_height - styled()->GetInsets().height()); |
| 247 | 247 |
| 248 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); | 248 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
| 249 styled()->Layout(); | 249 styled()->Layout(); |
| 250 ASSERT_EQ(2, styled()->child_count()); | 250 ASSERT_EQ(2, styled()->child_count()); |
| 251 // The label has no focus border while the link (and thus overall styled | 251 // The label has no focus border while the link (and thus overall styled |
| 252 // label) does, so the label should be inset by the width of the focus border. | 252 // label) does, so the label should be inset by the width of the focus border. |
| 253 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(0)->x()); | 253 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x()); |
| 254 EXPECT_EQ(0, styled()->child_at(1)->x()); | 254 EXPECT_EQ(0, styled()->child_at(1)->x()); |
| 255 } | 255 } |
| 256 | 256 |
| 257 TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) { | 257 TEST_F(StyledLabelTest, StyledRangeWithDisabledLineWrapping) { |
| 258 const std::string text("This is a test block of text, "); | 258 const std::string text("This is a test block of text, "); |
| 259 const std::string unbreakable_text("and this should not be broken"); | 259 const std::string unbreakable_text("and this should not be broken"); |
| 260 InitStyledLabel(text + unbreakable_text); | 260 InitStyledLabel(text + unbreakable_text); |
| 261 StyledLabel::RangeStyleInfo style_info; | 261 StyledLabel::RangeStyleInfo style_info; |
| 262 style_info.disable_line_wrapping = true; | 262 style_info.disable_line_wrapping = true; |
| 263 styled()->AddStyleRange( | 263 styled()->AddStyleRange( |
| (...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 459 | 459 |
| 460 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); | 460 styled()->SetBounds(0, 0, label_preferred_size.width(), pref_height); |
| 461 styled()->Layout(); | 461 styled()->Layout(); |
| 462 | 462 |
| 463 EXPECT_EQ(label_preferred_size.width(), styled()->width()); | 463 EXPECT_EQ(label_preferred_size.width(), styled()->width()); |
| 464 | 464 |
| 465 ASSERT_EQ(5, styled()->child_count()); | 465 ASSERT_EQ(5, styled()->child_count()); |
| 466 // The labels have no focus border while the link (and thus overall styled | 466 // The labels have no focus border while the link (and thus overall styled |
| 467 // label) does, so the labels should be inset by the width of the focus | 467 // label) does, so the labels should be inset by the width of the focus |
| 468 // border. | 468 // border. |
| 469 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(0)->x()); | 469 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(0)->x()); |
| 470 EXPECT_EQ(styled()->child_at(0)->bounds().right(), | 470 EXPECT_EQ(styled()->child_at(0)->bounds().right(), |
| 471 styled()->child_at(1)->x()); | 471 styled()->child_at(1)->x()); |
| 472 EXPECT_EQ(Label::kFocusBorderPadding, styled()->child_at(2)->x()); | 472 EXPECT_EQ(Link::kFocusBorderPadding, styled()->child_at(2)->x()); |
| 473 EXPECT_EQ(styled()->child_at(2)->bounds().right(), | 473 EXPECT_EQ(styled()->child_at(2)->bounds().right(), |
| 474 styled()->child_at(3)->x()); | 474 styled()->child_at(3)->x()); |
| 475 EXPECT_EQ(0, styled()->child_at(4)->x()); | 475 EXPECT_EQ(0, styled()->child_at(4)->x()); |
| 476 | 476 |
| 477 base::string16 tooltip; | 477 base::string16 tooltip; |
| 478 EXPECT_TRUE( | 478 EXPECT_TRUE( |
| 479 styled()->child_at(1)->GetTooltipText(gfx::Point(1, 1), &tooltip)); | 479 styled()->child_at(1)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
| 480 EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); | 480 EXPECT_EQ(ASCIIToUTF16("tooltip"), tooltip); |
| 481 EXPECT_TRUE( | 481 EXPECT_TRUE( |
| 482 styled()->child_at(2)->GetTooltipText(gfx::Point(1, 1), &tooltip)); | 482 styled()->child_at(2)->GetTooltipText(gfx::Point(1, 1), &tooltip)); |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 styled()->Layout(); | 573 styled()->Layout(); |
| 574 EXPECT_EQ( | 574 EXPECT_EQ( |
| 575 label_preferred_size.height() + 5 /*top border*/ + 6 /*bottom border*/, | 575 label_preferred_size.height() + 5 /*top border*/ + 6 /*bottom border*/, |
| 576 styled()->GetPreferredSize().height()); | 576 styled()->GetPreferredSize().height()); |
| 577 EXPECT_EQ( | 577 EXPECT_EQ( |
| 578 label_preferred_size.width() + 10 /*left border*/ + 20 /*right border*/, | 578 label_preferred_size.width() + 10 /*left border*/ + 20 /*right border*/, |
| 579 styled()->GetPreferredSize().width()); | 579 styled()->GetPreferredSize().width()); |
| 580 } | 580 } |
| 581 | 581 |
| 582 } // namespace views | 582 } // namespace views |
| OLD | NEW |