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

Side by Side Diff: Source/core/dom/DocumentStyleSheetCollection.cpp

Issue 17827004: Include disabled stylesheets in document.styleSheets. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 7 years, 6 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All r ights reserved.
7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/) 7 * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.t orchmobile.com/)
8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. 8 * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved.
9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 9 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved. 10 * Copyright (C) Research In Motion Limited 2010-2011. All rights reserved.
(...skipping 242 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 } while (it != begin); 253 } while (it != begin);
254 254
255 m_styleSheetCandidateNodes.insertBefore(followingNode, node); 255 m_styleSheetCandidateNodes.insertBefore(followingNode, node);
256 } 256 }
257 257
258 void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node) 258 void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node)
259 { 259 {
260 m_styleSheetCandidateNodes.remove(node); 260 m_styleSheetCandidateNodes.remove(node);
261 } 261 }
262 262
263 void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS heet> >& sheets) 263 void DocumentStyleSheetCollection::collectStyleSheets(Vector<RefPtr<StyleSheet> >& styleSheets, Vector<RefPtr<CSSStyleSheet> >& activeSheets)
264 { 264 {
265 if (m_document->settings() && !m_document->settings()->authorAndUserStylesEn abled()) 265 if (m_document->settings() && !m_document->settings()->authorAndUserStylesEn abled())
266 return; 266 return;
267 267
268 StyleSheetCandidateListHashSet::iterator begin = m_styleSheetCandidateNodes. begin(); 268 StyleSheetCandidateListHashSet::iterator begin = m_styleSheetCandidateNodes. begin();
269 StyleSheetCandidateListHashSet::iterator end = m_styleSheetCandidateNodes.en d(); 269 StyleSheetCandidateListHashSet::iterator end = m_styleSheetCandidateNodes.en d();
270 for (StyleSheetCandidateListHashSet::iterator it = begin; it != end; ++it) { 270 for (StyleSheetCandidateListHashSet::iterator it = begin; it != end; ++it) {
271 Node* n = *it; 271 Node* n = *it;
272 StyleSheet* sheet = 0; 272 StyleSheet* sheet = 0;
273 CSSStyleSheet* activeSheet = 0;
273 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) { 274 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
274 // Processing instruction (XML documents only). 275 // Processing instruction (XML documents only).
275 // We don't support linking to embedded CSS stylesheets, see <https: //bugs.webkit.org/show_bug.cgi?id=49281> for discussion. 276 // We don't support linking to embedded CSS stylesheets, see <https: //bugs.webkit.org/show_bug.cgi?id=49281> for discussion.
276 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n); 277 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n);
277 sheet = pi->sheet();
278 // Don't apply XSL transforms to already transformed documents -- <r dar://problem/4132806> 278 // Don't apply XSL transforms to already transformed documents -- <r dar://problem/4132806>
279 if (pi->isXSL() && !m_document->transformSourceDocument()) { 279 if (pi->isXSL() && !m_document->transformSourceDocument()) {
280 // Don't apply XSL transforms until loading is finished. 280 // Don't apply XSL transforms until loading is finished.
281 if (!m_document->parsing()) 281 if (!m_document->parsing())
282 m_document->applyXSLTransform(pi); 282 m_document->applyXSLTransform(pi);
283 return; 283 return;
284 } 284 }
285 sheet = pi->sheet();
286 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
287 activeSheet = static_cast<CSSStyleSheet*>(sheet);
285 } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagNa me(styleTag))) || (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))) { 288 } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagNa me(styleTag))) || (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))) {
286 Element* e = toElement(n); 289 Element* e = toElement(n);
287 AtomicString title = e->getAttribute(titleAttr); 290 AtomicString title = e->getAttribute(titleAttr);
288 bool enabledViaScript = false; 291 bool enabledViaScript = false;
289 if (e->hasLocalName(linkTag)) { 292 if (e->hasLocalName(linkTag)) {
290 // <LINK> element 293 // <LINK> element
291 HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n); 294 HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n);
292 if (linkElement->isDisabled())
293 continue;
294 enabledViaScript = linkElement->isEnabledViaScript(); 295 enabledViaScript = linkElement->isEnabledViaScript();
295 if (linkElement->styleSheetIsLoading()) { 296 if (!linkElement->isDisabled() && linkElement->styleSheetIsLoadi ng()) {
dglazkov 2013/06/26 15:56:27 This needs to be untangled too, at some point. We
rune 2013/06/28 09:14:37 Yes, according to the specs, disabled state should
296 // it is loading but we should still decide which style shee t set to use 297 // it is loading but we should still decide which style shee t set to use
297 if (!enabledViaScript && !title.isEmpty() && m_preferredStyl esheetSetName.isEmpty()) { 298 if (!enabledViaScript && !title.isEmpty() && m_preferredStyl esheetSetName.isEmpty()) {
298 const AtomicString& rel = e->getAttribute(relAttr); 299 const AtomicString& rel = e->getAttribute(relAttr);
299 if (!rel.contains("alternate")) { 300 if (!rel.contains("alternate")) {
300 m_preferredStylesheetSetName = title; 301 m_preferredStylesheetSetName = title;
301 m_selectedStylesheetSetName = title; 302 m_selectedStylesheetSetName = title;
302 } 303 }
303 } 304 }
305
304 continue; 306 continue;
305 } 307 }
306 if (!linkElement->sheet()) 308 sheet = linkElement->sheet();
309 if (!sheet)
307 title = nullAtom; 310 title = nullAtom;
311 } else if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag)) {
312 sheet = static_cast<SVGStyleElement*>(n)->sheet();
313 } else {
314 sheet = static_cast<HTMLStyleElement*>(n)->sheet();
308 } 315 }
309 // Get the current preferred styleset. This is the 316
310 // set of sheets that will be enabled. 317 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
311 if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag)) 318 activeSheet = static_cast<CSSStyleSheet*>(sheet);
312 sheet = static_cast<SVGStyleElement*>(n)->sheet(); 319
313 else if (e->hasLocalName(linkTag))
314 sheet = static_cast<HTMLLinkElement*>(n)->sheet();
315 else if (e->hasTagName(HTMLNames::styleTag))
316 sheet = toHTMLStyleElement(n)->sheet();
317 // Check to see if this sheet belongs to a styleset 320 // Check to see if this sheet belongs to a styleset
318 // (thus making it PREFERRED or ALTERNATE rather than 321 // (thus making it PREFERRED or ALTERNATE rather than
319 // PERSISTENT). 322 // PERSISTENT).
320 AtomicString rel = e->getAttribute(relAttr); 323 AtomicString rel = e->getAttribute(relAttr);
321 if (!enabledViaScript && sheet && !title.isEmpty()) { 324 if (!enabledViaScript && sheet && !title.isEmpty()) {
322 // Yes, we have a title. 325 // Yes, we have a title.
323 if (m_preferredStylesheetSetName.isEmpty()) { 326 if (m_preferredStylesheetSetName.isEmpty()) {
324 // No preferred set has been established. If 327 // No preferred set has been established. If
325 // we are NOT an alternate sheet, then establish 328 // we are NOT an alternate sheet, then establish
326 // us as the preferred set. Otherwise, just ignore 329 // us as the preferred set. Otherwise, just ignore
327 // this sheet. 330 // this sheet.
328 if (e->hasLocalName(styleTag) || !rel.contains("alternate")) 331 if (e->hasLocalName(styleTag) || !rel.contains("alternate"))
329 m_preferredStylesheetSetName = m_selectedStylesheetSetNa me = title; 332 m_preferredStylesheetSetName = m_selectedStylesheetSetNa me = title;
330 } 333 }
331 if (title != m_preferredStylesheetSetName) 334 if (title != m_preferredStylesheetSetName)
332 sheet = 0; 335 activeSheet = 0;
333 } 336 }
334 337
335 if (rel.contains("alternate") && title.isEmpty()) 338 if (rel.contains("alternate") && title.isEmpty())
336 sheet = 0; 339 activeSheet = 0;
337 } 340 }
338 if (sheet) 341 if (sheet)
339 sheets.append(sheet); 342 styleSheets.append(sheet);
343 if (activeSheet)
344 activeSheets.append(activeSheet);
340 } 345 }
341 } 346 }
342 347
343 void DocumentStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMo de updateMode, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolv erUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc) 348 void DocumentStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMo de updateMode, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolv erUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc)
344 { 349 {
345 styleResolverUpdateType = Reconstruct; 350 styleResolverUpdateType = Reconstruct;
346 requiresFullStyleRecalc = true; 351 requiresFullStyleRecalc = true;
347 352
348 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done. 353 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done.
349 bool hasActiveLoadingStylesheet = false; 354 bool hasActiveLoadingStylesheet = false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
401 406
402 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) 407 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
403 { 408 {
404 for (unsigned i = 0; i < sheets.size(); ++i) { 409 for (unsigned i = 0; i < sheets.size(); ++i) {
405 if (sheets[i]->contents()->usesRemUnits()) 410 if (sheets[i]->contents()->usesRemUnits())
406 return true; 411 return true;
407 } 412 }
408 return false; 413 return false;
409 } 414 }
410 415
411 static void filterEnabledCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)
412 {
413 for (unsigned i = 0; i < sheets.size(); ++i) {
414 if (!sheets[i]->isCSSStyleSheet())
415 continue;
416 if (sheets[i]->disabled())
dglazkov 2013/06/26 15:56:27 How did this used to work with <link>?
rune 2013/06/28 09:14:37 It would be caught by the code I removed from coll
417 continue;
418 result.append(static_cast<CSSStyleSheet*>(sheets[i].get()));
419 }
420 }
421
422 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document) 416 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document)
423 { 417 {
424 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame(); 418 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame();
425 if (!seamlessParentIFrame) 419 if (!seamlessParentIFrame)
426 return; 420 return;
427 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets()); 421 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets());
428 } 422 }
429 423
430 bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo de updateMode) 424 bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo de updateMode)
431 { 425 {
432 if (m_document->inStyleRecalc()) { 426 if (m_document->inStyleRecalc()) {
433 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc. 427 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc.
434 // https://bugs.webkit.org/show_bug.cgi?id=54344 428 // https://bugs.webkit.org/show_bug.cgi?id=54344
435 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc). 429 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc).
436 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; 430 m_needsUpdateActiveStylesheetsOnStyleRecalc = true;
437 m_document->scheduleForcedStyleRecalc(); 431 m_document->scheduleForcedStyleRecalc();
438 return false; 432 return false;
439 433
440 } 434 }
441 if (!m_document->renderer() || !m_document->attached()) 435 if (!m_document->renderer() || !m_document->attached())
442 return false; 436 return false;
443 437
444 Vector<RefPtr<StyleSheet> > activeStyleSheets; 438 Vector<RefPtr<StyleSheet> > cssStyleSheets;
dglazkov 2013/06/26 15:56:27 Does "css" prefix carry any information here? Mayb
rune 2013/06/28 09:14:37 Possibly not. According to the CSSOM spec, StyleSh
445 collectActiveStyleSheets(activeStyleSheets);
446
447 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets; 439 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
448 activeCSSStyleSheets.append(injectedAuthorStyleSheets()); 440 activeCSSStyleSheets.append(injectedAuthorStyleSheets());
449 activeCSSStyleSheets.append(documentAuthorStyleSheets()); 441 activeCSSStyleSheets.append(documentAuthorStyleSheets());
450 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent); 442 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent);
451 filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets); 443 collectStyleSheets(cssStyleSheets, activeCSSStyleSheets);
452 444
453 StyleResolverUpdateType styleResolverUpdateType; 445 StyleResolverUpdateType styleResolverUpdateType;
454 bool requiresFullStyleRecalc; 446 bool requiresFullStyleRecalc;
455 analyzeStyleSheetChange(updateMode, activeCSSStyleSheets, styleResolverUpdat eType, requiresFullStyleRecalc); 447 analyzeStyleSheetChange(updateMode, activeCSSStyleSheets, styleResolverUpdat eType, requiresFullStyleRecalc);
456 448
457 if (styleResolverUpdateType == Reconstruct) 449 if (styleResolverUpdateType == Reconstruct)
458 m_document->clearStyleResolver(); 450 m_document->clearStyleResolver();
459 else { 451 else {
460 StyleResolver* styleResolver = m_document->styleResolver(); 452 StyleResolver* styleResolver = m_document->styleResolver();
461 if (styleResolverUpdateType == Reset) { 453 if (styleResolverUpdateType == Reset) {
462 styleResolver->resetAuthorStyle(); 454 styleResolver->resetAuthorStyle();
463 styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets); 455 styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
464 } else { 456 } else {
465 ASSERT(styleResolverUpdateType == Additive); 457 ASSERT(styleResolverUpdateType == Additive);
466 styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.siz e(), activeCSSStyleSheets); 458 styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.siz e(), activeCSSStyleSheets);
467 } 459 }
468 resetCSSFeatureFlags(); 460 resetCSSFeatureFlags();
469 } 461 }
470 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets); 462 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
471 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSh eets); 463 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, cssStyleSheet s);
dglazkov 2013/06/26 15:56:27 I guess the name of this function should change to
rune 2013/06/28 09:14:37 Yes. So this changes which stylesheets are passed
rune 2013/06/28 09:37:25 Also, changing this method name means changing Ins
472 m_styleSheetsForStyleSheetList.swap(activeStyleSheets); 464 m_styleSheetsForStyleSheetList.swap(cssStyleSheets);
473 465
474 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); 466 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
475 m_needsUpdateActiveStylesheetsOnStyleRecalc = false; 467 m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
476 468
477 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate(); 469 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
478 470
479 return requiresFullStyleRecalc; 471 return requiresFullStyleRecalc;
480 } 472 }
481 473
482 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const 474 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const
483 { 475 {
484 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); 476 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
485 info.addMember(m_pageUserSheet, "pageUserSheet"); 477 info.addMember(m_pageUserSheet, "pageUserSheet");
486 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets"); 478 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets");
487 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets"); 479 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets");
488 info.addMember(m_userStyleSheets, "userStyleSheets"); 480 info.addMember(m_userStyleSheets, "userStyleSheets");
489 info.addMember(m_authorStyleSheets, "authorStyleSheets"); 481 info.addMember(m_authorStyleSheets, "authorStyleSheets");
490 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets"); 482 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets");
491 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList "); 483 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList ");
492 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes"); 484 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes");
493 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName"); 485 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName");
494 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName"); 486 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName");
495 info.addMember(m_document, "document"); 487 info.addMember(m_document, "document");
496 } 488 }
497 489
498 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698