Clean-up: Replaces Font with FontList in TooltipManager.

This is a part of refactoring to replace all use of gfx::Font with gfx::FontList.  Also this replacement solves a possible vertical alignment issue of text rendering.

See "Background & Problem" section in the following doc why this refactoring is needed.
https://docs.google.com/a/chromium.org/document/d/1D_25fp9B8b9aZJORfAjDIFq61NWvUquZ5xmKH-VcC4k/edit#heading=h.olbd4u4vk3h6

NOTE:
a) Existing Font::GetStringWidth() is now obsolete and should be replaced by gfx::GetStringWidth() in ui/gfx/text_utils.h .
b) 'const' has internal linkage so it doesn't require anonymous namespace (in ui/views/widget/tooltip_manager.cc).

BUG=265485
TEST=Run unittests.

Review URL: https://chromiumcodereview.appspot.com/23483015

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@220509 0039d316-1c4b-4281-b951-d872f2087c98
parent dc29340a
...@@ -609,14 +609,14 @@ string16 BookmarkBarView::CreateToolTipForURLAndTitle( ...@@ -609,14 +609,14 @@ string16 BookmarkBarView::CreateToolTipForURLAndTitle(
int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(), int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(),
screen_loc.y(), screen_loc.y(),
context); context);
gfx::Font tt_font = views::TooltipManager::GetDefaultFont(); const gfx::FontList& tt_fonts = views::TooltipManager::GetDefaultFontList();
string16 result; string16 result;
// First the title. // First the title.
if (!title.empty()) { if (!title.empty()) {
string16 localized_title = title; string16 localized_title = title;
base::i18n::AdjustStringForLocaleDirection(&localized_title); base::i18n::AdjustStringForLocaleDirection(&localized_title);
result.append(ui::ElideText(localized_title, tt_font, max_width, result.append(ui::ElideText(localized_title, tt_fonts, max_width,
ui::ELIDE_AT_END)); ui::ELIDE_AT_END));
} }
...@@ -633,7 +633,7 @@ string16 BookmarkBarView::CreateToolTipForURLAndTitle( ...@@ -633,7 +633,7 @@ string16 BookmarkBarView::CreateToolTipForURLAndTitle(
// default. // default.
std::string languages = profile->GetPrefs()->GetString( std::string languages = profile->GetPrefs()->GetString(
prefs::kAcceptLanguages); prefs::kAcceptLanguages);
string16 elided_url(ui::ElideUrl(url, tt_font, max_width, languages)); string16 elided_url(ui::ElideUrl(url, tt_fonts, max_width, languages));
elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url); elided_url = base::i18n::GetDisplayStringInLTRDirectionality(elided_url);
result.append(elided_url); result.append(elided_url);
} }
......
...@@ -9,9 +9,7 @@ ...@@ -9,9 +9,7 @@
#include "base/strings/string_split.h" #include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "ui/base/text/text_elider.h" #include "ui/base/text/text_elider.h"
#include "ui/gfx/font.h" #include "ui/gfx/text_utils.h"
namespace {
// Maximum number of characters we allow in a tooltip. // Maximum number of characters we allow in a tooltip.
const size_t kMaxTooltipLength = 1024; const size_t kMaxTooltipLength = 1024;
...@@ -19,8 +17,6 @@ const size_t kMaxTooltipLength = 1024; ...@@ -19,8 +17,6 @@ const size_t kMaxTooltipLength = 1024;
// Maximum number of lines we allow in the tooltip. // Maximum number of lines we allow in the tooltip.
const size_t kMaxLines = 6; const size_t kMaxLines = 6;
} // namespace
namespace views { namespace views {
// static // static
...@@ -49,13 +45,14 @@ void TooltipManager::TrimTooltipToFit(string16* text, ...@@ -49,13 +45,14 @@ void TooltipManager::TrimTooltipToFit(string16* text,
*line_count = static_cast<int>(lines.size()); *line_count = static_cast<int>(lines.size());
// Format each line to fit. // Format each line to fit.
gfx::Font font = GetDefaultFont(); const gfx::FontList& font_list = GetDefaultFontList();
string16 result; string16 result;
for (std::vector<string16>::iterator i = lines.begin(); i != lines.end(); for (std::vector<string16>::iterator i = lines.begin(); i != lines.end();
++i) { ++i) {
string16 elided_text = string16 elided_text =
ui::ElideText(*i, font, available_width, ui::ELIDE_AT_END); ui::ElideText(*i, font_list, available_width, ui::ELIDE_AT_END);
*max_width = std::max(*max_width, font.GetStringWidth(elided_text)); *max_width = std::max(*max_width,
gfx::GetStringWidth(elided_text, font_list));
if (!result.empty()) if (!result.empty())
result.push_back('\n'); result.push_back('\n');
result.append(elided_text); result.append(elided_text);
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
#include "ui/views/views_export.h" #include "ui/views/views_export.h"
namespace gfx { namespace gfx {
class Font; class FontList;
} // namespace gfx } // namespace gfx
namespace views { namespace views {
...@@ -30,7 +30,7 @@ class VIEWS_EXPORT TooltipManager { ...@@ -30,7 +30,7 @@ class VIEWS_EXPORT TooltipManager {
static int GetTooltipHeight(); static int GetTooltipHeight();
// Returns the default font used by tooltips. // Returns the default font used by tooltips.
static gfx::Font GetDefaultFont(); static const gfx::FontList& GetDefaultFontList();
// Returns the maximum width of the tooltip. |x| and |y| give the location // Returns the maximum width of the tooltip. |x| and |y| give the location
// the tooltip is to be displayed on in screen coordinates. |context| is // the tooltip is to be displayed on in screen coordinates. |context| is
......
...@@ -8,7 +8,6 @@ ...@@ -8,7 +8,6 @@
#include "ui/aura/client/tooltip_client.h" #include "ui/aura/client/tooltip_client.h"
#include "ui/aura/root_window.h" #include "ui/aura/root_window.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
#include "ui/gfx/rect.h" #include "ui/gfx/rect.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
...@@ -23,8 +22,8 @@ int TooltipManager::GetTooltipHeight() { ...@@ -23,8 +22,8 @@ int TooltipManager::GetTooltipHeight() {
} }
// static // static
gfx::Font TooltipManager::GetDefaultFont() { const gfx::FontList& TooltipManager::GetDefaultFontList() {
return ui::ResourceBundle::GetSharedInstance().GetFont( return ui::ResourceBundle::GetSharedInstance().GetFontList(
ui::ResourceBundle::BaseFont); ui::ResourceBundle::BaseFont);
} }
......
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
#include "ui/base/win/dpi.h" #include "ui/base/win/dpi.h"
#include "ui/base/win/hwnd_util.h" #include "ui/base/win/hwnd_util.h"
#include "ui/base/win/scoped_set_map_mode.h" #include "ui/base/win/scoped_set_map_mode.h"
#include "ui/gfx/font.h" #include "ui/gfx/font_list.h"
#include "ui/gfx/screen.h" #include "ui/gfx/screen.h"
#include "ui/views/view.h" #include "ui/views/view.h"
#include "ui/views/widget/monitor_win.h" #include "ui/views/widget/monitor_win.h"
...@@ -52,11 +52,11 @@ static gfx::Font DetermineDefaultFont() { ...@@ -52,11 +52,11 @@ static gfx::Font DetermineDefaultFont() {
} }
// static // static
gfx::Font TooltipManager::GetDefaultFont() { const gfx::FontList& TooltipManager::GetDefaultFontList() {
static gfx::Font* font = NULL; static gfx::FontList* font_list = NULL;
if (!font) if (!font_list)
font = new gfx::Font(DetermineDefaultFont()); font_list = new gfx::FontList(DetermineDefaultFont());
return *font; return *font_list;
} }
// static // static
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment