- a/Source/WebCore/ChangeLog +89 lines
Lines 1-3 a/Source/WebCore/ChangeLog_sec1
1
2013-03-07  Sheriff Bot  <webkit.review.bot@gmail.com>
2
3
        Unreviewed, rolling out r145059.
4
        http://trac.webkit.org/changeset/145059
5
        https://bugs.webkit.org/show_bug.cgi?id=111707
6
7
        crash webkit build (Requested by tasak on #webkit).
8
9
        * CMakeLists.txt:
10
        * GNUmakefile.list.am:
11
        * Target.pri:
12
        * WebCore.gypi:
13
        * WebCore.xcodeproj/project.pbxproj:
14
        * css/CSSAllInOne.cpp:
15
        * css/DocumentRuleSets.cpp:
16
        (WebCore::ShadowDistributedRules::collectMatchRequests):
17
        * css/DocumentRuleSets.h:
18
        * css/ElementRuleCollector.cpp: Removed.
19
        * css/ElementRuleCollector.h: Removed.
20
        * css/PageRuleCollector.cpp: Removed.
21
        * css/PageRuleCollector.h: Removed.
22
        * css/StyleResolver.cpp:
23
        (WebCore::leftToRightDeclaration):
24
        (WebCore):
25
        (WebCore::rightToLeftDeclaration):
26
        (WebCore::StyleResolver::State::ensureRuleList):
27
        (WebCore::StyleResolver::State::clear):
28
        (WebCore::StyleResolver::addMatchedProperties):
29
        (WebCore::StyleResolver::addElementStyleProperties):
30
        (MatchingUARulesScope):
31
        (WebCore::MatchingUARulesScope::MatchingUARulesScope):
32
        (WebCore::MatchingUARulesScope::~MatchingUARulesScope):
33
        (WebCore::MatchingUARulesScope::isMatchingUARules):
34
        (WebCore::StyleResolver::collectMatchingRules):
35
        (WebCore::StyleResolver::collectMatchingRulesForRegion):
36
        (WebCore::StyleResolver::sortAndTransferMatchedRules):
37
        (WebCore::StyleResolver::matchScopedAuthorRules):
38
        (WebCore::StyleResolver::matchHostRules):
39
        (WebCore::StyleResolver::matchAuthorRules):
40
        (WebCore::StyleResolver::matchUserRules):
41
        (WebCore::StyleResolver::matchUARules):
42
        (WebCore::StyleResolver::collectMatchingRulesForList):
43
        (WebCore::compareRules):
44
        (WebCore::StyleResolver::sortMatchedRules):
45
        (WebCore::StyleResolver::matchAllRules):
46
        (WebCore::StyleResolver::State::initForStyleResolve):
47
        (WebCore::StyleResolver::styleSharingCandidateMatchesRuleSet):
48
        (WebCore::StyleResolver::styleForElement):
49
        (WebCore::StyleResolver::styleForKeyframe):
50
        (WebCore::StyleResolver::pseudoStyleForElement):
51
        (WebCore::StyleResolver::styleForPage):
52
        (WebCore::StyleResolver::pseudoStyleRulesForElement):
53
        (WebCore::StyleResolver::ruleMatches):
54
        (WebCore::StyleResolver::checkRegionSelector):
55
        (WebCore::comparePageRules):
56
        (WebCore::StyleResolver::matchPageRules):
57
        (WebCore::checkPageSelectorComponents):
58
        (WebCore::StyleResolver::matchPageRulesForList):
59
        (WebCore::StyleResolver::isLeftPage):
60
        (WebCore::StyleResolver::isFirstPage):
61
        (WebCore::StyleResolver::pageName):
62
        * css/StyleResolver.h:
63
        (WebCore::MatchRequest::MatchRequest):
64
        (MatchRequest):
65
        (StyleResolver):
66
        (MatchResult):
67
        (WebCore::StyleResolver::State::State):
68
        (State):
69
        (WebCore::StyleResolver::State::takeRuleList):
70
        (WebCore::StyleResolver::State::setSameOriginOnly):
71
        (WebCore::StyleResolver::State::isSameOriginOnly):
72
        (WebCore::StyleResolver::State::pseudoStyleRequest):
73
        (WebCore::StyleResolver::State::setMode):
74
        (WebCore::StyleResolver::State::mode):
75
        (WebCore::StyleResolver::State::matchedRules):
76
        (WebCore::StyleResolver::State::addMatchedRule):
77
        * inspector/InspectorCSSAgent.cpp:
78
        (WebCore::InspectorCSSAgent::willMatchRule):
79
        * inspector/InspectorCSSAgent.h:
80
        (WebCore):
81
        (InspectorCSSAgent):
82
        * inspector/InspectorInstrumentation.cpp:
83
        (WebCore):
84
        (WebCore::InspectorInstrumentation::willMatchRuleImpl):
85
        * inspector/InspectorInstrumentation.h:
86
        (WebCore):
87
        (InspectorInstrumentation):
88
        (WebCore::InspectorInstrumentation::willMatchRule):
89
1
2013-03-07  Takashi Sakamoto  <tasak@google.com>
90
2013-03-07  Takashi Sakamoto  <tasak@google.com>
2
91
3
        [Refactoring] Implement RuleCollector
92
        [Refactoring] Implement RuleCollector
- a/Source/WebCore/CMakeLists.txt -2 lines
Lines 1070-1076 set(WebCore_SOURCES a/Source/WebCore/CMakeLists.txt_sec1
1070
    css/CSSValuePool.cpp
1070
    css/CSSValuePool.cpp
1071
    css/DOMWindowCSS.cpp
1071
    css/DOMWindowCSS.cpp
1072
    css/DocumentRuleSets.cpp
1072
    css/DocumentRuleSets.cpp
1073
    css/ElementRuleCollector.cpp
1074
    css/FontFeatureValue.cpp
1073
    css/FontFeatureValue.cpp
1075
    css/FontValue.cpp
1074
    css/FontValue.cpp
1076
    css/InspectorCSSOMWrappers.cpp
1075
    css/InspectorCSSOMWrappers.cpp
Lines 1083-1089 set(WebCore_SOURCES a/Source/WebCore/CMakeLists.txt_sec2
1083
    css/MediaQueryList.cpp
1082
    css/MediaQueryList.cpp
1084
    css/MediaQueryListListener.cpp
1083
    css/MediaQueryListListener.cpp
1085
    css/MediaQueryMatcher.cpp
1084
    css/MediaQueryMatcher.cpp
1086
    css/PageRuleCollector.cpp
1087
    css/PropertySetCSSStyleDeclaration.cpp
1085
    css/PropertySetCSSStyleDeclaration.cpp
1088
    css/RGBColor.cpp
1086
    css/RGBColor.cpp
1089
    css/RuleFeature.h
1087
    css/RuleFeature.h
- a/Source/WebCore/GNUmakefile.list.am -4 lines
Lines 2660-2667 webcore_sources += \ a/Source/WebCore/GNUmakefile.list.am_sec1
2660
	Source/WebCore/css/DashboardRegion.h \
2660
	Source/WebCore/css/DashboardRegion.h \
2661
	Source/WebCore/css/DocumentRuleSets.cpp \
2661
	Source/WebCore/css/DocumentRuleSets.cpp \
2662
	Source/WebCore/css/DocumentRuleSets.h \
2662
	Source/WebCore/css/DocumentRuleSets.h \
2663
	Source/WebCore/css/ElementRuleCollector.cpp \
2664
	Source/WebCore/css/ElementRuleCollector.h \
2665
	Source/WebCore/css/FontFeatureValue.cpp \
2663
	Source/WebCore/css/FontFeatureValue.cpp \
2666
	Source/WebCore/css/FontFeatureValue.h \
2664
	Source/WebCore/css/FontFeatureValue.h \
2667
	Source/WebCore/css/FontValue.cpp \
2665
	Source/WebCore/css/FontValue.cpp \
Lines 2686-2693 webcore_sources += \ a/Source/WebCore/GNUmakefile.list.am_sec2
2686
	Source/WebCore/css/MediaQueryListListener.h \
2684
	Source/WebCore/css/MediaQueryListListener.h \
2687
	Source/WebCore/css/MediaQueryMatcher.cpp \
2685
	Source/WebCore/css/MediaQueryMatcher.cpp \
2688
	Source/WebCore/css/MediaQueryMatcher.h \
2686
	Source/WebCore/css/MediaQueryMatcher.h \
2689
	Source/WebCore/css/PageRuleCollector.cpp \
2690
	Source/WebCore/css/PageRuleCollector.h \
2691
	Source/WebCore/css/Pair.h \
2687
	Source/WebCore/css/Pair.h \
2692
	Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp \
2688
	Source/WebCore/css/PropertySetCSSStyleDeclaration.cpp \
2693
	Source/WebCore/css/PropertySetCSSStyleDeclaration.h \
2689
	Source/WebCore/css/PropertySetCSSStyleDeclaration.h \
- a/Source/WebCore/Target.pri -2 lines
Lines 305-311 SOURCES += \ a/Source/WebCore/Target.pri_sec1
305
    css/CSSValuePool.cpp \
305
    css/CSSValuePool.cpp \
306
    css/DOMWindowCSS.cpp \
306
    css/DOMWindowCSS.cpp \
307
    css/DocumentRuleSets.cpp \
307
    css/DocumentRuleSets.cpp \
308
    css/ElementRuleCollector.cpp \
309
    css/FontFeatureValue.cpp \
308
    css/FontFeatureValue.cpp \
310
    css/FontValue.cpp \
309
    css/FontValue.cpp \
311
    css/InspectorCSSOMWrappers.cpp \
310
    css/InspectorCSSOMWrappers.cpp \
Lines 318-324 SOURCES += \ a/Source/WebCore/Target.pri_sec2
318
    css/MediaQueryList.cpp \
317
    css/MediaQueryList.cpp \
319
    css/MediaQueryListListener.cpp \
318
    css/MediaQueryListListener.cpp \
320
    css/MediaQueryMatcher.cpp \
319
    css/MediaQueryMatcher.cpp \
321
    css/PageRuleCollector.cpp \
322
    css/PropertySetCSSStyleDeclaration.cpp \
320
    css/PropertySetCSSStyleDeclaration.cpp \
323
    css/RGBColor.cpp \
321
    css/RGBColor.cpp \
324
    css/RuleFeature.cpp \
322
    css/RuleFeature.cpp \
- a/Source/WebCore/WebCore.gypi -4 lines
Lines 1651-1658 a/Source/WebCore/WebCore.gypi_sec1
1651
            'css/DashboardRegion.h',
1651
            'css/DashboardRegion.h',
1652
            'css/DocumentRuleSets.cpp',
1652
            'css/DocumentRuleSets.cpp',
1653
            'css/DocumentRuleSets.h',
1653
            'css/DocumentRuleSets.h',
1654
            'css/ElementRuleCollector.cpp',
1655
            'css/ElementRuleCollector.h',
1656
            'css/FontFeatureValue.cpp',
1654
            'css/FontFeatureValue.cpp',
1657
            'css/FontFeatureValue.h',
1655
            'css/FontFeatureValue.h',
1658
            'css/FontValue.cpp',
1656
            'css/FontValue.cpp',
Lines 1676-1683 a/Source/WebCore/WebCore.gypi_sec2
1676
            'css/MediaQueryListListener.h',
1674
            'css/MediaQueryListListener.h',
1677
            'css/MediaQueryMatcher.cpp',
1675
            'css/MediaQueryMatcher.cpp',
1678
            'css/MediaQueryMatcher.h',
1676
            'css/MediaQueryMatcher.h',
1679
            'css/PageRuleCollector.cpp',
1680
            'css/PageRuleCollector.h',
1681
            'css/PropertySetCSSStyleDeclaration.cpp',
1677
            'css/PropertySetCSSStyleDeclaration.cpp',
1682
            'css/PropertySetCSSStyleDeclaration.h',
1678
            'css/PropertySetCSSStyleDeclaration.h',
1683
            'css/RGBColor.cpp',
1679
            'css/RGBColor.cpp',
- a/Source/WebCore/WebCore.xcodeproj/project.pbxproj -16 lines
Lines 6550-6559 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec1
6550
		FBD6AF8B15EF25E5008B7110 /* CSSBasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */; };
6550
		FBD6AF8B15EF25E5008B7110 /* CSSBasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */; };
6551
		FBD6AF8C15EF2604008B7110 /* BasicShapes.h in Headers */ = {isa = PBXBuildFile; fileRef = FBD6AF8315EF21A3008B7110 /* BasicShapes.h */; settings = {ATTRIBUTES = (Private, ); }; };
6551
		FBD6AF8C15EF2604008B7110 /* BasicShapes.h in Headers */ = {isa = PBXBuildFile; fileRef = FBD6AF8315EF21A3008B7110 /* BasicShapes.h */; settings = {ATTRIBUTES = (Private, ); }; };
6552
		FBD6AF8D15EF260A008B7110 /* BasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8215EF21A3008B7110 /* BasicShapes.cpp */; };
6552
		FBD6AF8D15EF260A008B7110 /* BasicShapes.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBD6AF8215EF21A3008B7110 /* BasicShapes.cpp */; };
6553
		FBDB619B16D6032A00BB3394 /* ElementRuleCollector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBDB619A16D6032A00BB3394 /* ElementRuleCollector.cpp */; };
6554
		FBDB619D16D6034600BB3394 /* PageRuleCollector.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBDB619C16D6034600BB3394 /* PageRuleCollector.cpp */; };
6555
		FBDB619F16D6036500BB3394 /* ElementRuleCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = FBDB619E16D6036500BB3394 /* ElementRuleCollector.h */; };
6556
		FBDB61A116D6037E00BB3394 /* PageRuleCollector.h in Headers */ = {isa = PBXBuildFile; fileRef = FBDB61A016D6037E00BB3394 /* PageRuleCollector.h */; };
6557
		FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */; };
6553
		FBF89045169E9F1F0052D86E /* CSSGroupingRule.cpp in Sources */ = {isa = PBXBuildFile; fileRef = FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */; };
6558
		FC54D05716A7673100575E4D /* CSSSupportsRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FC63BDB1167AABAC00F9380F /* CSSSupportsRule.h */; };
6554
		FC54D05716A7673100575E4D /* CSSSupportsRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FC63BDB1167AABAC00F9380F /* CSSSupportsRule.h */; };
6559
		FC54D05816A7676E00575E4D /* JSCSSSupportsRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FC84802E167AB444008CD100 /* JSCSSSupportsRule.h */; };
6555
		FC54D05816A7676E00575E4D /* JSCSSSupportsRule.h in Headers */ = {isa = PBXBuildFile; fileRef = FC84802E167AB444008CD100 /* JSCSSSupportsRule.h */; };
Lines 14304-14313 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec2
14304
		FBD6AF8515EF21D4008B7110 /* BasicShapeFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicShapeFunctions.h; sourceTree = "<group>"; };
14300
		FBD6AF8515EF21D4008B7110 /* BasicShapeFunctions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BasicShapeFunctions.h; sourceTree = "<group>"; };
14305
		FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBasicShapes.cpp; sourceTree = "<group>"; };
14301
		FBD6AF8615EF21D4008B7110 /* CSSBasicShapes.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSBasicShapes.cpp; sourceTree = "<group>"; };
14306
		FBD6AF8715EF21D4008B7110 /* CSSBasicShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBasicShapes.h; sourceTree = "<group>"; };
14302
		FBD6AF8715EF21D4008B7110 /* CSSBasicShapes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSBasicShapes.h; sourceTree = "<group>"; };
14307
		FBDB619A16D6032A00BB3394 /* ElementRuleCollector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = ElementRuleCollector.cpp; sourceTree = "<group>"; };
14308
		FBDB619C16D6034600BB3394 /* PageRuleCollector.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PageRuleCollector.cpp; sourceTree = "<group>"; };
14309
		FBDB619E16D6036500BB3394 /* ElementRuleCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ElementRuleCollector.h; sourceTree = "<group>"; };
14310
		FBDB61A016D6037E00BB3394 /* PageRuleCollector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PageRuleCollector.h; sourceTree = "<group>"; };
14311
		FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGroupingRule.cpp; sourceTree = "<group>"; };
14303
		FBF89044169E9F1F0052D86E /* CSSGroupingRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSGroupingRule.cpp; sourceTree = "<group>"; };
14312
		FC63BDB0167AABAC00F9380F /* CSSSupportsRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSSupportsRule.cpp; sourceTree = "<group>"; };
14304
		FC63BDB0167AABAC00F9380F /* CSSSupportsRule.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSSupportsRule.cpp; sourceTree = "<group>"; };
14313
		FC63BDB1167AABAC00F9380F /* CSSSupportsRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSupportsRule.h; sourceTree = "<group>"; };
14305
		FC63BDB1167AABAC00F9380F /* CSSSupportsRule.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSSupportsRule.h; sourceTree = "<group>"; };
Lines 22134-22141 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec3
22134
				FC9A0F71164094CF003D6B8D /* DOMWindowCSS.cpp */,
