Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(11)

Side by Side Diff: Source/core/css/MediaQueryMatcher.h

Issue 214383008: Rework MediaQueryMatcher to batch up listener notification (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 24 matching lines...) Expand all
35 class MediaQuerySet; 35 class MediaQuerySet;
36 36
37 // MediaQueryMatcher class is responsible for keeping a vector of pairs 37 // MediaQueryMatcher class is responsible for keeping a vector of pairs
38 // MediaQueryList x MediaQueryListListener. It is responsible for evaluating the queries 38 // MediaQueryList x MediaQueryListListener. It is responsible for evaluating the queries
39 // whenever it is needed and to call the listeners if the corresponding query ha s changed. 39 // whenever it is needed and to call the listeners if the corresponding query ha s changed.
40 // The listeners must be called in the very same order in which they have been a dded. 40 // The listeners must be called in the very same order in which they have been a dded.
41 41
42 class MediaQueryMatcher FINAL : public RefCountedWillBeGarbageCollected<MediaQue ryMatcher> { 42 class MediaQueryMatcher FINAL : public RefCountedWillBeGarbageCollected<MediaQue ryMatcher> {
43 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryMatcher); 43 DECLARE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryMatcher);
44 public: 44 public:
45 static PassRefPtrWillBeRawPtr<MediaQueryMatcher> create(Document* document) { return adoptRefWillBeNoop(new MediaQueryMatcher(document)); } 45 static PassRefPtrWillBeRawPtr<MediaQueryMatcher> create(Document& document) { return adoptRefWillBeNoop(new MediaQueryMatcher(document)); }
46 void documentDestroyed();
47 46
48 void addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener>, PassRefPtrW illBeRawPtr<MediaQueryList>); 47 void documentDetached();
49 void removeListener(MediaQueryListListener*, MediaQueryList*); 48
49 void addMediaQueryList(MediaQueryList*);
50 void removeMediaQueryList(MediaQueryList*);
50 51
51 PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&); 52 PassRefPtrWillBeRawPtr<MediaQueryList> matchMedia(const String&);
52 53
53 unsigned evaluationRound() const { return m_evaluationRound; } 54 void mediaChanged();
54 void styleResolverChanged(); 55
55 bool evaluate(const MediaQuerySet*); 56 bool evaluate(const MediaQuerySet*);
56 57
57 void trace(Visitor*); 58 void trace(Visitor*);
58 59
59 private: 60 private:
60 class Listener FINAL : public NoBaseWillBeGarbageCollected<Listener> { 61 explicit MediaQueryMatcher(Document&);
61 public:
62 Listener(PassRefPtrWillBeRawPtr<MediaQueryListListener>, PassRefPtrWillB eRawPtr<MediaQueryList>);
63 void evaluate(ScriptState*, MediaQueryEvaluator*);
64
65 MediaQueryListListener* listener() { return m_listener.get(); }
66 MediaQueryList* query() { return m_query.get(); }
67
68 void trace(Visitor*);
69
70 private:
71 RefPtrWillBeMember<MediaQueryListListener> m_listener;
72 RefPtrWillBeMember<MediaQueryList> m_query;
73 };
74
75 MediaQueryMatcher(Document*);
76 PassOwnPtr<MediaQueryEvaluator> prepareEvaluator() const;
77 AtomicString mediaType() const; 62 AtomicString mediaType() const;
78 63
64 PassOwnPtr<MediaQueryEvaluator> createEvaluator() const;
65
79 Document* m_document; 66 Document* m_document;
80 WillBeHeapVector<OwnPtrWillBeMember<Listener> > m_listeners; 67 OwnPtr<MediaQueryEvaluator> m_evaluator;
81 68
82 // This value is incremented at style selector changes. 69 // FIXME: This should a HeapListHashSet.
83 // It is used to avoid evaluating queries more then once and to make sure 70 typedef ListHashSet<RawPtrWillBeMember<MediaQueryList> > MediaQueryListSet;
84 // that a media query result change is notified exactly once. 71 MediaQueryListSet m_mediaLists;
85 unsigned m_evaluationRound;
86 }; 72 };
87 73
88 } 74 }
89 75
90 #endif // MediaQueryMatcher_h 76 #endif // MediaQueryMatcher_h
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698