Add SPI for telling WebKit to prefer pictograph glyphs over monochrome ones
authoraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 23:05:22 +0000 (23:05 +0000)
committeraestes@apple.com <aestes@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 10 Oct 2013 23:05:22 +0000 (23:05 +0000)
https://bugs.webkit.org/show_bug.cgi?id=122608

Reviewed by Dan Bernstein.

Based on patches by Dan Bernstein.

Source/WebCore:

Test: fonts/font-fallback-prefers-pictographs.html

Created a mechanism to append a font to the end of a font's fallback
list, before the system fallback list. This mechanism is used when
Settings::fontFallbackPrefersPictographs() is true to insert a
pictograph font ahead of a monochrome one from the system fallback list.

* WebCore.exp.in: Moved
__ZN7WebCore8Settings33setFontFallbackPrefersPictographsEb outside of
an iOS platform guard.
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::fallbackFontDataCount): Retuned 1 if
pictograph fonts are preferred.
(WebCore::CSSFontSelector::getFallbackFontData): Returned the
pictograph font's FontData if it is preferred.
* css/CSSFontSelector.h:
* page/Settings.cpp:
(WebCore::Settings::Settings): Initialized
m_fontFallbackPrefersPictographs to false.
(WebCore::Settings::setFontFallbackPrefersPictographs): Set
m_fontFallbackPrefersPictographs and called
Page::setNeedsRecalcStyleInAllFrames().
* page/Settings.h:
(WebCore::Settings::fontFallbackPrefersPictographs):
* platform/graphics/FontGlyphs.cpp:
(WebCore::FontGlyphs::realizeFontDataAt): Realized the selector's
fallback font if necessary.
* platform/graphics/FontSelector.h:
* style/StyleResolveTree.cpp:
(WebCore::Style::resolveTree): Removed iOS platform guards.
* testing/InternalSettings.cpp:
(WebCore::InternalSettings::setFontFallbackPrefersPictographs): Set the
corresponding WebCore::Setting.
* testing/InternalSettings.h: Defined an internal setting for the test.
* testing/InternalSettings.idl: Ditto.

Source/WebKit/mac:

* WebView/WebView.mm:
(-[WebView _setFontFallbackPrefersPictographs:]): Called
WebCore::Settings::setFontFallbackPrefersPictographs().
* WebView/WebViewPrivate.h:

LayoutTests:

* fonts/font-fallback-prefers-pictographs-expected.html: Added.
* fonts/font-fallback-prefers-pictographs.html: Added.

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

18 files changed:
LayoutTests/ChangeLog
LayoutTests/fonts/font-fallback-prefers-pictographs-expected.html [new file with mode: 0644]
LayoutTests/fonts/font-fallback-prefers-pictographs.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/WebCore.exp.in
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/page/Settings.cpp
Source/WebCore/page/Settings.h
Source/WebCore/platform/graphics/FontGlyphs.cpp
Source/WebCore/platform/graphics/FontSelector.h
Source/WebCore/style/StyleResolveTree.cpp
Source/WebCore/testing/InternalSettings.cpp
Source/WebCore/testing/InternalSettings.h
Source/WebCore/testing/InternalSettings.idl
Source/WebKit/mac/ChangeLog
Source/WebKit/mac/WebView/WebView.mm
Source/WebKit/mac/WebView/WebViewPrivate.h

index 1340982..d5f807d 100644 (file)
@@ -1,3 +1,15 @@
+2013-10-10  Andy Estes  <aestes@apple.com>
+
+        Add SPI for telling WebKit to prefer pictograph glyphs over monochrome ones
+        https://bugs.webkit.org/show_bug.cgi?id=122608
+
+        Reviewed by Dan Bernstein.
+
+        Based on patches by Dan Bernstein.
+
+        * fonts/font-fallback-prefers-pictographs-expected.html: Added.
+        * fonts/font-fallback-prefers-pictographs.html: Added.
+
 2013-10-10  Gustavo Noronha Silva  <gns@gnome.org>
 
         Unreviewed gardening. Add timeout annotation to gtk-wk2-specific expectation for
diff --git a/LayoutTests/fonts/font-fallback-prefers-pictographs-expected.html b/LayoutTests/fonts/font-fallback-prefers-pictographs-expected.html
new file mode 100644 (file)
index 0000000..92ea429
--- /dev/null
@@ -0,0 +1,2 @@
+<!DOCTYPE html>
+<span style="font-family: -webkit-pictograph">&#x2665;</span>
diff --git a/LayoutTests/fonts/font-fallback-prefers-pictographs.html b/LayoutTests/fonts/font-fallback-prefers-pictographs.html
new file mode 100644 (file)
index 0000000..812f786
--- /dev/null
@@ -0,0 +1,6 @@
+<!DOCTYPE html>
+<script>
+if (window.internals)
+    window.internals.settings.setFontFallbackPrefersPictographs(true);
+</script>
+&#x2665;
index 7c945ac..d128611 100644 (file)
@@ -1,3 +1,48 @@
+2013-10-10  Andy Estes  <aestes@apple.com>
+
+        Add SPI for telling WebKit to prefer pictograph glyphs over monochrome ones
+        https://bugs.webkit.org/show_bug.cgi?id=122608
+
+        Reviewed by Dan Bernstein.
+
+        Based on patches by Dan Bernstein.
+
+        Test: fonts/font-fallback-prefers-pictographs.html
+
+        Created a mechanism to append a font to the end of a font's fallback
+        list, before the system fallback list. This mechanism is used when
+        Settings::fontFallbackPrefersPictographs() is true to insert a
+        pictograph font ahead of a monochrome one from the system fallback list.
+
+        * WebCore.exp.in: Moved
+        __ZN7WebCore8Settings33setFontFallbackPrefersPictographsEb outside of
+        an iOS platform guard.
+        * css/CSSFontSelector.cpp:
+        (WebCore::CSSFontSelector::fallbackFontDataCount): Retuned 1 if
+        pictograph fonts are preferred.
+        (WebCore::CSSFontSelector::getFallbackFontData): Returned the
+        pictograph font's FontData if it is preferred.
+        * css/CSSFontSelector.h:
+        * page/Settings.cpp:
+        (WebCore::Settings::Settings): Initialized
+        m_fontFallbackPrefersPictographs to false.
+        (WebCore::Settings::setFontFallbackPrefersPictographs): Set
+        m_fontFallbackPrefersPictographs and called
+        Page::setNeedsRecalcStyleInAllFrames().
+        * page/Settings.h:
+        (WebCore::Settings::fontFallbackPrefersPictographs):
+        * platform/graphics/FontGlyphs.cpp:
+        (WebCore::FontGlyphs::realizeFontDataAt): Realized the selector's
+        fallback font if necessary.
+        * platform/graphics/FontSelector.h:
+        * style/StyleResolveTree.cpp:
+        (WebCore::Style::resolveTree): Removed iOS platform guards.
+        * testing/InternalSettings.cpp:
+        (WebCore::InternalSettings::setFontFallbackPrefersPictographs): Set the
+        corresponding WebCore::Setting.
+        * testing/InternalSettings.h: Defined an internal setting for the test.
+        * testing/InternalSettings.idl: Ditto.
+
 2013-10-10  Sergio Correia  <sergio.correia@openbossa.org>
 
         Remove unused attribute in CoordinatedTile class
index 537f368..aa4d837 100644 (file)
@@ -1118,6 +1118,7 @@ __ZN7WebCore8Settings32setAcceleratedCompositingEnabledEb
 __ZN7WebCore8Settings32setNeedsAdobeFrameReloadingQuirkEb
 __ZN7WebCore8Settings32setScreenFontSubstitutionEnabledEb
 __ZN7WebCore8Settings33setAggressiveTileRetentionEnabledEb
+__ZN7WebCore8Settings33setFontFallbackPrefersPictographsEb
 __ZN7WebCore8Settings37setScrollingPerformanceLoggingEnabledEb
 __ZN7WebCore8Settings38setLowPowerVideoAudioBufferSizeEnabledEb
 __ZN7WebCore8Settings41setAcceleratedCompositedAnimationsEnabledEb
@@ -2243,7 +2244,6 @@ __ZN7WebCore8IntPointC1ERK7CGPoint
 __ZN7WebCore8PositionC1EN3WTF10PassRefPtrINS_4NodeEEENS0_19LegacyEditingOffsetE
 __ZN7WebCore8SVGNames4initEv
 __ZN7WebCore8Settings13setStandaloneEb
-__ZN7WebCore8Settings33setFontFallbackPrefersPictographsEb
 __ZN7WebCore9FontCache17getCachedFontDataERKNS_15FontDescriptionERKN3WTF12AtomicStringEbNS0_12ShouldRetainE
 __ZN7WebCore9FontCache25getLastResortFallbackFontERKNS_15FontDescriptionENS0_12ShouldRetainE
 __ZN7WebCore9FrameView20setWasScrolledByUserEb
index 9a05d55..cb36b95 100644 (file)
@@ -632,4 +632,29 @@ bool CSSFontSelector::resolvesFamilyFor(const FontDescription& description) cons
     return false;
 }
 