22126
				FC9A0F71164094CF003D6B8D /* DOMWindowCSS.cpp */,
22135
				FC9A0F72164094CF003D6B8D /* DOMWindowCSS.h */,
22127
				FC9A0F72164094CF003D6B8D /* DOMWindowCSS.h */,
22136
				FC9A0F73164094CF003D6B8D /* DOMWindowCSS.idl */,
22128
				FC9A0F73164094CF003D6B8D /* DOMWindowCSS.idl */,
22137
				FBDB619E16D6036500BB3394 /* ElementRuleCollector.h */,
22138
				FBDB619A16D6032A00BB3394 /* ElementRuleCollector.cpp */,
22139
				4A6E9FC213C17D1D0046A7F8 /* FontFeatureValue.h */,
22129
				4A6E9FC213C17D1D0046A7F8 /* FontFeatureValue.h */,
22140
				A80E6CC70A1989CA007FB8C5 /* FontValue.cpp */,
22130
				A80E6CC70A1989CA007FB8C5 /* FontValue.cpp */,
22141
				A80E6CC30A1989CA007FB8C5 /* FontValue.h */,
22131
				A80E6CC30A1989CA007FB8C5 /* FontValue.h */,
Lines 22171-22178 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec4
22171
				D3A94A35122DABAC00A37BBC /* MediaQueryListListener.idl */,
22161
				D3A94A35122DABAC00A37BBC /* MediaQueryListListener.idl */,
22172
				D3AA10F1123A98AA0092152B /* MediaQueryMatcher.cpp */,
22162
				D3AA10F1123A98AA0092152B /* MediaQueryMatcher.cpp */,
22173
				D3AA10F2123A98AA0092152B /* MediaQueryMatcher.h */,
22163
				D3AA10F2123A98AA0092152B /* MediaQueryMatcher.h */,
22174
				FBDB61A016D6037E00BB3394 /* PageRuleCollector.h */,
22175
				FBDB619C16D6034600BB3394 /* PageRuleCollector.cpp */,
22176
				A80E6CD10A1989CA007FB8C5 /* Pair.h */,
22164
				A80E6CD10A1989CA007FB8C5 /* Pair.h */,
22177
				3189E6DB16B2103500386EA3 /* plugIns.css */,
22165
				3189E6DB16B2103500386EA3 /* plugIns.css */,
22178
				E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */,
22166
				E4BBED0C14F4025D003F0B98 /* PropertySetCSSStyleDeclaration.cpp */,
Lines 26704-26711 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec5
26704
				7E66E23416D6EB6C00F7E7FF /* WebGLCompressedTextureATC.h in Headers */,
26692
				7E66E23416D6EB6C00F7E7FF /* WebGLCompressedTextureATC.h in Headers */,
26705
				7EA30F6A16DFFE7500257D0B /* JSWebGLCompressedTextureATC.h in Headers */,
26693
				7EA30F6A16DFFE7500257D0B /* JSWebGLCompressedTextureATC.h in Headers */,
26706
 				2D8287F716E4A0380086BD00 /* HitTestLocation.h in Headers */,
26694
 				2D8287F716E4A0380086BD00 /* HitTestLocation.h in Headers */,
26707
				FBDB619F16D6036500BB3394 /* ElementRuleCollector.h in Headers */,
26708
				FBDB61A116D6037E00BB3394 /* PageRuleCollector.h in Headers */,
26709
			);
26695
			);
26710
			runOnlyForDeploymentPostprocessing = 0;
26696
			runOnlyForDeploymentPostprocessing = 0;
26711
		};
26697
		};
Lines 29909-29916 a/Source/WebCore/WebCore.xcodeproj/project.pbxproj_sec6
29909
				7E66E23316D6EB6C00F7E7FF /* WebGLCompressedTextureATC.cpp in Sources */,
29895
				7E66E23316D6EB6C00F7E7FF /* WebGLCompressedTextureATC.cpp in Sources */,
29910
				7EA30F6916DFFE7500257D0B /* JSWebGLCompressedTextureATC.cpp in Sources */,
29896
				7EA30F6916DFFE7500257D0B /* JSWebGLCompressedTextureATC.cpp in Sources */,
29911
 				2D8287F616E4A0380086BD00 /* HitTestLocation.cpp in Sources */,
29897
 				2D8287F616E4A0380086BD00 /* HitTestLocation.cpp in Sources */,
29912
				FBDB619B16D6032A00BB3394 /* ElementRuleCollector.cpp in Sources */,
29913
				FBDB619D16D6034600BB3394 /* PageRuleCollector.cpp in Sources */,
29914
			);
29898
			);
29915
			runOnlyForDeploymentPostprocessing = 0;
29899
			runOnlyForDeploymentPostprocessing = 0;
29916
		};
29900
		};
- a/Source/WebCore/css/CSSAllInOne.cpp -2 lines
Lines 71-79 a/Source/WebCore/css/CSSAllInOne.cpp_sec1
71
#include "CSSValuePool.cpp"
71
#include "CSSValuePool.cpp"
72
#include "DOMWindowCSS.cpp"
72
#include "DOMWindowCSS.cpp"
73
#include "DocumentRuleSets.cpp"
73
#include "DocumentRuleSets.cpp"
74
#include "ElementRuleCollector.cpp"
75
#include "InspectorCSSOMWrappers.cpp"
74
#include "InspectorCSSOMWrappers.cpp"
76
#include "PageRuleCollector.cpp"
77
#include "RuleFeature.cpp"
75
#include "RuleFeature.cpp"
78
#include "RuleSet.cpp"
76
#include "RuleSet.cpp"
79
#include "SelectorCheckerFastPath.cpp"
77
#include "SelectorCheckerFastPath.cpp"
- a/Source/WebCore/css/DocumentRuleSets.cpp -1 / +1 lines
Lines 53-59 void ShadowDistributedRules::addRule(StyleRule* rule, size_t selectorIndex, Cont a/Source/WebCore/css/DocumentRuleSets.cpp_sec1
53
void ShadowDistributedRules::collectMatchRequests(bool includeEmptyRules, Vector<MatchRequest>& matchRequests)
53
void ShadowDistributedRules::collectMatchRequests(bool includeEmptyRules, Vector<MatchRequest>& matchRequests)
54
{
54
{
55
    for (ShadowDistributedRuleSetMap::iterator it = m_shadowDistributedRuleSetMap.begin(); it != m_shadowDistributedRuleSetMap.end(); ++it)
55
    for (ShadowDistributedRuleSetMap::iterator it = m_shadowDistributedRuleSetMap.begin(); it != m_shadowDistributedRuleSetMap.end(); ++it)
56
        matchRequests.append(MatchRequest(it->value.get(), includeEmptyRules, it->key));
56
        matchRequests.append(MatchRequest(it->value.get(), includeEmptyRules, it->key, SelectorChecker::CrossesBoundary));
57
}
57
}
58
#endif
58
#endif
59
59
- a/Source/WebCore/css/DocumentRuleSets.h -1 lines
Lines 47-53 public: a/Source/WebCore/css/DocumentRuleSets.h_sec1
47
    void addRule(StyleRule*, size_t selectorIndex, ContainerNode* scope, AddRuleFlags);
47
    void addRule(StyleRule*, size_t selectorIndex, ContainerNode* scope, AddRuleFlags);
48
    void collectMatchRequests(bool includeEmptyRules, Vector<MatchRequest>&);
48
    void collectMatchRequests(bool includeEmptyRules, Vector<MatchRequest>&);
49
    void clear() { m_shadowDistributedRuleSetMap.clear(); }
49
    void clear() { m_shadowDistributedRuleSetMap.clear(); }
50
    bool isEmpty() const { return m_shadowDistributedRuleSetMap.isEmpty(); }
51
private:
50
private:
52
    typedef HashMap<const ContainerNode*, OwnPtr<RuleSet> > ShadowDistributedRuleSetMap;
51
    typedef HashMap<const ContainerNode*, OwnPtr<RuleSet> > ShadowDistributedRuleSetMap;
53
    ShadowDistributedRuleSetMap m_shadowDistributedRuleSetMap;
52
    ShadowDistributedRuleSetMap m_shadowDistributedRuleSetMap;
- a/Source/WebCore/css/ElementRuleCollector.cpp -508 lines
Lines 1-508 a/Source/WebCore/css/ElementRuleCollector.cpp_sec1
1
/*
2
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4
 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6
 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7
 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9
 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10
 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11
 * Copyright (C) 2012 Google Inc. All rights reserved.
12
 *
13
 * This library is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Library General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 2 of the License, or (at your option) any later version.
17
 *
18
 * This library is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 * Library General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Library General Public License
24
 * along with this library; see the file COPYING.LIB.  If not, write to
25
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
 * Boston, MA 02110-1301, USA.
27
 */
28
29
#include "config.h"
30
#include "ElementRuleCollector.h"
31
32
#include "CSSDefaultStyleSheets.h"
33
#include "CSSRule.h"
34
#include "CSSRuleList.h"
35
#include "CSSSelector.h"
36
#include "CSSSelectorList.h"
37
#include "CSSValueKeywords.h"
38
#include "HTMLElement.h"
39
#include "RenderRegion.h"
40
#include "SVGElement.h"
41
#include "SelectorCheckerFastPath.h"
42
#include "SiblingTraversalStrategies.h"
43
#include "StylePropertySet.h"
44
#include "StyledElement.h"
45
46
#include <wtf/TemporaryChange.h>
47
48
namespace WebCore {
49
50
static StylePropertySet* leftToRightDeclaration()
51
{
52
    DEFINE_STATIC_LOCAL(RefPtr<StylePropertySet>, leftToRightDecl, (StylePropertySet::create()));
53
    if (leftToRightDecl->isEmpty())
54
        leftToRightDecl->setProperty(CSSPropertyDirection, CSSValueLtr);
55
    return leftToRightDecl.get();
56
}
57
58
static StylePropertySet* rightToLeftDeclaration()
59
{
60
    DEFINE_STATIC_LOCAL(RefPtr<StylePropertySet>, rightToLeftDecl, (StylePropertySet::create()));
61
    if (rightToLeftDecl->isEmpty())
62
        rightToLeftDecl->setProperty(CSSPropertyDirection, CSSValueRtl);
63
    return rightToLeftDecl.get();
64
}
65
66
StyleResolver::MatchResult& ElementRuleCollector::matchedResult()
67
{
68
    ASSERT(m_mode == SelectorChecker::ResolvingStyle);
69
    return m_result;
70
}
71
72
PassRefPtr<CSSRuleList> ElementRuleCollector::matchedRuleList()
73
{
74
    ASSERT(m_mode == SelectorChecker::CollectingRules);
75
    return m_ruleList.release();
76
}
77
78
inline void ElementRuleCollector::addMatchedRule(const RuleData* rule)
79
{
80
    if (!m_matchedRules)
81
        m_matchedRules = adoptPtr(new Vector<const RuleData*, 32>);
82
    m_matchedRules->append(rule);
83
}
84
85
inline void ElementRuleCollector::clearMatchedRules()
86
{
87
    if (!m_matchedRules)
88
        return;
89
    m_matchedRules->clear();
90
}
91
92
inline StaticCSSRuleList* ElementRuleCollector::ensureRuleList()
93
{
94
    if (!m_ruleList)
95
        m_ruleList = StaticCSSRuleList::create();
96
    return m_ruleList.get();
97
}
98
99
inline void ElementRuleCollector::addElementStyleProperties(const StylePropertySet* propertySet, bool isCacheable)
100
{
101
    if (!propertySet)
102
        return;
103
    m_result.ranges.lastAuthorRule = m_result.matchedProperties.size();
104
    if (m_result.ranges.firstAuthorRule == -1)
105
        m_result.ranges.firstAuthorRule = m_result.ranges.lastAuthorRule;
106
    m_result.addMatchedProperties(propertySet);
107
    if (!isCacheable)
108
        m_result.isCacheable = false;
109
}
110
111
void ElementRuleCollector::collectMatchingRules(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
112
{
113
    ASSERT(matchRequest.ruleSet);
114
    ASSERT(m_state.element());
115
116
    const StyleResolver::State& state = m_state;
117
    Element* element = state.element();
118
    const StyledElement* styledElement = state.styledElement();
119
    const AtomicString& pseudoId = element->shadowPseudoId();
120
    if (!pseudoId.isEmpty()) {
121
        ASSERT(styledElement);
122
        collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
123
    }
124
125
#if ENABLE(VIDEO_TRACK)
126
    if (element->isWebVTTElement())
127
        collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
128
#endif
129
    // Check whether other types of rules are applicable in the current tree scope. Criteria for this:
130
    // a) it's a UA rule
131
    // b) the tree scope allows author rules
132
    // c) the rules comes from a scoped style sheet within the same tree scope
133
    TreeScope* treeScope = element->treeScope();
134
    if (!m_matchingUARules
135
        && !treeScope->applyAuthorStyles()
136
        && (!matchRequest.scope || matchRequest.scope->treeScope() != treeScope)
137
        && m_behaviorAtBoundary == SelectorChecker::DoesNotCrossBoundary)
138
        return;
139
140
    // We need to collect the rules for id, class, tag, and everything else into a buffer and
141
    // then sort the buffer.
142
    if (element->hasID())
143
        collectMatchingRulesForList(matchRequest.ruleSet->idRules(element->idForStyleResolution().impl()), matchRequest, ruleRange);
144
    if (styledElement && styledElement->hasClass()) {
145
        for (size_t i = 0; i < styledElement->classNames().size(); ++i)
146
            collectMatchingRulesForList(matchRequest.ruleSet->classRules(styledElement->classNames()[i].impl()), matchRequest, ruleRange);
147
    }
148
149
    if (element->isLink())
150
        collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
151
    if (SelectorChecker::matchesFocusPseudoClass(element))
152
        collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
153
    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
154
    collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
155
}
156
157
void ElementRuleCollector::collectMatchingRulesForRegion(const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
158
{
159
    if (!m_regionForStyling)
160
        return;
161
162
    unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size();
163
    for (unsigned i = 0; i < size; ++i) {
164
        const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).selector;
165
        if (checkRegionSelector(regionSelector, static_cast<Element*>(m_regionForStyling->node()))) {
166
            RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
167
            ASSERT(regionRules);
168
            collectMatchingRules(MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), ruleRange);
169
        }
170
    }
171
}
172
173
void ElementRuleCollector::sortAndTransferMatchedRules()
174
{
175
    const StyleResolver::State& state = m_state;
176
177
    if (!m_matchedRules || m_matchedRules->isEmpty())
178
        return;
179
180
    sortMatchedRules();
181
182
    Vector<const RuleData*, 32>& matchedRules = *m_matchedRules;
183
    if (m_mode == SelectorChecker::CollectingRules) {
184
        for (unsigned i = 0; i < matchedRules.size(); ++i)
185
            ensureRuleList()->rules().append(matchedRules[i]->rule()->createCSSOMWrapper());
186
        return;
187
    }
188
189
    // Now transfer the set of matched rules over to our list of declarations.
190
    for (unsigned i = 0; i < matchedRules.size(); i++) {
191
        if (state.style() && matchedRules[i]->containsUncommonAttributeSelector())
192
            state.style()->setUnique();
193
        m_result.addMatchedProperties(matchedRules[i]->rule()->properties(), matchedRules[i]->rule(), matchedRules[i]->linkMatchType(), matchedRules[i]->propertyWhitelistType());
194
    }
195
}
196
197
void ElementRuleCollector::matchScopedAuthorRules(bool includeEmptyRules)
198
{
199
#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
200
    if (!m_scopeResolver)
201
        return;
202
203
    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
204
    if (m_scopeResolver->hasScopedStyles() && m_scopeResolver->ensureStackConsistency(m_state.element())) {
205
        bool applyAuthorStyles = m_state.element()->treeScope()->applyAuthorStyles();
206
        bool documentScope = true;
207
        unsigned scopeSize = m_scopeResolver->stackSize();
208
        for (unsigned i = 0; i < scopeSize; ++i) {
209
            clearMatchedRules();
210
            m_result.ranges.lastAuthorRule = m_result.matchedProperties.size() - 1;
211
212
            const StyleScopeResolver::StackFrame& frame = m_scopeResolver->stackFrameAt(i);
213
            documentScope = documentScope && !frame.m_scope->isInShadowTree();
214
            if (documentScope) {
215
                if (!applyAuthorStyles)
216
                    continue;
217
            } else {
218
                if (!m_scopeResolver->matchesStyleBounds(frame))
219
                    continue;
220
            }
221
222
            MatchRequest matchRequest(frame.m_ruleSet, includeEmptyRules, frame.m_scope);
223
            StyleResolver::RuleRange ruleRange = m_result.ranges.authorRuleRange();
224
            collectMatchingRules(matchRequest, ruleRange);
225
            collectMatchingRulesForRegion(matchRequest, ruleRange);
226
            sortAndTransferMatchedRules();
227
        }
228
    }
229
230
    matchHostRules(includeEmptyRules);
231
#else
232
    UNUSED_PARAM(includeEmptyRules);
233
#endif
234
}
235
236
void ElementRuleCollector::matchHostRules(bool includeEmptyRules)
237
{
238
#if ENABLE(SHADOW_DOM)
239
    ASSERT(m_scopeResolver);
240
241
    clearMatchedRules();
242
    m_result.ranges.lastAuthorRule = m_result.matchedProperties.size() - 1;
243
244
    Vector<RuleSet*> matchedRules;
245
    m_scopeResolver->matchHostRules(m_state.element(), matchedRules);
246
    if (matchedRules.isEmpty())
247
        return;
248
249
    for (unsigned i = matchedRules.size(); i > 0; --i) {
250
        StyleResolver::RuleRange ruleRange = m_result.ranges.authorRuleRange();
251
        collectMatchingRules(MatchRequest(matchedRules.at(i-1), includeEmptyRules, m_state.element()), ruleRange);
252
    }
253
    sortAndTransferMatchedRules();
254
#else
255
    UNUSED_PARAM(includeEmptyRules);
256
#endif
257
}
258
259
#if ENABLE(SHADOW_DOM)
260
inline void ElementRuleCollector::matchShadowDistributedRules(bool includeEmptyRules, StyleResolver::RuleRange& ruleRange)
261
{
262
    if (m_ruleSets.shadowDistributedRules().isEmpty())
263
        return;
264
265
    TemporaryChange<bool> canUseFastReject(m_canUseFastReject, false);
266
    TemporaryChange<SelectorChecker::BehaviorAtBoundary> behaviorAtBoundary(m_behaviorAtBoundary, SelectorChecker::CrossesBoundary);
267
268
    Vector<MatchRequest> matchRequests;
269
    m_ruleSets.shadowDistributedRules().collectMatchRequests(includeEmptyRules, matchRequests);
270
    for (size_t i = 0; i < matchRequests.size(); ++i)
271
        collectMatchingRules(matchRequests[i], ruleRange);
272
}
273
#endif
274
275
void ElementRuleCollector::matchAuthorRules(bool includeEmptyRules)
276
{
277
    clearMatchedRules();
278
    m_result.ranges.lastAuthorRule = m_result.matchedProperties.size() - 1;
279
280
    if (!m_state.element())
281
        return;
282
283
    // Match global author rules.
284
    MatchRequest matchRequest(m_ruleSets.authorStyle(), includeEmptyRules);
285
    StyleResolver::RuleRange ruleRange = m_result.ranges.authorRuleRange();
286
    collectMatchingRules(matchRequest, ruleRange);
287
    collectMatchingRulesForRegion(matchRequest, ruleRange);
288
#if ENABLE(SHADOW_DOM)
289
    matchShadowDistributedRules(includeEmptyRules, ruleRange);
290
#endif
291
    sortAndTransferMatchedRules();
292
293
    matchScopedAuthorRules(includeEmptyRules);
294
}
295
296
void ElementRuleCollector::matchUserRules(bool includeEmptyRules)
297
{
298
    if (!m_ruleSets.userStyle())
299
        return;
300
    
301
    clearMatchedRules();
302
303
    m_result.ranges.lastUserRule = m_result.matchedProperties.size() - 1;
304
    MatchRequest matchRequest(m_ruleSets.userStyle(), includeEmptyRules);
305
    StyleResolver::RuleRange ruleRange = m_result.ranges.userRuleRange();
306
    collectMatchingRules(matchRequest, ruleRange);
307
    collectMatchingRulesForRegion(matchRequest, ruleRange);
308
309
    sortAndTransferMatchedRules();
310
}
311
312
void ElementRuleCollector::matchUARules()
313
{
314
    TemporaryChange<bool> scope(m_matchingUARules, true);
315
316
    // First we match rules from the user agent sheet.
317
    if (CSSDefaultStyleSheets::simpleDefaultStyleSheet)
318
        m_result.isCacheable = false;
319
    RuleSet* userAgentStyleSheet = m_isPrintStyle
320
        ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defaultStyle;
321
    matchUARules(userAgentStyleSheet);
322
323
    // In quirks mode, we match rules from the quirks user agent sheet.
324
    if (document()->inQuirksMode())
325
        matchUARules(CSSDefaultStyleSheets::defaultQuirksStyle);
326
327
    // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
328
    if (document()->isViewSource())
329
        matchUARules(CSSDefaultStyleSheets::viewSourceStyle());
330
}
331
332
void ElementRuleCollector::matchUARules(RuleSet* rules)
333
{
334
    clearMatchedRules();
335
    
336
    m_result.ranges.lastUARule = m_result.matchedProperties.size() - 1;
337
    StyleResolver::RuleRange ruleRange = m_result.ranges.UARuleRange();
338
    collectMatchingRules(MatchRequest(rules), ruleRange);
339
340
    sortAndTransferMatchedRules();
341
}
342
343
inline bool ElementRuleCollector::ruleMatches(const RuleData& ruleData, const ContainerNode* scope, PseudoId& dynamicPseudo)
344
{
345
    const StyleResolver::State& state = m_state;
346
347
    if (ruleData.hasFastCheckableSelector()) {
348
        // We know this selector does not include any pseudo elements.
349
        if (m_pseudoStyleRequest.pseudoId != NOPSEUDO)
350
            return false;
351
        // We know a sufficiently simple single part selector matches simply because we found it from the rule hash.
352
        // This is limited to HTML only so we don't need to check the namespace.
353
        if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && state.element()->isHTMLElement()) {
354
            if (!ruleData.hasMultipartSelector())
355
                return true;
356
        }
357
        if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker::tagMatches(state.element(), ruleData.selector()->tagQName()))
358
            return false;
359
        SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), state.element());
