Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / ui / views / controls / styled_label.cc
index 93fb5ae..d707b6f 100644 (file)
@@ -23,13 +23,15 @@ namespace {
 
 // Calculates the height of a line of text. Currently returns the height of
 // a label.
-int CalculateLineHeight() {
+int CalculateLineHeight(const gfx::FontList& font_list) {
   Label label;
+  label.SetFontList(font_list);
   return label.GetPreferredSize().height();
 }
 
 scoped_ptr<Label> CreateLabelRange(
     const base::string16& text,
+    const gfx::FontList& font_list,
     const StyledLabel::RangeStyleInfo& style_info,
     views::LinkListener* link_listener) {
   scoped_ptr<Label> result;
@@ -44,13 +46,13 @@ scoped_ptr<Label> CreateLabelRange(
   }
 
   result->SetEnabledColor(style_info.color);
+  result->SetFontList(font_list);
 
   if (!style_info.tooltip.empty())
     result->SetTooltipText(style_info.tooltip);
   if (style_info.font_style != gfx::Font::NORMAL) {
     result->SetFontList(
-        result->font_list().DeriveFontListWithSizeDeltaAndStyle(
-            0, style_info.font_style));
+        result->font_list().DeriveWithStyle(style_info.font_style));
   }
 
   return result.Pass();
@@ -107,6 +109,11 @@ void StyledLabel::SetText(const base::string16& text) {
   PreferredSizeChanged();
 }
 
+void StyledLabel::SetBaseFontList(const gfx::FontList& font_list) {
+  font_list_ = font_list;
+  PreferredSizeChanged();
+}
+
 void StyledLabel::AddStyleRange(const gfx::Range& range,
                                 const RangeStyleInfo& style_info) {
   DCHECK(!range.is_reversed());
@@ -180,7 +187,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
   if (width <= 0 || text_.empty())
     return gfx::Size();
 
-  const int line_height = CalculateLineHeight();
+  const int line_height = CalculateLineHeight(font_list_);
   // 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
@@ -206,13 +213,13 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
 
     const gfx::Rect chunk_bounds(x, 0, width - x, 2 * line_height);
     std::vector<base::string16> substrings;
-    gfx::FontList text_font_list;
+    gfx::FontList text_font_list = font_list_;
     // If the start of the remaining text is inside a styled range, the font
     // style may differ from the base font. The font specified by the range
     // should be used when eliding text.
     if (position >= range.start()) {
-      text_font_list = text_font_list.DeriveFontListWithSizeDeltaAndStyle(
-          0, current_range->style_info.font_style);
+      text_font_list = text_font_list.DeriveWithStyle(
+          current_range->style_info.font_style);
     }
     gfx::ElideRectangleText(remaining_string,
                             text_font_list,
@@ -256,7 +263,7 @@ gfx::Size StyledLabel::CalculateAndDoLayout(int width, bool dry_run) {
 
       chunk = chunk.substr(0, std::min(chunk.size(), range.end() - position));
 
-      label = CreateLabelRange(chunk, style_info, this);
+      label = CreateLabelRange(chunk, font_list_, style_info, this);
 
       if (style_info.is_link && !dry_run)
         link_targets_[label.get()] = range;
@@ -267,7 +274,7 @@ 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, default_style_info_, this);
+      label = CreateLabelRange(chunk, font_list_, default_style_info_, this);
     }
 
     if (displayed_on_background_color_set_)