2 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public License
15 * along with this library; see the file COPYING.LIB. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
21 #include "core/css/MediaQueryList.h"
23 #include "core/css/MediaList.h"
24 #include "core/css/MediaQueryEvaluator.h"
25 #include "core/css/MediaQueryListListener.h"
26 #include "core/css/MediaQueryMatcher.h"
30 PassRefPtrWillBeRawPtr<MediaQueryList> MediaQueryList::create(PassRefPtrWillBeRawPtr<MediaQueryMatcher> vector, PassRefPtrWillBeRawPtr<MediaQuerySet> media, bool matches)
32 return adoptRefWillBeNoop(new MediaQueryList(vector, media, matches));
35 MediaQueryList::MediaQueryList(PassRefPtrWillBeRawPtr<MediaQueryMatcher> vector, PassRefPtrWillBeRawPtr<MediaQuerySet> media, bool matches)
38 , m_evaluationRound(m_matcher->evaluationRound())
39 , m_changeRound(m_evaluationRound - 1) // m_evaluationRound and m_changeRound initial values must be different.
44 DEFINE_EMPTY_DESTRUCTOR_WILL_BE_REMOVED(MediaQueryList)
46 String MediaQueryList::media() const
48 return m_media->mediaText();
51 void MediaQueryList::addListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
56 m_matcher->addListener(listener, this);
59 void MediaQueryList::removeListener(PassRefPtrWillBeRawPtr<MediaQueryListListener> listener)
64 m_matcher->removeListener(listener.get(), this);
67 bool MediaQueryList::evaluate(MediaQueryEvaluator* evaluator)
69 if (m_evaluationRound != m_matcher->evaluationRound() && evaluator)
70 setMatches(evaluator->eval(m_media.get()));
71 return m_changeRound == m_matcher->evaluationRound();
74 void MediaQueryList::setMatches(bool newValue)
76 m_evaluationRound = m_matcher->evaluationRound();
78 if (newValue == m_matches)
82 m_changeRound = m_evaluationRound;
85 bool MediaQueryList::matches()
87 if (m_evaluationRound != m_matcher->evaluationRound())
88 setMatches(m_matcher->evaluate(m_media.get()));
92 void MediaQueryList::trace(Visitor* visitor)
94 visitor->trace(m_matcher);
95 visitor->trace(m_media);