void ScriptedAnimationController::dispatchEvents(const AtomicString& eventInterfaceFilter)
{
    WillBeHeapVector<RefPtrWillBeMember<Event> > events;
    if (eventInterfaceFilter.isEmpty()) {
        events.swap(m_eventQueue);
        m_perFrameEvents.clear();
    } else {
        WillBeHeapVector<RefPtrWillBeMember<Event> > remaining;
        for (auto& event : m_eventQueue) {
            if (event && event->interfaceName() == eventInterfaceFilter) {
                m_perFrameEvents.remove(eventTargetKey(event.get()));
                events.append(event.release());
            } else {
                remaining.append(event.release());
            }
        }
        remaining.swap(m_eventQueue);
    }


    for (size_t i = 0; i < events.size(); ++i) {
        EventTarget* eventTarget = events[i]->target();
        // FIXME: we should figure out how to make dispatchEvent properly virtual to avoid
        // special casting window.
        // FIXME: We should not fire events for nodes that are no longer in the tree.
        if (LocalDOMWindow* window = eventTarget->toDOMWindow())
            window->dispatchEvent(events[i], nullptr);
        else
            eventTarget->dispatchEvent(events[i]);

        InspectorInstrumentation::didRemoveEvent(eventTarget, events[i].get());
    }
}
bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, CachedScript* cachedScript)
{
    EventTarget* target = errorEventTarget();
    if (!target)
        return false;

#if PLATFORM(IOS)
    if (target == target->toDOMWindow() && isDocument()) {
        Settings* settings = static_cast<Document*>(this)->settings();
        if (settings && !settings->shouldDispatchJavaScriptWindowOnErrorEvents())
            return false;
    }
#endif

    String message = errorMessage;
    int line = lineNumber;
    int column = columnNumber;
    String sourceName = sourceURL;
    sanitizeScriptError(message, line, column, sourceName, cachedScript);

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line, column);
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
Example #3
0
    void revoke()
    {
        ExecutionContext* executionContext = m_scriptState->executionContext();
        if (!executionContext)
            return;

        ScriptState::Scope scope(m_scriptState);
        v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate());
        v8::Local<v8::Value> reason = m_exception.newLocal(m_scriptState->isolate());
        // Either collected or https://crbug.com/450330
        if (value.IsEmpty() || !value->IsPromise())
            return;

        EventTarget* target = executionContext->errorEventTarget();
        if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) {
            PromiseRejectionEventInit init;
            init.setPromise(ScriptPromise(m_scriptState, value));
            init.setReason(ScriptValue(m_scriptState, reason));
            RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEvent::create(m_scriptState, EventTypeNames::rejectionhandled, init);
            target->dispatchEvent(event);
        }

        if (m_shouldLogToConsole) {
            RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, RevokedErrorMessageLevel, "Handler added to rejected promise");
            consoleMessage->setRelatedMessageId(m_consoleMessageId);
            executionContext->addConsoleMessage(consoleMessage.release());
        }
    }
