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

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: Changed expected result for mac Created 7 years, 5 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/dom/DocumentStyleSheetCollection.h ('k') | Source/core/html/HTMLLinkElement.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 226 matching lines...) Expand 10 before | Expand all | Expand 10 after
237 } 237 }
238 238
239 m_styleSheetCandidateNodes.add(node); 239 m_styleSheetCandidateNodes.add(node);
240 } 240 }
241 241
242 void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node) 242 void DocumentStyleSheetCollection::removeStyleSheetCandidateNode(Node* node)
243 { 243 {
244 m_styleSheetCandidateNodes.remove(node); 244 m_styleSheetCandidateNodes.remove(node);
245 } 245 }
246 246
247 void DocumentStyleSheetCollection::collectActiveStyleSheets(Vector<RefPtr<StyleS heet> >& sheets) 247 void DocumentStyleSheetCollection::collectStyleSheets(Vector<RefPtr<StyleSheet> >& styleSheets, Vector<RefPtr<CSSStyleSheet> >& activeSheets)
248 { 248 {
249 if (m_document->settings() && !m_document->settings()->authorAndUserStylesEn abled()) 249 if (m_document->settings() && !m_document->settings()->authorAndUserStylesEn abled())
250 return; 250 return;
251 251
252 DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin(); 252 DocumentOrderedList::iterator begin = m_styleSheetCandidateNodes.begin();
253 DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end(); 253 DocumentOrderedList::iterator end = m_styleSheetCandidateNodes.end();
254 for (DocumentOrderedList::iterator it = begin; it != end; ++it) { 254 for (DocumentOrderedList::iterator it = begin; it != end; ++it) {
255 Node* n = *it; 255 Node* n = *it;
256 StyleSheet* sheet = 0; 256 StyleSheet* sheet = 0;
257 CSSStyleSheet* activeSheet = 0;
257 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) { 258 if (n->nodeType() == Node::PROCESSING_INSTRUCTION_NODE) {
258 // Processing instruction (XML documents only). 259 // Processing instruction (XML documents only).
259 // We don't support linking to embedded CSS stylesheets, see <https: //bugs.webkit.org/show_bug.cgi?id=49281> for discussion. 260 // We don't support linking to embedded CSS stylesheets, see <https: //bugs.webkit.org/show_bug.cgi?id=49281> for discussion.
260 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n); 261 ProcessingInstruction* pi = static_cast<ProcessingInstruction*>(n);
261 sheet = pi->sheet();
262 // Don't apply XSL transforms to already transformed documents -- <r dar://problem/4132806> 262 // Don't apply XSL transforms to already transformed documents -- <r dar://problem/4132806>
263 if (pi->isXSL() && !m_document->transformSourceDocument()) { 263 if (pi->isXSL() && !m_document->transformSourceDocument()) {
264 // Don't apply XSL transforms until loading is finished. 264 // Don't apply XSL transforms until loading is finished.
265 if (!m_document->parsing()) 265 if (!m_document->parsing())
266 m_document->applyXSLTransform(pi); 266 m_document->applyXSLTransform(pi);
267 return; 267 return;
268 } 268 }
269 sheet = pi->sheet();
270 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
271 activeSheet = static_cast<CSSStyleSheet*>(sheet);
269 } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagNa me(styleTag))) || (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))) { 272 } else if ((n->isHTMLElement() && (n->hasTagName(linkTag) || n->hasTagNa me(styleTag))) || (n->isSVGElement() && n->hasTagName(SVGNames::styleTag))) {
270 Element* e = toElement(n); 273 Element* e = toElement(n);
271 AtomicString title = e->getAttribute(titleAttr); 274 AtomicString title = e->getAttribute(titleAttr);
272 bool enabledViaScript = false; 275 bool enabledViaScript = false;
273 if (e->hasLocalName(linkTag)) { 276 if (e->hasLocalName(linkTag)) {
274 // <LINK> element 277 // <LINK> element
275 HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n); 278 HTMLLinkElement* linkElement = static_cast<HTMLLinkElement*>(n);
276 if (linkElement->isDisabled())
277 continue;
278 enabledViaScript = linkElement->isEnabledViaScript(); 279 enabledViaScript = linkElement->isEnabledViaScript();
279 if (linkElement->styleSheetIsLoading()) { 280 if (!linkElement->isDisabled() && linkElement->styleSheetIsLoadi ng()) {
280 // it is loading but we should still decide which style shee t set to use 281 // it is loading but we should still decide which style shee t set to use
281 if (!enabledViaScript && !title.isEmpty() && m_preferredStyl esheetSetName.isEmpty()) { 282 if (!enabledViaScript && !title.isEmpty() && m_preferredStyl esheetSetName.isEmpty()) {
282 const AtomicString& rel = e->getAttribute(relAttr); 283 const AtomicString& rel = e->getAttribute(relAttr);
283 if (!rel.contains("alternate")) { 284 if (!rel.contains("alternate")) {
284 m_preferredStylesheetSetName = title; 285 m_preferredStylesheetSetName = title;
285 m_selectedStylesheetSetName = title; 286 m_selectedStylesheetSetName = title;
286 } 287 }
287 } 288 }
289
288 continue; 290 continue;
289 } 291 }
290 if (!linkElement->sheet()) 292 sheet = linkElement->sheet();
293 if (!sheet)
291 title = nullAtom; 294 title = nullAtom;
295 } else if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag)) {
296 sheet = static_cast<SVGStyleElement*>(n)->sheet();
297 } else {
298 sheet = static_cast<HTMLStyleElement*>(n)->sheet();
292 } 299 }
293 // Get the current preferred styleset. This is the 300
294 // set of sheets that will be enabled. 301 if (sheet && !sheet->disabled() && sheet->isCSSStyleSheet())
295 if (n->isSVGElement() && n->hasTagName(SVGNames::styleTag)) 302 activeSheet = static_cast<CSSStyleSheet*>(sheet);
296 sheet = static_cast<SVGStyleElement*>(n)->sheet(); 303
297 else if (e->hasLocalName(linkTag))
298 sheet = static_cast<HTMLLinkElement*>(n)->sheet();
299 else if (e->hasTagName(HTMLNames::styleTag))
300 sheet = toHTMLStyleElement(n)->sheet();
301 // Check to see if this sheet belongs to a styleset 304 // Check to see if this sheet belongs to a styleset
302 // (thus making it PREFERRED or ALTERNATE rather than 305 // (thus making it PREFERRED or ALTERNATE rather than
303 // PERSISTENT). 306 // PERSISTENT).
304 AtomicString rel = e->getAttribute(relAttr); 307 AtomicString rel = e->getAttribute(relAttr);
305 if (!enabledViaScript && sheet && !title.isEmpty()) { 308 if (!enabledViaScript && sheet && !title.isEmpty()) {
306 // Yes, we have a title. 309 // Yes, we have a title.
307 if (m_preferredStylesheetSetName.isEmpty()) { 310 if (m_preferredStylesheetSetName.isEmpty()) {
308 // No preferred set has been established. If 311 // No preferred set has been established. If
309 // we are NOT an alternate sheet, then establish 312 // we are NOT an alternate sheet, then establish
310 // us as the preferred set. Otherwise, just ignore 313 // us as the preferred set. Otherwise, just ignore
311 // this sheet. 314 // this sheet.
312 if (e->hasLocalName(styleTag) || !rel.contains("alternate")) 315 if (e->hasLocalName(styleTag) || !rel.contains("alternate"))
313 m_preferredStylesheetSetName = m_selectedStylesheetSetNa me = title; 316 m_preferredStylesheetSetName = m_selectedStylesheetSetNa me = title;
314 } 317 }
315 if (title != m_preferredStylesheetSetName) 318 if (title != m_preferredStylesheetSetName)
316 sheet = 0; 319 activeSheet = 0;
317 } 320 }
318 321
319 if (rel.contains("alternate") && title.isEmpty()) 322 if (rel.contains("alternate") && title.isEmpty())
320 sheet = 0; 323 activeSheet = 0;
321 } 324 }
322 if (sheet) 325 if (sheet)
323 sheets.append(sheet); 326 styleSheets.append(sheet);
327 if (activeSheet)
328 activeSheets.append(activeSheet);
324 } 329 }
325 } 330 }
326 331
327 void DocumentStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMo de updateMode, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolv erUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc) 332 void DocumentStyleSheetCollection::analyzeStyleSheetChange(StyleResolverUpdateMo de updateMode, const Vector<RefPtr<CSSStyleSheet> >& newStylesheets, StyleResolv erUpdateType& styleResolverUpdateType, bool& requiresFullStyleRecalc)
328 { 333 {
329 styleResolverUpdateType = Reconstruct; 334 styleResolverUpdateType = Reconstruct;
330 requiresFullStyleRecalc = true; 335 requiresFullStyleRecalc = true;
331 336
332 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done. 337 // Stylesheets of <style> elements that @import stylesheets are active but l oading. We need to trigger a full recalc when such loads are done.
333 bool hasActiveLoadingStylesheet = false; 338 bool hasActiveLoadingStylesheet = false;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 390
386 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets) 391 static bool styleSheetsUseRemUnits(const Vector<RefPtr<CSSStyleSheet> >& sheets)
387 { 392 {
388 for (unsigned i = 0; i < sheets.size(); ++i) { 393 for (unsigned i = 0; i < sheets.size(); ++i) {
389 if (sheets[i]->contents()->usesRemUnits()) 394 if (sheets[i]->contents()->usesRemUnits())
390 return true; 395 return true;
391 } 396 }
392 return false; 397 return false;
393 } 398 }
394 399
395 static void filterEnabledCSSStyleSheets(Vector<RefPtr<CSSStyleSheet> >& result, const Vector<RefPtr<StyleSheet> >& sheets)
396 {
397 for (unsigned i = 0; i < sheets.size(); ++i) {
398 if (!sheets[i]->isCSSStyleSheet())
399 continue;
400 if (sheets[i]->disabled())
401 continue;
402 result.append(static_cast<CSSStyleSheet*>(sheets[i].get()));
403 }
404 }
405
406 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document) 400 static void collectActiveCSSStyleSheetsFromSeamlessParents(Vector<RefPtr<CSSStyl eSheet> >& sheets, Document* document)
407 { 401 {
408 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame(); 402 HTMLIFrameElement* seamlessParentIFrame = document->seamlessParentIFrame();
409 if (!seamlessParentIFrame) 403 if (!seamlessParentIFrame)
410 return; 404 return;
411 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets()); 405 sheets.append(seamlessParentIFrame->document()->styleSheetCollection()->acti veAuthorStyleSheets());
412 } 406 }
413 407
414 bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo de updateMode) 408 bool DocumentStyleSheetCollection::updateActiveStyleSheets(StyleResolverUpdateMo de updateMode)
415 { 409 {
416 if (m_document->inStyleRecalc()) { 410 if (m_document->inStyleRecalc()) {
417 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc. 411 // SVG <use> element may manage to invalidate style selector in the midd le of a style recalc.
418 // https://bugs.webkit.org/show_bug.cgi?id=54344 412 // https://bugs.webkit.org/show_bug.cgi?id=54344
419 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc). 413 // FIXME: This should be fixed in SVG and the call site replaced by ASSE RT(!m_inStyleRecalc).
420 m_needsUpdateActiveStylesheetsOnStyleRecalc = true; 414 m_needsUpdateActiveStylesheetsOnStyleRecalc = true;
421 m_document->scheduleForcedStyleRecalc(); 415 m_document->scheduleForcedStyleRecalc();
422 return false; 416 return false;
423 417
424 } 418 }
425 if (!m_document->renderer() || !m_document->attached()) 419 if (!m_document->renderer() || !m_document->attached())
426 return false; 420 return false;
427 421
428 Vector<RefPtr<StyleSheet> > activeStyleSheets; 422 Vector<RefPtr<StyleSheet> > styleSheets;
429 collectActiveStyleSheets(activeStyleSheets);
430
431 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets; 423 Vector<RefPtr<CSSStyleSheet> > activeCSSStyleSheets;
432 activeCSSStyleSheets.append(injectedAuthorStyleSheets()); 424 activeCSSStyleSheets.append(injectedAuthorStyleSheets());
433 activeCSSStyleSheets.append(documentAuthorStyleSheets()); 425 activeCSSStyleSheets.append(documentAuthorStyleSheets());
434 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent); 426 collectActiveCSSStyleSheetsFromSeamlessParents(activeCSSStyleSheets, m_docum ent);
435 filterEnabledCSSStyleSheets(activeCSSStyleSheets, activeStyleSheets); 427 collectStyleSheets(styleSheets, activeCSSStyleSheets);
436 428
437 StyleResolverUpdateType styleResolverUpdateType; 429 StyleResolverUpdateType styleResolverUpdateType;
438 bool requiresFullStyleRecalc; 430 bool requiresFullStyleRecalc;
439 analyzeStyleSheetChange(updateMode, activeCSSStyleSheets, styleResolverUpdat eType, requiresFullStyleRecalc); 431 analyzeStyleSheetChange(updateMode, activeCSSStyleSheets, styleResolverUpdat eType, requiresFullStyleRecalc);
440 432
441 if (styleResolverUpdateType == Reconstruct) 433 if (styleResolverUpdateType == Reconstruct)
442 m_document->clearStyleResolver(); 434 m_document->clearStyleResolver();
443 else { 435 else {
444 StyleResolver* styleResolver = m_document->styleResolver(); 436 StyleResolver* styleResolver = m_document->styleResolver();
445 if (styleResolverUpdateType == Reset) { 437 if (styleResolverUpdateType == Reset) {
446 styleResolver->resetAuthorStyle(); 438 styleResolver->resetAuthorStyle();
447 styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets); 439 styleResolver->appendAuthorStyleSheets(0, activeCSSStyleSheets);
448 } else { 440 } else {
449 ASSERT(styleResolverUpdateType == Additive); 441 ASSERT(styleResolverUpdateType == Additive);
450 styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.siz e(), activeCSSStyleSheets); 442 styleResolver->appendAuthorStyleSheets(m_activeAuthorStyleSheets.siz e(), activeCSSStyleSheets);
451 } 443 }
452 resetCSSFeatureFlags(); 444 resetCSSFeatureFlags();
453 } 445 }
454 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets); 446 m_activeAuthorStyleSheets.swap(activeCSSStyleSheets);
455 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, activeStyleSh eets); 447 InspectorInstrumentation::activeStyleSheetsUpdated(m_document, styleSheets);
456 m_styleSheetsForStyleSheetList.swap(activeStyleSheets); 448 m_styleSheetsForStyleSheetList.swap(styleSheets);
457 449
458 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets); 450 m_usesRemUnits = styleSheetsUseRemUnits(m_activeAuthorStyleSheets);
459 m_needsUpdateActiveStylesheetsOnStyleRecalc = false; 451 m_needsUpdateActiveStylesheetsOnStyleRecalc = false;
460 452
461 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate(); 453 m_document->notifySeamlessChildDocumentsOfStylesheetUpdate();
462 454
463 return requiresFullStyleRecalc; 455 return requiresFullStyleRecalc;
464 } 456 }
465 457
466 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const 458 void DocumentStyleSheetCollection::reportMemoryUsage(MemoryObjectInfo* memoryObj ectInfo) const
467 { 459 {
468 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM); 460 MemoryClassInfo info(memoryObjectInfo, this, WebCoreMemoryTypes::DOM);
469 info.addMember(m_pageUserSheet, "pageUserSheet"); 461 info.addMember(m_pageUserSheet, "pageUserSheet");
470 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets"); 462 info.addMember(m_injectedUserStyleSheets, "injectedUserStyleSheets");
471 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets"); 463 info.addMember(m_injectedAuthorStyleSheets, "injectedAuthorStyleSheets");
472 info.addMember(m_userStyleSheets, "userStyleSheets"); 464 info.addMember(m_userStyleSheets, "userStyleSheets");
473 info.addMember(m_authorStyleSheets, "authorStyleSheets"); 465 info.addMember(m_authorStyleSheets, "authorStyleSheets");
474 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets"); 466 info.addMember(m_activeAuthorStyleSheets, "activeAuthorStyleSheets");
475 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList "); 467 info.addMember(m_styleSheetsForStyleSheetList, "styleSheetsForStyleSheetList ");
476 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes"); 468 info.addMember(m_styleSheetCandidateNodes, "styleSheetCandidateNodes");
477 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName"); 469 info.addMember(m_preferredStylesheetSetName, "preferredStylesheetSetName");
478 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName"); 470 info.addMember(m_selectedStylesheetSetName, "selectedStylesheetSetName");
479 info.addMember(m_document, "document"); 471 info.addMember(m_document, "document");
480 } 472 }
481 473
482 } 474 }
OLDNEW
« no previous file with comments | « Source/core/dom/DocumentStyleSheetCollection.h ('k') | Source/core/html/HTMLLinkElement.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698