360
        if (!selectorCheckerFastPath.matchesRightmostAttributeSelector())
361
            return false;
362
363
        return selectorCheckerFastPath.matches();
364
    }
365
366
    // Slow path.
367
    SelectorChecker selectorChecker(document(), m_mode);
368
    SelectorChecker::SelectorCheckingContext context(ruleData.selector(), state.element(), SelectorChecker::VisitedMatchEnabled);
369
    context.elementStyle = state.style();
370
    context.scope = scope;
371
    context.pseudoId = m_pseudoStyleRequest.pseudoId;
372
    context.scrollbar = m_pseudoStyleRequest.scrollbar;
373
    context.scrollbarPart = m_pseudoStyleRequest.scrollbarPart;
374
    context.behaviorAtBoundary = m_behaviorAtBoundary;
375
    SelectorChecker::Match match = selectorChecker.match(context, dynamicPseudo, DOMSiblingTraversalStrategy());
376
    if (match != SelectorChecker::SelectorMatches)
377
        return false;
378
    if (m_pseudoStyleRequest.pseudoId != NOPSEUDO && m_pseudoStyleRequest.pseudoId != dynamicPseudo)
379
        return false;
380
    return true;
381
}
382
383
void ElementRuleCollector::collectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, StyleResolver::RuleRange& ruleRange)
384
{
385
    if (!rules)
386
        return;
387
388
    const StyleResolver::State& state = m_state;
389
390
    unsigned size = rules->size();
391
    for (unsigned i = 0; i < size; ++i) {
392
        const RuleData& ruleData = rules->at(i);
393
        if (m_canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maximumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes()))
394
            continue;
395
396
        StyleRule* rule = ruleData.rule();
397
        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchRule(document(), rule, m_inspectorCSSOMWrappers, document()->styleSheetCollection());
398
        PseudoId dynamicPseudo = NOPSEUDO;
399
        if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo)) {
400
            // If the rule has no properties to apply, then ignore it in the non-debug mode.
401
            const StylePropertySet* properties = rule->properties();
402
            if (!properties || (properties->isEmpty() && !matchRequest.includeEmptyRules)) {
403
                InspectorInstrumentation::didMatchRule(cookie, false);
404
                continue;
405
            }
406
            // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed.
407
            if (m_sameOriginOnly && !ruleData.hasDocumentSecurityOrigin()) {
408
                InspectorInstrumentation::didMatchRule(cookie, false);
409
                continue;
410
            }
411
            // If we're matching normal rules, set a pseudo bit if
412
            // we really just matched a pseudo-element.
413
            if (dynamicPseudo != NOPSEUDO && m_pseudoStyleRequest.pseudoId == NOPSEUDO) {
414
                if (m_mode == SelectorChecker::CollectingRules) {
415
                    InspectorInstrumentation::didMatchRule(cookie, false);
416
                    continue;
417
                }
418
                if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID)
419
                    state.style()->setHasPseudoStyle(dynamicPseudo);
420
            } else {
421
                // Update our first/last rule indices in the matched rules array.
422
                ++ruleRange.lastRuleIndex;
423
                if (ruleRange.firstRuleIndex == -1)
424
                    ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
425
426
                // Add this rule to our list of matched rules.
427
                addMatchedRule(&ruleData);
428
                InspectorInstrumentation::didMatchRule(cookie, true);
429
                continue;
430
            }
431
        }
432
        InspectorInstrumentation::didMatchRule(cookie, false);
433
    }
434
}
435
436
static inline bool compareRules(const RuleData* r1, const RuleData* r2)
437
{
438
    unsigned specificity1 = r1->specificity();
439
    unsigned specificity2 = r2->specificity();
440
    return (specificity1 == specificity2) ? r1->position() < r2->position() : specificity1 < specificity2;
441
}
442
443
void ElementRuleCollector::sortMatchedRules()
444
{
445
    ASSERT(m_matchedRules);
446
    std::sort(m_matchedRules->begin(), m_matchedRules->end(), compareRules);
447
}
448
449
void ElementRuleCollector::matchAllRules(bool matchAuthorAndUserStyles, bool includeSMILProperties)
450
{
451
    matchUARules();
452
453
    // Now we check user sheet rules.
454
    if (matchAuthorAndUserStyles)
455
        matchUserRules(false);
456
457
    // Now check author rules, beginning first with presentational attributes mapped from HTML.
458
    if (m_state.styledElement()) {
459
        addElementStyleProperties(m_state.styledElement()->presentationAttributeStyle());
460
461
        // Now we check additional mapped declarations.
462
        // Tables and table cells share an additional mapped rule that must be applied
463
        // after all attributes, since their mapped style depends on the values of multiple attributes.
464
        addElementStyleProperties(m_state.styledElement()->additionalPresentationAttributeStyle());
465
466
        if (m_state.styledElement()->isHTMLElement()) {
467
            bool isAuto;
468
            TextDirection textDirection = toHTMLElement(m_state.styledElement())->directionalityIfhasDirAutoAttribute(isAuto);
469
            if (isAuto)
470
                m_result.addMatchedProperties(textDirection == LTR ? leftToRightDeclaration() : rightToLeftDeclaration());
471
        }
472
    }
473
    
474
    // Check the rules in author sheets next.
475
    if (matchAuthorAndUserStyles)
476
        matchAuthorRules(false);
477
478
    // Now check our inline style attribute.
479
    if (matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->inlineStyle()) {
480
        // Inline style is immutable as long as there is no CSSOM wrapper.
481
        // FIXME: Media control shadow trees seem to have problems with caching.
482
        bool isInlineStyleCacheable = !m_state.styledElement()->inlineStyle()->isMutable() && !m_state.styledElement()->isInShadowTree();
483
        // FIXME: Constify.
484
        addElementStyleProperties(m_state.styledElement()->inlineStyle(), isInlineStyleCacheable);
485
    }
486
487
#if ENABLE(SVG)
488
    // Now check SMIL animation override style.
489
    if (includeSMILProperties && matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->isSVGElement())
490
        addElementStyleProperties(static_cast<SVGElement*>(m_state.styledElement())->animatedSMILStyleProperties(), false /* isCacheable */);
491
#else
492
    UNUSED_PARAM(includeSMILProperties);
493
#endif
494
}
495
496
bool ElementRuleCollector::hasAnyMatchingRules(RuleSet* ruleSet)
497
{
498
    clearMatchedRules();
499
500
    m_mode = SelectorChecker::SharingRules;
501
    int firstRuleIndex = -1, lastRuleIndex = -1;
502
    StyleResolver::RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
503
    collectMatchingRules(MatchRequest(ruleSet), ruleRange);
504
505
    return m_matchedRules && !m_matchedRules->isEmpty();
506
}
507
508
} // namespace WebCore
- a/Source/WebCore/css/ElementRuleCollector.h -124 lines
Lines 1-124 a/Source/WebCore/css/ElementRuleCollector.h_sec1
1
/*
2
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 ElementRuleCollector_h
23
#define ElementRuleCollector_h
24
25
#include "MediaQueryEvaluator.h"
26
#include "SelectorChecker.h"
27
#include "StyleResolver.h"
28
#include <wtf/RefPtr.h>
29
#include <wtf/Vector.h>
30
31
namespace WebCore {
32
33
class CSSRuleList;
34
class DocumentRuleSets;
35
class RenderRegion;
36
class RuleData;
37
class RuleSet;
38
class SelectorFilter;
39
class StyleScopeResolver;
40
class StaticCSSRuleList;
41
42
class ElementRuleCollector {
43
public:
44
    ElementRuleCollector(StyleResolver* styleResolver, const StyleResolver::State& state)
45
        : m_state(state)
46
        , m_ruleSets(styleResolver->ruleSets())
47
        , m_selectorFilter(styleResolver->selectorFilter())
48
        , m_inspectorCSSOMWrappers(styleResolver->inspectorCSSOMWrappers())
49
        , m_scopeResolver(styleResolver->scopeResolver())
50
        , m_isPrintStyle(false)
51
        , m_regionForStyling(0)
52
        , m_pseudoStyleRequest(NOPSEUDO)
53
        , m_sameOriginOnly(false)
54
        , m_mode(SelectorChecker::ResolvingStyle)
55
        , m_canUseFastReject(m_selectorFilter.parentStackIsConsistent(state.parentNode()))
56
        , m_behaviorAtBoundary(SelectorChecker::DoesNotCrossBoundary)
57
        , m_matchingUARules(false) { }
58
59
    void matchAllRules(bool matchAuthorAndUserStyles, bool includeSMILProperties);
60
    void matchUARules();
61
    void matchAuthorRules(bool includeEmptyRules);
62
    void matchUserRules(bool includeEmptyRules);
63
64
    void setMode(SelectorChecker::Mode mode) { m_mode = mode; }
65
    void setPseudoStyleRequest(const PseudoStyleRequest& request) { m_pseudoStyleRequest = request; }
66
    void setSameOriginOnly(bool f) { m_sameOriginOnly = f; } 
67
    void setRegionForStyling(RenderRegion* regionForStyling) { m_regionForStyling = regionForStyling; }
68
    void setMedium(const MediaQueryEvaluator* medium) { m_isPrintStyle = medium->mediaTypeMatchSpecific("print"); }
69
70
    bool hasAnyMatchingRules(RuleSet*);
71
72
    StyleResolver::MatchResult& matchedResult();
73
    PassRefPtr<CSSRuleList> matchedRuleList();
74
75
private:
76
    Document* document() { return m_state.document(); }
77
    void addElementStyleProperties(const StylePropertySet*, bool isCacheable = true);
78
79
#if ENABLE(SHADOW_DOM)
80
    void matchUARules(RuleSet*);
81
    void matchShadowDistributedRules(bool includeEmptyRules, StyleResolver::RuleRange&);
82
    void matchScopedAuthorRules(bool includeEmptyRules);
83
    void matchHostRules(bool includeEmptyRules);
84
#endif
85
86
    void collectMatchingRules(const MatchRequest&, StyleResolver::RuleRange&);
87
    void collectMatchingRulesForRegion(const MatchRequest&, StyleResolver::RuleRange&);
88
    void collectMatchingRulesForList(const Vector<RuleData>*, const MatchRequest&, StyleResolver::RuleRange&);
89
    bool ruleMatches(const RuleData&, const ContainerNode* scope, PseudoId&);
90
91
    void sortMatchedRules();
92
    void sortAndTransferMatchedRules();
93
94
    void addMatchedRule(const RuleData*);
95
    void clearMatchedRules();
96
97
    StaticCSSRuleList* ensureRuleList();
98
        
99
private:
100
    const StyleResolver::State& m_state;
101
    DocumentRuleSets& m_ruleSets;
102
    SelectorFilter& m_selectorFilter;
103
    InspectorCSSOMWrappers& m_inspectorCSSOMWrappers;
104
    StyleScopeResolver* m_scopeResolver;
105
106
    bool m_isPrintStyle;
107
    RenderRegion* m_regionForStyling;
108
    PseudoStyleRequest m_pseudoStyleRequest;
109
    bool m_sameOriginOnly;
110
    SelectorChecker::Mode m_mode;
111
    bool m_canUseFastReject;
112
    SelectorChecker::BehaviorAtBoundary m_behaviorAtBoundary;
113
    bool m_matchingUARules;
114
115
    OwnPtr<Vector<const RuleData*, 32> > m_matchedRules;
116
117
    // Output.
118
    RefPtr<StaticCSSRuleList> m_ruleList;
119
    StyleResolver::MatchResult m_result;
120
};
121
122
} // namespace WebCore
123
124
#endif // ElementRuleCollector_h
- a/Source/WebCore/css/PageRuleCollector.cpp -130 lines
Lines 1-130 a/Source/WebCore/css/PageRuleCollector.cpp_sec1
1
/*
2
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
4
 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
5
 * Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 Apple Inc. All rights reserved.
6
 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
7
 * Copyright (C) 2007, 2008 Eric Seidel <eric@webkit.org>
8
 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/)
9
 * Copyright (c) 2011, Code Aurora Forum. All rights reserved.
10
 * Copyright (C) Research In Motion Limited 2011. All rights reserved.
11
 * Copyright (C) 2012 Google Inc. All rights reserved.
12
 *
13
 * This library is free software; you can redistribute it and/or
14
 * modify it under the terms of the GNU Library General Public
15
 * License as published by the Free Software Foundation; either
16
 * version 2 of the License, or (at your option) any later version.
17
 *
18
 * This library is distributed in the hope that it will be useful,
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
21
 * Library General Public License for more details.
22
 *
23
 * You should have received a copy of the GNU Library General Public License
24
 * along with this library; see the file COPYING.LIB.  If not, write to
25
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
26
 * Boston, MA 02110-1301, USA.
27
 */
