Commit 5c4f5303 authored by Peter Kvitek's avatar Peter Kvitek Committed by Commit Bot

[DevTools] Introduced Page.setFontFamilies method

Page.setFontFamilies method overrides default settings for generic
font families.

Change-Id: I17645126b1d9fd19b07322c521322ed47e9b73d8
Reviewed-on: https://chromium-review.googlesource.com/1086212
Commit-Queue: Peter Kvitek <kvitekp@chromium.org>
Reviewed-by: default avatarDmitry Gozman <dgozman@chromium.org>
Cr-Commit-Position: refs/heads/master@{#564921}
parent ada28616
Tests Page.setFontFamilies.
.standard_font
[
[0] : {
familyName : Ahem
glyphCount : 8
isCustomFont : false
}
]
.sans_serif_font
[
[0] : {
familyName : Ahem
glyphCount : 9
isCustomFont : false
}
]
.fixed_font
[
[0] : {
familyName : Ahem
glyphCount : 5
isCustomFont : false
}
]
(async function(testRunner) {
var {page, session, dp} = await testRunner.startHTML(
`<html>
<style>
@font-face {
font-family: myahem;
src: url(../../resources/Ahem.woff) format("woff");
}
div.standard_font {
}
div.sans_serif_font {
font-family: sans-serif;
}
div.fixed_font {
font-family: fixed;
}
</style>
<body>
<div class=standard_font>Standard</div>
<div class=sans_serif_font>SansSerif</div>
<div class=fixed_font>Fixed</div>
</body>
</html>`,
'Tests Page.setFontFamilies.');
await dp.DOM.enable();
await dp.CSS.enable();
async function logPlatformFonts(selector) {
testRunner.log(selector);
const root = (await dp.DOM.getDocument()).result.root;
const nodeId = (await dp.DOM.querySelector(
{nodeId: root.nodeId, selector: selector})).result.nodeId;
const fonts = (await dp.CSS.getPlatformFontsForNode(
{nodeId: nodeId})).result.fonts;
testRunner.log(fonts);
}
// Override generic fonts
await dp.Page.setFontFamilies({fontFamilies: {
standard: "Ahem",
sansSerif: "Ahem",
fixed: "Ahem"
}});
// Log overriden generic fonts
await logPlatformFonts('.standard_font');
await logPlatformFonts('.sans_serif_font');
await logPlatformFonts('.fixed_font');
testRunner.completeTest();
})
...@@ -4606,6 +4606,24 @@ domain Page ...@@ -4606,6 +4606,24 @@ domain Page
# Page scale factor. # Page scale factor.
number scale number scale
# Generic font families collection.
experimental type FontFamilies extends object
properties
# The standard font-family.
optional string standard
# The fixed font-family.
optional string fixed
# The serif font-family.
optional string serif
# The sansSerif font-family.
optional string sansSerif
# The cursive font-family.
optional string cursive
# The fantasy font-family.
optional string fantasy
# The pictograph font-family.
optional string pictograph
# Deprecated, please use addScriptToEvaluateOnNewDocument instead. # Deprecated, please use addScriptToEvaluateOnNewDocument instead.
experimental deprecated command addScriptToEvaluateOnLoad experimental deprecated command addScriptToEvaluateOnLoad
parameters parameters
...@@ -4930,6 +4948,12 @@ domain Page ...@@ -4930,6 +4948,12 @@ domain Page
# Mock gamma # Mock gamma
number gamma number gamma
# Set commonly used font families.
experimental command setFontFamilies
parameters
# Specifies font families to set. If a font family is not set, it won't be changed.
FontFamilies fontFamilies
# Sets given markup as the document's HTML. # Sets given markup as the document's HTML.
command setDocumentContent command setDocumentContent
parameters parameters
......
...@@ -88,6 +88,13 @@ static const char kPageAgentScriptsToEvaluateOnLoad[] = ...@@ -88,6 +88,13 @@ static const char kPageAgentScriptsToEvaluateOnLoad[] =
static const char kScreencastEnabled[] = "screencastEnabled"; static const char kScreencastEnabled[] = "screencastEnabled";
static const char kLifecycleEventsEnabled[] = "lifecycleEventsEnabled"; static const char kLifecycleEventsEnabled[] = "lifecycleEventsEnabled";
static const char kBypassCSPEnabled[] = "bypassCSPEnabled"; static const char kBypassCSPEnabled[] = "bypassCSPEnabled";
static const char kStandardFontFamily[] = "standardFontFamily";
static const char kFixedFontFamily[] = "fixedFontFamily";
static const char kSerifFontFamily[] = "serifFontFamily";
static const char kSansSerifFontFamily[] = "sansSerifFontFamily";
static const char kCursiveFontFamily[] = "cursiveFontFamily";
static const char kFantasyFontFamily[] = "fantasyFontFamily";
static const char kPictographFontFamily[] = "pictographFontFamily";
} // namespace PageAgentState } // namespace PageAgentState
namespace { namespace {
...@@ -463,6 +470,46 @@ void InspectorPageAgent::Restore() { ...@@ -463,6 +470,46 @@ void InspectorPageAgent::Restore() {
enable(); enable();
if (state_->booleanProperty(PageAgentState::kBypassCSPEnabled, false)) if (state_->booleanProperty(PageAgentState::kBypassCSPEnabled, false))
setBypassCSP(true); setBypassCSP(true);
// Re-apply generic fonts overrides.
String font;
bool notifyGenericFontFamilyChange = false;
LocalFrame* frame = inspected_frames_->Root();
auto* settings = frame->GetSettings();
if (settings) {
auto& family_settings = settings->GetGenericFontFamilySettings();
if (state_->getString(PageAgentState::kStandardFontFamily, &font)) {
family_settings.UpdateStandard(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kFixedFontFamily, &font)) {
family_settings.UpdateFixed(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kSerifFontFamily, &font)) {
family_settings.UpdateSerif(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kSansSerifFontFamily, &font)) {
family_settings.UpdateSansSerif(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kCursiveFontFamily, &font)) {
family_settings.UpdateCursive(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kFantasyFontFamily, &font)) {
family_settings.UpdateFantasy(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (state_->getString(PageAgentState::kPictographFontFamily, &font)) {
family_settings.UpdatePictograph(AtomicString(font));
notifyGenericFontFamilyChange = true;
}
if (notifyGenericFontFamilyChange) {
settings->NotifyGenericFontFamilyChange();
}
}
} }
Response InspectorPageAgent::enable() { Response InspectorPageAgent::enable() {
...@@ -1150,6 +1197,60 @@ protocol::Response InspectorPageAgent::createIsolatedWorld( ...@@ -1150,6 +1197,60 @@ protocol::Response InspectorPageAgent::createIsolatedWorld(
return Response::OK(); return Response::OK();
} }
Response InspectorPageAgent::setFontFamilies(
std::unique_ptr<protocol::Page::FontFamilies> font_families) {
LocalFrame* frame = inspected_frames_->Root();
auto* settings = frame->GetSettings();
if (settings) {
auto& family_settings = settings->GetGenericFontFamilySettings();
if (font_families->hasStandard()) {
state_->setString(PageAgentState::kStandardFontFamily,
font_families->getStandard(String()));
family_settings.UpdateStandard(
AtomicString(font_families->getStandard(String())));
}
if (font_families->hasFixed()) {
state_->setString(PageAgentState::kFixedFontFamily,
font_families->getFixed(String()));
family_settings.UpdateFixed(
AtomicString(font_families->getFixed(String())));
}
if (font_families->hasSerif()) {
state_->setString(PageAgentState::kSerifFontFamily,
font_families->getSerif(String()));
family_settings.UpdateSerif(
AtomicString(font_families->getSerif(String())));
}
if (font_families->hasSansSerif()) {
state_->setString(PageAgentState::kSansSerifFontFamily,
font_families->getSansSerif(String()));
family_settings.UpdateSansSerif(
AtomicString(font_families->getSansSerif(String())));
}
if (font_families->hasCursive()) {
state_->setString(PageAgentState::kCursiveFontFamily,
font_families->getCursive(String()));
family_settings.UpdateCursive(
AtomicString(font_families->getCursive(String())));
}
if (font_families->hasFantasy()) {
state_->setString(PageAgentState::kFantasyFontFamily,
font_families->getFantasy(String()));
family_settings.UpdateFantasy(
AtomicString(font_families->getFantasy(String())));
}
if (font_families->hasPictograph()) {
state_->setString(PageAgentState::kPictographFontFamily,
font_families->getPictograph(String()));
family_settings.UpdatePictograph(
AtomicString(font_families->getPictograph(String())));
}
settings->NotifyGenericFontFamilyChange();
}
return Response::OK();
}
void InspectorPageAgent::Trace(blink::Visitor* visitor) { void InspectorPageAgent::Trace(blink::Visitor* visitor) {
visitor->Trace(inspected_frames_); visitor->Trace(inspected_frames_);
visitor->Trace(inspector_resource_content_loader_); visitor->Trace(inspector_resource_content_loader_);
......
...@@ -152,6 +152,8 @@ class CORE_EXPORT InspectorPageAgent final ...@@ -152,6 +152,8 @@ class CORE_EXPORT InspectorPageAgent final
Maybe<String> world_name, Maybe<String> world_name,
Maybe<bool> grant_universal_access, Maybe<bool> grant_universal_access,
int* execution_context_id) override; int* execution_context_id) override;
protocol::Response setFontFamilies(
std::unique_ptr<protocol::Page::FontFamilies>) override;
// InspectorInstrumentation API // InspectorInstrumentation API
void DidClearDocumentOfWindowObject(LocalFrame*); void DidClearDocumentOfWindowObject(LocalFrame*);
......
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