Changeset 201441 in webkit


Ignore:
Timestamp:
May 26, 2016 5:05:24 PM (8 years ago)
Author:
Darin Adler
Message:

Media queries and platform screen modernization and streamlining
https://bugs.webkit.org/show_bug.cgi?id=158067

Reviewed by Alex Christensen.

Source/WebCore:

  • bindings/objc/DOM.mm:

(-[DOMHTMLLinkElement _mediaQueryMatches]): Use references, use fastGetAttribute,
pass a document instead of a frame to the media query evaluator and a reference instead
of a pointer.

  • css/CSSGrammar.y.in: Use "expression" instead of "exp" for media query expressions.

Update vectors and arguments to move media query expressions instead of using unique_ptr.

  • css/CSSImportRule.h: Use pragma once. Removed unneeded forward declarations.

Made more overrides private and marked them final.

  • css/CSSParser.cpp:

(WebCore::CSSParser::SourceSize::SourceSize): Added missing WTFMove to avoid reference
count churn. Changed type of expression to no longer use unique_ptr.
(WebCore::CSSParser::sourceSize): Ditto.

  • css/CSSParser.h: Changed SourceSize::expression to no longer use unique_ptr.

Also changed SourceSize::length to be Ref instead of RefPtr.

  • css/DocumentRuleSets.cpp:

(WebCore::DocumentRuleSets::appendAuthorStyleSheets): Updated for changes to
MediaQueryEvaluator.

  • css/MediaFeatureNames.cpp:

(WebCore::MediaFeatureNames::init): Streamlined a bit. Removed "MediaFeature" suffix from
names of media feature strings.

  • css/MediaFeatureNames.h: Use pragma once. Changed media feature name globals

to use normal WebKit naming style instead of all lowercase with underscores.
Sorted alphabetically. Removed "MediaFeature" suffix from names of media feature strings.

  • css/MediaList.cpp:

(WebCore::MediaQuerySet::MediaQuerySet): Simplified copy constructor since the queries
vector can now be copied normally.
(WebCore::parseMediaDescriptor): Normalized types and changed to use isASCIIAlphanumeric.
The old code was not handling '0' the way the comment said it did.
(WebCore::MediaQuerySet::internalParse): Added. Helper function to cut down on redundant
code in functions below.
(WebCore::MediaQuerySet::parse): Use stripLeadingAndTrailingHTMLSpaces instead of
stripWhiteSpace. Streamlined logic using helper function. Updated to use a vector of
queries instead of a vector of unique_ptr.
(WebCore::MediaQuerySet::add): Use internalParse.
(WebCore::MediaQuerySet::remove): Ditto.
(WebCore::MediaQuerySet::addMediaQuery): Changed argument type to not be unique_ptr.
(WebCore::MediaQuerySet::mediaText): Use modern for loop.
(WebCore::MediaList::MediaList): Initialize pointers to null in the class definition
rather than in these constructors.
(WebCore::MediaList::setMediaText): Removed unhelpful local variable.
(WebCore::MediaList::item): Updated since queries no longer use unique_ptr.
(WebCore::addResolutionWarningMessageToConsole): Changed argument types to references
instead of pointers with assertions.
(WebCore::reportMediaQueryWarningIfNeeded): Updated to modernize.

  • css/MediaList.h: Use pragma once. Removed unneeded includes and forward declarations.

Changed vector to contain media queries instead of unique_ptr. Use nullptr instead of 0.
Initialize pointers to null here.

  • css/MediaQuery.cpp: Deleted now-unneeded copy constructor and destructor. Both are

correctly generated without us writing them explicitly.
(WebCore::MediaQuery::serialize): Rewrote to streamline.
(WebCore::MediaQuery::MediaQuery): Updates since expressions are no longer unique_ptr.
(WebCore::MediaQuery::cssText): Changed return type to reference.

  • css/MediaQuery.h: Use pragma once. Added include since this now includes media query

expressions, not just unique_ptr. Deleted the unneeded copy function.

  • css/MediaQueryEvaluator.cpp:

(WebCore::isViewportDependent): Moved this here. It used to be a member function of
MediaQueryExp, but this file has a lot more functions about specific features and how
they are evaluated, so it really belongs here.
(WebCore::MediaQueryEvaluator::MediaQueryEvaluator): Changed constructor to take a
document instead of a frame. Initialize the fallback result in the class definition.
(WebCore::MediaQueryEvaluator::evaluate): Changed the argument type to a reference.
(WebCore::compareValue): Made both of the arguments separate template types. This
helps us compare an integer to a double without lots of type casts.
(WebCore::compareAspectRatioValue): Changed to use early return style and got rid of
the casts to int so we will do the work in double instead.
(WebCore::doubleValue): Replaced the old numberValue function with this. Since values
are stored as doubles, it's much better to use double rather than float.
(WebCore::zeroEvaluate): Added. Helpful for the many functions that just need to
evaluate as 0.
(WebCore::oneEvaluate): Ditto.
(WebCore::colorEvaluate): Renamed this and all the functions below. Simplified the logic
to use the new doubleValue function.
(WebCore::colorIndexEvaluate): Use zeroEvaluate.
(WebCore::colorGamutEvaluate): No longer use page just to get from the frame to the
main frame.
(WebCore::monochromeEvaluate): Simplify logic using zeroEvaluate.
(WebCore::invertedColorsEvaluate): Use auto for the keyword; easier to read.
(WebCore::orientationEvaluate): Use early return style.
(WebCore::aspectRatioEvaluate): Ditto.
(WebCore::deviceAspectRatioEvaluate): Simplified logic and removed type casts.
(WebCore::evaluateResolution): Added a couple null checks.
(WebCore::devicePixelRatioEvaluate): Renamed. Added missing type check.
(WebCore::resolutionEvaluate): Ditto.
(WebCore::gridEvaluate): Use zeroEvaluate.
(WebCore::computeLength): Added a null check.
(WebCore::deviceHeightEvaluate): Use early return.
(WebCore::deviceWidthEvaluate): Ditto.
(WebCore::heightEvaluate): Ditto.
(WebCore::widthEvaluate): Ditto.
(WebCore::minColorEvaluate): Updated name only.
(WebCore::maxColorEvaluate): Ditto.
(WebCore::minColorIndexEvaluate): Ditto.
(WebCore::maxColorIndexEvaluate): Ditto.
(WebCore::minMonochromeEvaluate): Ditto.
(WebCore::maxMonochromeEvaluate): Ditto.
(WebCore::minAspectRatioEvaluate): Ditto.
(WebCore::maxAspectRatioEvaluate): Ditto.
(WebCore::minDeviceAspectRatioEvaluate): Ditto.
(WebCore::maxDeviceAspectRatioEvaluate): Ditto.
(WebCore::minDevicePixelRatioEvaluate): Ditto.
(WebCore::maxDevicePixelRatioEvaluate): Ditto.
(WebCore::minHeightEvaluate): Ditto.
(WebCore::maxHeightEvaluate): Ditto.
(WebCore::minWidthEvaluate): Ditto.
(WebCore::maxWidthEvaluate): Ditto.
(WebCore::minDeviceHeightEvaluate): Ditto.
(WebCore::maxDeviceHeightEvaluate): Ditto.
(WebCore::minDeviceWidthEvaluate): Ditto.
(WebCore::maxDeviceWidthEvaluate): Ditto.
(WebCore::minResolutionEvaluate): Ditto.
(WebCore::maxResolutionEvaluate): Ditto.
(WebCore::animationEvaluate): Use oneEvaluate.
(WebCore::transitionEvaluate): Ditto.
(WebCore::transform2dEvaluate): Ditto.
(WebCore::transform3dEvaluate): Simplify using zeroEvaluate and oneEvaluate.
(WebCore::viewModeEvaluate): Simplified logic with fewer local variables and the name "keyword".
(WebCore::videoPlayableInlineEvaluate): Use reference.
(WebCore::hoverEvaluate): Simplify using keyword.
(WebCore::anyHoverEvaluate): Just updated name.
(WebCore::pointerEvaluate): Simplify using keyword.
(WebCore::anyPointerEvaluate): Just updated name.
(WebCore::add): Added. Helper for building up the media query function map.
(WebCore::MediaQueryEvaluator::evaluate): Moved code to build the function map in here in
a lambda, rather than having it in a separate global function.

  • css/MediaQueryEvaluator.h: Use pragma once. Removed uneeded includes. Simplified comments and

modernized their style.

  • css/MediaQueryExp.cpp:

(WebCore::isFeatureValidWithIdentifier): Renamed to make it clearer what this does. Updated
to take a reference and use te new feature names.
(WebCore::isFeatureValidWithNonNegativeLengthOrNumber): Ditto.
(WebCore::isFeatureValidWithDensity): Ditto.
(WebCore::isFeatureValidWithNonNegativeInteger): Ditto.
(WebCore::isFeatureValidWithNonNegativeNumber): Ditto.
(WebCore::isFeatureValidWithZeroOrOne): Ditto.
(WebCore::isAspectRatioFeature): Ditto.
(WebCore::isFeatureValidWithoutValue): Ditto.
(WebCore::isFeatureValidWithNumberWithUnit): Added. Helper that calls multiple functions above.
(WebCore::isFeatureValidWithNumber): Ditto.
(WebCore::isSlash): Added. Helper to make aspect ratio code below easier to read.
(WebCore::isPositiveIntegerValue): Ditto.
(WebCore::MediaQueryExpression::MediaQueryExpression): Rearranged code to be much less wordy and
to not use current/next.

  • css/MediaQueryExp.h: Use pragma once. Renamed class to MediaQueryExpression. Removed

the isViewportDependent function, now part of MediaQueryEvaluator. Removed unneeded includes.

  • css/MediaQueryList.cpp:

(WebCore::MediaQueryList::MediaQueryList): Marked this inline. Use a reference and a Ref&&
instead of PassRefPtr.
(WebCore::MediaQueryList::create): Updated argument types.
(WebCore::MediaQueryList::addListener): Updated argument type and use releaseNonNull.
(WebCore::MediaQueryList::removeListener): Updated argument types.
(WebCore::MediaQueryList::evaluate): Ditto.
(WebCore::MediaQueryList::matches): More of the same.

  • css/MediaQueryList.h: Use pragma once. Changed types to use references, RefPtr&& and Ref&&.
  • css/MediaQueryMatcher.cpp:

(WebCore::MediaQueryMatcher::MediaQueryMatcher): Take a reference.
(WebCore::MediaQueryMatcher::documentDestroyed): Use nullptr.
(WebCore::MediaQueryMatcher::documentElementUserAgentStyle): Use auto.
(WebCore::MediaQueryMatcher::evaluate): Take a reference. Updated for changes to MediaQueryEvaluator.
(WebCore::MediaQueryMatcher::matchMedia): Updated for above changes.
(WebCore::MediaQueryMatcher::addListener): Use Ref&& and reference for arguments. Simplify code.
(WebCore::MediaQueryMatcher::removeListener): Ditto.
(WebCore::MediaQueryMatcher::styleResolverChanged): Moved the logic for evaluating each query here.
Updated for changes to MediaQueryEvaluator.

  • css/MediaQueryMatcher.h: Use pragma once. Changed create to take a reference. Tightened argument

types for addListener and removeListener. Made the private Listener a simple struct rather than a
class. Initialized m_evaluationRound.

  • css/RuleSet.cpp:

(WebCore::RuleSet::addChildRules): Updated for changes to MediaQueryEvaluator.
(WebCore::RuleSet::addRulesFromSheet): Ditto.

  • css/SourceSizeList.cpp:

(WebCore::match): Updated to use MediaQueryEvaluator in a simpler way.
(WebCore::defaultLength): Use a reference and simpler syntax.
(WebCore::computeLength): Ditto.
(WebCore::parseSizesAttribute): Changed arguments to take a Document instead of both a
RenderView and a Frame.

  • css/SourceSizeList.h: Use #pragma once. Change parseSizesAttribute to take a Document.
  • css/StyleMedia.cpp:

(WebCore::StyleMedia::matchMedium): Update for changes to MediaQueryEvaluator.

  • css/StyleResolver.cpp:

(WebCore::StyleResolver::StyleResolver): Use a MediaQueryEvaluator instead of a unique_ptr
to one.
(WebCore::StyleResolver::appendAuthorStyleSheets): Ditto.
(WebCore::StyleResolver::styleForElement): Ditto.
(WebCore::StyleResolver::pseudoStyleForElement): Ditto.
(WebCore::StyleResolver::pseudoStyleRulesForElement): Ditto.
(WebCore::StyleResolver::addViewportDependentMediaQueryResult): Use references instead of
ponters, and use a vector of MediaQueryResult instead of unique_ptr.
(WebCore::StyleResolver::hasMediaQueriesAffectedByViewportChange): Use a modern for loop.

  • css/StyleResolver.h: Use a MediaQueryEvaluator instead of a unique_ptr to one.

Use a vector of MediaQueryResult instead of a vector of unique_ptr.

  • dom/Document.cpp:

(WebCore::Document::mediaQueryMatcher): Pass a reference instead of a pointer.

  • dom/InlineStyleSheetOwner.cpp:

(WebCore::InlineStyleSheetOwner::createSheet): Updated for changes to MediaQueryEvaluator.

  • editing/TextIterator.cpp:

(WebCore::SimplifiedBackwardsTextIterator::advance): Removed a stray space (unrelated to
the rest of the patch).

  • html/HTMLImageElement.cpp:

(WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Updated for changes to the
MediaQueryEvaluator class. Also use auto a bit more and eliminated a double hash table
lookup in code that used hasAttribute followed by fastGetAttribute.
(WebCore::HTMLImageElement::selectImageSource): Updated for changes to parseSizesAttribute.

  • html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process): Updated for changes to MediaQueryEvaluator.
(WebCore::HTMLLinkElement::setCSSStyleSheet): Use auto.

  • html/HTMLMediaElement.cpp:

(WebCore::HTMLMediaElement::selectNextSourceChild): Updated for changes to MediaQueryEvaluator.

  • html/HTMLPictureElement.cpp:

(WebCore::HTMLPictureElement::viewportChangeAffectedPicture): Updated for changes to
MediaQueryEvaluator.

  • html/HTMLPictureElement.h: Use #pragma once. Changed viewport dependent media query results

vector to be a vector of results, not of unique_ptr.

  • html/parser/HTMLPreloadScanner.cpp:

(WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): Updated for changes to
parseSizesAttribute.
(WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Updated for changes to
MediaQueryEvaluator.

  • html/parser/HTMLResourcePreloader.cpp:

(WebCore::mediaAttributeMatches): Updated for changes to MediaQueryEvaluator.
(WebCore::HTMLResourcePreloader::preload): Ditto.

  • page/DOMWindow.cpp: Removed unneeded include of PlatformScreen.h.
  • page/mac/EventHandlerMac.mm:

(WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll): Simplified code and
updated for changes to PlatformScreenMac functions.

  • platform/PlatformScreen.h: Use #pragma once. Use using instad of typedef. Put the typedef

for PlatformDisplayID inside the WebCore namespace. Removed the typedef for ColorProfile.
Renamed the functions that find a screen to just "screen".

  • platform/graphics/DisplayRefreshMonitorClient.cpp:

(WebCore::DisplayRefreshMonitorClient::DisplayRefreshMonitorClient): Moved initialization
of booleans to the class definition.

  • platform/graphics/DisplayRefreshMonitorClient.h: Use pragma once. Removed unneeded

forward declarations. Changed display ID data member to be an Optional instead of a boolean
paired with another data member.

  • platform/graphics/GraphicsLayerUpdater.h: Use pragma once. Removed unneeded include of

PlatformScreen.h.

  • platform/image-decoders/ImageDecoder.h: Use pragma once. Moved ColorProfile here from

PlatformScreen.h, since it's not used there. and is used here.

  • platform/mac/PlatformEventFactoryMac.h: Use parma once. Changed reutrn type of the

globalPoint function to NSPoint. Tweaked comments and formatting a bit.

  • platform/mac/PlatformEventFactoryMac.mm:

(WebCore::globalPoint): Changed return type to NSPoint and so removed the explicit
conversion to IntPoint.
(WebCore::globalPointForEvent): Changed return type to NSPoint.
(WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder): Moved conversion to
IntPoint in here. Also got rid of special indenting style and just indented normally.
(WebCore::PlatformWheelEventBuilder::PlatformWheelEventBuilder): Ditto.
(WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder): Ditto.

  • platform/mac/PlatformScreenMac.mm:

(WebCore::displayID): Renamed from displayIDFromScreen and displayFromWidget since this
is C++ and we have overloading to determine the types of arguments. Added a null check
of the how dinwo pointer.
(WebCore::firstScreen): Added. Helper used below.
(WebCore::window): Added. Helper used below.
(WebCore::screen): Renamed from screenForWidget and screenFromWindow and removed the
unneeded window argument from the widget version.
(WebCore::screenDepth): Simplified, using new helpers.
(WebCore::screenDepthPerComponent): Ditto.
(WebCore::screenIsMonochrome): Tweaked comment.
(WebCore::screenHasInvertedColors): Ditto.
(WebCore::screenRect): Simplified using new elpers.
(WebCore::screenAvailableRect): Ditto.
(WebCore::screenSupportsExtendedColor): Streamlined using fewer local variables and
using auto for types of the results of adoptCF.
(WebCore::toUserSpace): Updated for function name changes.
(WebCore::toDeviceSpace): Ditto.

Source/WebKit/mac:

  • WebView/WebFrame.mm:

(-[WebFrame _dragSourceEndedAt:operation:]): Updated to use the new version of
globalPoint, which returns an NSPoint.

Source/WebKit2:

  • Shared/mac/WebEventFactory.mm:

(WebKit::screenForWindow): Deleted.
(WebKit::flipScreenPoint): Deleted.
(WebKit::globalPoint): Deleted.
(WebKit::globalPointForEvent): Use globalPoint function from WebCore so we don't need
copies of everything in here.

  • UIProcess/Cocoa/WebViewImpl.mm:

(WebKit::WebViewImpl::windowDidChangeScreen): Removed unneeded type cast.
(WebKit::WebViewImpl::draggedImage): Added type cast since globalPoint now returns an
NSPoint rather than an IntPoint.

  • UIProcess/WebPageProxy.h: Use pragma once. Add a WebCore prefix to a use of

PlatformDisplayID, since that is now inside the WebCore namespace.

  • WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
  • WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.h: Ditto.
  • WebProcess/WebPage/DrawingArea.h: Ditto.
  • WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h: Ditto.
Location:
trunk/Source
Files:
59 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r201440 r201441  
     12016-05-26  Darin Adler  <darin@apple.com>
     2
     3        Media queries and platform screen modernization and streamlining
     4        https://bugs.webkit.org/show_bug.cgi?id=158067
     5
     6        Reviewed by Alex Christensen.
     7
     8        * bindings/objc/DOM.mm:
     9        (-[DOMHTMLLinkElement _mediaQueryMatches]): Use references, use fastGetAttribute,
     10        pass a document instead of a frame to the media query evaluator and a reference instead
     11        of a pointer.
     12
     13        * css/CSSGrammar.y.in: Use "expression" instead of "exp" for media query expressions.
     14        Update vectors and arguments to move media query expressions instead of using unique_ptr.
     15
     16        * css/CSSImportRule.h: Use pragma once. Removed unneeded forward declarations.
     17        Made more overrides private and marked them final.
     18
     19        * css/CSSParser.cpp:
     20        (WebCore::CSSParser::SourceSize::SourceSize): Added missing WTFMove to avoid reference
     21        count churn. Changed type of expression to no longer use unique_ptr.
     22        (WebCore::CSSParser::sourceSize): Ditto.
     23
     24        * css/CSSParser.h: Changed SourceSize::expression to no longer use unique_ptr.
     25        Also changed SourceSize::length to be Ref instead of RefPtr.
     26
     27        * css/DocumentRuleSets.cpp:
     28        (WebCore::DocumentRuleSets::appendAuthorStyleSheets): Updated for changes to
     29        MediaQueryEvaluator.
     30
     31        * css/MediaFeatureNames.cpp:
     32        (WebCore::MediaFeatureNames::init): Streamlined a bit. Removed "MediaFeature" suffix from
     33        names of media feature strings.
     34
     35        * css/MediaFeatureNames.h: Use pragma once. Changed media feature name globals
     36        to use normal WebKit naming style instead of all lowercase with underscores.
     37        Sorted alphabetically. Removed "MediaFeature" suffix from names of media feature strings.
     38
     39        * css/MediaList.cpp:
     40        (WebCore::MediaQuerySet::MediaQuerySet): Simplified copy constructor since the queries
     41        vector can now be copied normally.
     42        (WebCore::parseMediaDescriptor): Normalized types and changed to use isASCIIAlphanumeric.
     43        The old code was not handling '0' the way the comment said it did.
     44        (WebCore::MediaQuerySet::internalParse): Added. Helper function to cut down on redundant
     45        code in functions below.
     46        (WebCore::MediaQuerySet::parse): Use stripLeadingAndTrailingHTMLSpaces instead of
     47        stripWhiteSpace. Streamlined logic using helper function. Updated to use a vector of
     48        queries instead of a vector of unique_ptr.
     49        (WebCore::MediaQuerySet::add): Use internalParse.
     50        (WebCore::MediaQuerySet::remove): Ditto.
     51        (WebCore::MediaQuerySet::addMediaQuery): Changed argument type to not be unique_ptr.
     52        (WebCore::MediaQuerySet::mediaText): Use modern for loop.
     53        (WebCore::MediaList::MediaList): Initialize pointers to null in the class definition
     54        rather than in these constructors.
     55        (WebCore::MediaList::setMediaText): Removed unhelpful local variable.
     56        (WebCore::MediaList::item): Updated since queries no longer use unique_ptr.
     57        (WebCore::addResolutionWarningMessageToConsole): Changed argument types to references
     58        instead of pointers with assertions.
     59        (WebCore::reportMediaQueryWarningIfNeeded): Updated to modernize.
     60
     61        * css/MediaList.h: Use pragma once. Removed unneeded includes and forward declarations.
     62        Changed vector to contain media queries instead of unique_ptr. Use nullptr instead of 0.
     63        Initialize pointers to null here.
     64
     65        * css/MediaQuery.cpp: Deleted now-unneeded copy constructor and destructor. Both are
     66        correctly generated without us writing them explicitly.
     67        (WebCore::MediaQuery::serialize): Rewrote to streamline.
     68        (WebCore::MediaQuery::MediaQuery): Updates since expressions are no longer unique_ptr.
     69        (WebCore::MediaQuery::cssText): Changed return type to reference.
     70
     71        * css/MediaQuery.h: Use pragma once. Added include since this now includes media query
     72        expressions, not just unique_ptr. Deleted the unneeded copy function.
     73
     74        * css/MediaQueryEvaluator.cpp:
     75        (WebCore::isViewportDependent): Moved this here. It used to be a member function of
     76        MediaQueryExp, but this file has a lot more functions about specific features and how
     77        they are evaluated, so it really belongs here.
     78        (WebCore::MediaQueryEvaluator::MediaQueryEvaluator): Changed constructor to take a
     79        document instead of a frame. Initialize the fallback result in the class definition.
     80        (WebCore::MediaQueryEvaluator::evaluate): Changed the argument type to a reference.
     81        (WebCore::compareValue): Made both of the arguments separate template types. This
     82        helps us compare an integer to a double without lots of type casts.
     83        (WebCore::compareAspectRatioValue): Changed to use early return style and got rid of
     84        the casts to int so we will do the work in double instead.
     85        (WebCore::doubleValue): Replaced the old numberValue function with this. Since values
     86        are stored as doubles, it's much better to use double rather than float.
     87        (WebCore::zeroEvaluate): Added. Helpful for the many functions that just need to
     88        evaluate as 0.
     89        (WebCore::oneEvaluate): Ditto.
     90        (WebCore::colorEvaluate): Renamed this and all the functions below. Simplified the logic
     91        to use the new doubleValue function.
     92        (WebCore::colorIndexEvaluate): Use zeroEvaluate.
     93        (WebCore::colorGamutEvaluate): No longer use page just to get from the frame to the
     94        main frame.
     95        (WebCore::monochromeEvaluate): Simplify logic using zeroEvaluate.
     96        (WebCore::invertedColorsEvaluate): Use auto for the keyword; easier to read.
     97        (WebCore::orientationEvaluate): Use early return style.
     98        (WebCore::aspectRatioEvaluate): Ditto.
     99        (WebCore::deviceAspectRatioEvaluate): Simplified logic and removed type casts.
     100        (WebCore::evaluateResolution): Added a couple null checks.
     101        (WebCore::devicePixelRatioEvaluate): Renamed. Added missing type check.
     102        (WebCore::resolutionEvaluate): Ditto.
     103        (WebCore::gridEvaluate): Use zeroEvaluate.
     104        (WebCore::computeLength): Added a null check.
     105        (WebCore::deviceHeightEvaluate): Use early return.
     106        (WebCore::deviceWidthEvaluate): Ditto.
     107        (WebCore::heightEvaluate): Ditto.
     108        (WebCore::widthEvaluate): Ditto.
     109        (WebCore::minColorEvaluate): Updated name only.
     110        (WebCore::maxColorEvaluate): Ditto.
     111        (WebCore::minColorIndexEvaluate): Ditto.
     112        (WebCore::maxColorIndexEvaluate): Ditto.
     113        (WebCore::minMonochromeEvaluate): Ditto.
     114        (WebCore::maxMonochromeEvaluate): Ditto.
     115        (WebCore::minAspectRatioEvaluate): Ditto.
     116        (WebCore::maxAspectRatioEvaluate): Ditto.
     117        (WebCore::minDeviceAspectRatioEvaluate): Ditto.
     118        (WebCore::maxDeviceAspectRatioEvaluate): Ditto.
     119        (WebCore::minDevicePixelRatioEvaluate): Ditto.
     120        (WebCore::maxDevicePixelRatioEvaluate): Ditto.
     121        (WebCore::minHeightEvaluate): Ditto.
     122        (WebCore::maxHeightEvaluate): Ditto.
     123        (WebCore::minWidthEvaluate): Ditto.
     124        (WebCore::maxWidthEvaluate): Ditto.
     125        (WebCore::minDeviceHeightEvaluate): Ditto.
     126        (WebCore::maxDeviceHeightEvaluate): Ditto.
     127        (WebCore::minDeviceWidthEvaluate): Ditto.
     128        (WebCore::maxDeviceWidthEvaluate): Ditto.
     129        (WebCore::minResolutionEvaluate): Ditto.
     130        (WebCore::maxResolutionEvaluate): Ditto.
     131        (WebCore::animationEvaluate): Use oneEvaluate.
     132        (WebCore::transitionEvaluate): Ditto.
     133        (WebCore::transform2dEvaluate): Ditto.
     134        (WebCore::transform3dEvaluate): Simplify using zeroEvaluate and oneEvaluate.
     135        (WebCore::viewModeEvaluate): Simplified logic with fewer local variables and the name "keyword".
     136        (WebCore::videoPlayableInlineEvaluate): Use reference.
     137        (WebCore::hoverEvaluate): Simplify using keyword.
     138        (WebCore::anyHoverEvaluate): Just updated name.
     139        (WebCore::pointerEvaluate): Simplify using keyword.
     140        (WebCore::anyPointerEvaluate): Just updated name.
     141        (WebCore::add): Added. Helper for building up the media query function map.
     142        (WebCore::MediaQueryEvaluator::evaluate): Moved code to build the function map in here in
     143        a lambda, rather than having it in a separate global function.
     144
     145        * css/MediaQueryEvaluator.h: Use pragma once. Removed uneeded includes. Simplified comments and
     146        modernized their style.
     147
     148        * css/MediaQueryExp.cpp:
     149        (WebCore::isFeatureValidWithIdentifier): Renamed to make it clearer what this does. Updated
     150        to take a reference and use te new feature names.
     151        (WebCore::isFeatureValidWithNonNegativeLengthOrNumber): Ditto.
     152        (WebCore::isFeatureValidWithDensity): Ditto.
     153        (WebCore::isFeatureValidWithNonNegativeInteger): Ditto.
     154        (WebCore::isFeatureValidWithNonNegativeNumber): Ditto.
     155        (WebCore::isFeatureValidWithZeroOrOne): Ditto.
     156        (WebCore::isAspectRatioFeature): Ditto.
     157        (WebCore::isFeatureValidWithoutValue): Ditto.
     158        (WebCore::isFeatureValidWithNumberWithUnit): Added. Helper that calls multiple functions above.
     159        (WebCore::isFeatureValidWithNumber): Ditto.
     160        (WebCore::isSlash): Added. Helper to make aspect ratio code below easier to read.
     161        (WebCore::isPositiveIntegerValue): Ditto.
     162        (WebCore::MediaQueryExpression::MediaQueryExpression): Rearranged code to be much less wordy and
     163        to not use current/next.
     164
     165        * css/MediaQueryExp.h: Use pragma once. Renamed class to MediaQueryExpression. Removed
     166        the isViewportDependent function, now part of MediaQueryEvaluator. Removed unneeded includes.
     167
     168        * css/MediaQueryList.cpp:
     169        (WebCore::MediaQueryList::MediaQueryList): Marked this inline. Use a reference and a Ref&&
     170        instead of PassRefPtr.
     171        (WebCore::MediaQueryList::create): Updated argument types.
     172        (WebCore::MediaQueryList::addListener): Updated argument type and use releaseNonNull.
     173        (WebCore::MediaQueryList::removeListener): Updated argument types.
     174        (WebCore::MediaQueryList::evaluate): Ditto.
     175        (WebCore::MediaQueryList::matches): More of the same.
     176
     177        * css/MediaQueryList.h: Use pragma once. Changed types to use references, RefPtr&& and Ref&&.
     178
     179        * css/MediaQueryMatcher.cpp:
     180        (WebCore::MediaQueryMatcher::MediaQueryMatcher): Take a reference.
     181        (WebCore::MediaQueryMatcher::documentDestroyed): Use nullptr.
     182        (WebCore::MediaQueryMatcher::documentElementUserAgentStyle): Use auto.
     183        (WebCore::MediaQueryMatcher::evaluate): Take a reference. Updated for changes to MediaQueryEvaluator.
     184        (WebCore::MediaQueryMatcher::matchMedia): Updated for above changes.
     185        (WebCore::MediaQueryMatcher::addListener): Use Ref&& and reference for arguments. Simplify code.
     186        (WebCore::MediaQueryMatcher::removeListener): Ditto.
     187        (WebCore::MediaQueryMatcher::styleResolverChanged): Moved the logic for evaluating each query here.
     188        Updated for changes to MediaQueryEvaluator.
     189
     190        * css/MediaQueryMatcher.h: Use pragma once. Changed create to take a reference. Tightened argument
     191        types for addListener and removeListener. Made the private Listener a simple struct rather than a
     192        class. Initialized m_evaluationRound.
     193
     194        * css/RuleSet.cpp:
     195        (WebCore::RuleSet::addChildRules): Updated for changes to MediaQueryEvaluator.
     196        (WebCore::RuleSet::addRulesFromSheet): Ditto.
     197
     198        * css/SourceSizeList.cpp:
     199        (WebCore::match): Updated to use MediaQueryEvaluator in a simpler way.
     200        (WebCore::defaultLength): Use a reference and simpler syntax.
     201        (WebCore::computeLength): Ditto.
     202        (WebCore::parseSizesAttribute): Changed arguments to take a Document instead of both a
     203        RenderView and a Frame.
     204
     205        * css/SourceSizeList.h: Use #pragma once. Change parseSizesAttribute to take a Document.
     206
     207        * css/StyleMedia.cpp:
     208        (WebCore::StyleMedia::matchMedium): Update for changes to MediaQueryEvaluator.
     209
     210        * css/StyleResolver.cpp:
     211        (WebCore::StyleResolver::StyleResolver): Use a MediaQueryEvaluator instead of a unique_ptr
     212        to one.
     213        (WebCore::StyleResolver::appendAuthorStyleSheets): Ditto.
     214        (WebCore::StyleResolver::styleForElement): Ditto.
     215        (WebCore::StyleResolver::pseudoStyleForElement): Ditto.
     216        (WebCore::StyleResolver::pseudoStyleRulesForElement): Ditto.
     217        (WebCore::StyleResolver::addViewportDependentMediaQueryResult): Use references instead of
     218        ponters, and use a vector of MediaQueryResult instead of unique_ptr.
     219        (WebCore::StyleResolver::hasMediaQueriesAffectedByViewportChange): Use a modern for loop.
     220
     221        * css/StyleResolver.h: Use a MediaQueryEvaluator instead of a unique_ptr to one.
     222        Use a vector of MediaQueryResult instead of a vector of unique_ptr.
     223
     224        * dom/Document.cpp:
     225        (WebCore::Document::mediaQueryMatcher): Pass a reference instead of a pointer.
     226
     227        * dom/InlineStyleSheetOwner.cpp:
     228        (WebCore::InlineStyleSheetOwner::createSheet): Updated for changes to MediaQueryEvaluator.
     229
     230        * editing/TextIterator.cpp:
     231        (WebCore::SimplifiedBackwardsTextIterator::advance): Removed a stray space (unrelated to
     232        the rest of the patch).
     233
     234        * html/HTMLImageElement.cpp:
     235        (WebCore::HTMLImageElement::bestFitSourceFromPictureElement): Updated for changes to the
     236        MediaQueryEvaluator class. Also use auto a bit more and eliminated a double hash table
     237        lookup in code that used hasAttribute followed by fastGetAttribute.
     238        (WebCore::HTMLImageElement::selectImageSource): Updated for changes to parseSizesAttribute.
     239
     240        * html/HTMLLinkElement.cpp:
     241        (WebCore::HTMLLinkElement::process): Updated for changes to MediaQueryEvaluator.
     242        (WebCore::HTMLLinkElement::setCSSStyleSheet): Use auto.
     243
     244        * html/HTMLMediaElement.cpp:
     245        (WebCore::HTMLMediaElement::selectNextSourceChild): Updated for changes to MediaQueryEvaluator.
     246
     247        * html/HTMLPictureElement.cpp:
     248        (WebCore::HTMLPictureElement::viewportChangeAffectedPicture): Updated for changes to
     249        MediaQueryEvaluator.
     250
     251        * html/HTMLPictureElement.h: Use #pragma once. Changed viewport dependent media query results
     252        vector to be a vector of results, not of unique_ptr.
     253
     254        * html/parser/HTMLPreloadScanner.cpp:
     255        (WebCore::TokenPreloadScanner::StartTagScanner::processAttributes): Updated for changes to
     256        parseSizesAttribute.
     257        (WebCore::TokenPreloadScanner::StartTagScanner::processAttribute): Updated for changes to
     258        MediaQueryEvaluator.
     259
     260        * html/parser/HTMLResourcePreloader.cpp:
     261        (WebCore::mediaAttributeMatches): Updated for changes to MediaQueryEvaluator.
     262        (WebCore::HTMLResourcePreloader::preload): Ditto.
     263
     264        * page/DOMWindow.cpp: Removed unneeded include of PlatformScreen.h.
     265
     266        * page/mac/EventHandlerMac.mm:
     267        (WebCore::EventHandler::effectiveMousePositionForSelectionAutoscroll): Simplified code and
     268        updated for changes to PlatformScreenMac functions.
     269
     270        * platform/PlatformScreen.h: Use #pragma once. Use using instad of typedef. Put the typedef
     271        for PlatformDisplayID inside the WebCore namespace. Removed the typedef for ColorProfile.
     272        Renamed the functions that find a screen to just "screen".
     273
     274        * platform/graphics/DisplayRefreshMonitorClient.cpp:
     275        (WebCore::DisplayRefreshMonitorClient::DisplayRefreshMonitorClient): Moved initialization
     276        of booleans to the class definition.
     277
     278        * platform/graphics/DisplayRefreshMonitorClient.h: Use pragma once. Removed unneeded
     279        forward declarations. Changed display ID data member to be an Optional instead of a boolean
     280        paired with another data member.
     281
     282        * platform/graphics/GraphicsLayerUpdater.h: Use pragma once. Removed unneeded include of
     283        PlatformScreen.h.
     284
     285        * platform/image-decoders/ImageDecoder.h: Use pragma once. Moved ColorProfile here from
     286        PlatformScreen.h, since it's not used there. and is used here.
     287
     288        * platform/mac/PlatformEventFactoryMac.h: Use parma once. Changed reutrn type of the
     289        globalPoint function to NSPoint. Tweaked comments and formatting a bit.
     290
     291        * platform/mac/PlatformEventFactoryMac.mm:
     292        (WebCore::globalPoint): Changed return type to NSPoint and so removed the explicit
     293        conversion to IntPoint.
     294        (WebCore::globalPointForEvent): Changed return type to NSPoint.
     295        (WebCore::PlatformMouseEventBuilder::PlatformMouseEventBuilder): Moved conversion to
     296        IntPoint in here. Also got rid of special indenting style and just indented normally.
     297        (WebCore::PlatformWheelEventBuilder::PlatformWheelEventBuilder): Ditto.
     298        (WebCore::PlatformKeyboardEventBuilder::PlatformKeyboardEventBuilder): Ditto.
     299
     300        * platform/mac/PlatformScreenMac.mm:
     301        (WebCore::displayID): Renamed from displayIDFromScreen and displayFromWidget since this
     302        is C++ and we have overloading to determine the types of arguments. Added a null check
     303        of the how dinwo pointer.
     304        (WebCore::firstScreen): Added. Helper used below.
     305        (WebCore::window): Added. Helper used below.
     306        (WebCore::screen): Renamed from screenForWidget and screenFromWindow and removed the
     307        unneeded window argument from the widget version.
     308        (WebCore::screenDepth): Simplified, using new helpers.
     309        (WebCore::screenDepthPerComponent): Ditto.
     310        (WebCore::screenIsMonochrome): Tweaked comment.
     311        (WebCore::screenHasInvertedColors): Ditto.
     312        (WebCore::screenRect): Simplified using new elpers.
     313        (WebCore::screenAvailableRect): Ditto.
     314        (WebCore::screenSupportsExtendedColor): Streamlined using fewer local variables and
     315        using auto for types of the results of adoptCF.
     316        (WebCore::toUserSpace): Updated for function name changes.
     317        (WebCore::toDeviceSpace): Ditto.
     318
    13192016-05-26  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    2320
  • trunk/Source/WebCore/bindings/objc/DOM.mm

    r200563 r201441  
    763763
    764764#if PLATFORM(IOS)
     765
    765766@implementation DOMHTMLLinkElement (WebPrivate)
     767
    766768- (BOOL)_mediaQueryMatchesForOrientation:(int)orientation
    767769{
     
    791793- (BOOL)_mediaQueryMatches
    792794{
    793     HTMLLinkElement* link = static_cast<HTMLLinkElement*>(core(self));
    794     String media = link->getAttribute(HTMLNames::mediaAttr);
     795    HTMLLinkElement& link = *static_cast<HTMLLinkElement*>(core(self));
     796
     797    auto& media = link.fastGetAttribute(HTMLNames::mediaAttr);
    795798    if (media.isEmpty())
    796799        return true;
    797     Document& document = link->document();
    798 
    799     RefPtr<MediaQuerySet> mediaQuerySet = MediaQuerySet::createAllowingDescriptionSyntax(media);
    800     MediaQueryEvaluator screenEval("screen", document.frame(), document.renderView() ? &document.renderView()->style() : 0);
    801 
    802     return screenEval.eval(mediaQuerySet.get());
    803 }
    804 @end
     800
     801    Document& document = link.document();
     802    auto mediaQuerySet = MediaQuerySet::createAllowingDescriptionSyntax(media);
     803    return MediaQueryEvaluator { "screen", document, document.renderView() ? &document.renderView()->style() : nullptr }.evaluate(mediaQuerySet.get());
     804}
     805
     806@end
     807
    805808#endif
    806809
  • trunk/Source/WebCore/css/CSSGrammar.y.in

    r201290 r201441  
    3838    MediaQuery* mediaQuery;
    3939    MediaQuery::Restrictor mediaQueryRestrictor;
    40     MediaQueryExp* mediaQueryExp;
     40    MediaQueryExpression* mediaQueryExpression;
    4141    Vector<CSSParser::SourceSize>* sourceSizeList;
    42     Vector<std::unique_ptr<MediaQueryExp>>* mediaQueryExpList;
     42    Vector<MediaQueryExpression>* mediaQueryExpressionList;
    4343    StyleKeyframe* keyframe;
    4444    Vector<RefPtr<StyleKeyframe>>* keyframeRuleList;
     
    272272%type <mediaQueryRestrictor> maybe_media_restrictor
    273273
    274 %type <mediaQueryExp> media_query_exp base_media_query_exp
    275 %destructor { delete $$; } media_query_exp base_media_query_exp
     274%type <mediaQueryExpression> media_query_expression base_media_query_expression
     275%destructor { delete $$; } media_query_expression base_media_query_expression
    276276
    277277%type <sourceSizeList> source_size_list
    278278%destructor { delete $$; } source_size_list
    279279
    280 %type <mediaQueryExp> maybe_source_media_query_exp
    281 %destructor { delete $$; } maybe_source_media_query_exp
     280%type <mediaQueryExpression> maybe_source_media_query_expression
     281%destructor { delete $$; } maybe_source_media_query_expression
    282282
    283283%type <value> source_size_length
    284284%destructor { destroy($$); } source_size_length
    285285
    286 %type <mediaQueryExpList> media_query_exp_list maybe_and_media_query_exp_list
    287 %destructor { delete $$; } media_query_exp_list maybe_and_media_query_exp_list
     286%type <mediaQueryExpressionList> media_query_expression_list maybe_and_media_query_expression_list
     287%destructor { delete $$; } media_query_expression_list maybe_and_media_query_expression_list
    288288
    289289%type <string> keyframe_name
     
    577577
    578578source_size_list:
    579     maybe_source_media_query_exp source_size_length {
     579    maybe_source_media_query_expression source_size_length {
    580580        $$ = new Vector<CSSParser::SourceSize>;
    581         $$->append(parser->sourceSize(std::unique_ptr<MediaQueryExp>($1), $2));
    582     }
    583     | source_size_list maybe_space ',' maybe_space maybe_source_media_query_exp source_size_length {
     581        $$->append(parser->sourceSize(WTFMove(*$1), $2));
     582        delete $1;
     583    }
     584    | source_size_list maybe_space ',' maybe_space maybe_source_media_query_expression source_size_length {
    584585        $$ = $1;
    585         $$->append(parser->sourceSize(std::unique_ptr<MediaQueryExp>($5), $6));
    586     }
    587     ;
    588 
    589 maybe_source_media_query_exp:
     586        $$->append(parser->sourceSize(WTFMove(*$5), $6));
     587        delete $5;
     588    }
     589    ;
     590
     591maybe_source_media_query_expression:
    590592    /* empty */ {
    591         $$ = new MediaQueryExp;
    592     }
    593     | base_media_query_exp maybe_space;
     593        $$ = new MediaQueryExpression;
     594    }
     595    | base_media_query_expression maybe_space;
    594596
    595597source_size_length: unary_term | calc_function;
    596598
    597 base_media_query_exp: '(' maybe_space IDENT maybe_space maybe_media_value ')' {
     599base_media_query_expression: '(' maybe_space IDENT maybe_space maybe_media_value ')' {
    598600        std::unique_ptr<CSSParserValueList> mediaValue($5);
    599601        $3.convertToASCIILowercaseInPlace();
    600         $$ = new MediaQueryExp($3, mediaValue.get());
    601     }
    602     ;
    603 
    604 media_query_exp:
    605     maybe_media_restrictor maybe_space base_media_query_exp maybe_space {
     602        $$ = new MediaQueryExpression($3, mediaValue.get());
     603    }
     604    ;
     605
     606media_query_expression:
     607    maybe_media_restrictor maybe_space base_media_query_expression maybe_space {
    606608        if ($1 != MediaQuery::None) {
    607609            // If restrictor is specified, media query expression is invalid.
    608610            // Create empty media query expression and continue parsing media query.
    609611            delete $3;
    610             $$ = new MediaQueryExp;
     612            $$ = new MediaQueryExpression;
    611613        } else
    612614            $$ = $3;
     
    614616    ;
    615617
    616 media_query_exp_list:
    617     media_query_exp {
    618         $$ = new Vector<std::unique_ptr<MediaQueryExp>>;
    619         $$->append(std::unique_ptr<MediaQueryExp>($1));
    620     }
    621     | media_query_exp_list maybe_space MEDIA_AND maybe_space media_query_exp {
     618media_query_expression_list:
     619    media_query_expression {
     620        $$ = new Vector<MediaQueryExpression>;
     621        $$->append(WTFMove(*$1));
     622        delete $1;
     623    }
     624    | media_query_expression_list maybe_space MEDIA_AND maybe_space media_query_expression {
    622625        $$ = $1;
    623         $$->append(std::unique_ptr<MediaQueryExp>($5));
    624     }
    625     ;
    626 
    627 maybe_and_media_query_exp_list:
     626        $$->append(WTFMove(*$5));
     627        delete $5;
     628    }
     629    ;
     630
     631maybe_and_media_query_expression_list:
    628632    /*empty*/ {
    629         $$ = new Vector<std::unique_ptr<MediaQueryExp>>;
    630     }
    631     | MEDIA_AND maybe_space media_query_exp_list {
     633        $$ = new Vector<MediaQueryExpression>;
     634    }
     635    | MEDIA_AND maybe_space media_query_expression_list {
    632636        $$ = $3;
    633637    }
     
    647651
    648652media_query:
    649     media_query_exp_list {
    650         $$ = new MediaQuery(MediaQuery::None, "all", std::unique_ptr<Vector<std::unique_ptr<MediaQueryExp>>>($1));
     653    media_query_expression_list {
     654        $$ = new MediaQuery(MediaQuery::None, "all", WTFMove(*$1));
     655        delete $1;
    651656    }
    652657    |
    653     maybe_media_restrictor maybe_space IDENT maybe_space maybe_and_media_query_exp_list {
     658    maybe_media_restrictor maybe_space IDENT maybe_space maybe_and_media_query_expression_list {
    654659        $3.convertToASCIILowercaseInPlace();
    655         $$ = new MediaQuery($1, $3, std::unique_ptr<Vector<std::unique_ptr<MediaQueryExp>>>($5));
     660        $$ = new MediaQuery($1, $3, WTFMove(*$5));
     661        delete $5;
    656662    }
    657663    ;
     
    662668    media_query {
    663669        $$ = &MediaQuerySet::create().leakRef();
    664         $$->addMediaQuery(std::unique_ptr<MediaQuery>($1));
     670        $$->addMediaQuery(WTFMove(*$1));
     671        delete $1;
    665672        parser->updateLastMediaLine(*$$);
    666673    }
    667674    | media_list ',' maybe_space media_query {
    668675        $$ = $1;
    669         std::unique_ptr<MediaQuery> mediaQuery($4);
    670676        if ($$) {
    671             $$->addMediaQuery(WTFMove(mediaQuery));
     677            $$->addMediaQuery(WTFMove(*$4));
    672678            parser->updateLastMediaLine(*$$);
    673679        }
     680        delete $4;
    674681    }
    675682    | media_list error {
  • trunk/Source/WebCore/css/CSSImportRule.h

    r197563 r201441  
    2020 */
    2121
    22 #ifndef CSSImportRule_h
    23 #define CSSImportRule_h
     22#pragma once
    2423
    2524#include "CSSRule.h"
     
    2726namespace WebCore {
    2827
    29 class CachedCSSStyleSheet;
    3028class MediaList;
    31 class MediaQuerySet;
    3229class StyleRuleImport;
    3330
     
    3532public:
    3633    static Ref<CSSImportRule> create(StyleRuleImport& rule, CSSStyleSheet* sheet) { return adoptRef(*new CSSImportRule(rule, sheet)); }
    37    
     34
    3835    virtual ~CSSImportRule();
    39 
    40     String cssText() const override;
    41     void reattach(StyleRuleBase&) override;
    4236
    4337    String href() const;
     
    4842    CSSImportRule(StyleRuleImport&, CSSStyleSheet*);
    4943
    50     CSSRule::Type type() const override { return IMPORT_RULE; }
     44    CSSRule::Type type() const final { return IMPORT_RULE; }
     45    String cssText() const final;
     46    void reattach(StyleRuleBase&) final;
    5147
    5248    Ref<StyleRuleImport> m_importRule;
     
    5854
    5955SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSImportRule, CSSRule::IMPORT_RULE)
    60 
    61 #endif // CSSImportRule_h
  • trunk/Source/WebCore/css/CSSParser.cpp

    r201399 r201441  
    15301530// FIXME(141289): The following two constructors are only needed because of a bug in MSVC 2013 (and prior).
    15311531// We should remove this code as soon as a Visual Studio update that fixes this problem is released.
     1532
    15321533CSSParser::SourceSize::SourceSize(CSSParser::SourceSize&& original)
    15331534    : expression(WTFMove(original.expression))
    1534     , length(original.length)
    1535 {
    1536 }
    1537 
    1538 CSSParser::SourceSize::SourceSize(std::unique_ptr<MediaQueryExp>&& origExp, RefPtr<CSSValue>&& value)
    1539     : expression(WTFMove(origExp))
     1535    , length(WTFMove(original.length))
     1536{
     1537}
     1538
     1539CSSParser::SourceSize::SourceSize(MediaQueryExpression&& expression, Ref<CSSValue>&& value)
     1540    : expression(WTFMove(expression))
    15401541    , length(WTFMove(value))
    15411542{
    15421543}
    15431544
    1544 CSSParser::SourceSize CSSParser::sourceSize(std::unique_ptr<MediaQueryExp>&& expression, CSSParserValue& parserValue)
     1545CSSParser::SourceSize CSSParser::sourceSize(MediaQueryExpression&& expression, CSSParserValue& parserValue)
    15451546{
    15461547    RefPtr<CSSValue> value;
     
    15551556    // FIXME: Calling the constructor explicitly here to work around an MSVC bug.
    15561557    // For other compilers, we did not need to define the constructors and we could use aggregate initialization syntax.
    1557     return SourceSize(WTFMove(expression), WTFMove(value));
     1558    return SourceSize(WTFMove(expression), value.releaseNonNull());
    15581559}
    15591560
  • trunk/Source/WebCore/css/CSSParser.h

    r201382 r201441  
    6767class Element;
    6868class ImmutableStyleProperties;
    69 class MediaQueryExp;
     69class MediaQueryExpression;
    7070class MediaQuerySet;
    7171class MutableStyleProperties;
     
    169169
    170170    struct SourceSize {
    171         std::unique_ptr<MediaQueryExp> expression;
    172         RefPtr<CSSValue> length;
     171        MediaQueryExpression expression;
     172        Ref<CSSValue> length;
    173173
    174174        SourceSize(SourceSize&&);
    175         SourceSize(std::unique_ptr<MediaQueryExp>&&, RefPtr<CSSValue>&&);
     175        SourceSize(MediaQueryExpression&&, Ref<CSSValue>&&);
    176176    };
    177177    Vector<SourceSize> parseSizesAttribute(StringView);
    178     SourceSize sourceSize(std::unique_ptr<MediaQueryExp>&&, CSSParserValue&);
     178    SourceSize sourceSize(MediaQueryExpression&&, CSSParserValue&);
    179179
    180180    bool parseFillImage(CSSParserValueList&, RefPtr<CSSValue>&);
  • trunk/Source/WebCore/css/CSSStyleSheet.cpp

    r201318 r201441  
    228228    if (m_mediaCSSOMWrapper && m_mediaQueries)
    229229        m_mediaCSSOMWrapper->reattach(m_mediaQueries.get());
    230 
    231 #if ENABLE(RESOLUTION_MEDIA_QUERY)
    232     // Add warning message to inspector whenever dpi/dpcm values are used for "screen" media.
    233230    reportMediaQueryWarningIfNeeded(ownerDocument(), m_mediaQueries.get());
    234 #endif
    235231}
    236232
  • trunk/Source/WebCore/css/DocumentRuleSets.cpp

    r196629 r201441  
    8989    for (auto& cssSheet : styleSheets) {
    9090        ASSERT(!cssSheet->disabled());
    91         if (cssSheet->mediaQueries() && !medium->eval(cssSheet->mediaQueries(), resolver))
     91        if (cssSheet->mediaQueries() && !medium->evaluate(*cssSheet->mediaQueries(), resolver))
    9292            continue;
    9393        m_authorStyle->addRulesFromSheet(cssSheet->contents(), *medium, resolver);
  • trunk/Source/WebCore/css/MediaFeatureNames.cpp

    r165676 r201441  
    3131namespace MediaFeatureNames {
    3232
    33 #define DEFINE_MEDIAFEATURE_GLOBAL(name, str) \
    34     DEFINE_GLOBAL(AtomicString, name##MediaFeature, str)
     33#define DEFINE_MEDIAFEATURE_GLOBAL(name, string) DEFINE_GLOBAL(AtomicString, name)
    3534CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(DEFINE_MEDIAFEATURE_GLOBAL)
    3635#undef DEFINE_MEDIAFEATURE_GLOBAL
     
    4039    static bool initialized;
    4140    if (!initialized) {
    42        // Use placement new to initialize the globals.
    43 
     41        // Use placement new to initialize the globals.
    4442        AtomicString::init();
    45 #define INITIALIZE_GLOBAL(name, str) new (NotNull, (void*)&name##MediaFeature) AtomicString(str, AtomicString::ConstructFromLiteral);
     43#define INITIALIZE_GLOBAL(name, string) new (NotNull, (void*)&name) AtomicString(string, AtomicString::ConstructFromLiteral);
    4644        CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(INITIALIZE_GLOBAL)
    4745#undef INITIALIZE_GLOBAL
  • trunk/Source/WebCore/css/MediaFeatureNames.h

    r199024 r201441  
    1818 *
    1919 */
    20 #ifndef MediaFeatureNames_h
    21 #define MediaFeatureNames_h
     20
     21#pragma once
    2222
    2323#include <wtf/text/AtomicString.h>
    2424
    25 namespace WebCore {
    26     namespace MediaFeatureNames {
    27 
    2825#if ENABLE(VIEW_MODE_CSS_MEDIA)
    29 #define CSS_MEDIAQUERY_VIEW_MODE(macro) macro(view_mode, "-webkit-view-mode")
     26#define CSS_MEDIAQUERY_VIEW_MODE(macro) macro(viewMode, "-webkit-view-mode")
    3027#else
    3128#define CSS_MEDIAQUERY_VIEW_MODE(macro)
     
    3330
    3431#define CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(macro) \
    35     macro(any_hover, "any-hover") \
    36     macro(any_pointer, "any-pointer") \
     32    macro(animation, "-webkit-animation") \
     33    macro(anyHover, "any-hover") \
     34    macro(anyPointer, "any-pointer") \
     35    macro(aspectRatio, "aspect-ratio") \
    3736    macro(color, "color") \
    38     macro(color_index, "color-index") \
    39     macro(color_gamut, "color-gamut") \
     37    macro(colorGamut, "color-gamut") \
     38    macro(colorIndex, "color-index") \
     39    macro(deviceAspectRatio, "device-aspect-ratio") \
     40    macro(deviceHeight, "device-height") \
     41    macro(devicePixelRatio, "-webkit-device-pixel-ratio") \
     42    macro(deviceWidth, "device-width") \
    4043    macro(grid, "grid") \
    41     macro(monochrome, "monochrome") \
    4244    macro(height, "height") \
    4345    macro(hover, "hover") \
    44     macro(width, "width") \
     46    macro(invertedColors, "inverted-colors") \
     47    macro(maxAspectRatio, "max-aspect-ratio") \
     48    macro(maxColor, "max-color") \
     49    macro(maxColorIndex, "max-color-index") \
     50    macro(maxDeviceAspectRatio, "max-device-aspect-ratio") \
     51    macro(maxDeviceHeight, "max-device-height") \
     52    macro(maxDevicePixelRatio, "-webkit-max-device-pixel-ratio") \
     53    macro(maxDeviceWidth, "max-device-width") \
     54    macro(maxHeight, "max-height") \
     55    macro(maxMonochrome, "max-monochrome") \
     56    macro(maxResolution, "max-resolution") \
     57    macro(maxWidth, "max-width") \
     58    macro(minAspectRatio, "min-aspect-ratio") \
     59    macro(minColor, "min-color") \
     60    macro(minColorIndex, "min-color-index") \
     61    macro(minDeviceAspectRatio, "min-device-aspect-ratio") \
     62    macro(minDeviceHeight, "min-device-height") \
     63    macro(minDevicePixelRatio, "-webkit-min-device-pixel-ratio") \
     64    macro(minDeviceWidth, "min-device-width") \
     65    macro(minHeight, "min-height") \
     66    macro(minMonochrome, "min-monochrome") \
     67    macro(minResolution, "min-resolution") \
     68    macro(minWidth, "min-width") \
     69    macro(monochrome, "monochrome") \
    4570    macro(orientation, "orientation") \
    46     macro(aspect_ratio, "aspect-ratio") \
    47     macro(device_aspect_ratio, "device-aspect-ratio") \
    48     macro(device_pixel_ratio, "-webkit-device-pixel-ratio") \
    49     macro(device_height, "device-height") \
    50     macro(device_width, "device-width") \
    51     macro(inverted_colors, "inverted-colors") \
    52     macro(max_color, "max-color") \
    53     macro(max_color_index, "max-color-index") \
    54     macro(max_aspect_ratio, "max-aspect-ratio") \
    55     macro(max_device_aspect_ratio, "max-device-aspect-ratio") \
    56     macro(max_device_pixel_ratio, "-webkit-max-device-pixel-ratio") \
    57     macro(max_device_height, "max-device-height") \
    58     macro(max_device_width, "max-device-width") \
    59     macro(max_height, "max-height") \
    60     macro(max_monochrome, "max-monochrome") \
    61     macro(max_width, "max-width") \
    62     macro(max_resolution, "max-resolution") \
    63     macro(min_color, "min-color") \
    64     macro(min_color_index, "min-color-index") \
    65     macro(min_aspect_ratio, "min-aspect-ratio") \
    66     macro(min_device_aspect_ratio, "min-device-aspect-ratio") \
    67     macro(min_device_pixel_ratio, "-webkit-min-device-pixel-ratio") \
    68     macro(min_device_height, "min-device-height") \
    69     macro(min_device_width, "min-device-width") \
    70     macro(min_height, "min-height") \
    71     macro(min_monochrome, "min-monochrome") \
    72     macro(min_width, "min-width") \
    73     macro(min_resolution, "min-resolution") \
    7471    macro(pointer, "pointer") \
    7572    macro(resolution, "resolution") \
    76     macro(transform_2d, "-webkit-transform-2d") \
    77     macro(transform_3d, "-webkit-transform-3d") \
     73    macro(transform2d, "-webkit-transform-2d") \
     74    macro(transform3d, "-webkit-transform-3d") \
    7875    macro(transition, "-webkit-transition") \
    79     macro(animation, "-webkit-animation") \
    80     macro(video_playable_inline, "-webkit-video-playable-inline") \
     76    macro(videoPlayableInline, "-webkit-video-playable-inline") \
     77    macro(width, "width") \
    8178    CSS_MEDIAQUERY_VIEW_MODE(macro)
    8279
    8380// end of macro
    8481
     82namespace WebCore {
     83namespace MediaFeatureNames {
     84
    8585#ifndef CSS_MEDIAQUERY_NAMES_HIDE_GLOBALS
    86     #define CSS_MEDIAQUERY_NAMES_DECLARE(name, str) extern const AtomicString name##MediaFeature;
     86#define CSS_MEDIAQUERY_NAMES_DECLARE(name, string) extern const AtomicString name;
    8787    CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(CSS_MEDIAQUERY_NAMES_DECLARE)
    88     #undef CSS_MEDIAQUERY_NAMES_DECLARE
     88#undef CSS_MEDIAQUERY_NAMES_DECLARE
    8989#endif
    9090
    91         void init();
     91    void init();
    9292
    93     } // namespace MediaFeatureNames
     93} // namespace MediaFeatureNames
    9494} // namespace WebCore
    95 
    96 #endif // MediaFeatureNames_h
  • trunk/Source/WebCore/css/MediaList.cpp

    r201333 r201441  
    1818 * Boston, MA 02110-1301, USA.
    1919 */
     20
    2021#include "config.h"
    2122#include "MediaList.h"
     
    2728#include "Document.h"
    2829#include "ExceptionCode.h"
     30#include "HTMLParserIdioms.h"
    2931#include "MediaFeatureNames.h"
    3032#include "MediaQuery.h"
    31 #include "MediaQueryExp.h"
    3233#include "ScriptableDocumentParser.h"
    3334#include <wtf/NeverDestroyed.h>
     
    7576{
    7677    bool success = parse(mediaString);
     78
    7779    // FIXME: parsing can fail. The problem with failing constructor is that
    7880    // we would need additional flag saying MediaList is not valid
     
    8082    // forward-compatible syntax is not in use.
    8183    // DOMImplementationCSS seems to mandate that media descriptors are used
    82     // for both html and svg, even though svg:style doesn't use media descriptors
     84    // for both HTML and SVG, even though svg:style doesn't use media descriptors
    8385    // Currently the only places where parsing can fail are
    8486    // creating <svg:style>, creating css media / import rules from js
    85    
     87
    8688    // FIXME: This doesn't make much sense.
    8789    if (!success)
     
    9092
    9193MediaQuerySet::MediaQuerySet(const MediaQuerySet& o)
    92     : RefCounted<MediaQuerySet>()
     94    : RefCounted()
    9395    , m_fallbackToDescriptor(o.m_fallbackToDescriptor)
    9496    , m_lastLine(o.m_lastLine)
    95     , m_queries(o.m_queries.size())
    96 {
    97     for (unsigned i = 0; i < m_queries.size(); ++i)
    98         m_queries[i] = o.m_queries[i]->copy();
     97    , m_queries(o.m_queries)
     98{
    9999}
    100100
     
    110110    // or hyphen (hex 2d)."
    111111    unsigned length = string.length();
    112     unsigned i = 0;
    113     for (; i < length; ++i) {
    114         unsigned short c = string[i];
    115         if (! ((c >= 'a' && c <= 'z')
    116                || (c >= 'A' && c <= 'Z')
    117                || (c >= '1' && c <= '9')
    118                || (c == '-')))
     112    unsigned i;
     113    for (i = 0; i < length; ++i) {
     114        auto character = string[i];
     115        if (!(isASCIIAlphanumeric(character) || character == '-'))
    119116            break;
    120117    }
    121118    return string.left(i);
     119}
     120
     121Optional<MediaQuery> MediaQuerySet::internalParse(CSSParser& parser, const String& queryString)
     122{
     123    if (auto query = parser.parseMediaQuery(queryString))
     124        return WTFMove(*query);
     125    if (!m_fallbackToDescriptor)
     126        return Nullopt;
     127    return MediaQuery { MediaQuery::None, parseMediaDescriptor(queryString), Vector<MediaQueryExpression> { } };
     128}
     129
     130Optional<MediaQuery> MediaQuerySet::internalParse(const String& queryString)
     131{
     132    CSSParser parser(CSSStrictMode);
     133    return internalParse(parser, queryString);
    122134}
    123135
     
    126138    CSSParser parser(CSSStrictMode);
    127139   
    128     Vector<std::unique_ptr<MediaQuery>> result;
     140    Vector<MediaQuery> result;
    129141    Vector<String> list;
    130142    mediaString.split(',', list);
    131     for (unsigned i = 0; i < list.size(); ++i) {
    132         String medium = list[i].stripWhiteSpace();
     143    for (auto& listString : list) {
     144        String medium = stripLeadingAndTrailingHTMLSpaces(listString);
    133145        if (medium.isEmpty()) {
    134             if (!m_fallbackToDescriptor)
    135                 return false;
     146            if (m_fallbackToDescriptor)
     147                continue;
     148        } else if (auto query = internalParse(parser, medium)) {
     149            result.append(WTFMove(query.value()));
    136150            continue;
    137151        }
    138         std::unique_ptr<MediaQuery> mediaQuery = parser.parseMediaQuery(medium);
    139         if (!mediaQuery) {
    140             if (!m_fallbackToDescriptor)
    141                 return false;
    142             String mediaDescriptor = parseMediaDescriptor(medium);
    143             if (mediaDescriptor.isNull())
    144                 continue;
    145             mediaQuery = std::make_unique<MediaQuery>(MediaQuery::None, mediaDescriptor, nullptr);
    146         }
    147         result.append(WTFMove(mediaQuery));
     152        return false;
    148153    }
    149154    // ",,,," falls straight through, but is not valid unless fallback
    150155    if (!m_fallbackToDescriptor && list.isEmpty()) {
    151         String strippedMediaString = mediaString.stripWhiteSpace();
     156        String strippedMediaString = stripLeadingAndTrailingHTMLSpaces(mediaString);
    152157        if (!strippedMediaString.isEmpty())
    153158            return false;
     
    159164bool MediaQuerySet::add(const String& queryString)
    160165{
    161     CSSParser parser(CSSStrictMode);
    162 
    163     std::unique_ptr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryString);
    164     if (!parsedQuery && m_fallbackToDescriptor) {
    165         String medium = parseMediaDescriptor(queryString);
    166         if (!medium.isNull())
    167             parsedQuery = std::make_unique<MediaQuery>(MediaQuery::None, medium, nullptr);
    168     }
     166    auto parsedQuery = internalParse(queryString);
    169167    if (!parsedQuery)
    170168        return false;
    171 
    172     m_queries.append(WTFMove(parsedQuery));
     169    m_queries.append(WTFMove(parsedQuery.value()));
    173170    return true;
    174171}
    175172
    176 bool MediaQuerySet::remove(const String& queryStringToRemove)
    177 {
    178     CSSParser parser(CSSStrictMode);
    179 
    180     std::unique_ptr<MediaQuery> parsedQuery = parser.parseMediaQuery(queryStringToRemove);
    181     if (!parsedQuery && m_fallbackToDescriptor) {
    182         String medium = parseMediaDescriptor(queryStringToRemove);
    183         if (!medium.isNull())
    184             parsedQuery = std::make_unique<MediaQuery>(MediaQuery::None, medium, nullptr);
    185     }
     173bool MediaQuerySet::remove(const String& queryString)
     174{
     175    auto parsedQuery = internalParse(queryString);
    186176    if (!parsedQuery)
    187177        return false;
    188    
    189178    return m_queries.removeFirstMatching([&parsedQuery](auto& query) {
    190         return *query == *parsedQuery;
     179        return query == parsedQuery.value();
    191180    });
    192181}
    193182
    194 void MediaQuerySet::addMediaQuery(std::unique_ptr<MediaQuery> mediaQuery)
     183void MediaQuerySet::addMediaQuery(MediaQuery&& mediaQuery)
    195184{
    196185    m_queries.append(WTFMove(mediaQuery));
     
    200189{
    201190    StringBuilder text;
    202    
    203     bool first = true;
    204     for (size_t i = 0; i < m_queries.size(); ++i) {
    205         if (!first)
     191    bool needComma = false;
     192    for (auto& query : m_queries) {
     193        if (needComma)
    206194            text.appendLiteral(", ");
    207         else
    208             first = false;
    209         text.append(m_queries[i]->cssText());
     195        text.append(query.cssText());
     196        needComma = true;
    210197    }
    211198    return text.toString();
     
    215202    : m_mediaQueries(mediaQueries)
    216203    , m_parentStyleSheet(parentSheet)
    217     , m_parentRule(0)
    218204{
    219205}
     
    221207MediaList::MediaList(MediaQuerySet* mediaQueries, CSSRule* parentRule)
    222208    : m_mediaQueries(mediaQueries)
    223     , m_parentStyleSheet(0)
    224209    , m_parentRule(parentRule)
    225210{
     
    233218{
    234219    CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule);
    235 
    236     bool success = m_mediaQueries->parse(value);
    237     if (!success) {
     220    if (!m_mediaQueries->parse(value)) {
    238221        ec = SYNTAX_ERR;
    239222        return;
     
    247230    auto& queries = m_mediaQueries->queryVector();
    248231    if (index < queries.size())
    249         return queries[index]->cssText();
     232        return queries[index].cssText();
    250233    return String();
    251234}
     
    285268
    286269#if ENABLE(RESOLUTION_MEDIA_QUERY)
    287 static void addResolutionWarningMessageToConsole(Document* document, const String& serializedExpression, const CSSPrimitiveValue* value)
    288 {
    289     ASSERT(document);
    290     ASSERT(value);
    291 
     270
     271static void addResolutionWarningMessageToConsole(Document& document, const String& serializedExpression, const CSSPrimitiveValue& value)
     272{
    292273    static NeverDestroyed<String> mediaQueryMessage(ASCIILiteral("Consider using 'dppx' units instead of '%replacementUnits%', as in CSS '%replacementUnits%' means dots-per-CSS-%lengthUnit%, not dots-per-physical-%lengthUnit%, so does not correspond to the actual '%replacementUnits%' of a screen. In media query expression: "));
    293274    static NeverDestroyed<String> mediaValueDPI(ASCIILiteral("dpi"));
     
    297278
    298279    String message;
    299     if (value->isDotsPerInch())
    300         message = String(mediaQueryMessage).replace("%replacementUnits%", mediaValueDPI).replace("%lengthUnit%", lengthUnitInch);
    301     else if (value->isDotsPerCentimeter())
    302         message = String(mediaQueryMessage).replace("%replacementUnits%", mediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter);
     280    if (value.isDotsPerInch())
     281        message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPI).replace("%lengthUnit%", lengthUnitInch);
     282    else if (value.isDotsPerCentimeter())
     283        message = mediaQueryMessage.get().replace("%replacementUnits%", mediaValueDPCM).replace("%lengthUnit%", lengthUnitCentimeter);
    303284    else
    304285        ASSERT_NOT_REACHED();
     
    306287    message.append(serializedExpression);
    307288
    308     document->addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message);
     289    document.addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message);
    309290}
    310291
     
    314295        return;
    315296
    316     auto& mediaQueries = mediaQuerySet->queryVector();
    317     const size_t queryCount = mediaQueries.size();
    318 
    319     if (!queryCount)
    320         return;
    321 
    322     for (size_t i = 0; i < queryCount; ++i) {
    323         const MediaQuery* query = mediaQueries[i].get();
    324         String mediaType = query->mediaType();
    325         if (!query->ignored() && !equalLettersIgnoringASCIICase(mediaType, "print")) {
    326             auto& expressions = query->expressions();
    327             for (size_t j = 0; j < expressions.size(); ++j) {
    328                 const MediaQueryExp* exp = expressions.at(j).get();
    329                 if (exp->mediaFeature() == MediaFeatureNames::resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::max_resolutionMediaFeature || exp->mediaFeature() == MediaFeatureNames::min_resolutionMediaFeature) {
    330                     CSSValue* cssValue =  exp->value();
    331                     if (is<CSSPrimitiveValue>(cssValue)) {
    332                         CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*cssValue);
     297    for (auto& query : mediaQuerySet->queryVector()) {
     298        if (!query.ignored() && !equalLettersIgnoringASCIICase(query.mediaType(), "print")) {
     299            auto& expressions = query.expressions();
     300            for (auto& expression : expressions) {
     301                if (expression.mediaFeature() == MediaFeatureNames::resolution || expression.mediaFeature() == MediaFeatureNames::maxResolution || expression.mediaFeature() == MediaFeatureNames::minResolution) {
     302                    auto* value = expression.value();
     303                    if (is<CSSPrimitiveValue>(value)) {
     304                        auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
    333305                        if (primitiveValue.isDotsPerInch() || primitiveValue.isDotsPerCentimeter())
    334                             addResolutionWarningMessageToConsole(document, mediaQuerySet->mediaText(), &primitiveValue);
     306                            addResolutionWarningMessageToConsole(*document, mediaQuerySet->mediaText(), primitiveValue);
    335307                    }
    336308                }
     
    339311    }
    340312}
     313
    341314#endif
    342315
  • trunk/Source/WebCore/css/MediaList.h

    r188315 r201441  
    1919 */
    2020
    21 #ifndef MediaList_h
    22 #define MediaList_h
     21#pragma once
    2322
    24 #include "ExceptionCode.h"
    2523#include <memory>
    2624#include <wtf/Forward.h>
    27 #include <wtf/PassRefPtr.h>
    28 #include <wtf/RefCounted.h>
    2925#include <wtf/Vector.h>
    3026#include <wtf/text/WTFString.h>
     
    3228namespace WebCore {
    3329
     30class CSSParser;
    3431class CSSRule;
    3532class CSSStyleSheet;
    3633class Document;
    37 class MediaList;
    3834class MediaQuery;
     35
     36using ExceptionCode = int;
    3937
    4038class MediaQuerySet : public RefCounted<MediaQuerySet> {
     
    5351    }
    5452    ~MediaQuerySet();
    55    
     53
    5654    bool parse(const String&);
    5755    bool add(const String&);
    5856    bool remove(const String&);
    5957
    60     void addMediaQuery(std::unique_ptr<MediaQuery>);
     58    void addMediaQuery(MediaQuery&&);
    6159
    62     const Vector<std::unique_ptr<MediaQuery>>& queryVector() const { return m_queries; }
    63    
     60    const Vector<MediaQuery>& queryVector() const { return m_queries; }
     61
    6462    int lastLine() const { return m_lastLine; }
    6563    void setLastLine(int lastLine) { m_lastLine = lastLine; }
    66    
     64
    6765    String mediaText() const;
    6866
     
    7371    MediaQuerySet(const String& mediaQuery, bool fallbackToDescription);
    7472    MediaQuerySet(const MediaQuerySet&);
    75    
     73
     74    Optional<MediaQuery> internalParse(CSSParser&, const String&);
     75    Optional<MediaQuery> internalParse(const String&);
     76
    7677    unsigned m_fallbackToDescriptor : 1; // true if failed media query parsing should fallback to media description parsing.
    7778    signed m_lastLine : 31;
    78     Vector<std::unique_ptr<MediaQuery>> m_queries;
     79    Vector<MediaQuery> m_queries;
    7980};
    8081
     
    100101    void setMediaText(const String&, ExceptionCode&);
    101102
    102     // Not part of CSSOM.
    103103    CSSRule* parentRule() const { return m_parentRule; }
    104104    CSSStyleSheet* parentStyleSheet() const { return m_parentStyleSheet; }
    105     void clearParentStyleSheet() { ASSERT(m_parentStyleSheet); m_parentStyleSheet = 0; }
    106     void clearParentRule() { ASSERT(m_parentRule); m_parentRule = 0; }
     105    void clearParentStyleSheet() { ASSERT(m_parentStyleSheet); m_parentStyleSheet = nullptr; }
     106    void clearParentRule() { ASSERT(m_parentRule); m_parentRule = nullptr; }
    107107    const MediaQuerySet* queries() const { return m_mediaQueries.get(); }
    108108
     
    115115
    116116    RefPtr<MediaQuerySet> m_mediaQueries;
    117     CSSStyleSheet* m_parentStyleSheet;
    118     CSSRule* m_parentRule;
     117    CSSStyleSheet* m_parentStyleSheet { nullptr };
     118    CSSRule* m_parentRule { nullptr };
    119119};
    120120
    121 #if ENABLE(RESOLUTION_MEDIA_QUERY)
    122121// Adds message to inspector console whenever dpi or dpcm values are used for "screen" media.
     122// FIXME: Seems strange to have this here in this file, and unclear exactly who should call this and when.
    123123void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*);
     124
     125#if !ENABLE(RESOLUTION_MEDIA_QUERY)
     126
     127inline void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*)
     128{
     129}
     130
    124131#endif
    125132
    126133} // namespace
    127 
    128 #endif
  • trunk/Source/WebCore/css/MediaQuery.cpp

    r201333 r201441  
    3030#include "MediaQuery.h"
    3131
    32 #include "MediaQueryExp.h"
    3332#include <wtf/text/StringBuilder.h>
    3433
     
    3837String MediaQuery::serialize() const
    3938{
     39    if (m_ignored) {
     40        // If query is invalid, serialized text should turn into "not all".
     41        return ASCIILiteral("not all");
     42    }
     43
     44    bool shouldOmitMediaType = false;
    4045    StringBuilder result;
    41     if (!m_ignored) {
    42         switch (m_restrictor) {
    43         case MediaQuery::Only:
    44             result.appendLiteral("only ");
    45             break;
    46         case MediaQuery::Not:
    47             result.appendLiteral("not ");
    48             break;
    49         case MediaQuery::None:
    50             break;
    51         }
    52 
    53         if (m_expressions->isEmpty()) {
    54             result.append(m_mediaType);
    55             return result.toString();
    56         }
    57 
    58         if (m_mediaType != "all" || m_restrictor != None) {
    59             result.append(m_mediaType);
     46    switch (m_restrictor) {
     47    case MediaQuery::Only:
     48        result.appendLiteral("only ");
     49        break;
     50    case MediaQuery::Not:
     51        result.appendLiteral("not ");
     52        break;
     53    case MediaQuery::None:
     54        shouldOmitMediaType = !m_expressions.isEmpty() && m_mediaType == "all";
     55        break;
     56    }
     57    bool needsAnd = false;
     58    if (!shouldOmitMediaType) {
     59        result.append(m_mediaType);
     60        needsAnd = true;
     61    }
     62    for (auto& expression : m_expressions) {
     63        if (needsAnd)
    6064            result.appendLiteral(" and ");
    61         }
    62 
    63         result.append(m_expressions->at(0)->serialize());
    64         for (size_t i = 1; i < m_expressions->size(); ++i) {
    65             result.appendLiteral(" and ");
    66             result.append(m_expressions->at(i)->serialize());
    67         }
    68     } else {
    69         // If query is invalid, serialized text should turn into "not all".
    70         result.appendLiteral("not all");
     65        result.append(expression.serialize());
     66        needsAnd = true;
    7167    }
    7268    return result.toString();
    7369}
    7470
    75 MediaQuery::MediaQuery(Restrictor r, const String& mediaType, std::unique_ptr<ExpressionVector> exprs)
    76     : m_restrictor(r)
     71MediaQuery::MediaQuery(Restrictor restrictor, const String& mediaType, Vector<MediaQueryExpression>&& expressions)
     72    : m_restrictor(restrictor)
    7773    , m_mediaType(mediaType.convertToASCIILowercase())
    78     , m_expressions(WTFMove(exprs))
    79     , m_ignored(false)
     74    , m_expressions(WTFMove(expressions))
    8075{
    81     if (!m_expressions) {
    82         m_expressions = std::make_unique<ExpressionVector>();
    83         return;
    84     }
    85 
    86     std::sort(m_expressions->begin(), m_expressions->end(), [](auto& a, auto& b) {
    87         return codePointCompare(a->serialize(), b->serialize()) < 0;
     76    std::sort(m_expressions.begin(), m_expressions.end(), [](auto& a, auto& b) {
     77        return codePointCompare(a.serialize(), b.serialize()) < 0;
    8878    });
    8979
    90     // remove all duplicated expressions
     80    // Remove all duplicated expressions.
    9181    String key;
    92     for (int i = m_expressions->size() - 1; i >= 0; --i) {
     82    for (int i = m_expressions.size() - 1; i >= 0; --i) {
    9383
    94         // if not all of the expressions is valid the media query must be ignored.
     84        // If any expression is invalid the media query must be ignored.
    9585        if (!m_ignored)
    96             m_ignored = !m_expressions->at(i)->isValid();
     86            m_ignored = !m_expressions[i].isValid();
    9787
    98         if (m_expressions->at(i)->serialize() == key)
    99             m_expressions->remove(i);
     88        if (m_expressions[i].serialize() == key)
     89            m_expressions.remove(i);
    10090        else
    101             key = m_expressions->at(i)->serialize();
     91            key = m_expressions[i].serialize();
    10292    }
    103 }
    104 
    105 MediaQuery::MediaQuery(const MediaQuery& o)
    106     : m_restrictor(o.m_restrictor)
    107     , m_mediaType(o.m_mediaType)
    108     , m_expressions(std::make_unique<ExpressionVector>(o.m_expressions->size()))
    109     , m_ignored(o.m_ignored)
    110     , m_serializationCache(o.m_serializationCache)
    111 {
    112     for (unsigned i = 0; i < m_expressions->size(); ++i)
    113         (*m_expressions)[i] = std::make_unique<MediaQueryExp>(*o.m_expressions->at(i));
    114 }
    115 
    116 MediaQuery::~MediaQuery()
    117 {
    11893}
    11994
     
    125100
    126101// http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries
    127 String MediaQuery::cssText() const
     102const String& MediaQuery::cssText() const
    128103{
    129104    if (m_serializationCache.isNull())
    130         const_cast<MediaQuery*>(this)->m_serializationCache = serialize();
    131 
     105        m_serializationCache = serialize();
    132106    return m_serializationCache;
    133107}
  • trunk/Source/WebCore/css/MediaQuery.h

    r195310 r201441  
    2727 */
    2828
    29 #ifndef MediaQuery_h
    30 #define MediaQuery_h
     29#pragma once
    3130
    32 #include <memory>
     31#include "MediaQueryExp.h"
    3332#include <wtf/Vector.h>
    34 #include <wtf/text/StringHash.h>
    35 #include <wtf/text/WTFString.h>
    3633
    3734namespace WebCore {
    38 class MediaQueryExp;
    3935
    4036class MediaQuery {
    4137    WTF_MAKE_FAST_ALLOCATED;
    4238public:
    43     enum Restrictor {
    44         Only, Not, None
    45     };
     39    enum Restrictor { Only, Not, None };
    4640
    47     typedef Vector<std::unique_ptr<MediaQueryExp>> ExpressionVector;
    48 
    49     MediaQuery(Restrictor, const String& mediaType, std::unique_ptr<Vector<std::unique_ptr<MediaQueryExp>>> exprs);
    50     MediaQuery(const MediaQuery&);
    51     ~MediaQuery();
     41    MediaQuery(Restrictor, const String& mediaType, Vector<MediaQueryExpression>&&);
    5242
    5343    Restrictor restrictor() const { return m_restrictor; }
    54     const Vector<std::unique_ptr<MediaQueryExp>>& expressions() const { return *m_expressions; }
    55     String mediaType() const { return m_mediaType; }
    56     bool operator==(const MediaQuery& other) const;
    57     String cssText() const;
     44    const Vector<MediaQueryExpression>& expressions() const { return m_expressions; }
     45    const String& mediaType() const { return m_mediaType; }
    5846    bool ignored() const { return m_ignored; }
    5947
    60     std::unique_ptr<MediaQuery> copy() const { return std::make_unique<MediaQuery>(*this); }
     48    const String& cssText() const;
    6149
    62  private:
     50    bool operator==(const MediaQuery& other) const;
     51
     52private:
     53    String serialize() const;
     54
    6355    Restrictor m_restrictor;
    6456    String m_mediaType;
    65     std::unique_ptr<ExpressionVector> m_expressions;
    66     bool m_ignored;
    67     String m_serializationCache;
    68 
    69     String serialize() const;
     57    Vector<MediaQueryExpression> m_expressions;
     58    bool m_ignored { false };
     59    mutable String m_serializationCache;
    7060};
    7161
    7262} // namespace
    73 
    74 #endif
  • trunk/Source/WebCore/css/MediaQueryEvaluator.cpp

    r201065 r201441  
    4242#include "MediaList.h"
    4343#include "MediaQuery.h"
    44 #include "MediaQueryExp.h"
    4544#include "NodeRenderStyle.h"
    4645#include "Page.h"
     
    5958namespace WebCore {
    6059
    61 using namespace MediaFeatureNames;
    62 
    6360enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix };
    6461
    65 typedef bool (*EvalFunc)(CSSValue*, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix);
    66 typedef HashMap<AtomicStringImpl*, EvalFunc> FunctionMap;
    67 static FunctionMap* gFunctionMap;
    68 
    69 /*
    70  * FIXME: following media features are not implemented: scan
    71  *
    72  * scan: The "scan" media feature describes the scanning process of
    73  * tv output devices. It's unknown how to retrieve this information from
    74  * the platform
    75  */
     62typedef bool (*MediaQueryFunction)(CSSValue*, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix);
     63typedef HashMap<AtomicStringImpl*, MediaQueryFunction> MediaQueryFunctionMap;
     64
     65static bool isViewportDependent(const AtomicString& mediaFeature)
     66{
     67    return mediaFeature == MediaFeatureNames::width
     68        || mediaFeature == MediaFeatureNames::height
     69        || mediaFeature == MediaFeatureNames::minWidth
     70        || mediaFeature == MediaFeatureNames::minHeight
     71        || mediaFeature == MediaFeatureNames::maxWidth
     72        || mediaFeature == MediaFeatureNames::maxHeight
     73        || mediaFeature == MediaFeatureNames::orientation
     74        || mediaFeature == MediaFeatureNames::aspectRatio
     75        || mediaFeature == MediaFeatureNames::minAspectRatio
     76        || mediaFeature == MediaFeatureNames::maxAspectRatio;
     77}
    7678
    7779MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult)
    78     : m_expResult(mediaFeatureResult)
     80    : m_fallbackResult(mediaFeatureResult)
    7981{
    8082}
     
    8284MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult)
    8385    : m_mediaType(acceptedMediaType)
    84     , m_expResult(mediaFeatureResult)
    85 {
    86 }
    87 
    88 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, Frame* frame, const RenderStyle* style)
     86    , m_fallbackResult(mediaFeatureResult)
     87{
     88}
     89
     90MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, Document& document, const RenderStyle* style)
    8991    : m_mediaType(acceptedMediaType)
    90     , m_frame(frame)
     92    , m_frame(document.frame())
    9193    , m_style(style)
    92     , m_expResult(false) // doesn't matter when we have m_frame and m_style
    93 {
    94 }
    95 
    96 MediaQueryEvaluator::~MediaQueryEvaluator()
    9794{
    9895}
     
    119116}
    120117
    121 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, StyleResolver* styleResolver) const
    122 {
    123     if (!querySet)
    124         return true;
    125 
    126     auto& queries = querySet->queryVector();
     118bool MediaQueryEvaluator::evaluate(const MediaQuerySet& querySet, StyleResolver* styleResolver) const
     119{
     120    auto& queries = querySet.queryVector();
    127121    if (!queries.size())
    128122        return true; // empty query list evaluates to true
     
    131125    bool result = false;
    132126    for (size_t i = 0; i < queries.size() && !result; ++i) {
    133         MediaQuery* query = queries[i].get();
    134 
    135         if (query->ignored() || (!query->expressions().size() && query->mediaType().isEmpty()))
     127        auto& query = queries[i];
     128
     129        if (query.ignored() || (!query.expressions().size() && query.mediaType().isEmpty()))
    136130            continue;
    137131
    138         if (mediaTypeMatch(query->mediaType())) {
    139             auto& expressions = query->expressions();
    140             // iterate through expressions, stop if any of them eval to false
    141             // (AND semantics)
     132        if (mediaTypeMatch(query.mediaType())) {
     133            auto& expressions = query.expressions();
     134            // iterate through expressions, stop if any of them eval to false (AND semantics)
    142135            size_t j = 0;
    143136            for (; j < expressions.size(); ++j) {
    144                 bool exprResult = eval(expressions.at(j).get());
    145                 if (styleResolver && expressions.at(j)->isViewportDependent())
    146                     styleResolver->addViewportDependentMediaQueryResult(expressions.at(j).get(), exprResult);
    147                 if (!exprResult)
     137                bool expressionResult = evaluate(expressions[j]);
     138                if (styleResolver && isViewportDependent(expressions[j].mediaFeature()))
     139                    styleResolver->addViewportDependentMediaQueryResult(expressions[j], expressionResult);
     140                if (!expressionResult)
    148141                    break;
    149142            }
     
    151144            // assume true if we are at the end of the list,
    152145            // otherwise assume false
    153             result = applyRestrictor(query->restrictor(), expressions.size() == j);
     146            result = applyRestrictor(query.restrictor(), expressions.size() == j);
    154147        } else
    155             result = applyRestrictor(query->restrictor(), false);
     148            result = applyRestrictor(query.restrictor(), false);
    156149    }
    157150
     
    159152}
    160153
    161 bool MediaQueryEvaluator::evalCheckingViewportDependentResults(const MediaQuerySet* querySet, Vector<std::unique_ptr<MediaQueryResult>>& results)
    162 {
    163     if (!querySet)
    164         return true;
    165 
    166     auto& queries = querySet->queryVector();
     154bool MediaQueryEvaluator::evaluate(const MediaQuerySet& querySet, Vector<MediaQueryResult>& results) const
     155{
     156    auto& queries = querySet.queryVector();
    167157    if (!queries.size())
    168158        return true;
     
    170160    bool result = false;
    171161    for (size_t i = 0; i < queries.size() && !result; ++i) {
    172         MediaQuery* query = queries[i].get();
    173 
    174         if (query->ignored())
     162        auto& query = queries[i];
     163
     164        if (query.ignored())
    175165            continue;
    176166
    177         if (mediaTypeMatch(query->mediaType())) {
    178             auto& expressions = query->expressions();
     167        if (mediaTypeMatch(query.mediaType())) {
     168            auto& expressions = query.expressions();
    179169            size_t j = 0;
    180170            for (; j < expressions.size(); ++j) {
    181                 bool exprResult = eval(expressions.at(j).get());
    182                 if (expressions.at(j)->isViewportDependent())
    183                     results.append(std::make_unique<MediaQueryResult>(*expressions.at(j), exprResult));
    184                 if (!exprResult)
     171                bool expressionResult = evaluate(expressions[j]);
     172                if (isViewportDependent(expressions[j].mediaFeature()))
     173                    results.append({ expressions[j], expressionResult });
     174                if (!expressionResult)
    185175                    break;
    186176            }
    187             result = applyRestrictor(query->restrictor(), expressions.size() == j);
     177            result = applyRestrictor(query.restrictor(), expressions.size() == j);
    188178        } else
    189             result = applyRestrictor(query->restrictor(), false);
     179            result = applyRestrictor(query.restrictor(), false);
    190180    }
    191181
     
    193183}
    194184
    195 template<typename T>
    196 bool compareValue(T a, T b, MediaFeaturePrefix op)
     185template<typename T, typename U> bool compareValue(T a, U b, MediaFeaturePrefix op)
    197186{
    198187    switch (op) {
     
    209198static bool compareAspectRatioValue(CSSValue* value, int width, int height, MediaFeaturePrefix op)
    210199{
    211     if (is<CSSAspectRatioValue>(*value)) {
    212         CSSAspectRatioValue& aspectRatio = downcast<CSSAspectRatioValue>(*value);
    213         return compareValue(width * static_cast<int>(aspectRatio.denominatorValue()), height * static_cast<int>(aspectRatio.numeratorValue()), op);
    214     }
    215 
    216     return false;
    217 }
    218 
    219 static bool numberValue(CSSValue* value, float& result)
    220 {
    221     if (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isNumber()) {
    222         result = downcast<CSSPrimitiveValue>(*value).getFloatValue(CSSPrimitiveValue::CSS_NUMBER);
    223         return true;
    224     }
    225     return false;
    226 }
    227 
    228 static bool colorMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    229 {
    230     int bitsPerComponent = screenDepthPerComponent(frame->page()->mainFrame().view());
    231     float number;
    232     if (value)
    233         return numberValue(value, number) && compareValue(bitsPerComponent, static_cast<int>(number), op);
    234 
    235     return bitsPerComponent != 0;
    236 }
    237 
    238 static bool color_indexMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix op)
    239 {
    240     // FIXME: It's unknown how to retrieve the information if the display mode is indexed
    241     // Assume we don't support indexed display.
    242     if (!value)
    243         return false;
    244 
    245     float number;
    246     return numberValue(value, number) && compareValue(0, static_cast<int>(number), op);
    247 }
    248 
    249 static bool color_gamutMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix)
     200    if (!is<CSSAspectRatioValue>(value))
     201        return false;
     202    auto& aspectRatio = downcast<CSSAspectRatioValue>(*value);
     203    return compareValue(width * aspectRatio.denominatorValue(), height * aspectRatio.numeratorValue(), op);
     204}
     205
     206static Optional<double> doubleValue(CSSValue* value)
     207{
     208    if (!is<CSSPrimitiveValue>(value) || !downcast<CSSPrimitiveValue>(*value).isNumber())
     209        return Nullopt;
     210    return downcast<CSSPrimitiveValue>(*value).getDoubleValue(CSSPrimitiveValue::CSS_NUMBER);
     211}
     212
     213static bool zeroEvaluate(CSSValue* value, MediaFeaturePrefix op)
     214{
     215    auto numericValue = doubleValue(value);
     216    return numericValue && compareValue(0, numericValue.value(), op);
     217}
     218
     219static bool oneEvaluate(CSSValue* value, MediaFeaturePrefix op)
     220{
     221    if (!value)
     222        return true;
     223    auto numericValue = doubleValue(value);
     224    return numericValue && compareValue(1, numericValue.value(), op);
     225}
     226
     227static bool colorEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
     228{
     229    int bitsPerComponent = screenDepthPerComponent(frame.mainFrame().view());
     230    auto numericValue = doubleValue(value);
     231    if (!numericValue)
     232        return bitsPerComponent;
     233    return compareValue(bitsPerComponent, numericValue.value(), op);
     234}
     235
     236static bool colorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
     237{
     238    // Always return false for indexed display.
     239    return zeroEvaluate(value, op);
     240}
     241
     242static bool colorGamutEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
    250243{
    251244    if (!value)
     
    256249        return true;
    257250    case CSSValueP3:
    258         // FIXME: For the moment we'll just assume an "extended
    259         // color" display is at least as good as P3.
    260         return screenSupportsExtendedColor(frame->page()->mainFrame().view());
     251        // FIXME: For the moment we just assume any "extended color" display is at least as good as P3.
     252        return screenSupportsExtendedColor(frame.mainFrame().view());
    261253    case CSSValueRec2020:
    262         // FIXME: At some point we should start detecting displays that
    263         // support more colors.
     254        // FIXME: At some point we should start detecting displays that support more colors.
    264255        return false;
    265256    default:
     
    269260}
    270261
    271 static bool monochromeMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
    272 {
    273     if (!screenIsMonochrome(frame->page()->mainFrame().view())) {
    274         if (value) {
    275             float number;
    276             return numberValue(value, number) && compareValue(0, static_cast<int>(number), op);
    277         }
    278         return false;
    279     }
    280 
    281     return colorMediaFeatureEval(value, conversionData, frame, op);
    282 }
    283 
    284 static bool inverted_colorsMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
     262static bool monochromeEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op)
     263{
     264    if (!screenIsMonochrome(frame.mainFrame().view()))
     265        return zeroEvaluate(value, op);
     266    return colorEvaluate(value, conversionData, frame, op);
     267}
     268
     269static bool invertedColorsEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
    285270{
    286271    bool isInverted = screenHasInvertedColors();
    287 
    288272    if (!value)
    289273        return isInverted;
    290 
    291     const CSSValueID id = downcast<CSSPrimitiveValue>(*value).getValueID();
    292     return (isInverted && id == CSSValueInverted) || (!isInverted && id == CSSValueNone);
    293 }
    294 
    295 static bool orientationMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix)
    296 {
    297     FrameView* view = frame->view();
     274    return downcast<CSSPrimitiveValue>(*value).getValueID() == (isInverted ? CSSValueInverted : CSSValueNone);
     275}
     276
     277static bool orientationEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
     278{
     279    FrameView* view = frame.view();
    298280    if (!view)
    299281        return false;
    300282
    301     int width = view->layoutWidth();
    302     int height = view->layoutHeight();
    303     if (is<CSSPrimitiveValue>(value)) {
    304         const CSSValueID id = downcast<CSSPrimitiveValue>(*value).getValueID();
    305         if (width > height) // Square viewport is portrait.
    306             return CSSValueLandscape == id;
    307         return CSSValuePortrait == id;
    308     }
    309 
    310     // Expression (orientation) evaluates to true if width and height >= 0.
    311     return height >= 0 && width >= 0;
    312 }
    313 
    314 static bool aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    315 {
    316     FrameView* view = frame->view();
    317     if (!view)
    318         return true;
    319 
    320     if (value)
    321         return compareAspectRatioValue(value, view->layoutWidth(), view->layoutHeight(), op);
    322 
     283    auto width = view->layoutWidth();
     284    auto height = view->layoutHeight();
     285
     286    if (!is<CSSPrimitiveValue>(value)) {
     287        // Expression (orientation) evaluates to true if width and height >= 0.
     288        return height >= 0 && width >= 0;
     289    }
     290
     291    auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID();
     292    if (width > height) // Square viewport is portrait.
     293        return keyword == CSSValueLandscape;
     294    return keyword == CSSValuePortrait;
     295}
     296
     297static bool aspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
     298{
    323299    // ({,min-,max-}aspect-ratio)
    324300    // assume if we have a device, its aspect ratio is non-zero
    325     return true;
    326 }
    327 
    328 static bool device_aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    329 {
    330     if (value) {
    331         FloatRect sg = screenRect(frame->page()->mainFrame().view());
    332         return compareAspectRatioValue(value, static_cast<int>(sg.width()), static_cast<int>(sg.height()), op);
    333     }
    334 
     301    if (!value)
     302        return true;
     303
     304    FrameView* view = frame.view();
     305    if (!view)
     306        return true;
     307
     308    return compareAspectRatioValue(value, view->layoutWidth(), view->layoutHeight(), op);
     309}
     310
     311static bool deviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
     312{
    335313    // ({,min-,max-}device-aspect-ratio)
    336314    // assume if we have a device, its aspect ratio is non-zero
    337     return true;
    338 }
    339 
    340 static bool evalResolution(CSSValue* value, Frame* frame, MediaFeaturePrefix op)
     315    if (!value)
     316        return true;
     317
     318    auto size = screenRect(frame.mainFrame().view()).size();
     319    return compareAspectRatioValue(value, size.width(), size.height(), op);
     320}
     321
     322static bool evaluateResolution(CSSValue* value, Frame& frame, MediaFeaturePrefix op)
    341323{
    342324    // FIXME: Possible handle other media types than 'screen' and 'print'.
    343     FrameView* view = frame->view();
     325    FrameView* view = frame.view();
    344326    if (!view)
    345327        return false;
    346328
    347329    float deviceScaleFactor = 0;
     330
    348331    // This checks the actual media type applied to the document, and we know
    349332    // this method only got called if this media type matches the one defined
     
    352335    String mediaType = view->mediaType();
    353336    if (equalLettersIgnoringASCIICase(mediaType, "screen"))
    354         deviceScaleFactor = frame->page()->deviceScaleFactor();
     337        deviceScaleFactor = frame.page() ? frame.page()->deviceScaleFactor() : 1;
    355338    else if (equalLettersIgnoringASCIICase(mediaType, "print")) {
    356339        // The resolution of images while printing should not depend on the dpi
     
    363346        return !!deviceScaleFactor;
    364347
    365     if (!is<CSSPrimitiveValue>(*value))
    366         return false;
    367 
    368     CSSPrimitiveValue& resolution = downcast<CSSPrimitiveValue>(*value);
     348    if (!is<CSSPrimitiveValue>(value))
     349        return false;
     350
     351    auto& resolution = downcast<CSSPrimitiveValue>(*value);
    369352    return compareValue(deviceScaleFactor, resolution.isNumber() ? resolution.getFloatValue() : resolution.getFloatValue(CSSPrimitiveValue::CSS_DPPX), op);
    370353}
    371354
    372 static bool device_pixel_ratioMediaFeatureEval(CSSValue *value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    373 {
    374     return (!value || downcast<CSSPrimitiveValue>(*value).isNumber()) && evalResolution(value, frame, op);
    375 }
    376 
    377 static bool resolutionMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
     355static bool devicePixelRatioEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
     356{
     357    return (!value || (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isNumber())) && evaluateResolution(value, frame, op);
     358}
     359
     360static bool resolutionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
    378361{
    379362#if ENABLE(RESOLUTION_MEDIA_QUERY)
    380     return (!value || downcast<CSSPrimitiveValue>(*value).isResolution()) && evalResolution(value, frame, op);
     363    return (!value || (is<CSSPrimitiveValue>(*value) && downcast<CSSPrimitiveValue>(*value).isResolution())) && evaluateResolution(value, frame, op);
    381364#else
    382365    UNUSED_PARAM(value);
     
    387370}
    388371
    389 static bool gridMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix op)
    390 {
    391     // if output device is bitmap, grid: 0 == true
    392     // assume we have bitmap device
    393     float number;
    394     if (value && numberValue(value, number))
    395         return compareValue(static_cast<int>(number), 0, op);
    396     return false;
     372static bool gridEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
     373{
     374    return zeroEvaluate(value, op);
    397375}
    398376
    399377static bool computeLength(CSSValue* value, bool strict, const CSSToLengthConversionData& conversionData, int& result)
    400378{
    401     if (!is<CSSPrimitiveValue>(*value))
    402         return false;
    403 
    404     CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value);
     379    if (!is<CSSPrimitiveValue>(value))
     380        return false;
     381
     382    auto& primitiveValue = downcast<CSSPrimitiveValue>(*value);
    405383
    406384    if (primitiveValue.isNumber()) {
     
    417395}
    418396
    419 static bool device_heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
    420 {
    421     if (value) {
    422         FloatRect sg = screenRect(frame->page()->mainFrame().view());
    423         int length;
    424         long height = sg.height();
    425         return computeLength(value, !frame->document()->inQuirksMode(), conversionData, length) && compareValue(static_cast<int>(height), length, op);
    426     }
     397static bool deviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op)
     398{
    427399    // ({,min-,max-}device-height)
    428400    // assume if we have a device, assume non-zero
    429     return true;
    430 }
    431 
    432 static bool device_widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
    433 {
    434     if (value) {
    435         FloatRect sg = screenRect(frame->page()->mainFrame().view());
    436         int length;
    437         long width = sg.width();
    438         return computeLength(value, !frame->document()->inQuirksMode(), conversionData, length) && compareValue(static_cast<int>(width), length, op);
    439     }
     401    if (!value)
     402        return true;
     403    int length;
     404    auto height = screenRect(frame.mainFrame().view()).height();
     405    return computeLength(value, !frame.document()->inQuirksMode(), conversionData, length) && compareValue(height, length, op);
     406}
     407
     408static bool deviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op)
     409{
    440410    // ({,min-,max-}device-width)
    441411    // assume if we have a device, assume non-zero
    442     return true;
    443 }
    444 
    445 static bool heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
    446 {
    447     FrameView* view = frame->view();
     412    if (!value)
     413        return true;
     414    int length;
     415    auto width = screenRect(frame.mainFrame().view()).width();
     416    return computeLength(value, !frame.document()->inQuirksMode(), conversionData, length) && compareValue(width, length, op);
     417}
     418
     419static bool heightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op)
     420{
     421    FrameView* view = frame.view();
    448422    if (!view)
    449423        return false;
    450 
    451     if (value) {
    452         int height = view->layoutHeight();
    453         if (RenderView* renderView = frame->document()->renderView())
    454             height = adjustForAbsoluteZoom(height, *renderView);
    455         int length;
    456         return computeLength(value, !frame->document()->inQuirksMode(), conversionData, length) && compareValue(height, length, op);
    457     }
    458 
    459     return view->layoutHeight() != 0;
    460 }
    461 
    462 static bool widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix op)
    463 {
    464     FrameView* view = frame->view();
     424    int height = view->layoutHeight();
     425    if (!value)
     426        return height;
     427    if (auto* renderView = frame.document()->renderView())
     428        height = adjustForAbsoluteZoom(height, *renderView);
     429    int length;
     430    return computeLength(value, !frame.document()->inQuirksMode(), conversionData, length) && compareValue(height, length, op);
     431}
     432
     433static bool widthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op)
     434{
     435    FrameView* view = frame.view();
    465436    if (!view)
    466437        return false;
    467 
    468     if (value) {
    469         int width = view->layoutWidth();
    470         if (RenderView* renderView = frame->document()->renderView())
    471             width = adjustForAbsoluteZoom(width, *renderView);
    472         int length;
    473         return computeLength(value, !frame->document()->inQuirksMode(), conversionData, length) && compareValue(width, length, op);
    474     }
    475 
    476     return view->layoutWidth() != 0;
    477 }
    478 
    479 // rest of the functions are trampolines which set the prefix according to the media feature expression used
    480 
    481 static bool min_colorMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    482 {
    483     return colorMediaFeatureEval(value, conversionData, frame, MinPrefix);
    484 }
    485 
    486 static bool max_colorMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    487 {
    488     return colorMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    489 }
    490 
    491 static bool min_color_indexMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    492 {
    493     return color_indexMediaFeatureEval(value, conversionData, frame, MinPrefix);
    494 }
    495 
    496 static bool max_color_indexMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    497 {
    498     return color_indexMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    499 }
    500 
    501 static bool min_monochromeMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    502 {
    503     return monochromeMediaFeatureEval(value, conversionData, frame, MinPrefix);
    504 }
    505 
    506 static bool max_monochromeMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    507 {
    508     return monochromeMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    509 }
    510 
    511 static bool min_aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    512 {
    513     return aspect_ratioMediaFeatureEval(value, conversionData, frame, MinPrefix);
    514 }
    515 
    516 static bool max_aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    517 {
    518     return aspect_ratioMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    519 }
    520 
    521 static bool min_device_aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    522 {
    523     return device_aspect_ratioMediaFeatureEval(value, conversionData, frame, MinPrefix);
    524 }
    525 
    526 static bool max_device_aspect_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    527 {
    528     return device_aspect_ratioMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    529 }
    530 
    531 static bool min_device_pixel_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    532 {
    533     return device_pixel_ratioMediaFeatureEval(value, conversionData, frame, MinPrefix);
    534 }
    535 
    536 static bool max_device_pixel_ratioMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    537 {
    538     return device_pixel_ratioMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    539 }
    540 
    541 static bool min_heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    542 {
    543     return heightMediaFeatureEval(value, conversionData, frame, MinPrefix);
    544 }
    545 
    546 static bool max_heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    547 {
    548     return heightMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    549 }
    550 
    551 static bool min_widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    552 {
    553     return widthMediaFeatureEval(value, conversionData, frame, MinPrefix);
    554 }
    555 
    556 static bool max_widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    557 {
    558     return widthMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    559 }
    560 
    561 static bool min_device_heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    562 {
    563     return device_heightMediaFeatureEval(value, conversionData, frame, MinPrefix);
    564 }
    565 
    566 static bool max_device_heightMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    567 {
    568     return device_heightMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    569 }
    570 
    571 static bool min_device_widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    572 {
    573     return device_widthMediaFeatureEval(value, conversionData, frame, MinPrefix);
    574 }
    575 
    576 static bool max_device_widthMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    577 {
    578     return device_widthMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    579 }
    580 
    581 static bool min_resolutionMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    582 {
    583     return resolutionMediaFeatureEval(value, conversionData, frame, MinPrefix);
    584 }
    585 
    586 static bool max_resolutionMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame* frame, MediaFeaturePrefix)
    587 {
    588     return resolutionMediaFeatureEval(value, conversionData, frame, MaxPrefix);
    589 }
    590 
    591 static bool animationMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix op)
    592 {
    593     if (value) {
    594         float number;
    595         return numberValue(value, number) && compareValue(1, static_cast<int>(number), op);
    596     }
    597     return true;
    598 }
    599 
    600 static bool transitionMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix op)
    601 {
    602     if (value) {
    603         float number;
    604         return numberValue(value, number) && compareValue(1, static_cast<int>(number), op);
    605     }
    606     return true;
    607 }
    608 
    609 static bool transform_2dMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix op)
    610 {
    611     if (value) {
    612         float number;
    613         return numberValue(value, number) && compareValue(1, static_cast<int>(number), op);
    614     }
    615     return true;
    616 }
    617 
    618 static bool transform_3dMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    619 {
    620     bool returnValueIfNoParameter;
    621     int have3dRendering;
    622 
     438    int width = view->layoutWidth();
     439    if (!value)
     440        return width;
     441    if (auto* renderView = frame.document()->renderView())
     442        width = adjustForAbsoluteZoom(width, *renderView);
     443    int length;
     444    return computeLength(value, !frame.document()->inQuirksMode(), conversionData, length) && compareValue(width, length, op);
     445}
     446
     447static bool minColorEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     448{
     449    return colorEvaluate(value, conversionData, frame, MinPrefix);
     450}
     451
     452static bool maxColorEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     453{
     454    return colorEvaluate(value, conversionData, frame, MaxPrefix);
     455}
     456
     457static bool minColorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     458{
     459    return colorIndexEvaluate(value, conversionData, frame, MinPrefix);
     460}
     461
     462static bool maxColorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     463{
     464    return colorIndexEvaluate(value, conversionData, frame, MaxPrefix);
     465}
     466
     467static bool minMonochromeEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     468{
     469    return monochromeEvaluate(value, conversionData, frame, MinPrefix);
     470}
     471
     472static bool maxMonochromeEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     473{
     474    return monochromeEvaluate(value, conversionData, frame, MaxPrefix);
     475}
     476
     477static bool minAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     478{
     479    return aspectRatioEvaluate(value, conversionData, frame, MinPrefix);
     480}
     481
     482static bool maxAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     483{
     484    return aspectRatioEvaluate(value, conversionData, frame, MaxPrefix);
     485}
     486
     487static bool minDeviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     488{
     489    return deviceAspectRatioEvaluate(value, conversionData, frame, MinPrefix);
     490}
     491
     492static bool maxDeviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     493{
     494    return deviceAspectRatioEvaluate(value, conversionData, frame, MaxPrefix);
     495}
     496
     497static bool minDevicePixelRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     498{
     499    return devicePixelRatioEvaluate(value, conversionData, frame, MinPrefix);
     500}
     501
     502static bool maxDevicePixelRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     503{
     504    return devicePixelRatioEvaluate(value, conversionData, frame, MaxPrefix);
     505}
     506
     507static bool minHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     508{
     509    return heightEvaluate(value, conversionData, frame, MinPrefix);
     510}
     511
     512static bool maxHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     513{
     514    return heightEvaluate(value, conversionData, frame, MaxPrefix);
     515}
     516
     517static bool minWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     518{
     519    return widthEvaluate(value, conversionData, frame, MinPrefix);
     520}
     521
     522static bool maxWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     523{
     524    return widthEvaluate(value, conversionData, frame, MaxPrefix);
     525}
     526
     527static bool minDeviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     528{
     529    return deviceHeightEvaluate(value, conversionData, frame, MinPrefix);
     530}
     531
     532static bool maxDeviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     533{
     534    return deviceHeightEvaluate(value, conversionData, frame, MaxPrefix);
     535}
     536
     537static bool minDeviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     538{
     539    return deviceWidthEvaluate(value, conversionData, frame, MinPrefix);
     540}
     541
     542static bool maxDeviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     543{
     544    return deviceWidthEvaluate(value, conversionData, frame, MaxPrefix);
     545}
     546
     547static bool minResolutionEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     548{
     549    return resolutionEvaluate(value, conversionData, frame, MinPrefix);
     550}
     551
     552static bool maxResolutionEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix)
     553{
     554    return resolutionEvaluate(value, conversionData, frame, MaxPrefix);
     555}
     556
     557static bool animationEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
     558{
     559    return oneEvaluate(value, op);
     560}
     561
     562static bool transitionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
     563{
     564    return oneEvaluate(value, op);
     565}
     566
     567static bool transform2dEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op)
     568{
     569    return oneEvaluate(value, op);
     570}
     571
     572static bool transform3dEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op)
     573{
    623574#if ENABLE(3D_TRANSFORMS)
    624     bool threeDEnabled = false;
    625     if (RenderView* view = frame->contentRenderer())
    626         threeDEnabled = view->compositor().canRender3DTransforms();
    627 
    628     returnValueIfNoParameter = threeDEnabled;
    629     have3dRendering = threeDEnabled ? 1 : 0;
     575    auto* view = frame.contentRenderer();
     576    return view && view->compositor().canRender3DTransforms() ? oneEvaluate(value, op) : zeroEvaluate(value, op);
    630577#else
    631578    UNUSED_PARAM(frame);
    632     returnValueIfNoParameter = false;
    633     have3dRendering = 0;
     579    return zeroEvaluate(value, op);
    634580#endif
    635 
    636     if (value) {
    637         float number;
    638         return numberValue(value, number) && compareValue(have3dRendering, static_cast<int>(number), op);
    639     }
    640     return returnValueIfNoParameter;
    641581}
    642582
    643583#if ENABLE(VIEW_MODE_CSS_MEDIA)
    644 static bool view_modeMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix op)
    645 {
    646     UNUSED_PARAM(op);
    647     if (!value)
    648         return true;
    649 
    650     const int viewModeCSSKeywordID = downcast<CSSPrimitiveValue>(*value).getValueID();
    651     const Page::ViewMode viewMode = frame->page()->viewMode();
    652     bool result = false;
    653     switch (viewMode) {
     584
     585static bool viewModeEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
     586{
     587    if (!value)
     588        return true;
     589
     590    auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID();
     591
     592    switch (frame.page()->viewMode()) {
    654593    case Page::ViewModeWindowed:
    655         result = viewModeCSSKeywordID == CSSValueWindowed;
     594        return keyword == CSSValueWindowed;
     595    case Page::ViewModeFloating:
     596        return keyword == CSSValueFloating;
     597    case Page::ViewModeFullscreen:
     598        return keyword == CSSValueFullscreen;
     599    case Page::ViewModeMaximized:
     600        return keyword == CSSValueMaximized;
     601    case Page::ViewModeMinimized:
     602        return keyword == CSSValueMinimized;
     603    default:
    656604        break;
    657     case Page::ViewModeFloating:
    658         result = viewModeCSSKeywordID == CSSValueFloating;
    659         break;
    660     case Page::ViewModeFullscreen:
    661         result = viewModeCSSKeywordID == CSSValueFullscreen;
    662         break;
    663     case Page::ViewModeMaximized:
    664         result = viewModeCSSKeywordID == CSSValueMaximized;
    665         break;
    666     case Page::ViewModeMinimized:
    667         result = viewModeCSSKeywordID == CSSValueMinimized;
    668         break;
    669     default:
    670         result = false;
    671         break;
    672     }
    673 
    674     return result;
    675 }
     605    }
     606
     607    return false;
     608}
     609
    676610#endif // ENABLE(VIEW_MODE_CSS_MEDIA)
    677611
    678 static bool video_playable_inlineMediaFeatureEval(CSSValue*, const CSSToLengthConversionData&, Frame* frame, MediaFeaturePrefix)
    679 {
    680     return frame->settings().allowsInlineMediaPlayback();
    681 }
    682 
    683 static bool hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
     612static bool videoPlayableInlineEvaluate(CSSValue*, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix)
     613{
     614    return frame.settings().allowsInlineMediaPlayback();
     615}
     616
     617static bool hoverEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
    684618{
    685619    if (!is<CSSPrimitiveValue>(value)) {
     
    691625    }
    692626
    693     int hoverCSSKeywordID = downcast<CSSPrimitiveValue>(*value).getValueID();
     627    auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID();
    694628#if ENABLE(TOUCH_EVENTS)
    695     return hoverCSSKeywordID == CSSValueNone;
     629    return keyword == CSSValueNone;
    696630#else
    697     return hoverCSSKeywordID == CSSValueHover;
     631    return keyword == CSSValueHover;
    698632#endif
    699633}
    700634
    701 static bool any_hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame* frame, MediaFeaturePrefix prefix)
    702 {
    703     return hoverMediaFeatureEval(value, cssToLengthConversionData, frame, prefix);
    704 }
    705 
    706 static bool pointerMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)
     635static bool anyHoverEvaluate(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame& frame, MediaFeaturePrefix prefix)
     636{
     637    return hoverEvaluate(value, cssToLengthConversionData, frame, prefix);
     638}
     639
     640static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix)
    707641{
    708642    if (!is<CSSPrimitiveValue>(value))
    709643        return true;
    710644
    711     int pointerCSSKeywordID = downcast<CSSPrimitiveValue>(*value).getValueID();
     645    auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID();
    712646#if ENABLE(TOUCH_EVENTS)
    713     return pointerCSSKeywordID == CSSValueCoarse;
     647    return keyword == CSSValueCoarse;
    714648#else
    715     return pointerCSSKeywordID == CSSValueFine;
     649    return keyword == CSSValueFine;
    716650#endif
    717651}
    718652
    719 static bool any_pointerMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame* frame, MediaFeaturePrefix prefix)
    720 {
    721     return pointerMediaFeatureEval(value, cssToLengthConversionData, frame, prefix);
    722 }
    723 
    724 static void createFunctionMap()
    725 {
    726     // Create the table.
    727     gFunctionMap = new FunctionMap;
    728 #define ADD_TO_FUNCTIONMAP(name, str)  \
    729     gFunctionMap->set(name##MediaFeature.impl(), name##MediaFeatureEval);
    730     CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
     653static bool anyPointerEvaluate(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame& frame, MediaFeaturePrefix prefix)
     654{
     655    return pointerEvaluate(value, cssToLengthConversionData, frame, prefix);
     656}
     657
     658// Use this function instead of calling add directly to avoid inlining.
     659static void add(MediaQueryFunctionMap& map, AtomicStringImpl* key, MediaQueryFunction value)
     660{
     661    map.add(key, value);
     662}
     663
     664bool MediaQueryEvaluator::evaluate(const MediaQueryExpression& expression) const
     665{
     666    if (!m_frame || !m_frame->view() || !m_style)
     667        return m_fallbackResult;
     668
     669    if (!expression.isValid())
     670        return false;
     671
     672    static NeverDestroyed<MediaQueryFunctionMap> map = [] {
     673        MediaQueryFunctionMap map;
     674#define ADD_TO_FUNCTIONMAP(name, str) add(map, MediaFeatureNames::name.impl(), name##Evaluate);
     675        CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(ADD_TO_FUNCTIONMAP);
    731676#undef ADD_TO_FUNCTIONMAP
    732 }
    733 
    734 bool MediaQueryEvaluator::eval(const MediaQueryExp* expr) const
    735 {
    736     if (!m_frame || !m_frame->view() || !m_style)
    737         return m_expResult;
    738 
    739     if (!expr->isValid())
    740         return false;
    741 
    742     if (!gFunctionMap)
    743         createFunctionMap();
    744 
    745     // call the media feature evaluation function. Assume no prefix
    746     // and let trampoline functions override the prefix if prefix is
    747     // used
    748     EvalFunc func = gFunctionMap->get(expr->mediaFeature().impl());
    749     if (func) {
    750         CSSToLengthConversionData conversionData(m_style,
    751             m_frame->document()->documentElement()->renderStyle(),
    752             m_frame->document()->renderView(), 1, false);
    753         return func(expr->value(), conversionData, m_frame, NoPrefix);
    754     }
    755 
    756     return false;
     677        return map;
     678    }();
     679
     680    auto function = map.get().get(expression.mediaFeature().impl());
     681    if (!function)
     682        return false;
     683
     684    Document& document = *m_frame->document();
     685    return function(expression.value(), { m_style, document.documentElement()->renderStyle(), document.renderView(), 1, false }, *m_frame, NoPrefix);
    757686}
    758687
  • trunk/Source/WebCore/css/MediaQueryEvaluator.h

    r200098 r201441  
    2626 */
    2727
    28 #ifndef MediaQueryEvaluator_h
    29 #define MediaQueryEvaluator_h
     28#pragma once
    3029
    3130#include "MediaQueryExp.h"
    32 #include <wtf/text/WTFString.h>
    3331
    3432namespace WebCore {
     33
     34class Document;
    3535class Frame;
    36 class MediaQueryExp;
    3736class MediaQuerySet;
    3837class RenderStyle;
    3938class StyleResolver;
    4039
    41 class MediaQueryResult {
    42     WTF_MAKE_NONCOPYABLE(MediaQueryResult); WTF_MAKE_FAST_ALLOCATED;
    43 public:
    44     MediaQueryResult(const MediaQueryExp& expr, bool result)
    45         : m_expression(expr)
    46         , m_result(result)
    47     {
    48     }
    49 
    50     MediaQueryExp m_expression;
    51     bool m_result;
     40struct MediaQueryResult {
     41    MediaQueryExpression expression;
     42    bool result;
    5243};
    5344
    54 /**
    55  * Class that evaluates css media queries as defined in
    56  * CSS3 Module "Media Queries" (http://www.w3.org/TR/css3-mediaqueries/)
    57  * Special constructors are needed, if simple media queries are to be
    58  * evaluated without knowledge of the medium features. This can happen
    59  * for example when parsing UA stylesheets, if evaluation is done
    60  * right after parsing.
    61  *
    62  * the boolean parameter is used to approximate results of evaluation, if
    63  * the device characteristics are not known. This can be used to prune the loading
    64  * of stylesheets to only those which are probable to match.
    65  */
     45// Some of the constructors are used for cases where the device characteristics are not known.
     46// These  can be used to prune the loading of stylesheets to only those which are not already known to not match.
     47
    6648class MediaQueryEvaluator {
    67      WTF_MAKE_NONCOPYABLE(MediaQueryEvaluator); WTF_MAKE_FAST_ALLOCATED;
    6849public:
    69     /** Creates evaluator which evaluates only simple media queries
    70      *  Evaluator returns true for "all", and returns value of \mediaFeatureResult
    71      *  for any media features
    72      */
     50    // Creates evaluator which evaluates only simple media queries.
     51    // Evaluator returns true for "all", and returns value of \mediaFeatureResult for any media features.
    7352    explicit MediaQueryEvaluator(bool mediaFeatureResult = false);
    7453
    75     /** Creates evaluator which evaluates only simple media queries
    76      *  Evaluator  returns true for acceptedMediaType and returns value of \mediafeatureResult
    77      *  for any media features
    78      */
     54    // Creates evaluator which evaluates only simple media queries.
     55    // Evaluator returns true for acceptedMediaType and returns value of \mediaFeatureResult for any media features.
    7956    MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult = false);
    8057
    81     /** Creates evaluator which evaluates full media queries
    82      */
    83     MediaQueryEvaluator(const String& acceptedMediaType, Frame*, const RenderStyle*);
    84 
    85     ~MediaQueryEvaluator();
     58    // Creates evaluator which evaluates full media queries.
     59    MediaQueryEvaluator(const String& acceptedMediaType, Document&, const RenderStyle*);
    8660
    8761    bool mediaTypeMatch(const String& mediaTypeToMatch) const;
    8862    bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const;
    8963
    90     /** Evaluates a list of media queries */
    91     bool eval(const MediaQuerySet*, StyleResolver* = 0) const;
     64    // Evaluates a list of media queries.
     65    bool evaluate(const MediaQuerySet&, StyleResolver* = nullptr) const;
    9266
    93     /** Evaluates media query subexpression, ie "and (media-feature: value)" part */
    94     bool eval(const MediaQueryExp*) const;
    95    
    96     /* Evaluates a list of media queries and fills in a vector with any viewport-dependent results found. */
    97     bool evalCheckingViewportDependentResults(const MediaQuerySet*, Vector<std::unique_ptr<MediaQueryResult>>&);
     67    // Evaluates media query subexpression, ie "and (media-feature: value)" part.
     68    bool evaluate(const MediaQueryExpression&) const;
     69
     70    // Evaluates a list of media queries and fills in a vector with any viewport-dependent results found.
     71    bool evaluate(const MediaQuerySet&, Vector<MediaQueryResult>&) const;
    9872
    9973private:
     
    10175    Frame* m_frame { nullptr }; // not owned
    10276    const RenderStyle* m_style { nullptr };
    103     bool m_expResult;
     77    bool m_fallbackResult { false };
    10478};
    10579
    10680} // namespace
    107 #endif
  • trunk/Source/WebCore/css/MediaQueryExp.cpp

    r199024 r201441  
    3333#include "CSSPrimitiveValue.h"
    3434#include "CSSValueList.h"
     35#include "MediaFeatureNames.h"
    3536#include <wtf/text/StringBuilder.h>
    3637
    3738namespace WebCore {
    3839
    39 static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const CSSParserValue* value)
    40 {
    41     if (!value->id)
    42         return false;
    43 
    44     return mediaFeature == MediaFeatureNames::orientationMediaFeature
     40static inline bool isFeatureValidWithIdentifier(const AtomicString& mediaFeature, const CSSParserValue& value)
     41{
     42    if (!value.id)
     43        return false;
     44
     45    return mediaFeature == MediaFeatureNames::orientation
    4546#if ENABLE(VIEW_MODE_CSS_MEDIA)
    46         || mediaFeature == MediaFeatureNames::view_modeMediaFeature
    47 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
    48         || mediaFeature == MediaFeatureNames::color_gamutMediaFeature
    49         || mediaFeature == MediaFeatureNames::any_hoverMediaFeature
    50         || mediaFeature == MediaFeatureNames::any_pointerMediaFeature
    51         || mediaFeature == MediaFeatureNames::hoverMediaFeature
    52         || mediaFeature == MediaFeatureNames::inverted_colorsMediaFeature
    53         || mediaFeature == MediaFeatureNames::pointerMediaFeature;
    54 }
    55 
    56 static inline bool featureWithValidPositiveLenghtOrNumber(const AtomicString& mediaFeature, const CSSParserValue* value)
    57 {
    58     if (!(CSSPrimitiveValue::isLength(value->unit) || value->unit == CSSPrimitiveValue::CSS_NUMBER) || value->fValue < 0)
    59         return false;
    60 
    61     return mediaFeature == MediaFeatureNames::heightMediaFeature
    62         || mediaFeature == MediaFeatureNames::max_heightMediaFeature
    63         || mediaFeature == MediaFeatureNames::min_heightMediaFeature
    64         || mediaFeature == MediaFeatureNames::widthMediaFeature
    65         || mediaFeature == MediaFeatureNames::max_widthMediaFeature
    66         || mediaFeature == MediaFeatureNames::min_widthMediaFeature
    67         || mediaFeature == MediaFeatureNames::device_heightMediaFeature
    68         || mediaFeature == MediaFeatureNames::max_device_heightMediaFeature
    69         || mediaFeature == MediaFeatureNames::min_device_heightMediaFeature
    70         || mediaFeature == MediaFeatureNames::device_widthMediaFeature
    71         || mediaFeature == MediaFeatureNames::max_device_widthMediaFeature
    72         || mediaFeature == MediaFeatureNames::min_device_widthMediaFeature;
    73 }
    74 
    75 static inline bool featureWithValidDensity(const AtomicString& mediaFeature, const CSSParserValue* value)
    76 {
    77     if (!CSSPrimitiveValue::isResolution(value->unit) || value->fValue <= 0)
    78         return false;
    79 
    80     return mediaFeature == MediaFeatureNames::resolutionMediaFeature
    81         || mediaFeature == MediaFeatureNames::max_resolutionMediaFeature
    82         || mediaFeature == MediaFeatureNames::min_resolutionMediaFeature;
    83 }
    84 
    85 static inline bool featureWithPositiveInteger(const AtomicString& mediaFeature, const CSSParserValue* value)
    86 {
    87     if (!value->isInt || value->fValue < 0)
    88         return false;
    89 
    90     return mediaFeature == MediaFeatureNames::colorMediaFeature
    91         || mediaFeature == MediaFeatureNames::max_colorMediaFeature
    92         || mediaFeature == MediaFeatureNames::min_colorMediaFeature
    93         || mediaFeature == MediaFeatureNames::color_indexMediaFeature
    94         || mediaFeature == MediaFeatureNames::max_color_indexMediaFeature
    95         || mediaFeature == MediaFeatureNames::min_color_indexMediaFeature
    96         || mediaFeature == MediaFeatureNames::min_monochromeMediaFeature
    97         || mediaFeature == MediaFeatureNames::max_monochromeMediaFeature;
    98 }
    99 
    100 static inline bool featureWithPositiveNumber(const AtomicString& mediaFeature, const CSSParserValue* value)
    101 {
    102     if (value->unit != CSSPrimitiveValue::CSS_NUMBER || value->fValue < 0)
    103         return false;
    104 
    105     return mediaFeature == MediaFeatureNames::transform_2dMediaFeature
    106         || mediaFeature == MediaFeatureNames::transform_3dMediaFeature
    107         || mediaFeature == MediaFeatureNames::transitionMediaFeature
    108         || mediaFeature == MediaFeatureNames::animationMediaFeature
    109         || mediaFeature == MediaFeatureNames::device_pixel_ratioMediaFeature
    110         || mediaFeature == MediaFeatureNames::max_device_pixel_ratioMediaFeature
    111         || mediaFeature == MediaFeatureNames::min_device_pixel_ratioMediaFeature;
    112 }
    113 
    114 static inline bool featureWithZeroOrOne(const AtomicString& mediaFeature, const CSSParserValue* value)
    115 {
    116     if (!value->isInt || !(value->fValue == 1 || !value->fValue))
    117         return false;
    118 
    119     return mediaFeature == MediaFeatureNames::gridMediaFeature;
    120 }
    121 
    122 static inline bool featureWithAspectRatio(const AtomicString& mediaFeature)
    123 {
    124     return mediaFeature == MediaFeatureNames::aspect_ratioMediaFeature
    125         || mediaFeature == MediaFeatureNames::device_aspect_ratioMediaFeature
    126         || mediaFeature == MediaFeatureNames::min_aspect_ratioMediaFeature
    127         || mediaFeature == MediaFeatureNames::max_aspect_ratioMediaFeature
    128         || mediaFeature == MediaFeatureNames::min_device_aspect_ratioMediaFeature
    129         || mediaFeature == MediaFeatureNames::max_device_aspect_ratioMediaFeature;
    130 }
    131 
    132 static inline bool featureWithoutValue(const AtomicString& mediaFeature)
     47        || mediaFeature == MediaFeatureNames::viewMode
     48#endif
     49        || mediaFeature == MediaFeatureNames::colorGamut
     50        || mediaFeature == MediaFeatureNames::anyHover
     51        || mediaFeature == MediaFeatureNames::anyPointer
     52        || mediaFeature == MediaFeatureNames::hover
     53        || mediaFeature == MediaFeatureNames::invertedColors
     54        || mediaFeature == MediaFeatureNames::pointer;
     55}
     56
     57static inline bool isFeatureValidWithNonNegativeLengthOrNumber(const AtomicString& mediaFeature, const CSSParserValue& value)
     58{
     59    if (!(CSSPrimitiveValue::isLength(value.unit) || value.unit == CSSPrimitiveValue::CSS_NUMBER) || value.fValue < 0)
     60        return false;
     61
     62    return mediaFeature == MediaFeatureNames::height
     63        || mediaFeature == MediaFeatureNames::maxHeight
     64        || mediaFeature == MediaFeatureNames::minHeight
     65        || mediaFeature == MediaFeatureNames::width
     66        || mediaFeature == MediaFeatureNames::maxWidth
     67        || mediaFeature == MediaFeatureNames::minWidth
     68        || mediaFeature == MediaFeatureNames::deviceHeight
     69        || mediaFeature == MediaFeatureNames::maxDeviceHeight
     70        || mediaFeature == MediaFeatureNames::minDeviceHeight
     71        || mediaFeature == MediaFeatureNames::deviceWidth
     72        || mediaFeature == MediaFeatureNames::maxDeviceWidth
     73        || mediaFeature == MediaFeatureNames::minDeviceWidth;
     74}
     75
     76static inline bool isFeatureValidWithDensity(const AtomicString& mediaFeature, const CSSParserValue& value)
     77{
     78    if (!CSSPrimitiveValue::isResolution(value.unit) || value.fValue <= 0)
     79        return false;
     80
     81    return mediaFeature == MediaFeatureNames::resolution
     82        || mediaFeature == MediaFeatureNames::maxResolution
     83        || mediaFeature == MediaFeatureNames::minResolution;
     84}
     85
     86static inline bool isFeatureValidWithNonNegativeInteger(const AtomicString& mediaFeature, const CSSParserValue& value)
     87{
     88    if (!value.isInt || value.fValue < 0)
     89        return false;
     90
     91    return mediaFeature == MediaFeatureNames::color
     92        || mediaFeature == MediaFeatureNames::maxColor
     93        || mediaFeature == MediaFeatureNames::minColor
     94        || mediaFeature == MediaFeatureNames::colorIndex
     95        || mediaFeature == MediaFeatureNames::maxColorIndex
     96        || mediaFeature == MediaFeatureNames::minColorIndex
     97        || mediaFeature == MediaFeatureNames::minMonochrome
     98        || mediaFeature == MediaFeatureNames::maxMonochrome;
     99}
     100
     101static inline bool isFeatureValidWithNonNegativeNumber(const AtomicString& mediaFeature, const CSSParserValue& value)
     102{
     103    if (value.unit != CSSPrimitiveValue::CSS_NUMBER || value.fValue < 0)
     104        return false;
     105
     106    return mediaFeature == MediaFeatureNames::transform2d
     107        || mediaFeature == MediaFeatureNames::transform3d
     108        || mediaFeature == MediaFeatureNames::transition
     109        || mediaFeature == MediaFeatureNames::animation
     110        || mediaFeature == MediaFeatureNames::devicePixelRatio
     111        || mediaFeature == MediaFeatureNames::maxDevicePixelRatio
     112        || mediaFeature == MediaFeatureNames::minDevicePixelRatio;
     113}
     114
     115static inline bool isFeatureValidWithZeroOrOne(const AtomicString& mediaFeature, const CSSParserValue& value)
     116{
     117    if (!value.isInt || !(value.fValue == 1 || !value.fValue))
     118        return false;
     119
     120    return mediaFeature == MediaFeatureNames::grid;
     121}
     122
     123static inline bool isAspectRatioFeature(const AtomicString& mediaFeature)
     124{
     125    return mediaFeature == MediaFeatureNames::aspectRatio
     126        || mediaFeature == MediaFeatureNames::deviceAspectRatio
     127        || mediaFeature == MediaFeatureNames::minAspectRatio
     128        || mediaFeature == MediaFeatureNames::maxAspectRatio
     129        || mediaFeature == MediaFeatureNames::minDeviceAspectRatio
     130        || mediaFeature == MediaFeatureNames::maxDeviceAspectRatio;
     131}
     132
     133static inline bool isFeatureValidWithoutValue(const AtomicString& mediaFeature)
    133134{
    134135    // Media features that are prefixed by min/max cannot be used without a value.
    135     return mediaFeature == MediaFeatureNames::any_hoverMediaFeature
    136         || mediaFeature == MediaFeatureNames::any_pointerMediaFeature
    137         || mediaFeature == MediaFeatureNames::monochromeMediaFeature
    138         || mediaFeature == MediaFeatureNames::colorMediaFeature
    139         || mediaFeature == MediaFeatureNames::color_indexMediaFeature
    140         || mediaFeature == MediaFeatureNames::gridMediaFeature
    141         || mediaFeature == MediaFeatureNames::heightMediaFeature
    142         || mediaFeature == MediaFeatureNames::widthMediaFeature
    143         || mediaFeature == MediaFeatureNames::device_heightMediaFeature
    144         || mediaFeature == MediaFeatureNames::device_widthMediaFeature
    145         || mediaFeature == MediaFeatureNames::orientationMediaFeature
    146         || mediaFeature == MediaFeatureNames::aspect_ratioMediaFeature
    147         || mediaFeature == MediaFeatureNames::device_aspect_ratioMediaFeature
    148         || mediaFeature == MediaFeatureNames::hoverMediaFeature
    149         || mediaFeature == MediaFeatureNames::transform_2dMediaFeature
    150         || mediaFeature == MediaFeatureNames::transform_3dMediaFeature
    151         || mediaFeature == MediaFeatureNames::transitionMediaFeature
    152         || mediaFeature == MediaFeatureNames::animationMediaFeature
    153         || mediaFeature == MediaFeatureNames::inverted_colorsMediaFeature
     136    return mediaFeature == MediaFeatureNames::anyHover
     137        || mediaFeature == MediaFeatureNames::anyPointer
     138        || mediaFeature == MediaFeatureNames::monochrome
     139        || mediaFeature == MediaFeatureNames::color
     140        || mediaFeature == MediaFeatureNames::colorIndex
     141        || mediaFeature == MediaFeatureNames::grid
     142        || mediaFeature == MediaFeatureNames::height
     143        || mediaFeature == MediaFeatureNames::width
     144        || mediaFeature == MediaFeatureNames::deviceHeight
     145        || mediaFeature == MediaFeatureNames::deviceWidth
     146        || mediaFeature == MediaFeatureNames::orientation
     147        || mediaFeature == MediaFeatureNames::aspectRatio
     148        || mediaFeature == MediaFeatureNames::deviceAspectRatio
     149        || mediaFeature == MediaFeatureNames::hover
     150        || mediaFeature == MediaFeatureNames::transform2d
     151        || mediaFeature == MediaFeatureNames::transform3d
     152        || mediaFeature == MediaFeatureNames::transition
     153        || mediaFeature == MediaFeatureNames::animation
     154        || mediaFeature == MediaFeatureNames::invertedColors
    154155#if ENABLE(VIEW_MODE_CSS_MEDIA)
    155         || mediaFeature == MediaFeatureNames::view_modeMediaFeature
    156 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)
    157         || mediaFeature == MediaFeatureNames::pointerMediaFeature
    158         || mediaFeature == MediaFeatureNames::device_pixel_ratioMediaFeature
    159         || mediaFeature == MediaFeatureNames::resolutionMediaFeature
    160         || mediaFeature == MediaFeatureNames::video_playable_inlineMediaFeature;
    161 }
    162 
    163 MediaQueryExp::MediaQueryExp(const AtomicString& mediaFeature, CSSParserValueList* valueList)
     156        || mediaFeature == MediaFeatureNames::viewMode
     157#endif
     158        || mediaFeature == MediaFeatureNames::pointer
     159        || mediaFeature == MediaFeatureNames::devicePixelRatio
     160        || mediaFeature == MediaFeatureNames::resolution
     161        || mediaFeature == MediaFeatureNames::videoPlayableInline;
     162}
     163
     164static inline bool isFeatureValidWithNumberWithUnit(const AtomicString& mediaFeature, const CSSParserValue& value)
     165{
     166    return isFeatureValidWithDensity(mediaFeature, value) || isFeatureValidWithNonNegativeLengthOrNumber(mediaFeature, value);
     167}
     168
     169static inline bool isFeatureValidWithNumber(const AtomicString& mediaFeature, const CSSParserValue& value)
     170{
     171    return isFeatureValidWithNonNegativeInteger(mediaFeature, value) || isFeatureValidWithNonNegativeNumber(mediaFeature, value) || isFeatureValidWithZeroOrOne(mediaFeature, value);
     172}
     173
     174static inline bool isSlash(CSSParserValue& value)
     175{
     176    return value.unit == CSSParserValue::Operator && value.iValue == '/';
     177}
     178
     179static inline bool isPositiveIntegerValue(CSSParserValue& value)
     180{
     181    return value.unit == CSSPrimitiveValue::CSS_NUMBER && value.fValue > 0 && value.isInt;
     182}
     183
     184MediaQueryExpression::MediaQueryExpression(const AtomicString& mediaFeature, CSSParserValueList* valueList)
    164185    : m_mediaFeature(mediaFeature)
    165186{
    166     // Initialize media query expression that must have 1 or more values.
    167     if (valueList) {
    168         if (valueList->size() == 1) {
    169             CSSParserValue* value = valueList->current();
    170 
    171             // Media features that use CSSValueIDs.
    172             if (featureWithCSSValueID(mediaFeature, value))
    173                 m_value = CSSPrimitiveValue::createIdentifier(value->id);
    174 
    175             // Media features that must have non-negative <density>, ie. dppx, dpi or dpcm.
    176             else if (featureWithValidDensity(mediaFeature, value))
    177                 m_value = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
    178 
    179             // Media features that must have non-negative <lenght> or number value.
    180             else if (featureWithValidPositiveLenghtOrNumber(mediaFeature, value))
    181                 m_value = CSSPrimitiveValue::create(value->fValue, (CSSPrimitiveValue::UnitTypes) value->unit);
    182 
    183             // Media features that must have non-negative integer value.
    184             else if (featureWithPositiveInteger(mediaFeature, value))
    185                 m_value = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_NUMBER);
    186 
    187             // Media features that must have non-negative number value.
    188             else if (featureWithPositiveNumber(mediaFeature, value))
    189                 m_value = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_NUMBER);
    190 
    191             // Media features that must have (0|1) value.
    192             else if (featureWithZeroOrOne(mediaFeature, value))
    193                 m_value = CSSPrimitiveValue::create(value->fValue, CSSPrimitiveValue::CSS_NUMBER);
    194 
    195             m_isValid = m_value;
    196         } else if (valueList->size() == 3 && featureWithAspectRatio(mediaFeature)) {
    197             // Create list of values.
    198             // Currently accepts only <integer>/<integer>.
    199             // Applicable to device-aspect-ratio and aspec-ratio.
    200             bool isValid = true;
    201             float numeratorValue = 0;
    202             float denominatorValue = 0;
    203 
    204             // The aspect-ratio must be <integer> (whitespace)? / (whitespace)? <integer>.
    205             for (unsigned i = 0; i < 3; ++i, valueList->next()) {
    206                 const CSSParserValue* value = valueList->current();
    207                 if (i != 1 && value->unit == CSSPrimitiveValue::CSS_NUMBER && value->fValue > 0 && value->isInt) {
    208                     if (!i)
    209                         numeratorValue = value->fValue;
    210                     else
    211                         denominatorValue = value->fValue;
    212                 } else if (i == 1 && value->unit == CSSParserValue::Operator && value->iValue == '/')
    213                     continue;
    214                 else {
    215                     isValid = false;
    216                     break;
    217                 }
    218             }
    219 
    220             if (isValid)
    221                 m_value = CSSAspectRatioValue::create(numeratorValue, denominatorValue);
    222 
    223             m_isValid = m_value;
     187    if (!valueList) {
     188        if (isFeatureValidWithoutValue(mediaFeature))
     189            m_isValid = true;
     190    } else if (valueList->size() == 1) {
     191        auto& value = *valueList->valueAt(0);
     192        if (isFeatureValidWithIdentifier(mediaFeature, value)) {
     193            m_value = CSSPrimitiveValue::createIdentifier(value.id);
     194            m_isValid = true;
     195        } else if (isFeatureValidWithNumberWithUnit(mediaFeature, value) || isFeatureValidWithNonNegativeLengthOrNumber(mediaFeature, value)) {
     196            m_value = CSSPrimitiveValue::create(value.fValue, (CSSPrimitiveValue::UnitTypes) value.unit);
     197            m_isValid = true;
     198        } else if (isFeatureValidWithNumber(mediaFeature, value)) {
     199            // FIXME: Can we merge this with the case above?
     200            m_value = CSSPrimitiveValue::create(value.fValue, CSSPrimitiveValue::CSS_NUMBER);
     201            m_isValid = true;
    224202        }
    225     } else if (featureWithoutValue(mediaFeature))
    226         m_isValid = true;
    227 }
    228 
    229 String MediaQueryExp::serialize() const
     203    } else if (valueList->size() == 3 && isAspectRatioFeature(mediaFeature)) {
     204        auto& numerator = *valueList->valueAt(0);
     205        auto& slash = *valueList->valueAt(1);
     206        auto& denominator = *valueList->valueAt(2);
     207        if (isPositiveIntegerValue(numerator) && isSlash(slash) && isPositiveIntegerValue(denominator)) {
     208            m_value = CSSAspectRatioValue::create(numerator.fValue, denominator.fValue);
     209            m_isValid = true;
     210        }
     211    }
     212}
     213
     214String MediaQueryExpression::serialize() const
    230215{
    231216    if (!m_serializationCache.isNull())
  • trunk/Source/WebCore/css/MediaQueryExp.h

    r195310 r201441  
    2626 */
    2727
    28 #ifndef MediaQueryExp_h
    29 #define MediaQueryExp_h
     28#pragma once
    3029
    3130#include "CSSValue.h"
    32 #include "MediaFeatureNames.h"
    3331#include <memory>
    34 #include <wtf/text/AtomicString.h>
    3532
    3633namespace WebCore {
     
    3835class CSSParserValueList;
    3936
    40 class MediaQueryExp {
     37// FIXME: Rename the file to match this class's name.
     38class MediaQueryExpression {
    4139    WTF_MAKE_FAST_ALLOCATED;
    4240public:
    43     explicit MediaQueryExp(const AtomicString& mediaFeature = emptyAtom, CSSParserValueList* values = nullptr);
     41    explicit MediaQueryExpression(const AtomicString& mediaFeature = emptyAtom, CSSParserValueList* values = nullptr);
    4442
    4543    const AtomicString& mediaFeature() const;
     
    4745
    4846    bool isValid() const;
    49     bool isViewportDependent() const;
    5047
    5148    String serialize() const;
    5249
    53     bool operator==(const MediaQueryExp&) const;
     50    bool operator==(const MediaQueryExpression&) const;
    5451
    5552private:
     
    6057};
    6158
    62 inline const AtomicString& MediaQueryExp::mediaFeature() const
     59inline const AtomicString& MediaQueryExpression::mediaFeature() const
    6360{
    6461    return m_mediaFeature;
    6562}
    6663
    67 inline CSSValue* MediaQueryExp::value() const
     64inline CSSValue* MediaQueryExpression::value() const
    6865{
    6966    return m_value.get();
    7067}
    7168
    72 inline bool MediaQueryExp::operator==(const MediaQueryExp& other) const
     69inline bool MediaQueryExpression::operator==(const MediaQueryExpression& other) const
    7370{
    74     return (other.m_mediaFeature == m_mediaFeature)
    75         && ((!other.m_value && !m_value)
    76             || (other.m_value && m_value && other.m_value->equals(*m_value)));
     71    return other.m_mediaFeature == m_mediaFeature
     72        && ((!m_value && !other.m_value) || (m_value && other.m_value && *m_value == *other.m_value));
    7773}
    7874
    79 inline bool MediaQueryExp::isValid() const
     75inline bool MediaQueryExpression::isValid() const
    8076{
    8177    return m_isValid;
    8278}
    8379
    84 inline bool MediaQueryExp::isViewportDependent() const
    85 {
    86     return m_mediaFeature == MediaFeatureNames::widthMediaFeature
    87         || m_mediaFeature == MediaFeatureNames::heightMediaFeature
    88         || m_mediaFeature == MediaFeatureNames::min_widthMediaFeature
    89         || m_mediaFeature == MediaFeatureNames::min_heightMediaFeature
    90         || m_mediaFeature == MediaFeatureNames::max_widthMediaFeature
    91         || m_mediaFeature == MediaFeatureNames::max_heightMediaFeature
    92         || m_mediaFeature == MediaFeatureNames::orientationMediaFeature
    93         || m_mediaFeature == MediaFeatureNames::aspect_ratioMediaFeature
    94         || m_mediaFeature == MediaFeatureNames::min_aspect_ratioMediaFeature
    95         || m_mediaFeature == MediaFeatureNames::max_aspect_ratioMediaFeature;
    96 }
    97 
    9880} // namespace
    99 
    100 #endif
  • trunk/Source/WebCore/css/MediaQueryList.cpp

    r185238 r201441  
    2828namespace WebCore {
    2929
    30 Ref<MediaQueryList> MediaQueryList::create(PassRefPtr<MediaQueryMatcher> vector, PassRefPtr<MediaQuerySet> media, bool matches)
     30inline MediaQueryList::MediaQueryList(MediaQueryMatcher& matcher, Ref<MediaQuerySet>&& media, bool matches)
     31    : m_matcher(matcher)
     32    , m_media(WTFMove(media))
     33    , m_evaluationRound(m_matcher->evaluationRound())
     34    , m_changeRound(m_evaluationRound - 1) // Any value that is not the same as m_evaluationRound would do.
     35    , m_matches(matches)
    3136{
    32     return adoptRef(*new MediaQueryList(vector, media, matches));
    3337}
    3438
    35 MediaQueryList::MediaQueryList(PassRefPtr<MediaQueryMatcher> vector, PassRefPtr<MediaQuerySet> media, bool matches)
    36     : m_matcher(vector)
    37     , m_media(media)
    38     , m_evaluationRound(m_matcher->evaluationRound())
    39     , m_changeRound(m_evaluationRound - 1) // m_evaluationRound and m_changeRound initial values must be different.
    40     , m_matches(matches)
     39Ref<MediaQueryList> MediaQueryList::create(MediaQueryMatcher& matcher, Ref<MediaQuerySet>&& media, bool matches)
    4140{
     41    return adoptRef(*new MediaQueryList(matcher, WTFMove(media), matches));
    4242}
    4343
     
    5151}
    5252
    53 void MediaQueryList::addListener(PassRefPtr<MediaQueryListListener> listener)
     53void MediaQueryList::addListener(RefPtr<MediaQueryListListener>&& listener)
    5454{
    5555    if (!listener)
    5656        return;
    5757
    58     m_matcher->addListener(listener, this);
     58    m_matcher->addListener(listener.releaseNonNull(), *this);
    5959}
    6060
    61 void MediaQueryList::removeListener(PassRefPtr<MediaQueryListListener> listener)
     61void MediaQueryList::removeListener(RefPtr<MediaQueryListListener>&& listener)
    6262{
    6363    if (!listener)
    6464        return;
    6565
    66     m_matcher->removeListener(listener.get(), this);
     66    m_matcher->removeListener(*listener, *this);
    6767}
    6868
    69 void MediaQueryList::evaluate(MediaQueryEvaluator* evaluator, bool& notificationNeeded)
     69void MediaQueryList::evaluate(MediaQueryEvaluator& evaluator, bool& notificationNeeded)
    7070{
    71     if (m_evaluationRound != m_matcher->evaluationRound() && evaluator)
    72         setMatches(evaluator->eval(m_media.get()));
     71    if (m_evaluationRound != m_matcher->evaluationRound())
     72        setMatches(evaluator.evaluate(m_media.get()));
    7373    notificationNeeded = m_changeRound == m_matcher->evaluationRound();
    7474}
  • trunk/Source/WebCore/css/MediaQueryList.h

    r185238 r201441  
    1818 */
    1919
    20 #ifndef MediaQueryList_h
    21 #define MediaQueryList_h
     20#pragma once
    2221
    2322#include <wtf/Forward.h>
     
    3938class MediaQueryList : public RefCounted<MediaQueryList> {
    4039public:
    41     static Ref<MediaQueryList> create(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool);
     40    static Ref<MediaQueryList> create(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool);
    4241    ~MediaQueryList();
    4342
     
    4544    bool matches();
    4645
    47     void addListener(PassRefPtr<MediaQueryListListener>);
    48     void removeListener(PassRefPtr<MediaQueryListListener>);
     46    void addListener(RefPtr<MediaQueryListListener>&&);
     47    void removeListener(RefPtr<MediaQueryListListener>&&);
    4948
    50     void evaluate(MediaQueryEvaluator*, bool& notificationNeeded);
     49    void evaluate(MediaQueryEvaluator&, bool& notificationNeeded);
    5150
    5251private:
    53     MediaQueryList(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool matches);
     52    MediaQueryList(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool matches);
     53
    5454    void setMatches(bool);
    5555
    56     RefPtr<MediaQueryMatcher> m_matcher;
    57     RefPtr<MediaQuerySet> m_media;
     56    Ref<MediaQueryMatcher> m_matcher;
     57    Ref<MediaQuerySet> m_media;
    5858    unsigned m_evaluationRound; // Indicates if the query has been evaluated after the last style selector change.
    5959    unsigned m_changeRound; // Used to know if the query has changed in the last style selector change.
     
    6262
    6363}
    64 
    65 #endif // MediaQueryList_h
  • trunk/Source/WebCore/css/MediaQueryMatcher.cpp

    r201333 r201441  
    2222
    2323#include "Document.h"
    24 #include "Element.h"
    2524#include "Frame.h"
    2625#include "FrameView.h"
     
    3433namespace WebCore {
    3534
    36 MediaQueryMatcher::Listener::Listener(PassRefPtr<MediaQueryListListener> listener, PassRefPtr<MediaQueryList> query)
    37     : m_listener(listener)
    38     , m_query(query)
     35MediaQueryMatcher::MediaQueryMatcher(Document& document)
     36    : m_document(&document)
    3937{
    40 }
    41 
    42 MediaQueryMatcher::Listener::~Listener()
    43 {
    44 }
    45 
    46 void MediaQueryMatcher::Listener::evaluate(MediaQueryEvaluator* evaluator)
    47 {
    48     bool notify;
    49     m_query->evaluate(evaluator, notify);
    50     if (notify)
    51         m_listener->queryChanged(m_query.get());
    52 }
    53 
    54 MediaQueryMatcher::MediaQueryMatcher(Document* document)
    55     : m_document(document)
    56     , m_evaluationRound(1)
    57 {
    58     ASSERT(m_document);
    5938}
    6039
     
    6645{
    6746    m_listeners.clear();
    68     m_document = 0;
     47    m_document = nullptr;
    6948}
    7049
     
    8261        return nullptr;
    8362
    84     Element* documentElement = m_document->documentElement();
     63    auto* documentElement = m_document->documentElement();
    8564    if (!documentElement)
    8665        return nullptr;
     
    8968}
    9069
    91 bool MediaQueryMatcher::evaluate(const MediaQuerySet* media)
     70bool MediaQueryMatcher::evaluate(const MediaQuerySet& media)
    9271{
    93     if (!media)
    94         return false;
    95 
    9672    auto style = documentElementUserAgentStyle();
    9773    if (!style)
    9874        return false;
    99     MediaQueryEvaluator evaluator(mediaType(), m_document->frame(), style.get());
    100     return evaluator.eval(media);
     75    return MediaQueryEvaluator { mediaType(), *m_document, style.get() }.evaluate(media);
    10176}
    10277
     
    10681        return nullptr;
    10782
    108     RefPtr<MediaQuerySet> media = MediaQuerySet::create(query);
    109 #if ENABLE(RESOLUTION_MEDIA_QUERY)
    110     // Add warning message to inspector whenever dpi/dpcm values are used for "screen" media.
    111     reportMediaQueryWarningIfNeeded(m_document, media.get());
    112 #endif
    113     return MediaQueryList::create(this, media, evaluate(media.get()));
     83    auto media = MediaQuerySet::create(query);
     84    reportMediaQueryWarningIfNeeded(m_document, media.ptr());
     85    bool result = evaluate(media.get());
     86    return MediaQueryList::create(*this, WTFMove(media), result);
    11487}
    11588
    116 void MediaQueryMatcher::addListener(PassRefPtr<MediaQueryListListener> listener, PassRefPtr<MediaQueryList> query)
     89void MediaQueryMatcher::addListener(Ref<MediaQueryListListener>&& listener, MediaQueryList& query)
    11790{
    11891    if (!m_document)
    11992        return;
    12093
    121     for (size_t i = 0; i < m_listeners.size(); ++i) {
    122         if (*m_listeners[i]->listener() == *listener && m_listeners[i]->query() == query)
     94    for (auto& existingListener : m_listeners) {
     95        if (existingListener.listener.get() == listener.get() && existingListener.query.ptr() == &query)
    12396            return;
    12497    }
    12598
    126     m_listeners.append(std::make_unique<Listener>(listener, query));
     99    m_listeners.append(Listener { WTFMove(listener), query });
    127100}
    128101
    129 void MediaQueryMatcher::removeListener(MediaQueryListListener* listener, MediaQueryList* query)
     102void MediaQueryMatcher::removeListener(MediaQueryListListener& listener, MediaQueryList& query)
    130103{
    131     if (!m_document)
    132         return;
    133 
    134     m_listeners.removeFirstMatching([listener, query](auto& current) {
    135         return *current->listener() == *listener && current->query() == query;
     104    m_listeners.removeFirstMatching([&listener, &query](auto& existingListener) {
     105        return existingListener.listener.get() == listener && existingListener.query.ptr() == &query;
    136106    });
    137107}
     
    146116    if (!style)
    147117        return;
    148     MediaQueryEvaluator evaluator(mediaType(), m_document->frame(), style.get());
    149     for (size_t i = 0; i < m_listeners.size(); ++i)
    150         m_listeners[i]->evaluate(&evaluator);
     118
     119    MediaQueryEvaluator evaluator { mediaType(), *m_document, style.get() };
     120    for (auto& listener : m_listeners) {
     121        bool notify;
     122        listener.query->evaluate(evaluator, notify);
     123        if (notify)
     124            listener.listener->queryChanged(listener.query.ptr());
     125    }
    151126}
    152127
  • trunk/Source/WebCore/css/MediaQueryMatcher.h

    r199964 r201441  
    1818 */
    1919
    20 #ifndef MediaQueryMatcher_h
    21 #define MediaQueryMatcher_h
     20#pragma once
    2221
    2322#include <memory>
     
    3837// MediaQueryList x MediaQueryListListener. It is responsible for evaluating the queries
    3938// whenever it is needed and to call the listeners if the corresponding query has changed.
    40 // The listeners must be called in the very same order in which they have been added.
     39// The listeners must be called in the order in which they were added.
    4140
    4241class MediaQueryMatcher : public RefCounted<MediaQueryMatcher> {
    4342public:
    44     static Ref<MediaQueryMatcher> create(Document* document) { return adoptRef(*new MediaQueryMatcher(document)); }
     43    static Ref<MediaQueryMatcher> create(Document& document) { return adoptRef(*new MediaQueryMatcher(document)); }
    4544    ~MediaQueryMatcher();
     45
    4646    void documentDestroyed();
    4747
    48     void addListener(PassRefPtr<MediaQueryListListener>, PassRefPtr<MediaQueryList>);
    49     void removeListener(MediaQueryListListener*, MediaQueryList*);
     48    void addListener(Ref<MediaQueryListListener>&&, MediaQueryList&);
     49    void removeListener(MediaQueryListListener&, MediaQueryList&);
    5050
    5151    RefPtr<MediaQueryList> matchMedia(const String&);
    5252
    5353    unsigned evaluationRound() const { return m_evaluationRound; }
     54
    5455    void styleResolverChanged();
    55     bool evaluate(const MediaQuerySet*);
     56
     57    bool evaluate(const MediaQuerySet&);
    5658
    5759private:
    58     class Listener {
    59         WTF_MAKE_FAST_ALLOCATED;
    60     public:
    61         Listener(PassRefPtr<MediaQueryListListener>, PassRefPtr<MediaQueryList>);
    62         ~Listener();
    63 
    64         void evaluate(MediaQueryEvaluator*);
    65 
    66         MediaQueryListListener* listener() { return m_listener.get(); }
    67         MediaQueryList* query() { return m_query.get(); }
    68 
    69     private:
    70         RefPtr<MediaQueryListListener> m_listener;
    71         RefPtr<MediaQueryList> m_query;
     60    struct Listener {
     61        Ref<MediaQueryListListener> listener;
     62        Ref<MediaQueryList> query;
    7263    };
    7364
    74     MediaQueryMatcher(Document*);
     65    explicit MediaQueryMatcher(Document&);
    7566    std::unique_ptr<RenderStyle> documentElementUserAgentStyle() const;
    7667    String mediaType() const;
    7768
    7869    Document* m_document;
    79     Vector<std::unique_ptr<Listener>> m_listeners;
     70    Vector<Listener> m_listeners;
    8071
    8172    // This value is incremented at style selector changes.
    8273    // It is used to avoid evaluating queries more then once and to make sure
    8374    // that a media query result change is notified exactly once.
    84     unsigned m_evaluationRound;
     75    unsigned m_evaluationRound { 1 };
    8576};
    8677
    8778} // namespace WebCore
    88 
    89 #endif // MediaQueryMatcher_h
  • trunk/Source/WebCore/css/RuleSet.cpp

    r201290 r201441  
    338338        else if (is<StyleRuleMedia>(*rule)) {
    339339            auto& mediaRule = downcast<StyleRuleMedia>(*rule);
    340             if ((!mediaRule.mediaQueries() || medium.eval(mediaRule.mediaQueries(), resolver)))
     340            if ((!mediaRule.mediaQueries() || medium.evaluate(*mediaRule.mediaQueries(), resolver)))
    341341                addChildRules(mediaRule.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags);
    342342        } else if (is<StyleRuleFontFace>(*rule) && resolver) {
     
    364364{
    365365    for (auto& rule : sheet.importRules()) {
    366         if (rule->styleSheet() && (!rule->mediaQueries() || medium.eval(rule->mediaQueries(), resolver)))
     366        if (rule->styleSheet() && (!rule->mediaQueries() || medium.evaluate(*rule->mediaQueries(), resolver)))
    367367            addRulesFromSheet(*rule->styleSheet(), medium, resolver);
    368368    }
  • trunk/Source/WebCore/css/SourceSizeList.cpp

    r200098 r201441  
    2525#include "CSSToLengthConversionData.h"
    2626#include "MediaList.h"
    27 #include "MediaQuery.h"
    2827#include "MediaQueryEvaluator.h"
    29 #include "MediaQueryExp.h"
    3028#include "RenderStyle.h"
    3129#include "RenderView.h"
     
    3331namespace WebCore {
    3432
    35 static bool match(std::unique_ptr<MediaQueryExp>&& expression, const RenderStyle& style, Frame* frame)
     33static bool match(const MediaQueryExpression& expression, const RenderStyle& style, Document& document)
    3634{
    37     if (expression->mediaFeature().isEmpty())
    38         return true;
    39 
    40     auto expList = std::make_unique<Vector<std::unique_ptr<MediaQueryExp>>>();
    41     expList->append(WTFMove(expression));
    42 
    43     RefPtr<MediaQuerySet> mediaQuerySet = MediaQuerySet::create();
    44     mediaQuerySet->addMediaQuery(std::make_unique<MediaQuery>(MediaQuery::None, "all", WTFMove(expList)));
    45 
    46     MediaQueryEvaluator mediaQueryEvaluator("screen", frame, &style);
    47     return mediaQueryEvaluator.eval(mediaQuerySet.get());
     35    return expression.mediaFeature().isEmpty() || MediaQueryEvaluator { "screen", document, &style }.evaluate(expression);
    4836}
    4937
    50 static float defaultLength(const RenderStyle& style, RenderView* view)
     38static float defaultLength(const RenderStyle& style, RenderView& renderer)
    5139{
    52     return clampTo<float>(CSSPrimitiveValue::computeNonCalcLengthDouble(CSSToLengthConversionData(&style, &style, view), CSSPrimitiveValue::CSS_VW, 100.0));
     40    return clampTo<float>(CSSPrimitiveValue::computeNonCalcLengthDouble({ &style, &style, &renderer }, CSSPrimitiveValue::CSS_VW, 100.0));
    5341}
    5442
    55 static float computeLength(CSSValue* value, const RenderStyle& style, RenderView* view)
     43static float computeLength(CSSValue& value, const RenderStyle& style, RenderView& renderer)
    5644{
    57     CSSToLengthConversionData conversionData(&style, &style, view);
     45    CSSToLengthConversionData conversionData(&style, &style, &renderer);
    5846    if (is<CSSPrimitiveValue>(value)) {
    59         CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(*value);
     47        CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value);
    6048        if (!primitiveValue.isLength())
    61             return defaultLength(style, view);
     49            return defaultLength(style, renderer);
    6250        return primitiveValue.computeLength<float>(conversionData);
    6351    }
    6452    if (is<CSSCalcValue>(value))
    65         return downcast<CSSCalcValue>(*value).computeLengthPx(conversionData);
    66     return defaultLength(style, view);
     53        return downcast<CSSCalcValue>(value).computeLengthPx(conversionData);
     54    return defaultLength(style, renderer);
    6755}
    6856
    69 float parseSizesAttribute(StringView sizesAttribute, RenderView* view, Frame* frame)
     57float parseSizesAttribute(Document& document, StringView sizesAttribute)
    7058{
    71     if (!view)
     59    auto* renderer = document.renderView();
     60    if (!renderer)
    7261        return 0;
    73     auto& style = view->style();
     62    auto& style = renderer->style();
    7463    for (auto& sourceSize : CSSParser(CSSStrictMode).parseSizesAttribute(sizesAttribute)) {
    75         if (match(WTFMove(sourceSize.expression), style, frame))
    76             return computeLength(sourceSize.length.get(), style, view);
     64        if (match(sourceSize.expression, style, document))
     65            return computeLength(sourceSize.length.get(), style, *renderer);
    7766    }
    78     return defaultLength(style, view);
     67    return defaultLength(style, *renderer);
    7968}
    8069
  • trunk/Source/WebCore/css/SourceSizeList.h

    r183984 r201441  
    1919 */
    2020
    21 #ifndef SourceSizeList_h
    22 #define SourceSizeList_h
     21#pragma once
    2322
    2423#include <wtf/Forward.h>
     
    2625namespace WebCore {
    2726
    28 class Frame;
    29 class RenderView;
     27class Document;
    3028
    31 float parseSizesAttribute(StringView sizesAttribute, RenderView*, Frame*);
     29float parseSizesAttribute(Document&, StringView sizesAttribute);
    3230
    3331} // namespace WebCore
    34 
    35 #endif // SourceSizeList_h
  • trunk/Source/WebCore/css/StyleMedia.cpp

    r199964 r201441  
    6464    auto rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), MatchOnlyUserAgentRules).renderStyle;
    6565
    66     RefPtr<MediaQuerySet> media = MediaQuerySet::create();
     66    auto media = MediaQuerySet::create();
    6767    if (!media->parse(query))
    6868        return false;
    6969
    70     MediaQueryEvaluator screenEval(type(), m_frame, rootStyle.get());
    71     return screenEval.eval(media.get());
     70    return MediaQueryEvaluator { type(), *document, rootStyle.get() }.evaluate(media.get());
    7271}
    7372
  • trunk/Source/WebCore/css/StyleResolver.cpp

    r201290 r201441  
    271271    FrameView* view = m_document.view();
    272272    if (view)
    273         m_medium = std::make_unique<MediaQueryEvaluator>(view->mediaType());
     273        m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType() };
    274274    else
    275         m_medium = std::make_unique<MediaQueryEvaluator>("all");
     275        m_mediaQueryEvaluator = MediaQueryEvaluator { "all" };
    276276
    277277    if (root)
     
    279279
    280280    if (m_rootDefaultStyle && view)
    281         m_medium = std::make_unique<MediaQueryEvaluator>(view->mediaType(), &view->frame(), m_rootDefaultStyle.get());
     281        m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType(), m_document, m_rootDefaultStyle.get() };
    282282
    283283    m_ruleSets.resetAuthorStyle();
    284284
    285     m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), *m_medium, *this);
     285    m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), m_mediaQueryEvaluator, *this);
    286286
    287287#if ENABLE(SVG_FONTS)
     
    296296void StyleResolver::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets)
    297297{
    298     m_ruleSets.appendAuthorStyleSheets(styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);
     298    m_ruleSets.appendAuthorStyleSheets(styleSheets, &m_mediaQueryEvaluator, m_inspectorCSSOMWrappers, this);
    299299    if (auto renderView = document().renderView())
    300300        renderView->style().fontCascade().update(&document().fontSelector());
     
    420420    ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
    421421    collector.setRegionForStyling(regionForStyling);
    422     collector.setMedium(m_medium.get());
     422    collector.setMedium(&m_mediaQueryEvaluator);
    423423
    424424    if (matchingBehavior == MatchOnlyUserAgentRules)
     
    583583    ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter());
    584584    collector.setPseudoStyleRequest(pseudoStyleRequest);
    585     collector.setMedium(m_medium.get());
     585    collector.setMedium(&m_mediaQueryEvaluator);
    586586    collector.matchUARules();
    587587
     
    10871087    collector.setMode(SelectorChecker::Mode::CollectingRules);
    10881088    collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId));
    1089     collector.setMedium(m_medium.get());
     1089    collector.setMedium(&m_mediaQueryEvaluator);
    10901090
    10911091    if (rulesToInclude & UAAndUserCSSRules) {
     
    18791879}
    18801880
    1881 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp* expr, bool result)
    1882 {
    1883     m_viewportDependentMediaQueryResults.append(std::make_unique<MediaQueryResult>(*expr, result));
     1881void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExpression& expression, bool result)
     1882{
     1883    m_viewportDependentMediaQueryResults.append(MediaQueryResult { expression, result });
    18841884}
    18851885
    18861886bool StyleResolver::hasMediaQueriesAffectedByViewportChange() const
    18871887{
    1888     unsigned s = m_viewportDependentMediaQueryResults.size();
    1889     for (unsigned i = 0; i < s; i++) {
    1890         if (m_medium->eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
     1888    for (auto& result : m_viewportDependentMediaQueryResults) {
     1889        if (m_mediaQueryEvaluator.evaluate(result.expression) != result.result)
    18911890            return true;
    18921891    }
  • trunk/Source/WebCore/css/StyleResolver.h

    r201290 r201441  
    156156    const DocumentRuleSets& ruleSets() const { return m_ruleSets; }
    157157
    158     const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }
     158    const MediaQueryEvaluator& mediaQueryEvaluator() const { return m_mediaQueryEvaluator; }
    159159
    160160    void setOverrideDocumentElementStyle(RenderStyle* style) { m_overrideDocumentElementStyle = style; }
     
    202202#endif
    203203
    204     void addViewportDependentMediaQueryResult(const MediaQueryExp*, bool result);
     204    void addViewportDependentMediaQueryResult(const MediaQueryExpression&, bool result);
    205205    bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); }
    206206    bool hasMediaQueriesAffectedByViewportChange() const;
     
    518518    Timer m_matchedPropertiesCacheSweepTimer;
    519519
    520     std::unique_ptr<MediaQueryEvaluator> m_medium;
     520    MediaQueryEvaluator m_mediaQueryEvaluator;
    521521    std::unique_ptr<RenderStyle> m_rootDefaultStyle;
    522522
     
    527527    RenderStyle* m_overrideDocumentElementStyle { nullptr };
    528528
    529     Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
     529    Vector<MediaQueryResult> m_viewportDependentMediaQueryResults;
    530530
    531531#if ENABLE(CSS_DEVICE_ADAPTATION)
  • trunk/Source/WebCore/css/StyleSheetContents.cpp

    r201318 r201441  
    133133{
    134134    ASSERT(!rule->isCharsetRule());
     135
    135136    if (is<StyleRuleImport>(rule)) {
    136137        // Parser enforces that @import rules come before anything else except @charset.
     
    142143    }
    143144
    144 #if ENABLE(RESOLUTION_MEDIA_QUERY)
    145     // Add warning message to inspector if dpi/dpcm values are used for screen media.
    146145    if (is<StyleRuleMedia>(rule))
    147146        reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(rule.get()).mediaQueries());
    148 #endif
    149147
    150148    // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369>
    151149    // If we're adding a rule with a huge number of selectors, split it up into multiple rules
    152150    if (is<StyleRule>(rule) && downcast<StyleRule>(rule.get()).selectorList().componentCount() > RuleData::maximumSelectorComponentCount) {
    153         Vector<RefPtr<StyleRule>> rules = downcast<StyleRule>(rule.get()).splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount);
    154         m_childRules.appendVector(rules);
     151        m_childRules.appendVector(downcast<StyleRule>(rule.get()).splitIntoMultipleRulesWithMaximumSelectorComponentCount(RuleData::maximumSelectorComponentCount));
    155152        return;
    156153    }
  • trunk/Source/WebCore/dom/Document.cpp

    r201333 r201441  
    803803{
    804804    if (!m_mediaQueryMatcher)
    805         m_mediaQueryMatcher = MediaQueryMatcher::create(this);
     805        m_mediaQueryMatcher = MediaQueryMatcher::create(*this);
    806806    return *m_mediaQueryMatcher;
    807807}
  • trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp

    r201318 r201441  
    151151    MediaQueryEvaluator screenEval(ASCIILiteral("screen"), true);
    152152    MediaQueryEvaluator printEval(ASCIILiteral("print"), true);
    153     if (!screenEval.eval(mediaQueries.get()) && !printEval.eval(mediaQueries.get()))
     153    if (!screenEval.evaluate(*mediaQueries) && !printEval.evaluate(*mediaQueries))
    154154        return;
    155155
  • trunk/Source/WebCore/editing/TextIterator.cpp

    r201205 r201441  
    12671267            // Exit empty containers as we pass over them or containers
    12681268            // where [container, 0] is where we started iterating.
    1269             if (!m_handledNode && canHaveChildrenForEditing(*m_node)  && m_node->parentNode() && (!m_node->lastChild() || (m_node == m_endContainer && !m_endOffset))) {
     1269            if (!m_handledNode && canHaveChildrenForEditing(*m_node) && m_node->parentNode() && (!m_node->lastChild() || (m_node == m_endContainer && !m_endOffset))) {
    12701270                exitNode();
    12711271                if (m_positionNode) {
  • trunk/Source/WebCore/html/HTMLImageElement.cpp

    r200945 r201441  
    154154            continue;
    155155        auto& source = downcast<HTMLSourceElement>(*child);
     156
    156157        auto& srcset = source.fastGetAttribute(srcsetAttr);
    157158        if (srcset.isEmpty())
    158159            continue;
    159         if (source.hasAttribute(typeAttr)) {
    160             String type = source.fastGetAttribute(typeAttr).string();
    161             int indexOfSemicolon = type.find(';');
    162             if (indexOfSemicolon >= 0)
    163                 type.truncate(indexOfSemicolon);
     160
     161        auto& typeAttribute = source.fastGetAttribute(typeAttr);
     162        if (!typeAttribute.isNull()) {
     163            String type = typeAttribute.string();
     164            type.truncate(type.find(';'));
    164165            type = stripLeadingAndTrailingHTMLSpaces(type);
    165166            if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageMIMEType(type) && !equalLettersIgnoringASCIICase(type, "image/svg+xml"))
    166167                continue;
    167168        }
    168         MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement() ? document().documentElement()->computedStyle() : nullptr);
    169         bool evaluation = evaluator.evalCheckingViewportDependentResults(source.mediaQuerySet(), picture->viewportDependentResults());
     169
     170        auto* documentElement = document().documentElement();
     171        MediaQueryEvaluator evaluator { document().printing() ? "print" : "screen", document(), documentElement ? documentElement->computedStyle() : nullptr };
     172        auto* queries = source.mediaQuerySet();
     173        auto evaluation = !queries || evaluator.evaluate(*queries, picture->viewportDependentResults());
    170174        if (picture->hasViewportDependentResults())
    171175            document().addViewportDependentPicture(*picture);
     
    173177            continue;
    174178
    175         float sourceSize = parseSizesAttribute(source.fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
    176         ImageCandidate candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), nullAtom, source.fastGetAttribute(srcsetAttr), sourceSize);
     179        auto sourceSize = parseSizesAttribute(document(), source.fastGetAttribute(sizesAttr).string());
     180        auto candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), nullAtom, srcset, sourceSize);
    177181        if (!candidate.isEmpty())
    178182            return candidate;
     
    187191    if (candidate.isEmpty()) {
    188192        // If we don't have a <picture> or didn't find a source, then we use our own attributes.
    189         float sourceSize = parseSizesAttribute(fastGetAttribute(sizesAttr).string(), document().renderView(), document().frame());
     193        float sourceSize = parseSizesAttribute(document(), fastGetAttribute(sizesAttr).string());
    190194        candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), sourceSize);
    191195    }
  • trunk/Source/WebCore/html/HTMLLinkElement.cpp

    r201311 r201441  
    242242                documentStyle = Style::resolveForDocument(document());
    243243            auto media = MediaQuerySet::createAllowingDescriptionSyntax(m_media);
    244             MediaQueryEvaluator evaluator(document().frame()->view()->mediaType(), document().frame(), documentStyle ? &*documentStyle : nullptr);
    245             mediaQueryMatches = evaluator.eval(media.ptr());
     244            mediaQueryMatches = MediaQueryEvaluator { document().frame()->view()->mediaType(), document(), documentStyle ? &*documentStyle : nullptr }.evaluate(media.get());
    246245        }
    247246
     
    362361    }
    363362
    364     Ref<StyleSheetContents> styleSheet(StyleSheetContents::create(href, parserContext));
     363    auto styleSheet = StyleSheetContents::create(href, parserContext);
    365364    m_sheet = CSSStyleSheet::create(styleSheet.copyRef(), this);
    366365    m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media));
  • trunk/Source/WebCore/html/HTMLMediaElement.cpp

    r201435 r201441  
    41814181       
    41824182        if (source->fastHasAttribute(mediaAttr)) {
    4183             MediaQueryEvaluator screenEval("screen", document().frame(), renderer() ? &renderer()->style() : nullptr);
    4184             RefPtr<MediaQuerySet> media = source->mediaQuerySet();
     4183            auto media = source->mediaQuerySet();
    41854184#if !LOG_DISABLED
    41864185            if (shouldLog)
    41874186                LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'media' is %s", this, source->media().utf8().data());
    41884187#endif
    4189             if (!screenEval.eval(media.get()))
     4188            if (media && !MediaQueryEvaluator { "screen", document(), renderer() ? &renderer()->style() : nullptr }.evaluate(*media))
    41904189                goto check_again;
    41914190        }
  • trunk/Source/WebCore/html/HTMLPictureElement.cpp

    r195606 r201441  
    5858void HTMLPictureElement::sourcesChanged()
    5959{
    60     for (auto& imageElement : childrenOfType<HTMLImageElement>(*this))
    61         imageElement.selectImageSource();
     60    for (auto& element : childrenOfType<HTMLImageElement>(*this))
     61        element.selectImageSource();
    6262}
    6363
    64 bool HTMLPictureElement::viewportChangeAffectedPicture()
     64bool HTMLPictureElement::viewportChangeAffectedPicture() const
    6565{
    66     MediaQueryEvaluator evaluator(document().printing() ? "print" : "screen", document().frame(), document().documentElement() ? document().documentElement()->computedStyle() : nullptr);
    67     unsigned numResults = m_viewportDependentMediaQueryResults.size();
    68     for (unsigned i = 0; i < numResults; i++) {
    69         if (evaluator.eval(&m_viewportDependentMediaQueryResults[i]->m_expression) != m_viewportDependentMediaQueryResults[i]->m_result)
     66    auto* documentElement = document().documentElement();
     67    MediaQueryEvaluator evaluator { document().printing() ? "print" : "screen", document(), documentElement ? documentElement->computedStyle() : nullptr };
     68    for (auto& result : m_viewportDependentMediaQueryResults) {
     69        if (evaluator.evaluate(result.expression) != result.result)
    7070            return true;
    7171    }
  • trunk/Source/WebCore/html/HTMLPictureElement.h

    r195132 r201441  
    2424 */
    2525
    26 #ifndef HTMLPictureElement_h
    27 #define HTMLPictureElement_h
     26#pragma once
    2827
    2928#include "HTMLElement.h"
     
    3534public:
    3635    static Ref<HTMLPictureElement> create(const QualifiedName&, Document&);
    37     ~HTMLPictureElement();
     36    virtual ~HTMLPictureElement();
    3837
    3938    void sourcesChanged();
     
    4140    void clearViewportDependentResults() { m_viewportDependentMediaQueryResults.clear(); }
    4241    bool hasViewportDependentResults() const { return m_viewportDependentMediaQueryResults.size(); }
    43     Vector<std::unique_ptr<MediaQueryResult>>& viewportDependentResults() { return m_viewportDependentMediaQueryResults; }
     42    Vector<MediaQueryResult>& viewportDependentResults() { return m_viewportDependentMediaQueryResults; }
    4443
    45     void didMoveToNewDocument(Document* oldDocument);
    46    
    47     bool viewportChangeAffectedPicture();
     44    bool viewportChangeAffectedPicture() const;
    4845
    4946    WeakPtr<HTMLPictureElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); }
     
    5148private:
    5249    HTMLPictureElement(const QualifiedName&, Document&);
    53    
     50
     51    void didMoveToNewDocument(Document* oldDocument) final;
     52
    5453    WeakPtrFactory<HTMLPictureElement> m_weakFactory { this };
    55     Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;
    56 
     54    Vector<MediaQueryResult> m_viewportDependentMediaQueryResults;
    5755};
    5856
    5957} // namespace WebCore
    60 
    61 #endif // HTMLPictureElement_h
  • trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp

    r200519 r201441  
    119119       
    120120        if (m_tagId == TagId::Source && !pictureState.isEmpty() && !pictureState.last() && m_mediaMatched && !m_srcSetAttribute.isEmpty()) {
    121             float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
     121            float sourceSize = parseSizesAttribute(document, m_sizesAttribute);
    122122            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
    123123            if (!imageCandidate.isEmpty()) {
     
    129129        // Resolve between src and srcSet if we have them and the tag is img.
    130130        if (m_tagId == TagId::Img && !m_srcSetAttribute.isEmpty()) {
    131             float sourceSize = parseSizesAttribute(m_sizesAttribute, document.renderView(), document.frame());
     131            float sourceSize = parseSizesAttribute(document, m_sizesAttribute);
    132132            ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize);
    133133            setUrlToLoad(imageCandidate.string.toString(), true);
     
    199199            if (match(attributeName, mediaAttr) && m_mediaAttribute.isNull()) {
    200200                m_mediaAttribute = attributeValue;
    201                 Ref<MediaQuerySet> mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
    202                 Vector<std::unique_ptr<MediaQueryResult>> viewportDependentMediaQueryResults;
    203                 MediaQueryEvaluator evaluator(document.printing() ? "print" : "screen", document.frame(), document.documentElement() ? document.documentElement()->computedStyle() : nullptr);
    204                 m_mediaMatched = evaluator.evalCheckingViewportDependentResults(mediaSet.ptr(), viewportDependentMediaQueryResults);
     201                auto mediaSet = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
     202                auto* documentElement = document.documentElement();
     203                m_mediaMatched = MediaQueryEvaluator { document.printing() ? "print" : "screen", document, documentElement ? documentElement->computedStyle() : nullptr }.evaluate(mediaSet.get());
    205204            }
    206205            break;
  • trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp

    r200098 r201441  
    5959}
    6060
    61 static bool mediaAttributeMatches(Frame* frame, const RenderStyle* renderStyle, const String& attributeValue)
     61static bool mediaAttributeMatches(Document& document, const RenderStyle* renderStyle, const String& attributeValue)
    6262{
    63     RefPtr<MediaQuerySet> mediaQueries = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
    64     MediaQueryEvaluator mediaQueryEvaluator("screen", frame, renderStyle);
    65     return mediaQueryEvaluator.eval(mediaQueries.get());
     63    auto mediaQueries = MediaQuerySet::createAllowingDescriptionSyntax(attributeValue);
     64    return MediaQueryEvaluator { "screen", document, renderStyle }.evaluate(mediaQueries.get());
    6665}
    6766
     
    7069    ASSERT(m_document.frame());
    7170    ASSERT(m_document.renderView());
    72     if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document.frame(), &m_document.renderView()->style(), preload->media()))
     71    if (!preload->media().isEmpty() && !mediaAttributeMatches(m_document, &m_document.renderView()->style(), preload->media()))
    7372        return;
    7473
  • trunk/Source/WebCore/page/DOMWindow.cpp

    r201305 r201441  
    8080#include "PageTransitionEvent.h"
    8181#include "Performance.h"
    82 #include "PlatformScreen.h"
    8382#include "ResourceLoadInfo.h"
    8483#include "RuntimeEnabledFeatures.h"
  • trunk/Source/WebCore/page/mac/EventHandlerMac.mm

    r201213 r201441  
    11761176        return m_lastKnownMousePosition;
    11771177
    1178     NSScreen *screen = screenForDisplayID(page->chrome().displayID());
    1179     IntSize autoscrollAdjustmentFactor = autoscrollAdjustmentFactorForScreenBoundaries(m_lastKnownMouseGlobalPosition, toUserSpace(screen.frame, nil));
    1180 
    1181     return m_lastKnownMousePosition + autoscrollAdjustmentFactor;
    1182 }
    1183 
    1184 }
     1178    auto frame = toUserSpace(screen(page->chrome().displayID()).frame, nil);
     1179    return m_lastKnownMousePosition + autoscrollAdjustmentFactorForScreenBoundaries(m_lastKnownMouseGlobalPosition, frame);
     1180}
     1181
     1182}
  • trunk/Source/WebCore/platform/PlatformScreen.h

    r201065 r201441  
    2424 */
    2525
    26 #ifndef PlatformScreen_h
    27 #define PlatformScreen_h
    28 
    29 #include <wtf/Vector.h>
     26#pragma once
    3027
    3128#if PLATFORM(MAC)
     
    4542#endif
    4643
    47 typedef uint32_t PlatformDisplayID;
    48 
    49 typedef WTF::Vector<char> ColorProfile;
    50 
    5144namespace WebCore {
    5245
    53     class FloatRect;
    54     class FloatSize;
    55     class Widget;
     46class FloatRect;
     47class FloatSize;
     48class Widget;
    5649
    57     int screenDepth(Widget*);
    58     int screenDepthPerComponent(Widget*);
    59     bool screenIsMonochrome(Widget*);
     50using PlatformDisplayID = uint32_t;
    6051
    61     bool screenHasInvertedColors();
     52int screenDepth(Widget*);
     53int screenDepthPerComponent(Widget*);
     54bool screenIsMonochrome(Widget*);
    6255
    63     FloatRect screenRect(Widget*);
    64     FloatRect screenAvailableRect(Widget*);
     56bool screenHasInvertedColors();
    6557
    66     WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* widget = nullptr);
     58FloatRect screenRect(Widget*);
     59FloatRect screenAvailableRect(Widget*);
     60
     61WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* = nullptr);
    6762
    6863#if PLATFORM(MAC)
    69     NSScreen *screenForWindow(NSWindow *);
    70     NSScreen *screenForDisplayID(PlatformDisplayID);
    7164
    72     WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&, NSWindow *destination);
    73     WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source);
     65NSScreen *screen(NSWindow *);
     66NSScreen *screen(PlatformDisplayID);
    7467
    75     NSPoint flipScreenPoint(const NSPoint&, NSScreen *);
     68WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&, NSWindow *destination);
     69WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source);
     70
     71NSPoint flipScreenPoint(const NSPoint&, NSScreen *);
     72
    7673#endif
    7774
    7875#if PLATFORM(IOS)
    79     float screenPPIFactor();
    80     WEBCORE_EXPORT FloatSize screenSize();
    81     WEBCORE_EXPORT FloatSize availableScreenSize();
    82     WEBCORE_EXPORT float screenScaleFactor(UIScreen * = nullptr);
     76
     77float screenPPIFactor();
     78WEBCORE_EXPORT FloatSize screenSize();
     79WEBCORE_EXPORT FloatSize availableScreenSize();
     80WEBCORE_EXPORT float screenScaleFactor(UIScreen * = nullptr);
     81
    8382#endif
    8483
    8584} // namespace WebCore
    86 
    87 #endif // PlatformScreen_h
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.cpp

    r182985 r201441  
    3535
    3636DisplayRefreshMonitorClient::DisplayRefreshMonitorClient()
    37     : m_scheduled(false)
    38     , m_displayIDIsSet(false)
    3937{
    4038}
  • trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.h

    r182985 r201441  
    2424 */
    2525
    26 #ifndef DisplayRefreshMonitorClient_h
    27 #define DisplayRefreshMonitorClient_h
     26#pragma once
    2827
    2928#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    3029
    3130#include "PlatformScreen.h"
     31#include <wtf/Forward.h>
    3232#include <wtf/Optional.h>
    3333
     
    3535
    3636class DisplayRefreshMonitor;
    37 class DisplayRefreshMonitorManager;
    3837
    3938class DisplayRefreshMonitorClient {
     
    4746    virtual RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const = 0;
    4847
    49     PlatformDisplayID displayID() const { return m_displayID; }
    50     bool hasDisplayID() const { return m_displayIDIsSet; }
    51     void setDisplayID(PlatformDisplayID displayID)
    52     {
    53         m_displayID = displayID;
    54         m_displayIDIsSet = true;
    55     }
     48    PlatformDisplayID displayID() const { return m_displayID.value(); }
     49    bool hasDisplayID() const { return !!m_displayID; }
     50    void setDisplayID(PlatformDisplayID displayID) { m_displayID = displayID; }
    5651
    5752    void setIsScheduled(bool isScheduled) { m_scheduled = isScheduled; }
     
    6156
    6257private:
    63     bool m_scheduled;
    64     bool m_displayIDIsSet;
    65     PlatformDisplayID m_displayID;
     58    bool m_scheduled { false };
     59    Optional<PlatformDisplayID> m_displayID;
    6660};
    6761
     
    6963
    7064#endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    71 
    72 #endif
  • trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.h

    r197563 r201441  
    2424 */
    2525
    26 #ifndef GraphicsLayerUpdater_h
    27 #define GraphicsLayerUpdater_h
     26#pragma once
    2827
    2928#include "DisplayRefreshMonitorClient.h"
     
    6968
    7069} // namespace WebCore
    71 
    72 #endif // GraphicsLayerUpdater_h
  • trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h

    r199312 r201441  
    2727 */
    2828
    29 #ifndef ImageDecoder_h
    30 #define ImageDecoder_h
     29#pragma once
    3130
    3231#include "IntRect.h"
     
    4140
    4241namespace WebCore {
     42
     43using ColorProfile = Vector<char>;
    4344
    4445    // ImageFrame represents the decoded image data.  This buffer is what all
     
    412413
    413414} // namespace WebCore
    414 
    415 #endif
  • trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h

    r183954 r201441  
    2424 */
    2525
    26 #ifndef PlatformEventFactoryMac_h
    27 #define PlatformEventFactoryMac_h
     26#pragma once
    2827
    2928#include "PlatformKeyboardEvent.h"
     
    4140
    4241#if PLATFORM(COCOA) && defined(__OBJC__)
    43 // FIXME: This doesn't really belong here.
    44 WEBCORE_EXPORT IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *);
    4542
    46 // FIXME: WebKit2 has a lot of code copy/pasted from PlatformEventFactoryMac in WebEventFactory. It should be carefully shared with WebCore.
    47 WEBCORE_EXPORT int windowsKeyCodeForKeyEvent(NSEvent*);
    48 WEBCORE_EXPORT String keyIdentifierForKeyEvent(NSEvent*);
    49 WEBCORE_EXPORT double eventTimeStampSince1970(NSEvent*);
     43// FIXME: This function doesn't really belong in this header.
     44WEBCORE_EXPORT NSPoint globalPoint(const NSPoint& windowPoint, NSWindow *);
     45
     46// FIXME: WebKit2 has a lot of code copied and pasted from PlatformEventFactoryMac in WebEventFactory. More of it should be shared with WebCore.
     47WEBCORE_EXPORT int windowsKeyCodeForKeyEvent(NSEvent *);
     48WEBCORE_EXPORT String keyIdentifierForKeyEvent(NSEvent *);
     49WEBCORE_EXPORT double eventTimeStampSince1970(NSEvent *);
    5050
    5151#endif
    5252
    5353} // namespace WebCore
    54 
    55 #endif // PlatformEventFactoryMac_h
  • trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm

    r197789 r201441  
    3939namespace WebCore {
    4040
    41 IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *window)
    42 {
    43 #pragma clang diagnostic push
    44 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    45     return IntPoint(flipScreenPoint([window convertBaseToScreen:windowPoint], screenForWindow(window)));
    46 #pragma clang diagnostic pop
    47 }
    48 
    49 static IntPoint globalPointForEvent(NSEvent *event)
     41NSPoint globalPoint(const NSPoint& windowPoint, NSWindow *window)
     42{
     43#pragma clang diagnostic push
     44#pragma clang diagnostic ignored "-Wdeprecated-declarations"
     45    return flipScreenPoint([window convertBaseToScreen:windowPoint], screen(window));
     46#pragma clang diagnostic pop
     47}
     48
     49static NSPoint globalPointForEvent(NSEvent *event)
    5050{
    5151    switch ([event type]) {
     
    7171            return globalPoint([event locationInWindow], [event window]);
    7272        default:
    73             return IntPoint();
     73            return { 0, 0 };
    7474    }
    7575}
     
    486486        // PlatformMouseEvent
    487487        m_position = pointForEvent(event, windowView);
    488         m_globalPosition = globalPointForEvent(event);
     488        m_globalPosition = IntPoint(globalPointForEvent(event));
    489489        m_button = mouseButtonForEvent(event);
    490490        m_clickCount = clickCountForEvent(event);
     
    515515    {
    516516        // PlatformEvent
    517         m_type                              = PlatformEvent::Wheel;
    518         m_modifiers                         = modifiersForEvent(event);
    519         m_timestamp                         = eventTimeStampSince1970(event);
     517        m_type = PlatformEvent::Wheel;
     518        m_modifiers = modifiersForEvent(event);
     519        m_timestamp = eventTimeStampSince1970(event);
    520520
    521521        // PlatformWheelEvent
    522         m_position                          = pointForEvent(event, windowView);
    523         m_globalPosition                    = globalPointForEvent(event);
    524         m_granularity                       = ScrollByPixelWheelEvent;
     522        m_position = pointForEvent(event, windowView);
     523        m_globalPosition = IntPoint(globalPointForEvent(event));
     524        m_granularity = ScrollByPixelWheelEvent;
    525525
    526526        BOOL continuous;
     
    536536        }
    537537
    538         m_phase                             = phaseForEvent(event);
    539         m_momentumPhase                     = momentumPhaseForEvent(event);
    540         m_hasPreciseScrollingDeltas         = continuous;
    541         m_directionInvertedFromDevice       = [event isDirectionInvertedFromDevice];
     538        m_phase = phaseForEvent(event);
     539        m_momentumPhase = momentumPhaseForEvent(event);
     540        m_hasPreciseScrollingDeltas = continuous;
     541        m_directionInvertedFromDevice = [event isDirectionInvertedFromDevice];
    542542    }
    543543};
     
    554554    {
    555555        // PlatformEvent
    556         m_type                              = isKeyUpEvent(event) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown;
    557         m_modifiers                         = modifiersForEvent(event);
    558         m_timestamp                         = eventTimeStampSince1970(event);
     556        m_type = isKeyUpEvent(event) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown;
     557        m_modifiers = modifiersForEvent(event);
     558        m_timestamp = eventTimeStampSince1970(event);
    559559
    560560        // PlatformKeyboardEvent
    561         m_text                              = textFromEvent(event);
    562         m_unmodifiedText                    = unmodifiedTextFromEvent(event);
    563         m_keyIdentifier                     = keyIdentifierForKeyEvent(event);
    564         m_windowsVirtualKeyCode             = windowsKeyCodeForKeyEvent(event);
    565         m_nativeVirtualKeyCode              = [event keyCode];
    566         m_macCharCode                       = wkGetNSEventKeyChar(event);
    567 #pragma clang diagnostic push
    568 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    569         m_autoRepeat                        = ([event type] != NSFlagsChanged) && [event isARepeat];
    570 #pragma clang diagnostic pop
    571         m_isKeypad                          = isKeypadEvent(event);
    572         m_isSystemKey                       = false; // SystemKey is always false on the Mac.
     561        m_text = textFromEvent(event);
     562        m_unmodifiedText = unmodifiedTextFromEvent(event);
     563        m_keyIdentifier = keyIdentifierForKeyEvent(event);
     564        m_windowsVirtualKeyCode = windowsKeyCodeForKeyEvent(event);
     565        m_nativeVirtualKeyCode = [event keyCode];
     566        m_macCharCode = wkGetNSEventKeyChar(event);
     567#pragma clang diagnostic push
     568#pragma clang diagnostic ignored "-Wdeprecated-declarations"
     569        m_autoRepeat = [event type] != NSFlagsChanged && [event isARepeat];
     570#pragma clang diagnostic pop
     571        m_isKeypad = isKeypadEvent(event);
     572        m_isSystemKey = false; // SystemKey is always false on the Mac.
    573573
    574574        // Always use 13 for Enter/Return -- we don't want to use AppKit's different character for Enter.
  • trunk/Source/WebCore/platform/mac/PlatformScreenMac.mm

    r201065 r201441  
    3131#import "FrameView.h"
    3232#import "HostWindow.h"
    33 
    3433#import <ColorSync/ColorSync.h>
    3534
     
    4140namespace WebCore {
    4241
    43 static PlatformDisplayID displayIDFromScreen(NSScreen *screen)
    44 {
    45     return (PlatformDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
    46 }
    47 
    4842// These functions scale between screen and page coordinates because JavaScript/DOM operations
    4943// assume that the screen and the page share the same coordinate system.
    5044
    51 static PlatformDisplayID displayFromWidget(Widget* widget)
     45static PlatformDisplayID displayID(NSScreen *screen)
     46{
     47    return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];
     48}
     49
     50static PlatformDisplayID displayID(Widget* widget)
    5251{
    5352    if (!widget)
    5453        return 0;
    5554
    56     FrameView* view = widget->root();
     55    auto* view = widget->root();
    5756    if (!view)
    5857        return 0;
    5958
    60     return view->hostWindow()->displayID();
     59    auto* hostWindow = view->hostWindow();
     60    if (!hostWindow)
     61        return 0;
     62
     63    return hostWindow->displayID();
    6164}
    6265
    63 static NSScreen *screenForWidget(Widget* widget, NSWindow *window)
     66// Screen containing the menubar.
     67static NSScreen *firstScreen()
    6468{
    65     // Widget is in an NSWindow, use its screen.
    66     if (window)
    67         return screenForWindow(window);
     69    NSArray *screens = [NSScreen screens];
     70    if (![screens count])
     71        return nil;
     72    return [screens objectAtIndex:0];
     73}
    6874
    69     // Didn't get an NSWindow; probably WebKit2. Try using the Widget's display ID.
    70     if (NSScreen *screen = screenForDisplayID(displayFromWidget(widget)))
    71         return screen;
     75static NSWindow *window(Widget* widget)
     76{
     77    if (!widget)
     78        return nil;
     79    return widget->platformWidget().window;
     80}
    7281
    73     // Widget's window is offscreen, or no screens. Fall back to the first screen if available.
    74     return screenForWindow(nil);
     82static NSScreen *screen(Widget* widget)
     83{
     84    // If the widget is in a window, use that, otherwise use the display ID from the host window.
     85    // First case is for when the NSWindow is in the same process, second case for when it's not.
     86    if (auto screenFromWindow = window(widget).screen)
     87        return screenFromWindow;
     88    return screen(displayID(widget));
    7589}
    7690
    7791int screenDepth(Widget* widget)
    7892{
    79     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
    80     NSScreen *screen = screenForWidget(widget, window);
    81     return NSBitsPerPixelFromDepth(screen.depth);
     93    return NSBitsPerPixelFromDepth(screen(widget).depth);
    8294}
    8395
    8496int screenDepthPerComponent(Widget* widget)
    8597{
    86     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
    87     NSScreen *screen = screenForWidget(widget, window);
    88     return NSBitsPerSampleFromDepth(screen.depth);
     98    return NSBitsPerSampleFromDepth(screen(widget).depth);
    8999}
    90100
    91101bool screenIsMonochrome(Widget*)
    92102{
    93     // At the moment this is a system-wide accessibility setting,
    94     // so we don't need to check the screen we're using.
     103    // This is a system-wide accessibility setting, same on all screens.
    95104    return CGDisplayUsesForceToGray();
    96105}
     
    98107bool screenHasInvertedColors()
    99108{
    100     // At the moment this is a system-wide accessibility setting,
    101     // so we don't need to check the screen we're using.
     109    // This is a system-wide accessibility setting, same on all screens.
    102110    return CGDisplayUsesInvertedPolarity();
    103111}
     
    105113FloatRect screenRect(Widget* widget)
    106114{
    107     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
    108     NSScreen *screen = screenForWidget(widget, window);
    109     return toUserSpace([screen frame], window);
     115    return toUserSpace([screen(widget) frame], window(widget));
    110116}
    111117
    112118FloatRect screenAvailableRect(Widget* widget)
    113119{
    114     NSWindow *window = widget ? [widget->platformWidget() window] : nil;
    115     NSScreen *screen = screenForWidget(widget, window);
    116     return toUserSpace([screen visibleFrame], window);
     120    return toUserSpace([screen(widget) visibleFrame], window(widget));
    117121}
    118122
    119 NSScreen *screenForWindow(NSWindow *window)
     123NSScreen *screen(NSWindow *window)
    120124{
    121     NSScreen *screen = [window screen]; // nil if the window is off-screen
    122     if (screen)
    123         return screen;
    124 
    125     NSArray *screens = [NSScreen screens];
    126     if ([screens count] > 0)
    127         return [screens objectAtIndex:0]; // screen containing the menubar
    128 
    129     return nil;
     125    return [window screen] ?: firstScreen();
    130126}
    131127
    132 NSScreen *screenForDisplayID(PlatformDisplayID displayID)
     128NSScreen *screen(PlatformDisplayID displayID)
    133129{
    134130    for (NSScreen *screen in [NSScreen screens]) {
    135         if (displayIDFromScreen(screen) == displayID)
     131        if (WebCore::displayID(screen) == displayID)
    136132            return screen;
    137133    }
    138     return nil;
     134    return firstScreen();
    139135}
    140136
     
    148144        return false;
    149145
    150     NSWindow *window = [widget->platformWidget() window];
    151     NSScreen *screen = screenForWidget(widget, window);
    152     CGColorSpaceRef colorSpace = screen.colorSpace.CGColorSpace;
     146    auto colorSpace = screen(widget).colorSpace.CGColorSpace;
    153147
    154148#if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200
    155149    return CGColorSpaceIsWideGamutRGB(colorSpace);
    156150#else
    157     bool isWideGamut = false;
    158     RetainPtr<CFDataRef> iccData = adoptCF(CGColorSpaceCopyICCProfile(colorSpace));
    159     RetainPtr<ColorSyncProfileRef> profile = adoptCF(ColorSyncProfileCreate(iccData.get(), NULL));
    160     if (profile)
    161         isWideGamut = ColorSyncProfileIsWideGamut(profile.get());
    162     return isWideGamut;
     151    auto iccData = adoptCF(CGColorSpaceCopyICCProfile(colorSpace));
     152    auto profile = adoptCF(ColorSyncProfileCreate(iccData.get(), nullptr));
     153    return profile && ColorSyncProfileIsWideGamut(profile.get());
    163154#endif
    164155#endif
     
    168159{
    169160    FloatRect userRect = rect;
    170     userRect.setY(NSMaxY([screenForWindow(destination) frame]) - (userRect.y() + userRect.height())); // flip
     161    userRect.setY(NSMaxY([screen(destination) frame]) - (userRect.y() + userRect.height())); // flip
    171162    return userRect;
    172163}
     
    175166{
    176167    FloatRect deviceRect = rect;
    177     deviceRect.setY(NSMaxY([screenForWindow(source) frame]) - (deviceRect.y() + deviceRect.height())); // flip
     168    deviceRect.setY(NSMaxY([screen(source) frame]) - (deviceRect.y() + deviceRect.height())); // flip
    178169    return deviceRect;
    179170}
  • trunk/Source/WebKit/mac/ChangeLog

    r201430 r201441  
     12016-05-26  Darin Adler  <darin@apple.com>
     2
     3        Media queries and platform screen modernization and streamlining
     4        https://bugs.webkit.org/show_bug.cgi?id=158067
     5
     6        Reviewed by Alex Christensen.
     7
     8        * WebView/WebFrame.mm:
     9        (-[WebFrame _dragSourceEndedAt:operation:]): Updated to use the new version of
     10        globalPoint, which returns an NSPoint.
     11
    1122016-05-26  Myles C. Maxfield  <mmaxfield@apple.com>
    213
  • trunk/Source/WebKit/mac/WebView/WebFrame.mm

    r200770 r201441  
    977977        return;
    978978    // FIXME: These are fake modifier keys here, but they should be real ones instead.
    979     PlatformMouseEvent event(IntPoint(windowLoc), globalPoint(windowLoc, [view->platformWidget() window]),
     979    PlatformMouseEvent event(IntPoint(windowLoc), IntPoint(globalPoint(windowLoc, [view->platformWidget() window])),
    980980        LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime(), WebCore::ForceAtClick);
    981981    _private->coreFrame->eventHandler().dragSourceEndedAt(event, (DragOperation)operation);
  • trunk/Source/WebKit2/ChangeLog

    r201440 r201441  
     12016-05-26  Darin Adler  <darin@apple.com>
     2
     3        Media queries and platform screen modernization and streamlining
     4        https://bugs.webkit.org/show_bug.cgi?id=158067
     5
     6        Reviewed by Alex Christensen.
     7
     8        * Shared/mac/WebEventFactory.mm:
     9        (WebKit::screenForWindow): Deleted.
     10        (WebKit::flipScreenPoint): Deleted.
     11        (WebKit::globalPoint): Deleted.
     12        (WebKit::globalPointForEvent): Use globalPoint function from WebCore so we don't need
     13        copies of everything in here.
     14
     15        * UIProcess/Cocoa/WebViewImpl.mm:
     16        (WebKit::WebViewImpl::windowDidChangeScreen): Removed unneeded type cast.
     17        (WebKit::WebViewImpl::draggedImage): Added type cast since globalPoint now returns an
     18        NSPoint rather than an IntPoint.
     19
     20        * UIProcess/WebPageProxy.h: Use pragma once. Add a WebCore prefix to a use of
     21        PlatformDisplayID, since that is now inside the WebCore namespace.
     22        * WebProcess/WebCoreSupport/WebChromeClient.h: Ditto.
     23        * WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.h: Ditto.
     24        * WebProcess/WebPage/DrawingArea.h: Ditto.
     25        * WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h: Ditto.
     26
    1272016-05-26  Gyuyoung Kim  <gyuyoung.kim@webkit.org>
    228
  • trunk/Source/WebKit2/Shared/mac/WebEventFactory.mm

    r197795 r201441  
    138138}
    139139
    140 static NSScreen *screenForWindow(NSWindow *window)
    141 {
    142     NSScreen *screen = [window screen]; // nil if the window is off-screen
    143     if (screen)
    144         return screen;
    145    
    146     NSArray *screens = [NSScreen screens];
    147     if ([screens count] > 0)
    148         return [screens objectAtIndex:0]; // screen containing the menubar
    149    
    150     return nil;
    151 }
    152 
    153 static NSPoint flipScreenPoint(const NSPoint& screenPoint, NSScreen *screen)
    154 {
    155     NSPoint flippedPoint = screenPoint;
    156     flippedPoint.y = NSMaxY([screen frame]) - flippedPoint.y;
    157     return flippedPoint;
    158 }
    159 
    160 static NSPoint globalPoint(const NSPoint& windowPoint, NSWindow *window)
    161 {
    162 #pragma clang diagnostic push
    163 #pragma clang diagnostic ignored "-Wdeprecated-declarations"
    164     return flipScreenPoint([window convertBaseToScreen:windowPoint], screenForWindow(window));
    165 #pragma clang diagnostic pop
    166 }
    167 
    168140static NSPoint globalPointForEvent(NSEvent *event)
    169141{
     
    188160    case NSScrollWheel:
    189161#pragma clang diagnostic pop
    190         return globalPoint([event locationInWindow], [event window]);
     162        return WebCore::globalPoint([event locationInWindow], [event window]);
    191163    default:
    192164        return NSZeroPoint;
  • trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm

    r201227 r201441  
    10901090{
    10911091    NSWindow *window = m_targetWindowForMovePreparation ? m_targetWindowForMovePreparation : m_view.window;
    1092     m_page->windowScreenDidChange((PlatformDisplayID)[[[[window screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue]);
     1092    m_page->windowScreenDidChange([[[[window screen] deviceDescription] objectForKey:@"NSScreenNumber"] intValue]);
    10931093}
    10941094
     
    27792779    m_ignoresMouseDraggedEvents = true;
    27802780
    2781     m_page->dragEnded(WebCore::IntPoint(windowMouseLoc), WebCore::globalPoint(windowMouseLoc, m_view.window), operation);
     2781    m_page->dragEnded(WebCore::IntPoint(windowMouseLoc), WebCore::IntPoint(WebCore::globalPoint(windowMouseLoc, m_view.window)), operation);
    27822782}
    27832783
  • trunk/Source/WebKit2/UIProcess/WebPageProxy.h

    r201298 r201441  
    2424 */
    2525
    26 #ifndef WebPageProxy_h
    27 #define WebPageProxy_h
     26#pragma once
    2827
    2928#include "APIObject.h"
     
    667666    void setIntrinsicDeviceScaleFactor(float);
    668667    void setCustomDeviceScaleFactor(float);
    669     void windowScreenDidChange(PlatformDisplayID);
     668    void windowScreenDidChange(WebCore::PlatformDisplayID);
    670669
    671670    void setUseFixedLayout(bool);
     
    18321831
    18331832} // namespace WebKit
    1834 
    1835 #endif // WebPageProxy_h
  • trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h

    r199951 r201441  
    2525 */
    2626
    27 #ifndef WebChromeClient_h
    28 #define WebChromeClient_h
     27#pragma once
    2928
    3029#include "WebFrame.h"
     
    211210
    212211#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    213     RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const override;
     212    RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) const override;
    214213#endif
    215214
     
    347346
    348347} // namespace WebKit
    349 
    350 #endif // WebChromeClient_h
  • trunk/Source/WebKit2/WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.h

    r197563 r201441  
    2424 */
    2525
    26 #ifndef RemoteLayerTreeDisplayRefreshMonitor_h
    27 #define RemoteLayerTreeDisplayRefreshMonitor_h
     26#pragma once
    2827
    2928#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
     
    3635class RemoteLayerTreeDisplayRefreshMonitor : public WebCore::DisplayRefreshMonitor {
    3736public:
    38     static Ref<RemoteLayerTreeDisplayRefreshMonitor> create(PlatformDisplayID displayID, RemoteLayerTreeDrawingArea& drawingArea)
     37    static Ref<RemoteLayerTreeDisplayRefreshMonitor> create(WebCore::PlatformDisplayID displayID, RemoteLayerTreeDrawingArea& drawingArea)
    3938    {
    4039        return adoptRef(*new RemoteLayerTreeDisplayRefreshMonitor(displayID, drawingArea));
     
    4847
    4948private:
    50     explicit RemoteLayerTreeDisplayRefreshMonitor(PlatformDisplayID, RemoteLayerTreeDrawingArea&);
     49    explicit RemoteLayerTreeDisplayRefreshMonitor(WebCore::PlatformDisplayID, RemoteLayerTreeDrawingArea&);
    5150
    5251    WeakPtr<RemoteLayerTreeDrawingArea> m_drawingArea;
     
    5655
    5756#endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    58 
    59 #endif // RemoteLayerTreeDisplayRefreshMonitor_h
  • trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h

    r199111 r201441  
    2424 */
    2525
    26 #ifndef DrawingArea_h
    27 #define DrawingArea_h
     26#pragma once
    2827
    2928#include "DrawingAreaInfo.h"
     
    4039#include <wtf/Noncopyable.h>
    4140#include <wtf/TypeCasts.h>
     41#include <wtf/Vector.h>
    4242
    4343namespace IPC {
     
    112112
    113113#if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR)
    114     virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID);
     114    virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID);
    115115#endif
    116116
     
    183183    static bool isType(const WebKit::DrawingArea& area) { return area.type() == WebKit::AreaType; } \
    184184SPECIALIZE_TYPE_TRAITS_END()
    185 
    186 #endif // DrawingArea_h
  • trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h

    r199111 r201441  
    2424 */
    2525
    26 #ifndef RemoteLayerTreeDrawingArea_h
    27 #define RemoteLayerTreeDrawingArea_h
     26#pragma once
    2827
    2928#include "DrawingArea.h"
     
    7574    void addTransactionCallbackID(uint64_t callbackID) override;
    7675
    77     RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) override;
     76    RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override;
    7877    void willDestroyDisplayRefreshMonitor(WebCore::DisplayRefreshMonitor*);
    7978
     
    180179
    181180SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(RemoteLayerTreeDrawingArea, DrawingAreaTypeRemoteLayerTree)
    182 
    183 #endif // RemoteLayerTreeDrawingArea_h
Note: See TracChangeset for help on using the changeset viewer.