Example #4
0
bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, const String& sourceURL)
{
    EventTarget* target = errorEventTarget();
    if (!target)
        return false;

    String message;
    int line;
    String sourceName;
    KURL targetUrl = completeURL(sourceURL);
    if (securityOrigin()->canRequest(targetUrl)) {
        message = errorMessage;
        line = lineNumber;
        sourceName = sourceURL;
    } else {
        message = "Script error.";
        sourceName = String();
        line = 0;
    }

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line);
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
Example #5
0
void NodeRemovedFromDocument(Node* node)
{
	NodeList* childNodes = node->get_childNodes();

	unsigned int length = childNodes->get_length();

	for (unsigned int i = 0; i < length; ++i)
	{
		Node* child = childNodes->item(i);

		NodeRemovedFromDocument(child);
	}

	Document* ownerDocument = node->get_ownerDocument();

	DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(ownerDocument);
	ASSERT(ownerDocumentEvent != nullptr);

	MutationEvent* event = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(S("MutationEvent")));

	event->initMutationEvent(S("DOMNodeRemovedFromDocument"), false, false, NULL/*relatedNode*/, nullptr, nullptr, nullptr, CHANGE_UNKNOWN);

	EventTarget* target = dynamic_cast<EventTarget*>(node);

	target->dispatchEvent(event);
}
Example #6
0
bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, int columnNumber, const String& sourceURL, JSC::Exception* exception, CachedScript* cachedScript)
{
    EventTarget* target = errorEventTarget();
    if (!target)
        return false;

#if PLATFORM(IOS)
    if (target->toDOMWindow() && is<Document>(*this)) {
        Settings* settings = downcast<Document>(*this).settings();
        if (settings && !settings->shouldDispatchJavaScriptWindowOnErrorEvents())
            return false;
    }
#endif

    String message = errorMessage;
    int line = lineNumber;
    int column = columnNumber;
    String sourceName = sourceURL;
    Deprecated::ScriptValue error = exception && exception->value() ? Deprecated::ScriptValue(vm(), exception->value()) : Deprecated::ScriptValue();
    sanitizeScriptError(message, line, column, sourceName, error, cachedScript);

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    Ref<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line, column, error);
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
Example #7
0
  void revoke() {
    ExecutionContext* executionContext = m_scriptState->getExecutionContext();
    if (!executionContext)
      return;

    ScriptState::Scope scope(m_scriptState);
    v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate());
    v8::Local<v8::Value> reason =
        m_exception.newLocal(m_scriptState->isolate());
    // Either collected or https://crbug.com/450330
    if (value.IsEmpty() || !value->IsPromise())
      return;

    EventTarget* target = executionContext->errorEventTarget();
    if (target &&
        !executionContext->shouldSanitizeScriptError(m_resourceName,
                                                     m_corsStatus)) {
      PromiseRejectionEventInit init;
      init.setPromise(ScriptPromise(m_scriptState, value));
      init.setReason(ScriptValue(m_scriptState, reason));
      PromiseRejectionEvent* event = PromiseRejectionEvent::create(
          m_scriptState, EventTypeNames::rejectionhandled, init);
      target->dispatchEvent(event);
    }

    if (m_shouldLogToConsole && m_promiseRejectionId) {
      V8PerIsolateData* data = V8PerIsolateData::from(m_scriptState->isolate());
      if (data->threadDebugger())
        data->threadDebugger()->promiseRejectionRevoked(
            m_scriptState->context(), m_promiseRejectionId);
    }
  }
Example #8
0
void DOMWindowEventQueue::dispatchEvent(PassRefPtrWillBeRawPtr<Event> event)
{
    EventTarget* eventTarget = event->target();
    if (eventTarget->toDOMWindow())
        eventTarget->toDOMWindow()->dispatchEvent(event, nullptr);
    else
        eventTarget->dispatchEvent(event);
}
Example #9
0
void EventQueue::dispatchEvent(PassRefPtr<Event> event)
{
    EventTarget* eventTarget = event->target();
    if (eventTarget->toDOMWindow())
        eventTarget->toDOMWindow()->dispatchEvent(event, 0);
    else
        eventTarget->dispatchEvent(event);
}
Example #10
0
void DOMWindowEventQueue::dispatchEvent(Event* event) {
  EventTarget* eventTarget = event->target();
  InspectorInstrumentation::AsyncTask asyncTask(
      eventTarget->getExecutionContext(), event);
  if (LocalDOMWindow* window = eventTarget->toLocalDOMWindow())
    window->dispatchEvent(event, nullptr);
  else
    eventTarget->dispatchEvent(event);
}
Example #11
0
JSValue* jsEventTargetDispatchEvent(ExecState* exec, JSObject*, JSValue* thisValue, const ArgList& args)
{
    Node* eventNode = 0;
    EventTarget* eventTarget = 0;
    if (!retrieveEventTargetAndCorrespondingNode(exec, thisValue, eventNode, eventTarget))
        return throwError(exec, TypeError);

    DOMExceptionTranslator exception(exec);
    return jsBoolean(eventTarget->dispatchEvent(toEvent(args.at(exec, 0)), exception));
}
Example #12
0
    void report()
    {
        if (!m_scriptState->contextIsValid())
            return;
        // If execution termination has been triggered, quietly bail out.
        if (v8::V8::IsExecutionTerminating(m_scriptState->isolate()))
            return;
        ExecutionContext* executionContext = m_scriptState->executionContext();
        if (!executionContext)
            return;

        ScriptState::Scope scope(m_scriptState);
        v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate());
        v8::Local<v8::Value> reason = m_exception.newLocal(m_scriptState->isolate());
        // Either collected or https://crbug.com/450330
        if (value.IsEmpty() || !value->IsPromise())
            return;
        ASSERT(!hasHandler());

        EventTarget* target = executionContext->errorEventTarget();
        if (RuntimeEnabledFeatures::promiseRejectionEventEnabled() && target && !executionContext->shouldSanitizeScriptError(m_resourceName, m_corsStatus)) {
            PromiseRejectionEventInit init;
            init.setPromise(ScriptPromise(m_scriptState, value));
            init.setReason(ScriptValue(m_scriptState, reason));
            init.setCancelable(true);
            RefPtrWillBeRawPtr<PromiseRejectionEvent> event = PromiseRejectionEvent::create(m_scriptState, EventTypeNames::unhandledrejection, init);
            // Log to console if event was not preventDefault()'ed.
            m_shouldLogToConsole = target->dispatchEvent(event);
        }

        if (m_shouldLogToConsole) {
            const String errorMessage = "Uncaught (in promise)";
            Vector<ScriptValue> args;
            args.append(ScriptValue(m_scriptState, v8String(m_scriptState->isolate(), errorMessage)));
            args.append(ScriptValue(m_scriptState, reason));
            RefPtrWillBeRawPtr<ScriptArguments> arguments = ScriptArguments::create(m_scriptState, args);

            String embedderErrorMessage = m_errorMessage;
            if (embedderErrorMessage.isEmpty())
                embedderErrorMessage = errorMessage;
            else if (embedderErrorMessage.startsWith("Uncaught "))
                embedderErrorMessage.insert(" (in promise)", 8);

            RefPtrWillBeRawPtr<ConsoleMessage> consoleMessage = ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, embedderErrorMessage, m_resourceName, m_lineNumber, m_columnNumber);
            consoleMessage->setScriptArguments(arguments);
            consoleMessage->setCallStack(m_callStack);
            consoleMessage->setScriptId(m_scriptId);
            m_consoleMessageId = consoleMessage->assignMessageId();
            executionContext->addConsoleMessage(consoleMessage.release());
        }

        m_callStack.clear();
    }
