OLD | NEW |
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 12 matching lines...) Expand all Loading... |
23 * along with this library; see the file COPYING.LIB. If not, write to | 23 * along with this library; see the file COPYING.LIB. If not, write to |
24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, | 24 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
25 * Boston, MA 02110-1301, USA. | 25 * Boston, MA 02110-1301, USA. |
26 */ | 26 */ |
27 | 27 |
28 #include "config.h" | 28 #include "config.h" |
29 #include "core/dom/StyleEngine.h" | 29 #include "core/dom/StyleEngine.h" |
30 | 30 |
31 #include "HTMLNames.h" | 31 #include "HTMLNames.h" |
32 #include "SVGNames.h" | 32 #include "SVGNames.h" |
| 33 #include "core/css/CSSFontSelector.h" |
33 #include "core/css/CSSStyleSheet.h" | 34 #include "core/css/CSSStyleSheet.h" |
34 #include "core/css/StyleInvalidationAnalysis.h" | 35 #include "core/css/StyleInvalidationAnalysis.h" |
35 #include "core/css/StyleSheetContents.h" | 36 #include "core/css/StyleSheetContents.h" |
36 #include "core/dom/Element.h" | 37 #include "core/dom/Element.h" |
37 #include "core/dom/ProcessingInstruction.h" | 38 #include "core/dom/ProcessingInstruction.h" |
38 #include "core/dom/ShadowTreeStyleSheetCollection.h" | 39 #include "core/dom/ShadowTreeStyleSheetCollection.h" |
39 #include "core/dom/shadow/ShadowRoot.h" | 40 #include "core/dom/shadow/ShadowRoot.h" |
40 #include "core/html/HTMLIFrameElement.h" | 41 #include "core/html/HTMLIFrameElement.h" |
41 #include "core/html/HTMLImport.h" | 42 #include "core/html/HTMLImport.h" |
42 #include "core/html/HTMLLinkElement.h" | 43 #include "core/html/HTMLLinkElement.h" |
(...skipping 20 matching lines...) Expand all Loading... |
63 , m_usesSiblingRules(false) | 64 , m_usesSiblingRules(false) |
64 , m_usesSiblingRulesOverride(false) | 65 , m_usesSiblingRulesOverride(false) |
65 , m_usesFirstLineRules(false) | 66 , m_usesFirstLineRules(false) |
66 , m_usesFirstLetterRules(false) | 67 , m_usesFirstLetterRules(false) |
67 , m_usesRemUnits(false) | 68 , m_usesRemUnits(false) |
68 , m_maxDirectAdjacentSelectors(0) | 69 , m_maxDirectAdjacentSelectors(0) |
69 , m_ignorePendingStylesheets(false) | 70 , m_ignorePendingStylesheets(false) |
70 , m_didCalculateResolver(false) | 71 , m_didCalculateResolver(false) |
71 , m_lastResolverAccessCount(0) | 72 , m_lastResolverAccessCount(0) |
72 , m_resolverThrowawayTimer(this, &StyleEngine::resolverThrowawayTimerFired) | 73 , m_resolverThrowawayTimer(this, &StyleEngine::resolverThrowawayTimerFired) |
| 74 // We don't need to create CSSFontSelector for imported document or |
| 75 // HTMLTemplateElement's document, because those documents have no frame. |
| 76 , m_fontSelector(document.frame() ? CSSFontSelector::create(&document) : 0) |
73 { | 77 { |
74 } | 78 } |
75 | 79 |
76 StyleEngine::~StyleEngine() | 80 StyleEngine::~StyleEngine() |
77 { | 81 { |
78 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) | 82 for (unsigned i = 0; i < m_injectedAuthorStyleSheets.size(); ++i) |
79 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); | 83 m_injectedAuthorStyleSheets[i]->clearOwnerNode(); |
80 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) | 84 for (unsigned i = 0; i < m_authorStyleSheets.size(); ++i) |
81 m_authorStyleSheets[i]->clearOwnerNode(); | 85 m_authorStyleSheets[i]->clearOwnerNode(); |
82 } | 86 } |
(...skipping 377 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 m_resolver->setBuildScopedStyleTreeInDocumentOrder(false); | 464 m_resolver->setBuildScopedStyleTreeInDocumentOrder(false); |
461 } | 465 } |
462 | 466 |
463 void StyleEngine::createResolver() | 467 void StyleEngine::createResolver() |
464 { | 468 { |
465 // It is a programming error to attempt to resolve style on a Document | 469 // It is a programming error to attempt to resolve style on a Document |
466 // which is not in a frame. Code which hits this should have checked | 470 // which is not in a frame. Code which hits this should have checked |
467 // Document::isActive() before calling into code which could get here. | 471 // Document::isActive() before calling into code which could get here. |
468 | 472 |
469 ASSERT(m_document.frame()); | 473 ASSERT(m_document.frame()); |
| 474 ASSERT(m_fontSelector); |
470 | 475 |
471 m_resolver = adoptPtr(new StyleResolver(m_document)); | 476 m_resolver = adoptPtr(new StyleResolver(m_document)); |
472 appendActiveAuthorStyleSheets(); | 477 appendActiveAuthorStyleSheets(); |
| 478 m_fontSelector->registerForInvalidationCallbacks(m_resolver.get()); |
473 combineCSSFeatureFlags(m_resolver->ensureRuleFeatureSet()); | 479 combineCSSFeatureFlags(m_resolver->ensureRuleFeatureSet()); |
474 } | 480 } |
475 | 481 |
476 void StyleEngine::clearResolver() | 482 void StyleEngine::clearResolver() |
477 { | 483 { |
478 ASSERT(!m_document.inStyleRecalc()); | 484 ASSERT(!m_document.inStyleRecalc()); |
479 ASSERT(isMaster() || !m_resolver); | 485 ASSERT(isMaster() || !m_resolver); |
| 486 ASSERT(m_fontSelector || !m_resolver); |
| 487 if (m_resolver) |
| 488 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()); |
480 m_resolver.clear(); | 489 m_resolver.clear(); |
481 } | 490 } |
482 | 491 |
483 void StyleEngine::clearMasterResolver() | 492 void StyleEngine::clearMasterResolver() |
484 { | 493 { |
485 if (Document* master = this->master()) | 494 if (Document* master = this->master()) |
486 master->styleEngine()->clearResolver(); | 495 master->styleEngine()->clearResolver(); |
487 } | 496 } |
488 | 497 |
489 unsigned StyleEngine::resolverAccessCount() const | 498 unsigned StyleEngine::resolverAccessCount() const |
490 { | 499 { |
491 return m_resolver ? m_resolver->accessCount() : 0; | 500 return m_resolver ? m_resolver->accessCount() : 0; |
492 } | 501 } |
493 | 502 |
494 void StyleEngine::resolverThrowawayTimerFired(Timer<StyleEngine>*) | 503 void StyleEngine::resolverThrowawayTimerFired(Timer<StyleEngine>*) |
495 { | 504 { |
496 if (resolverAccessCount() == m_lastResolverAccessCount) | 505 if (resolverAccessCount() == m_lastResolverAccessCount) |
497 clearResolver(); | 506 clearResolver(); |
498 m_lastResolverAccessCount = resolverAccessCount(); | 507 m_lastResolverAccessCount = resolverAccessCount(); |
499 } | 508 } |
500 | 509 |
501 CSSFontSelector* StyleEngine::fontSelector() | |
502 { | |
503 return m_resolver ? m_resolver->fontSelector() : 0; | |
504 } | |
505 | |
506 void StyleEngine::didAttach() | 510 void StyleEngine::didAttach() |
507 { | 511 { |
508 m_resolverThrowawayTimer.startRepeating(60); | 512 m_resolverThrowawayTimer.startRepeating(60); |
509 } | 513 } |
510 | 514 |
511 void StyleEngine::didDetach() | 515 void StyleEngine::didDetach() |
512 { | 516 { |
513 m_resolverThrowawayTimer.stop(); | 517 m_resolverThrowawayTimer.stop(); |
514 clearResolver(); | 518 clearResolver(); |
515 } | 519 } |
(...skipping 23 matching lines...) Expand all Loading... |
539 m_didCalculateResolver = true; | 543 m_didCalculateResolver = true; |
540 if (m_document.didLayoutWithPendingStylesheets() && !hasPendingSheets()) | 544 if (m_document.didLayoutWithPendingStylesheets() && !hasPendingSheets()) |
541 change.setNeedsRepaint(); | 545 change.setNeedsRepaint(); |
542 | 546 |
543 if (updateActiveStyleSheets(mode)) | 547 if (updateActiveStyleSheets(mode)) |
544 change.setNeedsStyleRecalc(); | 548 change.setNeedsStyleRecalc(); |
545 | 549 |
546 return change; | 550 return change; |
547 } | 551 } |
548 | 552 |
| 553 void StyleEngine::resetFontSelector() |
| 554 { |
| 555 if (!m_fontSelector) |
| 556 return; |
| 557 |
| 558 m_fontSelector->clearDocument(); |
| 559 if (m_resolver) { |
| 560 m_fontSelector->unregisterForInvalidationCallbacks(m_resolver.get()); |
| 561 m_resolver->invalidateMatchedPropertiesCache(); |
| 562 } |
| 563 |
| 564 // If the document has been already detached, we don't need to recreate |
| 565 // CSSFontSelector. |
| 566 if (m_document.isActive()) { |
| 567 m_fontSelector = CSSFontSelector::create(&m_document); |
| 568 if (m_resolver) |
| 569 m_fontSelector->registerForInvalidationCallbacks(m_resolver.get()); |
| 570 } else { |
| 571 m_fontSelector = 0; |
| 572 } |
549 } | 573 } |
| 574 |
| 575 } |
OLD | NEW |