Changeset 83396 in webkit
- Timestamp:
- Apr 9, 2011 11:29:26 PM (13 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r83393 r83396 1 2011-04-09 Dan Bernstein <mitz@apple.com> 2 3 Reviewed by Beth Dakin. 4 5 <rdar://problem/9215280> Detached canvas draws with incorrect font 6 7 * fast/canvas/font-update-expected.checksum: Added. 8 * fast/canvas/font-update-expected.png: Added. 9 * fast/canvas/font-update-expected.txt: Added. 10 * fast/canvas/font-update.html: Added. 11 1 12 2011-04-09 Dirk Pranke <dpranke@chromium.org> 2 13 -
trunk/Source/WebCore/ChangeLog
r83392 r83396 1 2011-04-09 Dan Bernstein <mitz@apple.com> 2 3 Reviewed by Beth Dakin. 4 5 <rdar://problem/9215280> Detached canvas draws with incorrect font 6 7 Test: fast/canvas/font-update.html 8 9 The existing mechanism for updating the font in a canvas 2D context was lacking in at least 10 two ways: it neglected to update fonts in all but the topmost state in the stack, and since it 11 was based on HTMLCanvasElemen's attach() and recalcStyle(), it did not work when the element 12 was not attached. 13 14 This change takes the responsibility for font updates away from the canvas element and gives it 15 to the canvas context and its graphics state. 16 17 * css/CSSFontSelector.cpp: 18 (WebCore::CSSFontSelector::registerForInvalidationCallbacks): Added. Adds to the set of registered 19 font selector clients. 20 (WebCore::CSSFontSelector::unregisterForInvalidationCallbacks): Added. Removes from the set of 21 registered font selector clients. 22 (WebCore::CSSFontSelector::dispatchInvalidationCallbacks): Calls fontsNeedUpdate() on all registered 23 clients and forces a style recalc on the document. 24 (WebCore::CSSFontSelector::fontLoaded): Changed to call dispatchInvalidationCallbacks(). 25 (WebCore::CSSFontSelector::fontCacheInvalidated): Ditto. 26 * css/CSSFontSelector.h: 27 * html/HTMLCanvasElement.cpp: Removed overrides of attach() and recalcStyle(). 28 * html/HTMLCanvasElement.h: 29 * html/canvas/CanvasRenderingContext2D.cpp: 30 (WebCore::CanvasRenderingContext2D::State::~State): Added. Unregisters with the font selector. 31 (WebCore::CanvasRenderingContext2D::State::fontsNeedUpdate): Added. Called by the font selector 32 when its fonts need to be updated. Updates the font. 33 (WebCore::CanvasRenderingContext2D::setFont): Registers the state with the font selector. 34 * html/canvas/CanvasRenderingContext2D.h: 35 * platform/graphics/FontSelector.h: 36 (WebCore::FontSelectorClient::~FontSelectorClient): 37 1 38 2011-04-09 Geoffrey Garen <ggaren@apple.com> 2 39 -
trunk/Source/WebCore/css/CSSFontSelector.cpp
r72056 r83396 346 346 } 347 347 348 void CSSFontSelector::fontLoaded() 349 { 348 void CSSFontSelector::registerForInvalidationCallbacks(FontSelectorClient* client) 349 { 350 m_clients.add(client); 351 } 352 353 void CSSFontSelector::unregisterForInvalidationCallbacks(FontSelectorClient* client) 354 { 355 m_clients.remove(client); 356 } 357 358 void CSSFontSelector::dispatchInvalidationCallbacks() 359 { 360 Vector<FontSelectorClient*> clients; 361 copyToVector(m_clients, clients); 362 for (size_t i = 0; i < clients.size(); ++i) 363 clients[i]->fontsNeedUpdate(this); 364 365 // FIXME: Make Document a FontSelectorClient so that it can simply register for invalidation callbacks. 350 366 if (!m_document || m_document->inPageCache() || !m_document->renderer()) 351 367 return; … … 353 369 } 354 370 371 void CSSFontSelector::fontLoaded() 372 { 373 dispatchInvalidationCallbacks(); 374 } 375 355 376 void CSSFontSelector::fontCacheInvalidated() 356 377 { 357 if (!m_document || m_document->inPageCache() || !m_document->renderer()) 358 return; 359 m_document->scheduleForcedStyleRecalc(); 378 dispatchInvalidationCallbacks(); 360 379 } 361 380 -
trunk/Source/WebCore/css/CSSFontSelector.h
r66963 r83396 30 30 #include <wtf/Forward.h> 31 31 #include <wtf/HashMap.h> 32 #include <wtf/HashSet.h> 32 33 #include <wtf/RefPtr.h> 33 34 #include <wtf/text/StringHash.h> … … 63 64 CachedResourceLoader* cachedResourceLoader() const; 64 65 66 virtual void registerForInvalidationCallbacks(FontSelectorClient*); 67 virtual void unregisterForInvalidationCallbacks(FontSelectorClient*); 68 65 69 private: 66 70 CSSFontSelector(Document*); 71 72 void dispatchInvalidationCallbacks(); 67 73 68 74 Document* m_document; … … 70 76 HashMap<String, Vector<RefPtr<CSSFontFace> >*, CaseFoldingHash> m_locallyInstalledFontFaces; 71 77 HashMap<String, HashMap<unsigned, RefPtr<CSSSegmentedFontFace> >*, CaseFoldingHash> m_fonts; 78 HashSet<FontSelectorClient*> m_clients; 72 79 }; 73 80 -
trunk/Source/WebCore/html/HTMLCanvasElement.cpp
r82878 r83396 319 319 } 320 320 321 void HTMLCanvasElement::attach()322 {323 HTMLElement::attach();324 325 if (m_context && m_context->is2d()) {326 CanvasRenderingContext2D* ctx = static_cast<CanvasRenderingContext2D*>(m_context.get());327 ctx->updateFont();328 }329 }330 331 void HTMLCanvasElement::recalcStyle(StyleChange change)332 {333 HTMLElement::recalcStyle(change);334 335 // Update font if needed.336 if (change == Force && m_context && m_context->is2d()) {337 CanvasRenderingContext2D* ctx = static_cast<CanvasRenderingContext2D*>(m_context.get());338 ctx->updateFont();339 }340 }341 342 321 void HTMLCanvasElement::setSurfaceSize(const IntSize& size) 343 322 { -
trunk/Source/WebCore/html/HTMLCanvasElement.h
r81740 r83396 135 135 virtual RenderObject* createRenderer(RenderArena*, RenderStyle*); 136 136 137 virtual void attach();138 139 virtual void recalcStyle(StyleChange);140 141 137 void reset(); 142 138 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
r83355 r83396 214 214 } 215 215 216 CanvasRenderingContext2D::State::~State() 217 { 218 if (m_realizedFont) 219 m_font.fontSelector()->unregisterForInvalidationCallbacks(this); 220 } 221 222 void CanvasRenderingContext2D::State::fontsNeedUpdate(FontSelector* fontSelector) 223 { 224 ASSERT_ARG(fontSelector, fontSelector == m_font.fontSelector()); 225 ASSERT(m_realizedFont); 226 227 m_font.update(fontSelector); 228 } 229 216 230 void CanvasRenderingContext2D::save() 217 231 { … … 1691 1705 state().m_font.update(styleSelector->fontSelector()); 1692 1706 state().m_realizedFont = true; 1693 } 1694 1695 void CanvasRenderingContext2D::updateFont() 1696 { 1697 if (!state().m_realizedFont) 1698 return; 1699 1700 const Font& font = state().m_font; 1701 font.update(font.fontSelector()); 1707 styleSelector->fontSelector()->registerForInvalidationCallbacks(&state()); 1702 1708 } 1703 1709 -
trunk/Source/WebCore/html/canvas/CanvasRenderingContext2D.h
r75160 r83396 205 205 String font() const; 206 206 void setFont(const String&); 207 void updateFont();208 207 209 208 String textAlign() const; … … 229 228 230 229 private: 231 struct State {230 struct State : FontSelectorClient { 232 231 State(); 232 virtual ~State(); 233 234 virtual void fontsNeedUpdate(FontSelector*); 233 235 234 236 String m_unparsedStrokeColor; -
trunk/Source/WebCore/platform/graphics/FontSelector.h
r65021 r83396 34 34 class FontData; 35 35 class FontDescription; 36 class FontSelectorClient; 36 37 37 38 class FontSelector : public RefCounted<FontSelector> { … … 41 42 42 43 virtual void fontCacheInvalidated() { } 44 45 virtual void registerForInvalidationCallbacks(FontSelectorClient*) = 0; 46 virtual void unregisterForInvalidationCallbacks(FontSelectorClient*) = 0; 47 }; 48 49 class FontSelectorClient { 50 public: 51 virtual ~FontSelectorClient() { } 52 53 virtual void fontsNeedUpdate(FontSelector*) = 0; 43 54 }; 44 55
Note: See TracChangeset
for help on using the changeset viewer.