28
29
#include "config.h"
30
#include "PageRuleCollector.h"
31
32
#include "CSSDefaultStyleSheets.h"
33
#include "StylePropertySet.h"
34
#include "StyleRule.h"
35
36
namespace WebCore {
37
38
static inline bool comparePageRules(const StyleRulePage* r1, const StyleRulePage* r2)
39
{
40
    return r1->selector()->specificity() < r2->selector()->specificity();
41
}
42
43
bool PageRuleCollector::isLeftPage(int pageIndex) const
44
{
45
    bool isFirstPageLeft = false;
46
    if (!m_state.rootElementStyle()->isLeftToRightDirection())
47
        isFirstPageLeft = true;
48
49
    return (pageIndex + (isFirstPageLeft ? 1 : 0)) % 2;
50
}
51
52
bool PageRuleCollector::isFirstPage(int pageIndex) const
53
{
54
    // FIXME: In case of forced left/right page, page at index 1 (not 0) can be the first page.
55
    return (!pageIndex);
56
}
57
58
String PageRuleCollector::pageName(int /* pageIndex */) const
59
{
60
    // FIXME: Implement page index to page name mapping.
61
    return "";
62
}
63
64
void PageRuleCollector::matchAllPageRules(int pageIndex)
65
{
66
    const bool isLeft = isLeftPage(pageIndex);
67
    const bool isFirst = isFirstPage(pageIndex);
68
    const String page = pageName(pageIndex);
69
    
70
    matchPageRules(CSSDefaultStyleSheets::defaultPrintStyle, isLeft, isFirst, page);
71
    matchPageRules(m_ruleSets.userStyle(), isLeft, isFirst, page);
72
    // Only consider the global author RuleSet for @page rules, as per the HTML5 spec.
73
    matchPageRules(m_ruleSets.authorStyle(), isLeft, isFirst, page);
74
}
75
76
void PageRuleCollector::matchPageRules(RuleSet* rules, bool isLeftPage, bool isFirstPage, const String& pageName)
77
{
78
    if (!rules)
79
        return;
80
81
    Vector<StyleRulePage*> matchedPageRules;
82
    matchPageRulesForList(matchedPageRules, rules->pageRules(), isLeftPage, isFirstPage, pageName);
83
    if (matchedPageRules.isEmpty())
84
        return;
85
86
    std::stable_sort(matchedPageRules.begin(), matchedPageRules.end(), comparePageRules);
87
88
    for (unsigned i = 0; i < matchedPageRules.size(); i++)
89
        m_result.addMatchedProperties(matchedPageRules[i]->properties());
90
}
91
92
static bool checkPageSelectorComponents(const CSSSelector* selector, bool isLeftPage, bool isFirstPage, const String& pageName)
93
{
94
    for (const CSSSelector* component = selector; component; component = component->tagHistory()) {
95
        if (component->m_match == CSSSelector::Tag) {
96
            const AtomicString& localName = component->tagQName().localName();
97
            if (localName != starAtom && localName != pageName)
98
                return false;
99
        }
100
101
        CSSSelector::PseudoType pseudoType = component->pseudoType();
102
        if ((pseudoType == CSSSelector::PseudoLeftPage && !isLeftPage)
103
            || (pseudoType == CSSSelector::PseudoRightPage && isLeftPage)
104
            || (pseudoType == CSSSelector::PseudoFirstPage && !isFirstPage))
105
        {
106
            return false;
107
        }
108
    }
109
    return true;
110
}
111
112
void PageRuleCollector::matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName)
113
{
114
    for (unsigned i = 0; i < rules.size(); ++i) {
115
        StyleRulePage* rule = rules[i];
116
117
        if (!checkPageSelectorComponents(rule->selector(), isLeftPage, isFirstPage, pageName))
118
            continue;
119
120
        // If the rule has no properties to apply, then ignore it.
121
        const StylePropertySet* properties = rule->properties();
122
        if (!properties || properties->isEmpty())
123
            continue;
124
125
        // Add this rule to our list of matched rules.
126
        matchedRules.append(rule);
127
    }
128
}
129
130
} // namespace WebCore
- a/Source/WebCore/css/PageRuleCollector.h -60 lines
Lines 1-60 a/Source/WebCore/css/PageRuleCollector.h_sec1
1
/*
2
 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3
 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 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 PageRuleCollector_h
23
#define PageRuleCollector_h
24
25
#include "DocumentRuleSets.h"
26
#include "StyleResolver.h"
27
#include <wtf/RefPtr.h>
28
#include <wtf/Vector.h>
29
30
namespace WebCore {
31
32
class StyleRulePage;
33
34
class PageRuleCollector {
35
public:
36
    PageRuleCollector(StyleResolver::State& state, DocumentRuleSets& ruleSets)
37
        : m_state(state)
38
        , m_ruleSets(ruleSets) { }
39
40
    void matchAllPageRules(int pageIndex);
41
    StyleResolver::MatchResult& matchedResult() { return m_result; }
42
43
private:
44
    bool isLeftPage(int pageIndex) const;
45
    bool isRightPage(int pageIndex) const { return !isLeftPage(pageIndex); }
46
    bool isFirstPage(int pageIndex) const;
47
    String pageName(int pageIndex) const;
48
49
    void matchPageRules(RuleSet* rules, bool isLeftPage, bool isFirstPage, const String& pageName);
50
    void matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName);
51
52
    const StyleResolver::State& m_state;
53
    DocumentRuleSets& m_ruleSets;
54
55
    StyleResolver::MatchResult m_result;
56
};
57
58
} // namespace WebCore
59
60
#endif // PageRuleCollector_h
- a/Source/WebCore/css/StyleResolver.cpp -49 / +599 lines
Lines 59-65 a/Source/WebCore/css/StyleResolver.cpp_sec1
59
#include "CounterContent.h"
59
#include "CounterContent.h"
60
#include "CursorList.h"
60
#include "CursorList.h"
61
#include "DocumentStyleSheetCollection.h"
61
#include "DocumentStyleSheetCollection.h"
62
#include "ElementRuleCollector.h"
63
#include "ElementShadow.h"
62
#include "ElementShadow.h"
64
#include "FontFeatureValue.h"
63
#include "FontFeatureValue.h"
65
#include "FontValue.h"
64
#include "FontValue.h"
Lines 87-93 a/Source/WebCore/css/StyleResolver.cpp_sec2
87
#include "NodeRenderStyle.h"
86
#include "NodeRenderStyle.h"
88
#include "NodeRenderingContext.h"
87
#include "NodeRenderingContext.h"
89
#include "Page.h"
88
#include "Page.h"
90
#include "PageRuleCollector.h"
91
#include "Pair.h"
89
#include "Pair.h"
92
#include "PerspectiveTransformOperation.h"
90
#include "PerspectiveTransformOperation.h"
93
#include "QuotesData.h"
91
#include "QuotesData.h"
Lines 109-114 a/Source/WebCore/css/StyleResolver.cpp_sec3
109
#include "ShadowData.h"
107
#include "ShadowData.h"
110
#include "ShadowRoot.h"
108
#include "ShadowRoot.h"
111
#include "ShadowValue.h"
109
#include "ShadowValue.h"
110
#include "SiblingTraversalStrategies.h"
112
#include "SkewTransformOperation.h"
111
#include "SkewTransformOperation.h"
113
#include "StyleBuilder.h"
112
#include "StyleBuilder.h"
114
#include "StyleCachedImage.h"
113
#include "StyleCachedImage.h"
Lines 211-216 if (isInitial) { \ a/Source/WebCore/css/StyleResolver.cpp_sec4
211
210
212
RenderStyle* StyleResolver::s_styleNotYetAvailable;
211
RenderStyle* StyleResolver::s_styleNotYetAvailable;
213
212
213
static StylePropertySet* leftToRightDeclaration()
214
{
215
    DEFINE_STATIC_LOCAL(RefPtr<StylePropertySet>, leftToRightDecl, (StylePropertySet::create()));
216
    if (leftToRightDecl->isEmpty())
217
        leftToRightDecl->setProperty(CSSPropertyDirection, CSSValueLtr);
218
    return leftToRightDecl.get();
219
}
220
221
static StylePropertySet* rightToLeftDeclaration()
222
{
223
    DEFINE_STATIC_LOCAL(RefPtr<StylePropertySet>, rightToLeftDecl, (StylePropertySet::create()));
224
    if (rightToLeftDecl->isEmpty())
225
        rightToLeftDecl->setProperty(CSSPropertyDirection, CSSValueRtl);
226
    return rightToLeftDecl.get();
227
}
228
229
230
inline StaticCSSRuleList* StyleResolver::State::ensureRuleList()
231
{
232
    if (!m_ruleList)
233
        m_ruleList = StaticCSSRuleList::create();
234
    return m_ruleList.get();
235
}
236
214
inline void StyleResolver::State::cacheBorderAndBackground()
237
inline void StyleResolver::State::cacheBorderAndBackground()
215
{
238
{
216
    m_hasUAAppearance = m_style->hasAppearance();
239
    m_hasUAAppearance = m_style->hasAppearance();
Lines 228-233 inline void StyleResolver::State::clear() a/Source/WebCore/css/StyleResolver.cpp_sec5
228
    m_parentStyle = 0;
251
    m_parentStyle = 0;
229
    m_parentNode = 0;
252
    m_parentNode = 0;
230
    m_regionForStyling = 0;
253
    m_regionForStyling = 0;
254
    m_ruleList = 0;
255
    m_matchedRules.clear();
231
    m_pendingImageProperties.clear();
256
    m_pendingImageProperties.clear();
232
#if ENABLE(CSS_SHADERS)
257
#if ENABLE(CSS_SHADERS)
233
    m_hasPendingShaders = false;
258
    m_hasPendingShaders = false;
Lines 237-252 inline void StyleResolver::State::clear() a/Source/WebCore/css/StyleResolver.cpp_sec6
237
#endif
262
#endif
238
}
263
}
239
264
240
void StyleResolver::MatchResult::addMatchedProperties(const StylePropertySet* properties, StyleRule* rule, unsigned linkMatchType, PropertyWhitelistType propertyWhitelistType)
241
{
242
    matchedProperties.grow(matchedProperties.size() + 1);
243
    StyleResolver::MatchedProperties& newProperties = matchedProperties.last();
244
    newProperties.properties = const_cast<StylePropertySet*>(properties);
245
    newProperties.linkMatchType = linkMatchType;
246
    newProperties.whitelistType = propertyWhitelistType;
247
    matchedRules.append(rule);
248
}
249
250
StyleResolver::StyleResolver(Document* document, bool matchAuthorAndUserStyles)
265
StyleResolver::StyleResolver(Document* document, bool matchAuthorAndUserStyles)
251
    : m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
266
    : m_matchedPropertiesCacheAdditionsSinceLastSweep(0)
252
    , m_matchedPropertiesCacheSweepTimer(this, &StyleResolver::sweepMatchedPropertiesCache)
267
    , m_matchedPropertiesCacheSweepTimer(this, &StyleResolver::sweepMatchedPropertiesCache)
Lines 390-395 void StyleResolver::sweepMatchedPropertiesCache(Timer<StyleResolver>*) a/Source/WebCore/css/StyleResolver.cpp_sec7
390
    m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
405
    m_matchedPropertiesCacheAdditionsSinceLastSweep = 0;
391
}
406
}
392
407
408
void StyleResolver::addMatchedProperties(MatchResult& matchResult, const StylePropertySet* properties, StyleRule* rule, unsigned linkMatchType, PropertyWhitelistType propertyWhitelistType)
409
{
410
    matchResult.matchedProperties.grow(matchResult.matchedProperties.size() + 1);
411
    MatchedProperties& newProperties = matchResult.matchedProperties.last();
412
    newProperties.properties = const_cast<StylePropertySet*>(properties);
413
    newProperties.linkMatchType = linkMatchType;
414
    newProperties.whitelistType = propertyWhitelistType;
415
    matchResult.matchedRules.append(rule);
416
}
417
418
inline void StyleResolver::addElementStyleProperties(MatchResult& result, const StylePropertySet* propertySet, bool isCacheable)
419
{
420
    if (!propertySet)
421
        return;
422
    result.ranges.lastAuthorRule = result.matchedProperties.size();
423
    if (result.ranges.firstAuthorRule == -1)
424
        result.ranges.firstAuthorRule = result.ranges.lastAuthorRule;
425
    addMatchedProperties(result, propertySet);
426
    if (!isCacheable)
427
        result.isCacheable = false;
428
}
429
430
class MatchingUARulesScope {
431
public:
432
    MatchingUARulesScope();
433
    ~MatchingUARulesScope();
434
435
    static bool isMatchingUARules();
436
437
private:
438
    static bool m_matchingUARules;
439
};
440
441
MatchingUARulesScope::MatchingUARulesScope()
442
{
443
    ASSERT(!m_matchingUARules);
444
    m_matchingUARules = true;
445
}
446
447
MatchingUARulesScope::~MatchingUARulesScope()
448
{
449
    m_matchingUARules = false;
450
}
451
452
inline bool MatchingUARulesScope::isMatchingUARules()
453
{
454
    return m_matchingUARules;
455
}
456
457
bool MatchingUARulesScope::m_matchingUARules = false;
458
459
void StyleResolver::collectMatchingRules(const MatchRequest& matchRequest, RuleRange& ruleRange)
460
{
461
    ASSERT(matchRequest.ruleSet);
462
    ASSERT(m_state.element());
463
464
    State& state = m_state;
465
    Element* element = state.element();
466
    const StyledElement* styledElement = state.styledElement();
467
    const AtomicString& pseudoId = element->shadowPseudoId();
468
    if (!pseudoId.isEmpty()) {
469
        ASSERT(styledElement);
470
        collectMatchingRulesForList(matchRequest.ruleSet->shadowPseudoElementRules(pseudoId.impl()), matchRequest, ruleRange);
471
    }
472
473
#if ENABLE(VIDEO_TRACK)
474
    if (element->isWebVTTElement())
475
        collectMatchingRulesForList(matchRequest.ruleSet->cuePseudoRules(), matchRequest, ruleRange);
476
#endif
477
    // Check whether other types of rules are applicable in the current tree scope. Criteria for this:
478
    // a) it's a UA rule
479
    // b) the tree scope allows author rules
480
    // c) the rules comes from a scoped style sheet within the same tree scope
481
    TreeScope* treeScope = element->treeScope();
482
    if (!MatchingUARulesScope::isMatchingUARules()
483
        && !treeScope->applyAuthorStyles()
484
        && (!matchRequest.scope || matchRequest.scope->treeScope() != treeScope)
485
        && matchRequest.behaviorAtBoundary == SelectorChecker::DoesNotCrossBoundary)
486
        return;
487
488
    // We need to collect the rules for id, class, tag, and everything else into a buffer and
489
    // then sort the buffer.
490
    if (element->hasID())
491
        collectMatchingRulesForList(matchRequest.ruleSet->idRules(element->idForStyleResolution().impl()), matchRequest, ruleRange);
492
    if (styledElement && styledElement->hasClass()) {
493
        for (size_t i = 0; i < styledElement->classNames().size(); ++i)
494
            collectMatchingRulesForList(matchRequest.ruleSet->classRules(styledElement->classNames()[i].impl()), matchRequest, ruleRange);
495
    }
496
497
    if (element->isLink())
498
        collectMatchingRulesForList(matchRequest.ruleSet->linkPseudoClassRules(), matchRequest, ruleRange);
499
    if (SelectorChecker::matchesFocusPseudoClass(element))
500
        collectMatchingRulesForList(matchRequest.ruleSet->focusPseudoClassRules(), matchRequest, ruleRange);
501
    collectMatchingRulesForList(matchRequest.ruleSet->tagRules(element->localName().impl()), matchRequest, ruleRange);
502
    collectMatchingRulesForList(matchRequest.ruleSet->universalRules(), matchRequest, ruleRange);
503
}
504
505
void StyleResolver::collectMatchingRulesForRegion(const MatchRequest& matchRequest, RuleRange& ruleRange)
506
{
507
    if (!m_state.regionForStyling())
508
        return;
509
510
    unsigned size = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.size();
511
    for (unsigned i = 0; i < size; ++i) {
512
        const CSSSelector* regionSelector = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).selector;
513
        if (checkRegionSelector(regionSelector, static_cast<Element*>(m_state.regionForStyling()->node()))) {
514
            RuleSet* regionRules = matchRequest.ruleSet->m_regionSelectorsAndRuleSets.at(i).ruleSet.get();
515
            ASSERT(regionRules);
516
            collectMatchingRules(MatchRequest(regionRules, matchRequest.includeEmptyRules, matchRequest.scope), ruleRange);
517
        }
518
    }
519
}
520
521
void StyleResolver::sortAndTransferMatchedRules(MatchResult& result)
522
{
523
    State& state = m_state;
524
    Vector<const RuleData*, 32>& matchedRules = state.matchedRules();
525
    if (matchedRules.isEmpty())
526
        return;
527
528
    sortMatchedRules();
529
530
    if (state.mode() == SelectorChecker::CollectingRules) {
531
        for (unsigned i = 0; i < matchedRules.size(); ++i)
532
            state.ensureRuleList()->rules().append(matchedRules[i]->rule()->createCSSOMWrapper());
533
        return;
534
    }
535
536
    // Now transfer the set of matched rules over to our list of declarations.
537
    for (unsigned i = 0; i < matchedRules.size(); i++) {
538
        if (state.style() && matchedRules[i]->containsUncommonAttributeSelector())
539
            state.style()->setUnique();
540
        addMatchedProperties(result, matchedRules[i]->rule()->properties(), matchedRules[i]->rule(), matchedRules[i]->linkMatchType(), matchedRules[i]->propertyWhitelistType());
541
    }
542
}
543
544
void StyleResolver::matchScopedAuthorRules(MatchResult& result, bool includeEmptyRules)
545
{
546
#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
547
    if (!m_scopeResolver)
548
        return;
549
550
    // Match scoped author rules by traversing the scoped element stack (rebuild it if it got inconsistent).
551
    if (m_scopeResolver->hasScopedStyles() && m_scopeResolver->ensureStackConsistency(m_state.element())) {
552
        bool applyAuthorStyles = m_state.element()->treeScope()->applyAuthorStyles();
553
        bool documentScope = true;
554
        unsigned scopeSize = m_scopeResolver->stackSize();
555
        for (unsigned i = 0; i < scopeSize; ++i) {
556
            m_state.matchedRules().clear();
557
            result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
558
559
            const StyleScopeResolver::StackFrame& frame = m_scopeResolver->stackFrameAt(i);
560
            documentScope = documentScope && !frame.m_scope->isInShadowTree();
561
            if (documentScope) {
562
                if (!applyAuthorStyles)
563
                    continue;
564
            } else {
565
                if (!m_scopeResolver->matchesStyleBounds(frame))
566
                    continue;
567
            }
568
569
            MatchRequest matchRequest(frame.m_ruleSet, includeEmptyRules, frame.m_scope);
570
            RuleRange ruleRange = result.ranges.authorRuleRange();
571
            collectMatchingRules(matchRequest, ruleRange);
572
            collectMatchingRulesForRegion(matchRequest, ruleRange);
573
            sortAndTransferMatchedRules(result);
574
        }
575
    }
576
577
    matchHostRules(result, includeEmptyRules);
578
#else
579
    UNUSED_PARAM(result);
580
    UNUSED_PARAM(includeEmptyRules);
581
#endif
582
}
583
393
inline bool StyleResolver::styleSharingCandidateMatchesHostRules()
584
inline bool StyleResolver::styleSharingCandidateMatchesHostRules()
394
{
585
{
395
#if ENABLE(SHADOW_DOM)
586
#if ENABLE(SHADOW_DOM)
Lines 399-404 inline bool StyleResolver::styleSharingCandidateMatchesHostRules() a/Source/WebCore/css/StyleResolver.cpp_sec8
399
#endif
590
#endif
400
}
591
}
401
592
593
void StyleResolver::matchHostRules(MatchResult& result, bool includeEmptyRules)
594
{
595
#if ENABLE(SHADOW_DOM)
596
    ASSERT(m_scopeResolver);
597
598
    m_state.matchedRules().clear();
599
    result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
600
601
    Vector<RuleSet*> matchedRules;
602
    m_scopeResolver->matchHostRules(m_state.element(), matchedRules);
603
    if (matchedRules.isEmpty())
604
        return;
605
606
    for (unsigned i = matchedRules.size(); i > 0; --i) {
607
        RuleRange ruleRange = result.ranges.authorRuleRange();
608
        collectMatchingRules(MatchRequest(matchedRules.at(i-1), includeEmptyRules, m_state.element()), ruleRange);
609
    }
610
    sortAndTransferMatchedRules(result);
611
#else
612
    UNUSED_PARAM(result);
613
    UNUSED_PARAM(includeEmptyRules);
614
#endif
615
}
616
617
void StyleResolver::matchAuthorRules(MatchResult& result, bool includeEmptyRules)
618
{
619
    m_state.matchedRules().clear();
620
    result.ranges.lastAuthorRule = result.matchedProperties.size() - 1;
621
622
    if (!m_state.element())
623
        return;
624
625
    // Match global author rules.
626
    MatchRequest matchRequest(m_ruleSets.authorStyle(), includeEmptyRules);
627
    RuleRange ruleRange = result.ranges.authorRuleRange();
628
    collectMatchingRules(matchRequest, ruleRange);
629
    collectMatchingRulesForRegion(matchRequest, ruleRange);
630
#if ENABLE(SHADOW_DOM)
631
    Vector<MatchRequest> matchRequests;
632
    m_ruleSets.shadowDistributedRules().collectMatchRequests(includeEmptyRules, matchRequests);
633
    for (size_t i = 0; i < matchRequests.size(); ++i)
634
        collectMatchingRules(matchRequests[i], ruleRange);
635
#endif
636
637
    sortAndTransferMatchedRules(result);
638
639
    matchScopedAuthorRules(result, includeEmptyRules);
640
}
641
642
void StyleResolver::matchUserRules(MatchResult& result, bool includeEmptyRules)
643
{
644
    if (!m_ruleSets.userStyle())
645
        return;
646
    
647
    m_state.matchedRules().clear();
648
649
    result.ranges.lastUserRule = result.matchedProperties.size() - 1;
650
    MatchRequest matchRequest(m_ruleSets.userStyle(), includeEmptyRules);
651
    RuleRange ruleRange = result.ranges.userRuleRange();
652
    collectMatchingRules(matchRequest, ruleRange);
653
    collectMatchingRulesForRegion(matchRequest, ruleRange);
654
655
    sortAndTransferMatchedRules(result);
656
}
657
658
void StyleResolver::matchUARules(MatchResult& result, RuleSet* rules)
659
{
660
    m_state.matchedRules().clear();
661
    
662
    result.ranges.lastUARule = result.matchedProperties.size() - 1;
663
    RuleRange ruleRange = result.ranges.UARuleRange();
664
    collectMatchingRules(MatchRequest(rules), ruleRange);
665
666
    sortAndTransferMatchedRules(result);
667
}
668
669
void StyleResolver::collectMatchingRulesForList(const Vector<RuleData>* rules, const MatchRequest& matchRequest, RuleRange& ruleRange)
670
{
671
    if (!rules)
672
        return;
673
674
    State& state = m_state;
675
    // In some cases we may end up looking up style for random elements in the middle of a recursive tree resolve.
676
    // Ancestor identifier filter won't be up-to-date in that case and we can't use the fast path.
677
    bool canUseFastReject = m_selectorFilter.parentStackIsConsistent(state.parentNode()) && matchRequest.behaviorAtBoundary == SelectorChecker::DoesNotCrossBoundary;
678
679
    unsigned size = rules->size();
680
    for (unsigned i = 0; i < size; ++i) {
681
        const RuleData& ruleData = rules->at(i);
682
        if (canUseFastReject && m_selectorFilter.fastRejectSelector<RuleData::maximumIdentifierCount>(ruleData.descendantSelectorIdentifierHashes()))
683
            continue;
684
685
        StyleRule* rule = ruleData.rule();
686
        InspectorInstrumentationCookie cookie = InspectorInstrumentation::willMatchRule(document(), rule, this);
687
        PseudoId dynamicPseudo = NOPSEUDO;
688
        if (ruleMatches(ruleData, matchRequest.scope, dynamicPseudo, matchRequest.behaviorAtBoundary)) {
689
            // If the rule has no properties to apply, then ignore it in the non-debug mode.
690
            const StylePropertySet* properties = rule->properties();
691
            if (!properties || (properties->isEmpty() && !matchRequest.includeEmptyRules)) {
692
                InspectorInstrumentation::didMatchRule(cookie, false);
693
                continue;
694
            }
695
            // FIXME: Exposing the non-standard getMatchedCSSRules API to web is the only reason this is needed.
696
            if (state.isSameOriginOnly() && !ruleData.hasDocumentSecurityOrigin()) {
697
                InspectorInstrumentation::didMatchRule(cookie, false);
698
                continue;
699
            }
700
            // If we're matching normal rules, set a pseudo bit if
701
            // we really just matched a pseudo-element.
702
            if (dynamicPseudo != NOPSEUDO && state.pseudoStyleRequest().pseudoId == NOPSEUDO) {
703
                if (state.mode() == SelectorChecker::CollectingRules) {
704
                    InspectorInstrumentation::didMatchRule(cookie, false);
705
                    continue;
706
                }
707
                if (dynamicPseudo < FIRST_INTERNAL_PSEUDOID)
708
                    state.style()->setHasPseudoStyle(dynamicPseudo);
709
            } else {
710
                // Update our first/last rule indices in the matched rules array.
711
                ++ruleRange.lastRuleIndex;
712
                if (ruleRange.firstRuleIndex == -1)
713
                    ruleRange.firstRuleIndex = ruleRange.lastRuleIndex;
714
715
                // Add this rule to our list of matched rules.
716
                m_state.addMatchedRule(&ruleData);
717
                InspectorInstrumentation::didMatchRule(cookie, true);
718
                continue;
719
            }
720
        }
721
        InspectorInstrumentation::didMatchRule(cookie, false);
722
    }
723
}
724
725
static inline bool compareRules(const RuleData* r1, const RuleData* r2)
726
{
727
    unsigned specificity1 = r1->specificity();
728
    unsigned specificity2 = r2->specificity();
729
    return (specificity1 == specificity2) ? r1->position() < r2->position() : specificity1 < specificity2;
730
}
731
732
void StyleResolver::sortMatchedRules()
733
{
734
    std::sort(m_state.matchedRules().begin(), m_state.matchedRules().end(), compareRules);
735
}
736
737
void StyleResolver::matchAllRules(MatchResult& result, bool includeSMILProperties)
738
{
739
    matchUARules(result);
740
741
    // Now we check user sheet rules.
742
    if (m_matchAuthorAndUserStyles)
743
        matchUserRules(result, false);
744
745
    // Now check author rules, beginning first with presentational attributes mapped from HTML.
746
    if (m_state.styledElement()) {
747
        addElementStyleProperties(result, m_state.styledElement()->presentationAttributeStyle());
748
749
        // Now we check additional mapped declarations.
750
        // Tables and table cells share an additional mapped rule that must be applied
751
        // after all attributes, since their mapped style depends on the values of multiple attributes.
752
        addElementStyleProperties(result, m_state.styledElement()->additionalPresentationAttributeStyle());
753
754
        if (m_state.styledElement()->isHTMLElement()) {
755
            bool isAuto;
756
            TextDirection textDirection = toHTMLElement(m_state.styledElement())->directionalityIfhasDirAutoAttribute(isAuto);
757
            if (isAuto)
758
                addMatchedProperties(result, textDirection == LTR ? leftToRightDeclaration() : rightToLeftDeclaration());
759
        }
760
    }
761
    
762
    // Check the rules in author sheets next.
763
    if (m_matchAuthorAndUserStyles)
764
        matchAuthorRules(result, false);
765
766
    // Now check our inline style attribute.
767
    if (m_matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->inlineStyle()) {
768
        // Inline style is immutable as long as there is no CSSOM wrapper.
769
        // FIXME: Media control shadow trees seem to have problems with caching.
770
        bool isInlineStyleCacheable = !m_state.styledElement()->inlineStyle()->isMutable() && !m_state.styledElement()->isInShadowTree();
771
        // FIXME: Constify.
772
        addElementStyleProperties(result, m_state.styledElement()->inlineStyle(), isInlineStyleCacheable);
773
    }
774
775
#if ENABLE(SVG)
776
    // Now check SMIL animation override style.
777
    if (includeSMILProperties && m_matchAuthorAndUserStyles && m_state.styledElement() && m_state.styledElement()->isSVGElement())
778
        addElementStyleProperties(result, static_cast<SVGElement*>(m_state.styledElement())->animatedSMILStyleProperties(), false /* isCacheable */);
