JSDocumentCustom.cpp [plain text]
#include "config.h"
#include "JSDocument.h"
#include "DOMWindow.h"
#include "Document.h"
#include "Frame.h"
#include "FrameLoader.h"
#include "HTMLDocument.h"
#include "JSDOMWindow.h"
#include "JSHTMLDocument.h"
#include "JSLocation.h"
#include "kjs_binding.h"
#include "kjs_proxy.h"
#if ENABLE(SVG)
#include "JSSVGDocument.h"
#include "SVGDocument.h"
#endif
#if ENABLE(TOUCH_EVENTS)
#include "TouchList.h"
#include "JSTouch.h"
#include "JSTouchList.h"
#endif
namespace WebCore {
using namespace KJS;
void JSDocument::mark()
{
JSEventTargetNode::mark();
ScriptInterpreter::markDOMNodesForDocument(static_cast<Document*>(impl()));
}
JSValue* JSDocument::location(ExecState* exec) const
{
Frame* frame = static_cast<Document*>(impl())->frame();
if (!frame)
return jsNull();
KJS::Window* win = KJS::Window::retrieveWindow(frame);
ASSERT(win);
return win->location();
}
void JSDocument::setLocation(ExecState* exec, JSValue* value)
{
Frame* frame = static_cast<Document*>(impl())->frame();
if (!frame)
return;
String str = value->toString(exec);
Frame* activeFrame = static_cast<JSDOMWindow*>(exec->dynamicGlobalObject())->impl()->frame();
if (activeFrame)
str = activeFrame->document()->completeURL(str);
bool userGesture = activeFrame->scriptProxy()->processingUserGesture();
frame->loader()->scheduleLocationChange(str, activeFrame->loader()->outgoingReferrer(), false, userGesture);
}
JSValue* toJS(ExecState* exec, Document* doc)
{
if (!doc)
return jsNull();
JSDocument* ret = static_cast<JSDocument*>(ScriptInterpreter::getDOMObject(doc));
if (ret)
return ret;
if (doc->isHTMLDocument())
ret = new JSHTMLDocument(JSHTMLDocumentPrototype::self(exec), static_cast<HTMLDocument*>(doc));
#if ENABLE(SVG)
else if (doc->isSVGDocument())
ret = new JSSVGDocument(JSSVGDocumentPrototype::self(exec), static_cast<SVGDocument*>(doc));
#endif
else
ret = new JSDocument(JSDocumentPrototype::self(exec), doc);
if (doc->frame())
KJS::Window::retrieveWindow(doc->frame())->putDirect("document", ret, DontDelete|ReadOnly);
else {
size_t nodeCount = 0;
for (Node* n = doc; n; n = n->traverseNextNode())
nodeCount++;
Collector::reportExtraMemoryCost(nodeCount * sizeof(Node));
}
ScriptInterpreter::putDOMObject(doc, ret);
return ret;
}
#if ENABLE(TOUCH_EVENTS)
JSValue* JSDocument::createTouchList(ExecState* exec, const List& args)
{
TouchList* touchList = new TouchList();
int sz = args.size();
for (int i = 0; i < sz; i++) {
touchList->append(toTouch(args[i]));
}
return toJS(exec, touchList);
}
#endif
}