source: webkit/trunk/Source/WebCore/css/MediaQueryMatcher.h

Last change on this file was 260243, checked in by Alexey Shvayka, 5 years ago

MediaQueryList should extend EventTarget
https://bugs.webkit.org/show_bug.cgi?id=203288

Reviewed by Darin Adler.

LayoutTests/imported/w3c:

  • web-platform-tests/css/cssom-view/MediaQueryList-addListener-handleEvent-expected.txt:
  • web-platform-tests/css/cssom-view/MediaQueryList-addListener-removeListener-expected.txt:
  • web-platform-tests/css/cssom-view/MediaQueryList-extends-EventTarget-expected.txt:
  • web-platform-tests/css/cssom-view/MediaQueryList-extends-EventTarget-interop-expected.txt:
  • web-platform-tests/css/cssom-view/MediaQueryListEvent-expected.txt:
  • web-platform-tests/css/cssom-view/idlharness-expected.txt:
  • web-platform-tests/css/cssom-view/matchMedia-expected.txt:

Source/WebCore:

Initially, CSSOM View Module specification [1] had a custom callback mechanism with addListener() and removeListener(),
and the callback was invoked with the associated MediaQueryList as argument.

Now the normal event mechanism [2] is used instead. For backwards compatibility, addListener() and removeListener()
methods are basically aliases for addEventListener() and removeEventListener(), respectively, and the "change" event
masquerades as a MediaQueryList.

This patch implements new event mechanism, aligning WebKit with Blink and SpiderMonkey, and also fixes
a few minor spec incompatibilities: mandatory listener argument, "handleEvent" support, and listeners call order.

[1]: https://www.w3.org/TR/2011/WD-cssom-view-20110804/#mediaquerylist
[2]: https://www.w3.org/TR/cssom-view-1/#mediaquerylist

Tests: fast/media/media-query-list-07.html

web-platform-tests/css/cssom-view/MediaQueryList-addListener-handleEvent.html
web-platform-tests/css/cssom-view/MediaQueryList-addListener-removeListener.html
web-platform-tests/css/cssom-view/MediaQueryList-extends-EventTarget.html
web-platform-tests/css/cssom-view/MediaQueryList-extends-EventTarget-interop.html
web-platform-tests/css/cssom-view/MediaQueryListEvent.html
web-platform-tests/css/cssom-view/idlharness.html
web-platform-tests/css/cssom-view/matchMedia.html

  • CMakeLists.txt:
  • DerivedSources-input.xcfilelist:
  • DerivedSources-output.xcfilelist:
  • DerivedSources.make:
  • Sources.txt:
  • WebCore.xcodeproj/project.pbxproj:
  • bindings/js/WebCoreBuiltinNames.h:
  • bindings/scripts/test/JS/*: Updated.
  • css/MediaQueryList.cpp:

(WebCore::MediaQueryList::MediaQueryList):
(WebCore::MediaQueryList::create):
(WebCore::MediaQueryList::~MediaQueryList):
(WebCore::MediaQueryList::addListener):
(WebCore::MediaQueryList::removeListener):

  • css/MediaQueryList.h:
  • css/MediaQueryList.idl:
  • css/MediaQueryListEvent.cpp: Added.

(WebCore::MediaQueryListEvent::MediaQueryListEvent):

  • css/MediaQueryListEvent.h: Added.
  • css/MediaQueryListEvent.idl: Added.
  • css/MediaQueryListListener.h: Removed.
  • css/MediaQueryListListener.idl: Removed.
  • css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::documentDestroyed):
(WebCore::MediaQueryMatcher::addMediaQueryList):
(WebCore::MediaQueryMatcher::removeMediaQueryList):
(WebCore::MediaQueryMatcher::matchMedia):
(WebCore::MediaQueryMatcher::evaluateAll):
(WebCore::MediaQueryMatcher::addListener): Deleted.
(WebCore::MediaQueryMatcher::removeListener): Deleted.

  • css/MediaQueryMatcher.h:
  • dom/EventNames.in:
  • dom/EventTarget.h:

(WebCore::EventTarget::removeEventListener):

  • dom/EventTargetFactory.in:

Source/WebInspectorUI:

  • UserInterface/Models/NativeFunctionParameters.js:

LayoutTests:

  • TestExpectations:
  • fast/media/media-query-list-07-expected.txt:
  • fast/media/media-query-list-07.html:
  • Property svn:eol-style set to native
File size: 2.4 KB
Line 
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
20#pragma once
21
22#include <memory>
23#include <wtf/Forward.h>
24#include <wtf/RefCounted.h>
25#include <wtf/Vector.h>
26#include <wtf/WeakPtr.h>
27
28namespace WebCore {
29
30class Document;
31class MediaQueryList;
32class MediaQueryEvaluator;
33class MediaQuerySet;
34class RenderStyle;
35
36// MediaQueryMatcher class is responsible for evaluating the queries whenever it
37// is needed and dispatch "change" event on MediaQueryLists if the corresponding
38// query has changed. MediaQueryLists are invoked in the order in which they were added.
39
40class MediaQueryMatcher final : public RefCounted<MediaQueryMatcher> {
41public:
42 static Ref<MediaQueryMatcher> create(Document& document) { return adoptRef(*new MediaQueryMatcher(document)); }
43 ~MediaQueryMatcher();
44
45 void documentDestroyed();
46 void addMediaQueryList(MediaQueryList&);
47 void removeMediaQueryList(MediaQueryList&);
48
49 RefPtr<MediaQueryList> matchMedia(const String&);
50
51 unsigned evaluationRound() const { return m_evaluationRound; }
52
53 void evaluateAll();
54
55 bool evaluate(const MediaQuerySet&);
56
57private:
58 explicit MediaQueryMatcher(Document&);
59 std::unique_ptr<RenderStyle> documentElementUserAgentStyle() const;
60 String mediaType() const;
61
62 WeakPtr<Document> m_document;
63 Vector<WeakPtr<MediaQueryList>> m_mediaQueryLists;
64
65 // This value is incremented at style selector changes.
66 // It is used to avoid evaluating queries more then once and to make sure
67 // that a media query result change is notified exactly once.
68 unsigned m_evaluationRound { 1 };
69};
70
71} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.