779
#else
780
    UNUSED_PARAM(includeSMILProperties);
781
#endif
782
}
783
402
bool StyleResolver::classNamesAffectedByRules(const SpaceSplitString& classNames) const
784
bool StyleResolver::classNamesAffectedByRules(const SpaceSplitString& classNames) const
403
{
785
{
404
    for (unsigned i = 0; i < classNames.size(); ++i) {
786
    for (unsigned i = 0; i < classNames.size(); ++i) {
Lines 426-433 inline void StyleResolver::initElement(Element* e) a/Source/WebCore/css/StyleResolver.cpp_sec9
426
    }
808
    }
427
}
809
}
428
810
429
inline void StyleResolver::State::initForStyleResolve(Document* document, Element* e, RenderStyle* parentStyle, RenderRegion* regionForStyling)
811
inline void StyleResolver::State::initForStyleResolve(Document* document, Element* e, RenderStyle* parentStyle, const PseudoStyleRequest& pseudoStyleRequest, RenderRegion* regionForStyling)
430
{
812
{
813
    m_pseudoStyleRequest = pseudoStyleRequest;
431
    m_regionForStyling = regionForStyling;
814
    m_regionForStyling = regionForStyling;
432
815
433
    if (e) {
816
    if (e) {
Lines 449-454 inline void StyleResolver::State::initForStyleResolve(Document* document, Elemen a/Source/WebCore/css/StyleResolver.cpp_sec10
449
832
450
    m_style = 0;
833
    m_style = 0;
451
    m_pendingImageProperties.clear();
834
    m_pendingImageProperties.clear();
835
    m_ruleList = 0;
452
    m_fontDirty = false;
836
    m_fontDirty = false;
453
}
837
}
454
838
Lines 516-524 bool StyleResolver::styleSharingCandidateMatchesRuleSet(RuleSet* ruleSet) a/Source/WebCore/css/StyleResolver.cpp_sec11
516
{
900
{
517
    if (!ruleSet)
901
    if (!ruleSet)
518
        return false;
902
        return false;
519
903
    m_state.matchedRules().clear();
520
    ElementRuleCollector collector(this, m_state);
904
521
    return collector.hasAnyMatchingRules(ruleSet);
905
    m_state.setMode(SelectorChecker::SharingRules);
906
    int firstRuleIndex = -1, lastRuleIndex = -1;
907
    RuleRange ruleRange(firstRuleIndex, lastRuleIndex);
908
    collectMatchingRules(MatchRequest(ruleSet), ruleRange);
909
    m_state.setMode(SelectorChecker::ResolvingStyle);
910
    if (m_state.matchedRules().isEmpty())
911
        return false;
912
    m_state.matchedRules().clear();
913
    return true;
522
}
914
}
523
915
524
bool StyleResolver::canShareStyleWithControl(StyledElement* element) const
916
bool StyleResolver::canShareStyleWithControl(StyledElement* element) const
Lines 786-791 RenderStyle* StyleResolver::locateSharedStyle() a/Source/WebCore/css/StyleResolver.cpp_sec12
786
    return shareElement->renderStyle();
1178
    return shareElement->renderStyle();
787
}
1179
}
788
1180
1181
void StyleResolver::matchUARules(MatchResult& result)
1182
{
1183
    MatchingUARulesScope scope;
1184
1185
    // First we match rules from the user agent sheet.
1186
    if (CSSDefaultStyleSheets::simpleDefaultStyleSheet)
1187
        result.isCacheable = false;
1188
    RuleSet* userAgentStyleSheet = m_medium->mediaTypeMatchSpecific("print")
1189
        ? CSSDefaultStyleSheets::defaultPrintStyle : CSSDefaultStyleSheets::defaultStyle;
1190
    matchUARules(result, userAgentStyleSheet);
1191
1192
    // In quirks mode, we match rules from the quirks user agent sheet.
1193
    if (document()->inQuirksMode())
1194
        matchUARules(result, CSSDefaultStyleSheets::defaultQuirksStyle);
1195
1196
    // If document uses view source styles (in view source mode or in xml viewer mode), then we match rules from the view source style sheet.
1197
    if (document()->isViewSource())
1198
        matchUARules(result, CSSDefaultStyleSheets::viewSourceStyle());
1199
}
1200
789
static void setStylesForPaginationMode(Pagination::Mode paginationMode, RenderStyle* style)
1201
static void setStylesForPaginationMode(Pagination::Mode paginationMode, RenderStyle* style)
790
{
1202
{
791
    if (paginationMode == Pagination::Unpaginated)
1203
    if (paginationMode == Pagination::Unpaginated)
Lines 983-989 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS a/Source/WebCore/css/StyleResolver.cpp_sec13
983
1395
984
    State& state = m_state;
1396
    State& state = m_state;
985
    initElement(element);
1397
    initElement(element);
986
    state.initForStyleResolve(document(), element, defaultParent, regionForStyling);
1398
    state.initForStyleResolve(document(), element, defaultParent, NOPSEUDO, regionForStyling);
987
    if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoint()) {
1399
    if (sharingBehavior == AllowStyleSharing && !state.distributedToInsertionPoint()) {
988
        RenderStyle* sharedStyle = locateSharedStyle();
1400
        RenderStyle* sharedStyle = locateSharedStyle();
989
        if (sharedStyle)
1401
        if (sharedStyle)
Lines 1025-1040 PassRefPtr<RenderStyle> StyleResolver::styleForElement(Element* element, RenderS a/Source/WebCore/css/StyleResolver.cpp_sec14
1025
    if (needsCollection)
1437
    if (needsCollection)
1026
        m_ruleSets.collectFeatures(document()->isViewSource(), m_scopeResolver.get());
1438
        m_ruleSets.collectFeatures(document()->isViewSource(), m_scopeResolver.get());
1027
1439
1028
    ElementRuleCollector collector(this, state);
1440
    MatchResult matchResult;
1029
    collector.setRegionForStyling(regionForStyling);
1030
    collector.setMedium(m_medium.get());
1031
1032
    if (matchingBehavior == MatchOnlyUserAgentRules)
1441
    if (matchingBehavior == MatchOnlyUserAgentRules)
1033
        collector.matchUARules();
1442
        matchUARules(matchResult);
1034
    else
1443
    else
1035
        collector.matchAllRules(m_matchAuthorAndUserStyles, matchingBehavior != MatchAllRulesExcludingSMIL);
1444
        matchAllRules(matchResult, matchingBehavior != MatchAllRulesExcludingSMIL);
1036
1445
1037
    applyMatchedProperties(collector.matchedResult(), element);
1446
    applyMatchedProperties(matchResult, element);
1038
1447
1039
    // Clean up our style object's display and text decorations (among other fixups).
1448
    // Clean up our style object's display and text decorations (among other fixups).
1040
    adjustRenderStyle(state.style(), state.parentStyle(), element);
1449
    adjustRenderStyle(state.style(), state.parentStyle(), element);
Lines 1051-1057 PassRefPtr<RenderStyle> StyleResolver::styleForKeyframe(const RenderStyle* eleme a/Source/WebCore/css/StyleResolver.cpp_sec15
1051
{
1460
{
1052
    MatchResult result;
1461
    MatchResult result;
1053
    if (keyframe->properties())
1462
    if (keyframe->properties())
1054
        result.addMatchedProperties(keyframe->properties());
1463
        addMatchedProperties(result, keyframe->properties());
1055
1464
1056
    ASSERT(!m_state.style());
1465
    ASSERT(!m_state.style());
1057
1466
Lines 1175-1181 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P a/Source/WebCore/css/StyleResolver.cpp_sec16
1175
1584
1176
    initElement(e);
1585
    initElement(e);
1177
1586
1178
    state.initForStyleResolve(document(), e, parentStyle);
1587
    state.initForStyleResolve(document(), e, parentStyle, pseudoStyleRequest);
1179
    state.setStyle(RenderStyle::create());
1588
    state.setStyle(RenderStyle::create());
1180
    state.style()->inheritFrom(m_state.parentStyle());
1589
    state.style()->inheritFrom(m_state.parentStyle());
1181
1590
Lines 1183-1204 PassRefPtr<RenderStyle> StyleResolver::pseudoStyleForElement(Element* e, const P a/Source/WebCore/css/StyleResolver.cpp_sec17
1183
    // those rules.
1592
    // those rules.
1184
1593
1185
    // Check UA, user and author rules.
1594
    // Check UA, user and author rules.
1186
    ElementRuleCollector collector(this, state);
1595
    MatchResult matchResult;
1187
    collector.setPseudoStyleRequest(pseudoStyleRequest);
1596
    matchUARules(matchResult);
1188
    collector.setMedium(m_medium.get());
1189
    collector.matchUARules();
1190
1597
1191
    if (m_matchAuthorAndUserStyles) {
1598
    if (m_matchAuthorAndUserStyles) {
1192
        collector.matchUserRules(false);
1599
        matchUserRules(matchResult, false);
1193
        collector.matchAuthorRules(false);
1600
        matchAuthorRules(matchResult, false);
1194
    }
1601
    }
1195
1602
1196
    if (collector.matchedResult().matchedProperties.isEmpty())
1603
    if (matchResult.matchedProperties.isEmpty())
1197
        return 0;
1604
        return 0;
1198
1605
1199
    state.style()->setStyleType(pseudoStyleRequest.pseudoId);
1606
    state.style()->setStyleType(pseudoStyleRequest.pseudoId);
1200
1607
1201
    applyMatchedProperties(collector.matchedResult(), e);
1608
    applyMatchedProperties(matchResult, e);
1202
1609
1203
    // Clean up our style object's display and text decorations (among other fixups).
1610
    // Clean up our style object's display and text decorations (among other fixups).
1204
    adjustRenderStyle(state.style(), m_state.parentStyle(), 0);
1611
    adjustRenderStyle(state.style(), m_state.parentStyle(), 0);
Lines 1219-1230 PassRefPtr<RenderStyle> StyleResolver::styleForPage(int pageIndex) a/Source/WebCore/css/StyleResolver.cpp_sec18
1219
    m_state.setStyle(RenderStyle::create());
1626
    m_state.setStyle(RenderStyle::create());
1220
    m_state.style()->inheritFrom(m_state.rootElementStyle());
1627
    m_state.style()->inheritFrom(m_state.rootElementStyle());
1221
1628
1222
    PageRuleCollector collector(m_state, m_ruleSets);
1629
    const bool isLeft = isLeftPage(pageIndex);
1223
    collector.matchAllPageRules(pageIndex);
1630
    const bool isFirst = isFirstPage(pageIndex);
1631
    const String page = pageName(pageIndex);
1632
    
1633
    MatchResult result;
1634
    matchPageRules(result, CSSDefaultStyleSheets::defaultPrintStyle, isLeft, isFirst, page);
1635
    matchPageRules(result, m_ruleSets.userStyle(), isLeft, isFirst, page);
1636
    // Only consider the global author RuleSet for @page rules, as per the HTML5 spec.
1637
    matchPageRules(result, m_ruleSets.authorStyle(), isLeft, isFirst, page);
1224
    m_state.setLineHeightValue(0);
1638
    m_state.setLineHeightValue(0);
1225
    bool inheritedOnly = false;
1639
    bool inheritedOnly = false;
1226
1227
    MatchResult& result = collector.matchedResult();
1228
#if ENABLE(CSS_VARIABLES)
1640
#if ENABLE(CSS_VARIABLES)
1229
    applyMatchedProperties<VariableDefinitions>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
1641
    applyMatchedProperties<VariableDefinitions>(result, false, 0, result.matchedProperties.size() - 1, inheritedOnly);
1230
#endif
1642
#endif
Lines 1651-1681 PassRefPtr<CSSRuleList> StyleResolver::pseudoStyleRulesForElement(Element* e, Ps a/Source/WebCore/css/StyleResolver.cpp_sec19
1651
    if (!e || !e->document()->haveStylesheetsLoaded())
2063
    if (!e || !e->document()->haveStylesheetsLoaded())
1652
        return 0;
2064
        return 0;
1653
2065
1654
    initElement(e);
2066
    m_state.setMode(SelectorChecker::CollectingRules);
1655
    m_state.initForStyleResolve(document(), e, 0);
1656
2067
1657
    ElementRuleCollector collector(this, m_state);
2068
    initElement(e);
1658
    collector.setMode(SelectorChecker::CollectingRules);
2069
    m_state.initForStyleResolve(document(), e, 0, pseudoId);
1659
    collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
1660
    collector.setMedium(m_medium.get());
1661
2070
2071
    MatchResult dummy;
1662
    if (rulesToInclude & UAAndUserCSSRules) {
2072
    if (rulesToInclude & UAAndUserCSSRules) {
1663
        // First we match rules from the user agent sheet.
2073
        // First we match rules from the user agent sheet.
1664
        collector.matchUARules();
2074
        matchUARules(dummy);
1665
2075
1666
        // Now we check user sheet rules.
2076
        // Now we check user sheet rules.
1667
        if (m_matchAuthorAndUserStyles)
2077
        if (m_matchAuthorAndUserStyles)
1668
            collector.matchUserRules(rulesToInclude & EmptyCSSRules);
2078
            matchUserRules(dummy, rulesToInclude & EmptyCSSRules);
1669
    }
2079
    }
1670
2080
1671
    if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) {
2081
    if (m_matchAuthorAndUserStyles && (rulesToInclude & AuthorCSSRules)) {
1672
        collector.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
2082
        m_state.setSameOriginOnly(!(rulesToInclude & CrossOriginCSSRules));
1673
2083
1674
        // Check the rules in author sheets.
2084
        // Check the rules in author sheets.
1675
        collector.matchAuthorRules(rulesToInclude & EmptyCSSRules);
2085
        matchAuthorRules(dummy, rulesToInclude & EmptyCSSRules);
2086
2087
        m_state.setSameOriginOnly(false);
2088
    }
2089
2090
    m_state.setMode(SelectorChecker::ResolvingStyle);
2091
2092
    return m_state.takeRuleList();
2093
}
2094
2095
inline bool StyleResolver::ruleMatches(const RuleData& ruleData, const ContainerNode* scope, PseudoId& dynamicPseudo, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary)
2096
{
2097
    State& state = m_state;
2098
2099
    if (ruleData.hasFastCheckableSelector()) {
2100
        // We know this selector does not include any pseudo elements.
2101
        if (state.pseudoStyleRequest().pseudoId != NOPSEUDO)
2102
            return false;
2103
        // We know a sufficiently simple single part selector matches simply because we found it from the rule hash.
2104
        // This is limited to HTML only so we don't need to check the namespace.
2105
        if (ruleData.hasRightmostSelectorMatchingHTMLBasedOnRuleHash() && state.element()->isHTMLElement()) {
2106
            if (!ruleData.hasMultipartSelector())
2107
                return true;
2108
        }
2109
        if (ruleData.selector()->m_match == CSSSelector::Tag && !SelectorChecker::tagMatches(state.element(), ruleData.selector()->tagQName()))
2110
            return false;
2111
        SelectorCheckerFastPath selectorCheckerFastPath(ruleData.selector(), state.element());
2112
        if (!selectorCheckerFastPath.matchesRightmostAttributeSelector())
2113
            return false;
2114
2115
        return selectorCheckerFastPath.matches();
1676
    }
2116
    }
1677
2117
1678
    return collector.matchedRuleList();
2118
    // Slow path.
2119
    SelectorChecker selectorChecker(document(), state.mode());
2120
    SelectorChecker::SelectorCheckingContext context(ruleData.selector(), state.element(), SelectorChecker::VisitedMatchEnabled);
2121
    context.elementStyle = state.style();
2122
    context.scope = scope;
2123
    context.pseudoId = state.pseudoStyleRequest().pseudoId;
2124
    context.scrollbar = state.pseudoStyleRequest().scrollbar;
2125
    context.scrollbarPart = state.pseudoStyleRequest().scrollbarPart;
2126
    context.behaviorAtBoundary = behaviorAtBoundary;
2127
    SelectorChecker::Match match = selectorChecker.match(context, dynamicPseudo, DOMSiblingTraversalStrategy());
2128
    if (match != SelectorChecker::SelectorMatches)
2129
        return false;
2130
    if (state.pseudoStyleRequest().pseudoId != NOPSEUDO && state.pseudoStyleRequest().pseudoId != dynamicPseudo)
2131
        return false;
2132
    return true;
2133
}
2134
2135
bool StyleResolver::checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement)
2136
{
2137
    if (!regionSelector || !regionElement)
2138
        return false;
2139
2140
    SelectorChecker selectorChecker(document(), m_state.mode());
2141
    for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
2142
        SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regionElement, SelectorChecker::VisitedMatchDisabled);
2143
        PseudoId ignoreDynamicPseudo = NOPSEUDO;
2144
        if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches)
2145
            return true;
2146
    }
2147
2148
    return false;
1679
}
2149
}
1680
2150
1681
// -------------------------------------------------------------------------------------
2151
// -------------------------------------------------------------------------------------
Lines 1954-1959 void StyleResolver::applyMatchedProperties(const MatchResult& matchResult, const a/Source/WebCore/css/StyleResolver.cpp_sec20
1954
    addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
2424
    addToMatchedPropertiesCache(state.style(), state.parentStyle(), cacheHash, matchResult);
1955
}
2425
}
1956
2426
2427
static inline bool comparePageRules(const StyleRulePage* r1, const StyleRulePage* r2)
2428
{
2429
    return r1->selector()->specificity() < r2->selector()->specificity();
2430
}
2431
2432
void StyleResolver::matchPageRules(MatchResult& result, RuleSet* rules, bool isLeftPage, bool isFirstPage, const String& pageName)
2433
{
2434
    if (!rules)
2435
        return;
2436
2437
    Vector<StyleRulePage*> matchedPageRules;
2438
    matchPageRulesForList(matchedPageRules, rules->pageRules(), isLeftPage, isFirstPage, pageName);
2439
    if (matchedPageRules.isEmpty())
2440
        return;
2441
2442
    std::stable_sort(matchedPageRules.begin(), matchedPageRules.end(), comparePageRules);
2443
2444
    for (unsigned i = 0; i < matchedPageRules.size(); i++)
2445
        addMatchedProperties(result, matchedPageRules[i]->properties());
2446
}
2447
2448
static bool checkPageSelectorComponents(const CSSSelector* selector, bool isLeftPage, bool isFirstPage, const String& pageName)
2449
{
2450
    for (const CSSSelector* component = selector; component; component = component->tagHistory()) {
2451
        if (component->m_match == CSSSelector::Tag) {
2452
            const AtomicString& localName = component->tagQName().localName();
2453
            if (localName != starAtom && localName != pageName)
2454
                return false;
2455
        }
2456
2457
        CSSSelector::PseudoType pseudoType = component->pseudoType();
2458
        if ((pseudoType == CSSSelector::PseudoLeftPage && !isLeftPage)
2459
            || (pseudoType == CSSSelector::PseudoRightPage && isLeftPage)
2460
            || (pseudoType == CSSSelector::PseudoFirstPage && !isFirstPage))
2461
        {
2462
            return false;
2463
        }
2464
    }
2465
    return true;
2466
}
2467
2468
void StyleResolver::matchPageRulesForList(Vector<StyleRulePage*>& matchedRules, const Vector<StyleRulePage*>& rules, bool isLeftPage, bool isFirstPage, const String& pageName)
2469
{
2470
    for (unsigned i = 0; i < rules.size(); ++i) {
2471
        StyleRulePage* rule = rules[i];
2472
2473
        if (!checkPageSelectorComponents(rule->selector(), isLeftPage, isFirstPage, pageName))
2474
            continue;
2475
2476
        // If the rule has no properties to apply, then ignore it.
2477
        const StylePropertySet* properties = rule->properties();
2478
        if (!properties || properties->isEmpty())
2479
            continue;
2480
2481
        // Add this rule to our list of matched rules.
2482
        matchedRules.append(rule);
2483
    }
2484
}
2485
2486
bool StyleResolver::isLeftPage(int pageIndex) const
2487
{
2488
    bool isFirstPageLeft = false;
2489
    if (!m_state.rootElementStyle()->isLeftToRightDirection())
2490
        isFirstPageLeft = true;
2491
2492
    return (pageIndex + (isFirstPageLeft ? 1 : 0)) % 2;
2493
}
2494
2495
bool StyleResolver::isFirstPage(int pageIndex) const
2496
{
2497
    // FIXME: In case of forced left/right page, page at index 1 (not 0) can be the first page.
2498
    return (!pageIndex);
2499
}
2500
2501
String StyleResolver::pageName(int /* pageIndex */) const
2502
{
2503
    // FIXME: Implement page index to page name mapping.
2504
    return "";
2505
}
2506
1957
void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style)
2507
void StyleResolver::applyPropertyToStyle(CSSPropertyID id, CSSValue* value, RenderStyle* style)
1958
{
2508
{
1959
    initElement(0);
2509
    initElement(0);
- a/Source/WebCore/css/StyleResolver.h -34 / +55 lines
Lines 36-42 a/Source/WebCore/css/StyleResolver.h_sec1
36
#include "ScrollTypes.h"
36
#include "ScrollTypes.h"
37
#include "SelectorChecker.h"
37
#include "SelectorChecker.h"
38
#include "SelectorFilter.h"
38
#include "SelectorFilter.h"
39
#include "SiblingTraversalStrategies.h"
40
#include "StyleInheritedData.h"
39
#include "StyleInheritedData.h"
41
#include "StyleScopeResolver.h"
40
#include "StyleScopeResolver.h"
42
#include "ViewportStyleResolver.h"
41
#include "ViewportStyleResolver.h"
Lines 157-166 public: a/Source/WebCore/css/StyleResolver.h_sec2
157
    MatchRequest(RuleSet* ruleSet, bool includeEmptyRules = false, const ContainerNode* scope = 0, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary)
156
    MatchRequest(RuleSet* ruleSet, bool includeEmptyRules = false, const ContainerNode* scope = 0, SelectorChecker::BehaviorAtBoundary behaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary)
158
        : ruleSet(ruleSet)
157
        : ruleSet(ruleSet)
159
        , includeEmptyRules(includeEmptyRules)
158
        , includeEmptyRules(includeEmptyRules)
160
        , scope(scope) { }
159
        , scope(scope)
160
        , behaviorAtBoundary(behaviorAtBoundary) { }
161
    const RuleSet* ruleSet;
161
    const RuleSet* ruleSet;
162
    const bool includeEmptyRules;
162
    const bool includeEmptyRules;
163
    const ContainerNode* scope;
163
    const ContainerNode* scope;
164
    const SelectorChecker::BehaviorAtBoundary behaviorAtBoundary;
164
};
165
};
165
166
166
// This class selects a RenderStyle for a given element based on a collection of stylesheets.
167
// This class selects a RenderStyle for a given element based on a collection of stylesheets.
Lines 206-212 public: a/Source/WebCore/css/StyleResolver.h_sec3
206
207
207
    DocumentRuleSets& ruleSets() { return m_ruleSets; }
208
    DocumentRuleSets& ruleSets() { return m_ruleSets; }
208
    const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
209
    const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
209
    SelectorFilter& selectorFilter() { return m_selectorFilter; }
210
210
211
#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
211
#if ENABLE(STYLE_SCOPED) || ENABLE(SHADOW_DOM)
212
    StyleScopeResolver* ensureScopeResolver()
212
    StyleScopeResolver* ensureScopeResolver()
Lines 325-330 public: a/Source/WebCore/css/StyleResolver.h_sec4
325
325
326
    void loadPendingResources();
326
    void loadPendingResources();
327
327
328
private:
329
    // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
330
    void checkForGenericFamilyChange(RenderStyle*, RenderStyle* parentStyle);
331
    void checkForZoomChange(RenderStyle*, RenderStyle* parentStyle);
332
    void checkForTextSizeAdjust();
333
334
    void adjustRenderStyle(RenderStyle* styleToAdjust, RenderStyle* parentStyle, Element*);
335
328
    struct RuleRange {
336
    struct RuleRange {
329
        RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { }
337
        RuleRange(int& firstRuleIndex, int& lastRuleIndex): firstRuleIndex(firstRuleIndex), lastRuleIndex(lastRuleIndex) { }
330
        int& firstRuleIndex;
338
        int& firstRuleIndex;
Lines 366-387 public: a/Source/WebCore/css/StyleResolver.h_sec5
366
        Vector<StyleRule*, 64> matchedRules;
374
        Vector<StyleRule*, 64> matchedRules;
367
        MatchRanges ranges;
375
        MatchRanges ranges;
368
        bool isCacheable;
376
        bool isCacheable;
369
370
        void addMatchedProperties(const StylePropertySet* properties, StyleRule* = 0, unsigned linkMatchType = SelectorChecker::MatchAll, PropertyWhitelistType = PropertyWhitelistNone);
371
    };
377
    };
372
378
373
private:
379
    static void addMatchedProperties(MatchResult&, const StylePropertySet* properties, StyleRule* = 0, unsigned linkMatchType = SelectorChecker::MatchAll, PropertyWhitelistType = PropertyWhitelistNone);
374
    // This function fixes up the default font size if it detects that the current generic font family has changed. -dwh
380
    void addElementStyleProperties(MatchResult&, const StylePropertySet*, bool isCacheable = true);
375
    void checkForGenericFamilyChange(RenderStyle*, RenderStyle* parentStyle);
376
    void checkForZoomChange(RenderStyle*, RenderStyle* parentStyle);
377
    void checkForTextSizeAdjust();
378
381
379
    void adjustRenderStyle(RenderStyle* styleToAdjust, RenderStyle* parentStyle, Element*);
382
    void matchAllRules(MatchResult&, bool includeSMILProperties);
383
    void matchUARules(MatchResult&);
384
    void matchUARules(MatchResult&, RuleSet*);
385
    void matchAuthorRules(MatchResult&, bool includeEmptyRules);
386
    void matchUserRules(MatchResult&, bool includeEmptyRules);
387
    void matchScopedAuthorRules(MatchResult&, bool includeEmptyRules);
388
    void matchHostRules(MatchResult&, bool includeEmptyRules);
389
390
    void collectMatchingRules(const MatchRequest&, RuleRange&);
391
    void collectMatchingRulesForRegion(const MatchRequest&, RuleRange&);
392
    void collectMatchingRulesForList(const Vector<RuleData>*, const MatchRequest&, RuleRange&);
380
393
381
    bool fastRejectSelector(const RuleData&) const;
394
    bool fastRejectSelector(const RuleData&) const;
395
    void sortMatchedRules();
396
    void sortAndTransferMatchedRules(MatchResult&);
382
397
398
    bool ruleMatches(const RuleData&, const ContainerNode* scope, PseudoId&, SelectorChecker::BehaviorAtBoundary = SelectorChecker::DoesNotCrossBoundary);
399
    bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement);
