#include "config.h"
#include "XMLTreeViewer.h"
#if ENABLE(XSLT)
#include "Document.h"
#include "Element.h"
#include "Frame.h"
#include "Page.h"
#include "ScriptSourceCode.h"
#include "ScriptValue.h"
#include "Settings.h"
#include "Text.h"
#include "XMLViewerCSS.h"
#include "XMLViewerJS.h"
using namespace std;
namespace WebCore {
XMLTreeViewer::XMLTreeViewer(Document* document)
: m_document(document)
{
}
bool XMLTreeViewer::hasNoStyleInformation() const
{
if (m_document->sawElementsInKnownNamespaces() || m_document->transformSourceDocument())
return false;
if (!m_document->frame() || !m_document->frame()->page())
return false;
if (!m_document->frame()->page()->settings()->developerExtrasEnabled())
return false;
if (m_document->frame()->tree()->parent(true))
return false;
return true;
}
void XMLTreeViewer::transformDocumentToTreeView()
{
m_document->setIsViewSource(true);
String scriptString(reinterpret_cast<const char*>(XMLViewer_js), sizeof(XMLViewer_js));
m_document->frame()->script()->evaluate(ScriptSourceCode(scriptString));
String noStyleMessage("This XML file does not appear to have any style information associated with it. The document tree is shown below.");
m_document->frame()->script()->evaluate(ScriptSourceCode("prepareWebKitXMLViewer('" + noStyleMessage + "');"));
String cssString(reinterpret_cast<const char*>(XMLViewer_css), sizeof(XMLViewer_css));
RefPtr<Text> text = m_document->createTextNode(cssString);
ExceptionCode exceptionCode;
m_document->getElementById("xml-viewer-style")->appendChild(text, exceptionCode);
m_document->styleResolverChanged(RecalcStyleImmediately);
}
}
#endif // ENABLE(XSLT)