void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
{
    ASSERT(!m_timer.isActive());
    ASSERT(!m_pendingEvents.isEmpty());

    Vector<RefPtr<Event> > pendingEvents;
    m_pendingEvents.swap(pendingEvents);

    RefPtr<EventTarget> protect(m_owner);
    for (unsigned i = 0; i < pendingEvents.size(); ++i) {
        EventTarget* target = pendingEvents[i]->target() ? pendingEvents[i]->target() : m_owner;
        target->dispatchEvent(pendingEvents[i].release());
    }
}
Example #14
0
bool ExecutionContext::dispatchErrorEventInternal(
    ErrorEvent* errorEvent,
    AccessControlStatus corsStatus) {
  EventTarget* target = errorEventTarget();
  if (!target)
    return false;

  if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus))
    errorEvent = ErrorEvent::createSanitizedError(errorEvent->world());

  DCHECK(!m_inDispatchErrorEvent);
  m_inDispatchErrorEvent = true;
  target->dispatchEvent(errorEvent);
  m_inDispatchErrorEvent = false;
  return errorEvent->defaultPrevented();
}
Example #15
0
 static v8::Handle<v8::Value> v8dispatchEvent(  const v8::Arguments& arguments ){
   if( arguments.Length() > 0 ){
     v8::Local<v8::External> external = v8::Local<v8::External>::Cast( arguments.This()->GetInternalField(0) );
     EventTarget* object = static_cast<EventTarget*>( external->Value() );
     
     
     v8::Handle<v8::Object> ev =  v8::Handle<v8::Object>::Cast(arguments[0]);
     external = v8::Local<v8::External>::Cast( ev->GetInternalField(0) );
     Event* event = static_cast<Event*>( external->Value() );
     
     
     object->dispatchEvent(event, ev);
   }
   // TODO return value
   return v8::Undefined();
 }
