Changeset 252255 in webkit


Ignore:
Timestamp:
Nov 8, 2019 1:10:11 PM (5 years ago)
Author:
Antti Koivisto
Message:

StyleResolver state should store user agent appearance style as RenderStyle
https://bugs.webkit.org/show_bug.cgi?id=204008

Reviewed by Zalan Bujtas.

Generate and pass around user agent style as RenderStyle for apperance computation instead
of awkwardly passing around separate property values.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::styleForElement):
(WebCore::StyleResolver::styleForKeyframe):
(WebCore::StyleResolver::pseudoStyleForElement):
(WebCore::StyleResolver::adjustRenderStyle):
(WebCore::StyleResolver::applyMatchedProperties):
(WebCore::StyleResolver::State::cacheBorderAndBackground): Deleted.

  • css/StyleResolver.h:

(WebCore::StyleResolver::element const):
(WebCore::StyleResolver::State::userAgentAppearanceStyle const):
(WebCore::StyleResolver::State::setUserAgentAppearanceStyle):
(WebCore::StyleResolver::element): Deleted.
(WebCore::StyleResolver::State::hasUAAppearance const): Deleted.
(WebCore::StyleResolver::State::borderData const): Deleted.
(WebCore::StyleResolver::State::backgroundData const): Deleted.
(WebCore::StyleResolver::State::backgroundColor const): Deleted.

  • rendering/RenderTheme.cpp:

(WebCore::RenderTheme::adjustStyle):
(WebCore::RenderTheme::isControlStyled const):

  • rendering/RenderTheme.h:
  • rendering/RenderThemeIOS.h:
  • rendering/RenderThemeIOS.mm:

(WebCore::RenderThemeIOS::isControlStyled const):

  • rendering/RenderThemeMac.h:
  • rendering/RenderThemeMac.mm:

(WebCore::RenderThemeMac::isControlStyled const):

  • style/StyleBuilder.cpp:

(WebCore::Style::Builder::Builder):

Allow providing style separately from StyleResolver state.

  • style/StyleBuilder.h:
Location:
trunk/Source/WebCore
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r252254 r252255  
     12019-11-08  Antti Koivisto  <antti@apple.com>
     2
     3        StyleResolver state should store user agent appearance style as RenderStyle
     4        https://bugs.webkit.org/show_bug.cgi?id=204008
     5
     6        Reviewed by Zalan Bujtas.
     7
     8        Generate and pass around user agent style as RenderStyle for apperance computation instead
     9        of awkwardly passing around separate property values.
     10
     11        * css/StyleResolver.cpp:
     12        (WebCore::StyleResolver::styleForElement):
     13        (WebCore::StyleResolver::styleForKeyframe):
     14        (WebCore::StyleResolver::pseudoStyleForElement):
     15        (WebCore::StyleResolver::adjustRenderStyle):
     16        (WebCore::StyleResolver::applyMatchedProperties):
     17        (WebCore::StyleResolver::State::cacheBorderAndBackground): Deleted.
     18        * css/StyleResolver.h:
     19        (WebCore::StyleResolver::element const):
     20        (WebCore::StyleResolver::State::userAgentAppearanceStyle const):
     21        (WebCore::StyleResolver::State::setUserAgentAppearanceStyle):
     22        (WebCore::StyleResolver::element): Deleted.
     23        (WebCore::StyleResolver::State::hasUAAppearance const): Deleted.
     24        (WebCore::StyleResolver::State::borderData const): Deleted.
     25        (WebCore::StyleResolver::State::backgroundData const): Deleted.
     26        (WebCore::StyleResolver::State::backgroundColor const): Deleted.
     27        * rendering/RenderTheme.cpp:
     28        (WebCore::RenderTheme::adjustStyle):
     29        (WebCore::RenderTheme::isControlStyled const):
     30        * rendering/RenderTheme.h:
     31        * rendering/RenderThemeIOS.h:
     32        * rendering/RenderThemeIOS.mm:
     33        (WebCore::RenderThemeIOS::isControlStyled const):
     34        * rendering/RenderThemeMac.h:
     35        * rendering/RenderThemeMac.mm:
     36        (WebCore::RenderThemeMac::isControlStyled const):
     37        * style/StyleBuilder.cpp:
     38        (WebCore::Style::Builder::Builder):
     39
     40        Allow providing style separately from StyleResolver state.
     41
     42        * style/StyleBuilder.h:
     43
    1442019-11-08  Daniel Bates  <dabates@apple.com>
    245
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r252208 r252255  
    9898using namespace HTMLNames;
    9999
    100 inline void StyleResolver::State::cacheBorderAndBackground()
    101 {
    102     m_hasUAAppearance = m_style->hasAppearance();
    103     if (m_hasUAAppearance) {
    104         m_borderData = m_style->border();
    105         m_backgroundData = m_style->backgroundLayers();
    106         m_backgroundColor = m_style->backgroundColor();
    107     }
    108 }
    109 
    110100inline void StyleResolver::State::clear()
    111101{
     
    113103    m_parentStyle = nullptr;
    114104    m_ownedParentStyle = nullptr;
     105    m_userAgentAppearanceStyle = nullptr;
    115106}
    116107
     
    286277
    287278    // Clean up our style object's display and text decorations (among other fixups).
    288     adjustRenderStyle(*state.style(), *state.parentStyle(), parentBoxStyle, &element);
     279    adjustRenderStyle(*state.style(), *state.parentStyle(), parentBoxStyle, &element, state.userAgentAppearanceStyle());
    289280
    290281    if (state.style()->hasViewportUnits())
     
    314305    builder.applyAllProperties();
    315306
    316     adjustRenderStyle(*state.style(), *state.parentStyle(), nullptr, nullptr);
     307    adjustRenderStyle(*state.style(), *state.parentStyle(), nullptr, nullptr, state.userAgentAppearanceStyle());
    317308
    318309    // Add all the animating properties to the keyframe.
     
    470461
    471462    // Clean up our style object's display and text decorations (among other fixups).
    472     adjustRenderStyle(*state.style(), *m_state.parentStyle(), parentBoxStyle, nullptr);
     463    adjustRenderStyle(*state.style(), *m_state.parentStyle(), parentBoxStyle, nullptr, state.userAgentAppearanceStyle());
    473464
    474465    if (state.style()->hasViewportUnits())
     
    780771#endif
    781772
    782 void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element)
     773void StyleResolver::adjustRenderStyle(RenderStyle& style, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element* element, const RenderStyle* userAgentAppearanceStyle)
    783774{
    784775    // If the composed tree parent has display:contents, the parent box style will be different from the parent style.
     
    1000991    // Let the theme also have a crack at adjusting the style.
    1001992    if (style.hasAppearance())
    1002         RenderTheme::singleton().adjustStyle(*this, style, element, m_state.hasUAAppearance(), m_state.borderData(), m_state.backgroundData(), m_state.backgroundColor());
     993        RenderTheme::singleton().adjustStyle(*this, style, element, userAgentAppearanceStyle);
    1003994
    1004995    // If we have first-letter pseudo style, do not share this style.
     
    11391130
    11401131    if (elementTypeHasAppearanceFromUAStyle(element)) {
    1141         // FIXME: This is such a hack.
    11421132        // Find out if there's a -webkit-appearance property in effect from the UA sheet.
    11431133        // If so, we cache the border and background styles so that RenderTheme::adjustStyle()
    11441134        // can look at them later to figure out if this is a styled form control or not.
    1145         Style::Builder builder(*this, matchResult, { Style::CascadeLevel::UserAgent }, includedProperties);
     1135        auto userAgentStyle = RenderStyle::clonePtr(style);
     1136        Style::Builder builder(*userAgentStyle, *this, matchResult, { Style::CascadeLevel::UserAgent });
    11461137        builder.applyAllProperties();
    11471138
    1148         state.cacheBorderAndBackground();
     1139        state.setUserAgentAppearanceStyle(WTFMove(userAgentStyle));
    11491140    }
    11501141
  • trunk/Source/WebCore/css/StyleResolver.h

    r252208 r252255  
    118118    const RenderStyle* parentStyle() const { return m_state.parentStyle(); }
    119119    const RenderStyle* rootElementStyle() const { return m_state.rootElementStyle(); }
    120     const Element* element() { return m_state.element(); }
     120    const Element* element() const { return m_state.element(); }
    121121    Document& document() { return m_document; }
    122122    const Document& document() const { return m_document; }
     
    184184
    185185private:
    186     void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*);
     186    void adjustRenderStyle(RenderStyle&, const RenderStyle& parentStyle, const RenderStyle* parentBoxStyle, const Element*, const RenderStyle* userAgentStyle);
    187187    void adjustRenderStyleForSiteSpecificQuirks(RenderStyle&, const Element&);
    188188
     
    216216        const RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
    217217
    218         void cacheBorderAndBackground();
    219         bool hasUAAppearance() const { return m_hasUAAppearance; }
    220         BorderData borderData() const { return m_borderData; }
    221         FillLayer backgroundData() const { return m_backgroundData; }
    222         const Color& backgroundColor() const { return m_backgroundColor; }
     218        const RenderStyle* userAgentAppearanceStyle() const { return m_userAgentAppearanceStyle.get(); }
     219        void setUserAgentAppearanceStyle(std::unique_ptr<RenderStyle> style) { m_userAgentAppearanceStyle = WTFMove(style); }
    223220
    224221        const SelectorFilter* selectorFilter() const { return m_selectorFilter; }
     
    233230        const SelectorFilter* m_selectorFilter { nullptr };
    234231
    235         BorderData m_borderData;
    236         FillLayer m_backgroundData { FillLayerType::Background };
    237         Color m_backgroundColor;
    238 
    239         bool m_hasUAAppearance { false };
     232        std::unique_ptr<RenderStyle> m_userAgentAppearanceStyle;
    240233    };
    241234
  • trunk/Source/WebCore/rendering/RenderTheme.cpp

    r245072 r252255  
    7979}
    8080
    81 void RenderTheme::adjustStyle(StyleResolver& styleResolver, RenderStyle& style, const Element* element, bool UAHasAppearance, const BorderData& border, const FillLayer& background, const Color& backgroundColor)
     81void RenderTheme::adjustStyle(StyleResolver& styleResolver, RenderStyle& style, const Element* element, const RenderStyle* userAgentAppearanceStyle)
    8282{
    8383    // Force inline and table display styles to be inline-block (except for table- which is block)
     
    9191        style.setDisplay(DisplayType::Block);
    9292
    93     if (UAHasAppearance && isControlStyled(style, border, background, backgroundColor)) {
     93    if (userAgentAppearanceStyle && isControlStyled(style, *userAgentAppearanceStyle)) {
    9494        switch (part) {
    9595        case MenulistPart:
     
    731731}
    732732
    733 bool RenderTheme::isControlStyled(const RenderStyle& style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const
     733bool RenderTheme::isControlStyled(const RenderStyle& style, const RenderStyle& userAgentStyle) const
    734734{
    735735    switch (style.appearance()) {
     
    753753    case TextAreaPart:
    754754        // Test the style to see if the UA border and background match.
    755         return style.border() != border
    756             || style.backgroundLayers() != background
    757             || !style.backgroundColorEqualsToColorIgnoringVisited(backgroundColor);
     755        return style.border() != userAgentStyle.border()
     756            || style.backgroundLayers() != userAgentStyle.backgroundLayers()
     757            || !style.backgroundColorEqualsToColorIgnoringVisited(userAgentStyle.backgroundColor());
    758758    default:
    759759        return false;
  • trunk/Source/WebCore/rendering/RenderTheme.h

    r246490 r252255  
    6666    // selection of control size based off the font, the disabling of appearance when certain other properties like
    6767    // "border" are set, or if the appearance is not supported by the theme.
    68     void adjustStyle(StyleResolver&, RenderStyle&, const Element*,  bool UAHasAppearance, const BorderData&, const FillLayer&, const Color& backgroundColor);
     68    void adjustStyle(StyleResolver&, RenderStyle&, const Element*, const RenderStyle* userAgentAppearanceStyle);
    6969
    7070    // This method is called to paint the widget as a background of the RenderObject.  A widget's foreground, e.g., the
     
    117117
    118118    // Whether or not the control has been styled enough by the author to disable the native appearance.
    119     virtual bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color& backgroundColor) const;
     119    virtual bool isControlStyled(const RenderStyle&, const RenderStyle& userAgentStyle) const;
    120120
    121121    // A general method asking if any control tinting is supported at all.
  • trunk/Source/WebCore/rendering/RenderThemeIOS.h

    r241825 r252255  
    6767    int baselinePosition(const RenderBox&) const override;
    6868
    69     bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer& background, const Color& backgroundColor) const override;
     69    bool isControlStyled(const RenderStyle&, const RenderStyle& userAgentStyle) const override;
    7070
    7171    // Methods for each appearance value.
  • trunk/Source/WebCore/rendering/RenderThemeIOS.mm

    r251896 r252255  
    448448}
    449449
    450 bool RenderThemeIOS::isControlStyled(const RenderStyle& style, const BorderData& border, const FillLayer& background, const Color& backgroundColor) const
     450bool RenderThemeIOS::isControlStyled(const RenderStyle& style, const RenderStyle& userAgentStyle) const
    451451{
    452452    // Buttons and MenulistButtons are styled if they contain a background image.
     
    455455
    456456    if (style.appearance() == TextFieldPart || style.appearance() == TextAreaPart)
    457         return style.backgroundLayers() != background;
    458 
    459     return RenderTheme::isControlStyled(style, border, background, backgroundColor);
     457        return style.backgroundLayers() != userAgentStyle.backgroundLayers();
     458
     459    return RenderTheme::isControlStyled(style, userAgentStyle);
    460460}
    461461
  • trunk/Source/WebCore/rendering/RenderThemeMac.h

    r240628 r252255  
    5050    void adjustRepaintRect(const RenderObject&, FloatRect&) final;
    5151
    52     bool isControlStyled(const RenderStyle&, const BorderData&, const FillLayer&, const Color& backgroundColor) const final;
     52    bool isControlStyled(const RenderStyle&, const RenderStyle& userAgentStyle) const final;
    5353
    5454    bool supportsSelectionForegroundColors(OptionSet<StyleColor::Options>) const final;
  • trunk/Source/WebCore/rendering/RenderThemeMac.mm

    r249217 r252255  
    883883}
    884884
    885 bool RenderThemeMac::isControlStyled(const RenderStyle& style, const BorderData& border,
    886                                      const FillLayer& background, const Color& backgroundColor) const
     885bool RenderThemeMac::isControlStyled(const RenderStyle& style, const RenderStyle& userAgentStyle) const
    887886{
    888887    if (style.appearance() == TextFieldPart || style.appearance() == TextAreaPart || style.appearance() == ListboxPart)
    889         return style.border() != border;
     888        return style.border() != userAgentStyle.border();
    890889
    891890    // FIXME: This is horrible, but there is not much else that can be done.  Menu lists cannot draw properly when
     
    896895        return true;
    897896
    898     return RenderTheme::isControlStyled(style, border, background, backgroundColor);
     897    return RenderTheme::isControlStyled(style, userAgentStyle);
    899898}
    900899
  • trunk/Source/WebCore/style/StyleBuilder.cpp

    r252030 r252255  
    5050}
    5151
     52Builder::Builder(RenderStyle& style, const StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
     53    : m_cascade(matchResult, cascadeLevels, includedProperties, directionFromStyle(style))
     54    , m_state(*this, style, *resolver.parentStyle(), resolver.rootElementStyle(), resolver.document(), resolver.element())
     55{
     56    ASSERT(resolver.parentStyle());
     57}
     58
    5259Builder::Builder(StyleResolver& resolver, const MatchResult& matchResult, OptionSet<CascadeLevel> cascadeLevels, PropertyCascade::IncludedProperties includedProperties)
    53     : m_cascade(matchResult, cascadeLevels, includedProperties, directionFromStyle(*resolver.style()))
    54     , m_state(*this, *resolver.style(), *resolver.parentStyle(), resolver.rootElementStyle(), resolver.document(), resolver.element())
     60    : Builder(*resolver.style(), resolver, matchResult, cascadeLevels, includedProperties)
    5561{
    5662    ASSERT(resolver.style());
    57     ASSERT(resolver.parentStyle());
    5863}
    5964
  • trunk/Source/WebCore/style/StyleBuilder.h

    r251864 r252255  
    3636    WTF_MAKE_FAST_ALLOCATED;
    3737public:
     38    Builder(RenderStyle&, const StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, PropertyCascade::IncludedProperties = PropertyCascade::IncludedProperties::All);
    3839    Builder(StyleResolver&, const MatchResult&, OptionSet<CascadeLevel>, PropertyCascade::IncludedProperties = PropertyCascade::IncludedProperties::All);
    3940    ~Builder();
Note: See TracChangeset for help on using the changeset viewer.