383
    void applyMatchedProperties(const MatchResult&, const Element*);
400
    void applyMatchedProperties(const MatchResult&, const Element*);
384
385
    enum StyleApplicationPass {
401
    enum StyleApplicationPass {
386
#if ENABLE(CSS_VARIABLES)
402
#if ENABLE(CSS_VARIABLES)
387
        VariableDefinitions,
403
        VariableDefinitions,
Lines 430-438 public: a/Source/WebCore/css/StyleResolver.h_sec6
430
        , m_parentStyle(0)
446
        , m_parentStyle(0)
431
        , m_rootElementStyle(0)
447
        , m_rootElementStyle(0)
432
        , m_regionForStyling(0)
448
        , m_regionForStyling(0)
449
        , m_sameOriginOnly(false)
450
        , m_pseudoStyleRequest(NOPSEUDO)
433
        , m_elementLinkState(NotInsideLink)
451
        , m_elementLinkState(NotInsideLink)
434
        , m_distributedToInsertionPoint(false)
452
        , m_distributedToInsertionPoint(false)
435
        , m_elementAffectedByClassRules(false)
453
        , m_elementAffectedByClassRules(false)
454
        , m_mode(SelectorChecker::ResolvingStyle)
436
        , m_applyPropertyToRegularStyle(true)
455
        , m_applyPropertyToRegularStyle(true)
437
        , m_applyPropertyToVisitedLinkStyle(false)
456
        , m_applyPropertyToVisitedLinkStyle(false)
438
#if ENABLE(CSS_SHADERS)
457
#if ENABLE(CSS_SHADERS)
Lines 445-451 public: a/Source/WebCore/css/StyleResolver.h_sec7
445
464
446
    public:
465
    public:
447
        void initElement(Element*);
466
        void initElement(Element*);
448
        void initForStyleResolve(Document*, Element*, RenderStyle* parentStyle = 0, RenderRegion* regionForStyling = 0);
467
        void initForStyleResolve(Document*, Element*, RenderStyle* parentStyle = 0, const PseudoStyleRequest& = PseudoStyleRequest(NOPSEUDO), RenderRegion* regionForStyling = 0);
449
        void clear();
468
        void clear();
450
469
451
        Document* document() const { return m_element->document(); }
470
        Document* document() const { return m_element->document(); }
Lines 455-471 public: a/Source/WebCore/css/StyleResolver.h_sec8
455
        RenderStyle* style() const { return m_style.get(); }
474
        RenderStyle* style() const { return m_style.get(); }
456
        PassRefPtr<RenderStyle> takeStyle() { return m_style.release(); }
475
        PassRefPtr<RenderStyle> takeStyle() { return m_style.release(); }
457
476
477
        StaticCSSRuleList* ensureRuleList();
478
        PassRefPtr<CSSRuleList> takeRuleList() { return m_ruleList.release(); }
479
458
        const ContainerNode* parentNode() const { return m_parentNode; }
480
        const ContainerNode* parentNode() const { return m_parentNode; }
459
        void setParentStyle(RenderStyle* parentStyle) { m_parentStyle = parentStyle; }
481
        void setParentStyle(RenderStyle* parentStyle) { m_parentStyle = parentStyle; }
460
        RenderStyle* parentStyle() const { return m_parentStyle; }
482
        RenderStyle* parentStyle() const { return m_parentStyle; }
461
        RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
483
        RenderStyle* rootElementStyle() const { return m_rootElementStyle; }
462
484
463
        const RenderRegion* regionForStyling() const { return m_regionForStyling; }
485
        const RenderRegion* regionForStyling() const { return m_regionForStyling; }
486
        void setSameOriginOnly(bool isSameOriginOnly) { m_sameOriginOnly = isSameOriginOnly; }
487
        bool isSameOriginOnly() const { return m_sameOriginOnly; }
488
        const PseudoStyleRequest& pseudoStyleRequest() const { return m_pseudoStyleRequest; }
464
        EInsideLink elementLinkState() const { return m_elementLinkState; }
489
        EInsideLink elementLinkState() const { return m_elementLinkState; }
465
        bool distributedToInsertionPoint() const { return m_distributedToInsertionPoint; }
490
        bool distributedToInsertionPoint() const { return m_distributedToInsertionPoint; }
466
        void setElementAffectedByClassRules(bool isAffected) { m_elementAffectedByClassRules = isAffected; }
491
        void setElementAffectedByClassRules(bool isAffected) { m_elementAffectedByClassRules = isAffected; }
467
        bool elementAffectedByClassRules() const { return m_elementAffectedByClassRules; }
492
        bool elementAffectedByClassRules() const { return m_elementAffectedByClassRules; }
468
493
        void setMode(SelectorChecker::Mode mode) { m_mode = mode; }
494
        SelectorChecker::Mode mode() const { return m_mode; }
495
        
469
        void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
496
        void setApplyPropertyToRegularStyle(bool isApply) { m_applyPropertyToRegularStyle = isApply; }
470
        void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
497
        void setApplyPropertyToVisitedLinkStyle(bool isApply) { m_applyPropertyToVisitedLinkStyle = isApply; }
471
        bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
498
        bool applyPropertyToRegularStyle() const { return m_applyPropertyToRegularStyle; }
Lines 499-506 public: a/Source/WebCore/css/StyleResolver.h_sec9
499
        void setWritingMode(WritingMode writingMode) { m_fontDirty |= m_style->setWritingMode(writingMode); }
526
        void setWritingMode(WritingMode writingMode) { m_fontDirty |= m_style->setWritingMode(writingMode); }
500
        void setTextOrientation(TextOrientation textOrientation) { m_fontDirty |= m_style->setTextOrientation(textOrientation); }
527
        void setTextOrientation(TextOrientation textOrientation) { m_fontDirty |= m_style->setTextOrientation(textOrientation); }
501
528
502
        bool useSVGZoomRules() const { return m_element && m_element->isSVGElement(); }
529
        Vector<const RuleData*, 32>& matchedRules() { return m_matchedRules; }
503
530
        void addMatchedRule(const RuleData* rule) { m_matchedRules.append(rule); }
531
        
504
    private:
532
    private:
505
        // FIXME(bug 108563): to make it easier to review, these member
533
        // FIXME(bug 108563): to make it easier to review, these member
506
        // variables are public. However we should add methods to access
534
        // variables are public. However we should add methods to access
Lines 511-526 public: a/Source/WebCore/css/StyleResolver.h_sec10
511
        ContainerNode* m_parentNode;
539
        ContainerNode* m_parentNode;
512
        RenderStyle* m_parentStyle;
540
        RenderStyle* m_parentStyle;
513
        RenderStyle* m_rootElementStyle;
541
        RenderStyle* m_rootElementStyle;
514
515
        // Required to ASSERT in applyProperties.
516
        RenderRegion* m_regionForStyling;
517
        
542
        
543
        RenderRegion* m_regionForStyling;
544
        bool m_sameOriginOnly;
545
        PseudoStyleRequest m_pseudoStyleRequest;
546
518
        EInsideLink m_elementLinkState;
547
        EInsideLink m_elementLinkState;
519
548
520
        bool m_distributedToInsertionPoint;
549
        bool m_distributedToInsertionPoint;
521
550
522
        bool m_elementAffectedByClassRules;
551
        bool m_elementAffectedByClassRules;
523
552
553
        SelectorChecker::Mode m_mode;
554
555
        // A buffer used to hold the set of matched rules for an element,
556
        // and a temporary buffer used for merge sorting.
557
        Vector<const RuleData*, 32> m_matchedRules;
558
        RefPtr<StaticCSSRuleList> m_ruleList;
559
524
        bool m_applyPropertyToRegularStyle;
560
        bool m_applyPropertyToRegularStyle;
525
        bool m_applyPropertyToVisitedLinkStyle;
561
        bool m_applyPropertyToVisitedLinkStyle;
526
562
Lines 659-679 inline bool StyleResolver::hasSelectorForId(const AtomicString& idValue) const a/Source/WebCore/css/StyleResolver.h_sec11
659
    return m_ruleSets.features().idsInRules.contains(idValue.impl());
695
    return m_ruleSets.features().idsInRules.contains(idValue.impl());
660
}
696
}
661
697
662
inline bool checkRegionSelector(const CSSSelector* regionSelector, Element* regionElement)
663
{
664
    if (!regionSelector || !regionElement)
665
        return false;
666
667
    SelectorChecker selectorChecker(regionElement->document(), SelectorChecker::QueryingRules);
668
    for (const CSSSelector* s = regionSelector; s; s = CSSSelectorList::next(s)) {
669
        SelectorChecker::SelectorCheckingContext selectorCheckingContext(s, regionElement, SelectorChecker::VisitedMatchDisabled);
670
        PseudoId ignoreDynamicPseudo = NOPSEUDO;
671
        if (selectorChecker.match(selectorCheckingContext, ignoreDynamicPseudo, DOMSiblingTraversalStrategy()) == SelectorChecker::SelectorMatches)
672
            return true;
673
    }
674
    return false;
675
}
676
677
} // namespace WebCore
698
} // namespace WebCore
678
699
679
#endif // StyleResolver_h
700
#endif // StyleResolver_h
- a/Source/WebCore/inspector/InspectorCSSAgent.cpp -2 / +2 lines
Lines 958-968 PassRefPtr<TypeBuilder::CSS::SelectorProfile> InspectorCSSAgent::stopSelectorPro a/Source/WebCore/inspector/InspectorCSSAgent.cpp_sec1
958
    return result.release();