+size_t CSSFontSelector::fallbackFontDataCount()
+{
+    if (!m_document)
+        return 0;
+
+    if (Settings* settings = m_document->settings())
+        return settings->fontFallbackPrefersPictographs() ? 1 : 0;
+
+    return 0;
+}
+
+PassRefPtr<FontData> CSSFontSelector::getFallbackFontData(const FontDescription& fontDescription, size_t index)
+{
+    ASSERT_UNUSED(index, !index);
+
+    if (!m_document)
+        return 0;
+
+    Settings* settings = m_document->settings();
+    if (!settings || !settings->fontFallbackPrefersPictographs())
+        return 0;
+
+    return fontCache()->getCachedFontData(fontDescription, settings->pictographFontFamily());
+}
+
 }
index 6123b59..48261ea 100644 (file)
@@ -57,6 +57,8 @@ public:
     virtual unsigned uniqueId() const OVERRIDE { return m_uniqueId; }
 
     virtual PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString&) OVERRIDE;
+    virtual size_t fallbackFontDataCount() OVERRIDE;
+    virtual PassRefPtr<FontData> getFallbackFontData(const FontDescription&, size_t) OVERRIDE;
     CSSSegmentedFontFace* getFontFace(const FontDescription&, const AtomicString& family);
 
     virtual bool resolvesFamilyFor(const FontDescription&) const OVERRIDE;
index 1d02c95..1e034c2 100644 (file)
@@ -182,6 +182,7 @@ Settings::Settings(Page* page)
 #if ENABLE(PAGE_VISIBILITY_API)
     , m_hiddenPageCSSAnimationSuspensionEnabled(false)
 #endif
+    , m_fontFallbackPrefersPictographs(false)
 {
     // A Frame may not have been created yet, so we initialize the AtomicString
     // hash before trying to use it.
@@ -641,6 +642,15 @@ void Settings::setHiddenPageCSSAnimationSuspensionEnabled(bool flag)
 }
 #endif
 
