W3C home > Mailing lists > Public > www-style@w3.org > September 2012

Re: [css3-fonts] rethinking font load events

From: Tab Atkins Jr. <jackalmage@gmail.com>
Date: Thu, 6 Sep 2012 10:35:20 -0700
Message-ID: <CAAWBYDAGGiOmdvk72=2z8NvsVjpW8TrdzG0OLt7ZVw46w6ObvA@mail.gmail.com>
To: Sebastian Zartner <sebastianzartner@gmail.com>
Cc: John Daggett <jdaggett@mozilla.com>, www-style list <www-style@w3.org>
On Thu, Sep 6, 2012 at 10:03 AM, Sebastian Zartner
<sebastianzartner@gmail.com> wrote:
>> >   // notify completion, even if no fonts load
>> >   void notifyAfterCompletion();
>>
>> I'm fine with things like this (simplifies interaction/API usually),
>> but this is the reason promises are often better than events - you
>> could just hinge some code on the allloaded promise and it'll either
>> run immediately (well, in the next event loop cycle) or be held until
>> the promise actually fulfills.  I wish tc39 would hurry up and decide
>> which flavor of promises they want to bless. :/
>
> If I understand correctly notifyAfterCompletion() "arms"
> document.fontloader again. So the "allcomplete" / "idle" event is
> normally just fired once in the life cycle of a page, right?

No, as far as I understand.  FontLoader can flip between idle and
loading muiltiple times in the page lifecycle, as all the fonts the
page *currently* needs are loaded, then you add more text in a new
font that needs to pull down a new one.

notifyAfterCompletion() just lets you simplify your code a bit - if
you're doing some work that *might* trigger new font downloads, and
want to do something only after the appropriate fonts have loaded, but
you don't want to have to screw around with figuring out whether or
not you *actually* triggered any new font loads, you can just call
notifyAfterCompletion().  If there are pending font loads, it does
nothing; if there aren't, it triggers an "allcomplete" event *anyway*.
 This way, your "only after fonts have loaded" code can just listen
for the allcomplete event and work in both cases.

>> Is that supposed to be the CSSFontFaceRule that actually kicked off
>> the load?  Note that you can't expose that cross-origin.  This also
>> means that to identify the font, you have to write
>> "event.fontface.style.foo".  This is why I flattened the @font-face
>> descriptors onto the event object - much shorter, and no cross-origin
>> issues.
>
> But it also means when the CSSFontFaceRule descriptors get extended
> the event will also have to be adjusted, no?

Yes, it does.  I don't know of any problems with this.

~TJ
Received on Thursday, 6 September 2012 17:36:08 GMT

This archive was generated by hypermail 2.3.1 : Tuesday, 26 March 2013 17:20:59 GMT