<rdar://problem/9215280> Detached canvas draws with incorrect font
authormitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Apr 2011 06:29:26 +0000 (06:29 +0000)
committermitz@apple.com <mitz@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 10 Apr 2011 06:29:26 +0000 (06:29 +0000)
commitd6c8a2e2cf75234e405839ae0de1d6732e4a1d78
tree7381435aceb287287a23d09258d8451ea78c3e40
parent4a0acc3185dc3baf05bf06b3ad285353b66c3c4a
<rdar://problem/9215280> Detached canvas draws with incorrect font

Reviewed by Beth Dakin.

Source/WebCore:

Test: fast/canvas/font-update.html

The existing mechanism for updating the font in a canvas 2D context was lacking in at least
two ways: it neglected to update fonts in all but the topmost state in the stack, and since it
was based on HTMLCanvasElemen's attach() and recalcStyle(), it did not work when the element
was not attached.

This change takes the responsibility for font updates away from the canvas element and gives it
to the canvas context and its graphics state.

* css/CSSFontSelector.cpp:
(WebCore::CSSFontSelector::registerForInvalidationCallbacks): Added. Adds to the set of registered
font selector clients.
(WebCore::CSSFontSelector::unregisterForInvalidationCallbacks): Added. Removes from the set of
registered font selector clients.
(WebCore::CSSFontSelector::dispatchInvalidationCallbacks): Calls fontsNeedUpdate() on all registered
clients and forces a style recalc on the document.
(WebCore::CSSFontSelector::fontLoaded): Changed to call dispatchInvalidationCallbacks().
(WebCore::CSSFontSelector::fontCacheInvalidated): Ditto.
* css/CSSFontSelector.h:
* html/HTMLCanvasElement.cpp: Removed overrides of attach() and recalcStyle().
* html/HTMLCanvasElement.h:
* html/canvas/CanvasRenderingContext2D.cpp:
(WebCore::CanvasRenderingContext2D::State::~State): Added. Unregisters with the font selector.
(WebCore::CanvasRenderingContext2D::State::fontsNeedUpdate): Added. Called by the font selector
when its fonts need to be updated. Updates the font.
(WebCore::CanvasRenderingContext2D::setFont): Registers the state with the font selector.
* html/canvas/CanvasRenderingContext2D.h:
* platform/graphics/FontSelector.h:
(WebCore::FontSelectorClient::~FontSelectorClient):

LayoutTests:

* fast/canvas/font-update-expected.checksum: Added.
* fast/canvas/font-update-expected.png: Added.
* fast/canvas/font-update-expected.txt: Added.
* fast/canvas/font-update.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@83396 268f45cc-cd09-0410-ab3c-d52691b4dbfc
13 files changed:
LayoutTests/ChangeLog
LayoutTests/fast/canvas/font-update-expected.checksum [new file with mode: 0644]
LayoutTests/fast/canvas/font-update-expected.png [new file with mode: 0644]
LayoutTests/fast/canvas/font-update-expected.txt [new file with mode: 0644]
LayoutTests/fast/canvas/font-update.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontSelector.cpp
Source/WebCore/css/CSSFontSelector.h
Source/WebCore/html/HTMLCanvasElement.cpp
Source/WebCore/html/HTMLCanvasElement.h
Source/WebCore/html/canvas/CanvasRenderingContext2D.cpp
Source/WebCore/html/canvas/CanvasRenderingContext2D.h
Source/WebCore/platform/graphics/FontSelector.h