JSHTMLInputElementBase.cpp [plain text]
#include "config.h"
#include "JSHTMLInputElementBase.h"
#include "HTMLInputElement.h"
#include "JSHTMLInputElementBaseTable.cpp"
using namespace KJS;
namespace WebCore {
KJS_IMPLEMENT_PROTOFUNC(JSHTMLInputElementBaseProtoFunc)
KJS_IMPLEMENT_PROTOTYPE("JSHTMLInputElementBase", JSHTMLInputElementBaseProto, JSHTMLInputElementBaseProtoFunc)
JSValue* JSHTMLInputElementBaseProtoFunc::callAsFunction(ExecState*, JSObject*, const List&)
{
return 0;
}
class JSHTMLInputElementBaseFunction : public InternalFunctionImp {
public:
JSHTMLInputElementBaseFunction(ExecState*, int i, int len, const Identifier& name);
virtual JSValue *callAsFunction(ExecState*, JSObject* thisObj, const List& args);
private:
int m_id;
};
JSHTMLInputElementBaseFunction::JSHTMLInputElementBaseFunction(ExecState* exec, int i, int len, const Identifier& name)
: InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
, m_id(i)
{
put(exec, lengthPropertyName, jsNumber(len), DontDelete|ReadOnly|DontEnum);
}
JSValue* JSHTMLInputElementBaseFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
HTMLInputElement& input = *static_cast<HTMLInputElement*>(static_cast<JSHTMLInputElementBase*>(thisObj)->impl());
if (m_id == JSHTMLInputElementBase::SetSelectionRange) {
input.setSelectionRange(args[0]->toInt32(exec), args[1]->toInt32(exec));
return jsUndefined();
}
return jsUndefined();
}
const ClassInfo JSHTMLInputElementBase::info = { "JSHTMLInputElementBase", &KJS::JSHTMLElement::info, &JSHTMLInputElementBaseTable, 0 };
JSHTMLInputElementBase::JSHTMLInputElementBase(ExecState* exec, PassRefPtr<HTMLInputElement> e)
: KJS::JSHTMLElement(exec, e.get())
{
setPrototype(KJS::JSHTMLElementProto::self(exec));
}
bool JSHTMLInputElementBase::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)
{
HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
if (!input.canHaveSelection())
return KJS::JSHTMLElement::getOwnPropertySlot(exec, propertyName, slot);
const HashEntry* entry = Lookup::findEntry(&JSHTMLInputElementBaseFunctionTable, propertyName);
if (entry && (entry->value == SetSelectionRange)) {
slot.setStaticEntry(this, entry, staticFunctionGetter<JSHTMLInputElementBaseFunction>);
return true;
}
ASSERT(!entry);
return getStaticValueSlot<JSHTMLInputElementBase, KJS::JSHTMLElement>(exec, &JSHTMLInputElementBaseTable, this, propertyName, slot);
}
JSValue* JSHTMLInputElementBase::getValueProperty(ExecState* exec, int token) const
{
HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
ASSERT(input.canHaveSelection());
switch (token) {
case SelectionStart:
return jsNumber(input.selectionStart());
case SelectionEnd:
return jsNumber(input.selectionEnd());
}
ASSERT_NOT_REACHED();
return jsUndefined();
}
void JSHTMLInputElementBase::put(ExecState* exec, const Identifier& propertyName, JSValue* value, int attr)
{
lookupPut<JSHTMLInputElementBase, KJS::JSHTMLElement>(exec, propertyName, value, attr, &JSHTMLInputElementBaseTable, this);
}
void JSHTMLInputElementBase::putValueProperty(ExecState* exec, int token, JSValue* value, int )
{
HTMLInputElement& input = *static_cast<HTMLInputElement*>(impl());
ASSERT(input.canHaveSelection());
switch (token) {
case SelectionStart:
input.setSelectionStart(value->toInt32(exec));
return;
case SelectionEnd:
input.setSelectionEnd(value->toInt32(exec));
return;
}
ASSERT_NOT_REACHED();
}
}