diff options
Diffstat (limited to 'src/3rdparty/webkit/WebCore/notifications')
3 files changed, 16 insertions, 151 deletions
diff --git a/src/3rdparty/webkit/WebCore/notifications/Notification.cpp b/src/3rdparty/webkit/WebCore/notifications/Notification.cpp index 61ad1f3..8dd168f 100644 --- a/src/3rdparty/webkit/WebCore/notifications/Notification.cpp +++ b/src/3rdparty/webkit/WebCore/notifications/Notification.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009 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 @@ -96,137 +97,14 @@ void Notification::cancel() m_presenter->cancel(this); } -EventListener* Notification::ondisplay() const +EventTargetData* Notification::eventTargetData() { - return getAttributeEventListener("display"); + return &m_eventTargetData; } -void Notification::setOndisplay(PassRefPtr<EventListener> eventListener) +EventTargetData* Notification::ensureEventTargetData() { - setAttributeEventListener("display", eventListener); -} - -EventListener* Notification::onerror() const -{ - return getAttributeEventListener(eventNames().errorEvent); -} - -void Notification::setOnerror(PassRefPtr<EventListener> eventListener) -{ - setAttributeEventListener(eventNames().errorEvent, eventListener); -} - -EventListener* Notification::onclose() const -{ - return getAttributeEventListener(eventNames().closeEvent); -} - -void Notification::setOnclose(PassRefPtr<EventListener> eventListener) -{ - setAttributeEventListener(eventNames().closeEvent, eventListener); -} - -EventListener* Notification::getAttributeEventListener(const AtomicString& eventType) const -{ - const RegisteredEventListenerVector& listeners = m_eventListeners; - size_t size = listeners.size(); - for (size_t i = 0; i < size; ++i) { - const RegisteredEventListener& r = *listeners[i]; - if (r.eventType() == eventType && r.listener()->isAttribute()) - return r.listener(); - } - return 0; -} - -void Notification::setAttributeEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener) -{ - clearAttributeEventListener(eventType); - if (listener) - addEventListener(eventType, listener, false); -} - -void Notification::clearAttributeEventListener(const AtomicString& eventType) -{ - RegisteredEventListenerVector* listeners = &m_eventListeners; - size_t size = listeners->size(); - for (size_t i = 0; i < size; ++i) { - RegisteredEventListener& r = *listeners->at(i); - if (r.eventType() != eventType || !r.listener()->isAttribute()) - continue; - - r.setRemoved(true); - listeners->remove(i); - return; - } -} - -void Notification::dispatchDisplayEvent() -{ - RefPtr<Event> event = Event::create("display", false, true); - ExceptionCode ec = 0; - dispatchEvent(event.release(), ec); - ASSERT(!ec); -} - -void Notification::dispatchErrorEvent() -{ - RefPtr<Event> event = Event::create(eventNames().errorEvent, false, true); - ExceptionCode ec = 0; - dispatchEvent(event.release(), ec); - ASSERT(!ec); -} - -void Notification::dispatchCloseEvent() -{ - RefPtr<Event> event = Event::create(eventNames().closeEvent, false, true); - ExceptionCode ec = 0; - dispatchEvent(event.release(), ec); - ASSERT(!ec); -} - -void Notification::addEventListener(const AtomicString& eventType, PassRefPtr<EventListener> listener, bool useCapture) -{ - RefPtr<RegisteredEventListener> registeredListener = RegisteredEventListener::create(eventType, listener, useCapture); - m_eventListeners.append(registeredListener); -} - -void Notification::removeEventListener(const AtomicString& eventType, EventListener* listener, bool useCapture) -{ - size_t size = m_eventListeners.size(); - for (size_t i = 0; i < size; ++i) { - RegisteredEventListener& r = *m_eventListeners[i]; - if (r.eventType() == eventType && r.useCapture() == useCapture && *r.listener() == *listener) { - r.setRemoved(true); - m_eventListeners.remove(i); - return; - } - } -} - -void Notification::handleEvent(PassRefPtr<Event> event, bool useCapture) -{ - RegisteredEventListenerVector listenersCopy = m_eventListeners; - size_t size = listenersCopy.size(); - for (size_t i = 0; i < size; ++i) { - RegisteredEventListener& r = *listenersCopy[i]; - if (r.eventType() == event->type() && r.useCapture() == useCapture && !r.removed()) - r.listener()->handleEvent(event.get()); - } -} - -bool Notification::dispatchEvent(PassRefPtr<Event> inEvent, ExceptionCode&) -{ - RefPtr<Event> event(inEvent); - - event->setEventPhase(Event::AT_TARGET); - event->setCurrentTarget(this); - - handleEvent(event.get(), true); - if (!event->propagationStopped()) { - handleEvent(event.get(), false); - } - - return !event->defaultPrevented(); + return &m_eventTargetData; } } // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/notifications/Notification.h b/src/3rdparty/webkit/WebCore/notifications/Notification.h index baae4ee..6545579 100644 --- a/src/3rdparty/webkit/WebCore/notifications/Notification.h +++ b/src/3rdparty/webkit/WebCore/notifications/Notification.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2009 Google Inc. All rights reserved. + * Copyright (C) 2009 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 @@ -35,6 +36,7 @@ #include "AtomicStringHash.h" #include "Event.h" #include "EventListener.h" +#include "EventNames.h" #include "EventTarget.h" #include "ExceptionCode.h" #include "KURL.h" @@ -65,33 +67,17 @@ namespace WebCore { KURL url() { return m_notificationURL; } NotificationContents& contents() { return m_contents; } - EventListener* ondisplay() const; - void setOndisplay(PassRefPtr<EventListener> eventListener); - EventListener* onerror() const; - void setOnerror(PassRefPtr<EventListener> eventListener); - EventListener* onclose() const; - void setOnclose(PassRefPtr<EventListener> eventListener); + DEFINE_ATTRIBUTE_EVENT_LISTENER(display); + DEFINE_ATTRIBUTE_EVENT_LISTENER(error); + DEFINE_ATTRIBUTE_EVENT_LISTENER(close); using RefCounted<Notification>::ref; using RefCounted<Notification>::deref; - // Dispatching of events on the notification. The presenter should call these when events occur. - void dispatchDisplayEvent(); - void dispatchErrorEvent(); - void dispatchCloseEvent(); - // EventTarget interface virtual ScriptExecutionContext* scriptExecutionContext() const { return ActiveDOMObject::scriptExecutionContext(); } - virtual void addEventListener(const AtomicString&, PassRefPtr<EventListener>, bool); - virtual void removeEventListener(const AtomicString&, EventListener*, bool); - virtual bool dispatchEvent(PassRefPtr<Event>, ExceptionCode&); virtual Notification* toNotification() { return this; } - // These methods are for onEvent style listeners. - EventListener* getAttributeEventListener(const AtomicString&) const; - void setAttributeEventListener(const AtomicString&, PassRefPtr<EventListener>); - void clearAttributeEventListener(const AtomicString&); - private: Notification(const String& url, ScriptExecutionContext* context, ExceptionCode& ec, NotificationPresenter* provider); Notification(const NotificationContents& fields, ScriptExecutionContext* context, ExceptionCode& ec, NotificationPresenter* provider); @@ -99,8 +85,8 @@ namespace WebCore { // EventTarget interface virtual void refEventTarget() { ref(); } virtual void derefEventTarget() { deref(); } - - void handleEvent(PassRefPtr<Event> event, bool useCapture); + virtual EventTargetData* eventTargetData(); + virtual EventTargetData* ensureEventTargetData(); bool m_isHTML; KURL m_notificationURL; @@ -108,9 +94,9 @@ namespace WebCore { bool m_isShowing; - RegisteredEventListenerVector m_eventListeners; - NotificationPresenter* m_presenter; + + EventTargetData m_eventTargetData; }; } // namespace WebCore diff --git a/src/3rdparty/webkit/WebCore/notifications/Notification.idl b/src/3rdparty/webkit/WebCore/notifications/Notification.idl index eca2eb4..ec6a9c8 100644 --- a/src/3rdparty/webkit/WebCore/notifications/Notification.idl +++ b/src/3rdparty/webkit/WebCore/notifications/Notification.idl @@ -31,7 +31,8 @@ module threads { interface [ - Conditional=NOTIFICATIONS + Conditional=NOTIFICATIONS, + EventTarget ] Notification { void show(); void cancel(); |