MediaQueryList.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. /*
  2. * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
  3. *
  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.
  8. *
  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.
  13. *
  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.
  18. */
  19. #ifndef MediaQueryList_h
  20. #define MediaQueryList_h
  21. #include <wtf/Forward.h>
  22. #include <wtf/RefCounted.h>
  23. #include <wtf/RefPtr.h>
  24. namespace WebCore {
  25. class MediaQueryListListener;
  26. class MediaQueryEvaluator;
  27. class MediaQueryMatcher;
  28. class MediaQuerySet;
  29. // MediaQueryList interface is specified at http://dev.w3.org/csswg/cssom-view/#the-mediaquerylist-interface
  30. // The objects of this class are returned by window.matchMedia. They may be used to
  31. // retrieve the current value of the given media query and to add/remove listeners that
  32. // will be called whenever the value of the query changes.
  33. class MediaQueryList : public RefCounted<MediaQueryList> {
  34. public:
  35. static PassRefPtr<MediaQueryList> create(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool);
  36. ~MediaQueryList();
  37. String media() const;
  38. bool matches();
  39. void addListener(PassRefPtr<MediaQueryListListener>);
  40. void removeListener(PassRefPtr<MediaQueryListListener>);
  41. void evaluate(MediaQueryEvaluator*, bool& notificationNeeded);
  42. private:
  43. MediaQueryList(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool matches);
  44. void setMatches(bool);
  45. RefPtr<MediaQueryMatcher> m_matcher;
  46. RefPtr<MediaQuerySet> m_media;
  47. unsigned m_evaluationRound; // Indicates if the query has been evaluated after the last style selector change.
  48. unsigned m_changeRound; // Used to know if the query has changed in the last style selector change.
  49. bool m_matches;
  50. };
  51. }
  52. #endif // MediaQueryList_h