958
    return result.release();
959
}
959
}
960
960
961
void InspectorCSSAgent::willMatchRule(StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection)
961
void InspectorCSSAgent::willMatchRule(StyleRule* rule, StyleResolver* styleResolver)
962
{
962
{
963
//    printf("InspectorCSSAgent::willMatchRule %s\n", rule->selectorList().selectorsText().utf8().data());
963
//    printf("InspectorCSSAgent::willMatchRule %s\n", rule->selectorList().selectorsText().utf8().data());
964
    if (m_currentSelectorProfile)
964
    if (m_currentSelectorProfile)
965
        m_currentSelectorProfile->startSelector(inspectorCSSOMWrappers.getWrapperForRuleInSheets(rule, styleSheetCollection));
965
        m_currentSelectorProfile->startSelector(styleResolver->inspectorCSSOMWrappers().getWrapperForRuleInSheets(rule, styleResolver->document()->styleSheetCollection()));
966
}
966
}
967
967
968
void InspectorCSSAgent::didMatchRule(bool matched)
968
void InspectorCSSAgent::didMatchRule(bool matched)
- a/Source/WebCore/inspector/InspectorCSSAgent.h -3 / +1 lines
Lines 47-55 class CSSStyleDeclaration; a/Source/WebCore/inspector/InspectorCSSAgent.h_sec1
47
class CSSStyleRule;
47
class CSSStyleRule;
48
class CSSStyleSheet;
48
class CSSStyleSheet;
49
class Document;
49
class Document;
50
class DocumentStyleSheetCollection;
51
class Element;
50
class Element;
52
class InspectorCSSOMWrappers;
53
class InspectorFrontend;
51
class InspectorFrontend;
54
class InstrumentingAgents;
52
class InstrumentingAgents;
55
class NameNodeMap;
53
class NameNodeMap;
Lines 127-133 public: a/Source/WebCore/inspector/InspectorCSSAgent.h_sec2
127
    virtual void stopSelectorProfiler(ErrorString*, RefPtr<TypeBuilder::CSS::SelectorProfile>&);
