TEST_F(StyleEngineTest, AnalyzedInject) { document().body()->setInnerHTML( "<style>div { color: red }</style><div id='t1'>Green</div><div></div>"); document().view()->updateAllLifecyclePhases(); Element* t1 = document().getElementById("t1"); ASSERT_TRUE(t1); ASSERT_TRUE(t1->computedStyle()); EXPECT_EQ(makeRGB(255, 0, 0), t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); unsigned beforeCount = styleEngine().styleForElementCount(); StyleSheetContents* parsedSheet = StyleSheetContents::create(CSSParserContext(document(), nullptr)); parsedSheet->parseString("#t1 { color: green }"); styleEngine().injectAuthorSheet(parsedSheet); document().view()->updateAllLifecyclePhases(); unsigned afterCount = styleEngine().styleForElementCount(); EXPECT_EQ(1u, afterCount - beforeCount); ASSERT_TRUE(t1->computedStyle()); EXPECT_EQ(makeRGB(0, 128, 0), t1->computedStyle()->visitedDependentColor(CSSPropertyColor)); }
void WebDocument::insertStyleSheet(const WebString& sourceCode) { Document* document = unwrap<Document>(); DCHECK(document); StyleSheetContents* parsedSheet = StyleSheetContents::create(CSSParserContext(*document, nullptr)); parsedSheet->parseString(sourceCode); document->styleEngine().injectAuthorSheet(parsedSheet); }
static CSSStyleSheet* createSheet(const String& cssText = String()) { StyleSheetContents* contents = StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr)); contents->parseString(cssText); contents->ensureRuleSet(MediaQueryEvaluator(), RuleHasDocumentSecurityOrigin); return CSSStyleSheet::create(contents); }
TEST_F(StyleEngineTest, DocumentDirtyAfterInject) { StyleSheetContents* parsedSheet = StyleSheetContents::create(CSSParserContext(document(), nullptr)); parsedSheet->parseString("div {}"); styleEngine().injectAuthorSheet(parsedSheet); document().view()->updateAllLifecyclePhases(); EXPECT_TRUE(isDocumentStyleSheetCollectionClean()); }
static StyleSheetContents* parseUASheet(const String& str) { StyleSheetContents* sheet = StyleSheetContents::create(CSSParserContext(UASheetMode, nullptr)); sheet->parseString(str); // User Agent stylesheets are parsed once for the lifetime of the renderer // process and are intentionally leaked. LEAK_SANITIZER_IGNORE_OBJECT(sheet); return sheet; }
StyleEngineTest::RuleSetInvalidation StyleEngineTest::scheduleInvalidationsForRules(TreeScope& treeScope, const String& cssText) { StyleSheetContents* sheet = StyleSheetContents::create(CSSParserContext(HTMLStandardMode, nullptr)); sheet->parseString(cssText); HeapVector<Member<RuleSet>> ruleSets; RuleSet& ruleSet = sheet->ensureRuleSet(MediaQueryEvaluator(), RuleHasDocumentSecurityOrigin); ruleSet.compactRulesIfNeeded(); if (ruleSet.needsFullRecalcForRuleSetInvalidation()) return RuleSetInvalidationFullRecalc; ruleSets.append(&ruleSet); styleEngine().scheduleInvalidationsForRuleSets(treeScope, ruleSets); return RuleSetInvalidationsScheduled; }
static StyleSheetContents* parseUASheet(const String& str) { StyleSheetContents* sheet = StyleSheetContents::create(CSSParserContext(UASheetMode)).leakRef(); // leak the sheet on purpose sheet->parseString(str); return sheet; }