Commit 85fa241e authored by kojii's avatar kojii Committed by Commit bot

Set the font family for the "system-ui" generic font family on Linux

This patch sets the font family for the "system-ui" generic font family
added in [1] on Linux.

With this change, all platforms use the correct font. On Windows, the
browser already pass menu_font_family_name to the renderer. On Mac and
Android, the render can find the system font without needing the
browser to set.

On Linux and Chrome OS, gfx::Font() calls LinuxFontDelegate to figure
out the current system font. On the default Ubuntu, this resolves to
"sans", which Skia resolves to "DejaVu Sans", or "Arial" in
run-layout-test.

[1] http://crrev.com/2137483004

BUG=654679

Review-Url: https://codereview.chromium.org/2138613002
Cr-Commit-Position: refs/heads/master@{#427262}
parent eb033605
......@@ -113,8 +113,8 @@ using blink::WebPluginAction;
namespace content {
namespace {
void GetPlatformSpecificPrefs(RendererPreferences* prefs) {
#if defined(OS_WIN)
void GetWindowsSpecificPrefs(RendererPreferences* prefs) {
NONCLIENTMETRICS_XP metrics = {0};
base::win::GetNonClientMetrics(&metrics);
......@@ -146,8 +146,10 @@ void GetWindowsSpecificPrefs(RendererPreferences* prefs) {
display::win::ScreenWin::GetSystemMetricsInDIP(SM_CYVSCROLL);
prefs->arrow_bitmap_width_horizontal_scroll_bar_in_dips =
display::win::ScreenWin::GetSystemMetricsInDIP(SM_CXHSCROLL);
}
#elif defined(OS_LINUX)
prefs->system_font_family_name = gfx::Font().GetFontName();
#endif
}
std::vector<DropData::Metadata> DropDataToMetaData(const DropData& drop_data) {
std::vector<DropData::Metadata> metadata;
......@@ -341,9 +343,7 @@ bool RenderViewHostImpl::CreateRenderView(
mojom::CreateViewParamsPtr params = mojom::CreateViewParams::New();
params->renderer_preferences =
delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
#if defined(OS_WIN)
GetWindowsSpecificPrefs(&params->renderer_preferences);
#endif
GetPlatformSpecificPrefs(&params->renderer_preferences);
params->web_preferences = GetWebkitPreferences();
params->view_id = GetRoutingID();
params->main_frame_routing_id = main_frame_routing_id_;
......@@ -409,9 +409,7 @@ bool RenderViewHostImpl::IsRenderViewLive() const {
void RenderViewHostImpl::SyncRendererPrefs() {
RendererPreferences renderer_preferences =
delegate_->GetRendererPrefs(GetProcess()->GetBrowserContext());
#if defined(OS_WIN)
GetWindowsSpecificPrefs(&renderer_preferences);
#endif
GetPlatformSpecificPrefs(&renderer_preferences);
Send(new ViewMsg_SetRendererPrefs(GetRoutingID(), renderer_preferences));
}
......
......@@ -245,6 +245,9 @@ IPC_STRUCT_TRAITS_BEGIN(content::RendererPreferences)
IPC_STRUCT_TRAITS_MEMBER(plugin_fullscreen_allowed)
IPC_STRUCT_TRAITS_MEMBER(use_video_overlay_for_embedded_encrypted_video)
IPC_STRUCT_TRAITS_MEMBER(network_contry_iso)
#if defined(OS_LINUX)
IPC_STRUCT_TRAITS_MEMBER(system_font_family_name)
#endif
#if defined(OS_WIN)
IPC_STRUCT_TRAITS_MEMBER(caption_font_family_name)
IPC_STRUCT_TRAITS_MEMBER(caption_font_height)
......
......@@ -139,6 +139,10 @@ struct CONTENT_EXPORT RendererPreferences {
// Country iso of the mobile network for content detection purpose.
std::string network_contry_iso;
#if defined(OS_LINUX)
std::string system_font_family_name;
#endif
#if defined(OS_WIN)
// The default system font settings for caption, small caption, menu and
// status messages. Used only by Windows.
......
......@@ -69,6 +69,12 @@ void RenderViewImpl::UpdateFontRenderingFromRendererPrefs() {
prefs.default_font_size <= kMaxDefaultFontSize) {
WebFontRendering::setDefaultFontSize(prefs.default_font_size);
}
#if !defined(OS_ANDROID)
if (!prefs.system_font_family_name.empty()) {
WebFontRendering::setSystemFontFamily(
blink::WebString::fromUTF8(prefs.system_font_family_name));
}
#endif
}
} // namespace content
This text should use the system font.
#system-ui:
"Times New Roman" : 37
"Arial" : 37
This text should use the system font.
#system-ui-20pt:
"Times New Roman" : 37
"Arial" : 37
......@@ -120,8 +120,8 @@ class PLATFORM_EXPORT FontCache {
#else
static const AtomicString& legacySystemFontFamily();
#endif
#if OS(LINUX)
static void setSystemFontFamily(const char*);
#if OS(LINUX) || OS(ANDROID)
static void setSystemFontFamily(const AtomicString&);
#endif
#if OS(WIN)
......
......@@ -60,6 +60,9 @@ const AtomicString& FontCache::systemFontFamily() {
return systemFontFamily;
}
// static
void FontCache::setSystemFontFamily(const AtomicString&) {}
PassRefPtr<SimpleFontData> FontCache::fallbackFontForCharacter(
const FontDescription& fontDescription,
UChar32 c,
......
......@@ -54,8 +54,8 @@ const AtomicString& FontCache::systemFontFamily() {
}
// static
void FontCache::setSystemFontFamily(const char* familyName) {
DCHECK(familyName && *familyName);
void FontCache::setSystemFontFamily(const AtomicString& familyName) {
DCHECK(!familyName.isEmpty());
mutableSystemFontFamily() = familyName;
}
......
......@@ -81,4 +81,9 @@ void WebFontRendering::setDefaultFontSize(int size) {
LayoutThemeFontProvider::setDefaultFontSize(size);
}
// static
void WebFontRendering::setSystemFontFamily(const WebString& name) {
FontCache::setSystemFontFamily(name);
}
} // namespace blink
......@@ -32,6 +32,7 @@
#define WebFontRendering_h
#include "../../platform/WebCommon.h"
#include "../../platform/WebString.h"
#include <SkFontMgr.h>
#include <SkPaint.h>
......@@ -49,6 +50,7 @@ class WebFontRendering {
BLINK_EXPORT static void setSubpixelRendering(bool);
BLINK_EXPORT static void setSubpixelPositioning(bool);
BLINK_EXPORT static void setDefaultFontSize(int);
BLINK_EXPORT static void setSystemFontFamily(const WebString&);
};
} // namespace blink
......
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