Index: ui/views/controls/styled_label.cc |
diff --git a/ui/views/controls/styled_label.cc b/ui/views/controls/styled_label.cc |
index f46c93c046f5b9de5d231fcad4c2ad1fceddc17f..38adb353a9728f183b8006b1a41e24756024abe1 100644 |
--- a/ui/views/controls/styled_label.cc |
+++ b/ui/views/controls/styled_label.cc |
@@ -307,7 +307,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
base::string16 chunk = substrings[0]; |
- std::unique_ptr<Label> label; |
+ std::unique_ptr<Label> label_ptr; |
if (position >= range.start()) { |
const RangeStyleInfo& style_info = current_range->style_info; |
@@ -323,10 +323,10 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
if (chunk.size() > range.end() - position) |
chunk = chunk.substr(0, range.end() - position); |
- label = CreateLabelRange(chunk, font_list_, style_info, this); |
+ label_ptr = CreateLabelRange(chunk, font_list_, style_info, this); |
if (style_info.is_link && !dry_run) |
- link_targets_[label.get()] = range; |
+ link_targets_[label_ptr.get()] = range; |
if (position + chunk.size() >= range.end()) |
++current_range; |
@@ -334,8 +334,16 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
// This chunk is normal text. |
if (position + chunk.size() > range.start()) |
chunk = chunk.substr(0, range.start() - position); |
- label = CreateLabelRange(chunk, font_list_, default_style_info_, this); |
+ label_ptr = |
+ CreateLabelRange(chunk, font_list_, default_style_info_, this); |
} |
+ Label* label = label_ptr.get(); |
+ |
+ // Since Label::GetInsets() depends on IsFocusable(), add |label| to the |
+ // view hierarchy first, to ensure Label::GetInsets returns the correct |
+ // value. |
+ if (!dry_run) |
+ AddChildView(label_ptr.release()); |
if (displayed_on_background_color_set_) |
label->SetBackgroundColor(displayed_on_background_color_); |
@@ -352,7 +360,6 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) { |
GetInsets().top() + line * line_height - |
focus_border_insets.top()), |
view_size)); |
- AddChildView(label.release()); |
} |
x += view_size.width() - focus_border_insets.width(); |
used_width = std::max(used_width, x); |