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

Last change on this file was 294886, checked in by Sam Sneddon, 3 years ago

Remove resolution media feature dpi/dpcm unit warning
https://bugs.webkit.org/show_bug.cgi?id=240907

Reviewed by Simon Fraser.

  • LayoutTests/fast/media/mq-resolution-dpi-dpcm-warning-expected.txt:
  • LayoutTests/fast/media/mq-resolution-expected.txt:
  • LayoutTests/imported/w3c/web-platform-tests/css/mediaqueries/test_media_queries-expected.txt:
  • LayoutTests/platform/gtk/imported/w3c/web-platform-tests/css/mediaqueries/test_media_queries-expected.txt:
  • LayoutTests/platform/wpe/imported/w3c/web-platform-tests/css/mediaqueries/test_media_queries-expected.txt:
  • Source/WebCore/css/CSSStyleSheet.cpp:

(WebCore::CSSStyleSheet::setMediaQueries):

  • Source/WebCore/css/MediaList.cpp:

(WebCore::addResolutionWarningMessageToConsole): Deleted.
(WebCore::reportMediaQueryWarningIfNeeded): Deleted.

  • Source/WebCore/css/MediaList.h:
  • Source/WebCore/css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::matchMedia):

  • Source/WebCore/css/StyleSheetContents.cpp:

(WebCore::StyleSheetContents::parserAppendRule):

Canonical link: https://commits.webkit.org/251014@main

  • Property svn:eol-style set to native
File size: 4.0 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#include "config.h"
21#include "MediaQueryMatcher.h"
22
23#include "Document.h"
24#include "EventNames.h"
25#include "Frame.h"
26#include "FrameView.h"
27#include "Logging.h"
28#include "MediaList.h"
29#include "MediaQueryEvaluator.h"
30#include "MediaQueryList.h"
31#include "MediaQueryListEvent.h"
32#include "MediaQueryParserContext.h"
33#include "NodeRenderStyle.h"
34#include "RenderElement.h"
35#include "StyleResolver.h"
36#include "StyleScope.h"
37#include <wtf/text/TextStream.h>
38
39namespace WebCore {
40
41MediaQueryMatcher::MediaQueryMatcher(Document& document)
42 : m_document(document)
43{
44}
45
46MediaQueryMatcher::~MediaQueryMatcher() = default;
47
48void MediaQueryMatcher::documentDestroyed()
49{
50 m_document = nullptr;
51 auto mediaQueryLists = std::exchange(m_mediaQueryLists, { });
52 for (auto& mediaQueryList : mediaQueryLists) {
53 if (mediaQueryList)
54 mediaQueryList->detachFromMatcher();
55 }
56}
57
58String MediaQueryMatcher::mediaType() const
59{
60 if (!m_document || !m_document->frame() || !m_document->frame()->view())
61 return String();
62
63 return m_document->frame()->view()->mediaType();
64}
65
66std::unique_ptr<RenderStyle> MediaQueryMatcher::documentElementUserAgentStyle() const
67{
68 if (!m_document || !m_document->frame())
69 return nullptr;
70
71 auto* documentElement = m_document->documentElement();
72 if (!documentElement)
73 return nullptr;
74
75 return m_document->styleScope().resolver().styleForElement(*documentElement, { m_document->renderStyle() }, RuleMatchingBehavior::MatchOnlyUserAgentRules).renderStyle;
76}
77
78bool MediaQueryMatcher::evaluate(const MediaQuerySet& media)
79{
80 auto style = documentElementUserAgentStyle();
81 if (!style)
82 return false;
83 return MediaQueryEvaluator { mediaType(), *m_document, style.get() }.evaluate(media);
84}
85
86void MediaQueryMatcher::addMediaQueryList(MediaQueryList& list)
87{
88 ASSERT(!m_mediaQueryLists.contains(&list));
89 m_mediaQueryLists.append(list);
90}
91
92void MediaQueryMatcher::removeMediaQueryList(MediaQueryList& list)
93{
94 m_mediaQueryLists.removeFirst(&list);
95}
96
97RefPtr<MediaQueryList> MediaQueryMatcher::matchMedia(const String& query)
98{
99 if (!m_document)
100 return nullptr;
101
102 auto media = MediaQuerySet::create(query, MediaQueryParserContext(*m_document));
103 bool matches = evaluate(media.get());
104 return MediaQueryList::create(*m_document, *this, WTFMove(media), matches);
105}
106
107void MediaQueryMatcher::evaluateAll()
108{
109 ASSERT(m_document);
110
111 ++m_evaluationRound;
112
113 auto style = documentElementUserAgentStyle();
114 if (!style)
115 return;
116
117 LOG_WITH_STREAM(MediaQueries, stream << "MediaQueryMatcher::styleResolverChanged " << m_document->url());
118
119 MediaQueryEvaluator evaluator { mediaType(), *m_document, style.get() };
120
121 auto mediaQueryLists = m_mediaQueryLists;
122 for (auto& list : mediaQueryLists) {
123 if (!list)
124 continue;
125 bool notify;
126 list->evaluate(evaluator, notify);
127 if (notify) {
128 if (m_document && m_document->quirks().shouldSilenceMediaQueryListChangeEvents())
129 continue;
130
131 list->dispatchEvent(MediaQueryListEvent::create(eventNames().changeEvent, list->media(), list->matches()));
132 }
133 }
134}
135
136} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.