- Revision
- 109700
- Author
- [email protected]
- Date
- 2012-03-04 19:44:45 -0800 (Sun, 04 Mar 2012)
Log Message
Merge 108574 - REGRESSION (r104060): Web font is not loaded if specified by link element dynamically inserted
https://bugs.webkit.org/show_bug.cgi?id=79186
Reviewed by Andreas Kling.
Source/WebCore:
Test: fast/css/font-face-insert-link.html
If a dynamically inserted stylesheet contains @font-face rules, we may fail to update the rendering.
Before r104060 the style selector was destroyed on every style change, and the font selector along with it.
This is no longer the case and we can't rely on comparing font selector pointers when comparing Fonts
for equality. This patch adds version number to the font selector and checks it in Font::operator==.
The version number is incremented when new font-face rules are added to the font selector.
FontFallbackList is an object shared between Fonts so the extra field shouldn't matter much in terms
of memory.
* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::CSSFontSelector):
(WebCore::CSSFontSelector::addFontFaceRule):
* css/CSSFontSelector.h:
(CSSFontSelector):
* platform/graphics/Font.cpp:
(WebCore::Font::operator==):
* platform/graphics/FontFallbackList.cpp:
(WebCore::FontFallbackList::FontFallbackList):
(WebCore::FontFallbackList::invalidate):
* platform/graphics/FontFallbackList.h:
(FontFallbackList):
(WebCore::FontFallbackList::fontSelectorVersion):
* platform/graphics/FontSelector.h:
(FontSelector):
LayoutTests:
* fast/css/font-face-insert-link-expected.txt: Added.
* fast/css/font-face-insert-link.html: Added.
* fast/css/resources/ahem.css: Added.
(@font-face):
[email protected]
Review URL: https://chromiumcodereview.appspot.com/9595009
Modified Paths
Added Paths
Diff
Copied: branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link-expected.txt (from rev 108574, trunk/LayoutTests/fast/css/font-face-insert-link-expected.txt) (0 => 109700)
--- branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link-expected.txt (rev 0)
+++ branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link-expected.txt 2012-03-05 03:44:45 UTC (rev 109700)
@@ -0,0 +1,5 @@
+PASS window.getComputedStyle(a).width == window.getComputedStyle(b).width is false
+PASS successfullyParsed is true
+
+TEST COMPLETE
+TextText
Copied: branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link.html (from rev 108574, trunk/LayoutTests/fast/css/font-face-insert-link.html) (0 => 109700)
--- branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link.html (rev 0)
+++ branches/chromium/1025/LayoutTests/fast/css/font-face-insert-link.html 2012-03-05 03:44:45 UTC (rev 109700)
@@ -0,0 +1,39 @@
+<head>
+<script src=""
+<style>
+.test {
+ font-family: 'myahem';
+}
+#a, #b, #container { position:absolute; }
+#b { top: 20px }
+</style>
+</head>
+
+<div id=container>
+<div id=a>Text</div>
+<div id=b class="test">Text</div>
+</div>
+
+<script>
+jsTestIsAsync = true;
+
+window.setTimeout(
+ function() {
+ var link = document.createElement("link");
+ link.setAttribute("href", "resources/ahem.css");
+ link.setAttribute("rel", "stylesheet");
+ link.setAttribute("type", "text/css");
+ document.head.appendChild(link);
+ window.setTimeout(
+ function() {
+ var a = document.getElementById('a');
+ var b = document.getElementById('b');
+ shouldBeFalse('window.getComputedStyle(a).width == window.getComputedStyle(b).width');
+ finishJSTest();
+ },
+ 500
+ );
+ },
+ 1);
+</script>
+<script src=""
Copied: branches/chromium/1025/LayoutTests/fast/css/resources/ahem.css (from rev 108574, trunk/LayoutTests/fast/css/resources/ahem.css) (0 => 109700)
--- branches/chromium/1025/LayoutTests/fast/css/resources/ahem.css (rev 0)
+++ branches/chromium/1025/LayoutTests/fast/css/resources/ahem.css 2012-03-05 03:44:45 UTC (rev 109700)
@@ -0,0 +1,4 @@
+@font-face {
+ font-family: 'myahem';
+ src: url(../../../resources/Ahem.ttf);
+}
Modified: branches/chromium/1025/Source/WebCore/css/CSSFontSelector.cpp (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/css/CSSFontSelector.cpp 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/css/CSSFontSelector.cpp 2012-03-05 03:44:45 UTC (rev 109700)
@@ -63,6 +63,7 @@
CSSFontSelector::CSSFontSelector(Document* document)
: m_document(document)
, m_beginLoadingTimer(this, &CSSFontSelector::beginLoadTimerFired)
+ , m_version(0)
{
// FIXME: An old comment used to say there was no need to hold a reference to m_document
// because "we are guaranteed to be destroyed before the document". But there does not
@@ -341,6 +342,8 @@
}
familyFontFaces->append(fontFace);
+
+ ++m_version;
}
}
Modified: branches/chromium/1025/Source/WebCore/css/CSSFontSelector.h (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/css/CSSFontSelector.h 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/css/CSSFontSelector.h 2012-03-05 03:44:45 UTC (rev 109700)
@@ -51,6 +51,8 @@
return adoptRef(new CSSFontSelector(document));
}
virtual ~CSSFontSelector();
+
+ virtual unsigned version() const OVERRIDE { return m_version; }
virtual FontData* getFontData(const FontDescription& fontDescription, const AtomicString& familyName);
@@ -85,6 +87,8 @@
Vector<CachedResourceHandle<CachedFont> > m_fontsToBeginLoading;
Timer<CSSFontSelector> m_beginLoadingTimer;
+
+ unsigned m_version;
};
} // namespace WebCore
Modified: branches/chromium/1025/Source/WebCore/platform/graphics/Font.cpp (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/platform/graphics/Font.cpp 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/platform/graphics/Font.cpp 2012-03-05 03:44:45 UTC (rev 109700)
@@ -120,11 +120,12 @@
FontSelector* first = m_fontList ? m_fontList->fontSelector() : 0;
FontSelector* second = other.m_fontList ? other.m_fontList->fontSelector() : 0;
-
+
return first == second
&& m_fontDescription == other.m_fontDescription
&& m_letterSpacing == other.m_letterSpacing
&& m_wordSpacing == other.m_wordSpacing
+ && (m_fontList ? m_fontList->fontSelectorVersion() : 0) == (other.m_fontList ? other.m_fontList->fontSelectorVersion() : 0)
&& (m_fontList ? m_fontList->generation() : 0) == (other.m_fontList ? other.m_fontList->generation() : 0);
}
Modified: branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.cpp (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.cpp 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.cpp 2012-03-05 03:44:45 UTC (rev 109700)
@@ -39,6 +39,7 @@
: m_pageZero(0)
, m_cachedPrimarySimpleFontData(0)
, m_fontSelector(0)
+ , m_fontSelectorVersion(0)
, m_familyIndex(0)
, m_generation(fontCache()->generation())
, m_pitch(UnknownPitch)
@@ -57,6 +58,7 @@
m_pitch = UnknownPitch;
m_loadingCustomFonts = false;
m_fontSelector = fontSelector;
+ m_fontSelectorVersion = m_fontSelector ? m_fontSelector->version() : 0;
m_generation = fontCache()->generation();
}
Modified: branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.h (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.h 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/platform/graphics/FontFallbackList.h 2012-03-05 03:44:45 UTC (rev 109700)
@@ -51,6 +51,8 @@
bool loadingCustomFonts() const { return m_loadingCustomFonts; }
FontSelector* fontSelector() const { return m_fontSelector.get(); }
+ // FIXME: It should be possible to combine fontSelectorVersion and generation.
+ unsigned fontSelectorVersion() const { return m_fontSelectorVersion; }
unsigned generation() const { return m_generation; }
struct GlyphPagesHashTraits : HashTraits<int> {
@@ -87,6 +89,7 @@
mutable GlyphPageTreeNode* m_pageZero;
mutable const SimpleFontData* m_cachedPrimarySimpleFontData;
RefPtr<FontSelector> m_fontSelector;
+ unsigned m_fontSelectorVersion;
mutable int m_familyIndex;
unsigned short m_generation;
mutable unsigned m_pitch : 3; // Pitch
Modified: branches/chromium/1025/Source/WebCore/platform/graphics/FontSelector.h (109699 => 109700)
--- branches/chromium/1025/Source/WebCore/platform/graphics/FontSelector.h 2012-03-05 03:38:58 UTC (rev 109699)
+++ branches/chromium/1025/Source/WebCore/platform/graphics/FontSelector.h 2012-03-05 03:44:45 UTC (rev 109700)
@@ -44,6 +44,8 @@
virtual void registerForInvalidationCallbacks(FontSelectorClient*) = 0;
virtual void unregisterForInvalidationCallbacks(FontSelectorClient*) = 0;
+
+ virtual unsigned version() const = 0;
};
class FontSelectorClient {