#include "config.h"
#include "DOMWindow.h"
#include "Console.h"
#include "cssstyleselector.h"
#include "CSSComputedStyleDeclaration.h"
#include "CSSRuleList.h"
#include "Document.h"
#include "Element.h"
#include "Frame.h"
namespace WebCore {
DOMWindow::DOMWindow(Frame* f)
: m_frame(f)
{
}
Frame* DOMWindow::frame()
{
return m_frame;
}
void DOMWindow::disconnectFrame()
{
m_frame = 0;
clear();
}
void DOMWindow::clear()
{
if (m_console)
m_console->disconnectFrame();
m_console = 0;
}
Document* DOMWindow::document() const
{
if (!m_frame)
return 0;
if (!m_frame->document()) {
m_frame->createEmptyDocument();
m_frame->begin();
m_frame->write("<HTML><BODY>");
m_frame->end();
}
return m_frame->document();
}
PassRefPtr<CSSStyleDeclaration> DOMWindow::getComputedStyle(Element* elt, const String&) const
{
if (!elt)
return 0;
return new CSSComputedStyleDeclaration(elt);
}
PassRefPtr<CSSRuleList> DOMWindow::getMatchedCSSRules(Element* elt, const String& pseudoElt, bool authorOnly) const
{
if (!m_frame || !m_frame->document())
return 0;
if (!pseudoElt.isEmpty())
return m_frame->document()->styleSelector()->pseudoStyleRulesForElement(elt, pseudoElt.impl(), authorOnly);
return m_frame->document()->styleSelector()->styleRulesForElement(elt, authorOnly);
}
double DOMWindow::devicePixelRatio() const
{
return m_frame->view() ? m_frame->view()->scaleFactor() : 1.0;
}
Console* DOMWindow::console() const
{
if (!m_console)
m_console = new Console(m_frame);
return m_console.get();
}
}