Web Inspector: Add a function to CSSCompletions to get a list of supported system...
authordrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 20:24:08 +0000 (20:24 +0000)
committerdrousso@apple.com <drousso@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 23 Jul 2015 20:24:08 +0000 (20:24 +0000)
https://bugs.webkit.org/show_bug.cgi?id=147009

Reviewed by Joseph Pecoraro.

Source/JavaScriptCore:

* inspector/protocol/CSS.json: Added getSupportedSystemFontFamilyNames function.

Source/WebCore:

Test: inspector/css/get-system-fonts.html

* inspector/InspectorCSSAgent.cpp:
(WebCore::InspectorCSSAgent::getSupportedSystemFontFamilyNames):
Gets the list of system fonts (implemented in each platform) and returns that list.
* inspector/InspectorCSSAgent.h:
* platform/graphics/FontCache.h:
* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::FontCache::systemFontFamilies):
* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::FontCache::systemFontFamilies):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::FontCache::systemFontFamilies):
* platform/graphics/win/FontCacheWin.cpp:
(WebCore::FontCache::systemFontFamilies):

Source/WebInspectorUI:

* UserInterface/Base/Main.js:
(WebInspector.loaded):
(WebInspector.activateExtraDomains):
* UserInterface/Base/Test.js:
(WebInspector.loaded):
* UserInterface/Models/CSSCompletions.js:
(WebInspector.CSSCompletions.requestCSSCompletions.fontFamilyNamesCallback):
(WebInspector.CSSCompletions.requestCSSCompletions):
Now also grabs the list of system font family names and adds that list to the existing completion
list for both font and font-family in CSSKeywordCompletions.
(WebInspector.CSSCompletions.requestCSSNameCompletions): Deleted.

LayoutTests:

Skip the get-system-fonts test until it is implemented.
* platform/efl/TestExpectations:
* platform/gtk/TestExpectations:
* platform/win/TestExpectations:

Added the get-system-fonts test that returns the list of system fonts.
* inspector/css/get-system-fonts-expected.html:
* inspector/css/get-system-fonts.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@187249 268f45cc-cd09-0410-ab3c-d52691b4dbfc

20 files changed:
LayoutTests/ChangeLog
LayoutTests/inspector/css/get-system-fonts-expected.txt [new file with mode: 0644]
LayoutTests/inspector/css/get-system-fonts.html [new file with mode: 0644]
LayoutTests/platform/efl/TestExpectations
LayoutTests/platform/gtk/TestExpectations
LayoutTests/platform/win/TestExpectations
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/inspector/protocol/CSS.json
Source/WebCore/ChangeLog
Source/WebCore/inspector/InspectorCSSAgent.cpp
Source/WebCore/inspector/InspectorCSSAgent.h
Source/WebCore/platform/graphics/FontCache.h
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/graphics/win/FontCacheWin.cpp
Source/WebInspectorUI/ChangeLog
Source/WebInspectorUI/UserInterface/Base/Main.js
Source/WebInspectorUI/UserInterface/Base/Test.js
Source/WebInspectorUI/UserInterface/Models/CSSCompletions.js

index 106d963..acbbfad 100644 (file)
@@ -1,3 +1,19 @@
+2015-07-23  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147009
+
+        Reviewed by Joseph Pecoraro.
+
+        Skip the get-system-fonts test until it is implemented.
+        * platform/efl/TestExpectations:
+        * platform/gtk/TestExpectations:
+        * platform/win/TestExpectations:
+
+        Added the get-system-fonts test that returns the list of system fonts.
+        * inspector/css/get-system-fonts-expected.html:
+        * inspector/css/get-system-fonts.html:
+
 2015-07-23  Brady Eidson  <beidson@apple.com>
 
         Crash in WebPlatformStrategies::createPingHandle - Deref a null NetworkingContext.
