-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
zhangjipeng
committed
Oct 15, 2024
1 parent
f52b38c
commit 978dc9c
Showing
3 changed files
with
297 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2007 Apple Inc. All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* 1. Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* 2. Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in the | ||
* documentation and/or other materials provided with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | ||
* EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | ||
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | ||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | ||
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | ||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | ||
* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#ifndef JSEventTargetNode_h | ||
#define JSEventTargetNode_h | ||
|
||
#include "QJSNode.h" | ||
|
||
namespace WebCore { | ||
|
||
class EventTargetNode; | ||
class Node; | ||
|
||
class JSEventTargetNode : public JSNode { | ||
public: | ||
JSEventTargetNode(KJS::ExecState*, Node* n); | ||
|
||
void setListener(KJS::ExecState*, const AtomicString& eventType, KJS::JSValue* func) const; | ||
KJS::JSValue* getListener(const AtomicString& eventType) const; | ||
virtual void pushEventHandlerScope(KJS::ExecState*, KJS::ScopeChain&) const; | ||
|
||
bool getOwnPropertySlot(KJS::ExecState*, const KJS::Identifier&, KJS::PropertySlot&); | ||
KJS::JSValue* getValueProperty(KJS::ExecState*, int token) const; | ||
virtual void put(KJS::ExecState*, const KJS::Identifier&, KJS::JSValue* value, int attr); | ||
void putValueProperty(KJS::ExecState*, int token, KJS::JSValue* value, int attr); | ||
|
||
enum { | ||
AddEventListener, RemoveEventListener, DispatchEvent, | ||
OnAbort, OnBlur, OnChange, OnClick, OnContextMenu, OnDblClick, OnError, | ||
OnDragEnter, OnDragOver, OnDragLeave, OnDrop, OnDragStart, OnDrag, OnDragEnd, | ||
OnBeforeCut, OnCut, OnBeforeCopy, OnCopy, OnBeforePaste, OnPaste, OnSelectStart, | ||
OnFocus, OnInput, OnKeyDown, OnKeyPress, OnKeyUp, OnLoad, OnMouseDown, | ||
OnMouseMove, OnMouseOut, OnMouseOver, OnMouseUp, OnMouseWheel, OnReset, | ||
OnResize, OnScroll, OnSearch, OnSelect, OnSubmit, OnUnload | ||
}; | ||
}; | ||
|
||
EventTargetNode* toEventTargetNode(KJS::JSValue*); | ||
|
||
KJS_DEFINE_PROTOTYPE_WITH_PROTOTYPE(JSEventTargetNodePrototype, JSNodePrototype) | ||
|
||
} // namespace WebCore | ||
|
||
#endif // JSEventTargetNode_h |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
// -*- c-basic-offset: 4 -*- | ||
/* | ||
* This file is part of the KDE libraries | ||
* Copyright (C) 1999-2001 Harri Porten (porten@kde.org) | ||
* Copyright (C) 2003, 2004, 2005, 2006 Apple Computer, Inc. | ||
* Copyright (C) 2007 Samuel Weinig <sam@webkit.org> | ||
* | ||
* This library is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU Lesser General Public | ||
* License as published by the Free Software Foundation; either | ||
* version 2 of the License, or (at your option) any later version. | ||
* | ||
* This library is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License along with this library; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | ||
*/ | ||
|
||
#ifndef kjs_binding_h | ||
#define kjs_binding_h | ||
|
||
#include <kjs/function.h> | ||
#include <kjs/lookup.h> | ||
#include <wtf/Noncopyable.h> | ||
|
||
#include <quickjs.h> | ||
|
||
|
||
namespace WebCore { | ||
class AtomicString; | ||
class Document; | ||
class Event; | ||
class Frame; | ||
class Node; | ||
class String; | ||
class JSNode; | ||
|
||
typedef int ExceptionCode; | ||
|
||
#if ENABLE(SVG) | ||
class SVGElement; | ||
#endif | ||
} | ||
|
||
namespace KJS { | ||
|
||
/** | ||
* Base class for all objects in this binding. | ||
*/ | ||
class DOMObject : public JSObject { | ||
protected: | ||
DOMObject() | ||
{ | ||
// DOMObject destruction is not thread-safe because DOMObjects wrap | ||
// unsafe WebCore DOM data structures. | ||
Collector::collectOnMainThreadOnly(this); | ||
} | ||
#ifndef NDEBUG | ||
virtual ~DOMObject(); | ||
#endif | ||
}; | ||
|
||
/** | ||
* We inherit from Interpreter, to save a pointer to the HTML part | ||
* that the interpreter runs for. | ||
* The interpreter also stores the DOM object -> KJS::DOMObject cache. | ||
*/ | ||
class ScriptInterpreter : public Interpreter { | ||
public: | ||
ScriptInterpreter(JSObject* global, WebCore::Frame*); | ||
|
||
static DOMObject* getDOMObject(void* objectHandle); | ||
static void putDOMObject(void* objectHandle, DOMObject*); | ||
static void forgetDOMObject(void* objectHandle); | ||
|
||
static WebCore::JSNode* getDOMNodeForDocument(WebCore::Document*, WebCore::Node*); | ||
static void putDOMNodeForDocument(WebCore::Document*, WebCore::Node*, WebCore::JSNode* nodeWrapper); | ||
static void forgetDOMNodeForDocument(WebCore::Document*, WebCore::Node*); | ||
static void forgetAllDOMNodesForDocument(WebCore::Document*); | ||
static void updateDOMNodeDocument(WebCore::Node*, WebCore::Document* oldDoc, WebCore::Document* newDoc); | ||
static void markDOMNodesForDocument(WebCore::Document*); | ||
|
||
WebCore::Frame* frame() const { return m_frame; } | ||
|
||
/** | ||
* Set the event that is triggering the execution of a script, if any | ||
*/ | ||
void setCurrentEvent(WebCore::Event* event) { m_currentEvent = event; } | ||
void setInlineCode(bool inlineCode) { m_inlineCode = inlineCode; } | ||
void setProcessingTimerCallback(bool timerCallback) { m_timerCallback = timerCallback; } | ||
|
||
/** | ||
* "Smart" window.open policy | ||
*/ | ||
bool wasRunByUserGesture() const; | ||
|
||
virtual ExecState* globalExec(); | ||
|
||
WebCore::Event* getCurrentEvent() const { return m_currentEvent; } | ||
|
||
virtual bool isGlobalObject(JSValue*); | ||
virtual Interpreter* interpreterForGlobalObject(const JSValue*); | ||
virtual bool isSafeScript(const Interpreter* target); | ||
|
||
virtual bool shouldInterruptScript() const; | ||
|
||
private: | ||
virtual ~ScriptInterpreter() { } // only deref on the base class should delete us | ||
|
||
WebCore::Frame* m_frame; | ||
WebCore::Event* m_currentEvent; | ||
bool m_inlineCode; | ||
bool m_timerCallback; | ||
}; | ||
|
||
/** | ||
* Retrieve from cache, or create, a KJS object around a DOM object | ||
*/ | ||
template<class DOMObj, class KJSDOMObj> inline JSValue *cacheDOMObject(ExecState* exec, DOMObj* domObj) | ||
{ | ||
if (!domObj) | ||
return jsNull(); | ||
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter()); | ||
if (DOMObject* ret = interp->getDOMObject(domObj)) | ||
return ret; | ||
DOMObject* ret = new KJSDOMObj(exec, domObj); | ||
interp->putDOMObject(domObj, ret); | ||
return ret; | ||
} | ||
|
||
#if ENABLE(SVG) | ||
/** | ||
* Retrieve from cache, or create, a KJS object around a SVG DOM object | ||
*/ | ||
template<class DOMObj, class KJSDOMObj> inline JSValue* cacheSVGDOMObject(ExecState* exec, DOMObj* domObj, WebCore::SVGElement* context) | ||
{ | ||
if (!domObj) | ||
return jsNull(); | ||
ScriptInterpreter* interp = static_cast<ScriptInterpreter*>(exec->dynamicInterpreter()); | ||
if (DOMObject* ret = interp->getDOMObject(domObj)) | ||
return ret; | ||
DOMObject* ret = new KJSDOMObj(exec, domObj, context); | ||
interp->putDOMObject(domObj, ret); | ||
return ret; | ||
} | ||
#endif | ||
|
||
// Convert a DOM implementation exception code into a JavaScript exception in the execution state. | ||
void setDOMException(ExecState*, WebCore::ExceptionCode); | ||
|
||
// Helper class to call setDOMException on exit without adding lots of separate calls to that function. | ||
class DOMExceptionTranslator : Noncopyable { | ||
public: | ||
explicit DOMExceptionTranslator(ExecState* exec) : m_exec(exec), m_code(0) { } | ||
~DOMExceptionTranslator() { setDOMException(m_exec, m_code); } | ||
operator WebCore::ExceptionCode&() { return m_code; } | ||
private: | ||
ExecState* m_exec; | ||
WebCore::ExceptionCode m_code; | ||
}; | ||
|
||
JSValue* jsStringOrNull(const WebCore::String&); // null if the string is null | ||
JSValue* jsStringOrUndefined(const WebCore::String&); // undefined if the string is null | ||
JSValue* jsStringOrFalse(const WebCore::String&); // boolean false if the string is null | ||
|
||
// see JavaScriptCore for explanation should be used for UString that is already owned | ||
// by another object, so that collecting the JSString wrapper is unlikely to save memory. | ||
JSValue* jsOwnedStringOrNull(const KJS::UString&); | ||
|
||
WebCore::String valueToStringWithNullCheck(ExecState*, JSValue*); // null String if the value is null | ||
WebCore::String valueToStringWithUndefinedOrNullCheck(ExecState*, JSValue*); // null String if the value is null or undefined | ||
|
||
template <typename T> inline JSValue* toJS(ExecState* exec, PassRefPtr<T> ptr) { return toJS(exec, ptr.get()); } | ||
|
||
} // namespace | ||
|
||
#endif |
Oops, something went wrong.