 Chromium Code Reviews
 Chromium Code Reviews Issue 337883003:
  Call media query change listeners asynchronously.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk
    
  
    Issue 337883003:
  Call media query change listeners asynchronously.  (Closed) 
  Base URL: svn://svn.chromium.org/blink/trunk| OLD | NEW | 
|---|---|
| 1 /* | 1 /* | 
| 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) | 
| 3 * | 3 * | 
| 4 * This library is free software; you can redistribute it and/or | 4 * This library is free software; you can redistribute it and/or | 
| 5 * modify it under the terms of the GNU Library General Public | 5 * modify it under the terms of the GNU Library General Public | 
| 6 * License as published by the Free Software Foundation; either | 6 * License as published by the Free Software Foundation; either | 
| 7 * version 2 of the License, or (at your option) any later version. | 7 * version 2 of the License, or (at your option) any later version. | 
| 8 * | 8 * | 
| 9 * This library is distributed in the hope that it will be useful, | 9 * This library is distributed in the hope that it will be useful, | 
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 class MediaQueryMatcher; | 32 class MediaQueryMatcher; | 
| 33 class MediaQuerySet; | 33 class MediaQuerySet; | 
| 34 | 34 | 
| 35 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/# the-mediaquerylist-interface | 35 // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/# the-mediaquerylist-interface | 
| 36 // The objects of this class are returned by window.matchMedia. They may be used to | 36 // The objects of this class are returned by window.matchMedia. They may be used to | 
| 37 // retrieve the current value of the given media query and to add/remove listene rs that | 37 // retrieve the current value of the given media query and to add/remove listene rs that | 
| 38 // will be called whenever the value of the query changes. | 38 // will be called whenever the value of the query changes. | 
| 39 | 39 | 
| 40 class MediaQueryList FINAL : public RefCountedWillBeGarbageCollectedFinalized<Me diaQueryList> { | 40 class MediaQueryList FINAL : public RefCountedWillBeGarbageCollectedFinalized<Me diaQueryList> { | 
| 41 public: | 41 public: | 
| 42 class Listener : public RefCountedWillBeGarbageCollectedFinalized<Listener> { | |
| 
esprehn
2014/07/01 00:01:06
This virtual abstraction seems like it could be a
 
cbiesinger
2014/07/01 00:12:09
It could. Want me to do that?
 | |
| 43 public: | |
| 44 virtual ~Listener() { } | |
| 45 virtual void mediaQueryChanged() = 0; | |
| 46 virtual bool equals(Listener* other) { return this == other; } | |
| 
esprehn
2014/07/01 00:01:06
This shouldn't need to be virtual.
 
cbiesinger
2014/07/01 00:12:09
How so? The implementation for JS listeners needs
 | |
| 47 | |
| 48 virtual MediaQueryListListener* isMediaQueryListListener() { return null ptr; } | |
| 49 | |
| 50 // Used to keep the MediaQueryList alive and registered with the MediaQu eryMatcher | |
| 51 // as long as the listener exists. | |
| 52 void setMediaQueryList(MediaQueryList* query) { m_query = query; } | |
| 53 void clearMediaQueryList() { m_query = nullptr; } | |
| 54 | |
| 55 void trace(Visitor* visitor) { visitor->trace(m_query); } | |
| 56 protected: | |
| 57 RefPtrWillBeMember<MediaQueryList> m_query; | |
| 58 }; | |
| 59 | |
| 42 static PassRefPtrWillBeRawPtr<MediaQueryList> create(PassRefPtrWillBeRawPtr< MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); | 60 static PassRefPtrWillBeRawPtr<MediaQueryList> create(PassRefPtrWillBeRawPtr< MediaQueryMatcher>, PassRefPtrWillBeRawPtr<MediaQuerySet>); | 
| 43 virtual ~MediaQueryList(); | 61 virtual ~MediaQueryList(); | 
| 44 | 62 | 
| 45 String media() const; | 63 String media() const; | 
| 46 bool matches(); | 64 bool matches(); | 
| 47 | 65 | 
| 48 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); | 66 // These listeners will be called at requestAnimationFrame time. | 
| 49 void removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>); | 67 void addListener(PassRefPtrWillBeRawPtr<Listener>); | 
| 68 void removeListener(PassRefPtrWillBeRawPtr<Listener>); | |
| 50 | 69 | 
| 51 void mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<MediaQueryList Listener> >* toNotify); | 70 void mediaFeaturesChanged(WillBeHeapVector<RefPtrWillBeMember<Listener> >* l istenersToNotify); | 
| 52 | 71 | 
| 53 void trace(Visitor*); | 72 void trace(Visitor*); | 
| 54 | 73 | 
| 55 void documentDetached(); | 74 void documentDetached(); | 
| 56 | 75 | 
| 57 private: | 76 private: | 
| 58 MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRa wPtr<MediaQuerySet>); | 77 MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher>, PassRefPtrWillBeRa wPtr<MediaQuerySet>); | 
| 59 | 78 | 
| 60 bool updateMatches(); | 79 bool updateMatches(); | 
| 61 | 80 | 
| 62 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; | 81 RefPtrWillBeMember<MediaQueryMatcher> m_matcher; | 
| 63 RefPtrWillBeMember<MediaQuerySet> m_media; | 82 RefPtrWillBeMember<MediaQuerySet> m_media; | 
| 64 typedef WillBeHeapListHashSet<RefPtrWillBeMember<MediaQueryListListener> > L istenerList; | 83 typedef WillBeHeapListHashSet<RefPtrWillBeMember<Listener> > ListenerList; | 
| 65 ListenerList m_listeners; | 84 ListenerList m_listeners; | 
| 66 bool m_matchesDirty; | 85 bool m_matchesDirty; | 
| 67 bool m_matches; | 86 bool m_matches; | 
| 68 }; | 87 }; | 
| 69 | 88 | 
| 70 } | 89 } | 
| 71 | 90 | 
| 72 #endif // MediaQueryList_h | 91 #endif // MediaQueryList_h | 
| OLD | NEW |