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(
int max_width = views::TooltipManager::GetMaxWidth(screen_loc.x(),
screen_loc.y(),
context);
gfx::Font tt_font = views::TooltipManager::GetDefaultFont();
const gfx::FontList& tt_fonts = views::TooltipManager::GetDefaultFontList();
string16 result;
// First the title.
if (!title.empty()) {
string16 localized_title = 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));
}
......@@ -633,7 +633,7 @@ string16 BookmarkBarView::CreateToolTipForURLAndTitle(
// default.
std::string languages = profile->GetPrefs()->GetString(
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);
result.append(elided_url);
}
......
......@@ -9,9 +9,7 @@
#include "base/strings/string_split.h"
#include "base/strings/utf_string_conversions.h"
#include "ui/base/text/text_elider.h"
#include "ui/gfx/font.h"
namespace {
#include "ui/gfx/text_utils.h"
// Maximum number of characters we allow in a tooltip.
const size_t kMaxTooltipLength = 1024;
......@@ -19,8 +17,6 @@ const size_t kMaxTooltipLength = 1024;
// Maximum number of lines we allow in the tooltip.
const size_t kMaxLines = 6;
} // namespace
namespace views {
// static
......@@ -49,13 +45,14 @@ void TooltipManager::TrimTooltipToFit(string16* text,
*line_count = static_cast<int>(lines.size());
// Format each line to fit.
gfx::Font font = GetDefaultFont();
const gfx::FontList& font_list = GetDefaultFontList();
string16 result;
for (std::vector<string16>::iterator i = lines.begin(); i != lines.end();
++i) {
string16 elided_text =
ui::ElideText(*i, font, available_width, ui::ELIDE_AT_END);
*max_width = std::max(*max_width, font.GetStringWidth(elided_text));
ui::ElideText(*i, font_list, available_width, ui::ELIDE_AT_END);
*max_width = std::max(*max_width,
gfx::GetStringWidth(elided_text, font_list));
if (!result.empty())
result.push_back('\n');
result.append(elided_text);
......
......@@ -13,7 +13,7 @@
#include "ui/views/views_export.h"
namespace gfx {
class Font;
class FontList;
} // namespace gfx
namespace views {
......@@ -30,7 +30,7 @@ class VIEWS_EXPORT TooltipManager {
static int GetTooltipHeight();
// 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
// the tooltip is to be displayed on in screen coordinates. |context| is
......
......@@ -8,7 +8,6 @@
#include "ui/aura/client/tooltip_client.h"
#include "ui/aura/root_window.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font.h"
#include "ui/gfx/rect.h"
#include "ui/gfx/screen.h"
#include "ui/views/widget/widget.h"
......@@ -23,8 +22,8 @@ int TooltipManager::GetTooltipHeight() {
}
// static
gfx::Font TooltipManager::GetDefaultFont() {
return ui::ResourceBundle::GetSharedInstance().GetFont(
const gfx::FontList& TooltipManager::GetDefaultFontList() {
return ui::ResourceBundle::GetSharedInstance().GetFontList(
ui::ResourceBundle::BaseFont);
}
......
......@@ -19,7 +19,7 @@
#include "ui/base/win/dpi.h"
#include "ui/base/win/hwnd_util.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/views/view.h"
#include "ui/views/widget/monitor_win.h"
......@@ -52,11 +52,11 @@ static gfx::Font DetermineDefaultFont() {
}
// static
gfx::Font TooltipManager::GetDefaultFont() {
static gfx::Font* font = NULL;
if (!font)
font = new gfx::Font(DetermineDefaultFont());
return *font;
const gfx::FontList& TooltipManager::GetDefaultFontList() {
static gfx::FontList* font_list = NULL;
if (!font_list)
font_list = new gfx::FontList(DetermineDefaultFont());
return *font_list;
}
// 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