diff options
author | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 19:16:10 +0000 |
---|---|---|
committer | jungshik@google.com <jungshik@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-04-15 19:16:10 +0000 |
commit | 3bd29d38ab1b03648ba9d3682ddc1d23c5cadad5 (patch) | |
tree | 20e24e86fa15207175dbcd1c0da23b31d980bfb2 /chrome/views | |
parent | 658b4fe27cae13bd99c0d8cb910d3d4ee16fea7c (diff) | |
download | chromium_src-3bd29d38ab1b03648ba9d3682ddc1d23c5cadad5.zip chromium_src-3bd29d38ab1b03648ba9d3682ddc1d23c5cadad5.tar.gz chromium_src-3bd29d38ab1b03648ba9d3682ddc1d23c5cadad5.tar.bz2 |
For some Indian locales, the automatic font fallback by Windows UI components leads to too tiny glyphs for UI strings. Therefore, this patch makes it possible to override the UI font family and UI font size localizable by adding two entries to locale_settings (IDS_UI_FONT_FAMILY and IDS_UI_FONT_SIZE_SCALER - percentile scale).
It's is also to fix a P1 bug for Chrome 2.0 final (so this patch needs to be merged back to the branch).
For most locales, the UI font family is set to 'default' and the UI font size scaler is set to 100, which indicates that the UI font (menu, message, etc) obtained from Windows will be used.
For ml and bn, it's set to the 'kartica' and 'vrinda' (the default Windows fonts for those scripts) and the scaler is set to 150 and 160 respectively. For Hindi and Telugu, only the font size scaler is set to 150.
When IDS_UI_FONT_FAMILY is 'default' and the scaler is 100, the behavior will remain the same. When it's not, their values are used to create ChromeFont (base and derived) and WindowsTitle font. In addition, menu will be drawn by 'owner' (to override the windows font) and the font for table view, tree and tooltip is also set to IDS_UI_FONT_FAMILY.
While working on this, I replaced all the instances of 'static ChromeFont' with 'static ChromeFont*' and initialized them in a lazy manner.
The whole approach is still a hack necessary due to the size issue with the default fonts for some Indic scripts on Windows. We'd not need this on Linux and Mac.
TEST=1. Run chrome with '--lang=bn' or '--lang=ml' and see UI strings are legible in menu, context menu, bookmark, bookmark manager, tooltips, and tab titles. With '--lang=hi' and '--lang=te', the difference is not dramatic but should be more readable. In other locales, it should remain the same.
2.UI test in en-US locale should pass.
3. Running UI tests under Purify should not have any new leak.
BUG=7319
Review URL: http://codereview.chromium.org/62064
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@13773 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/views')
-rw-r--r-- | chrome/views/controls/menu/chrome_menu.cc | 2 | ||||
-rw-r--r-- | chrome/views/controls/menu/menu.cc | 37 | ||||
-rw-r--r-- | chrome/views/controls/table/table_view.cc | 3 | ||||
-rw-r--r-- | chrome/views/controls/tree/tree_view.cc | 3 | ||||
-rw-r--r-- | chrome/views/widget/aero_tooltip_manager.cc | 3 | ||||
-rw-r--r-- | chrome/views/widget/tooltip_manager.cc | 6 | ||||
-rw-r--r-- | chrome/views/widget/tooltip_manager.h | 3 | ||||
-rw-r--r-- | chrome/views/window/custom_frame_view.cc | 13 | ||||
-rw-r--r-- | chrome/views/window/custom_frame_view.h | 2 | ||||
-rw-r--r-- | chrome/views/window/dialog_client_view.cc | 6 | ||||
-rw-r--r-- | chrome/views/window/dialog_client_view.h | 2 |
11 files changed, 60 insertions, 20 deletions
diff --git a/chrome/views/controls/menu/chrome_menu.cc b/chrome/views/controls/menu/chrome_menu.cc index 6373cde..64bee99 100644 --- a/chrome/views/controls/menu/chrome_menu.cc +++ b/chrome/views/controls/menu/chrome_menu.cc @@ -19,6 +19,7 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/color_utils.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/l10n_util_win.h" #include "chrome/common/os_exchange_data.h" #include "chrome/views/border.h" #include "chrome/views/view_constants.h" @@ -129,6 +130,7 @@ ChromeFont GetMenuFont() { NONCLIENTMETRICS metrics; win_util::GetNonClientMetrics(&metrics); + l10n_util::AdjustUIFont(&(metrics.lfMenuFont)); HFONT font = CreateFontIndirect(&metrics.lfMenuFont); DLOG_ASSERT(font); return ChromeFont::CreateFont(font); diff --git a/chrome/views/controls/menu/menu.cc b/chrome/views/controls/menu/menu.cc index 3c290f7..3b1d836 100644 --- a/chrome/views/controls/menu/menu.cc +++ b/chrome/views/controls/menu/menu.cc @@ -112,6 +112,9 @@ class MenuHostWindow : public CWindowImpl<MenuHostWindow, CWindow, GetSystemMetrics(SM_CXMENUCHECK); if (data->submenu) lpmis->itemWidth += kArrowWidth; + // If the label contains an accelerator, make room for tab. + if (data->label.find(L'\t') != std::wstring::npos) + lpmis->itemWidth += font.GetStringWidth(L" "); lpmis->itemHeight = font.height() + kItemBottomMargin + kItemTopMargin; } else { // Measure separator size. @@ -139,7 +142,6 @@ class MenuHostWindow : public CWindowImpl<MenuHostWindow, CWindow, if (lpdis->itemData) { Menu::ItemData* data = reinterpret_cast<Menu::ItemData*>(lpdis->itemData); - wchar_t* str = const_cast<wchar_t*>(data->label.c_str()); // Draw the background. HBRUSH hbr = CreateSolidBrush(GetBkColor(hDC)); @@ -149,15 +151,38 @@ class MenuHostWindow : public CWindowImpl<MenuHostWindow, CWindow, // Draw the label. RECT rect = lpdis->rcItem; rect.top += kItemTopMargin; + // Should we add kIconWidth only when icon.width() != 0 ? rect.left += kItemLeftMargin + kIconWidth; - UINT format = DT_TOP | DT_LEFT | DT_SINGLELINE; + rect.right -= kItemRightMargin; + UINT format = DT_TOP | DT_SINGLELINE; // Check whether the mnemonics should be underlined. BOOL underline_mnemonics; SystemParametersInfo(SPI_GETKEYBOARDCUES, 0, &underline_mnemonics, 0); if (!underline_mnemonics) format |= DT_HIDEPREFIX; - DrawTextEx(hDC, str, static_cast<int>(data->label.size()), - &rect, format, NULL); + ChromeFont font; + HGDIOBJ old_font = static_cast<HFONT>(SelectObject(hDC, font.hfont())); + int fontsize = font.FontSize(); + + // If an accelerator is specified (with a tab delimiting the rest + // of the label from the accelerator), we have to justify + // the fist part on the left and the accelerator on the right. + // TODO(jungshik): This will break in RTL UI. Currently, he/ar + // use the window system UI font and will not hit here. + std::wstring label = data->label; + std::wstring accel; + std::wstring::size_type tab_pos = label.find(L'\t'); + if (tab_pos != std::wstring::npos) { + accel = label.substr(tab_pos); + label = label.substr(0, tab_pos); + } + DrawTextEx(hDC, const_cast<wchar_t*>(label.data()), + static_cast<int>(label.size()), &rect, format | DT_LEFT, NULL); + if (!accel.empty()) + DrawTextEx(hDC, const_cast<wchar_t*>(accel.data()), + static_cast<int>(accel.size()), &rect, + format | DT_RIGHT, NULL); + SelectObject(hDC, old_font); // Draw the icon after the label, otherwise it would be covered // by the label. @@ -219,7 +244,7 @@ Menu::Menu(Delegate* delegate, AnchorPoint anchor, HWND owner) anchor_(anchor), owner_(owner), is_menu_visible_(false), - owner_draw_(false) { + owner_draw_(l10n_util::NeedOverrideDefaultUIFont(NULL, NULL)) { DCHECK(delegate_); } @@ -229,7 +254,7 @@ Menu::Menu(Menu* parent) anchor_(parent->anchor_), owner_(parent->owner_), is_menu_visible_(false), - owner_draw_(false) { + owner_draw_(parent->owner_draw_) { } Menu::Menu(HMENU hmenu) diff --git a/chrome/views/controls/table/table_view.cc b/chrome/views/controls/table/table_view.cc index 1a01acc..35a0140 100644 --- a/chrome/views/controls/table/table_view.cc +++ b/chrome/views/controls/table/table_view.cc @@ -12,6 +12,7 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/favicon_size.h" #include "chrome/common/gfx/icon_util.h" +#include "chrome/common/l10n_util_win.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/win_util.h" #include "chrome/views/controls/hwnd_view.h" @@ -823,6 +824,7 @@ HWND TableView::CreateNativeControl(HWND parent_container) { if (table_type_ == CHECK_BOX_AND_TEXT) list_view_style |= LVS_EX_CHECKBOXES; ListView_SetExtendedListViewStyleEx(list_view_, 0, list_view_style); + l10n_util::AdjustUIFontForWindow(list_view_); // Add the columns. for (std::vector<int>::iterator i = visible_columns_.begin(); @@ -1203,6 +1205,7 @@ LRESULT TableView::OnCustomDraw(NMLVCUSTOMDRAW* draw_info) { // with a bool like we do with colors? if (custom_cell_font_) DeleteObject(custom_cell_font_); + l10n_util::AdjustUIFont(&logfont); custom_cell_font_ = CreateFontIndirect(&logfont); SelectObject(draw_info->nmcd.hdc, custom_cell_font_); draw_info->clrText = foreground.color_is_set diff --git a/chrome/views/controls/tree/tree_view.cc b/chrome/views/controls/tree/tree_view.cc index cf4f147..8c130bd 100644 --- a/chrome/views/controls/tree/tree_view.cc +++ b/chrome/views/controls/tree/tree_view.cc @@ -10,6 +10,7 @@ #include "chrome/common/gfx/chrome_canvas.h" #include "chrome/common/gfx/icon_util.h" #include "chrome/common/l10n_util.h" +#include "chrome/common/l10n_util_win.h" #include "chrome/common/resource_bundle.h" #include "chrome/common/stl_util-inl.h" #include "chrome/views/focus/focus_manager.h" @@ -346,6 +347,8 @@ HWND TreeView::CreateNativeControl(HWND parent_container) { reinterpret_cast<LONG_PTR>(&wrapper_)); original_handler_ = win_util::SetWindowProc(tree_view_, &TreeWndProc); + l10n_util::AdjustUIFontForWindow(tree_view_); + if (model_) { CreateRootItems(); model_->SetObserver(this); diff --git a/chrome/views/widget/aero_tooltip_manager.cc b/chrome/views/widget/aero_tooltip_manager.cc index bd6404d..e6ed9da 100644 --- a/chrome/views/widget/aero_tooltip_manager.cc +++ b/chrome/views/widget/aero_tooltip_manager.cc @@ -72,6 +72,9 @@ void AeroTooltipManager::Init() { WS_EX_TRANSPARENT | l10n_util::GetExtendedTooltipStyles(), TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, parent_, NULL, NULL, NULL); + + l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); + // Add one tool that is used for all tooltips. toolinfo_.cbSize = sizeof(toolinfo_); diff --git a/chrome/views/widget/tooltip_manager.cc b/chrome/views/widget/tooltip_manager.cc index 200b8da..dd63196 100644 --- a/chrome/views/widget/tooltip_manager.cc +++ b/chrome/views/widget/tooltip_manager.cc @@ -2,9 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include "chrome/views/widget/tooltip_manager.h" + #include <limits> -#include "chrome/common/gfx/chrome_font.h" #include "base/logging.h" #include "base/message_loop.h" #include "chrome/common/l10n_util.h" @@ -13,7 +14,6 @@ #include "chrome/common/win_util.h" #include "chrome/views/view.h" #include "chrome/views/widget/root_view.h" -#include "chrome/views/widget/tooltip_manager.h" #include "chrome/views/widget/widget.h" namespace views { @@ -107,6 +107,8 @@ void TooltipManager::Init() { TOOLTIPS_CLASS, NULL, TTS_NOPREFIX, 0, 0, 0, 0, parent_, NULL, NULL, NULL); + l10n_util::AdjustUIFontForWindow(tooltip_hwnd_); + // This effectively turns off clipping of tooltips. We need this otherwise // multi-line text (\r\n) won't work right. The size doesn't really matter // (just as long as its bigger than the monitor's width) as we clip to the diff --git a/chrome/views/widget/tooltip_manager.h b/chrome/views/widget/tooltip_manager.h index 312e30e..03e56a1 100644 --- a/chrome/views/widget/tooltip_manager.h +++ b/chrome/views/widget/tooltip_manager.h @@ -6,8 +6,11 @@ #define CHROME_VIEWS_WIDGET_TOOLTIP_MANAGER_H_ #include <windows.h> +#include <commctrl.h> + #include <string> #include "base/basictypes.h" +#include "base/task.h" class ChromeFont; diff --git a/chrome/views/window/custom_frame_view.cc b/chrome/views/window/custom_frame_view.cc index 9c02f72..b1ef417 100644 --- a/chrome/views/window/custom_frame_view.cc +++ b/chrome/views/window/custom_frame_view.cc @@ -106,7 +106,6 @@ class ActiveWindowResources : public WindowResources { } static SkBitmap* standard_frame_bitmaps_[FRAME_PART_BITMAP_COUNT]; - static ChromeFont title_font_; DISALLOW_EVIL_CONSTRUCTORS(ActiveWindowResources); }; @@ -168,7 +167,7 @@ SkBitmap* InactiveWindowResources::standard_frame_bitmaps_[]; // static WindowResources* CustomFrameView::active_resources_ = NULL; WindowResources* CustomFrameView::inactive_resources_ = NULL; -ChromeFont CustomFrameView::title_font_; +ChromeFont* CustomFrameView::title_font_ = NULL; namespace { // The frame border is only visible in restored mode and is hardcoded to 4 px on @@ -433,7 +432,7 @@ int CustomFrameView::TitleCoordinates(int* title_top_spacing, *title_top_spacing += title_adjust; title_bottom_spacing -= title_adjust; } - *title_thickness = std::max(title_font_.height(), + *title_thickness = std::max(title_font_->height(), min_titlebar_height - *title_top_spacing - title_bottom_spacing); return *title_top_spacing + *title_thickness + title_bottom_spacing + BottomEdgeThicknessWithinNonClientHeight(); @@ -506,7 +505,7 @@ void CustomFrameView::PaintTitleBar(ChromeCanvas* canvas) { if (!d) return; - canvas->DrawStringInt(d->GetWindowTitle(), title_font_, SK_ColorWHITE, + canvas->DrawStringInt(d->GetWindowTitle(), *title_font_, SK_ColorWHITE, MirroredLeftPointForRect(title_bounds_), title_bounds_.y(), title_bounds_.width(), title_bounds_.height()); } @@ -667,8 +666,8 @@ void CustomFrameView::LayoutTitleBar() { int title_right = (should_show_minmax_buttons_ ? minimize_button_->x() : close_button_->x()) - kTitleCaptionSpacing; title_bounds_.SetRect(title_x, - title_top_spacing + ((title_thickness - title_font_.height()) / 2), - std::max(0, title_right - title_x), title_font_.height()); + title_top_spacing + ((title_thickness - title_font_->height()) / 2), + std::max(0, title_right - title_x), title_font_->height()); } void CustomFrameView::LayoutClientView() { @@ -688,7 +687,7 @@ void CustomFrameView::InitClass() { active_resources_ = new ActiveWindowResources; inactive_resources_ = new InactiveWindowResources; - title_font_ = win_util::GetWindowTitleFont(); + title_font_ = new ChromeFont(win_util::GetWindowTitleFont()); initialized = true; } diff --git a/chrome/views/window/custom_frame_view.h b/chrome/views/window/custom_frame_view.h index 6e39d3d..1170355 100644 --- a/chrome/views/window/custom_frame_view.h +++ b/chrome/views/window/custom_frame_view.h @@ -112,7 +112,7 @@ class CustomFrameView : public NonClientFrameView, static void InitClass(); static WindowResources* active_resources_; static WindowResources* inactive_resources_; - static ChromeFont title_font_; + static ChromeFont* title_font_; DISALLOW_EVIL_CONSTRUCTORS(CustomFrameView); }; diff --git a/chrome/views/window/dialog_client_view.cc b/chrome/views/window/dialog_client_view.cc index 4779c25..542439d 100644 --- a/chrome/views/window/dialog_client_view.cc +++ b/chrome/views/window/dialog_client_view.cc @@ -78,7 +78,7 @@ class DialogButton : public NativeButton { } // namespace // static -ChromeFont DialogClientView::dialog_button_font_; +ChromeFont* DialogClientView::dialog_button_font_ = NULL; static const int kDialogMinButtonWidth = 75; static const int kDialogButtonLabelSpacing = 16; static const int kDialogButtonContentSpacing = 5; @@ -353,7 +353,7 @@ int DialogClientView::GetButtonWidth(int button) const { DialogDelegate* dd = GetDialogDelegate(); std::wstring button_label = dd->GetDialogButtonLabel( static_cast<DialogDelegate::DialogButton>(button)); - int string_width = dialog_button_font_.GetStringWidth(button_label); + int string_width = dialog_button_font_->GetStringWidth(button_label); return std::max(string_width + kDialogButtonLabelSpacing, kDialogMinButtonWidth); } @@ -431,7 +431,7 @@ void DialogClientView::InitClass() { static bool initialized = false; if (!initialized) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - dialog_button_font_ = rb.GetFont(ResourceBundle::BaseFont); + dialog_button_font_ = new ChromeFont(rb.GetFont(ResourceBundle::BaseFont)); initialized = true; } } diff --git a/chrome/views/window/dialog_client_view.h b/chrome/views/window/dialog_client_view.h index bfea8e0..fadabb6 100644 --- a/chrome/views/window/dialog_client_view.h +++ b/chrome/views/window/dialog_client_view.h @@ -113,7 +113,7 @@ class DialogClientView : public ClientView, // Static resource initialization static void InitClass(); - static ChromeFont dialog_button_font_; + static ChromeFont* dialog_button_font_; DISALLOW_COPY_AND_ASSIGN(DialogClientView); }; |