Home | History | Annotate | Download | only in css
      1 // Copyright 2014 The Chromium Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef MediaQueryListEvent_h
      6 #define MediaQueryListEvent_h
      7 
      8 #include "core/css/MediaQueryList.h"
      9 #include "core/events/Event.h"
     10 
     11 namespace blink {
     12 
     13 struct MediaQueryListEventInit : public EventInit {
     14     MediaQueryListEventInit() : matches(false) { }
     15 
     16     String media;
     17     bool matches;
     18 };
     19 
     20 class MediaQueryListEvent FINAL : public Event {
     21     DEFINE_WRAPPERTYPEINFO();
     22 public:
     23     static PassRefPtrWillBeRawPtr<MediaQueryListEvent> create()
     24     {
     25         return adoptRefWillBeNoop(new MediaQueryListEvent);
     26     }
     27 
     28     static PassRefPtrWillBeRawPtr<MediaQueryListEvent> create(PassRefPtrWillBeRawPtr<MediaQueryList> list)
     29     {
     30         return adoptRefWillBeNoop(new MediaQueryListEvent(list));
     31     }
     32 
     33     static PassRefPtrWillBeRawPtr<MediaQueryListEvent> create(const String& media, bool matches)
     34     {
     35         return adoptRefWillBeNoop(new MediaQueryListEvent(media, matches));
     36     }
     37 
     38     static PassRefPtrWillBeRawPtr<MediaQueryListEvent> create(const AtomicString& eventType, const MediaQueryListEventInit& initializer)
     39     {
     40         return adoptRefWillBeNoop(new MediaQueryListEvent(eventType, initializer));
     41     }
     42 
     43     String media() const { return m_mediaQueryList ? m_mediaQueryList->media() : m_media; }
     44     bool matches() const { return m_mediaQueryList ? m_mediaQueryList->matches() : m_matches; }
     45 
     46     virtual const AtomicString& interfaceName() const OVERRIDE { return EventNames::MediaQueryListEvent; }
     47 
     48     virtual void trace(Visitor* visitor) OVERRIDE
     49     {
     50         Event::trace(visitor);
     51         visitor->trace(m_mediaQueryList);
     52     }
     53 
     54 private:
     55     MediaQueryListEvent()
     56         : m_matches(false) { }
     57 
     58     MediaQueryListEvent(const String& media, bool matches)
     59         : Event(EventTypeNames::change, false, false)
     60         , m_media(media)
     61         , m_matches(matches) { }
     62 
     63     explicit MediaQueryListEvent(PassRefPtrWillBeRawPtr<MediaQueryList> list)
     64         : Event(EventTypeNames::change, false, false)
     65         , m_mediaQueryList(list)
     66         , m_matches(false) { }
     67 
     68     MediaQueryListEvent(const AtomicString& eventType, const MediaQueryListEventInit& initializer)
     69         : Event(eventType, initializer)
     70         , m_media(initializer.media)
     71         , m_matches(initializer.matches) { }
     72 
     73     // We have m_media/m_matches for JS-created events; we use m_mediaQueryList
     74     // for events that blink generates.
     75     RefPtrWillBeMember<MediaQueryList> m_mediaQueryList;
     76     String m_media;
     77     bool m_matches;
     78 };
     79 
     80 } // namespace blink
     81 
     82 #endif // MediaQueryListEvent_h
     83