diff --git a/LayoutTests/inspector/css/get-system-fonts-expected.txt b/LayoutTests/inspector/css/get-system-fonts-expected.txt
new file mode 100644 (file)
index 0000000..2e3161b
--- /dev/null
@@ -0,0 +1,4 @@
+Has at least 5 fonts: true
+PASS: Includes Arial
+PASS: Includes Times
+
diff --git a/LayoutTests/inspector/css/get-system-fonts.html b/LayoutTests/inspector/css/get-system-fonts.html
new file mode 100644 (file)
index 0000000..83ef274
--- /dev/null
@@ -0,0 +1,28 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script type="text/javascript" src="../../http/tests/inspector/inspector-test.js"></script>
+<script>
+// Testing that we can get the fonts on the system and that the fonts contain some universal fonts (arial, times, etc).
+function test() {
+    function hasFontFamily(fontFamilies, fontFamily) {
+        return (fontFamilies.includes(fontFamily) ? "PASS: Includes " : "FAIL: Missing ") + fontFamily;
+    }
+
+    function fontFamilyNamesCallback(error, fontFamilyNames) {
+        InspectorTest.assert(!error, "Error in getting font family names.");
+
+        if (!error) {
+            InspectorTest.log("Has at least 5 fonts: " + (fontFamilyNames.length >= 5));
+            InspectorTest.log(hasFontFamily(fontFamilyNames, "Arial"));
+            InspectorTest.log(hasFontFamily(fontFamilyNames, "Times"));
+        }
+
+        InspectorTest.completeTest();
+    }
+    CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback);
+}
+</script>
+</head>
+<body onload="runTest()"></body>
+</html>
index 9e27ac6..f573e08 100644 (file)
@@ -660,6 +660,8 @@ webkit.org/b/136227 mathml/very-large-stretchy-operators.html [ Crash Timeout Pa
 
 #webkit.org/b/142158 inspector-protocol/dom/remove-multiple-nodes.html [ Crash Pass ]
 
+webkit.org/b/147018 inspector/css/get-system-fonts.html [ Skip ]
+
 #////////////////////////////////////////////////////////////////////////////////////////
 # FLAKY TESTS
 #////////////////////////////////////////////////////////////////////////////////////////
index b4d6720..57cbb11 100644 (file)
@@ -1319,6 +1319,7 @@ webkit.org/b/137698 media/video-controls-drag.html [ Timeout ]
 
 webkit.org/b/139362 inspector/css/pseudo-element-matches.html [ Timeout ]
 webkit.org/b/139362 inspector/css/selector-specificity.html [ Timeout Pass ]
+webkit.org/b/147018 inspector/css/get-system-fonts.html [ Skip ]
 
 webkit.org/b/139363 media/media-controls-timeline-updates.html [ Timeout ]
 
index c76a36e..c326dc3 100644 (file)
@@ -2359,6 +2359,8 @@ inspector/dom/content-node-region-info.html [ Crash Pass Failure Timeout ]
 inspector/css/selector-specificity.html [ Skip ]
 inspector/css/pseudo-element-matches.html [ Skip ]
 
+webkit.org/b/147017 inspector/css/get-system-fonts.html [ Skip ]
+
 # Inspector Protocol
 webkit.org/b/140510 inspector-protocol/debugger/terminate-dedicated-worker-while-paused.html [ Skip ]  # Crashing
 inspector-protocol/debugger/pause-on-assert.html [ Skip ]
index 26ca6d2..c13befd 100644 (file)
@@ -1,3 +1,12 @@
+2015-07-23  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147009
+
+        Reviewed by Joseph Pecoraro.
+
+        * inspector/protocol/CSS.json: Added getSupportedSystemFontFamilyNames function.
+
 2015-07-22  Sukolsak Sakshuwong  <sukolsak@gmail.com>
 
         Add ENABLE_WEBASSEMBLY feature flag for WebAssembly
index f02216d..1b3264b 100644 (file)
             "description": "Returns all supported CSS property names."
         },
         {
+            "name": "getSupportedSystemFontFamilyNames",
+            "returns": [
+                { "name": "fontFamilyNames", "type": "array", "items": { "type": "string" }, "description": "Supported system font families." }
+            ],
+            "description": "Returns all supported system font family names."
+        },
+        {
             "name": "forcePseudoState",
             "parameters": [
                 { "name": "nodeId", "$ref": "DOM.NodeId", "description": "The element id for which to force the pseudo state." },
index a1f9c0d..8b5ca7f 100644 (file)
@@ -1,3 +1,26 @@
+2015-07-23  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147009
+
+        Reviewed by Joseph Pecoraro.
+
+        Test: inspector/css/get-system-fonts.html
+
+        * inspector/InspectorCSSAgent.cpp:
+        (WebCore::InspectorCSSAgent::getSupportedSystemFontFamilyNames):
+        Gets the list of system fonts (implemented in each platform) and returns that list.
+        * inspector/InspectorCSSAgent.h:
+        * platform/graphics/FontCache.h:
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::FontCache::systemFontFamilies):
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::FontCache::systemFontFamilies):
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::FontCache::systemFontFamilies):
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::FontCache::systemFontFamilies):
+
 2015-07-23  Brent Fulgham  <bfulgham@apple.com>
 
         [Win] Implement High DPI support features
index 3d06208..dda9b88 100644 (file)
@@ -36,6 +36,7 @@
 #include "ContentSecurityPolicy.h"
 #include "DOMWindow.h"
 #include "ExceptionCodePlaceholder.h"
+#include "FontCache.h"
 #include "HTMLHeadElement.h"
 #include "HTMLStyleElement.h"
 #include "InspectorDOMAgent.h"
