Example #1
0
/**
*	This is called when a text event is deleted.
*/
void EventSystem::textEventDeleted(QString ID) {
	for (int i = 0; i < _textEvents.size(); i++) {
		TextEvent *it = _textEvents.at(i);
		if (it->getName() == ID)
			_textEvents.remove(i);
	}
}
Example #2
0
/**
* Translate the text event from XML.
*/
TextEvent* TextEvent::translateFromXML(QDomElement element) {
	QString ID = element.attributeNode("ID").value();
	QDomElement typeElement = element.firstChildElement("type");
	QString typeString = typeElement.attributeNode("value").value();

	if (typeString != "TEXT")
		throw ProjectException("The translation of a text event should have type TEXT instead of " + typeString + ".");

	Event::Trigger trigger = Event::NONE;
	QString triggerString = element.firstChildElement("trigger").attributeNode("value").value();
	if (triggerString == "TOUCH")
		trigger = Event::TOUCH;
	else if (triggerString == "INTERACT")
		trigger = Event::INTERACT;
	else if (triggerString == "NONE")
		trigger = Event::NONE;

	TextEvent *event = create(ID, trigger);
	Event::translateFromXML(element, event);

	QDomNodeList textElements = element.elementsByTagName("text");
	for (int i = 0; i < textElements.size(); i++) {
		QDomElement textElement = textElements.at(i).toElement();
		event->addMessage(textElement.text());
	}

	return event;
}
Example #3
0
EncodedJSValue JSC_HOST_CALL jsTextEventPrototypeFunctionInitTextEvent(ExecState* exec)
{
    JSValue thisValue = exec->hostThisValue();
    if (!thisValue.inherits(&JSTextEvent::s_info))
        return throwVMTypeError(exec);
    JSTextEvent* castedThis = static_cast<JSTextEvent*>(asObject(thisValue));
    ASSERT_GC_OBJECT_INHERITS(castedThis, &JSTextEvent::s_info);
    TextEvent* imp = static_cast<TextEvent*>(castedThis->impl());
    const String& typeArg(ustringToString(exec->argument(0).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    bool canBubbleArg(exec->argument(1).toBoolean(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    bool cancelableArg(exec->argument(2).toBoolean(exec));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    DOMWindow* viewArg(toDOMWindow(exec->argument(3)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());
    const String& dataArg(ustringToString(exec->argument(4).toString(exec)));
    if (exec->hadException())
        return JSValue::encode(jsUndefined());

    imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
    return JSValue::encode(jsUndefined());
}
Example #4
0
JSValue jsTextEventData(ExecState* exec, JSValue slotBase, const Identifier&)
{
    JSTextEvent* castedThis = static_cast<JSTextEvent*>(asObject(slotBase));
    UNUSED_PARAM(exec);
    TextEvent* imp = static_cast<TextEvent*>(castedThis->impl());
    JSValue result = jsString(exec, imp->data());
    return result;
}
Example #5
0
void WMLInputElement::defaultEventHandler(Event* evt)
{
    bool clickDefaultFormButton = false;

    if (evt->type() == eventNames().textInputEvent && evt->isTextEvent()) {
        TextEvent* textEvent = static_cast<TextEvent*>(evt);
        if (textEvent->data() == "\n")
            clickDefaultFormButton = true;
        else if (renderer() && !isConformedToInputMask(textEvent->data()[0], toRenderTextControl(renderer())->text().length() + 1))
            // If the inputed char doesn't conform to the input mask, stop handling 
            return;
    }

    if (evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent() && focused() && document()->frame()
        && document()->frame()->editor()->doTextFieldCommandFromEvent(this, static_cast<KeyboardEvent*>(evt))) {
        evt->setDefaultHandled();
        return;
    }
    
    // Let the key handling done in EventTargetNode take precedence over the event handling here for editable text fields
    if (!clickDefaultFormButton) {
        WMLElement::defaultEventHandler(evt);
        if (evt->defaultHandled())
            return;
    }

    // Use key press event here since sending simulated mouse events
    // on key down blocks the proper sending of the key press event.
    if (evt->type() == eventNames().keypressEvent && evt->isKeyboardEvent()) {
        // Simulate mouse click on the default form button for enter for these types of elements.
        if (static_cast<KeyboardEvent*>(evt)->charCode() == '\r')
            clickDefaultFormButton = true;
    }

    if (clickDefaultFormButton) {
        // Fire onChange for text fields.
        if (wasChangedSinceLastFormControlChangeEvent()) {
            setChangedSinceLastFormControlChangeEvent(false);
            dispatchEvent(Event::create(eventNames().changeEvent, true, false));
        }

        evt->setDefaultHandled();
        return;
    }

    if (evt->isBeforeTextInsertedEvent())
        InputElement::handleBeforeTextInsertedEvent(m_data, this, this, evt);

    if (renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent))
        toRenderTextControlSingleLine(renderer())->forwardEvent(evt);

    //add. When has two input element, can't move second input element.
    if (evt->type() == eventNames().webkitEditableContentChangedEvent && renderer() && renderer()->isTextControl()) {
        toRenderTextControl(renderer())->subtreeHasChanged();
    }
    /*guoxiaolei 20120827 end>*/
}
void WMLInputElement::defaultEventHandler(Event* evt)
{
    bool clickDefaultFormButton = false;

    if (evt->type() == eventNames().textInputEvent && evt->isTextEvent()) {
        TextEvent* textEvent = static_cast<TextEvent*>(evt);
        if (textEvent->data() == "\n")
            clickDefaultFormButton = true;
        else if (renderer() && !isConformedToInputMask(textEvent->data()[0], toRenderTextControl(renderer())->text().length() + 1))
            // If the inputed char doesn't conform to the input mask, stop handling 
            return;
    }

    if (evt->type() == eventNames().keydownEvent && evt->isKeyboardEvent() && focused() && document()->frame()
        && document()->frame()->doTextFieldCommandFromEvent(this, static_cast<KeyboardEvent*>(evt))) {
        evt->setDefaultHandled();
        return;
    }
    
    // Let the key handling done in EventTargetNode take precedence over the event handling here for editable text fields
    if (!clickDefaultFormButton) {
        WMLElement::defaultEventHandler(evt);
        if (evt->defaultHandled())
            return;
    }

    // Use key press event here since sending simulated mouse events
    // on key down blocks the proper sending of the key press event.
    if (evt->type() == eventNames().keypressEvent && evt->isKeyboardEvent()) {
        // Simulate mouse click on the default form button for enter for these types of elements.
        if (static_cast<KeyboardEvent*>(evt)->charCode() == '\r')
            clickDefaultFormButton = true;
    }

    if (clickDefaultFormButton) {
        // Fire onChange for text fields.
        RenderObject* r = renderer();
        if (r && toRenderTextControl(r)->isEdited()) {
            dispatchEvent(Event::create(eventNames().changeEvent, true, false));
            
            // Refetch the renderer since arbitrary JS code run during onchange can do anything, including destroying it.
            r = renderer();
            if (r)
                toRenderTextControl(r)->setEdited(false);
        }

        evt->setDefaultHandled();
        return;
    }

    if (evt->isBeforeTextInsertedEvent())
        InputElement::handleBeforeTextInsertedEvent(m_data, this, this, evt);

    if (renderer() && (evt->isMouseEvent() || evt->isDragEvent() || evt->isWheelEvent() || evt->type() == eventNames().blurEvent || evt->type() == eventNames().focusEvent))
        toRenderTextControlSingleLine(renderer())->forwardEvent(evt);
}
Example #7
0
 static v8::Handle<v8::Value> initTextEventCallback(const v8::Arguments& args) {
   INC_STATS("DOM.TextEvent.initTextEvent");
   TextEvent* imp = V8TextEvent::toNative(args.Holder());
   V8Parameter<> typeArg = args[0];
   bool canBubbleArg = args[1]->BooleanValue();
   bool cancelableArg = args[2]->BooleanValue();
   DOMWindow* viewArg = V8DOMWindow::HasInstance(args[3]) ? V8DOMWindow::toNative(v8::Handle<v8::Object>::Cast(args[3])) : 0;
   V8Parameter<> dataArg = args[4];
   imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
   return v8::Handle<v8::Value>();
 }
JSValue* JSTextEvent::getValueProperty(ExecState* exec, int token) const
{
    switch (token) {
    case DataAttrNum: {
        TextEvent* imp = static_cast<TextEvent*>(impl());

        return jsString(imp->data());
    }
    }
    return 0;
}
Example #9
0
/**
*	Get text event with specified name.
*/
TextEvent* EventSystem::getTextEvent(QString ID) const {
	if (ID == QString())
		throw ProjectException("Cannot search for a text event with an empty ID.");

	for (int i = 0; i < _textEvents.size(); i++) {
		TextEvent *it = _textEvents.at(i);
		if (!!it && (it->getName() == ID))
			return it;
	}

	return 0;
}
Example #10
0
static v8::Handle<v8::Value> initTextEventCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TextEvent.initTextEvent");
    TextEvent* imp = V8TextEvent::toNative(args.Holder());
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, typeArg, MAYBE_MISSING_PARAMETER(args, 0, MissingIsUndefined));
    EXCEPTION_BLOCK(bool, canBubbleArg, MAYBE_MISSING_PARAMETER(args, 1, MissingIsUndefined)->BooleanValue());
    EXCEPTION_BLOCK(bool, cancelableArg, MAYBE_MISSING_PARAMETER(args, 2, MissingIsUndefined)->BooleanValue());
    EXCEPTION_BLOCK(DOMWindow*, viewArg, V8DOMWindow::HasInstance(MAYBE_MISSING_PARAMETER(args, 3, MissingIsUndefined)) ? V8DOMWindow::toNative(v8::Handle<v8::Object>::Cast(MAYBE_MISSING_PARAMETER(args, 3, MissingIsUndefined))) : 0);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, dataArg, MAYBE_MISSING_PARAMETER(args, 4, MissingIsUndefined));
    imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
    return v8::Handle<v8::Value>();
}
Example #11
0
static v8::Handle<v8::Value> initTextEventCallback(const v8::Arguments& args)
{
    INC_STATS("DOM.TextEvent.initTextEvent");
    TextEvent* imp = V8TextEvent::toNative(args.Holder());
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, typeArg, args[0]);
    EXCEPTION_BLOCK(bool, canBubbleArg, args[1]->BooleanValue());
    EXCEPTION_BLOCK(bool, cancelableArg, args[2]->BooleanValue());
    EXCEPTION_BLOCK(DOMWindow*, viewArg, V8DOMWindow::HasInstance(args[3]) ? V8DOMWindow::toNative(v8::Handle<v8::Object>::Cast(args[3])) : 0);
    STRING_TO_V8PARAMETER_EXCEPTION_BLOCK(V8Parameter<>, dataArg, args[4]);
    imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
    return v8::Handle<v8::Value>();
}
Example #12
0
/**
*	Remove text event with name <i>name</i> from the system.
*/
void EventSystem::removeTextEvent(QString name) {
	if (name == QString())
		throw ProjectException("Cannot search for a text event with an empty name.");

	for (int i = 0; i < _textEvents.size(); i++) {
		TextEvent *it = _textEvents.at(i);
		if (!!it && (it->getName() == name)) {
			_textEvents.remove(i);
			delete it;
			return;
		}
	}
}
Example #13
0
JSValue* jsTextEventPrototypeFunctionInitTextEvent(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    if (!thisValue->isObject(&JSTextEvent::s_info))
        return throwError(exec, TypeError);
    JSTextEvent* castedThisObj = static_cast<JSTextEvent*>(thisValue);
    TextEvent* imp = static_cast<TextEvent*>(castedThisObj->impl());
    const UString& typeArg = args[0]->toString(exec);
    bool canBubbleArg = args[1]->toBoolean(exec);
    bool cancelableArg = args[2]->toBoolean(exec);
    DOMWindow* viewArg = toDOMWindow(args[3]);
    const UString& dataArg = args[4]->toString(exec);

    imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
    return jsUndefined();
}
JSValue* JSTextEventPrototypeFunction::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
{
    if (!thisObj->inherits(&JSTextEvent::info))
      return throwError(exec, TypeError);

    TextEvent* imp = static_cast<TextEvent*>(static_cast<JSTextEvent*>(thisObj)->impl());

    switch (id) {
    case JSTextEvent::InitTextEventFuncNum: {
        String typeArg = args[0]->toString(exec);
        bool canBubbleArg = args[1]->toBoolean(exec);
        bool cancelableArg = args[2]->toBoolean(exec);
        DOMWindow* viewArg = toDOMWindow(args[3]);
        String dataArg = args[4]->toString(exec);

        imp->initTextEvent(typeArg, canBubbleArg, cancelableArg, viewArg, dataArg);
        return jsUndefined();
    }
    }
    return 0;
}
void ChatEntity::processEventsClient(ChatEvent* cEvent) {
	// A text line
	TextEvent* text = dynamic_cast<TextEvent*> (cEvent);
	if (text) {
		// Update all the listeners
		std::string user = text->getUser();
		std::string line = text->getLine();
		for (listener_iterator it = listenersBegin(); it != listenersEnd(); ++it) {
			(*it)->newMessage(user, line);
		}
	}

	// A notification
	NotifyEvent* notify = dynamic_cast<NotifyEvent*> (cEvent);
	if (notify) {
		// Update all the listeners
		std::string line = notify->getLine();
		for (listener_iterator it = listenersBegin(); it != listenersEnd(); ++it) {
			(*it)->newNotification(line);
		}
	}
}
Example #16
0
 static v8::Handle<v8::Value> dataAttrGetter(v8::Local<v8::String> name, const v8::AccessorInfo& info) {
   INC_STATS("DOM.TextEvent.data._get");
   TextEvent* imp = V8TextEvent::toNative(info.Holder());
   return v8String(imp->data());
 }