Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(88)

Side by Side Diff: Source/core/css/parser/CSSParserImpl.cpp

Issue 1322543004: CSSStyleSheet::insertRule should respect the default namespace (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/core/css/parser/CSSParserImpl.h ('k') | Source/core/css/parser/CSSSelectorParser.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "config.h" 5 #include "config.h"
6 #include "core/css/parser/CSSParserImpl.h" 6 #include "core/css/parser/CSSParserImpl.h"
7 7
8 #include "core/css/CSSKeyframesRule.h" 8 #include "core/css/CSSKeyframesRule.h"
9 #include "core/css/CSSStyleSheet.h" 9 #include "core/css/CSSStyleSheet.h"
10 #include "core/css/StylePropertySet.h" 10 #include "core/css/StylePropertySet.h"
(...skipping 12 matching lines...) Expand all
23 #include "core/dom/Document.h" 23 #include "core/dom/Document.h"
24 #include "core/dom/Element.h" 24 #include "core/dom/Element.h"
25 #include "core/frame/UseCounter.h" 25 #include "core/frame/UseCounter.h"
26 #include "platform/TraceEvent.h" 26 #include "platform/TraceEvent.h"
27 #include "wtf/BitArray.h" 27 #include "wtf/BitArray.h"
28 28
29 namespace blink { 29 namespace blink {
30 30
31 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet) 31 CSSParserImpl::CSSParserImpl(const CSSParserContext& context, StyleSheetContents * styleSheet)
32 : m_context(context) 32 : m_context(context)
33 , m_defaultNamespace(starAtom)
34 , m_styleSheet(styleSheet) 33 , m_styleSheet(styleSheet)
35 , m_observerWrapper(nullptr) 34 , m_observerWrapper(nullptr)
36 { 35 {
37 } 36 }
38 37
39 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID unresolvedProperty, const String& string, bool important, const CSSParserCont ext& context) 38 bool CSSParserImpl::parseValue(MutableStylePropertySet* declaration, CSSProperty ID unresolvedProperty, const String& string, bool important, const CSSParserCont ext& context)
40 { 39 {
41 CSSParserImpl parser(context); 40 CSSParserImpl parser(context);
42 StyleRule::Type ruleType = StyleRule::Style; 41 StyleRule::Type ruleType = StyleRule::Style;
43 if (declaration->cssParserMode() == CSSViewportRuleMode) 42 if (declaration->cssParserMode() == CSSViewportRuleMode)
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 prelude.consumeWhitespace(); 380 prelude.consumeWhitespace();
382 AtomicString namespacePrefix; 381 AtomicString namespacePrefix;
383 if (prelude.peek().type() == IdentToken) 382 if (prelude.peek().type() == IdentToken)
384 namespacePrefix = prelude.consumeIncludingWhitespace().value(); 383 namespacePrefix = prelude.consumeIncludingWhitespace().value();
385 384
386 AtomicString uri(consumeStringOrURI(prelude)); 385 AtomicString uri(consumeStringOrURI(prelude));
387 prelude.consumeWhitespace(); 386 prelude.consumeWhitespace();
388 if (uri.isNull() || !prelude.atEnd()) 387 if (uri.isNull() || !prelude.atEnd())
389 return nullptr; // Parse error, expected string or URI 388 return nullptr; // Parse error, expected string or URI
390 389
391 if (namespacePrefix.isNull())
392 m_defaultNamespace = uri;
393 return StyleRuleNamespace::create(namespacePrefix, uri); 390 return StyleRuleNamespace::create(namespacePrefix, uri);
394 } 391 }
395 392
396 PassRefPtrWillBeRawPtr<StyleRuleMedia> CSSParserImpl::consumeMediaRule(CSSParser TokenRange prelude, CSSParserTokenRange block) 393 PassRefPtrWillBeRawPtr<StyleRuleMedia> CSSParserImpl::consumeMediaRule(CSSParser TokenRange prelude, CSSParserTokenRange block)
397 { 394 {
398 WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase>> rules; 395 WillBeHeapVector<RefPtrWillBeMember<StyleRuleBase>> rules;
399 396
400 if (m_observerWrapper) { 397 if (m_observerWrapper) {
401 CSSParserTokenRange preludeWithoutWhitespace = prelude; 398 CSSParserTokenRange preludeWithoutWhitespace = prelude;
402 preludeWithoutWhitespace.consumeWhitespace(); 399 preludeWithoutWhitespace.consumeWhitespace();
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
531 return nullptr; // Parse error; expected ident token following colon in @page header 528 return nullptr; // Parse error; expected ident token following colon in @page header
532 pseudo = prelude.consume().value(); 529 pseudo = prelude.consume().value();
533 } 530 }
534 531
535 prelude.consumeWhitespace(); 532 prelude.consumeWhitespace();
536 if (!prelude.atEnd()) 533 if (!prelude.atEnd())
537 return nullptr; // Parse error; extra tokens in @page header 534 return nullptr; // Parse error; extra tokens in @page header
538 535
539 OwnPtr<CSSParserSelector> selector; 536 OwnPtr<CSSParserSelector> selector;
540 if (!typeSelector.isNull() && pseudo.isNull()) { 537 if (!typeSelector.isNull() && pseudo.isNull()) {
541 selector = CSSParserSelector::create(QualifiedName(nullAtom, typeSelecto r, m_defaultNamespace)); 538 selector = CSSParserSelector::create(QualifiedName(nullAtom, typeSelecto r, m_styleSheet->defaultNamespace()));
542 } else { 539 } else {
543 selector = CSSParserSelector::create(); 540 selector = CSSParserSelector::create();
544 if (!pseudo.isNull()) { 541 if (!pseudo.isNull()) {
545 selector->setMatch(CSSSelector::PagePseudoClass); 542 selector->setMatch(CSSSelector::PagePseudoClass);
546 selector->updatePseudoType(pseudo.lower()); 543 selector->updatePseudoType(pseudo.lower());
547 if (selector->pseudoType() == CSSSelector::PseudoUnknown) 544 if (selector->pseudoType() == CSSSelector::PseudoUnknown)
548 return nullptr; // Parse error; unknown page pseudo-class 545 return nullptr; // Parse error; unknown page pseudo-class
549 } 546 }
550 if (!typeSelector.isNull()) 547 if (!typeSelector.isNull())
551 selector->prependTagSelector(QualifiedName(nullAtom, typeSelector, m _defaultNamespace)); 548 selector->prependTagSelector(QualifiedName(nullAtom, typeSelector, m _styleSheet->defaultNamespace()));
552 } 549 }
553 550
554 if (m_observerWrapper) { 551 if (m_observerWrapper) {
555 unsigned endOffset = m_observerWrapper->endOffset(prelude); 552 unsigned endOffset = m_observerWrapper->endOffset(prelude);
556 m_observerWrapper->observer().startRuleHeader(StyleRule::Page, m_observe rWrapper->startOffset(prelude)); 553 m_observerWrapper->observer().startRuleHeader(StyleRule::Page, m_observe rWrapper->startOffset(prelude));
557 m_observerWrapper->observer().endRuleHeader(endOffset); 554 m_observerWrapper->observer().endRuleHeader(endOffset);
558 } 555 }
559 556
560 selector->setForPage(); 557 selector->setForPage();
561 Vector<OwnPtr<CSSParserSelector>> selectorVector; 558 Vector<OwnPtr<CSSParserSelector>> selectorVector;
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 wrapper.observer().observeSelector(wrapper.startOffset(selector), wrappe r.endOffset(selector)); 591 wrapper.observer().observeSelector(wrapper.startOffset(selector), wrappe r.endOffset(selector));
595 } 592 }
596 593
597 wrapper.observer().endRuleHeader(wrapper.endOffset(originalRange)); 594 wrapper.observer().endRuleHeader(wrapper.endOffset(originalRange));
598 } 595 }
599 596
600 597
601 PassRefPtrWillBeRawPtr<StyleRule> CSSParserImpl::consumeStyleRule(CSSParserToken Range prelude, CSSParserTokenRange block) 598 PassRefPtrWillBeRawPtr<StyleRule> CSSParserImpl::consumeStyleRule(CSSParserToken Range prelude, CSSParserTokenRange block)
602 { 599 {
603 CSSSelectorList selectorList; 600 CSSSelectorList selectorList;
604 CSSSelectorParser::parseSelector(prelude, m_context, m_defaultNamespace, m_s tyleSheet, selectorList); 601 CSSSelectorParser::parseSelector(prelude, m_context, m_styleSheet, selectorL ist);
605 if (!selectorList.isValid()) 602 if (!selectorList.isValid())
606 return nullptr; // Parse error, invalid selector list 603 return nullptr; // Parse error, invalid selector list
607 604
608 if (m_observerWrapper) 605 if (m_observerWrapper)
609 observeSelectors(*m_observerWrapper, prelude); 606 observeSelectors(*m_observerWrapper, prelude);
610 607
611 consumeDeclarationList(block, StyleRule::Style); 608 consumeDeclarationList(block, StyleRule::Style);
612 609
613 return StyleRule::create(selectorList, createStylePropertySet(m_parsedProper ties, m_context.mode())); 610 return StyleRule::create(selectorList, createStylePropertySet(m_parsedProper ties, m_context.mode()));
614 } 611 }
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
729 else 726 else
730 return nullptr; // Parser error, invalid value in keyframe selector 727 return nullptr; // Parser error, invalid value in keyframe selector
731 if (range.atEnd()) 728 if (range.atEnd())
732 return result.release(); 729 return result.release();
733 if (range.consume().type() != CommaToken) 730 if (range.consume().type() != CommaToken)
734 return nullptr; // Parser error 731 return nullptr; // Parser error
735 } 732 }
736 } 733 }
737 734
738 } // namespace blink 735 } // namespace blink
OLDNEW
« no previous file with comments | « Source/core/css/parser/CSSParserImpl.h ('k') | Source/core/css/parser/CSSSelectorParser.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698