2 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 #include "CachedPage.h"
29 #include "CSSStyleSelector.h"
32 #include "FocusController.h"
34 #include "FrameView.h"
37 #include <wtf/CurrentTime.h>
38 #include <wtf/RefCountedLeakCounter.h>
45 static WTF::RefCountedLeakCounter cachedPageCounter("CachedPage");
48 PassRefPtr<CachedPage> CachedPage::create(Page* page)
50 return adoptRef(new CachedPage(page));
53 CachedPage::CachedPage(Page* page)
54 : m_timeStamp(currentTime())
55 , m_cachedMainFrame(CachedFrame::create(page->mainFrame()))
56 , m_needStyleRecalcForVisitedLinks(false)
57 , m_needsFullStyleRecalc(false)
60 cachedPageCounter.increment();
64 CachedPage::~CachedPage()
67 cachedPageCounter.decrement();
71 ASSERT(!m_cachedMainFrame);
74 void CachedPage::restore(Page* page)
76 ASSERT(m_cachedMainFrame);
77 ASSERT(page && page->mainFrame() && page->mainFrame() == m_cachedMainFrame->view()->frame());
78 ASSERT(!page->frameCount());
80 m_cachedMainFrame->open();
82 // Restore the focus appearance for the focused element.
83 // FIXME: Right now we don't support pages w/ frames in the b/f cache. This may need to be tweaked when we add support for that.
84 Document* focusedDocument = page->focusController()->focusedOrMainFrame()->document();
85 if (Node* node = focusedDocument->focusedNode()) {
86 if (node->isElementNode())
87 static_cast<Element*>(node)->updateFocusAppearance(true);
90 if (m_needStyleRecalcForVisitedLinks) {
91 for (Frame* frame = page->mainFrame(); frame; frame = frame->tree()->traverseNext()) {
92 if (CSSStyleSelector* styleSelector = frame->document()->styleSelector())
93 styleSelector->allVisitedStateChanged();
97 if (m_needsFullStyleRecalc)
98 page->setNeedsRecalcStyleInAllFrames();
103 void CachedPage::clear()
105 ASSERT(m_cachedMainFrame);
106 m_cachedMainFrame->clear();
107 m_cachedMainFrame = 0;
108 m_needStyleRecalcForVisitedLinks = false;
109 m_needsFullStyleRecalc = false;
112 void CachedPage::destroy()
114 if (m_cachedMainFrame)
115 m_cachedMainFrame->destroy();
117 m_cachedMainFrame = 0;
120 } // namespace WebCore