bool ExecutionContext::dispatchErrorEvent(PassRefPtrWillBeRawPtr<ErrorEvent> event, AccessControlStatus corsStatus)
{
    EventTarget* target = errorEventTarget();
    if (!target)
        return false;

    RefPtrWillBeRawPtr<ErrorEvent> errorEvent = event;
    if (shouldSanitizeScriptError(errorEvent->filename(), corsStatus))
        errorEvent = ErrorEvent::createSanitizedError(errorEvent->world());

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
void ScriptedAnimationController::dispatchEvents()
{
    Vector<RefPtr<Event> > events;
    events.swap(m_eventQueue);
    m_perFrameEvents.clear();

    for (size_t i = 0; i < events.size(); ++i) {
        EventTarget* eventTarget = events[i]->target();
        // FIXME: we should figure out how to make dispatchEvent properly virtual to avoid
        // special casting window.
        // FIXME: We should not fire events for nodes that are no longer in the tree.
        if (LocalDOMWindow* window = eventTarget->toDOMWindow())
            window->dispatchEvent(events[i], nullptr);
        else
            eventTarget->dispatchEvent(events[i]);
    }
}
bool ScriptExecutionContext::dispatchErrorEvent(const String& errorMessage, int lineNumber, const String& sourceURL)
{
    EventTarget* target = errorEventTarget();
    if (!target)
        return false;

    String message = errorMessage;
    int line = lineNumber;
    String sourceName = sourceURL;
    sanitizeScriptError(message, line, sourceName);

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    RefPtr<ErrorEvent> errorEvent = ErrorEvent::create(message, sourceName, line);
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
{
    ASSERT(!m_timer.isActive());
    ASSERT(!m_pendingEvents.isEmpty());

    HeapVector<Member<Event>> pendingEvents;
    m_pendingEvents.swap(pendingEvents);

    for (const auto& pendingEvent : pendingEvents) {
        Event* event = pendingEvent.get();
        EventTarget* target = event->target() ? event->target() : m_owner.get();
        CString type(event->type().ascii());
        InspectorInstrumentation::AsyncTask asyncTask(target->getExecutionContext(), event);
        TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type);
        target->dispatchEvent(pendingEvent);
        TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type);
    }
}
Example #20
0
void GenericEventQueue::timerFired(Timer<GenericEventQueue>*)
{
    ASSERT(!m_timer.isActive());
    ASSERT(!m_pendingEvents.isEmpty());

    Vector<RefPtr<Event> > pendingEvents;
    m_pendingEvents.swap(pendingEvents);

    RefPtr<EventTarget> protect(m_owner);
    for (size_t i = 0; i < pendingEvents.size(); ++i) {
        Event* event = pendingEvents[i].get();
        EventTarget* target = event->target() ? event->target() : m_owner;
        CString type(event->type().ascii());
        TRACE_EVENT_ASYNC_STEP_INTO1("event", "GenericEventQueue:enqueueEvent", event, "dispatch", "type", type);
        target->dispatchEvent(pendingEvents[i].release());
        TRACE_EVENT_ASYNC_END1("event", "GenericEventQueue:enqueueEvent", event, "type", type);
    }
}
Example #21
0
bool ExecutionContext::dispatchErrorEvent(PassRefPtr<ErrorEvent> event)
{
    if (!m_client)
        return false;
    EventTarget* target = m_client->errorEventTarget();
    if (!target)
        return false;

    RefPtr<ErrorEvent> errorEvent = event;
    if (shouldSanitizeScriptError(errorEvent->filename()))
        errorEvent = ErrorEvent::createSanitizedError(errorEvent->world());

    ASSERT(!m_inDispatchErrorEvent);
    m_inDispatchErrorEvent = true;
    target->dispatchEvent(errorEvent);
    m_inDispatchErrorEvent = false;
    return errorEvent->defaultPrevented();
}
Example #22
0
  void report() {
    if (!m_scriptState->contextIsValid())
      return;
    // If execution termination has been triggered, quietly bail out.
    if (m_scriptState->isolate()->IsExecutionTerminating())
      return;
    ExecutionContext* executionContext = m_scriptState->getExecutionContext();
    if (!executionContext)
      return;

    ScriptState::Scope scope(m_scriptState);
    v8::Local<v8::Value> value = m_promise.newLocal(m_scriptState->isolate());
    v8::Local<v8::Value> reason =
        m_exception.newLocal(m_scriptState->isolate());
    // Either collected or https://crbug.com/450330
    if (value.IsEmpty() || !value->IsPromise())
      return;
    ASSERT(!hasHandler());

    EventTarget* target = executionContext->errorEventTarget();
    if (target &&
        !executionContext->shouldSanitizeScriptError(m_resourceName,
                                                     m_corsStatus)) {
      PromiseRejectionEventInit init;
      init.setPromise(ScriptPromise(m_scriptState, value));
      init.setReason(ScriptValue(m_scriptState, reason));
      init.setCancelable(true);
      PromiseRejectionEvent* event = PromiseRejectionEvent::create(
          m_scriptState, EventTypeNames::unhandledrejection, init);
      // Log to console if event was not canceled.
      m_shouldLogToConsole =
          target->dispatchEvent(event) == DispatchEventResult::NotCanceled;
    }

    if (m_shouldLogToConsole) {
      V8PerIsolateData* data = V8PerIsolateData::from(m_scriptState->isolate());
      if (data->threadDebugger())
        m_promiseRejectionId = data->threadDebugger()->promiseRejected(
            m_scriptState->context(), m_errorMessage, reason,
            std::move(m_location));
    }

    m_location.reset();
  }