+void Settings::setFontFallbackPrefersPictographs(bool preferPictographs)
+{
+    if (m_fontFallbackPrefersPictographs == preferPictographs)
+        return;
+
+    m_fontFallbackPrefersPictographs = preferPictographs;
+    m_page->setNeedsRecalcStyleInAllFrames();
+}
+
 void Settings::setLowPowerVideoAudioBufferSizeEnabled(bool flag)
 {
     gLowPowerVideoAudioBufferSizeEnabled = flag;
index 649763f..ac2a786 100644 (file)
@@ -261,6 +261,9 @@ public:
     void setHiddenPageCSSAnimationSuspensionEnabled(bool);
 #endif
 
+    void setFontFallbackPrefersPictographs(bool);
+    bool fontFallbackPrefersPictographs() const { return m_fontFallbackPrefersPictographs; }
+
     static bool lowPowerVideoAudioBufferSizeEnabled() { return gLowPowerVideoAudioBufferSizeEnabled; }
     static void setLowPowerVideoAudioBufferSizeEnabled(bool);
 
@@ -323,6 +326,8 @@ private:
 #if ENABLE(PAGE_VISIBILITY_API)
     bool m_hiddenPageCSSAnimationSuspensionEnabled : 1;
 #endif
+    bool m_fontFallbackPrefersPictographs : 1;
+
     static double gDefaultMinDOMTimerInterval;
     static double gDefaultDOMTimerAlignmentInterval;
 
index 3c21194..8612da1 100644 (file)
@@ -99,8 +99,20 @@ const FontData* FontGlyphs::realizeFontDataAt(const FontDescription& description
     // Make sure we're not passing in some crazy value here.
     ASSERT(realizedFontIndex == m_realizedFontData.size());
 
-    if (m_familyIndex == cAllFamiliesScanned)
-        return 0;
+    if (m_familyIndex <= cAllFamiliesScanned) {
+        if (!m_fontSelector)
+            return 0;
+
+        size_t index = cAllFamiliesScanned - m_familyIndex;
+        if (index == m_fontSelector->fallbackFontDataCount())
+            return 0;
+
+        m_familyIndex--;
+        RefPtr<FontData> fallback = m_fontSelector->getFallbackFontData(description, index);
+        if (fallback)
+            m_realizedFontData.append(fallback);
+        return fallback.get();
+    }
 
     // Ask the font cache for the font data.
     // We are obtaining this font for the first time. We keep track of the families we've looked at before
index 6571077..68a22de 100644 (file)
@@ -39,7 +39,12 @@ class FontSelectorClient;
 class FontSelector : public RefCounted<FontSelector> {
 public:
     virtual ~FontSelector() { }
+
+    // FIXME: Remove the "get" prefix from these two member functions
     virtual PassRefPtr<FontData> getFontData(const FontDescription&, const AtomicString& familyName) = 0;
+    virtual PassRefPtr<FontData> getFallbackFontData(const FontDescription&, size_t) = 0;
+
+    virtual size_t fallbackFontDataCount() = 0;
     virtual bool resolvesFamilyFor(const FontDescription&) const = 0;
 
     virtual void fontCacheInvalidated() { }
index bbb88c2..674dc89 100644 (file)
@@ -27,6 +27,7 @@
 #include "StyleResolveTree.h"
 
 #include "AXObjectCache.h"
+#include "CSSFontSelector.h"
 #include "Element.h"
 #include "ElementIterator.h"
 #include "ElementRareData.h"
@@ -791,7 +792,6 @@ void resolveTree(Document& document, Change change)
     if (resolveRootStyle) {
         RefPtr<RenderStyle> documentStyle = resolveForDocument(document);
 
-#if PLATFORM(IOS)
         // Inserting the pictograph font at the end of the font fallback list is done by the
         // font selector, so set a font selector if needed.
         if (Settings* settings = document.settings()) {
@@ -799,7 +799,6 @@ void resolveTree(Document& document, Change change)
             if (settings->fontFallbackPrefersPictographs() && styleResolver)
                 documentStyle->font().update(styleResolver->fontSelector());
         }
-#endif
 
         Style::Change documentChange = determineChange(documentStyle.get(), document.renderView()->style(), document.settings());
         if (documentChange != NoChange)
index 51e9929..6c32dff 100644 (file)
@@ -522,4 +522,10 @@ void InternalSettings::setAutoscrollForDragAndDropEnabled(bool enabled, Exceptio
     settings()->setAutoscrollForDragAndDropEnabled(enabled);
 }
 
+void InternalSettings::setFontFallbackPrefersPictographs(bool preferPictographs, ExceptionCode& ec)
+{
+    InternalSettingsGuardForSettings();
+    settings()->setFontFallbackPrefersPictographs(preferPictographs);
+}
+
 }
index a9b39ea..0fa845e 100644 (file)
@@ -135,6 +135,7 @@ public:
     void setTimeWithoutMouseMovementBeforeHidingControls(double time, ExceptionCode&);
     void setUseLegacyBackgroundSizeShorthandBehavior(bool enabled, ExceptionCode&);
     void setAutoscrollForDragAndDropEnabled(bool enabled, ExceptionCode&);
+    void setFontFallbackPrefersPictographs(bool preferPictographs, ExceptionCode&);
 
 private:
     explicit InternalSettings(Page*);
index 4dd1d51..709c11e 100644 (file)
@@ -59,4 +59,5 @@
     [RaisesException] void setTimeWithoutMouseMovementBeforeHidingControls(double time);
     [RaisesException] void setUseLegacyBackgroundSizeShorthandBehavior(boolean enabled);
     [RaisesException] void setAutoscrollForDragAndDropEnabled(boolean enabled);
+    [RaisesException] void setFontFallbackPrefersPictographs(boolean preferPictographs);
 };
index 6c52bac..42dc095 100644 (file)
@@ -1,3 +1,17 @@
+2013-10-10  Andy Estes  <aestes@apple.com>
+
+        Add SPI for telling WebKit to prefer pictograph glyphs over monochrome ones
+        https://bugs.webkit.org/show_bug.cgi?id=122608
+
+        Reviewed by Dan Bernstein.
+
+        Based on patches by Dan Bernstein.
+
+        * WebView/WebView.mm:
+        (-[WebView _setFontFallbackPrefersPictographs:]): Called
+        WebCore::Settings::setFontFallbackPrefersPictographs().
+        * WebView/WebViewPrivate.h:
+
 2013-10-10  Mark Rowe  <mrowe@apple.com>
 
         <rdar://problem/13341666> WebKit should always build against an SDK.
index 3bb1de1..3b80062 100644 (file)
@@ -3154,6 +3154,12 @@ static Vector<String> toStringVector(NSArray* patterns)
     return _private->sourceApplicationAuditData.get();
 }
 
+- (void)_setFontFallbackPrefersPictographs:(BOOL)flag
+{
+    if (_private->page)
+        _private->page->settings().setFontFallbackPrefersPictographs(flag);
+}
+
 @end
 
 @implementation _WebSafeForwarder
index 62dc667..28a4017 100644 (file)
@@ -649,6 +649,8 @@ Could be worth adding to the API.
 
 @property (nonatomic, copy, getter=_sourceApplicationAuditData, setter=_setSourceApplicationAuditData:) NSData *sourceApplicationAuditData;
 
+- (void)_setFontFallbackPrefersPictographs:(BOOL)flag;
+
 @end
 
 @interface WebView (WebViewPrintingPrivate)