Diff
Modified: trunk/Source/WebCore/ChangeLog (209303 => 209304)
--- trunk/Source/WebCore/ChangeLog 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/ChangeLog 2016-12-03 21:22:49 UTC (rev 209304)
@@ -1,3 +1,67 @@
+2016-12-03 Dave Hyatt <hy...@apple.com>
+
+ [CSS Parser] Remove line numbers from StyleRule.
+ https://bugs.webkit.org/show_bug.cgi?id=165361
+
+ Reviewed by Simon Fraser.
+
+ StyleRules have a concept of a source line that is eventually passed
+ to the inspector. This was only ever used by normal rules, i.e., ones with
+ selectors, and set to 0 for all other rules. This line was set to the line number
+ at which the end of the selector text occurred.
+
+ Because Inspector already computes the start and end range for the selector
+ text, storing a source line on StyleRule ends up being redundant. This patch
+ gets rid of the source line and uses the end line of the selector text
+ instead.
+
+ * css/CSSGrammar.y.in:
+ Remove the code that updates the last seen selector line.
+
+ * css/CSSKeyframeRule.cpp:
+ (WebCore::StyleKeyframe::StyleKeyframe):
+ * css/CSSKeyframesRule.cpp:
+ (WebCore::StyleRuleKeyframes::StyleRuleKeyframes):
+ No longer need to pass in a 0 line number.
+
+ * css/StyleRule.cpp:
+ (WebCore::StyleRule::StyleRule):
+ (WebCore::StyleRule::create):
+ (WebCore::StyleRule::splitIntoMultipleRulesWithMaximumSelectorComponentCount):
+ (WebCore::StyleRuleFontFace::StyleRuleFontFace):
+ (WebCore::StyleRuleGroup::StyleRuleGroup):
+ (WebCore::StyleRuleCharset::StyleRuleCharset):
+ (WebCore::StyleRuleNamespace::StyleRuleNamespace):
+ * css/StyleRule.h:
+ (WebCore::StyleRuleBase::StyleRuleBase):
+ (WebCore::StyleRuleBase::sourceLine): Deleted.
+ * css/StyleRuleImport.cpp:
+ (WebCore::StyleRuleImport::StyleRuleImport):
+ Remove m_sourceLine and change the create methods and constructors to not
+ require a line number.
+
+ * css/parser/CSSParser.cpp:
+ (WebCore::CSSParser::createStyleRule):
+ Line number no longer needed.
+
+ (WebCore::CSSParser::updateLastSelectorLineAndPosition): Deleted.
+ * css/parser/CSSParser.h:
+ Got rid of the function that tracks and updates the last seen selector line.
+
+ * css/parser/CSSParserImpl.cpp:
+ (WebCore::CSSParserImpl::consumeStyleRule):
+ Fix the rule creation in the new parser to not pass in a 0 line number.
+
+ * inspector/InspectorStyleSheet.cpp:
+ (WebCore::buildSourceRangeObject):
+ (WebCore::InspectorStyleSheet::buildObjectForSelectorList):
+ (WebCore::InspectorStyleSheet::buildObjectForRule):
+ * inspector/InspectorStyleSheet.h:
+ Patch the methods that build up the selector range to return the end line
+ information for selector text so that it can be set as the source line
+ for the rule (thus eliminating the need to store the line number on the style
+ rule itself).
+
2016-12-02 Sam Weinig <s...@webkit.org>
optional sequence values not handled correctly by binding generator
Modified: trunk/Source/WebCore/css/CSSGrammar.y.in (209303 => 209304)
--- trunk/Source/WebCore/css/CSSGrammar.y.in 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/CSSGrammar.y.in 2016-12-03 21:22:49 UTC (rev 209304)
@@ -1048,7 +1048,6 @@
if ($1) {
$$ = parser->createSelectorVector().release();
$$->append(std::unique_ptr<CSSParserSelector>($1));
- parser->updateLastSelectorLineAndPosition();
}
}
| selector_list at_selector_end ',' maybe_space before_selector_group_item complex_selector %prec UNIMPORTANT_TOK {
@@ -1058,7 +1057,6 @@
if (selectorList && selector) {
$$ = selectorList.release();
$$->append(WTFMove(selector));
- parser->updateLastSelectorLineAndPosition();
}
}
| selector_list error {
Modified: trunk/Source/WebCore/css/CSSKeyframeRule.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/CSSKeyframeRule.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/CSSKeyframeRule.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -34,13 +34,13 @@
namespace WebCore {
StyleKeyframe::StyleKeyframe(Ref<StyleProperties>&& properties)
- : StyleRuleBase(Keyframe, 0)
+ : StyleRuleBase(Keyframe)
, m_properties(WTFMove(properties))
{
}
StyleKeyframe::StyleKeyframe(std::unique_ptr<Vector<double>> keys, Ref<StyleProperties>&& properties)
- : StyleRuleBase(Keyframe, 0)
+ : StyleRuleBase(Keyframe)
, m_properties(WTFMove(properties))
, m_keys(*keys)
{
Modified: trunk/Source/WebCore/css/CSSKeyframesRule.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/CSSKeyframesRule.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/CSSKeyframesRule.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -38,7 +38,7 @@
namespace WebCore {
StyleRuleKeyframes::StyleRuleKeyframes()
- : StyleRuleBase(Keyframes, 0)
+ : StyleRuleBase(Keyframes)
{
}
Modified: trunk/Source/WebCore/css/StyleRule.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/StyleRule.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/StyleRule.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -40,7 +40,7 @@
namespace WebCore {
struct SameSizeAsStyleRuleBase : public WTF::RefCountedBase {
- unsigned bitfields;
+ unsigned bitfields : 5;
};
COMPILE_ASSERT(sizeof(StyleRuleBase) == sizeof(SameSizeAsStyleRuleBase), StyleRuleBase_should_stay_small);
@@ -204,8 +204,8 @@
return sizeof(StyleRule) + sizeof(CSSSelector) + StyleProperties::averageSizeInBytes();
}
-StyleRule::StyleRule(int sourceLine, Ref<StyleProperties>&& properties)
- : StyleRuleBase(Style, sourceLine)
+StyleRule::StyleRule(Ref<StyleProperties>&& properties)
+ : StyleRuleBase(Style)
, m_properties(WTFMove(properties))
{
}
@@ -228,7 +228,7 @@
return downcast<MutableStyleProperties>(m_properties.get());
}
-Ref<StyleRule> StyleRule::create(int sourceLine, const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties)
+Ref<StyleRule> StyleRule::create(const Vector<const CSSSelector*>& selectors, Ref<StyleProperties>&& properties)
{
ASSERT_WITH_SECURITY_IMPLICATION(!selectors.isEmpty());
CSSSelector* selectorListArray = reinterpret_cast<CSSSelector*>(fastMalloc(sizeof(CSSSelector) * selectors.size()));
@@ -235,7 +235,7 @@
for (unsigned i = 0; i < selectors.size(); ++i)
new (NotNull, &selectorListArray[i]) CSSSelector(*selectors.at(i));
selectorListArray[selectors.size() - 1].setLastInSelectorList();
- auto rule = StyleRule::create(sourceLine, WTFMove(properties));
+ auto rule = StyleRule::create(WTFMove(properties));
rule.get().parserAdoptSelectorArray(selectorListArray);
return rule;
}
@@ -253,7 +253,7 @@
componentsInThisSelector.append(component);
if (componentsInThisSelector.size() + componentsSinceLastSplit.size() > maxCount && !componentsSinceLastSplit.isEmpty()) {
- rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
+ rules.append(create(componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
componentsSinceLastSplit.clear();
}
@@ -261,7 +261,7 @@
}
if (!componentsSinceLastSplit.isEmpty())
- rules.append(create(sourceLine(), componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
+ rules.append(create(componentsSinceLastSplit, const_cast<StyleProperties&>(m_properties.get())));
return rules;
}
@@ -291,7 +291,7 @@
}
StyleRuleFontFace::StyleRuleFontFace(Ref<StyleProperties>&& properties)
- : StyleRuleBase(FontFace, 0)
+ : StyleRuleBase(FontFace)
, m_properties(WTFMove(properties))
{
}
@@ -314,7 +314,7 @@
}
StyleRuleGroup::StyleRuleGroup(Type type, Vector<RefPtr<StyleRuleBase>>& adoptRule)
- : StyleRuleBase(type, 0)
+ : StyleRuleBase(type)
{
m_childRules.swap(adoptRule);
}
@@ -411,7 +411,7 @@
#endif // ENABLE(CSS_DEVICE_ADAPTATION)
StyleRuleCharset::StyleRuleCharset()
- : StyleRuleBase(Charset, 0)
+ : StyleRuleBase(Charset)
{
}
@@ -425,7 +425,7 @@
}
StyleRuleNamespace::StyleRuleNamespace(AtomicString prefix, AtomicString uri)
- : StyleRuleBase(Namespace, 0)
+ : StyleRuleBase(Namespace)
, m_prefix(prefix)
, m_uri(uri)
{
Modified: trunk/Source/WebCore/css/StyleRule.h (209303 => 209304)
--- trunk/Source/WebCore/css/StyleRule.h 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/StyleRule.h 2016-12-03 21:22:49 UTC (rev 209304)
@@ -76,8 +76,6 @@
Ref<StyleRuleBase> copy() const;
- int sourceLine() const { return m_sourceLine; }
-
void deref()
{
if (derefBase())
@@ -89,9 +87,15 @@
RefPtr<CSSRule> createCSSOMWrapper(CSSRule* parentRule) const;
protected:
- StyleRuleBase(Type type, signed sourceLine = 0) : m_type(type), m_sourceLine(sourceLine) { }
- StyleRuleBase(const StyleRuleBase& o) : WTF::RefCountedBase(), m_type(o.m_type), m_sourceLine(o.m_sourceLine) { }
+ StyleRuleBase(Type type)
+ : m_type(type)
+ { }
+ StyleRuleBase(const StyleRuleBase& o)
+ : WTF::RefCountedBase()
+ , m_type(o.m_type)
+ { }
+
~StyleRuleBase() { }
private:
@@ -100,15 +104,14 @@
RefPtr<CSSRule> createCSSOMWrapper(CSSStyleSheet* parentSheet, CSSRule* parentRule) const;
unsigned m_type : 5;
- signed m_sourceLine : 27;
};
class StyleRule final : public StyleRuleBase {
WTF_MAKE_FAST_ALLOCATED;
public:
- static Ref<StyleRule> create(int sourceLine, Ref<StyleProperties>&& properties)
+ static Ref<StyleRule> create(Ref<StyleProperties>&& properties)
{
- return adoptRef(*new StyleRule(sourceLine, WTFMove(properties)));
+ return adoptRef(*new StyleRule(WTFMove(properties)));
}
~StyleRule();
@@ -128,10 +131,10 @@
static unsigned averageSizeInBytes();
private:
- StyleRule(int sourceLine, Ref<StyleProperties>&&);
+ StyleRule(Ref<StyleProperties>&&);
StyleRule(const StyleRule&);
- static Ref<StyleRule> create(int sourceLine, const Vector<const CSSSelector*>&, Ref<StyleProperties>&&);
+ static Ref<StyleRule> create(const Vector<const CSSSelector*>&, Ref<StyleProperties>&&);
Ref<StyleProperties> m_properties;
CSSSelectorList m_selectorList;
Modified: trunk/Source/WebCore/css/StyleRuleImport.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/StyleRuleImport.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/StyleRuleImport.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -41,7 +41,7 @@
}
StyleRuleImport::StyleRuleImport(const String& href, Ref<MediaQuerySet>&& media)
- : StyleRuleBase(Import, 0)
+ : StyleRuleBase(Import)
, m_parentStyleSheet(0)
, m_styleSheetClient(this)
, m_strHref(href)
Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/parser/CSSParser.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -13042,7 +13042,7 @@
if (selectors) {
m_allowImportRules = false;
m_allowNamespaceDeclarations = false;
- rule = StyleRule::create(m_lastSelectorLineNumber, createStyleProperties());
+ rule = StyleRule::create(createStyleProperties());
rule->parserAdoptSelectorVector(*selectors);
processAndAddNewRuleToSourceTreeIfNeeded();
} else
@@ -13269,11 +13269,6 @@
m_styleSheet->setHasSyntacticallyValidCSSHeader(false);
}
-void CSSParser::updateLastSelectorLineAndPosition()
-{
- m_lastSelectorLineNumber = m_lineNumber;
-}
-
void CSSParser::updateLastMediaLine(MediaQuerySet& media)
{
media.setLastLine(m_lineNumber);
Modified: trunk/Source/WebCore/css/parser/CSSParser.h (209303 => 209304)
--- trunk/Source/WebCore/css/parser/CSSParser.h 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/parser/CSSParser.h 2016-12-03 21:22:49 UTC (rev 209304)
@@ -415,7 +415,6 @@
void invalidBlockHit();
- void updateLastSelectorLineAndPosition();
void updateLastMediaLine(MediaQuerySet&);
void clearProperties();
@@ -652,7 +651,6 @@
int m_lineNumber { 0 };
int m_tokenStartLineNumber { 0 };
int m_tokenStartColumnNumber { 0 };
- int m_lastSelectorLineNumber { 0 };
int m_columnOffsetForLine { 0 };
int m_sheetStartLineNumber { 0 };
Modified: trunk/Source/WebCore/css/parser/CSSParserImpl.cpp (209303 => 209304)
--- trunk/Source/WebCore/css/parser/CSSParserImpl.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/css/parser/CSSParserImpl.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -689,8 +689,7 @@
consumeDeclarationList(block, StyleRule::Style);
- // FIXME-NEWPARSER: Line number is in the StyleRule constructor (gross), need to figure this out.
- RefPtr<StyleRule> rule = StyleRule::create(0, createStyleProperties(m_parsedProperties, m_context.mode));
+ RefPtr<StyleRule> rule = StyleRule::create(createStyleProperties(m_parsedProperties, m_context.mode));
rule->wrapperAdoptSelectorList(selectorList);
return rule;
}
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp (209303 => 209304)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.cpp 2016-12-03 21:22:49 UTC (rev 209304)
@@ -385,7 +385,7 @@
MediaListSourceImportRule
};
-static RefPtr<Inspector::Protocol::CSS::SourceRange> buildSourceRangeObject(const SourceRange& range, Vector<size_t>* lineEndings)
+static RefPtr<Inspector::Protocol::CSS::SourceRange> buildSourceRangeObject(const SourceRange& range, Vector<size_t>* lineEndings, int* endingLine = nullptr)
{
if (!lineEndings)
return nullptr;
@@ -392,6 +392,9 @@
TextPosition start = ContentSearchUtilities::textPositionFromOffset(range.start, *lineEndings);
TextPosition end = ContentSearchUtilities::textPositionFromOffset(range.end, *lineEndings);
+ if (endingLine)
+ *endingLine = end.m_line.zeroBasedInt();
+
return Inspector::Protocol::CSS::SourceRange::create()
.setStartLine(start.m_line.zeroBasedInt())
.setStartColumn(start.m_column.zeroBasedInt())
@@ -1115,7 +1118,7 @@
return buildObjectForSelectorHelper(selector->selectorText(), *selector, element);
}
-Ref<Inspector::Protocol::CSS::SelectorList> InspectorStyleSheet::buildObjectForSelectorList(CSSStyleRule* rule, Element* element)
+Ref<Inspector::Protocol::CSS::SelectorList> InspectorStyleSheet::buildObjectForSelectorList(CSSStyleRule* rule, Element* element, int& endingLine)
{
RefPtr<CSSRuleSourceData> sourceData;
if (ensureParsedDataReady())
@@ -1138,7 +1141,7 @@
.setText(selectorText)
.release();
if (sourceData)
- result->setRange(buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get()));
+ result->setRange(buildSourceRangeObject(sourceData->ruleHeaderRange, lineEndings().get(), &endingLine));
return result;
}
@@ -1148,9 +1151,10 @@
if (!styleSheet)
return nullptr;
+ int endingLine = 0;
auto result = Inspector::Protocol::CSS::CSSRule::create()
- .setSelectorList(buildObjectForSelectorList(rule, element))
- .setSourceLine(rule->styleRule().sourceLine())
+ .setSelectorList(buildObjectForSelectorList(rule, element, endingLine))
+ .setSourceLine(endingLine)
.setOrigin(m_origin)
.setStyle(buildObjectForStyle(&rule->style()))
.release();
Modified: trunk/Source/WebCore/inspector/InspectorStyleSheet.h (209303 => 209304)
--- trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2016-12-03 20:22:43 UTC (rev 209303)
+++ trunk/Source/WebCore/inspector/InspectorStyleSheet.h 2016-12-03 21:22:49 UTC (rev 209304)
@@ -215,7 +215,7 @@
bool inlineStyleSheetText(String* result) const;
Ref<Inspector::Protocol::Array<Inspector::Protocol::CSS::CSSRule>> buildArrayForRuleList(CSSRuleList*);
Ref<Inspector::Protocol::CSS::CSSSelector> buildObjectForSelector(const CSSSelector*, Element*);
- Ref<Inspector::Protocol::CSS::SelectorList> buildObjectForSelectorList(CSSStyleRule*, Element*);
+ Ref<Inspector::Protocol::CSS::SelectorList> buildObjectForSelectorList(CSSStyleRule*, Element*, int& endingLine);
InspectorPageAgent* m_pageAgent;
String m_id;