diff options
author | yukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 17:01:50 +0000 |
---|---|---|
committer | yukishiino@chromium.org <yukishiino@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-08-01 17:01:50 +0000 |
commit | 7682076160467ecef5f3e788006036f834df5b7d (patch) | |
tree | 30511a8e648f475ff1e6258b735872004d84c91b /ui/gfx | |
parent | 2a684221ee7fe5a83b0c51e87424ad9f3828b2bc (diff) | |
download | chromium_src-7682076160467ecef5f3e788006036f834df5b7d.zip chromium_src-7682076160467ecef5f3e788006036f834df5b7d.tar.gz chromium_src-7682076160467ecef5f3e788006036f834df5b7d.tar.bz2 |
Supports FontList in Textfield.
The current interface of Textfield does not support FontList while RenderText supports FontList. This CL supports FontList in Textfield.
The direct cause of crbug.com/263169 was that RenderText always uses the IDS_UI_FONT_FAMILY_CROS font set ignoring what font is specified for Textfield on ChromeOS. (See https://code.google.com/p/chromium/codesearch#chromium/src/ui/views/controls/textfield/native_textfield_views.cc&q=IDS_UI_FONT_FAMILY_CROS&sq=package:chromium&type=cs&l=88 )
The Omnibox font size is carefully calculated, but the font is ignored right now.
This CL changes the following:
- Supports FontList in Textfield so Omnibox layer can specify the font set, such as IDS_UI_FONT_FAMILY_CROS, for the underlying Textfield.
- Makes NativeTextfieldViews follow the specified font set via Textfield on ChromeOS.
BUG=263169,263196
TEST=Test manually.
Review URL: https://chromiumcodereview.appspot.com/19666006
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@215055 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ui/gfx')
-rw-r--r-- | ui/gfx/font_list.cc | 16 | ||||
-rw-r--r-- | ui/gfx/font_list.h | 6 | ||||
-rw-r--r-- | ui/gfx/render_text.cc | 11 | ||||
-rw-r--r-- | ui/gfx/render_text.h | 2 | ||||
-rw-r--r-- | ui/gfx/render_text_linux.cc | 3 | ||||
-rw-r--r-- | ui/gfx/render_text_mac.cc | 2 | ||||
-rw-r--r-- | ui/gfx/render_text_unittest.cc | 6 | ||||
-rw-r--r-- | ui/gfx/render_text_win.cc | 2 |
8 files changed, 35 insertions, 13 deletions
diff --git a/ui/gfx/font_list.cc b/ui/gfx/font_list.cc index 3c1b014..cb6cc97 100644 --- a/ui/gfx/font_list.cc +++ b/ui/gfx/font_list.cc @@ -208,6 +208,18 @@ const std::string& FontList::GetFontDescriptionString() const { return font_description_string_; } +int FontList::GetFontSize() const { + if (!fonts_.empty()) + return fonts_[0].GetFontSize(); + + std::vector<std::string> font_names; + int font_style; + int font_size; + ParseFontDescriptionString(font_description_string_, &font_names, + &font_style, &font_size); + return font_size; +} + const std::vector<Font>& FontList::GetFonts() const { if (fonts_.empty()) { DCHECK(!font_description_string_.empty()); @@ -230,4 +242,8 @@ const std::vector<Font>& FontList::GetFonts() const { return fonts_; } +const Font& FontList::GetPrimaryFont() const { + return GetFonts()[0]; +} + } // namespace gfx diff --git a/ui/gfx/font_list.h b/ui/gfx/font_list.h index d8f5e72..8c1d0f3 100644 --- a/ui/gfx/font_list.h +++ b/ui/gfx/font_list.h @@ -73,9 +73,15 @@ class UI_EXPORT FontList { // for the description. const std::string& GetFontDescriptionString() const; + // Returns the font size in pixels. + int GetFontSize() const; + // Returns the Font vector. const std::vector<Font>& GetFonts() const; + // Returns the first font in the list. + const Font& GetPrimaryFont() const; + private: // A vector of Font. If FontList is constructed with font description string, // |fonts_| is not initialized during construction. Instead, it is computed diff --git a/ui/gfx/render_text.cc b/ui/gfx/render_text.cc index 91f9f42..14bdcfa 100644 --- a/ui/gfx/render_text.cc +++ b/ui/gfx/render_text.cc @@ -360,15 +360,15 @@ void RenderText::SetFontSize(int size) { SetFontList(font_list_.DeriveFontListWithSize(size)); } +const Font& RenderText::GetPrimaryFont() const { + return font_list_.GetPrimaryFont(); +} + void RenderText::SetCursorEnabled(bool cursor_enabled) { cursor_enabled_ = cursor_enabled; cached_bounds_and_offset_valid_ = false; } -const Font& RenderText::GetFont() const { - return font_list_.GetFonts()[0]; -} - void RenderText::ToggleInsertMode() { insert_mode_ = !insert_mode_; cached_bounds_and_offset_valid_ = false; @@ -873,7 +873,8 @@ void RenderText::ApplyFadeEffects(internal::SkiaTextRenderer* renderer) { if (text_width <= display_width) return; - int gradient_width = CalculateFadeGradientWidth(GetFont(), display_width); + int gradient_width = CalculateFadeGradientWidth(GetPrimaryFont(), + display_width); if (gradient_width == 0) return; diff --git a/ui/gfx/render_text.h b/ui/gfx/render_text.h index c4d48fd..8a25d13 100644 --- a/ui/gfx/render_text.h +++ b/ui/gfx/render_text.h @@ -145,7 +145,7 @@ class UI_EXPORT RenderText { void SetFontSize(int size); // Get the first font in |font_list_|. - const Font& GetFont() const; + const Font& GetPrimaryFont() const; bool cursor_enabled() const { return cursor_enabled_; } void SetCursorEnabled(bool cursor_enabled); diff --git a/ui/gfx/render_text_linux.cc b/ui/gfx/render_text_linux.cc index 0bf2686..0178cf8 100644 --- a/ui/gfx/render_text_linux.cc +++ b/ui/gfx/render_text_linux.cc @@ -235,8 +235,7 @@ std::vector<Rect> RenderTextLinux::GetSubstringBounds(const ui::Range& range) { &ranges, &n_ranges); - int height = 0; - pango_layout_get_pixel_size(layout_, NULL, &height); + const int height = GetStringSize().height(); std::vector<Rect> bounds; for (int i = 0; i < n_ranges; ++i) { diff --git a/ui/gfx/render_text_mac.cc b/ui/gfx/render_text_mac.cc index cfc7a51..c56c626 100644 --- a/ui/gfx/render_text_mac.cc +++ b/ui/gfx/render_text_mac.cc @@ -107,7 +107,7 @@ void RenderTextMac::EnsureLayout() { runs_.clear(); runs_valid_ = false; - const Font& font = GetFont(); + const Font& font = GetPrimaryFont(); base::ScopedCFTypeRef<CFStringRef> font_name_cf_string( base::SysUTF8ToCFStringRef(font.GetFontName())); base::ScopedCFTypeRef<CTFontRef> ct_font( diff --git a/ui/gfx/render_text_unittest.cc b/ui/gfx/render_text_unittest.cc index 7b9f9b6..400c27b 100644 --- a/ui/gfx/render_text_unittest.cc +++ b/ui/gfx/render_text_unittest.cc @@ -1198,8 +1198,8 @@ TEST_F(RenderTextTest, StringSizeRespectsFontListMetrics) { TEST_F(RenderTextTest, SetFont) { scoped_ptr<RenderText> render_text(RenderText::CreateInstance()); render_text->SetFont(Font("Arial", 12)); - EXPECT_EQ("Arial", render_text->GetFont().GetFontName()); - EXPECT_EQ(12, render_text->GetFont().GetFontSize()); + EXPECT_EQ("Arial", render_text->GetPrimaryFont().GetFontName()); + EXPECT_EQ(12, render_text->GetPrimaryFont().GetFontSize()); } TEST_F(RenderTextTest, SetFontList) { @@ -1209,7 +1209,7 @@ TEST_F(RenderTextTest, SetFontList) { ASSERT_EQ(2U, fonts.size()); EXPECT_EQ("Arial", fonts[0].GetFontName()); EXPECT_EQ("Symbol", fonts[1].GetFontName()); - EXPECT_EQ(13, render_text->GetFont().GetFontSize()); + EXPECT_EQ(13, render_text->GetPrimaryFont().GetFontSize()); } TEST_F(RenderTextTest, StringSizeBoldWidth) { diff --git a/ui/gfx/render_text_win.cc b/ui/gfx/render_text_win.cc index e38d263..ac018de 100644 --- a/ui/gfx/render_text_win.cc +++ b/ui/gfx/render_text_win.cc @@ -578,7 +578,7 @@ void RenderTextWin::ItemizeLogicalText() { for (size_t run_break = 0; run_break < layout_text_length;) { internal::TextRun* run = new internal::TextRun(); run->range.set_start(run_break); - run->font = GetFont(); + run->font = GetPrimaryFont(); run->font_style = (style.style(BOLD) ? Font::BOLD : 0) | (style.style(ITALIC) ? Font::ITALIC : 0); DeriveFontIfNecessary(run->font.GetFontSize(), run->font.GetHeight(), |