Example #23
0
void SVGVisual::OnLeftMouseButtonDown(Gui::MouseButtonEventArgs* args)
{
	Gui::Point mousepos = args->GetPosition(this);

	PSVGElement* pElement;
	pElement = m_psvgelement->HitTestElement(gm::Matrix3d::GetIdentity(), gm::PointD(mousepos.X, mousepos.Y));

	if (pElement)
	{
		EventTarget* target = dynamic_cast<EventTarget*>(pElement->m_pNode);
		EventTarget* relatedTarget = dynamic_cast<EventTarget*>(m_psvgelement->m_pNode);

		gm::PointF screenpt;
		gm::PointF clientpt = mousepos;
		UINT nFlags = 0;
		bool m_bAlt = false;
		int iButton = 0;

		//IDocumentEvent* documentEvent = dynamic_cast<IDocumentEvent*>(m_document);

		MouseEvent* mouseevt = static_cast<MouseEvent*>(m_document->createEvent(WSTR("MouseEvents")));
		mouseevt->initMouseEvent(L"mousedown",
			true,	// bubbles
			true,	// cancelable
			m_window,	// viewArg
			0,		// detail
			screenpt.X, screenpt.Y,	// screen
			clientpt.X, clientpt.Y, // client,
			(nFlags & MK_CONTROL)? true: false,
			(nFlags & MK_SHIFT)? true: false,
			(m_bAlt)? true: false,
			0,	// meta
			iButton,
			relatedTarget
			);

		bool doDefault = target->dispatchEvent(mouseevt);
		if (doDefault)
		{
		}
	}
}
Example #24
0
void NodeInsertedIntoDocument(Node* node)
{
	NodeList* childNodes = node->get_childNodes();
	long length = childNodes->get_length();

	for (int i = 0; i < length; ++i)
	{
		Node* child = childNodes->item(i);

		NodeInsertedIntoDocument(child);
	}

	Document* ownerDocument = node->get_ownerDocument();

	DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(ownerDocument);
	ASSERT(ownerDocumentEvent != nullptr);

	MutationEvent* pEvent = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(S("MutationEvent")));
	pEvent->initMutationEvent(S("DOMNodeInsertedIntoDocument"), false, false, nullptr/*relatedNode*/, nullptr, nullptr, nullptr, CHANGE_UNKNOWN);

	EventTarget* target = dynamic_cast<EventTarget*>(node);

	target->dispatchEvent(pEvent);
}
Example #25
0
Node* Node::insertNode(Node* _newChild, Node* _pBefore)
{
	ChildNode* newChild = dynamic_cast<ChildNode*>(_newChild);
	ChildNode* pBefore = dynamic_cast<ChildNode*>(_pBefore);

	Node* pPrevParent = newChild->get_parentNode();
	if (pPrevParent)
	{
		pPrevParent->removeChild(newChild);
	}

	ChildNode* pAfter;

	if (pBefore)
		pAfter = pBefore->get_previousSibling();
	else
		pAfter = m_lastChild;

	newChild->set_nextSibling(pBefore);
	newChild->set_previousSibling(pAfter);

	if (pAfter == NULL)
		m_firstChild = newChild;
	else
		pAfter->set_nextSibling(newChild);

	if (pBefore == NULL)
		m_lastChild = newChild;
	else
		pBefore->set_previousSibling(newChild);

	if (pBefore)
	{
		for (int i = 0; i < m_childNodes->m_items.GetSize(); i++)
		{
			if (m_childNodes->m_items[i] == pBefore)
			{
				m_childNodes->m_items.InsertAt(i, newChild);
			//	m_childNodes->m_items.insert(&m_childNodes->m_items[i], newChild);
				break;
			}
		}
	}
	else
	{
		m_childNodes->m_items.Add(newChild);
	}

// Set new child node's parent to this element
	newChild->set_parentNode(this);

//	TRACE("TODO\n");
#if 0
// Update computed xmlspace for inserted child(ren)
	CComQIPtr<ILDOMElement> newElement((IUnknown*)newChild);
	if (newElement)
	{
		CComBSTR xmlspace;
		newElement->getAttribute(OLESTR("xml:space"), &xmlspace);
		if (xmlspace.Length()==0)	// inherit from parent
		{
			CComQIPtr<CLDOMElementImplImpl>((IUnknown*)newChild)->m_xmlspace = m_xmlspace;
		}
		else	// explicitly set
		{
			CComQIPtr<CLDOMElementImplImpl>((IUnknown*)newChild)->m_xmlspace = cmpbstr(xmlspace, OLESTR("preserve")) == 0;
		}
	// TODO, update recursively for newChild
	}
#endif
	// SMIL Animation (TODO, not very well thought trough)
#if 0
	{
		CLDOMDocument* pDocument = static_cast<CLDOMDocument*>(static_cast<CLDOMDocumentImpl<ILDOMDocument>*>(m_ownerDocument));

		if (pDocument)
		{
			CComQIPtr<ILDOMElement> newElement = newChild;

			if (newElement)
			{
			// SMIL Animation (connect animate/set etc. elements to the elements they target)
				pDocument->BuildAnimationListForAllElements(newElement, pDocument->m_documentElement);

			// Set baseVal/animVal from attributes and parse 'style' attributes
				pDocument->UpdateAnimationElements(newElement);
			}
		}
	}
#endif

//	TRACE("TODO\n");
#if 0
	// Timing stuff (TODO)
	{
		ElementTimeImplImpl* elementTimeImpl((IUnknown*)newChild);
		if (elementTimeImpl)
		{
			elementTimeImpl->CalculateTimeBeforeParent();

			CComPtr<ILElementTimeContainer> parentTimeContainer;
			elementTimeImpl->get_parentTimeContainer(&parentTimeContainer);
			CComQIPtr<CLElementTimeContainerImplImpl> parentTimeContainerImpl((IUnknown*)parentTimeContainer);
			if (parentTimeContainerImpl)
			{
				parentTimeContainerImpl->RecalculateTime();
			}

			elementTimeImpl->CalculateTimeAfterParent();
		}
	}

	CComQIPtr<ILAnimationElement, &IID_ILAnimationElement> animation = (IUnknown*)newChild;
	if (animation)
	{
		CComQIPtr<CLAnimationElementImplImpl> pAnimation((IUnknown*)animation);

		pAnimation->SetValuesFromAttributes();
	}
#endif

	{
#if 0	// TODO
		for (int i = 0; i < m_pNodes.GetSize(); i++)
		{
			ASSERT(0);
			m_pNodes[i]->OnInsertedChild(newChild);
		}
#endif

#if 0
		if (TRUE)	// TODO, probably remove this (use above loop only)
		{
			CComQIPtr<INotifySend, &IID_INotifySend> cp = newChild;
			if (cp)
			{
				CComQIPtr<INotifyGet, &IID_INotifyGet> get = (IUnknown*)thisNode;
				if (get)
				{
					DWORD cookie;
					cp->Advise(get, &cookie);
				}

				cp->FireOnChanged(NOTIFY_ADD, newChild, DISPID_UNKNOWN);
			}
		}
#endif
	}

//	CComPtr<ILDOMDocument> ownerDocument;
//	newChild->get_ownerDocument(&ownerDocument);
//	if (ownerDocument)
	{
////////////////////////////////
// create an event notification

		DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(m_ownerDocument);

		if (ownerDocumentEvent == NULL)
			ownerDocumentEvent = dynamic_cast<DocumentEvent*>(this);

		if (ownerDocumentEvent)
		{
			MutationEvent* event = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(S("MutationEvent")));

			EventTarget* eventTarget = dynamic_cast<EventTarget*>(newChild);

		//
			event->initMutationEvent(S("DOMNodeInserted"), true, false, this, nullptr, nullptr, nullptr, CHANGE_UNKNOWN);

			bool doDefault = eventTarget->dispatchEvent(event);

			if (IsDocumentOrPartOfDocument(this))
			{
			// Send "DOMNodeInsertedIntoDocument" to the node and it's children
				NodeInsertedIntoDocument(newChild);
			}
		}

		{
			Node* p = this;
			while (p)
			{
				if (p->m_pNode)
				{
					p->m_pNode->m_bArrangeValid = false;
				}

				p = p->get_parentNode();
			}
		}

#if 0
	//
		event->initMutationEvent(OLESTR("DOMSubtreeModified"), VARIANT_TRUE, VARIANT_FALSE, thisNode, NULL, NULL, NULL, CHANGE_UNKNOWN);
		eventTarget->dispatchEvent(event, &doDefault);
#endif
	}

	return newChild;
}
Example #26
0
Node* Node::removeChild(Node *oldChild)
{
	//ASSERT(0);
#if 0
	// Do this first?
	{
		CComQIPtr<INotifySend> cp = thisNode;
		if (cp)
		{
			cp->FireOnChanged(NOTIFY_REMOVE, oldChild, DISPID_UNKNOWN);
		}
	}
#endif

	Document* ownerDocument = oldChild->get_ownerDocument();

	if (ownerDocument)
	{
		ASSERT(ownerDocument != NULL);

		DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(ownerDocument);
		ASSERT(ownerDocumentEvent != NULL);

		MutationEvent* evt = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(S("MutationEvent")));

	// Create a DOMNodeRemoved event
		evt->initMutationEvent(S("DOMNodeRemoved"), true, false, this, nullptr, nullptr, nullptr, CHANGE_UNKNOWN);

		EventTarget* target = dynamic_cast<EventTarget*>(oldChild);
		target->dispatchEvent(evt);

		NodeRemovedFromDocument(oldChild);
	}

