Question about StyleEngine and when StyleEngine::ApplyRuleSetChanges gets called

7 views
Skip to first unread message

Alex Clarke

unread,
Sep 19, 2017, 11:48:10 AM9/19/17
to blink-dev
In the context of a headless browser, I'm trying to solve a problem with VirtualTime and StyleEngine.  Suppose a page has an onload handler which adds a stylesheet with a webfont.  Lets say we've turned on Virtual time with policy VirtualTimePolicy::DETERMINISTIC_LOADING.  Virtual time is not supposed to advance while there are network fetches pending.

Unfortunately after the document has finished loading there's a gap between the stylesheet getting loaded and StyleEngine::ApplyRuleSetChanges getting called which triggers the load of the webfont, during which virtual time can advance when it probably shouldn't.

I'm thinking of wiring up a signal to the WebFrameScheduler to tell it about dirty styles, and I'm wondering if this can be really simple or of I need to do something more complex.
Specifically if StyleEngine::MarkDocumentDirty told WebFrameScheduler it was dirty and if StyleEngine::ApplyRuleSetChanges and StyleEngine::~StyleEngine cleared the bit would that work?   The thing I;m worried about is  there might be something that defers calling StyleEngine::ApplyRuleSetChanges which might cause virtual time to stall forever.

Does Blink try to be smart about when StyleEngine::ApplyRuleSetChanges  is called?

Thanks!
Alex Clarke

Rune Lillesveen

unread,
Sep 19, 2017, 7:16:30 PM9/19/17
to Alex Clarke, blink-dev
I'm not familiar with VirtualTime.

Like other style changes, ApplyRuleSetChanges() is called as part of UpdateActiveStyle() which is called from Document::UpdateStyleAndLayoutTree() as part of the whole lifecycle update when we generate a frame [1]. The frame is triggered by a ScheduleVisualUpdate() like we do for other style and layout changes.

Similarly, it can be forced by accessing an API where the style/layout has to be up-to-date just like we do for getComputedStyle(), offsetTop, etc.

Strictly speaking StyleEngine::ApplyRuleSetChanges does not trigger webfont loading. ApplyRuleSetChanges marks elements for style invalidation/recalc when adding @font-face rules and it's the subsequent UpdateStyle() which triggers web font loading.


-- 
Rune Lillesveen

Alex Clarke

unread,
Sep 20, 2017, 10:19:58 AM9/20/17
to Rune Lillesveen, blink-dev
Thanks for the background information, very useful. Hopefully I'll be able to figure out what hooks are needed.
Reply all
Reply to author
Forward
0 new messages