Changeset 270886 in webkit


Ignore:
Timestamp:
Dec 16, 2020 4:55:09 AM (3 years ago)
Author:
Antti Koivisto
Message:

Remove simpleUserAgentStyleSheet (to fix flaky fast/lists/001.html and fast/lists/001-vertical.html)
https://bugs.webkit.org/show_bug.cgi?id=218995
<rdar://problem/71452387>

Reviewed by Antoine Quint.

Source/WebCore:

The simpleUserAgentStyleSheet optimization allows WebKit to load a very simple version of the user agent
stylesheet as long as the document is very simple too (mostly just <div>/<span>). It was implemented
to support certain non-web use cases a long time ago when the cost of simply parsing the main stylesheet was
significant.

It can cause problems like seen here when it is not fully in-sync with the real stylesheet. The ways it may be out
of sync can be pretty obscure.

The optimization hasn't been useful for a while now. Let's just remove it instead of continuing fix problems caused by it.

  • page/ProcessWarming.cpp:

(WebCore::ProcessWarming::prewarmGlobally):

  • style/ElementRuleCollector.cpp:

(WebCore::Style::ElementRuleCollector::matchUARules):

  • style/InspectorCSSOMWrappers.cpp:

(WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):

  • style/StyleResolver.cpp:

(WebCore::Style::Resolver::Resolver):

  • style/UserAgentStyle.cpp:

(WebCore::Style::UserAgentStyle::initDefaultStyleSheet):
(WebCore::Style::UserAgentStyle::ensureDefaultStyleSheetsForElement):
(WebCore::Style::elementCanUseSimpleDefaultStyle): Deleted.
(WebCore::Style::UserAgentStyle::initDefaultStyle): Deleted.
(WebCore::Style::UserAgentStyle::loadFullDefaultStyle): Deleted.
(WebCore::Style::UserAgentStyle::loadSimpleDefaultStyle): Deleted.

  • style/UserAgentStyle.h:

LayoutTests:

  • platform/mac-wk2/TestExpectations:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r270885 r270886  
     12020-12-16  Antti Koivisto  <antti@apple.com>
     2
     3        Remove simpleUserAgentStyleSheet (to fix flaky fast/lists/001.html and fast/lists/001-vertical.html)
     4        https://bugs.webkit.org/show_bug.cgi?id=218995
     5        <rdar://problem/71452387>
     6
     7        Reviewed by Antoine Quint.
     8
     9        * platform/mac-wk2/TestExpectations:
     10
    1112020-12-16  Youenn Fablet  <youenn@apple.com>
    212
  • trunk/LayoutTests/platform/mac-wk2/TestExpectations

    r270823 r270886  
    13171317webkit.org/b/219322 fast/layoutformattingcontext/table-simple-border-collapse.html [ ImageOnlyFailure ]
    13181318webkit.org/b/219322 fast/layoutformattingcontext/table-simple-border-collapse2.html [ ImageOnlyFailure ]
    1319 
    1320 webkit.org/b/218995 fast/lists/001.html [ Skip ]
    1321 webkit.org/b/218995 fast/lists/001-vertical.html [ Skip ]
  • trunk/Source/WebCore/ChangeLog

    r270883 r270886  
     12020-12-16  Antti Koivisto  <antti@apple.com>
     2
     3        Remove simpleUserAgentStyleSheet (to fix flaky fast/lists/001.html and fast/lists/001-vertical.html)
     4        https://bugs.webkit.org/show_bug.cgi?id=218995
     5        <rdar://problem/71452387>
     6
     7        Reviewed by Antoine Quint.
     8
     9        The simpleUserAgentStyleSheet optimization allows WebKit to load a very simple version of the user agent
     10        stylesheet as long as the document is very simple too (mostly just <div>/<span>). It was implemented
     11        to support certain non-web use cases a long time ago when the cost of simply parsing the main stylesheet was
     12        significant.
     13
     14        It can cause problems like seen here when it is not fully in-sync with the real stylesheet. The ways it may be out
     15        of sync can be pretty obscure.
     16
     17        The optimization hasn't been useful for a while now. Let's just remove it instead of continuing fix problems caused by it.
     18
     19        * page/ProcessWarming.cpp:
     20        (WebCore::ProcessWarming::prewarmGlobally):
     21        * style/ElementRuleCollector.cpp:
     22        (WebCore::Style::ElementRuleCollector::matchUARules):
     23        * style/InspectorCSSOMWrappers.cpp:
     24        (WebCore::Style::InspectorCSSOMWrappers::collectDocumentWrappers):
     25        * style/StyleResolver.cpp:
     26        (WebCore::Style::Resolver::Resolver):
     27        * style/UserAgentStyle.cpp:
     28        (WebCore::Style::UserAgentStyle::initDefaultStyleSheet):
     29        (WebCore::Style::UserAgentStyle::ensureDefaultStyleSheetsForElement):
     30        (WebCore::Style::elementCanUseSimpleDefaultStyle): Deleted.
     31        (WebCore::Style::UserAgentStyle::initDefaultStyle): Deleted.
     32        (WebCore::Style::UserAgentStyle::loadFullDefaultStyle): Deleted.
     33        (WebCore::Style::UserAgentStyle::loadSimpleDefaultStyle): Deleted.
     34        * style/UserAgentStyle.h:
     35
    1362020-12-16  Youenn Fablet  <youenn@apple.com>
    237
  • trunk/Source/WebCore/page/ProcessWarming.cpp

    r265418 r270886  
    7373   
    7474    // Prewarms user agent stylesheet.
    75     Style::UserAgentStyle::loadFullDefaultStyle();
     75    Style::UserAgentStyle::initDefaultStyleSheet();
    7676   
    7777    // Prewarms JS VM.
  • trunk/Source/WebCore/style/ElementRuleCollector.cpp

    r269415 r270886  
    386386{
    387387    // First we match rules from the user agent sheet.
    388     if (UserAgentStyle::simpleDefaultStyleSheet)
    389         m_result.isCacheable = false;
    390388    auto* userAgentStyleSheet = m_isPrintStyle
    391389        ? UserAgentStyle::defaultPrintStyle : UserAgentStyle::defaultStyle;
  • trunk/Source/WebCore/style/InspectorCSSOMWrappers.cpp

    r269999 r270886  
    105105{
    106106    if (m_styleRuleToCSSOMWrapperMap.isEmpty()) {
    107         collectFromStyleSheetContents(UserAgentStyle::simpleDefaultStyleSheet);
    108107        collectFromStyleSheetContents(UserAgentStyle::defaultStyleSheet);
    109108        collectFromStyleSheetContents(UserAgentStyle::quirksStyleSheet);
  • trunk/Source/WebCore/style/StyleResolver.cpp

    r267497 r270886  
    9090    , m_matchAuthorAndUserStyles(m_document.settings().authorAndUserStylesEnabled())
    9191{
    92     Element* root = m_document.documentElement();
    93 
    94     UserAgentStyle::initDefaultStyle(root);
     92    UserAgentStyle::initDefaultStyleSheet();
    9593
    9694    // construct document root element default style. this is needed
     
    106104        m_mediaQueryEvaluator = MediaQueryEvaluator { };
    107105
    108     if (root) {
    109         m_rootDefaultStyle = styleForElement(*root, m_document.renderStyle(), nullptr, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
     106    if (auto* documentElement = m_document.documentElement()) {
     107        m_rootDefaultStyle = styleForElement(*documentElement, m_document.renderStyle(), nullptr, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
    110108        // Turn off assertion against font lookups during style resolver initialization. We may need root style font for media queries.
    111109        m_document.fontSelector().incrementIsComputingRootStyleFont();
  • trunk/Source/WebCore/style/UserAgentStyle.cpp

    r270678 r270886  
    6868unsigned UserAgentStyle::defaultStyleVersion;
    6969
    70 StyleSheetContents* UserAgentStyle::simpleDefaultStyleSheet;
    7170StyleSheetContents* UserAgentStyle::defaultStyleSheet;
    7271StyleSheetContents* UserAgentStyle::quirksStyleSheet;
     
    8988#endif
    9089
    91 #if PLATFORM(IOS_FAMILY)
    92 #define DEFAULT_OUTLINE_WIDTH "3px"
    93 #else
    94 #define DEFAULT_OUTLINE_WIDTH "5px"
    95 #endif
    96 
    97 #if HAVE(OS_DARK_MODE_SUPPORT)
    98 #define CSS_DARK_MODE_ADDITION "html{color:text}"
    99 #else
    100 #define CSS_DARK_MODE_ADDITION ""
    101 #endif
    102 
    103 // FIXME: It would be nice to use some mechanism that guarantees this is in sync with the real UA stylesheet.
    104 static const char simpleUserAgentStyleSheet[] = "html,body,div{display:block}" CSS_DARK_MODE_ADDITION "head{display:none}body{margin:8px}div:focus,span:focus,a:focus{outline:auto " DEFAULT_OUTLINE_WIDTH " -webkit-focus-ring-color}a:any-link{color:-webkit-link;text-decoration:underline}a:any-link:active{color:-webkit-activelink}";
    105 
    106 static inline bool elementCanUseSimpleDefaultStyle(const Element& element)
    107 {
    108     return is<HTMLHtmlElement>(element) || is<HTMLHeadElement>(element)
    109         || is<HTMLBodyElement>(element) || is<HTMLDivElement>(element)
    110         || is<HTMLSpanElement>(element) || is<HTMLBRElement>(element)
    111         || is<HTMLAnchorElement>(element);
    112 }
    113 
    11490static const MediaQueryEvaluator& screenEval()
    11591{
     
    134110{
    135111    return parseUASheet(String(characters, size));
    136 }
    137 
    138 void UserAgentStyle::initDefaultStyle(const Element* root)
    139 {
    140     if (!defaultStyle) {
    141         if (!root || elementCanUseSimpleDefaultStyle(*root))
    142             loadSimpleDefaultStyle();
    143         else
    144             loadFullDefaultStyle();
    145     }
    146112}
    147113
     
    168134}
    169135
    170 void UserAgentStyle::loadFullDefaultStyle()
    171 {
    172     if (defaultStyle && !simpleDefaultStyleSheet)
     136void UserAgentStyle::initDefaultStyleSheet()
     137{
     138    if (defaultStyle)
    173139        return;
    174    
    175     if (simpleDefaultStyleSheet) {
    176         ASSERT(defaultStyle);
    177         ASSERT(defaultPrintStyle == defaultStyle);
    178         defaultStyle->deref();
    179         simpleDefaultStyleSheet->deref();
    180         simpleDefaultStyleSheet = nullptr;
    181     } else {
    182         ASSERT(!defaultStyle);
    183         defaultQuirksStyle = &RuleSet::create().leakRef();
    184     }
    185140
    186141    defaultStyle = &RuleSet::create().leakRef();
    187142    defaultPrintStyle = &RuleSet::create().leakRef();
     143    defaultQuirksStyle = &RuleSet::create().leakRef();
    188144    mediaQueryStyleSheet = &StyleSheetContents::create(CSSParserContext(UASheetMode)).leakRef();
    189145
     
    197153    quirksStyleSheet = parseUASheet(quirksRules);
    198154    defaultQuirksStyle->addRulesFromSheet(*quirksStyleSheet, screenEval());
    199 }
    200 
    201 void UserAgentStyle::loadSimpleDefaultStyle()
    202 {
    203     ASSERT(!defaultStyle);
    204     ASSERT(!simpleDefaultStyleSheet);
    205 
    206     defaultStyle = &RuleSet::create().leakRef();
    207     // There are no media-specific rules in the simple default style.
    208     defaultPrintStyle = defaultStyle;
    209     defaultQuirksStyle = &RuleSet::create().leakRef();
    210 
    211     simpleDefaultStyleSheet = parseUASheet(simpleUserAgentStyleSheet, strlen(simpleUserAgentStyleSheet));
    212     defaultStyle->addRulesFromSheet(*simpleDefaultStyleSheet, screenEval());
     155
    213156    ++defaultStyleVersion;
    214     // No need to initialize quirks sheet yet as there are no quirk rules for elements allowed in simple default style.
    215157}
    216158
    217159void UserAgentStyle::ensureDefaultStyleSheetsForElement(const Element& element)
    218160{
    219     if (simpleDefaultStyleSheet && !elementCanUseSimpleDefaultStyle(element)) {
    220         loadFullDefaultStyle();
    221         ++defaultStyleVersion;
    222     }
    223 
    224161    if (is<HTMLElement>(element)) {
    225162        if (is<HTMLObjectElement>(element) || is<HTMLEmbedElement>(element)) {
  • trunk/Source/WebCore/style/UserAgentStyle.h

    r269999 r270886  
    3939    static unsigned defaultStyleVersion;
    4040
    41     static StyleSheetContents* simpleDefaultStyleSheet;
    4241    static StyleSheetContents* defaultStyleSheet;
    4342    static StyleSheetContents* quirksStyleSheet;
     
    6160    static StyleSheetContents* mediaQueryStyleSheet;
    6261
    63     static void initDefaultStyle(const Element*);
     62    static void initDefaultStyleSheet();
    6463    static void ensureDefaultStyleSheetsForElement(const Element&);
    65     static void loadFullDefaultStyle();
    6664
    6765private:
    68     static void loadSimpleDefaultStyle();
    6966    static void addToDefaultStyle(StyleSheetContents&);
    7067};
Note: See TracChangeset for help on using the changeset viewer.