// Do the work
	ChildNode* previous = oldChild->get_previousSibling();

	ChildNode* next = oldChild->get_nextSibling();

	if (previous != NULL)
		previous->set_nextSibling(next);
	else
		m_firstChild = next;

	if (next != NULL)
		next->set_previousSibling(previous);
	else
		m_lastChild = previous;

	oldChild->set_previousSibling(nullptr);
	oldChild->set_nextSibling(nullptr);

	for (int i = 0; i < m_childNodes->m_items.GetSize(); ++i)
	{
		if (m_childNodes->m_items[i] == oldChild)
		{
#if 0
			ASSERT(0);
			/////////
			CComQIPtr<INotifySend, &IID_INotifySend> cp = (IUnknown*)oldChild;
			if (cp)
			{
				CComQIPtr<INotifyGet, &IID_INotifyGet> get = (IUnknown*)thisNode;
				if (get)
				{
					cp->Unadvise(get);
				}
			}
#endif
			/////////

		//	m_childNodes->m_items.erase(&m_childNodes->m_items[i]);
			m_childNodes->m_items.RemoveAt(i);
			break;
		}
	}

	oldChild->set_parentNode(NULL);

	return oldChild;
}
Example #27
0
WebInputEventResult TouchEventManager::dispatchTouchEvents(
    const PlatformTouchEvent& event,
    const HeapVector<TouchInfo>& touchInfos,
    bool allTouchesReleased)
{
    bool touchStartOrFirstTouchMove = false;
    if (event.type() == PlatformEvent::TouchStart) {
        m_waitingForFirstTouchMove = true;
        touchStartOrFirstTouchMove = true;
    } else if (event.type() == PlatformEvent::TouchMove) {
        touchStartOrFirstTouchMove = m_waitingForFirstTouchMove;
        m_waitingForFirstTouchMove = false;
    }

    // Build up the lists to use for the |touches|, |targetTouches| and
    // |changedTouches| attributes in the JS event. See
    // http://www.w3.org/TR/touch-events/#touchevent-interface for how these
    // lists fit together.

    // Holds the complete set of touches on the screen.
    TouchList* touches = TouchList::create();

    // A different view on the 'touches' list above, filtered and grouped by
    // event target. Used for the |targetTouches| list in the JS event.
    using TargetTouchesHeapMap = HeapHashMap<EventTarget*, Member<TouchList>>;
    TargetTouchesHeapMap touchesByTarget;

    // Array of touches per state, used to assemble the |changedTouches| list.
    ChangedTouches changedTouches[PlatformTouchPoint::TouchStateEnd];

    for (unsigned i = 0; i < touchInfos.size(); ++i) {
        const TouchInfo& touchInfo = touchInfos[i];
        const PlatformTouchPoint& point = touchInfo.point;
        PlatformTouchPoint::TouchState pointState = point.state();

        if (touchInfo.consumed)
            continue;

        Touch* touch = Touch::create(
            touchInfo.targetFrame.get(),
            touchInfo.touchNode.get(),
            point.id(),
            point.screenPos(),
            touchInfo.contentPoint,
            touchInfo.adjustedRadius,
            point.rotationAngle(),
            point.force(),
            touchInfo.region);

        // Ensure this target's touch list exists, even if it ends up empty, so
        // it can always be passed to TouchEvent::Create below.
        TargetTouchesHeapMap::iterator targetTouchesIterator = touchesByTarget.find(touchInfo.touchNode.get());
        if (targetTouchesIterator == touchesByTarget.end()) {
            touchesByTarget.set(touchInfo.touchNode.get(), TouchList::create());
            targetTouchesIterator = touchesByTarget.find(touchInfo.touchNode.get());
        }

        // |touches| and |targetTouches| should only contain information about
        // touches still on the screen, so if this point is released or
        // cancelled it will only appear in the |changedTouches| list.
        if (pointState != PlatformTouchPoint::TouchReleased && pointState != PlatformTouchPoint::TouchCancelled) {
            touches->append(touch);
            targetTouchesIterator->value->append(touch);
        }

        // Now build up the correct list for |changedTouches|.
        // Note that  any touches that are in the TouchStationary state (e.g. if
        // the user had several points touched but did not move them all) should
        // never be in the |changedTouches| list so we do not handle them
        // explicitly here. See https://bugs.webkit.org/show_bug.cgi?id=37609
        // for further discussion about the TouchStationary state.
        if (pointState != PlatformTouchPoint::TouchStationary && touchInfo.knownTarget) {
            ASSERT(pointState < PlatformTouchPoint::TouchStateEnd);
            if (!changedTouches[pointState].m_touches)
                changedTouches[pointState].m_touches = TouchList::create();
            changedTouches[pointState].m_touches->append(touch);
            changedTouches[pointState].m_targets.add(touchInfo.touchNode);
        }
    }

    if (allTouchesReleased) {
        m_touchSequenceDocument.clear();
        m_touchSequenceUserGestureToken.clear();
    }

    WebInputEventResult eventResult = WebInputEventResult::NotHandled;

    // Now iterate through the |changedTouches| list and |m_targets| within it,
    // sending TouchEvents to the targets as required.
    for (unsigned state = 0; state != PlatformTouchPoint::TouchStateEnd; ++state) {
        if (!changedTouches[state].m_touches)
            continue;

        const AtomicString& eventName(touchEventNameForTouchPointState(static_cast<PlatformTouchPoint::TouchState>(state)));
        for (const auto& eventTarget : changedTouches[state].m_targets) {
            EventTarget* touchEventTarget = eventTarget;
            TouchEvent* touchEvent = TouchEvent::create(
                touches, touchesByTarget.get(touchEventTarget), changedTouches[state].m_touches.get(),
                eventName, touchEventTarget->toNode()->document().domWindow(),
                event.getModifiers(), event.cancelable(), event.causesScrollingIfUncanceled(), event.timestamp());

            DispatchEventResult domDispatchResult = touchEventTarget->dispatchEvent(touchEvent);

            // Only report for top level documents with a single touch on
            // touch-start or the first touch-move.
            if (touchStartOrFirstTouchMove && touchInfos.size() == 1 && event.cancelable() && m_frame->isMainFrame()) {
                DEFINE_STATIC_LOCAL(EnumerationHistogram, rootDocumentListenerHistogram, ("Event.Touch.TargetAndDispatchResult", TouchTargetAndDispatchResultTypeMax));
                rootDocumentListenerHistogram.count(toTouchTargetHistogramValue(eventTarget, domDispatchResult));

                // Count the handled touch starts and first touch moves before and after the page is fully loaded respectively.
                if (m_frame->document()->isLoadCompleted()) {
                    DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsAfterPageLoadHistogram, ("Event.Touch.TouchDispositionsAfterPageLoad", TouchEventDispatchResultTypeMax));
                    touchDispositionsAfterPageLoadHistogram.count((domDispatchResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches);
                } else {
                    DEFINE_STATIC_LOCAL(EnumerationHistogram, touchDispositionsBeforePageLoadHistogram, ("Event.Touch.TouchDispositionsBeforePageLoad", TouchEventDispatchResultTypeMax));
                    touchDispositionsBeforePageLoadHistogram.count((domDispatchResult != DispatchEventResult::NotCanceled) ? HandledTouches : UnhandledTouches);
                }
            }
            eventResult = EventHandler::mergeEventResult(eventResult,
                EventHandler::toWebInputEventResult(domDispatchResult));
        }
    }
    return eventResult;
}
Example #28
0
void Attr::set_value(StringIn newVal)
{
	String prevValue = nullptr;
	if (false)
	{
		prevValue = get_value();
	}

	m_valueIsValid = true;

// Optimize if there is one single textnode already there
	Text* textNode;
#if 0
	CComQIPtr<ILDOMText, &IID_ILDOMText> textNode;
	if ((m_childNodes->m_items.GetSize() == 1) && (textNode = m_childNodes->m_items[0]))
	{
		textNode->set_data(newVal);
	}
	else
#endif
	{
		for (int i = m_childNodes->m_items.GetSize()-1; i >= 0; i--)
		{
			removeChild(m_childNodes->m_items[i]);
		}

		textNode = m_ownerDocument->createTextNode(newVal);
		appendChild(textNode);
	}

#if 0
	ASSERT(m_callbacks);
	(m_ownerElement->*m_callbacks->SetBaseValString)();
#endif
	if (m_owner)
	{
		m_owner->UpdateBaseValString();
	}

//	m_callbacks->SetBaseValString(m_ownerElement);
//	m_notify->OnSetBaseValString();

	/*
	if (m_pListener)
	{
		m_pListener->OnAttrValueChanged(m_nodeName, this);
	}
	*/

	if (false)
	{
		EventTarget* eventTarget = dynamic_cast<EventTarget*>(m_ownerElement);
		if (eventTarget)
		{
			DocumentEvent* ownerDocumentEvent = dynamic_cast<DocumentEvent*>(m_ownerDocument);
			if (ownerDocumentEvent)
			{
				MutationEvent* evt;
				
				evt = dynamic_cast<MutationEvent*>(ownerDocumentEvent->createEvent(WSTR("MutationEvent")));

				if (evt)
				{
				// Create an attr modification event
					evt->initMutationEvent(WSTR("DOMAttrModified"), true, false, this, prevValue, newVal, m_nodeName, CHANGE_MODIFICATION);

					eventTarget->dispatchEvent(evt);
				}
			}
		}
	}
}