Changeset 213515 in webkit


Ignore:
Timestamp:
Mar 7, 2017, 8:54:56 AM (8 years ago)
Author:
Antti Koivisto
Message:

Differentiate between pending head and body stylesheets in Style::Scope
https://bugs.webkit.org/show_bug.cgi?id=169277

Reviewed by Andreas Kling.

Split pending stylesheet node set into separate sets for head and body elements and processing instructions.

This tightens typing and will also be useful later.

  • style/StyleScope.cpp:

(WebCore::Style::Scope::~Scope):
(WebCore::Style::Scope::addPendingSheet):
(WebCore::Style::Scope::removePendingSheet):
(WebCore::Style::Scope::didRemovePendingStylesheet):
(WebCore::Style::Scope::hasPendingSheet):
(WebCore::Style::Scope::hasPendingSheetInBody):
(WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet): Deleted.

  • style/StyleScope.h:

(WebCore::Style::Scope::hasPendingSheet): Deleted.
(WebCore::Style::Scope::hasPendingSheets): Deleted.

  • style/StyleTreeResolver.cpp:

(WebCore::Style::hasLoadingStylesheet):

Just test for body stylesheets.

(WebCore::Style::TreeResolver::resolve):

Treat all before-body stylesheets uniformly.

Location:
trunk/Source/WebCore
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r213514 r213515  
     12017-03-07  Antti Koivisto  <antti@apple.com>
     2
     3        Differentiate between pending head and body stylesheets in Style::Scope
     4        https://bugs.webkit.org/show_bug.cgi?id=169277
     5
     6        Reviewed by Andreas Kling.
     7
     8        Split pending stylesheet node set into separate sets for head and body elements and processing instructions.
     9
     10        This tightens typing and will also be useful later.
     11
     12        * style/StyleScope.cpp:
     13        (WebCore::Style::Scope::~Scope):
     14        (WebCore::Style::Scope::addPendingSheet):
     15        (WebCore::Style::Scope::removePendingSheet):
     16        (WebCore::Style::Scope::didRemovePendingStylesheet):
     17        (WebCore::Style::Scope::hasPendingSheet):
     18        (WebCore::Style::Scope::hasPendingSheetInBody):
     19        (WebCore::Style::Scope::hasProcessingInstructionWithPendingSheet): Deleted.
     20        * style/StyleScope.h:
     21        (WebCore::Style::Scope::hasPendingSheet): Deleted.
     22        (WebCore::Style::Scope::hasPendingSheets): Deleted.
     23        * style/StyleTreeResolver.cpp:
     24        (WebCore::Style::hasLoadingStylesheet):
     25
     26            Just test for body stylesheets.
     27
     28        (WebCore::Style::TreeResolver::resolve):
     29
     30            Treat all before-body stylesheets uniformly.
     31
    1322017-03-07  Antoine Quint  <graouts@apple.com>
    233
  • trunk/Source/WebCore/style/StyleScope.cpp

    r213446 r213515  
    3333#include "ElementChildIterator.h"
    3434#include "ExtensionStyleSheets.h"
     35#include "HTMLHeadElement.h"
    3536#include "HTMLIFrameElement.h"
    3637#include "HTMLLinkElement.h"
     
    7374Scope::~Scope()
    7475{
    75     ASSERT(m_nodesWithPendingSheets.isEmpty());
     76    ASSERT(!hasPendingSheets());
    7677}
    7778
     
    173174}
    174175
    175 void Scope::addPendingSheet(const Node& node)
    176 {
    177     ASSERT(!m_nodesWithPendingSheets.contains(&node));
    178 
    179     m_nodesWithPendingSheets.add(&node);
     176
     177void Scope::addPendingSheet(const Element& element)
     178{
     179    ASSERT(!hasPendingSheet(element));
     180
     181    bool isInHead = ancestorsOfType<HTMLHeadElement>(element).first();
     182    if (isInHead)
     183        m_elementsInHeadWithPendingSheets.add(&element);
     184    else
     185        m_elementsInBodyWithPendingSheets.add(&element);
    180186}
    181187
    182188// This method is called whenever a top-level stylesheet has finished loading.
    183 void Scope::removePendingSheet(const Node& node)
    184 {
    185     ASSERT(m_nodesWithPendingSheets.contains(&node));
    186 
    187     m_nodesWithPendingSheets.remove(&node);
    188     if (!m_nodesWithPendingSheets.isEmpty())
     189void Scope::removePendingSheet(const Element& element)
     190{
     191    ASSERT(hasPendingSheet(element));
     192
     193    if (!m_elementsInHeadWithPendingSheets.remove(&element))
     194        m_elementsInBodyWithPendingSheets.remove(&element);
     195
     196    didRemovePendingStylesheet();
     197}
     198
     199void Scope::addPendingSheet(const ProcessingInstruction& processingInstruction)
     200{
     201    ASSERT(!m_processingInstructionsWithPendingSheets.contains(&processingInstruction));
     202
     203    m_processingInstructionsWithPendingSheets.add(&processingInstruction);
     204}
     205
     206void Scope::removePendingSheet(const ProcessingInstruction& processingInstruction)
     207{
     208    ASSERT(m_processingInstructionsWithPendingSheets.contains(&processingInstruction));
     209
     210    m_processingInstructionsWithPendingSheets.remove(&processingInstruction);
     211
     212    didRemovePendingStylesheet();
     213}
     214
     215void Scope::didRemovePendingStylesheet()
     216{
     217    if (hasPendingSheets())
    189218        return;
    190219
     
    195224}
    196225
    197 bool Scope::hasProcessingInstructionWithPendingSheet()
    198 {
    199     ASSERT(!m_shadowRoot);
    200 
    201     for (auto* child = m_document.firstChild(); child; child = child->nextSibling()) {
    202         if (is<Element>(*child))
    203             return false;
    204         if (m_nodesWithPendingSheets.contains(child)) {
    205             ASSERT(is<ProcessingInstruction>(*child));
    206             return true;
    207         }
    208     }
    209     return false;
     226bool Scope::hasPendingSheet(const Element& element) const
     227{
     228    return m_elementsInHeadWithPendingSheets.contains(&element) || hasPendingSheetInBody(element);
     229}
     230
     231bool Scope::hasPendingSheetInBody(const Element& element) const
     232{
     233    return m_elementsInBodyWithPendingSheets.contains(&element);
    210234}
    211235
  • trunk/Source/WebCore/style/StyleScope.h

    r213446 r213515  
    4444class Element;
    4545class Node;
     46class ProcessingInstruction;
    4647class StyleResolver;
    4748class StyleSheet;
     
    8384    void setSelectedStylesheetSetName(const String&);
    8485
    85     void addPendingSheet(const Node&);
    86     void removePendingSheet(const Node&);
    87     bool hasPendingSheet(const Node& node) const { return m_nodesWithPendingSheets.contains(&node); }
    88     bool hasProcessingInstructionWithPendingSheet();
    89     bool hasPendingSheets() const { return !m_nodesWithPendingSheets.isEmpty(); }
     86    void addPendingSheet(const Element&);
     87    void removePendingSheet(const Element&);
     88    void addPendingSheet(const ProcessingInstruction&);
     89    void removePendingSheet(const ProcessingInstruction&);
     90    bool hasPendingSheets() const;
     91    bool hasPendingSheetsBeforeBody() const;
     92    bool hasPendingSheetsInBody() const;
     93    bool hasPendingSheet(const Element&) const;
     94    bool hasPendingSheetInBody(const Element&) const;
    9095
    9196    bool usesStyleBasedEditability() { return m_usesStyleBasedEditability; }
     
    116121    bool shouldUseSharedUserAgentShadowTreeStyleResolver() const;
    117122
     123    void didRemovePendingStylesheet();
     124
    118125    enum class UpdateType { ActiveSet, ContentsOrInterpretation };
    119126    void updateActiveStyleSheets(UpdateType);
     
    144151    Vector<RefPtr<CSSStyleSheet>> m_activeStyleSheets;
    145152
    146 
    147153    Timer m_pendingUpdateTimer;
    148154
     
    153159    // We use this count of pending sheets to detect when we can begin attaching
    154160    // elements and when it is safe to execute scripts.
    155     HashSet<const Node*> m_nodesWithPendingSheets;
     161    HashSet<const ProcessingInstruction*> m_processingInstructionsWithPendingSheets;
     162    HashSet<const Element*> m_elementsInHeadWithPendingSheets;
     163    HashSet<const Element*> m_elementsInBodyWithPendingSheets;
    156164
    157165    bool m_didUpdateActiveStyleSheets { false };
     
    168176    bool m_isUpdatingStyleResolver { false };
    169177};
     178
     179inline bool Scope::hasPendingSheets() const
     180{
     181    return hasPendingSheetsBeforeBody() || !m_elementsInBodyWithPendingSheets.isEmpty();
     182}
     183
     184inline bool Scope::hasPendingSheetsBeforeBody() const
     185{
     186    return !m_elementsInHeadWithPendingSheets.isEmpty() || !m_processingInstructionsWithPendingSheets.isEmpty();
     187}
     188
     189inline bool Scope::hasPendingSheetsInBody() const
     190{
     191    return !m_elementsInBodyWithPendingSheets.isEmpty();
     192}
    170193
    171194inline void Scope::flushPendingUpdate()
  • trunk/Source/WebCore/style/StyleTreeResolver.cpp

    r213446 r213515  
    362362static bool hasLoadingStylesheet(const Style::Scope& styleScope, const Element& element, bool checkDescendants)
    363363{
    364     if (!styleScope.hasPendingSheets())
     364    if (!styleScope.hasPendingSheetsInBody())
    365365        return false;
    366     if (styleScope.hasPendingSheet(element))
     366    if (styleScope.hasPendingSheetInBody(element))
    367367        return true;
    368368    if (!checkDescendants)
    369369        return false;
    370370    for (auto& descendant : descendantsOfType<Element>(element)) {
    371         if (styleScope.hasPendingSheet(descendant))
     371        if (styleScope.hasPendingSheetInBody(descendant))
    372372            return true;
    373373    };
     
    483483        return nullptr;
    484484
    485     m_didSeePendingStylesheet = m_document.styleScope().hasProcessingInstructionWithPendingSheet();
     485    m_didSeePendingStylesheet = m_document.styleScope().hasPendingSheetsBeforeBody();
    486486
    487487    m_update = std::make_unique<Update>(m_document);
Note: See TracChangeset for help on using the changeset viewer.