@@ -708,6 +709,17 @@ void InspectorCSSAgent::getSupportedCSSProperties(ErrorString&, RefPtr<Inspector
     cssProperties = WTF::move(properties);
 }
 
+void InspectorCSSAgent::getSupportedSystemFontFamilyNames(ErrorString&, RefPtr<Inspector::Protocol::Array<String>>& fontFamilyNames)
+{
+    auto families = Inspector::Protocol::Array<String>::create();
+
+    Vector<String> systemFontFamilies = FontCache::singleton().systemFontFamilies();
+    for (const auto& familyName : systemFontFamilies)
+        families->addItem(familyName);
+
+    fontFamilyNames = WTF::move(families);
+}
+
 void InspectorCSSAgent::forcePseudoState(ErrorString& errorString, int nodeId, const InspectorArray& forcedPseudoClasses)
 {
     Element* element = m_domAgent->assertElement(errorString, nodeId);
index a630fe5..ece0299 100644 (file)
@@ -119,6 +119,7 @@ public:
     virtual void setRuleSelector(ErrorString&, const Inspector::InspectorObject& ruleId, const String& selector, RefPtr<Inspector::Protocol::CSS::CSSRule>& result) override;
     virtual void addRule(ErrorString&, int contextNodeId, const String& selector, RefPtr<Inspector::Protocol::CSS::CSSRule>& result) override;
     virtual void getSupportedCSSProperties(ErrorString&, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSPropertyInfo>>& result) override;
+    virtual void getSupportedSystemFontFamilyNames(ErrorString&, RefPtr<Inspector::Protocol::Array<String>>& result) override;
     virtual void forcePseudoState(ErrorString&, int nodeId, const Inspector::InspectorArray& forcedPseudoClasses) override;
     virtual void getNamedFlowCollection(ErrorString&, int documentNodeId, RefPtr<Inspector::Protocol::Array<Inspector::Protocol::CSS::NamedFlow>>& result) override;
 
index 31989ae..176a330 100644 (file)
@@ -110,10 +110,9 @@ class FontCache {
 public:
     WEBCORE_EXPORT static FontCache& singleton();
 
-    // This method is implemented by the platform.
+    // These methods are implemented by the platform.
     RefPtr<Font> systemFallbackForCharacters(const FontDescription&, const Font* originalFontData, bool isPlatformFont, const UChar* characters, unsigned length);
-
-    // Also implemented by the platform.
+    Vector<String> systemFontFamilies();
     void platformInit();
 
 #if PLATFORM(IOS)
index b232716..c7a7ea8 100644 (file)
@@ -98,6 +98,13 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     return fontForPlatformData(alternateFontData);
 }
 
+Vector<String> FontCache::systemFontFamilies()
+{
+    // FIXME: <https://webkit.org/b/147018> Web Inspector: [Freetype] Allow inspector to retrieve a list of system fonts
+    Vector<String> fontFamilies;
+    return fontFamilies;
+}
+
 Ref<Font> FontCache::lastResortFallbackFont(const FontDescription& fontDescription)
 {
     // We want to return a fallback font here, otherwise the logic preventing FontConfig
index c9131c2..31fa6d3 100644 (file)
@@ -462,6 +462,13 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     return lastResortFallbackFont(description);
 }
 
+Vector<String> FontCache::systemFontFamilies()
+{
+    // FIXME: <https://webkit.org/b/147033> Web Inspector: [iOS] Allow inspector to retrieve a list of system fonts
+    Vector<String> fontFamilies;
+    return fontFamilies;
+}
+
 RefPtr<Font> FontCache::similarFont(const FontDescription& description)
 {
     // Attempt to find an appropriate font using a match based on the presence of keywords in
index 6d9c4f8..385f963 100644 (file)
@@ -527,6 +527,26 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     return fontForPlatformData(alternateFont);
 }
 
+Vector<String> FontCache::systemFontFamilies()
+{
+    Vector<String> fontFamilies;
+    RetainPtr<CFArrayRef> availableFontFamilies = adoptCF(CTFontManagerCopyAvailableFontFamilyNames());
+    CFIndex count = CFArrayGetCount(availableFontFamilies.get());
+    for (CFIndex i = 0; i < count; ++i) {
+        CFStringRef fontName = static_cast<CFStringRef>(CFArrayGetValueAtIndex(availableFontFamilies.get(), i));
+        if (CFGetTypeID(fontName) != CFStringGetTypeID()) {
+            ASSERT_NOT_REACHED();
+            continue;
+        }
+        // We don't want to make the hidden system fonts visible and since they
+        // all begin with a period, ignore all fonts that begin with a period.
+        if (CFStringHasPrefix(fontName, CFSTR(".")))
+            continue;
+        fontFamilies.append(fontName);
+    }
+    return fontFamilies;
+}
+
 RefPtr<Font> FontCache::similarFont(const FontDescription& description)
 {
     // Attempt to find an appropriate font using a match based on 
index 479cb85..afa4841 100644 (file)
@@ -309,6 +309,13 @@ RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& descr
     return fontData.release();
 }
 
+Vector<String> FontCache::systemFontFamilies()
+{
+    // FIXME: <https://webkit.org/b/147017> Web Inspector: [Win] Allow inspector to retrieve a list of system fonts
+    Vector<String> fontFamilies;
+    return fontFamilies;
+}
+
 RefPtr<Font> FontCache::fontFromDescriptionAndLogFont(const FontDescription& fontDescription, const LOGFONT& font, AtomicString& outFontFamilyName)
 {
     AtomicString familyName = String(font.lfFaceName, wcsnlen(font.lfFaceName, LF_FACESIZE));
index 46431c7..b762c1f 100644 (file)
@@ -1,3 +1,22 @@
+2015-07-23  Devin Rousso  <drousso@apple.com>
+
+        Web Inspector: Add a function to CSSCompletions to get a list of supported system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147009
+
+        Reviewed by Joseph Pecoraro.
+
+        * UserInterface/Base/Main.js:
+        (WebInspector.loaded):
+        (WebInspector.activateExtraDomains):
+        * UserInterface/Base/Test.js:
+        (WebInspector.loaded):
+        * UserInterface/Models/CSSCompletions.js:
+        (WebInspector.CSSCompletions.requestCSSCompletions.fontFamilyNamesCallback):
+        (WebInspector.CSSCompletions.requestCSSCompletions):
+        Now also grabs the list of system font family names and adds that list to the existing completion
+        list for both font and font-family in CSSKeywordCompletions.
+        (WebInspector.CSSCompletions.requestCSSNameCompletions): Deleted.
+
 2015-07-23  Matt Baker  <mattbaker@apple.com>
 
         Web Inspector: wrong cursor shown when selecting time interval from timeline overview
index b502f20..b4ebf0f 100644 (file)
@@ -90,7 +90,7 @@ WebInspector.loaded = function()
         InspectorAgent.enable();
 
     // Perform one-time tasks.
-    WebInspector.CSSCompletions.requestCSSNameCompletions();
+    WebInspector.CSSCompletions.requestCSSCompletions();
     this._generateDisclosureTriangleImages();
 
     // Listen for the ProvisionalLoadStarted event before registering for events so our code gets called before any managers or sidebars.
@@ -501,7 +501,7 @@ WebInspector.activateExtraDomains = function(domains)
 
     this.notifications.dispatchEventToListeners(WebInspector.Notification.ExtraDomainsActivated, {"domains": domains});
 
-    WebInspector.CSSCompletions.requestCSSNameCompletions();
+    WebInspector.CSSCompletions.requestCSSCompletions();
 
     this._updateReloadToolbarButton();
     this._updateDownloadToolbarButton();
index a0bedc0..1ed844a 100644 (file)
@@ -69,7 +69,7 @@ WebInspector.loaded = function()
     ConsoleAgent.enable();
 
     // Perform one-time tasks.
-    WebInspector.CSSCompletions.requestCSSNameCompletions();
+    WebInspector.CSSCompletions.requestCSSCompletions();
 
     // Global settings.
     this.showShadowDOMSetting = new WebInspector.Setting("show-shadow-dom", true);
index 55515a9..47fe67e 100644 (file)
@@ -76,7 +76,7 @@ WebInspector.CSSCompletions = class CSSCompletions
 
     // Static
 
-    static requestCSSNameCompletions()
+    static requestCSSCompletions()
     {
         if (WebInspector.CSSCompletions.cssNameCompletions)
             return;
@@ -158,8 +158,21 @@ WebInspector.CSSCompletions = class CSSCompletions
             updateCodeMirrorCSSMode("text/x-scss");
         }
 
-        if (window.CSSAgent)
+        function fontFamilyNamesCallback(error, fontFamilyNames)
+        {
+            if (error)
+                return;
+
+            WebInspector.CSSKeywordCompletions.addPropertyCompletionValues("font-family", fontFamilyNames);
+            WebInspector.CSSKeywordCompletions.addPropertyCompletionValues("font", fontFamilyNames);
+        }
+
+        if (window.CSSAgent) {
             CSSAgent.getSupportedCSSProperties(propertyNamesCallback);
+
+            if (CSSAgent.getSupportedSystemFontFamilyNames)
+                CSSAgent.getSupportedSystemFontFamilyNames(fontFamilyNamesCallback);
+        }
     }
 
     // Public