125
    virtual void stopSelectorProfiler(ErrorString*, RefPtr<TypeBuilder::CSS::SelectorProfile>&);
128
126
129
    PassRefPtr<TypeBuilder::CSS::SelectorProfile> stopSelectorProfilerImpl(ErrorString*, bool needProfile);
127
    PassRefPtr<TypeBuilder::CSS::SelectorProfile> stopSelectorProfilerImpl(ErrorString*, bool needProfile);
130
    void willMatchRule(StyleRule*, InspectorCSSOMWrappers&, DocumentStyleSheetCollection*);
128
    void willMatchRule(StyleRule*, StyleResolver*);
131
    void didMatchRule(bool);
129
    void didMatchRule(bool);
132
    void willProcessRule(StyleRule*, StyleResolver*);
130
    void willProcessRule(StyleRule*, StyleResolver*);
133
    void didProcessRule();
131
    void didProcessRule();
- a/Source/WebCore/inspector/InspectorInstrumentation.cpp -2 / +2 lines
Lines 590-600 void InspectorInstrumentation::didScheduleStyleRecalculationImpl(InstrumentingAg a/Source/WebCore/inspector/InspectorInstrumentation.cpp_sec1
590
        resourceAgent->didScheduleStyleRecalculation(document);
590
        resourceAgent->didScheduleStyleRecalculation(document);
591
}
591
}
592
592
593
InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* sheetCollection)
593
InspectorInstrumentationCookie InspectorInstrumentation::willMatchRuleImpl(InstrumentingAgents* instrumentingAgents, StyleRule* rule, StyleResolver* styleResolver)
594
{
594
{
595
    InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
595
    InspectorCSSAgent* cssAgent = instrumentingAgents->inspectorCSSAgent();
596
    if (cssAgent) {
596
    if (cssAgent) {
597
        cssAgent->willMatchRule(rule, inspectorCSSOMWrappers, sheetCollection);
597
        cssAgent->willMatchRule(rule, styleResolver);
598
        return InspectorInstrumentationCookie(instrumentingAgents, 1);
598
        return InspectorInstrumentationCookie(instrumentingAgents, 1);
599
    }
599
    }
600
600
- a/Source/WebCore/inspector/InspectorInstrumentation.h -8 / +5 lines
Lines 61-72 class Document; a/Source/WebCore/inspector/InspectorInstrumentation.h_sec1
61
class Element;
61
class Element;
62
class EventContext;
62
class EventContext;
63
class DocumentLoader;
63
class DocumentLoader;
64
class DocumentStyleSheetCollection;
65
class DeviceOrientationData;
64
class DeviceOrientationData;
66
class GeolocationPosition;
65
class GeolocationPosition;
67
class GraphicsContext;
66
class GraphicsContext;
68
class InspectorCSSAgent;
67
class InspectorCSSAgent;
69
class InspectorCSSOMWrappers;
70
class InspectorInstrumentation;
68
class InspectorInstrumentation;
71
class InspectorTimelineAgent;
69
class InspectorTimelineAgent;
72
class InstrumentingAgents;
70
class InstrumentingAgents;
Lines 176-182 public: a/Source/WebCore/inspector/InspectorInstrumentation.h_sec2
176
    static InspectorInstrumentationCookie willRecalculateStyle(Document*);
174
    static InspectorInstrumentationCookie willRecalculateStyle(Document*);
177
    static void didRecalculateStyle(const InspectorInstrumentationCookie&);
175
    static void didRecalculateStyle(const InspectorInstrumentationCookie&);
178
    static void didScheduleStyleRecalculation(Document*);
176
    static void didScheduleStyleRecalculation(Document*);
179
    static InspectorInstrumentationCookie willMatchRule(Document*, StyleRule*, InspectorCSSOMWrappers&, DocumentStyleSheetCollection*);
177
    static InspectorInstrumentationCookie willMatchRule(Document*, StyleRule*, StyleResolver*);
180
    static void didMatchRule(const InspectorInstrumentationCookie&, bool matched);
178
    static void didMatchRule(const InspectorInstrumentationCookie&, bool matched);
181
    static InspectorInstrumentationCookie willProcessRule(Document*, StyleRule*, StyleResolver*);
179
    static InspectorInstrumentationCookie willProcessRule(Document*, StyleRule*, StyleResolver*);
182
    static void didProcessRule(const InspectorInstrumentationCookie&);
180
    static void didProcessRule(const InspectorInstrumentationCookie&);
Lines 377-383 private: a/Source/WebCore/inspector/InspectorInstrumentation.h_sec3
377
    static InspectorInstrumentationCookie willRecalculateStyleImpl(InstrumentingAgents*, Frame*);
375
    static InspectorInstrumentationCookie willRecalculateStyleImpl(InstrumentingAgents*, Frame*);
378
    static void didRecalculateStyleImpl(const InspectorInstrumentationCookie&);
376
    static void didRecalculateStyleImpl(const InspectorInstrumentationCookie&);
379
    static void didScheduleStyleRecalculationImpl(InstrumentingAgents*, Document*);
377
    static void didScheduleStyleRecalculationImpl(InstrumentingAgents*, Document*);
380
    static InspectorInstrumentationCookie willMatchRuleImpl(InstrumentingAgents*, StyleRule*, InspectorCSSOMWrappers&, DocumentStyleSheetCollection*);
378
    static InspectorInstrumentationCookie willMatchRuleImpl(InstrumentingAgents*, StyleRule*, StyleResolver*);
381
    static void didMatchRuleImpl(const InspectorInstrumentationCookie&, bool matched);
379
    static void didMatchRuleImpl(const InspectorInstrumentationCookie&, bool matched);
382
    static InspectorInstrumentationCookie willProcessRuleImpl(InstrumentingAgents*, StyleRule*, StyleResolver*);
380
    static InspectorInstrumentationCookie willProcessRuleImpl(InstrumentingAgents*, StyleRule*, StyleResolver*);
383
    static void didProcessRuleImpl(const InspectorInstrumentationCookie&);
381
    static void didProcessRuleImpl(const InspectorInstrumentationCookie&);
Lines 1180-1196 inline void InspectorInstrumentation::didScheduleStyleRecalculation(Document* do a/Source/WebCore/inspector/InspectorInstrumentation.h_sec4
1180
#endif
1178
#endif
1181
}
1179
}
1182
1180
1183
inline InspectorInstrumentationCookie InspectorInstrumentation::willMatchRule(Document* document, StyleRule* rule, InspectorCSSOMWrappers& inspectorCSSOMWrappers, DocumentStyleSheetCollection* styleSheetCollection)
1181
inline InspectorInstrumentationCookie InspectorInstrumentation::willMatchRule(Document* document, StyleRule* rule, StyleResolver* styleResolver)
1184
{
1182
{
1185
#if ENABLE(INSPECTOR)
1183
#if ENABLE(INSPECTOR)
1186
    FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
1184
    FAST_RETURN_IF_NO_FRONTENDS(InspectorInstrumentationCookie());
1187
    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1185
    if (InstrumentingAgents* instrumentingAgents = instrumentingAgentsForDocument(document))
1188
        return willMatchRuleImpl(instrumentingAgents, rule, inspectorCSSOMWrappers, styleSheetCollection);
1186
        return willMatchRuleImpl(instrumentingAgents, rule, styleResolver);
1189
#else
1187
#else
1190
    UNUSED_PARAM(document);
1188
    UNUSED_PARAM(document);
1191
    UNUSED_PARAM(rule);
1189
    UNUSED_PARAM(rule);
1192
    UNUSED_PARAM(inspectorCSSOMWrappers);
1190
    UNUSED_PARAM(styleResolver);
1193
    UNUSED_PARAM(styleSheetCollection);
1194
#endif
1191
#endif
1195
    return InspectorInstrumentationCookie();
1192
    return InspectorInstrumentationCookie();
1196
}
1193
}

Return to Bug 111707