diff options
Diffstat (limited to 'WebCore/css')
-rw-r--r-- | WebCore/css/CSSFontSelector.cpp | 2 | ||||
-rw-r--r-- | WebCore/css/CSSGrammar.y | 7 | ||||
-rw-r--r-- | WebCore/css/CSSParser.cpp | 35 | ||||
-rw-r--r-- | WebCore/css/CSSParser.h | 14 | ||||
-rw-r--r-- | WebCore/css/CSSStyleSelector.cpp | 16 |
5 files changed, 59 insertions, 15 deletions
diff --git a/WebCore/css/CSSFontSelector.cpp b/WebCore/css/CSSFontSelector.cpp index 56ee261..752798d 100644 --- a/WebCore/css/CSSFontSelector.cpp +++ b/WebCore/css/CSSFontSelector.cpp @@ -231,7 +231,6 @@ void CSSFontSelector::addFontFaceRule(const CSSFontFaceRule* fontFaceRule) int srcLength = srcList->length(); - bool foundLocal = false; bool foundSVGFont = false; for (int i = 0; i < srcLength; i++) { @@ -257,7 +256,6 @@ void CSSFontSelector::addFontFaceRule(const CSSFontFaceRule* fontFaceRule) } } else { source = new CSSFontFaceSource(item->resource()); - foundLocal = true; } if (!fontFace) diff --git a/WebCore/css/CSSGrammar.y b/WebCore/css/CSSGrammar.y index 37c5385..06c6d01 100644 --- a/WebCore/css/CSSGrammar.y +++ b/WebCore/css/CSSGrammar.y @@ -889,7 +889,8 @@ unary_operator: ruleset: selector_list '{' maybe_space declaration_list closing_brace { - $$ = static_cast<CSSParser*>(parser)->createStyleRule($1); + CSSParser* p = static_cast<CSSParser*>(parser); + $$ = p->createStyleRule($1); } ; @@ -901,7 +902,7 @@ selector_list: deleteAllValues(*$$); $$->shrink(0); $$->append(p->sinkFloatingSelector($1)); - p->updateLastSelectorLine(); + p->updateLastSelectorLineAndPosition(); } } | selector_list ',' maybe_space selector %prec UNIMPORTANT_TOK { @@ -909,7 +910,7 @@ selector_list: CSSParser* p = static_cast<CSSParser*>(parser); $$ = $1; $$->append(p->sinkFloatingSelector($4)); - p->updateLastSelectorLine(); + p->updateLastSelectorLineAndPosition(); } else $$ = 0; } diff --git a/WebCore/css/CSSParser.cpp b/WebCore/css/CSSParser.cpp index 91b0f98..76f9fb1 100644 --- a/WebCore/css/CSSParser.cpp +++ b/WebCore/css/CSSParser.cpp @@ -150,6 +150,9 @@ CSSParser::CSSParser(bool strictParsing) , m_hasFontFaceOnlyValues(false) , m_hadSyntacticallyValidCSSRule(false) , m_defaultNamespace(starAtom) + , m_ruleBodyStartOffset(0) + , m_ruleBodyEndOffset(0) + , m_ruleRanges(0) , m_data(0) , yy_start(1) , m_line(0) @@ -229,18 +232,21 @@ void CSSParser::setupParser(const char* prefix, const String& string, const char yyleng = 0; yytext = yy_c_buf_p = m_data; yy_hold_char = *yy_c_buf_p; + resetRuleBodyMarks(); } -void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string) +void CSSParser::parseSheet(CSSStyleSheet* sheet, const String& string, StyleRuleRanges* ruleRangeMap) { #ifdef ANDROID_INSTRUMENT android::TimeCounter::start(android::TimeCounter::CSSParseTimeCounter); #endif m_styleSheet = sheet; m_defaultNamespace = starAtom; // Reset the default namespace. + m_ruleRanges = ruleRangeMap; setupParser("", string, ""); cssyyparse(this); + m_ruleRanges = 0; m_rule = 0; #ifdef ANDROID_INSTRUMENT android::TimeCounter::record(android::TimeCounter::CSSParseTimeCounter, __FUNCTION__); @@ -3624,9 +3630,8 @@ bool CSSParser::parseFontFaceSrc() bool CSSParser::parseFontFaceUnicodeRange() { RefPtr<CSSValueList> values = CSSValueList::createCommaSeparated(); - CSSParserValue* currentValue; bool failed = false; - while ((currentValue = m_valueList->current())) { + while (m_valueList->current()) { if (m_valueList->current()->unit != CSSPrimitiveValue::CSS_UNICODE_RANGE) { failed = true; break; @@ -5295,6 +5300,7 @@ CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors) { m_allowImportRules = m_allowNamespaceDeclarations = m_allowVariablesRules = false; CSSStyleRule* result = 0; + markRuleBodyEnd(); if (selectors) { RefPtr<CSSStyleRule> rule = CSSStyleRule::create(m_styleSheet, m_lastSelectorLine); rule->adoptSelectorVector(*selectors); @@ -5303,7 +5309,10 @@ CSSRule* CSSParser::createStyleRule(Vector<CSSSelector*>* selectors) rule->setDeclaration(CSSMutableStyleDeclaration::create(rule.get(), m_parsedProperties, m_numParsedProperties)); result = rule.get(); m_parsedStyleObjects.append(rule.release()); + if (m_ruleRanges) + m_ruleRanges->set(result, std::pair<unsigned, unsigned>(m_ruleBodyStartOffset, m_ruleBodyEndOffset)); } + resetRuleBodyMarks(); clearProperties(); return result; } @@ -5551,6 +5560,26 @@ void CSSParser::invalidBlockHit() m_styleSheet->setHasSyntacticallyValidCSSHeader(false); } +void CSSParser::updateLastSelectorLineAndPosition() +{ + m_lastSelectorLine = m_line; + markRuleBodyStart(); +} + +void CSSParser::markRuleBodyStart() +{ + unsigned offset = yytext - m_data; + if (!m_ruleBodyStartOffset || offset < m_ruleBodyStartOffset) + m_ruleBodyStartOffset = offset; +} + +void CSSParser::markRuleBodyEnd() +{ + unsigned offset = yytext - m_data; + if (offset > m_ruleBodyEndOffset) + m_ruleBodyEndOffset = offset; +} + static int cssPropertyID(const UChar* propertyName, unsigned length) { if (!length) diff --git a/WebCore/css/CSSParser.h b/WebCore/css/CSSParser.h index d1a5a43..271e98e 100644 --- a/WebCore/css/CSSParser.h +++ b/WebCore/css/CSSParser.h @@ -28,6 +28,7 @@ #include "CSSParserValues.h" #include "CSSSelectorList.h" #include "MediaQuery.h" +#include <wtf/HashMap.h> #include <wtf/HashSet.h> #include <wtf/Vector.h> @@ -39,6 +40,7 @@ namespace WebCore { class CSSRule; class CSSRuleList; class CSSSelector; + class CSSStyleRule; class CSSStyleSheet; class CSSValue; class CSSValueList; @@ -53,10 +55,12 @@ namespace WebCore { class CSSParser { public: + typedef HashMap<CSSStyleRule*, std::pair<unsigned, unsigned> > StyleRuleRanges; + CSSParser(bool strictParsing = true); ~CSSParser(); - void parseSheet(CSSStyleSheet*, const String&); + void parseSheet(CSSStyleSheet*, const String&, StyleRuleRanges* ruleRangeMap = 0); PassRefPtr<CSSRule> parseRule(CSSStyleSheet*, const String&); PassRefPtr<CSSRule> parseKeyframeRule(CSSStyleSheet*, const String&); bool parseValue(CSSMutableStyleDeclaration*, int propId, const String&, bool important); @@ -207,7 +211,7 @@ namespace WebCore { Vector<CSSSelector*>* reusableSelectorVector() { return &m_reusableSelectorVector; } - void updateLastSelectorLine() { m_lastSelectorLine = m_line; } + void updateLastSelectorLineAndPosition(); void clearProperties(); @@ -238,6 +242,12 @@ namespace WebCore { AtomicString m_defaultNamespace; // tokenizer methods and data + unsigned m_ruleBodyStartOffset; + unsigned m_ruleBodyEndOffset; + StyleRuleRanges* m_ruleRanges; + void markRuleBodyStart(); + void markRuleBodyEnd(); + void resetRuleBodyMarks() { m_ruleBodyStartOffset = m_ruleBodyEndOffset = 0; } int lex(void* yylval); int token() { return yyTok; } UChar* text(int* length); diff --git a/WebCore/css/CSSStyleSelector.cpp b/WebCore/css/CSSStyleSelector.cpp index ae919ef..92ba843 100644 --- a/WebCore/css/CSSStyleSelector.cpp +++ b/WebCore/css/CSSStyleSelector.cpp @@ -1099,10 +1099,12 @@ void CSSStyleSelector::matchUARules(int& firstUARule, int& lastUARule) PassRefPtr<RenderStyle> CSSStyleSelector::styleForDocument(Document* document) { + FrameView* view = document->view(); + RefPtr<RenderStyle> documentStyle = RenderStyle::create(); documentStyle->setDisplay(BLOCK); documentStyle->setVisuallyOrdered(document->visuallyOrdered()); - documentStyle->setZoom(document->frame()->pageZoomFactor()); + documentStyle->setZoom(view ? view->pageZoomFactor() : 1); FontDescription fontDescription; fontDescription.setUsePrinterFont(document->printing()); @@ -4032,8 +4034,12 @@ void CSSStyleSelector::applyProperty(int id, CSSValue *value) lineHeight = Length(-100.0, Percent); else if (CSSPrimitiveValue::isUnitTypeLength(type)) { double multiplier = zoomFactor; - if (m_style->textSizeAdjust() && m_checker.m_document->frame() && m_checker.m_document->frame()->shouldApplyTextZoom()) - multiplier *= m_checker.m_document->frame()->textZoomFactor(); + if (m_style->textSizeAdjust()) { + if (FrameView* view = m_checker.m_document->view()) { + if (view->shouldApplyTextZoom()) + multiplier *= view->textZoomFactor(); + } + } lineHeight = Length(primitiveValue->computeLengthIntForLength(style(), m_rootElementStyle, multiplier), Fixed); } else if (type == CSSPrimitiveValue::CSS_PERCENTAGE) lineHeight = Length((m_style->fontSize() * primitiveValue->getIntValue()) / 100, Fixed); @@ -5930,8 +5936,8 @@ float CSSStyleSelector::getComputedSizeFromSpecifiedSize(Document* document, Ren float zoomFactor = 1.0f; if (!useSVGZoomRules) { zoomFactor = style->effectiveZoom(); - if (document->frame() && document->frame()->shouldApplyTextZoom()) - zoomFactor *= document->frame()->textZoomFactor(); + if (document->view() && document->view()->shouldApplyTextZoom()) + zoomFactor *= document->view()->textZoomFactor(); } // We support two types of minimum font size. The first is a hard override that applies to |