source: trunk/Source/WebCore/css/StyleResolver.h @ 174190

Revision 173659, 23.7 KB checked in by darin@apple.com, 2 weeks ago (diff)

Source/WebCore:
Scroll snap properties don't handle inherit and initial propertly.
https://bugs.webkit.org/show_bug.cgi?id=136643

Reviewed by Beth Dakin.

Restructured scroll snap code both to handle inherit and initial, and to reduce the
total code size a bit, fixing a few minor bugs along the way. Updated the regression
tests to cover the new parts.

  • css/CSSComputedStyleDeclaration.cpp:

(WebCore::addValuesForNamedGridLinesAtIndex): Use a modern for loop.
(WebCore::scrollSnapDestination): Changed to take a LengthSize. Also streamlined.
(WebCore::scrollSnapPoints): Changed to to take a ScrollSnapPoints. Also streamlined and
added code to handle the "uses elements" case; serialize that as an identifier, not the
string "elements", fixing a minor bug.
(WebCore::scrollSnapCoordinates): Changed to take a Vector<LengthSize>. Also streamlined
and added code to handle the empty vector case; serialize that as an identifier, not the
string "none", fixing a minor bug.
(WebCore::ComputedStyleExtractor::getFontSizeCSSValuePreferringKeyword): Use nullptr.
(WebCore::counterToCSSValue): Use nullptr.
(WebCore::ComputedStyleExtractor::styledNode): Use nullptr.
(WebCore::ComputedStyleExtractor::propertyValue): Use nullptr. Moved CSS_SCROLL_SNAP
to a more appropriate section of the switch statement. Made it just call through to
the functions above in a more straightforward way.
(WebCore::CSSComputedStyleDeclaration::getPropertyValue): Reversed logic to use early
return and to call emptyString.
(WebCore::CSSComputedStyleDeclaration::item): Use emptyString.
(WebCore::ComputedStyleExtractor::getCSSPropertyValuesForSidesShorthand): Use nullptr.
(WebCore::CSSComputedStyleDeclaration::parentRule): Use nullptr.
(WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Use nullptr.
(WebCore::CSSComputedStyleDeclaration::getPropertyPriority): Use emptyString.
(WebCore::CSSComputedStyleDeclaration::getPropertyShorthand): Use emptyString.

  • css/DeprecatedStyleBuilder.cpp:

(WebCore::ApplyPropertyMarqueeIncrement::applyValue): Use the switch statement for the
invalid value as well as for the valid values, rather than a separate if statement.
Call convertToLength directly rather than through a StyleResolver static member function.

  • css/PropertySetCSSStyleDeclaration.cpp:

(WebCore::PropertySetCSSStyleDeclaration::getPropertyValue): Fixed a formatting mistake.

  • css/StyleResolver.cpp:

(WebCore::convertToIntLength): Made this function local to this file instead of a
static member function.
(WebCore::convertToFloatLength): Ditto.
(WebCore::StyleResolver::parseSnapCoordinate): Added. Used to keep snap point parsing
code small.
(WebCore::StyleResolver::parseSnapCoordinatePair): Ditto.
(WebCore::StyleResolver::parseSnapPoints): Added. Parses an entire snap points property.
(WebCore::StyleResolver::applyProperty): Removed various bits of redundant code that
were not using the primitiveValue value already in a local variable. Added the
HANDLE_INHERIT_AND_INITIAL to all the scroll snap properties and updated since the
RenderStyle structure now more closely matches the CSS properties.

  • css/StyleResolver.h: Updated for above changes, and removed a redundant "private:".
  • page/scrolling/AxisScrollSnapOffsets.cpp:

(WebCore::appendChildSnapOffsets): Use auto& instead of SnapCoordinate since that type
is now gone. Updated since coordinates are now LengthSize.
(WebCore::updateFromStyle): Changed to take a reference instead of a pointer and
also to fetch the data from RenderStyle in a new way that more closely matches the
CSS properties.
(WebCore::updateSnapOffsetsForScrollableArea): Ditto. Also moved some memory allocation
inside if statements so we don't wastefully allocate and destroy.

  • rendering/style/RenderStyle.cpp: Added an include of StyleScrollSnapPoints.h now

that the header doesn't include them. Moved the conditional includes out of the main
include paragraph (even though I don't think conditional includes are usually a good
idea).
(WebCore::RenderStyle::initialScrollSnapPointsX): Added.
(WebCore::RenderStyle::initialScrollSnapPointsY): Added.
(WebCore::RenderStyle::initialScrollSnapDestination): Added.
(WebCore::RenderStyle::initialScrollSnapCoordinates): Added.
(WebCore::RenderStyle::scrollSnapPointsX): Added.
(WebCore::RenderStyle::scrollSnapPointsY): Added.
(WebCore::RenderStyle::scrollSnapDestination): Added.
(WebCore::RenderStyle::scrollSnapCoordinates): Added.
(WebCore::RenderStyle::setScrollSnapPointsX): Added.
(WebCore::RenderStyle::setScrollSnapPointsY): Added.
(WebCore::RenderStyle::setScrollSnapDestination): Added.
(WebCore::RenderStyle::setScrollSnapCoordinates): Added.

  • rendering/style/RenderStyle.h: Replaced the include of StyleScrollSnapPoints.h with

a forward declaration of ScrollSnapPoints. Removed getters and setters for the old
style properties and replaced them with new ones that match the CSS properties more
closely. Tweaked formatting a bit. Added initial value functions for the the scroll snap
properties.

  • rendering/style/StyleRareNonInheritedData.cpp: Added include of StyleScrollSnapPoints.h

now that RenderStyle.h doesn't include it.
(WebCore::StyleRareNonInheritedData::StyleRareNonInheritedData): Updated since
m_scrollSnapType is now unsigned instead of ScrollSnapType.

  • rendering/style/StyleRareNonInheritedData.h: Fixed type of m_scrollSnapType to be

unsigned instead of ScrollSnapType. This should have been causing problems on Windows,
but I think we got lucky and had no detectable problems.

  • rendering/style/StyleScrollSnapPoints.cpp:

(WebCore::ScrollSnapPoints::ScrollSnapPoints): Added.
(WebCore::operator==): Added overloads for both ScrollSnapPoints and also for
StyleScrollSnapPoints; using a free function for both since both have public data.
(WebCore::defaultScrollSnapDestination): Added, replaces a static member function.
(WebCore::StyleScrollSnapPoints::StyleScrollSnapPoints): Updated both the default
constructor and the copy constructor for the new design.

  • rendering/style/StyleScrollSnapPoints.h: Added a ScrollSnapPoints struct for the

type of the snap-points-x and snap-points-y CSS properties. Changed the data members
of StyleScrollSnapPoints to match the various CSS properties rather than breaking
out all the data into separate data members.
(WebCore::StyleScrollSnapPoints::defaultRepeatOffset): Deleted. Replaced by the
default constructor for ScrollSnapPoints.
(WebCore::StyleScrollSnapPoints::defaultDestinationOffset): Deleted. Replaced by
a function inside the .cpp file.

LayoutTests:
Scroll snap properties do not handle inherit and initial properly.
https://bugs.webkit.org/show_bug.cgi?id=136643

Reviewed by Beth Dakin.

  • css3/scroll-snap/scroll-snap-property-computed-style-expected.txt: Added

expected passing results from new tests.

  • css3/scroll-snap/scroll-snap-property-computed-style.js: Added new test

cases that cover inherit and initial. Before, these would crash or fail.

  • css3/scroll-snap/scroll-snap-property-parsing-expected.txt: Added expected

passing results from new tests, and also updated to expect pass rather than
fail for the tests that had incorrect expected results.

  • css3/scroll-snap/scroll-snap-property-parsing.js: Added new test cases that

cover inherit and initial. Also updated expected results for certain pixel
repeat cases that were incorrect.

  • platform/mac/TestExpectations: Fixed an unrelated syntax error in this file.
  • Property svn:eol-style set to native
Line 
1/*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB.  If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#ifndef StyleResolver_h
23#define StyleResolver_h
24
25#include "CSSToLengthConversionData.h"
26#include "CSSToStyleMap.h"
27#include "CSSValueList.h"
28#include "DocumentRuleSets.h"
29#include "InspectorCSSOMWrappers.h"
30#include "LinkHash.h"
31#include "MediaQueryExp.h"
32#include "RenderStyle.h"
33#include "RuleFeature.h"
34#include "RuleSet.h"
35#include "RuntimeEnabledFeatures.h"
36#include "ScrollTypes.h"
37#include "SelectorChecker.h"
38#include "SelectorFilter.h"
39#include "StyleInheritedData.h"
40#include "ViewportStyleResolver.h"
41#include <memory>
42#include <wtf/HashMap.h>
43#include <wtf/HashSet.h>
44#include <wtf/RefPtr.h>
45#include <wtf/Vector.h>
46#include <wtf/text/AtomicStringHash.h>
47#include <wtf/text/StringHash.h>
48
49namespace WebCore {
50
51class CSSCursorImageValue;
52class CSSFontSelector;
53class CSSFontFace;
54class CSSFontFaceRule;
55class CSSImageGeneratorValue;
56class CSSImageSetValue;
57class CSSImageValue;
58class CSSPageRule;
59class CSSPrimitiveValue;
60class CSSProperty;
61class CSSSelector;
62class CSSStyleSheet;
63class CSSValue;
64class ContainerNode;
65class Document;
66class DeprecatedStyleBuilder;
67class Element;
68class Frame;
69class FrameView;
70class URL;
71class KeyframeList;
72class KeyframeValue;
73class MediaQueryEvaluator;
74class Node;
75class RenderRegion;
76class RenderScrollbar;
77class RuleData;
78class RuleSet;
79class Settings;
80class StyleImage;
81class StyleKeyframe;
82class StylePendingImage;
83class StyleProperties;
84class StyleRule;
85class StyleRuleKeyframes;
86class StyleRulePage;
87class StyleRuleRegion;
88class StyleSheet;
89class StyleSheetList;
90class StyledElement;
91class SVGSVGElement;
92class ViewportStyleResolver;
93class WebKitCSSFilterValue;
94struct ResourceLoaderOptions;
95
96class MediaQueryResult {
97    WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
98public:
99    MediaQueryResult(const MediaQueryExp& expr, bool result)
100        : m_expression(expr)
101        , m_result(result)
102    {
103    }
104
105    MediaQueryExp m_expression;
106    bool m_result;
107};
108
109enum StyleSharingBehavior {
110    AllowStyleSharing,
111    DisallowStyleSharing,
112};
113
114// MatchOnlyUserAgentRules is used in media queries, where relative units
115// are interpreted according to the document root element style, and styled only
116// from the User Agent Stylesheet rules.
117
118enum RuleMatchingBehavior {
119    MatchAllRules,
120    MatchAllRulesExcludingSMIL,
121    MatchOnlyUserAgentRules,
122};
123
124class PseudoStyleRequest {
125public:
126    PseudoStyleRequest(PseudoId pseudoId, RenderScrollbar* scrollbar = 0, ScrollbarPart scrollbarPart = NoPart)
127        : pseudoId(pseudoId)
128        , scrollbarPart(scrollbarPart)
129        , scrollbar(scrollbar)
130    {
131    }
132
133    PseudoId pseudoId;
134    ScrollbarPart scrollbarPart;
135    RenderScrollbar* scrollbar;
136};
137
138// This class selects a RenderStyle for a given element based on a collection of stylesheets.
139class StyleResolver {
140    WTF_MAKE_NONCOPYABLE(StyleResolver); WTF_MAKE_FAST_ALLOCATED;
141public:
142    StyleResolver(Document&, bool matchAuthorAndUserStyles);
143    ~StyleResolver();
144
145    // Using these during tree walk will allow style selector to optimize child and descendant selector lookups.
146    void pushParentElement(Element*);
147    void popParentElement(Element*);
148
149    PassRef<RenderStyle> styleForElement(Element*, RenderStyle* parentStyle, StyleSharingBehavior = AllowStyleSharing,
150        RuleMatchingBehavior = MatchAllRules, RenderRegion* regionForStyling = nullptr);
151
152    void keyframeStylesForAnimation(Element*, const RenderStyle*, KeyframeList&);
153
154    PassRefPtr<RenderStyle> pseudoStyleForElement(Element*, const PseudoStyleRequest&, RenderStyle* parentStyle);
155
156    PassRef<RenderStyle> styleForPage(int pageIndex);
157    PassRef<RenderStyle> defaultStyleForElement();
158
159    RenderStyle* style() const { return m_state.style(); }
160    RenderStyle* parentStyle() const { return m_state.parentStyle(); }
161    RenderStyle* rootElementStyle() const { return m_state.rootElementStyle(); }
162    Element* element() { return m_state.element(); }
163    Document& document() { return m_document; }
164
165    // FIXME: It could be better to call m_ruleSets.appendAuthorStyleSheets() directly after we factor StyleRsolver further.
166    // https://bugs.webkit.org/show_bug.cgi?id=108890
167    void appendAuthorStyleSheets(unsigned firstNew, const Vector<RefPtr<CSSStyleSheet>>&);
168
169    DocumentRuleSets& ruleSets() { return m_ruleSets; }
170    const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
171    SelectorFilter& selectorFilter() { return m_selectorFilter; }
172
173    const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }
174
175private:
176    void initElement(Element*);
177    RenderStyle* locateSharedStyle();
178    bool styleSharingCandidateMatchesRuleSet(RuleSet*);
179    Node* locateCousinList(Element* parent, unsigned& visitedNodeCount) const;
180    StyledElement* findSiblingForStyleSharing(Node*, unsigned& count) const;
181    bool canShareStyleWithElement(StyledElement*) const;
182
183    PassRef<RenderStyle> styleForKeyframe(const RenderStyle*, const StyleKeyframe*, KeyframeValue&);
184
185public:
186    // These methods will give back the set of rules that matched for a given element (or a pseudo-element).
187    enum CSSRuleFilter {
188        UAAndUserCSSRules   = 1 << 1,
189        AuthorCSSRules      = 1 << 2,
190        EmptyCSSRules       = 1 << 3,
191        CrossOriginCSSRules = 1 << 4,
192        AllButEmptyCSSRules = UAAndUserCSSRules | AuthorCSSRules | CrossOriginCSSRules,
193        AllCSSRules         = AllButEmptyCSSRules | EmptyCSSRules,
194    };
195    Vector<RefPtr<StyleRule>> styleRulesForElement(Element*, unsigned rulesToInclude = AllButEmptyCSSRules);
196    Vector<RefPtr<StyleRule>> pseudoStyleRulesForElement(Element*, PseudoId, unsigned rulesToInclude = AllButEmptyCSSRules);
197
198public:
199    void applyPropertyToStyle(CSSPropertyID, CSSValue*, RenderStyle*);
200
201    void applyPropertyToCurrentStyle(CSSPropertyID, CSSValue*);
202
203    void updateFont();
204    void initializeFontStyle(Settings*);
205
206    void setFontSize(FontDescription&, float size);
207
208public:
209    bool useSVGZoomRules();
210    bool useSVGZoomRulesForLength();
211
212    static bool colorFromPrimitiveValueIsDerivedFromElement(CSSPrimitiveValue*);
213    Color colorFromPrimitiveValue(CSSPrimitiveValue*, bool forVisitedLink = false) const;
214
215    bool hasSelectorForId(const AtomicString&) const;
216    bool hasSelectorForClass(const AtomicString&) const;
217    bool hasSelectorForAttribute(const Element&, const AtomicString&) const;
218
219    CSSFontSelector* fontSelector() const { return m_fontSelector.get(); }
220#if ENABLE(CSS_DEVICE_ADAPTATION)
221    ViewportStyleResolver* viewportStyleResolver() { return m_viewportStyleResolver.get(); }
222#endif
223
224    void addViewportDependentMediaQueryResult(const MediaQueryExp*, bool result);
225    bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); }
226    bool hasMediaQueriesAffectedByViewportChange() const;
227
228    void addKeyframeStyle(PassRefPtr<StyleRuleKeyframes>);
229
230    bool checkRegionStyle(Element* regionElement);
231
232    bool usesSiblingRules() const { return !m_ruleSets.features().siblingRules.isEmpty(); }
233    bool usesFirstLineRules() const { return m_ruleSets.features().usesFirstLineRules; }
234    bool usesFirstLetterRules() const { return m_ruleSets.features().usesFirstLetterRules; }
235    bool usesBeforeAfterRules() const { return m_ruleSets.features().usesBeforeAfterRules; }
236   
237    void invalidateMatchedPropertiesCache();
238
239    void clearCachedPropertiesAffectedByViewportUnits();
240
241    bool createFilterOperations(CSSValue* inValue, FilterOperations& outOperations);
242    void loadPendingSVGDocuments();
243
244    void loadPendingResources();
245
246    struct RuleRange {
247        RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { }
248        int& firstRuleIndex;
249        int& lastRuleIndex;
250    };
251
252    struct MatchRanges {
253        MatchRanges() : firstUARule(-1), lastUARule(-1), firstAuthorRule(-1), lastAuthorRule(-1), firstUserRule(-1), lastUserRule(-1) { }
254        int firstUARule;
255        int lastUARule;
256        int firstAuthorRule;
257        int lastAuthorRule;
258        int firstUserRule;
259        int lastUserRule;
260        RuleRange UARuleRange() { return RuleRange(firstUARule, lastUARule); }
261        RuleRange authorRuleRange() { return RuleRange(firstAuthorRule, lastAuthorRule); }
262        RuleRange userRuleRange() { return RuleRange(firstUserRule, lastUserRule); }
263    };
264
265    struct MatchedProperties {
266        MatchedProperties();
267        ~MatchedProperties();
268       
269        RefPtr<StyleProperties> properties;
270        union {
271            struct {
272                unsigned linkMatchType : 2;
273                unsigned whitelistType : 2;
274            };
275            // Used to make sure all memory is zero-initialized since we compute the hash over the bytes of this object.
276            void* possiblyPaddedMember;
277        };
278    };
279
280    struct MatchResult {
281        MatchResult() : isCacheable(true) { }
282        Vector<MatchedProperties, 64> matchedProperties;
283        Vector<StyleRule*, 64> matchedRules;
284        MatchRanges ranges;
285        bool isCacheable;
286
287        void addMatchedProperties(const StyleProperties&, StyleRule* = 0, unsigned linkMatchType = SelectorChecker::MatchAll, PropertyWhitelistType = PropertyWhitelistNone);
288    };
289
290private:
291    // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
292    void checkForGenericFamilyChange(RenderStyle*, RenderStyle* parentStyle);
293    void checkForZoomChange(RenderStyle*, RenderStyle* parentStyle);
294#if ENABLE(IOS_TEXT_AUTOSIZING)
295    void checkForTextSizeAdjust(RenderStyle*);
296#endif
297
298    void adjustRenderStyle(RenderStyle& styleToAdjust, const RenderStyle& parentStyle, Element*);
299#if ENABLE(CSS_GRID_LAYOUT)
300    std::unique_ptr<GridPosition> adjustNamedGridItemPosition(const NamedGridAreaMap&, const NamedGridLinesMap&, const GridPosition&, GridPositionSide) const;
301#endif
302   
303    void adjustStyleForInterCharacterRuby();
304   
305    bool fastRejectSelector(const RuleData&) const;
306
307    enum ShouldUseMatchedPropertiesCache { DoNotUseMatchedPropertiesCache = 0, UseMatchedPropertiesCache };
308    void applyMatchedProperties(const MatchResult&, const Element*, ShouldUseMatchedPropertiesCache = UseMatchedPropertiesCache);
309
310    class CascadedProperties;
311
312    void applyCascadedProperties(CascadedProperties&, int firstProperty, int lastProperty);
313    void cascadeMatches(CascadedProperties&, const MatchResult&, bool important, int startIndex, int endIndex, bool inheritedOnly);
314
315    static bool isValidRegionStyleProperty(CSSPropertyID);
316#if ENABLE(VIDEO_TRACK)
317    static bool isValidCueStyleProperty(CSSPropertyID);
318#endif
319    void matchPageRules(MatchResult&, RuleSet*, bool isLeftPage, bool isFirstPage, const String& pageName);
320    void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>&, bool isLeftPage, bool isFirstPage, const String& pageName);
321    Settings* documentSettings() { return m_document.settings(); }
322
323    bool isLeftPage(int pageIndex) const;
324    bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
325    bool isFirstPage(int pageIndex) const;
326    String pageName(int pageIndex) const;
327
328    DocumentRuleSets m_ruleSets;
329
330    typedef HashMap<AtomicStringImpl*, RefPtr<StyleRuleKeyframes>> KeyframesRuleMap;
331    KeyframesRuleMap m_keyframesRuleMap;
332
333public:
334    typedef HashMap<CSSPropertyID, RefPtr<CSSValue>> PendingImagePropertyMap;
335
336    class State {
337        WTF_MAKE_NONCOPYABLE(State);
338    public:
339        State()
340            : m_element(nullptr)
341            , m_styledElement(nullptr)
342            , m_parentStyle(nullptr)
343            , m_rootElementStyle(nullptr)
344            , m_regionForStyling(nullptr)
345            , m_elementLinkState(NotInsideLink)
346            , m_elementAffectedByClassRules(false)
347            , m_applyPropertyToRegularStyle(true)
348            , m_applyPropertyToVisitedLinkStyle(false)
349            , m_lineHeightValue(nullptr)
350            , m_fontDirty(false)
351            , m_fontSizeHasViewportUnits(false)
352            , m_hasUAAppearance(false)
353            , m_backgroundData(BackgroundFillLayer)
354        {
355        }
356
357    public:
358        void initElement(Element*);
359        void initForStyleResolve(Document&, Element*, RenderStyle* parentStyle, RenderRegion* regionForStyling = nullptr);
360        void clear();
361
362        Document& document() const { return m_element->document(); }
363        Element* element() const { return m_element; }
364        StyledElement* styledElement() const { return m_styledElement; }
365        void setStyle(PassRef<RenderStyle>);
366        RenderStyle* style() const { return m_style.get(); }
367        PassRef<RenderStyle> takeStyle() { return m_style.releaseNonNull(); }
368
369        void setParentStyle(PassRef<RenderStyle> parentStyle) { m_parentStyle = WTF::move(parentStyle); }
370        RenderStyle* parentStyle() const { return m_parentStyle.get(); }
371        RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
372
373        const RenderRegion* regionForStyling() const { return m_regionForStyling; }
374        EInsideLink elementLinkState() const { return m_elementLinkState; }
375        void setElementAffectedByClassRules(bool isAffected) { m_elementAffectedByClassRules = isAffected; }
376        bool elementAffectedByClassRules() const { return m_elementAffectedByClassRules; }
377
378        void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
379        void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
380        bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
381        bool applyPropertyToVisitedLinkStyle() const { return m_applyPropertyToVisitedLinkStyle; }
382        PendingImagePropertyMap& pendingImageProperties() { return m_pendingImageProperties; }
383
384        Vector<RefPtr<ReferenceFilterOperation>>& filtersWithPendingSVGDocuments() { return m_filtersWithPendingSVGDocuments; }
385
386        void setLineHeightValue(CSSValue* value) { m_lineHeightValue = value; }
387        CSSValue* lineHeightValue() { return m_lineHeightValue; }
388        void setFontDirty(bool isDirty) { m_fontDirty = isDirty; }
389        bool fontDirty() const { return m_fontDirty; }
390        void setFontSizeHasViewportUnits(bool hasViewportUnits) { m_fontSizeHasViewportUnits = hasViewportUnits; }
391        bool fontSizeHasViewportUnits() const { return m_fontSizeHasViewportUnits; }
392
393        void cacheBorderAndBackground();
394        bool hasUAAppearance() const { return m_hasUAAppearance; }
395        BorderData borderData() const { return m_borderData; }
396        FillLayer backgroundData() const { return m_backgroundData; }
397        Color backgroundColor() const { return m_backgroundColor; }
398
399        const FontDescription& fontDescription() { return m_style->fontDescription(); }
400        const FontDescription& parentFontDescription() { return m_parentStyle->fontDescription(); }
401        void setFontDescription(const FontDescription& fontDescription) { m_fontDirty |= m_style->setFontDescription(fontDescription); }
402        void setZoom(float f) { m_fontDirty |= m_style->setZoom(f); }
403        void setEffectiveZoom(float f) { m_fontDirty |= m_style->setEffectiveZoom(f); }
404        void setWritingMode(WritingMode writingMode) { m_fontDirty |= m_style->setWritingMode(writingMode); }
405        void setTextOrientation(TextOrientation textOrientation) { m_fontDirty |= m_style->setTextOrientation(textOrientation); }
406
407        bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
408
409        CSSToLengthConversionData cssToLengthConversionData() const { return m_cssToLengthConversionData; }
410
411    private:
412        void updateConversionData();
413
414        Element* m_element;
415        RefPtr<RenderStyle> m_style;
416        StyledElement* m_styledElement;
417        RefPtr<RenderStyle> m_parentStyle;
418        RenderStyle* m_rootElementStyle;
419
420        // Required to ASSERT in applyProperties.
421        RenderRegion* m_regionForStyling;
422       
423        EInsideLink m_elementLinkState;
424
425        bool m_elementAffectedByClassRules;
426
427        bool m_applyPropertyToRegularStyle;
428        bool m_applyPropertyToVisitedLinkStyle;
429
430        PendingImagePropertyMap m_pendingImageProperties;
431
432        Vector<RefPtr<ReferenceFilterOperation>> m_filtersWithPendingSVGDocuments;
433
434        CSSValue* m_lineHeightValue;
435        bool m_fontDirty;
436        bool m_fontSizeHasViewportUnits;
437
438        bool m_hasUAAppearance;
439        BorderData m_borderData;
440        FillLayer m_backgroundData;
441        Color m_backgroundColor;
442
443        CSSToLengthConversionData m_cssToLengthConversionData;
444    };
445
446    State& state() { return m_state; }
447
448    static RenderStyle* styleNotYetAvailable() { return s_styleNotYetAvailable; }
449
450    PassRefPtr<StyleImage> styleImage(CSSPropertyID, CSSValue*);
451    PassRefPtr<StyleImage> cachedOrPendingFromValue(CSSPropertyID, CSSImageValue*);
452    PassRefPtr<StyleImage> generatedOrPendingFromValue(CSSPropertyID, CSSImageGeneratorValue&);
453#if ENABLE(CSS_IMAGE_SET)
454    PassRefPtr<StyleImage> setOrPendingFromValue(CSSPropertyID, CSSImageSetValue*);
455#endif
456    PassRefPtr<StyleImage> cursorOrPendingFromValue(CSSPropertyID, CSSCursorImageValue*);
457
458    bool applyPropertyToRegularStyle() const { return m_state.applyPropertyToRegularStyle(); }
459    bool applyPropertyToVisitedLinkStyle() const { return m_state.applyPropertyToVisitedLinkStyle(); }
460
461    CSSToStyleMap* styleMap() { return &m_styleMap; }
462    InspectorCSSOMWrappers& inspectorCSSOMWrappers() { return m_inspectorCSSOMWrappers; }
463    const FontDescription& fontDescription() { return m_state.fontDescription(); }
464    const FontDescription& parentFontDescription() { return m_state.parentFontDescription(); }
465    void setFontDescription(const FontDescription& fontDescription) { m_state.setFontDescription(fontDescription); }
466    void setZoom(float f) { m_state.setZoom(f); }
467    void setEffectiveZoom(float f) { m_state.setEffectiveZoom(f); }
468    void setWritingMode(WritingMode writingMode) { m_state.setWritingMode(writingMode); }
469    void setTextOrientation(TextOrientation textOrientation) { m_state.setTextOrientation(textOrientation); }
470
471private:
472    static RenderStyle* s_styleNotYetAvailable;
473
474    void cacheBorderAndBackground();
475
476    bool canShareStyleWithControl(StyledElement*) const;
477
478    void applyProperty(CSSPropertyID, CSSValue*);
479
480    void applySVGProperty(CSSPropertyID, CSSValue*);
481
482    PassRefPtr<StyleImage> loadPendingImage(const StylePendingImage&, const ResourceLoaderOptions&);
483    PassRefPtr<StyleImage> loadPendingImage(const StylePendingImage&);
484    void loadPendingImages();
485#if ENABLE(CSS_SHAPES)
486    void loadPendingShapeImage(ShapeValue*);
487#endif
488
489    static unsigned computeMatchedPropertiesHash(const MatchedProperties*, unsigned size);
490    struct MatchedPropertiesCacheItem {
491        Vector<MatchedProperties> matchedProperties;
492        MatchRanges ranges;
493        RefPtr<RenderStyle> renderStyle;
494        RefPtr<RenderStyle> parentRenderStyle;
495    };
496    const MatchedPropertiesCacheItem* findFromMatchedPropertiesCache(unsigned hash, const MatchResult&);
497    void addToMatchedPropertiesCache(const RenderStyle*, const RenderStyle* parentStyle, unsigned hash, const MatchResult&);
498
499    // Every N additions to the matched declaration cache trigger a sweep where entries holding
500    // the last reference to a style declaration are garbage collected.
501    void sweepMatchedPropertiesCache(Timer<StyleResolver>*);
502
503    bool classNamesAffectedByRules(const SpaceSplitString&) const;
504    bool sharingCandidateHasIdenticalStyleAffectingAttributes(StyledElement*) const;
505
506    Length parseSnapCoordinate(CSSPrimitiveValue&);
507    Length parseSnapCoordinate(CSSValueList&, unsigned offset);
508    LengthSize parseSnapCoordinatePair(CSSValueList&, unsigned offset);
509    ScrollSnapPoints parseSnapPoints(CSSValue&);
510
511    unsigned m_matchedPropertiesCacheAdditionsSinceLastSweep;
512
513    typedef HashMap<unsigned, MatchedPropertiesCacheItem> MatchedPropertiesCache;
514    MatchedPropertiesCache m_matchedPropertiesCache;
515
516    Timer<StyleResolver> m_matchedPropertiesCacheSweepTimer;
517
518    std::unique_ptr<MediaQueryEvaluator> m_medium;
519    RefPtr<RenderStyle> m_rootDefaultStyle;
520
521    Document& m_document;
522    SelectorFilter m_selectorFilter;
523
524    bool m_matchAuthorAndUserStyles;
525
526    RefPtr<CSSFontSelector> m_fontSelector;
527    Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
528
529#if ENABLE(CSS_DEVICE_ADAPTATION)
530    RefPtr<ViewportStyleResolver> m_viewportStyleResolver;
531#endif
532
533    const DeprecatedStyleBuilder& m_deprecatedStyleBuilder;
534
535    CSSToStyleMap m_styleMap;
536    InspectorCSSOMWrappers m_inspectorCSSOMWrappers;
537
538    State m_state;
539
540    friend class DeprecatedStyleBuilder;
541    friend bool operator==(const MatchedProperties&, const MatchedProperties&);
542    friend bool operator!=(const MatchedProperties&, const MatchedProperties&);
543    friend bool operator==(const MatchRanges&, const MatchRanges&);
544    friend bool operator!=(const MatchRanges&, const MatchRanges&);
545};
546
547inline bool StyleResolver::hasSelectorForAttribute(const Element& element, const AtomicString &attributeName) const
548{
549    ASSERT(!attributeName.isEmpty());
550    if (element.isHTMLElement())
551        return m_ruleSets.features().attributeCanonicalLocalNamesInRules.contains(attributeName.impl());
552    return m_ruleSets.features().attributeLocalNamesInRules.contains(attributeName.impl());
553}
554
555inline bool StyleResolver::hasSelectorForClass(const AtomicString& classValue) const
556{
557    ASSERT(!classValue.isEmpty());
558    return m_ruleSets.features().classesInRules.contains(classValue.impl());
559}
560
561inline bool StyleResolver::hasSelectorForId(const AtomicString& idValue) const
562{
563    ASSERT(!idValue.isEmpty());
564    return m_ruleSets.features().idsInRules.contains(idValue.impl());
565}
566
567inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement)
568{
569    if (!regionSelector || !regionElement)
570        return false;
571
572    SelectorChecker selectorChecker(regionElement->document());
573    for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
574        SelectorChecker::CheckingContext selectorCheckingContext(SelectorChecker::Mode::QueryingRules);
575        if (selectorChecker.match(s, regionElement, selectorCheckingContext))
576            return true;
577    }
578    return false;
579}
580
581class StyleResolverParentPusher {
582public:
583    StyleResolverParentPusher(Element* parent)
584        : m_parent(parent)
585        , m_pushedStyleResolver(0)
586    { }
587    void push()
588    {
589        if (m_pushedStyleResolver)
590            return;
591        m_pushedStyleResolver = &m_parent->document().ensureStyleResolver();
592        m_pushedStyleResolver->pushParentElement(m_parent);
593    }
594    ~StyleResolverParentPusher()
595    {
596        if (!m_pushedStyleResolver)
597            return;
598        // This tells us that our pushed style selector is in a bad state,
599        // so we should just bail out in that scenario.
600        ASSERT(m_pushedStyleResolver == &m_parent->document().ensureStyleResolver());
601        if (m_pushedStyleResolver != &m_parent->document().ensureStyleResolver())
602            return;
603        m_pushedStyleResolver->popParentElement(m_parent);
604    }
605   
606private:
607    Element* m_parent;
608    StyleResolver* m_pushedStyleResolver;
609};
610
611} // namespace WebCore
612
613#endif // StyleResolver_h
Note: See TracBrowser for help on using the repository browser.