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
3 // found in the LICENSE file.
6 #include "core/html/imports/HTMLImportTreeRoot.h"
8 #include "core/dom/Document.h"
9 #include "core/dom/StyleEngine.h"
10 #include "core/frame/LocalFrame.h"
11 #include "core/html/imports/HTMLImportChild.h"
15 PassOwnPtrWillBeRawPtr<HTMLImportTreeRoot> HTMLImportTreeRoot::create(Document* document)
17 return adoptPtrWillBeNoop(new HTMLImportTreeRoot(document));
20 HTMLImportTreeRoot::HTMLImportTreeRoot(Document* document)
21 : HTMLImport(HTMLImport::Sync)
22 , m_document(document)
23 , m_recalcTimer(this, &HTMLImportTreeRoot::recalcTimerFired)
25 scheduleRecalcState(); // This recomputes initial state.
28 HTMLImportTreeRoot::~HTMLImportTreeRoot()
31 for (size_t i = 0; i < m_imports.size(); ++i)
32 m_imports[i]->importDestroyed();
38 Document* HTMLImportTreeRoot::document() const
43 bool HTMLImportTreeRoot::isDone() const
45 return !m_document->parsing() && m_document->styleEngine()->haveStylesheetsLoaded();
48 void HTMLImportTreeRoot::stateWillChange()
50 scheduleRecalcState();
53 void HTMLImportTreeRoot::stateDidChange()
55 HTMLImport::stateDidChange();
57 if (!state().isReady())
59 if (LocalFrame* frame = m_document->frame())
60 frame->loader().checkCompleted();
63 void HTMLImportTreeRoot::scheduleRecalcState()
67 if (m_recalcTimer.isActive() || !m_document->isActive())
70 if (m_recalcTimer.isActive() || !m_document)
73 m_recalcTimer.startOneShot(0, FROM_HERE);
76 HTMLImportChild* HTMLImportTreeRoot::add(PassOwnPtrWillBeRawPtr<HTMLImportChild> child)
78 m_imports.append(child);
79 return m_imports.last().get();
82 HTMLImportChild* HTMLImportTreeRoot::find(const KURL& url) const
84 for (size_t i = 0; i < m_imports.size(); ++i) {
85 HTMLImportChild* candidate = m_imports[i].get();
86 if (equalIgnoringFragmentIdentifier(candidate->url(), url))
93 void HTMLImportTreeRoot::recalcTimerFired(Timer<HTMLImportTreeRoot>*)
99 HTMLImport::recalcTreeState(this);
100 } while (m_recalcTimer.isActive());
103 void HTMLImportTreeRoot::trace(Visitor* visitor)
105 visitor->trace(m_document);
106 visitor->trace(m_imports);
107 HTMLImport::trace(visitor);