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

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

Issue 342833002: [Password Generation] Update Aura UI (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: More mac fixes Created 6 years, 6 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
« no previous file with comments | « ui/views/controls/styled_label.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/views/controls/styled_label.cc
diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc
index e7ee56c0b44de2b806803fd4da900308c5ade9d4..64c6b296a352496575c9cef5728bb95546052e4a 100644
--- a/ui/views/controls/styled_label.cc
+++ b/ui/views/controls/styled_label.cc
@@ -94,7 +94,8 @@ bool StyledLabel::StyleRange::operator<(
StyledLabel::StyledLabel(const base::string16& text,
StyledLabelListener* listener)
- : listener_(listener),
+ : line_height_(-1),
+ listener_(listener),
displayed_on_background_color_set_(false),
auto_color_readability_enabled_(true) {
base::TrimWhitespace(text, base::TRIM_TRAILING, &text_);
@@ -133,6 +134,11 @@ void StyledLabel::SetDefaultStyle(const RangeStyleInfo& style_info) {
PreferredSizeChanged();
}
+void StyledLabel::SetLineHeight(int line_height) {
+ line_height_ = line_height;
+ PreferredSizeChanged();
+}
+
void StyledLabel::SetDisplayedOnBackgroundColor(SkColor color) {
displayed_on_background_color_ = color;
displayed_on_background_color_set_ = true;
@@ -193,7 +199,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
if (width <= 0 || text_.empty())
return gfx::Size();
- const int line_height = CalculateLineHeight(font_list_);
+ const int line_height = GetLineHeight();
// The index of the line we're on.
int line = 0;
// The x position (in pixels) of the line we're on, relative to content
@@ -295,11 +301,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
gfx::Insets focus_border_insets(label->GetInsets());
focus_border_insets += -label->View::GetInsets();
const gfx::Size view_size = label->GetPreferredSize();
- DCHECK_EQ(line_height, view_size.height() - focus_border_insets.height());
if (!dry_run) {
label->SetBoundsRect(gfx::Rect(
gfx::Point(GetInsets().left() + x - focus_border_insets.left(),
- GetInsets().top() + line * line_height -
+ GetInsets().top() + GetOffsetForLine(line) -
focus_border_insets.top()),
view_size));
AddChildView(label.release());
@@ -309,7 +314,31 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
remaining_string = remaining_string.substr(chunk.size());
}
- return gfx::Size(width, (line + 1) * line_height + GetInsets().height());
+ return gfx::Size(
+ width,
+ (line + 1) * line_height + GetInsets().height());
+}
+
+int StyledLabel::GetLineHeight() {
sky 2014/06/25 21:53:48 nit: const
Garrett Casto 2014/06/25 22:06:43 Done.
+ if (line_height_ >= 0)
+ return line_height_;
+ return CalculateLineHeight(font_list_);
+}
+
+int StyledLabel::GetOffsetForLine(int line) {
sky 2014/06/25 21:53:48 nit: const
Garrett Casto 2014/06/25 22:06:43 Done.
+ int default_line_height = CalculateLineHeight(font_list_);
+
+ // If no user override, return default.
+ if (line_height_ < 0)
+ return default_line_height * line;
+
+ // If line height is less than default, no centering needed.
+ if (line_height_ < default_line_height)
+ return line_height_ * line;
+
+ // Center text in the space available.
sky 2014/06/25 21:53:48 Why do you need this or the if on 336. I guess mor
Garrett Casto 2014/06/25 22:06:43 I don't have a use case for it, but estade@ though
+ int interline_offset = (line_height_ - default_line_height) / 2;
+ return line_height_ * line + interline_offset;
}
} // namespace views
« no previous file with comments | « ui/views/controls/styled_label.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698