Changeset 201441 in webkit
- Timestamp:
- May 26, 2016 5:05:24 PM (8 years ago)
- Location:
- trunk/Source
- Files:
-
- 59 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r201440 r201441 1 2016-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 1 319 2016-05-26 Gyuyoung Kim <gyuyoung.kim@webkit.org> 2 320 -
trunk/Source/WebCore/bindings/objc/DOM.mm
r200563 r201441 763 763 764 764 #if PLATFORM(IOS) 765 765 766 @implementation DOMHTMLLinkElement (WebPrivate) 767 766 768 - (BOOL)_mediaQueryMatchesForOrientation:(int)orientation 767 769 { … … 791 793 - (BOOL)_mediaQueryMatches 792 794 { 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); 795 798 if (media.isEmpty()) 796 799 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 805 808 #endif 806 809 -
trunk/Source/WebCore/css/CSSGrammar.y.in
r201290 r201441 38 38 MediaQuery* mediaQuery; 39 39 MediaQuery::Restrictor mediaQueryRestrictor; 40 MediaQueryExp * mediaQueryExp;40 MediaQueryExpression* mediaQueryExpression; 41 41 Vector<CSSParser::SourceSize>* sourceSizeList; 42 Vector< std::unique_ptr<MediaQueryExp>>* mediaQueryExpList;42 Vector<MediaQueryExpression>* mediaQueryExpressionList; 43 43 StyleKeyframe* keyframe; 44 44 Vector<RefPtr<StyleKeyframe>>* keyframeRuleList; … … 272 272 %type <mediaQueryRestrictor> maybe_media_restrictor 273 273 274 %type <mediaQueryExp > media_query_exp base_media_query_exp275 %destructor { delete $$; } media_query_exp base_media_query_exp274 %type <mediaQueryExpression> media_query_expression base_media_query_expression 275 %destructor { delete $$; } media_query_expression base_media_query_expression 276 276 277 277 %type <sourceSizeList> source_size_list 278 278 %destructor { delete $$; } source_size_list 279 279 280 %type <mediaQueryExp > maybe_source_media_query_exp281 %destructor { delete $$; } maybe_source_media_query_exp 280 %type <mediaQueryExpression> maybe_source_media_query_expression 281 %destructor { delete $$; } maybe_source_media_query_expression 282 282 283 283 %type <value> source_size_length 284 284 %destructor { destroy($$); } source_size_length 285 285 286 %type <mediaQueryExp List> media_query_exp_list maybe_and_media_query_exp_list287 %destructor { delete $$; } media_query_exp _list maybe_and_media_query_exp_list286 %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 288 288 289 289 %type <string> keyframe_name … … 577 577 578 578 source_size_list: 579 maybe_source_media_query_exp source_size_length {579 maybe_source_media_query_expression source_size_length { 580 580 $$ = 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 { 584 585 $$ = $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 591 maybe_source_media_query_expression: 590 592 /* empty */ { 591 $$ = new MediaQueryExp ;592 } 593 | base_media_query_exp maybe_space;593 $$ = new MediaQueryExpression; 594 } 595 | base_media_query_expression maybe_space; 594 596 595 597 source_size_length: unary_term | calc_function; 596 598 597 base_media_query_exp : '(' maybe_space IDENT maybe_space maybe_media_value ')' {599 base_media_query_expression: '(' maybe_space IDENT maybe_space maybe_media_value ')' { 598 600 std::unique_ptr<CSSParserValueList> mediaValue($5); 599 601 $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 606 media_query_expression: 607 maybe_media_restrictor maybe_space base_media_query_expression maybe_space { 606 608 if ($1 != MediaQuery::None) { 607 609 // If restrictor is specified, media query expression is invalid. 608 610 // Create empty media query expression and continue parsing media query. 609 611 delete $3; 610 $$ = new MediaQueryExp ;612 $$ = new MediaQueryExpression; 611 613 } else 612 614 $$ = $3; … … 614 616 ; 615 617 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 { 618 media_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 { 622 625 $$ = $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 631 maybe_and_media_query_expression_list: 628 632 /*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 { 632 636 $$ = $3; 633 637 } … … 647 651 648 652 media_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; 651 656 } 652 657 | 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 { 654 659 $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; 656 662 } 657 663 ; … … 662 668 media_query { 663 669 $$ = &MediaQuerySet::create().leakRef(); 664 $$->addMediaQuery(std::unique_ptr<MediaQuery>($1)); 670 $$->addMediaQuery(WTFMove(*$1)); 671 delete $1; 665 672 parser->updateLastMediaLine(*$$); 666 673 } 667 674 | media_list ',' maybe_space media_query { 668 675 $$ = $1; 669 std::unique_ptr<MediaQuery> mediaQuery($4);670 676 if ($$) { 671 $$->addMediaQuery(WTFMove( mediaQuery));677 $$->addMediaQuery(WTFMove(*$4)); 672 678 parser->updateLastMediaLine(*$$); 673 679 } 680 delete $4; 674 681 } 675 682 | media_list error { -
trunk/Source/WebCore/css/CSSImportRule.h
r197563 r201441 20 20 */ 21 21 22 #ifndef CSSImportRule_h 23 #define CSSImportRule_h 22 #pragma once 24 23 25 24 #include "CSSRule.h" … … 27 26 namespace WebCore { 28 27 29 class CachedCSSStyleSheet;30 28 class MediaList; 31 class MediaQuerySet;32 29 class StyleRuleImport; 33 30 … … 35 32 public: 36 33 static Ref<CSSImportRule> create(StyleRuleImport& rule, CSSStyleSheet* sheet) { return adoptRef(*new CSSImportRule(rule, sheet)); } 37 34 38 35 virtual ~CSSImportRule(); 39 40 String cssText() const override;41 void reattach(StyleRuleBase&) override;42 36 43 37 String href() const; … … 48 42 CSSImportRule(StyleRuleImport&, CSSStyleSheet*); 49 43 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; 51 47 52 48 Ref<StyleRuleImport> m_importRule; … … 58 54 59 55 SPECIALIZE_TYPE_TRAITS_CSS_RULE(CSSImportRule, CSSRule::IMPORT_RULE) 60 61 #endif // CSSImportRule_h -
trunk/Source/WebCore/css/CSSParser.cpp
r201399 r201441 1530 1530 // FIXME(141289): The following two constructors are only needed because of a bug in MSVC 2013 (and prior). 1531 1531 // We should remove this code as soon as a Visual Studio update that fixes this problem is released. 1532 1532 1533 CSSParser::SourceSize::SourceSize(CSSParser::SourceSize&& original) 1533 1534 : 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 1539 CSSParser::SourceSize::SourceSize(MediaQueryExpression&& expression, Ref<CSSValue>&& value) 1540 : expression(WTFMove(expression)) 1540 1541 , length(WTFMove(value)) 1541 1542 { 1542 1543 } 1543 1544 1544 CSSParser::SourceSize CSSParser::sourceSize( std::unique_ptr<MediaQueryExp>&& expression, CSSParserValue& parserValue)1545 CSSParser::SourceSize CSSParser::sourceSize(MediaQueryExpression&& expression, CSSParserValue& parserValue) 1545 1546 { 1546 1547 RefPtr<CSSValue> value; … … 1555 1556 // FIXME: Calling the constructor explicitly here to work around an MSVC bug. 1556 1557 // 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()); 1558 1559 } 1559 1560 -
trunk/Source/WebCore/css/CSSParser.h
r201382 r201441 67 67 class Element; 68 68 class ImmutableStyleProperties; 69 class MediaQueryExp ;69 class MediaQueryExpression; 70 70 class MediaQuerySet; 71 71 class MutableStyleProperties; … … 169 169 170 170 struct SourceSize { 171 std::unique_ptr<MediaQueryExp>expression;172 Ref Ptr<CSSValue> length;171 MediaQueryExpression expression; 172 Ref<CSSValue> length; 173 173 174 174 SourceSize(SourceSize&&); 175 SourceSize( std::unique_ptr<MediaQueryExp>&&, RefPtr<CSSValue>&&);175 SourceSize(MediaQueryExpression&&, Ref<CSSValue>&&); 176 176 }; 177 177 Vector<SourceSize> parseSizesAttribute(StringView); 178 SourceSize sourceSize( std::unique_ptr<MediaQueryExp>&&, CSSParserValue&);178 SourceSize sourceSize(MediaQueryExpression&&, CSSParserValue&); 179 179 180 180 bool parseFillImage(CSSParserValueList&, RefPtr<CSSValue>&); -
trunk/Source/WebCore/css/CSSStyleSheet.cpp
r201318 r201441 228 228 if (m_mediaCSSOMWrapper && m_mediaQueries) 229 229 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.233 230 reportMediaQueryWarningIfNeeded(ownerDocument(), m_mediaQueries.get()); 234 #endif235 231 } 236 232 -
trunk/Source/WebCore/css/DocumentRuleSets.cpp
r196629 r201441 89 89 for (auto& cssSheet : styleSheets) { 90 90 ASSERT(!cssSheet->disabled()); 91 if (cssSheet->mediaQueries() && !medium->eval (cssSheet->mediaQueries(), resolver))91 if (cssSheet->mediaQueries() && !medium->evaluate(*cssSheet->mediaQueries(), resolver)) 92 92 continue; 93 93 m_authorStyle->addRulesFromSheet(cssSheet->contents(), *medium, resolver); -
trunk/Source/WebCore/css/MediaFeatureNames.cpp
r165676 r201441 31 31 namespace MediaFeatureNames { 32 32 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) 35 34 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(DEFINE_MEDIAFEATURE_GLOBAL) 36 35 #undef DEFINE_MEDIAFEATURE_GLOBAL … … 40 39 static bool initialized; 41 40 if (!initialized) { 42 // Use placement new to initialize the globals. 43 41 // Use placement new to initialize the globals. 44 42 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); 46 44 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(INITIALIZE_GLOBAL) 47 45 #undef INITIALIZE_GLOBAL -
trunk/Source/WebCore/css/MediaFeatureNames.h
r199024 r201441 18 18 * 19 19 */ 20 #ifndef MediaFeatureNames_h 21 # define MediaFeatureNames_h20 21 #pragma once 22 22 23 23 #include <wtf/text/AtomicString.h> 24 24 25 namespace WebCore {26 namespace MediaFeatureNames {27 28 25 #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") 30 27 #else 31 28 #define CSS_MEDIAQUERY_VIEW_MODE(macro) … … 33 30 34 31 #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") \ 37 36 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") \ 40 43 macro(grid, "grid") \ 41 macro(monochrome, "monochrome") \42 44 macro(height, "height") \ 43 45 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") \ 45 70 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") \74 71 macro(pointer, "pointer") \ 75 72 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") \ 78 75 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") \ 81 78 CSS_MEDIAQUERY_VIEW_MODE(macro) 82 79 83 80 // end of macro 84 81 82 namespace WebCore { 83 namespace MediaFeatureNames { 84 85 85 #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; 87 87 CSS_MEDIAQUERY_NAMES_FOR_EACH_MEDIAFEATURE(CSS_MEDIAQUERY_NAMES_DECLARE) 88 88 #undef CSS_MEDIAQUERY_NAMES_DECLARE 89 89 #endif 90 90 91 91 void init(); 92 92 93 93 } // namespace MediaFeatureNames 94 94 } // namespace WebCore 95 96 #endif // MediaFeatureNames_h -
trunk/Source/WebCore/css/MediaList.cpp
r201333 r201441 18 18 * Boston, MA 02110-1301, USA. 19 19 */ 20 20 21 #include "config.h" 21 22 #include "MediaList.h" … … 27 28 #include "Document.h" 28 29 #include "ExceptionCode.h" 30 #include "HTMLParserIdioms.h" 29 31 #include "MediaFeatureNames.h" 30 32 #include "MediaQuery.h" 31 #include "MediaQueryExp.h"32 33 #include "ScriptableDocumentParser.h" 33 34 #include <wtf/NeverDestroyed.h> … … 75 76 { 76 77 bool success = parse(mediaString); 78 77 79 // FIXME: parsing can fail. The problem with failing constructor is that 78 80 // we would need additional flag saying MediaList is not valid … … 80 82 // forward-compatible syntax is not in use. 81 83 // DOMImplementationCSS seems to mandate that media descriptors are used 82 // for both html and svg, even though svg:style doesn't use media descriptors84 // for both HTML and SVG, even though svg:style doesn't use media descriptors 83 85 // Currently the only places where parsing can fail are 84 86 // creating <svg:style>, creating css media / import rules from js 85 87 86 88 // FIXME: This doesn't make much sense. 87 89 if (!success) … … 90 92 91 93 MediaQuerySet::MediaQuerySet(const MediaQuerySet& o) 92 : RefCounted <MediaQuerySet>()94 : RefCounted() 93 95 , m_fallbackToDescriptor(o.m_fallbackToDescriptor) 94 96 , 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 { 99 99 } 100 100 … … 110 110 // or hyphen (hex 2d)." 111 111 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 == '-')) 119 116 break; 120 117 } 121 118 return string.left(i); 119 } 120 121 Optional<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 130 Optional<MediaQuery> MediaQuerySet::internalParse(const String& queryString) 131 { 132 CSSParser parser(CSSStrictMode); 133 return internalParse(parser, queryString); 122 134 } 123 135 … … 126 138 CSSParser parser(CSSStrictMode); 127 139 128 Vector< std::unique_ptr<MediaQuery>> result;140 Vector<MediaQuery> result; 129 141 Vector<String> list; 130 142 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); 133 145 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())); 136 150 continue; 137 151 } 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; 148 153 } 149 154 // ",,,," falls straight through, but is not valid unless fallback 150 155 if (!m_fallbackToDescriptor && list.isEmpty()) { 151 String strippedMediaString = mediaString.stripWhiteSpace();156 String strippedMediaString = stripLeadingAndTrailingHTMLSpaces(mediaString); 152 157 if (!strippedMediaString.isEmpty()) 153 158 return false; … … 159 164 bool MediaQuerySet::add(const String& queryString) 160 165 { 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); 169 167 if (!parsedQuery) 170 168 return false; 171 172 m_queries.append(WTFMove(parsedQuery)); 169 m_queries.append(WTFMove(parsedQuery.value())); 173 170 return true; 174 171 } 175 172 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 } 173 bool MediaQuerySet::remove(const String& queryString) 174 { 175 auto parsedQuery = internalParse(queryString); 186 176 if (!parsedQuery) 187 177 return false; 188 189 178 return m_queries.removeFirstMatching([&parsedQuery](auto& query) { 190 return *query == *parsedQuery;179 return query == parsedQuery.value(); 191 180 }); 192 181 } 193 182 194 void MediaQuerySet::addMediaQuery( std::unique_ptr<MediaQuery>mediaQuery)183 void MediaQuerySet::addMediaQuery(MediaQuery&& mediaQuery) 195 184 { 196 185 m_queries.append(WTFMove(mediaQuery)); … … 200 189 { 201 190 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) 206 194 text.appendLiteral(", "); 207 else 208 first = false; 209 text.append(m_queries[i]->cssText()); 195 text.append(query.cssText()); 196 needComma = true; 210 197 } 211 198 return text.toString(); … … 215 202 : m_mediaQueries(mediaQueries) 216 203 , m_parentStyleSheet(parentSheet) 217 , m_parentRule(0)218 204 { 219 205 } … … 221 207 MediaList::MediaList(MediaQuerySet* mediaQueries, CSSRule* parentRule) 222 208 : m_mediaQueries(mediaQueries) 223 , m_parentStyleSheet(0)224 209 , m_parentRule(parentRule) 225 210 { … … 233 218 { 234 219 CSSStyleSheet::RuleMutationScope mutationScope(m_parentRule); 235 236 bool success = m_mediaQueries->parse(value); 237 if (!success) { 220 if (!m_mediaQueries->parse(value)) { 238 221 ec = SYNTAX_ERR; 239 222 return; … … 247 230 auto& queries = m_mediaQueries->queryVector(); 248 231 if (index < queries.size()) 249 return queries[index] ->cssText();232 return queries[index].cssText(); 250 233 return String(); 251 234 } … … 285 268 286 269 #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 271 static void addResolutionWarningMessageToConsole(Document& document, const String& serializedExpression, const CSSPrimitiveValue& value) 272 { 292 273 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: ")); 293 274 static NeverDestroyed<String> mediaValueDPI(ASCIILiteral("dpi")); … … 297 278 298 279 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); 303 284 else 304 285 ASSERT_NOT_REACHED(); … … 306 287 message.append(serializedExpression); 307 288 308 document ->addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message);289 document.addConsoleMessage(MessageSource::CSS, MessageLevel::Debug, message); 309 290 } 310 291 … … 314 295 return; 315 296 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); 333 305 if (primitiveValue.isDotsPerInch() || primitiveValue.isDotsPerCentimeter()) 334 addResolutionWarningMessageToConsole( document, mediaQuerySet->mediaText(), &primitiveValue);306 addResolutionWarningMessageToConsole(*document, mediaQuerySet->mediaText(), primitiveValue); 335 307 } 336 308 } … … 339 311 } 340 312 } 313 341 314 #endif 342 315 -
trunk/Source/WebCore/css/MediaList.h
r188315 r201441 19 19 */ 20 20 21 #ifndef MediaList_h 22 #define MediaList_h 21 #pragma once 23 22 24 #include "ExceptionCode.h"25 23 #include <memory> 26 24 #include <wtf/Forward.h> 27 #include <wtf/PassRefPtr.h>28 #include <wtf/RefCounted.h>29 25 #include <wtf/Vector.h> 30 26 #include <wtf/text/WTFString.h> … … 32 28 namespace WebCore { 33 29 30 class CSSParser; 34 31 class CSSRule; 35 32 class CSSStyleSheet; 36 33 class Document; 37 class MediaList;38 34 class MediaQuery; 35 36 using ExceptionCode = int; 39 37 40 38 class MediaQuerySet : public RefCounted<MediaQuerySet> { … … 53 51 } 54 52 ~MediaQuerySet(); 55 53 56 54 bool parse(const String&); 57 55 bool add(const String&); 58 56 bool remove(const String&); 59 57 60 void addMediaQuery( std::unique_ptr<MediaQuery>);58 void addMediaQuery(MediaQuery&&); 61 59 62 const Vector< std::unique_ptr<MediaQuery>>& queryVector() const { return m_queries; }63 60 const Vector<MediaQuery>& queryVector() const { return m_queries; } 61 64 62 int lastLine() const { return m_lastLine; } 65 63 void setLastLine(int lastLine) { m_lastLine = lastLine; } 66 64 67 65 String mediaText() const; 68 66 … … 73 71 MediaQuerySet(const String& mediaQuery, bool fallbackToDescription); 74 72 MediaQuerySet(const MediaQuerySet&); 75 73 74 Optional<MediaQuery> internalParse(CSSParser&, const String&); 75 Optional<MediaQuery> internalParse(const String&); 76 76 77 unsigned m_fallbackToDescriptor : 1; // true if failed media query parsing should fallback to media description parsing. 77 78 signed m_lastLine : 31; 78 Vector< std::unique_ptr<MediaQuery>> m_queries;79 Vector<MediaQuery> m_queries; 79 80 }; 80 81 … … 100 101 void setMediaText(const String&, ExceptionCode&); 101 102 102 // Not part of CSSOM.103 103 CSSRule* parentRule() const { return m_parentRule; } 104 104 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; } 107 107 const MediaQuerySet* queries() const { return m_mediaQueries.get(); } 108 108 … … 115 115 116 116 RefPtr<MediaQuerySet> m_mediaQueries; 117 CSSStyleSheet* m_parentStyleSheet ;118 CSSRule* m_parentRule ;117 CSSStyleSheet* m_parentStyleSheet { nullptr }; 118 CSSRule* m_parentRule { nullptr }; 119 119 }; 120 120 121 #if ENABLE(RESOLUTION_MEDIA_QUERY)122 121 // 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. 123 123 void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*); 124 125 #if !ENABLE(RESOLUTION_MEDIA_QUERY) 126 127 inline void reportMediaQueryWarningIfNeeded(Document*, const MediaQuerySet*) 128 { 129 } 130 124 131 #endif 125 132 126 133 } // namespace 127 128 #endif -
trunk/Source/WebCore/css/MediaQuery.cpp
r201333 r201441 30 30 #include "MediaQuery.h" 31 31 32 #include "MediaQueryExp.h"33 32 #include <wtf/text/StringBuilder.h> 34 33 … … 38 37 String MediaQuery::serialize() const 39 38 { 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; 40 45 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) 60 64 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; 71 67 } 72 68 return result.toString(); 73 69 } 74 70 75 MediaQuery::MediaQuery(Restrictor r , const String& mediaType, std::unique_ptr<ExpressionVector> exprs)76 : m_restrictor(r )71 MediaQuery::MediaQuery(Restrictor restrictor, const String& mediaType, Vector<MediaQueryExpression>&& expressions) 72 : m_restrictor(restrictor) 77 73 , m_mediaType(mediaType.convertToASCIILowercase()) 78 , m_expressions(WTFMove(exprs)) 79 , m_ignored(false) 74 , m_expressions(WTFMove(expressions)) 80 75 { 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; 88 78 }); 89 79 90 // remove all duplicated expressions80 // Remove all duplicated expressions. 91 81 String key; 92 for (int i = m_expressions ->size() - 1; i >= 0; --i) {82 for (int i = m_expressions.size() - 1; i >= 0; --i) { 93 83 94 // if not all of the expressions isvalid the media query must be ignored.84 // If any expression is invalid the media query must be ignored. 95 85 if (!m_ignored) 96 m_ignored = !m_expressions ->at(i)->isValid();86 m_ignored = !m_expressions[i].isValid(); 97 87 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); 100 90 else 101 key = m_expressions ->at(i)->serialize();91 key = m_expressions[i].serialize(); 102 92 } 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 {118 93 } 119 94 … … 125 100 126 101 // http://dev.w3.org/csswg/cssom/#serialize-a-list-of-media-queries 127 StringMediaQuery::cssText() const102 const String& MediaQuery::cssText() const 128 103 { 129 104 if (m_serializationCache.isNull()) 130 const_cast<MediaQuery*>(this)->m_serializationCache = serialize(); 131 105 m_serializationCache = serialize(); 132 106 return m_serializationCache; 133 107 } -
trunk/Source/WebCore/css/MediaQuery.h
r195310 r201441 27 27 */ 28 28 29 #ifndef MediaQuery_h 30 #define MediaQuery_h 29 #pragma once 31 30 32 #include <memory>31 #include "MediaQueryExp.h" 33 32 #include <wtf/Vector.h> 34 #include <wtf/text/StringHash.h>35 #include <wtf/text/WTFString.h>36 33 37 34 namespace WebCore { 38 class MediaQueryExp;39 35 40 36 class MediaQuery { 41 37 WTF_MAKE_FAST_ALLOCATED; 42 38 public: 43 enum Restrictor { 44 Only, Not, None 45 }; 39 enum Restrictor { Only, Not, None }; 46 40 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>&&); 52 42 53 43 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; } 58 46 bool ignored() const { return m_ignored; } 59 47 60 std::unique_ptr<MediaQuery> copy() const { return std::make_unique<MediaQuery>(*this); }48 const String& cssText() const; 61 49 62 private: 50 bool operator==(const MediaQuery& other) const; 51 52 private: 53 String serialize() const; 54 63 55 Restrictor m_restrictor; 64 56 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; 70 60 }; 71 61 72 62 } // namespace 73 74 #endif -
trunk/Source/WebCore/css/MediaQueryEvaluator.cpp
r201065 r201441 42 42 #include "MediaList.h" 43 43 #include "MediaQuery.h" 44 #include "MediaQueryExp.h"45 44 #include "NodeRenderStyle.h" 46 45 #include "Page.h" … … 59 58 namespace WebCore { 60 59 61 using namespace MediaFeatureNames;62 63 60 enum MediaFeaturePrefix { MinPrefix, MaxPrefix, NoPrefix }; 64 61 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 */ 62 typedef bool (*MediaQueryFunction)(CSSValue*, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix); 63 typedef HashMap<AtomicStringImpl*, MediaQueryFunction> MediaQueryFunctionMap; 64 65 static 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 } 76 78 77 79 MediaQueryEvaluator::MediaQueryEvaluator(bool mediaFeatureResult) 78 : m_ expResult(mediaFeatureResult)80 : m_fallbackResult(mediaFeatureResult) 79 81 { 80 82 } … … 82 84 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult) 83 85 : 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 90 MediaQueryEvaluator::MediaQueryEvaluator(const String& acceptedMediaType, Document& document, const RenderStyle* style) 89 91 : m_mediaType(acceptedMediaType) 90 , m_frame( frame)92 , m_frame(document.frame()) 91 93 , m_style(style) 92 , m_expResult(false) // doesn't matter when we have m_frame and m_style93 {94 }95 96 MediaQueryEvaluator::~MediaQueryEvaluator()97 94 { 98 95 } … … 119 116 } 120 117 121 bool MediaQueryEvaluator::eval(const MediaQuerySet* querySet, StyleResolver* styleResolver) const 122 { 123 if (!querySet) 124 return true; 125 126 auto& queries = querySet->queryVector(); 118 bool MediaQueryEvaluator::evaluate(const MediaQuerySet& querySet, StyleResolver* styleResolver) const 119 { 120 auto& queries = querySet.queryVector(); 127 121 if (!queries.size()) 128 122 return true; // empty query list evaluates to true … … 131 125 bool result = false; 132 126 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())) 136 130 continue; 137 131 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) 142 135 size_t j = 0; 143 136 for (; j < expressions.size(); ++j) { 144 bool expr Result = eval(expressions.at(j).get());145 if (styleResolver && expressions.at(j)->isViewportDependent())146 styleResolver->addViewportDependentMediaQueryResult(expressions .at(j).get(), exprResult);147 if (!expr Result)137 bool expressionResult = evaluate(expressions[j]); 138 if (styleResolver && isViewportDependent(expressions[j].mediaFeature())) 139 styleResolver->addViewportDependentMediaQueryResult(expressions[j], expressionResult); 140 if (!expressionResult) 148 141 break; 149 142 } … … 151 144 // assume true if we are at the end of the list, 152 145 // otherwise assume false 153 result = applyRestrictor(query ->restrictor(), expressions.size() == j);146 result = applyRestrictor(query.restrictor(), expressions.size() == j); 154 147 } else 155 result = applyRestrictor(query ->restrictor(), false);148 result = applyRestrictor(query.restrictor(), false); 156 149 } 157 150 … … 159 152 } 160 153 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(); 154 bool MediaQueryEvaluator::evaluate(const MediaQuerySet& querySet, Vector<MediaQueryResult>& results) const 155 { 156 auto& queries = querySet.queryVector(); 167 157 if (!queries.size()) 168 158 return true; … … 170 160 bool result = false; 171 161 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()) 175 165 continue; 176 166 177 if (mediaTypeMatch(query ->mediaType())) {178 auto& expressions = query ->expressions();167 if (mediaTypeMatch(query.mediaType())) { 168 auto& expressions = query.expressions(); 179 169 size_t j = 0; 180 170 for (; j < expressions.size(); ++j) { 181 bool expr Result = eval(expressions.at(j).get());182 if ( expressions.at(j)->isViewportDependent())183 results.append( std::make_unique<MediaQueryResult>(*expressions.at(j), exprResult));184 if (!expr Result)171 bool expressionResult = evaluate(expressions[j]); 172 if (isViewportDependent(expressions[j].mediaFeature())) 173 results.append({ expressions[j], expressionResult }); 174 if (!expressionResult) 185 175 break; 186 176 } 187 result = applyRestrictor(query ->restrictor(), expressions.size() == j);177 result = applyRestrictor(query.restrictor(), expressions.size() == j); 188 178 } else 189 result = applyRestrictor(query ->restrictor(), false);179 result = applyRestrictor(query.restrictor(), false); 190 180 } 191 181 … … 193 183 } 194 184 195 template<typename T> 196 bool compareValue(T a, T b, MediaFeaturePrefix op) 185 template<typename T, typename U> bool compareValue(T a, U b, MediaFeaturePrefix op) 197 186 { 198 187 switch (op) { … … 209 198 static bool compareAspectRatioValue(CSSValue* value, int width, int height, MediaFeaturePrefix op) 210 199 { 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 206 static 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 213 static bool zeroEvaluate(CSSValue* value, MediaFeaturePrefix op) 214 { 215 auto numericValue = doubleValue(value); 216 return numericValue && compareValue(0, numericValue.value(), op); 217 } 218 219 static 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 227 static 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 236 static bool colorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op) 237 { 238 // Always return false for indexed display. 239 return zeroEvaluate(value, op); 240 } 241 242 static bool colorGamutEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix) 250 243 { 251 244 if (!value) … … 256 249 return true; 257 250 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()); 261 253 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. 264 255 return false; 265 256 default: … … 269 260 } 270 261 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) 262 static 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 269 static bool invertedColorsEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix) 285 270 { 286 271 bool isInverted = screenHasInvertedColors(); 287 288 272 if (!value) 289 273 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 277 static bool orientationEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix) 278 { 279 FrameView* view = frame.view(); 298 280 if (!view) 299 281 return false; 300 282 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 297 static bool aspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op) 298 { 323 299 // ({,min-,max-}aspect-ratio) 324 300 // 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 311 static bool deviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op) 312 { 335 313 // ({,min-,max-}device-aspect-ratio) 336 314 // 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 322 static bool evaluateResolution(CSSValue* value, Frame& frame, MediaFeaturePrefix op) 341 323 { 342 324 // FIXME: Possible handle other media types than 'screen' and 'print'. 343 FrameView* view = frame ->view();325 FrameView* view = frame.view(); 344 326 if (!view) 345 327 return false; 346 328 347 329 float deviceScaleFactor = 0; 330 348 331 // This checks the actual media type applied to the document, and we know 349 332 // this method only got called if this media type matches the one defined … … 352 335 String mediaType = view->mediaType(); 353 336 if (equalLettersIgnoringASCIICase(mediaType, "screen")) 354 deviceScaleFactor = frame ->page()->deviceScaleFactor();337 deviceScaleFactor = frame.page() ? frame.page()->deviceScaleFactor() : 1; 355 338 else if (equalLettersIgnoringASCIICase(mediaType, "print")) { 356 339 // The resolution of images while printing should not depend on the dpi … … 363 346 return !!deviceScaleFactor; 364 347 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); 369 352 return compareValue(deviceScaleFactor, resolution.isNumber() ? resolution.getFloatValue() : resolution.getFloatValue(CSSPrimitiveValue::CSS_DPPX), op); 370 353 } 371 354 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 resolution MediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*frame, MediaFeaturePrefix op)355 static 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 360 static bool resolutionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op) 378 361 { 379 362 #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); 381 364 #else 382 365 UNUSED_PARAM(value); … … 387 370 } 388 371 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; 372 static bool gridEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op) 373 { 374 return zeroEvaluate(value, op); 397 375 } 398 376 399 377 static bool computeLength(CSSValue* value, bool strict, const CSSToLengthConversionData& conversionData, int& result) 400 378 { 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); 405 383 406 384 if (primitiveValue.isNumber()) { … … 417 395 } 418 396 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 } 397 static bool deviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op) 398 { 427 399 // ({,min-,max-}device-height) 428 400 // 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 408 static bool deviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op) 409 { 440 410 // ({,min-,max-}device-width) 441 411 // 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 419 static bool heightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op) 420 { 421 FrameView* view = frame.view(); 448 422 if (!view) 449 423 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 433 static bool widthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix op) 434 { 435 FrameView* view = frame.view(); 465 436 if (!view) 466 437 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 447 static bool minColorEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 448 { 449 return colorEvaluate(value, conversionData, frame, MinPrefix); 450 } 451 452 static bool maxColorEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 453 { 454 return colorEvaluate(value, conversionData, frame, MaxPrefix); 455 } 456 457 static bool minColorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 458 { 459 return colorIndexEvaluate(value, conversionData, frame, MinPrefix); 460 } 461 462 static bool maxColorIndexEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 463 { 464 return colorIndexEvaluate(value, conversionData, frame, MaxPrefix); 465 } 466 467 static bool minMonochromeEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 468 { 469 return monochromeEvaluate(value, conversionData, frame, MinPrefix); 470 } 471 472 static bool maxMonochromeEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 473 { 474 return monochromeEvaluate(value, conversionData, frame, MaxPrefix); 475 } 476 477 static bool minAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 478 { 479 return aspectRatioEvaluate(value, conversionData, frame, MinPrefix); 480 } 481 482 static bool maxAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 483 { 484 return aspectRatioEvaluate(value, conversionData, frame, MaxPrefix); 485 } 486 487 static bool minDeviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 488 { 489 return deviceAspectRatioEvaluate(value, conversionData, frame, MinPrefix); 490 } 491 492 static bool maxDeviceAspectRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 493 { 494 return deviceAspectRatioEvaluate(value, conversionData, frame, MaxPrefix); 495 } 496 497 static bool minDevicePixelRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 498 { 499 return devicePixelRatioEvaluate(value, conversionData, frame, MinPrefix); 500 } 501 502 static bool maxDevicePixelRatioEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 503 { 504 return devicePixelRatioEvaluate(value, conversionData, frame, MaxPrefix); 505 } 506 507 static bool minHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 508 { 509 return heightEvaluate(value, conversionData, frame, MinPrefix); 510 } 511 512 static bool maxHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 513 { 514 return heightEvaluate(value, conversionData, frame, MaxPrefix); 515 } 516 517 static bool minWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 518 { 519 return widthEvaluate(value, conversionData, frame, MinPrefix); 520 } 521 522 static bool maxWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 523 { 524 return widthEvaluate(value, conversionData, frame, MaxPrefix); 525 } 526 527 static bool minDeviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 528 { 529 return deviceHeightEvaluate(value, conversionData, frame, MinPrefix); 530 } 531 532 static bool maxDeviceHeightEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 533 { 534 return deviceHeightEvaluate(value, conversionData, frame, MaxPrefix); 535 } 536 537 static bool minDeviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 538 { 539 return deviceWidthEvaluate(value, conversionData, frame, MinPrefix); 540 } 541 542 static bool maxDeviceWidthEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 543 { 544 return deviceWidthEvaluate(value, conversionData, frame, MaxPrefix); 545 } 546 547 static bool minResolutionEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 548 { 549 return resolutionEvaluate(value, conversionData, frame, MinPrefix); 550 } 551 552 static bool maxResolutionEvaluate(CSSValue* value, const CSSToLengthConversionData& conversionData, Frame& frame, MediaFeaturePrefix) 553 { 554 return resolutionEvaluate(value, conversionData, frame, MaxPrefix); 555 } 556 557 static bool animationEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op) 558 { 559 return oneEvaluate(value, op); 560 } 561 562 static bool transitionEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op) 563 { 564 return oneEvaluate(value, op); 565 } 566 567 static bool transform2dEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix op) 568 { 569 return oneEvaluate(value, op); 570 } 571 572 static bool transform3dEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix op) 573 { 623 574 #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); 630 577 #else 631 578 UNUSED_PARAM(frame); 632 returnValueIfNoParameter = false; 633 have3dRendering = 0; 579 return zeroEvaluate(value, op); 634 580 #endif 635 636 if (value) {637 float number;638 return numberValue(value, number) && compareValue(have3dRendering, static_cast<int>(number), op);639 }640 return returnValueIfNoParameter;641 581 } 642 582 643 583 #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 585 static 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()) { 654 593 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: 656 604 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 676 610 #endif // ENABLE(VIEW_MODE_CSS_MEDIA) 677 611 678 static bool video _playable_inlineMediaFeatureEval(CSSValue*, const CSSToLengthConversionData&, Frame*frame, MediaFeaturePrefix)679 { 680 return frame ->settings().allowsInlineMediaPlayback();681 } 682 683 static bool hover MediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)612 static bool videoPlayableInlineEvaluate(CSSValue*, const CSSToLengthConversionData&, Frame& frame, MediaFeaturePrefix) 613 { 614 return frame.settings().allowsInlineMediaPlayback(); 615 } 616 617 static bool hoverEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix) 684 618 { 685 619 if (!is<CSSPrimitiveValue>(value)) { … … 691 625 } 692 626 693 int hoverCSSKeywordID= downcast<CSSPrimitiveValue>(*value).getValueID();627 auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID(); 694 628 #if ENABLE(TOUCH_EVENTS) 695 return hoverCSSKeywordID== CSSValueNone;629 return keyword == CSSValueNone; 696 630 #else 697 return hoverCSSKeywordID== CSSValueHover;631 return keyword == CSSValueHover; 698 632 #endif 699 633 } 700 634 701 static bool any _hoverMediaFeatureEval(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame*frame, MediaFeaturePrefix prefix)702 { 703 return hover MediaFeatureEval(value, cssToLengthConversionData, frame, prefix);704 } 705 706 static bool pointer MediaFeatureEval(CSSValue* value, const CSSToLengthConversionData&, Frame*, MediaFeaturePrefix)635 static bool anyHoverEvaluate(CSSValue* value, const CSSToLengthConversionData& cssToLengthConversionData, Frame& frame, MediaFeaturePrefix prefix) 636 { 637 return hoverEvaluate(value, cssToLengthConversionData, frame, prefix); 638 } 639 640 static bool pointerEvaluate(CSSValue* value, const CSSToLengthConversionData&, Frame&, MediaFeaturePrefix) 707 641 { 708 642 if (!is<CSSPrimitiveValue>(value)) 709 643 return true; 710 644 711 int pointerCSSKeywordID= downcast<CSSPrimitiveValue>(*value).getValueID();645 auto keyword = downcast<CSSPrimitiveValue>(*value).getValueID(); 712 646 #if ENABLE(TOUCH_EVENTS) 713 return pointerCSSKeywordID== CSSValueCoarse;647 return keyword == CSSValueCoarse; 714 648 #else 715 return pointerCSSKeywordID== CSSValueFine;649 return keyword == CSSValueFine; 716 650 #endif 717 651 } 718 652 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); 653 static 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. 659 static void add(MediaQueryFunctionMap& map, AtomicStringImpl* key, MediaQueryFunction value) 660 { 661 map.add(key, value); 662 } 663 664 bool 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); 731 676 #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); 757 686 } 758 687 -
trunk/Source/WebCore/css/MediaQueryEvaluator.h
r200098 r201441 26 26 */ 27 27 28 #ifndef MediaQueryEvaluator_h 29 #define MediaQueryEvaluator_h 28 #pragma once 30 29 31 30 #include "MediaQueryExp.h" 32 #include <wtf/text/WTFString.h>33 31 34 32 namespace WebCore { 33 34 class Document; 35 35 class Frame; 36 class MediaQueryExp;37 36 class MediaQuerySet; 38 37 class RenderStyle; 39 38 class StyleResolver; 40 39 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; 40 struct MediaQueryResult { 41 MediaQueryExpression expression; 42 bool result; 52 43 }; 53 44 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 66 48 class MediaQueryEvaluator { 67 WTF_MAKE_NONCOPYABLE(MediaQueryEvaluator); WTF_MAKE_FAST_ALLOCATED;68 49 public: 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. 73 52 explicit MediaQueryEvaluator(bool mediaFeatureResult = false); 74 53 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. 79 56 MediaQueryEvaluator(const String& acceptedMediaType, bool mediaFeatureResult = false); 80 57 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*); 86 60 87 61 bool mediaTypeMatch(const String& mediaTypeToMatch) const; 88 62 bool mediaTypeMatchSpecific(const char* mediaTypeToMatch) const; 89 63 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; 92 66 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 eval CheckingViewportDependentResults(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; 98 72 99 73 private: … … 101 75 Frame* m_frame { nullptr }; // not owned 102 76 const RenderStyle* m_style { nullptr }; 103 bool m_ expResult;77 bool m_fallbackResult { false }; 104 78 }; 105 79 106 80 } // namespace 107 #endif -
trunk/Source/WebCore/css/MediaQueryExp.cpp
r199024 r201441 33 33 #include "CSSPrimitiveValue.h" 34 34 #include "CSSValueList.h" 35 #include "MediaFeatureNames.h" 35 36 #include <wtf/text/StringBuilder.h> 36 37 37 38 namespace WebCore { 38 39 39 static inline bool featureWithCSSValueID(const AtomicString& mediaFeature, const CSSParserValue*value)40 { 41 if (!value ->id)42 return false; 43 44 return mediaFeature == MediaFeatureNames::orientation MediaFeature40 static inline bool isFeatureValidWithIdentifier(const AtomicString& mediaFeature, const CSSParserValue& value) 41 { 42 if (!value.id) 43 return false; 44 45 return mediaFeature == MediaFeatureNames::orientation 45 46 #if ENABLE(VIEW_MODE_CSS_MEDIA) 46 || mediaFeature == MediaFeatureNames::view _modeMediaFeature47 #endif // ENABLE(VIEW_MODE_CSS_MEDIA)48 || mediaFeature == MediaFeatureNames::color _gamutMediaFeature49 || mediaFeature == MediaFeatureNames::any _hoverMediaFeature50 || mediaFeature == MediaFeatureNames::any _pointerMediaFeature51 || mediaFeature == MediaFeatureNames::hover MediaFeature52 || mediaFeature == MediaFeatureNames::inverted _colorsMediaFeature53 || mediaFeature == MediaFeatureNames::pointer MediaFeature;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::height MediaFeature62 || mediaFeature == MediaFeatureNames::max _heightMediaFeature63 || mediaFeature == MediaFeatureNames::min _heightMediaFeature64 || mediaFeature == MediaFeatureNames::width MediaFeature65 || mediaFeature == MediaFeatureNames::max _widthMediaFeature66 || mediaFeature == MediaFeatureNames::min _widthMediaFeature67 || mediaFeature == MediaFeatureNames::device _heightMediaFeature68 || mediaFeature == MediaFeatureNames::max _device_heightMediaFeature69 || mediaFeature == MediaFeatureNames::min _device_heightMediaFeature70 || mediaFeature == MediaFeatureNames::device _widthMediaFeature71 || mediaFeature == MediaFeatureNames::max _device_widthMediaFeature72 || 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::resolution MediaFeature81 || mediaFeature == MediaFeatureNames::max _resolutionMediaFeature82 || 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::color MediaFeature91 || mediaFeature == MediaFeatureNames::max _colorMediaFeature92 || mediaFeature == MediaFeatureNames::min _colorMediaFeature93 || mediaFeature == MediaFeatureNames::color _indexMediaFeature94 || mediaFeature == MediaFeatureNames::max _color_indexMediaFeature95 || mediaFeature == MediaFeatureNames::min _color_indexMediaFeature96 || mediaFeature == MediaFeatureNames::min _monochromeMediaFeature97 || 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 _2dMediaFeature106 || mediaFeature == MediaFeatureNames::transform _3dMediaFeature107 || mediaFeature == MediaFeatureNames::transition MediaFeature108 || mediaFeature == MediaFeatureNames::animation MediaFeature109 || mediaFeature == MediaFeatureNames::device _pixel_ratioMediaFeature110 || mediaFeature == MediaFeatureNames::max _device_pixel_ratioMediaFeature111 || 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::grid MediaFeature;120 } 121 122 static inline bool featureWithAspectRatio(const AtomicString& mediaFeature)123 { 124 return mediaFeature == MediaFeatureNames::aspect _ratioMediaFeature125 || mediaFeature == MediaFeatureNames::device _aspect_ratioMediaFeature126 || mediaFeature == MediaFeatureNames::min _aspect_ratioMediaFeature127 || mediaFeature == MediaFeatureNames::max _aspect_ratioMediaFeature128 || mediaFeature == MediaFeatureNames::min _device_aspect_ratioMediaFeature129 || 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 57 static 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 76 static 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 86 static 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 101 static 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 115 static 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 123 static 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 133 static inline bool isFeatureValidWithoutValue(const AtomicString& mediaFeature) 133 134 { 134 135 // Media features that are prefixed by min/max cannot be used without a value. 135 return mediaFeature == MediaFeatureNames::any _hoverMediaFeature136 || mediaFeature == MediaFeatureNames::any _pointerMediaFeature137 || mediaFeature == MediaFeatureNames::monochrome MediaFeature138 || mediaFeature == MediaFeatureNames::color MediaFeature139 || mediaFeature == MediaFeatureNames::color _indexMediaFeature140 || mediaFeature == MediaFeatureNames::grid MediaFeature141 || mediaFeature == MediaFeatureNames::height MediaFeature142 || mediaFeature == MediaFeatureNames::width MediaFeature143 || mediaFeature == MediaFeatureNames::device _heightMediaFeature144 || mediaFeature == MediaFeatureNames::device _widthMediaFeature145 || mediaFeature == MediaFeatureNames::orientation MediaFeature146 || mediaFeature == MediaFeatureNames::aspect _ratioMediaFeature147 || mediaFeature == MediaFeatureNames::device _aspect_ratioMediaFeature148 || mediaFeature == MediaFeatureNames::hover MediaFeature149 || mediaFeature == MediaFeatureNames::transform _2dMediaFeature150 || mediaFeature == MediaFeatureNames::transform _3dMediaFeature151 || mediaFeature == MediaFeatureNames::transition MediaFeature152 || mediaFeature == MediaFeatureNames::animation MediaFeature153 || mediaFeature == MediaFeatureNames::inverted _colorsMediaFeature136 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 154 155 #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 164 static inline bool isFeatureValidWithNumberWithUnit(const AtomicString& mediaFeature, const CSSParserValue& value) 165 { 166 return isFeatureValidWithDensity(mediaFeature, value) || isFeatureValidWithNonNegativeLengthOrNumber(mediaFeature, value); 167 } 168 169 static inline bool isFeatureValidWithNumber(const AtomicString& mediaFeature, const CSSParserValue& value) 170 { 171 return isFeatureValidWithNonNegativeInteger(mediaFeature, value) || isFeatureValidWithNonNegativeNumber(mediaFeature, value) || isFeatureValidWithZeroOrOne(mediaFeature, value); 172 } 173 174 static inline bool isSlash(CSSParserValue& value) 175 { 176 return value.unit == CSSParserValue::Operator && value.iValue == '/'; 177 } 178 179 static inline bool isPositiveIntegerValue(CSSParserValue& value) 180 { 181 return value.unit == CSSPrimitiveValue::CSS_NUMBER && value.fValue > 0 && value.isInt; 182 } 183 184 MediaQueryExpression::MediaQueryExpression(const AtomicString& mediaFeature, CSSParserValueList* valueList) 164 185 : m_mediaFeature(mediaFeature) 165 186 { 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; 224 202 } 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 214 String MediaQueryExpression::serialize() const 230 215 { 231 216 if (!m_serializationCache.isNull()) -
trunk/Source/WebCore/css/MediaQueryExp.h
r195310 r201441 26 26 */ 27 27 28 #ifndef MediaQueryExp_h 29 #define MediaQueryExp_h 28 #pragma once 30 29 31 30 #include "CSSValue.h" 32 #include "MediaFeatureNames.h"33 31 #include <memory> 34 #include <wtf/text/AtomicString.h>35 32 36 33 namespace WebCore { … … 38 35 class CSSParserValueList; 39 36 40 class MediaQueryExp { 37 // FIXME: Rename the file to match this class's name. 38 class MediaQueryExpression { 41 39 WTF_MAKE_FAST_ALLOCATED; 42 40 public: 43 explicit MediaQueryExp (const AtomicString& mediaFeature = emptyAtom, CSSParserValueList* values = nullptr);41 explicit MediaQueryExpression(const AtomicString& mediaFeature = emptyAtom, CSSParserValueList* values = nullptr); 44 42 45 43 const AtomicString& mediaFeature() const; … … 47 45 48 46 bool isValid() const; 49 bool isViewportDependent() const;50 47 51 48 String serialize() const; 52 49 53 bool operator==(const MediaQueryExp &) const;50 bool operator==(const MediaQueryExpression&) const; 54 51 55 52 private: … … 60 57 }; 61 58 62 inline const AtomicString& MediaQueryExp ::mediaFeature() const59 inline const AtomicString& MediaQueryExpression::mediaFeature() const 63 60 { 64 61 return m_mediaFeature; 65 62 } 66 63 67 inline CSSValue* MediaQueryExp ::value() const64 inline CSSValue* MediaQueryExpression::value() const 68 65 { 69 66 return m_value.get(); 70 67 } 71 68 72 inline bool MediaQueryExp ::operator==(const MediaQueryExp& other) const69 inline bool MediaQueryExpression::operator==(const MediaQueryExpression& other) const 73 70 { 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)); 77 73 } 78 74 79 inline bool MediaQueryExp ::isValid() const75 inline bool MediaQueryExpression::isValid() const 80 76 { 81 77 return m_isValid; 82 78 } 83 79 84 inline bool MediaQueryExp::isViewportDependent() const85 {86 return m_mediaFeature == MediaFeatureNames::widthMediaFeature87 || m_mediaFeature == MediaFeatureNames::heightMediaFeature88 || m_mediaFeature == MediaFeatureNames::min_widthMediaFeature89 || m_mediaFeature == MediaFeatureNames::min_heightMediaFeature90 || m_mediaFeature == MediaFeatureNames::max_widthMediaFeature91 || m_mediaFeature == MediaFeatureNames::max_heightMediaFeature92 || m_mediaFeature == MediaFeatureNames::orientationMediaFeature93 || m_mediaFeature == MediaFeatureNames::aspect_ratioMediaFeature94 || m_mediaFeature == MediaFeatureNames::min_aspect_ratioMediaFeature95 || m_mediaFeature == MediaFeatureNames::max_aspect_ratioMediaFeature;96 }97 98 80 } // namespace 99 100 #endif -
trunk/Source/WebCore/css/MediaQueryList.cpp
r185238 r201441 28 28 namespace WebCore { 29 29 30 Ref<MediaQueryList> MediaQueryList::create(PassRefPtr<MediaQueryMatcher> vector, PassRefPtr<MediaQuerySet> media, bool matches) 30 inline 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) 31 36 { 32 return adoptRef(*new MediaQueryList(vector, media, matches));33 37 } 34 38 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) 39 Ref<MediaQueryList> MediaQueryList::create(MediaQueryMatcher& matcher, Ref<MediaQuerySet>&& media, bool matches) 41 40 { 41 return adoptRef(*new MediaQueryList(matcher, WTFMove(media), matches)); 42 42 } 43 43 … … 51 51 } 52 52 53 void MediaQueryList::addListener( PassRefPtr<MediaQueryListListener>listener)53 void MediaQueryList::addListener(RefPtr<MediaQueryListListener>&& listener) 54 54 { 55 55 if (!listener) 56 56 return; 57 57 58 m_matcher->addListener(listener ,this);58 m_matcher->addListener(listener.releaseNonNull(), *this); 59 59 } 60 60 61 void MediaQueryList::removeListener( PassRefPtr<MediaQueryListListener>listener)61 void MediaQueryList::removeListener(RefPtr<MediaQueryListListener>&& listener) 62 62 { 63 63 if (!listener) 64 64 return; 65 65 66 m_matcher->removeListener( listener.get(),this);66 m_matcher->removeListener(*listener, *this); 67 67 } 68 68 69 void MediaQueryList::evaluate(MediaQueryEvaluator *evaluator, bool& notificationNeeded)69 void MediaQueryList::evaluate(MediaQueryEvaluator& evaluator, bool& notificationNeeded) 70 70 { 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())); 73 73 notificationNeeded = m_changeRound == m_matcher->evaluationRound(); 74 74 } -
trunk/Source/WebCore/css/MediaQueryList.h
r185238 r201441 18 18 */ 19 19 20 #ifndef MediaQueryList_h 21 #define MediaQueryList_h 20 #pragma once 22 21 23 22 #include <wtf/Forward.h> … … 39 38 class MediaQueryList : public RefCounted<MediaQueryList> { 40 39 public: 41 static Ref<MediaQueryList> create( PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool);40 static Ref<MediaQueryList> create(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool); 42 41 ~MediaQueryList(); 43 42 … … 45 44 bool matches(); 46 45 47 void addListener( PassRefPtr<MediaQueryListListener>);48 void removeListener( PassRefPtr<MediaQueryListListener>);46 void addListener(RefPtr<MediaQueryListListener>&&); 47 void removeListener(RefPtr<MediaQueryListListener>&&); 49 48 50 void evaluate(MediaQueryEvaluator *, bool& notificationNeeded);49 void evaluate(MediaQueryEvaluator&, bool& notificationNeeded); 51 50 52 51 private: 53 MediaQueryList(PassRefPtr<MediaQueryMatcher>, PassRefPtr<MediaQuerySet>, bool matches); 52 MediaQueryList(MediaQueryMatcher&, Ref<MediaQuerySet>&&, bool matches); 53 54 54 void setMatches(bool); 55 55 56 Ref Ptr<MediaQueryMatcher> m_matcher;57 Ref Ptr<MediaQuerySet> m_media;56 Ref<MediaQueryMatcher> m_matcher; 57 Ref<MediaQuerySet> m_media; 58 58 unsigned m_evaluationRound; // Indicates if the query has been evaluated after the last style selector change. 59 59 unsigned m_changeRound; // Used to know if the query has changed in the last style selector change. … … 62 62 63 63 } 64 65 #endif // MediaQueryList_h -
trunk/Source/WebCore/css/MediaQueryMatcher.cpp
r201333 r201441 22 22 23 23 #include "Document.h" 24 #include "Element.h"25 24 #include "Frame.h" 26 25 #include "FrameView.h" … … 34 33 namespace WebCore { 35 34 36 MediaQueryMatcher::Listener::Listener(PassRefPtr<MediaQueryListListener> listener, PassRefPtr<MediaQueryList> query) 37 : m_listener(listener) 38 , m_query(query) 35 MediaQueryMatcher::MediaQueryMatcher(Document& document) 36 : m_document(&document) 39 37 { 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);59 38 } 60 39 … … 66 45 { 67 46 m_listeners.clear(); 68 m_document = 0;47 m_document = nullptr; 69 48 } 70 49 … … 82 61 return nullptr; 83 62 84 Element* documentElement = m_document->documentElement();63 auto* documentElement = m_document->documentElement(); 85 64 if (!documentElement) 86 65 return nullptr; … … 89 68 } 90 69 91 bool MediaQueryMatcher::evaluate(const MediaQuerySet *media)70 bool MediaQueryMatcher::evaluate(const MediaQuerySet& media) 92 71 { 93 if (!media)94 return false;95 96 72 auto style = documentElementUserAgentStyle(); 97 73 if (!style) 98 74 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); 101 76 } 102 77 … … 106 81 return nullptr; 107 82 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); 114 87 } 115 88 116 void MediaQueryMatcher::addListener( PassRefPtr<MediaQueryListListener> listener, PassRefPtr<MediaQueryList>query)89 void MediaQueryMatcher::addListener(Ref<MediaQueryListListener>&& listener, MediaQueryList& query) 117 90 { 118 91 if (!m_document) 119 92 return; 120 93 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) 123 96 return; 124 97 } 125 98 126 m_listeners.append( std::make_unique<Listener>(listener, query));99 m_listeners.append(Listener { WTFMove(listener), query }); 127 100 } 128 101 129 void MediaQueryMatcher::removeListener(MediaQueryListListener * listener, MediaQueryList*query)102 void MediaQueryMatcher::removeListener(MediaQueryListListener& listener, MediaQueryList& query) 130 103 { 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; 136 106 }); 137 107 } … … 146 116 if (!style) 147 117 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 } 151 126 } 152 127 -
trunk/Source/WebCore/css/MediaQueryMatcher.h
r199964 r201441 18 18 */ 19 19 20 #ifndef MediaQueryMatcher_h 21 #define MediaQueryMatcher_h 20 #pragma once 22 21 23 22 #include <memory> … … 38 37 // MediaQueryList x MediaQueryListListener. It is responsible for evaluating the queries 39 38 // 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 beenadded.39 // The listeners must be called in the order in which they were added. 41 40 42 41 class MediaQueryMatcher : public RefCounted<MediaQueryMatcher> { 43 42 public: 44 static Ref<MediaQueryMatcher> create(Document *document) { return adoptRef(*new MediaQueryMatcher(document)); }43 static Ref<MediaQueryMatcher> create(Document& document) { return adoptRef(*new MediaQueryMatcher(document)); } 45 44 ~MediaQueryMatcher(); 45 46 46 void documentDestroyed(); 47 47 48 void addListener( PassRefPtr<MediaQueryListListener>, PassRefPtr<MediaQueryList>);49 void removeListener(MediaQueryListListener *, MediaQueryList*);48 void addListener(Ref<MediaQueryListListener>&&, MediaQueryList&); 49 void removeListener(MediaQueryListListener&, MediaQueryList&); 50 50 51 51 RefPtr<MediaQueryList> matchMedia(const String&); 52 52 53 53 unsigned evaluationRound() const { return m_evaluationRound; } 54 54 55 void styleResolverChanged(); 55 bool evaluate(const MediaQuerySet*); 56 57 bool evaluate(const MediaQuerySet&); 56 58 57 59 private: 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; 72 63 }; 73 64 74 MediaQueryMatcher(Document*);65 explicit MediaQueryMatcher(Document&); 75 66 std::unique_ptr<RenderStyle> documentElementUserAgentStyle() const; 76 67 String mediaType() const; 77 68 78 69 Document* m_document; 79 Vector< std::unique_ptr<Listener>> m_listeners;70 Vector<Listener> m_listeners; 80 71 81 72 // This value is incremented at style selector changes. 82 73 // It is used to avoid evaluating queries more then once and to make sure 83 74 // that a media query result change is notified exactly once. 84 unsigned m_evaluationRound ;75 unsigned m_evaluationRound { 1 }; 85 76 }; 86 77 87 78 } // namespace WebCore 88 89 #endif // MediaQueryMatcher_h -
trunk/Source/WebCore/css/RuleSet.cpp
r201290 r201441 338 338 else if (is<StyleRuleMedia>(*rule)) { 339 339 auto& mediaRule = downcast<StyleRuleMedia>(*rule); 340 if ((!mediaRule.mediaQueries() || medium.eval (mediaRule.mediaQueries(), resolver)))340 if ((!mediaRule.mediaQueries() || medium.evaluate(*mediaRule.mediaQueries(), resolver))) 341 341 addChildRules(mediaRule.childRules(), medium, resolver, hasDocumentSecurityOrigin, isInitiatingElementInUserAgentShadowTree, addRuleFlags); 342 342 } else if (is<StyleRuleFontFace>(*rule) && resolver) { … … 364 364 { 365 365 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))) 367 367 addRulesFromSheet(*rule->styleSheet(), medium, resolver); 368 368 } -
trunk/Source/WebCore/css/SourceSizeList.cpp
r200098 r201441 25 25 #include "CSSToLengthConversionData.h" 26 26 #include "MediaList.h" 27 #include "MediaQuery.h"28 27 #include "MediaQueryEvaluator.h" 29 #include "MediaQueryExp.h"30 28 #include "RenderStyle.h" 31 29 #include "RenderView.h" … … 33 31 namespace WebCore { 34 32 35 static bool match( std::unique_ptr<MediaQueryExp>&& expression, const RenderStyle& style, Frame* frame)33 static bool match(const MediaQueryExpression& expression, const RenderStyle& style, Document& document) 36 34 { 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); 48 36 } 49 37 50 static float defaultLength(const RenderStyle& style, RenderView * view)38 static float defaultLength(const RenderStyle& style, RenderView& renderer) 51 39 { 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)); 53 41 } 54 42 55 static float computeLength(CSSValue * value, const RenderStyle& style, RenderView* view)43 static float computeLength(CSSValue& value, const RenderStyle& style, RenderView& renderer) 56 44 { 57 CSSToLengthConversionData conversionData(&style, &style, view);45 CSSToLengthConversionData conversionData(&style, &style, &renderer); 58 46 if (is<CSSPrimitiveValue>(value)) { 59 CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>( *value);47 CSSPrimitiveValue& primitiveValue = downcast<CSSPrimitiveValue>(value); 60 48 if (!primitiveValue.isLength()) 61 return defaultLength(style, view);49 return defaultLength(style, renderer); 62 50 return primitiveValue.computeLength<float>(conversionData); 63 51 } 64 52 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); 67 55 } 68 56 69 float parseSizesAttribute( StringView sizesAttribute, RenderView* view, Frame* frame)57 float parseSizesAttribute(Document& document, StringView sizesAttribute) 70 58 { 71 if (!view) 59 auto* renderer = document.renderView(); 60 if (!renderer) 72 61 return 0; 73 auto& style = view->style();62 auto& style = renderer->style(); 74 63 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); 77 66 } 78 return defaultLength(style, view);67 return defaultLength(style, *renderer); 79 68 } 80 69 -
trunk/Source/WebCore/css/SourceSizeList.h
r183984 r201441 19 19 */ 20 20 21 #ifndef SourceSizeList_h 22 #define SourceSizeList_h 21 #pragma once 23 22 24 23 #include <wtf/Forward.h> … … 26 25 namespace WebCore { 27 26 28 class Frame; 29 class RenderView; 27 class Document; 30 28 31 float parseSizesAttribute( StringView sizesAttribute, RenderView*, Frame*);29 float parseSizesAttribute(Document&, StringView sizesAttribute); 32 30 33 31 } // namespace WebCore 34 35 #endif // SourceSizeList_h -
trunk/Source/WebCore/css/StyleMedia.cpp
r199964 r201441 64 64 auto rootStyle = document->ensureStyleResolver().styleForElement(*documentElement, document->renderStyle(), MatchOnlyUserAgentRules).renderStyle; 65 65 66 RefPtr<MediaQuerySet>media = MediaQuerySet::create();66 auto media = MediaQuerySet::create(); 67 67 if (!media->parse(query)) 68 68 return false; 69 69 70 MediaQueryEvaluator screenEval(type(), m_frame, rootStyle.get()); 71 return screenEval.eval(media.get()); 70 return MediaQueryEvaluator { type(), *document, rootStyle.get() }.evaluate(media.get()); 72 71 } 73 72 -
trunk/Source/WebCore/css/StyleResolver.cpp
r201290 r201441 271 271 FrameView* view = m_document.view(); 272 272 if (view) 273 m_medi um = std::make_unique<MediaQueryEvaluator>(view->mediaType());273 m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType() }; 274 274 else 275 m_medi um = std::make_unique<MediaQueryEvaluator>("all");275 m_mediaQueryEvaluator = MediaQueryEvaluator { "all" }; 276 276 277 277 if (root) … … 279 279 280 280 if (m_rootDefaultStyle && view) 281 m_medi um = std::make_unique<MediaQueryEvaluator>(view->mediaType(), &view->frame(), m_rootDefaultStyle.get());281 m_mediaQueryEvaluator = MediaQueryEvaluator { view->mediaType(), m_document, m_rootDefaultStyle.get() }; 282 282 283 283 m_ruleSets.resetAuthorStyle(); 284 284 285 m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), *m_medium, *this);285 m_ruleSets.initUserStyle(m_document.extensionStyleSheets(), m_mediaQueryEvaluator, *this); 286 286 287 287 #if ENABLE(SVG_FONTS) … … 296 296 void StyleResolver::appendAuthorStyleSheets(const Vector<RefPtr<CSSStyleSheet>>& styleSheets) 297 297 { 298 m_ruleSets.appendAuthorStyleSheets(styleSheets, m_medium.get(), m_inspectorCSSOMWrappers, this);298 m_ruleSets.appendAuthorStyleSheets(styleSheets, &m_mediaQueryEvaluator, m_inspectorCSSOMWrappers, this); 299 299 if (auto renderView = document().renderView()) 300 300 renderView->style().fontCascade().update(&document().fontSelector()); … … 420 420 ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter()); 421 421 collector.setRegionForStyling(regionForStyling); 422 collector.setMedium( m_medium.get());422 collector.setMedium(&m_mediaQueryEvaluator); 423 423 424 424 if (matchingBehavior == MatchOnlyUserAgentRules) … … 583 583 ElementRuleCollector collector(element, m_ruleSets, m_state.selectorFilter()); 584 584 collector.setPseudoStyleRequest(pseudoStyleRequest); 585 collector.setMedium( m_medium.get());585 collector.setMedium(&m_mediaQueryEvaluator); 586 586 collector.matchUARules(); 587 587 … … 1087 1087 collector.setMode(SelectorChecker::Mode::CollectingRules); 1088 1088 collector.setPseudoStyleRequest(PseudoStyleRequest(pseudoId)); 1089 collector.setMedium( m_medium.get());1089 collector.setMedium(&m_mediaQueryEvaluator); 1090 1090 1091 1091 if (rulesToInclude & UAAndUserCSSRules) { … … 1879 1879 } 1880 1880 1881 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExp * expr, bool result)1882 { 1883 m_viewportDependentMediaQueryResults.append( std::make_unique<MediaQueryResult>(*expr, result));1881 void StyleResolver::addViewportDependentMediaQueryResult(const MediaQueryExpression& expression, bool result) 1882 { 1883 m_viewportDependentMediaQueryResults.append(MediaQueryResult { expression, result }); 1884 1884 } 1885 1885 1886 1886 bool StyleResolver::hasMediaQueriesAffectedByViewportChange() const 1887 1887 { 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) 1891 1890 return true; 1892 1891 } -
trunk/Source/WebCore/css/StyleResolver.h
r201290 r201441 156 156 const DocumentRuleSets& ruleSets() const { return m_ruleSets; } 157 157 158 const MediaQueryEvaluator& mediaQueryEvaluator() const { return *m_medium; }158 const MediaQueryEvaluator& mediaQueryEvaluator() const { return m_mediaQueryEvaluator; } 159 159 160 160 void setOverrideDocumentElementStyle(RenderStyle* style) { m_overrideDocumentElementStyle = style; } … … 202 202 #endif 203 203 204 void addViewportDependentMediaQueryResult(const MediaQueryExp *, bool result);204 void addViewportDependentMediaQueryResult(const MediaQueryExpression&, bool result); 205 205 bool hasViewportDependentMediaQueries() const { return !m_viewportDependentMediaQueryResults.isEmpty(); } 206 206 bool hasMediaQueriesAffectedByViewportChange() const; … … 518 518 Timer m_matchedPropertiesCacheSweepTimer; 519 519 520 std::unique_ptr<MediaQueryEvaluator> m_medium;520 MediaQueryEvaluator m_mediaQueryEvaluator; 521 521 std::unique_ptr<RenderStyle> m_rootDefaultStyle; 522 522 … … 527 527 RenderStyle* m_overrideDocumentElementStyle { nullptr }; 528 528 529 Vector< std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults;529 Vector<MediaQueryResult> m_viewportDependentMediaQueryResults; 530 530 531 531 #if ENABLE(CSS_DEVICE_ADAPTATION) -
trunk/Source/WebCore/css/StyleSheetContents.cpp
r201318 r201441 133 133 { 134 134 ASSERT(!rule->isCharsetRule()); 135 135 136 if (is<StyleRuleImport>(rule)) { 136 137 // Parser enforces that @import rules come before anything else except @charset. … … 142 143 } 143 144 144 #if ENABLE(RESOLUTION_MEDIA_QUERY)145 // Add warning message to inspector if dpi/dpcm values are used for screen media.146 145 if (is<StyleRuleMedia>(rule)) 147 146 reportMediaQueryWarningIfNeeded(singleOwnerDocument(), downcast<StyleRuleMedia>(rule.get()).mediaQueries()); 148 #endif149 147 150 148 // NOTE: The selector list has to fit into RuleData. <http://webkit.org/b/118369> 151 149 // If we're adding a rule with a huge number of selectors, split it up into multiple rules 152 150 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)); 155 152 return; 156 153 } -
trunk/Source/WebCore/dom/Document.cpp
r201333 r201441 803 803 { 804 804 if (!m_mediaQueryMatcher) 805 m_mediaQueryMatcher = MediaQueryMatcher::create( this);805 m_mediaQueryMatcher = MediaQueryMatcher::create(*this); 806 806 return *m_mediaQueryMatcher; 807 807 } -
trunk/Source/WebCore/dom/InlineStyleSheetOwner.cpp
r201318 r201441 151 151 MediaQueryEvaluator screenEval(ASCIILiteral("screen"), true); 152 152 MediaQueryEvaluator printEval(ASCIILiteral("print"), true); 153 if (!screenEval.eval (mediaQueries.get()) && !printEval.eval(mediaQueries.get()))153 if (!screenEval.evaluate(*mediaQueries) && !printEval.evaluate(*mediaQueries)) 154 154 return; 155 155 -
trunk/Source/WebCore/editing/TextIterator.cpp
r201205 r201441 1267 1267 // Exit empty containers as we pass over them or containers 1268 1268 // where [container, 0] is where we started iterating. 1269 if (!m_handledNode && canHaveChildrenForEditing(*m_node) 1269 if (!m_handledNode && canHaveChildrenForEditing(*m_node) && m_node->parentNode() && (!m_node->lastChild() || (m_node == m_endContainer && !m_endOffset))) { 1270 1270 exitNode(); 1271 1271 if (m_positionNode) { -
trunk/Source/WebCore/html/HTMLImageElement.cpp
r200945 r201441 154 154 continue; 155 155 auto& source = downcast<HTMLSourceElement>(*child); 156 156 157 auto& srcset = source.fastGetAttribute(srcsetAttr); 157 158 if (srcset.isEmpty()) 158 159 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(';')); 164 165 type = stripLeadingAndTrailingHTMLSpaces(type); 165 166 if (!type.isEmpty() && !MIMETypeRegistry::isSupportedImageMIMEType(type) && !equalLettersIgnoringASCIICase(type, "image/svg+xml")) 166 167 continue; 167 168 } 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()); 170 174 if (picture->hasViewportDependentResults()) 171 175 document().addViewportDependentPicture(*picture); … … 173 177 continue; 174 178 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); 177 181 if (!candidate.isEmpty()) 178 182 return candidate; … … 187 191 if (candidate.isEmpty()) { 188 192 // 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()); 190 194 candidate = bestFitSourceForImageAttributes(document().deviceScaleFactor(), fastGetAttribute(srcAttr), fastGetAttribute(srcsetAttr), sourceSize); 191 195 } -
trunk/Source/WebCore/html/HTMLLinkElement.cpp
r201311 r201441 242 242 documentStyle = Style::resolveForDocument(document()); 243 243 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()); 246 245 } 247 246 … … 362 361 } 363 362 364 Ref<StyleSheetContents> styleSheet(StyleSheetContents::create(href, parserContext));363 auto styleSheet = StyleSheetContents::create(href, parserContext); 365 364 m_sheet = CSSStyleSheet::create(styleSheet.copyRef(), this); 366 365 m_sheet->setMediaQueries(MediaQuerySet::createAllowingDescriptionSyntax(m_media)); -
trunk/Source/WebCore/html/HTMLMediaElement.cpp
r201435 r201441 4181 4181 4182 4182 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(); 4185 4184 #if !LOG_DISABLED 4186 4185 if (shouldLog) 4187 4186 LOG(Media, "HTMLMediaElement::selectNextSourceChild(%p) - 'media' is %s", this, source->media().utf8().data()); 4188 4187 #endif 4189 if ( !screenEval.eval(media.get()))4188 if (media && !MediaQueryEvaluator { "screen", document(), renderer() ? &renderer()->style() : nullptr }.evaluate(*media)) 4190 4189 goto check_again; 4191 4190 } -
trunk/Source/WebCore/html/HTMLPictureElement.cpp
r195606 r201441 58 58 void HTMLPictureElement::sourcesChanged() 59 59 { 60 for (auto& imageElement : childrenOfType<HTMLImageElement>(*this))61 imageElement.selectImageSource();60 for (auto& element : childrenOfType<HTMLImageElement>(*this)) 61 element.selectImageSource(); 62 62 } 63 63 64 bool HTMLPictureElement::viewportChangeAffectedPicture() 64 bool HTMLPictureElement::viewportChangeAffectedPicture() const 65 65 { 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) 70 70 return true; 71 71 } -
trunk/Source/WebCore/html/HTMLPictureElement.h
r195132 r201441 24 24 */ 25 25 26 #ifndef HTMLPictureElement_h 27 #define HTMLPictureElement_h 26 #pragma once 28 27 29 28 #include "HTMLElement.h" … … 35 34 public: 36 35 static Ref<HTMLPictureElement> create(const QualifiedName&, Document&); 37 ~HTMLPictureElement();36 virtual ~HTMLPictureElement(); 38 37 39 38 void sourcesChanged(); … … 41 40 void clearViewportDependentResults() { m_viewportDependentMediaQueryResults.clear(); } 42 41 bool hasViewportDependentResults() const { return m_viewportDependentMediaQueryResults.size(); } 43 Vector< std::unique_ptr<MediaQueryResult>>& viewportDependentResults() { return m_viewportDependentMediaQueryResults; }42 Vector<MediaQueryResult>& viewportDependentResults() { return m_viewportDependentMediaQueryResults; } 44 43 45 void didMoveToNewDocument(Document* oldDocument); 46 47 bool viewportChangeAffectedPicture(); 44 bool viewportChangeAffectedPicture() const; 48 45 49 46 WeakPtr<HTMLPictureElement> createWeakPtr() { return m_weakFactory.createWeakPtr(); } … … 51 48 private: 52 49 HTMLPictureElement(const QualifiedName&, Document&); 53 50 51 void didMoveToNewDocument(Document* oldDocument) final; 52 54 53 WeakPtrFactory<HTMLPictureElement> m_weakFactory { this }; 55 Vector<std::unique_ptr<MediaQueryResult>> m_viewportDependentMediaQueryResults; 56 54 Vector<MediaQueryResult> m_viewportDependentMediaQueryResults; 57 55 }; 58 56 59 57 } // namespace WebCore 60 61 #endif // HTMLPictureElement_h -
trunk/Source/WebCore/html/parser/HTMLPreloadScanner.cpp
r200519 r201441 119 119 120 120 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); 122 122 ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize); 123 123 if (!imageCandidate.isEmpty()) { … … 129 129 // Resolve between src and srcSet if we have them and the tag is img. 130 130 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); 132 132 ImageCandidate imageCandidate = bestFitSourceForImageAttributes(m_deviceScaleFactor, m_urlToLoad, m_srcSetAttribute, sourceSize); 133 133 setUrlToLoad(imageCandidate.string.toString(), true); … … 199 199 if (match(attributeName, mediaAttr) && m_mediaAttribute.isNull()) { 200 200 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()); 205 204 } 206 205 break; -
trunk/Source/WebCore/html/parser/HTMLResourcePreloader.cpp
r200098 r201441 59 59 } 60 60 61 static bool mediaAttributeMatches( Frame* frame, const RenderStyle* renderStyle, const String& attributeValue)61 static bool mediaAttributeMatches(Document& document, const RenderStyle* renderStyle, const String& attributeValue) 62 62 { 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()); 66 65 } 67 66 … … 70 69 ASSERT(m_document.frame()); 71 70 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())) 73 72 return; 74 73 -
trunk/Source/WebCore/page/DOMWindow.cpp
r201305 r201441 80 80 #include "PageTransitionEvent.h" 81 81 #include "Performance.h" 82 #include "PlatformScreen.h"83 82 #include "ResourceLoadInfo.h" 84 83 #include "RuntimeEnabledFeatures.h" -
trunk/Source/WebCore/page/mac/EventHandlerMac.mm
r201213 r201441 1176 1176 return m_lastKnownMousePosition; 1177 1177 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 24 24 */ 25 25 26 #ifndef PlatformScreen_h 27 #define PlatformScreen_h 28 29 #include <wtf/Vector.h> 26 #pragma once 30 27 31 28 #if PLATFORM(MAC) … … 45 42 #endif 46 43 47 typedef uint32_t PlatformDisplayID;48 49 typedef WTF::Vector<char> ColorProfile;50 51 44 namespace WebCore { 52 45 53 54 55 46 class FloatRect; 47 class FloatSize; 48 class Widget; 56 49 57 int screenDepth(Widget*); 58 int screenDepthPerComponent(Widget*); 59 bool screenIsMonochrome(Widget*); 50 using PlatformDisplayID = uint32_t; 60 51 61 bool screenHasInvertedColors(); 52 int screenDepth(Widget*); 53 int screenDepthPerComponent(Widget*); 54 bool screenIsMonochrome(Widget*); 62 55 63 FloatRect screenRect(Widget*); 64 FloatRect screenAvailableRect(Widget*); 56 bool screenHasInvertedColors(); 65 57 66 WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* widget = nullptr); 58 FloatRect screenRect(Widget*); 59 FloatRect screenAvailableRect(Widget*); 60 61 WEBCORE_EXPORT bool screenSupportsExtendedColor(Widget* = nullptr); 67 62 68 63 #if PLATFORM(MAC) 69 NSScreen *screenForWindow(NSWindow *);70 NSScreen *screenForDisplayID(PlatformDisplayID);71 64 72 WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&, NSWindow *destination);73 WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source);65 NSScreen *screen(NSWindow *); 66 NSScreen *screen(PlatformDisplayID); 74 67 75 NSPoint flipScreenPoint(const NSPoint&, NSScreen *); 68 WEBCORE_EXPORT FloatRect toUserSpace(const NSRect&, NSWindow *destination); 69 WEBCORE_EXPORT NSRect toDeviceSpace(const FloatRect&, NSWindow *source); 70 71 NSPoint flipScreenPoint(const NSPoint&, NSScreen *); 72 76 73 #endif 77 74 78 75 #if PLATFORM(IOS) 79 float screenPPIFactor(); 80 WEBCORE_EXPORT FloatSize screenSize(); 81 WEBCORE_EXPORT FloatSize availableScreenSize(); 82 WEBCORE_EXPORT float screenScaleFactor(UIScreen * = nullptr); 76 77 float screenPPIFactor(); 78 WEBCORE_EXPORT FloatSize screenSize(); 79 WEBCORE_EXPORT FloatSize availableScreenSize(); 80 WEBCORE_EXPORT float screenScaleFactor(UIScreen * = nullptr); 81 83 82 #endif 84 83 85 84 } // namespace WebCore 86 87 #endif // PlatformScreen_h -
trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.cpp
r182985 r201441 35 35 36 36 DisplayRefreshMonitorClient::DisplayRefreshMonitorClient() 37 : m_scheduled(false)38 , m_displayIDIsSet(false)39 37 { 40 38 } -
trunk/Source/WebCore/platform/graphics/DisplayRefreshMonitorClient.h
r182985 r201441 24 24 */ 25 25 26 #ifndef DisplayRefreshMonitorClient_h 27 #define DisplayRefreshMonitorClient_h 26 #pragma once 28 27 29 28 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) 30 29 31 30 #include "PlatformScreen.h" 31 #include <wtf/Forward.h> 32 32 #include <wtf/Optional.h> 33 33 … … 35 35 36 36 class DisplayRefreshMonitor; 37 class DisplayRefreshMonitorManager;38 37 39 38 class DisplayRefreshMonitorClient { … … 47 46 virtual RefPtr<DisplayRefreshMonitor> createDisplayRefreshMonitor(PlatformDisplayID) const = 0; 48 47 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; } 56 51 57 52 void setIsScheduled(bool isScheduled) { m_scheduled = isScheduled; } … … 61 56 62 57 private: 63 bool m_scheduled; 64 bool m_displayIDIsSet; 65 PlatformDisplayID m_displayID; 58 bool m_scheduled { false }; 59 Optional<PlatformDisplayID> m_displayID; 66 60 }; 67 61 … … 69 63 70 64 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) 71 72 #endif -
trunk/Source/WebCore/platform/graphics/GraphicsLayerUpdater.h
r197563 r201441 24 24 */ 25 25 26 #ifndef GraphicsLayerUpdater_h 27 #define GraphicsLayerUpdater_h 26 #pragma once 28 27 29 28 #include "DisplayRefreshMonitorClient.h" … … 69 68 70 69 } // namespace WebCore 71 72 #endif // GraphicsLayerUpdater_h -
trunk/Source/WebCore/platform/image-decoders/ImageDecoder.h
r199312 r201441 27 27 */ 28 28 29 #ifndef ImageDecoder_h 30 #define ImageDecoder_h 29 #pragma once 31 30 32 31 #include "IntRect.h" … … 41 40 42 41 namespace WebCore { 42 43 using ColorProfile = Vector<char>; 43 44 44 45 // ImageFrame represents the decoded image data. This buffer is what all … … 412 413 413 414 } // namespace WebCore 414 415 #endif -
trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.h
r183954 r201441 24 24 */ 25 25 26 #ifndef PlatformEventFactoryMac_h 27 #define PlatformEventFactoryMac_h 26 #pragma once 28 27 29 28 #include "PlatformKeyboardEvent.h" … … 41 40 42 41 #if PLATFORM(COCOA) && defined(__OBJC__) 43 // FIXME: This doesn't really belong here.44 WEBCORE_EXPORT IntPoint globalPoint(const NSPoint& windowPoint, NSWindow *);45 42 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. 44 WEBCORE_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. 47 WEBCORE_EXPORT int windowsKeyCodeForKeyEvent(NSEvent *); 48 WEBCORE_EXPORT String keyIdentifierForKeyEvent(NSEvent *); 49 WEBCORE_EXPORT double eventTimeStampSince1970(NSEvent *); 50 50 51 51 #endif 52 52 53 53 } // namespace WebCore 54 55 #endif // PlatformEventFactoryMac_h -
trunk/Source/WebCore/platform/mac/PlatformEventFactoryMac.mm
r197789 r201441 39 39 namespace WebCore { 40 40 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)41 NSPoint 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 49 static NSPoint globalPointForEvent(NSEvent *event) 50 50 { 51 51 switch ([event type]) { … … 71 71 return globalPoint([event locationInWindow], [event window]); 72 72 default: 73 return IntPoint();73 return { 0, 0 }; 74 74 } 75 75 } … … 486 486 // PlatformMouseEvent 487 487 m_position = pointForEvent(event, windowView); 488 m_globalPosition = globalPointForEvent(event);488 m_globalPosition = IntPoint(globalPointForEvent(event)); 489 489 m_button = mouseButtonForEvent(event); 490 490 m_clickCount = clickCountForEvent(event); … … 515 515 { 516 516 // PlatformEvent 517 m_type 518 m_modifiers 519 m_timestamp 517 m_type = PlatformEvent::Wheel; 518 m_modifiers = modifiersForEvent(event); 519 m_timestamp = eventTimeStampSince1970(event); 520 520 521 521 // PlatformWheelEvent 522 m_position 523 m_globalPosition = globalPointForEvent(event);524 m_granularity 522 m_position = pointForEvent(event, windowView); 523 m_globalPosition = IntPoint(globalPointForEvent(event)); 524 m_granularity = ScrollByPixelWheelEvent; 525 525 526 526 BOOL continuous; … … 536 536 } 537 537 538 m_phase 539 m_momentumPhase 540 m_hasPreciseScrollingDeltas 541 m_directionInvertedFromDevice 538 m_phase = phaseForEvent(event); 539 m_momentumPhase = momentumPhaseForEvent(event); 540 m_hasPreciseScrollingDeltas = continuous; 541 m_directionInvertedFromDevice = [event isDirectionInvertedFromDevice]; 542 542 } 543 543 }; … … 554 554 { 555 555 // PlatformEvent 556 m_type 557 m_modifiers 558 m_timestamp 556 m_type = isKeyUpEvent(event) ? PlatformEvent::KeyUp : PlatformEvent::KeyDown; 557 m_modifiers = modifiersForEvent(event); 558 m_timestamp = eventTimeStampSince1970(event); 559 559 560 560 // PlatformKeyboardEvent 561 m_text 562 m_unmodifiedText 563 m_keyIdentifier 564 m_windowsVirtualKeyCode 565 m_nativeVirtualKeyCode 566 m_macCharCode 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 572 m_isSystemKey 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. 573 573 574 574 // 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 31 31 #import "FrameView.h" 32 32 #import "HostWindow.h" 33 34 33 #import <ColorSync/ColorSync.h> 35 34 … … 41 40 namespace WebCore { 42 41 43 static PlatformDisplayID displayIDFromScreen(NSScreen *screen)44 {45 return (PlatformDisplayID)[[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue];46 }47 48 42 // These functions scale between screen and page coordinates because JavaScript/DOM operations 49 43 // assume that the screen and the page share the same coordinate system. 50 44 51 static PlatformDisplayID displayFromWidget(Widget* widget) 45 static PlatformDisplayID displayID(NSScreen *screen) 46 { 47 return [[[screen deviceDescription] objectForKey:@"NSScreenNumber"] intValue]; 48 } 49 50 static PlatformDisplayID displayID(Widget* widget) 52 51 { 53 52 if (!widget) 54 53 return 0; 55 54 56 FrameView* view = widget->root();55 auto* view = widget->root(); 57 56 if (!view) 58 57 return 0; 59 58 60 return view->hostWindow()->displayID(); 59 auto* hostWindow = view->hostWindow(); 60 if (!hostWindow) 61 return 0; 62 63 return hostWindow->displayID(); 61 64 } 62 65 63 static NSScreen *screenForWidget(Widget* widget, NSWindow *window) 66 // Screen containing the menubar. 67 static NSScreen *firstScreen() 64 68 { 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 } 68 74 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; 75 static NSWindow *window(Widget* widget) 76 { 77 if (!widget) 78 return nil; 79 return widget->platformWidget().window; 80 } 72 81 73 // Widget's window is offscreen, or no screens. Fall back to the first screen if available. 74 return screenForWindow(nil); 82 static 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)); 75 89 } 76 90 77 91 int screenDepth(Widget* widget) 78 92 { 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); 82 94 } 83 95 84 96 int screenDepthPerComponent(Widget* widget) 85 97 { 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); 89 99 } 90 100 91 101 bool screenIsMonochrome(Widget*) 92 102 { 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. 95 104 return CGDisplayUsesForceToGray(); 96 105 } … … 98 107 bool screenHasInvertedColors() 99 108 { 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. 102 110 return CGDisplayUsesInvertedPolarity(); 103 111 } … … 105 113 FloatRect screenRect(Widget* widget) 106 114 { 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)); 110 116 } 111 117 112 118 FloatRect screenAvailableRect(Widget* widget) 113 119 { 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)); 117 121 } 118 122 119 NSScreen *screen ForWindow(NSWindow *window)123 NSScreen *screen(NSWindow *window) 120 124 { 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(); 130 126 } 131 127 132 NSScreen *screen ForDisplayID(PlatformDisplayID displayID)128 NSScreen *screen(PlatformDisplayID displayID) 133 129 { 134 130 for (NSScreen *screen in [NSScreen screens]) { 135 if ( displayIDFromScreen(screen) == displayID)131 if (WebCore::displayID(screen) == displayID) 136 132 return screen; 137 133 } 138 return nil;134 return firstScreen(); 139 135 } 140 136 … … 148 144 return false; 149 145 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; 153 147 154 148 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200 155 149 return CGColorSpaceIsWideGamutRGB(colorSpace); 156 150 #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()); 163 154 #endif 164 155 #endif … … 168 159 { 169 160 FloatRect userRect = rect; 170 userRect.setY(NSMaxY([screen ForWindow(destination) frame]) - (userRect.y() + userRect.height())); // flip161 userRect.setY(NSMaxY([screen(destination) frame]) - (userRect.y() + userRect.height())); // flip 171 162 return userRect; 172 163 } … … 175 166 { 176 167 FloatRect deviceRect = rect; 177 deviceRect.setY(NSMaxY([screen ForWindow(source) frame]) - (deviceRect.y() + deviceRect.height())); // flip168 deviceRect.setY(NSMaxY([screen(source) frame]) - (deviceRect.y() + deviceRect.height())); // flip 178 169 return deviceRect; 179 170 } -
trunk/Source/WebKit/mac/ChangeLog
r201430 r201441 1 2016-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 1 12 2016-05-26 Myles C. Maxfield <mmaxfield@apple.com> 2 13 -
trunk/Source/WebKit/mac/WebView/WebFrame.mm
r200770 r201441 977 977 return; 978 978 // 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])), 980 980 LeftButton, PlatformEvent::MouseMoved, 0, false, false, false, false, currentTime(), WebCore::ForceAtClick); 981 981 _private->coreFrame->eventHandler().dragSourceEndedAt(event, (DragOperation)operation); -
trunk/Source/WebKit2/ChangeLog
r201440 r201441 1 2016-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 1 27 2016-05-26 Gyuyoung Kim <gyuyoung.kim@webkit.org> 2 28 -
trunk/Source/WebKit2/Shared/mac/WebEventFactory.mm
r197795 r201441 138 138 } 139 139 140 static NSScreen *screenForWindow(NSWindow *window)141 {142 NSScreen *screen = [window screen]; // nil if the window is off-screen143 if (screen)144 return screen;145 146 NSArray *screens = [NSScreen screens];147 if ([screens count] > 0)148 return [screens objectAtIndex:0]; // screen containing the menubar149 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 push163 #pragma clang diagnostic ignored "-Wdeprecated-declarations"164 return flipScreenPoint([window convertBaseToScreen:windowPoint], screenForWindow(window));165 #pragma clang diagnostic pop166 }167 168 140 static NSPoint globalPointForEvent(NSEvent *event) 169 141 { … … 188 160 case NSScrollWheel: 189 161 #pragma clang diagnostic pop 190 return globalPoint([event locationInWindow], [event window]);162 return WebCore::globalPoint([event locationInWindow], [event window]); 191 163 default: 192 164 return NSZeroPoint; -
trunk/Source/WebKit2/UIProcess/Cocoa/WebViewImpl.mm
r201227 r201441 1090 1090 { 1091 1091 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]); 1093 1093 } 1094 1094 … … 2779 2779 m_ignoresMouseDraggedEvents = true; 2780 2780 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); 2782 2782 } 2783 2783 -
trunk/Source/WebKit2/UIProcess/WebPageProxy.h
r201298 r201441 24 24 */ 25 25 26 #ifndef WebPageProxy_h 27 #define WebPageProxy_h 26 #pragma once 28 27 29 28 #include "APIObject.h" … … 667 666 void setIntrinsicDeviceScaleFactor(float); 668 667 void setCustomDeviceScaleFactor(float); 669 void windowScreenDidChange( PlatformDisplayID);668 void windowScreenDidChange(WebCore::PlatformDisplayID); 670 669 671 670 void setUseFixedLayout(bool); … … 1832 1831 1833 1832 } // namespace WebKit 1834 1835 #endif // WebPageProxy_h -
trunk/Source/WebKit2/WebProcess/WebCoreSupport/WebChromeClient.h
r199951 r201441 25 25 */ 26 26 27 #ifndef WebChromeClient_h 28 #define WebChromeClient_h 27 #pragma once 29 28 30 29 #include "WebFrame.h" … … 211 210 212 211 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) 213 RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor( PlatformDisplayID) const override;212 RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) const override; 214 213 #endif 215 214 … … 347 346 348 347 } // namespace WebKit 349 350 #endif // WebChromeClient_h -
trunk/Source/WebKit2/WebProcess/WebPage/Cocoa/RemoteLayerTreeDisplayRefreshMonitor.h
r197563 r201441 24 24 */ 25 25 26 #ifndef RemoteLayerTreeDisplayRefreshMonitor_h 27 #define RemoteLayerTreeDisplayRefreshMonitor_h 26 #pragma once 28 27 29 28 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) … … 36 35 class RemoteLayerTreeDisplayRefreshMonitor : public WebCore::DisplayRefreshMonitor { 37 36 public: 38 static Ref<RemoteLayerTreeDisplayRefreshMonitor> create( PlatformDisplayID displayID, RemoteLayerTreeDrawingArea& drawingArea)37 static Ref<RemoteLayerTreeDisplayRefreshMonitor> create(WebCore::PlatformDisplayID displayID, RemoteLayerTreeDrawingArea& drawingArea) 39 38 { 40 39 return adoptRef(*new RemoteLayerTreeDisplayRefreshMonitor(displayID, drawingArea)); … … 48 47 49 48 private: 50 explicit RemoteLayerTreeDisplayRefreshMonitor( PlatformDisplayID, RemoteLayerTreeDrawingArea&);49 explicit RemoteLayerTreeDisplayRefreshMonitor(WebCore::PlatformDisplayID, RemoteLayerTreeDrawingArea&); 51 50 52 51 WeakPtr<RemoteLayerTreeDrawingArea> m_drawingArea; … … 56 55 57 56 #endif // USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) 58 59 #endif // RemoteLayerTreeDisplayRefreshMonitor_h -
trunk/Source/WebKit2/WebProcess/WebPage/DrawingArea.h
r199111 r201441 24 24 */ 25 25 26 #ifndef DrawingArea_h 27 #define DrawingArea_h 26 #pragma once 28 27 29 28 #include "DrawingAreaInfo.h" … … 40 39 #include <wtf/Noncopyable.h> 41 40 #include <wtf/TypeCasts.h> 41 #include <wtf/Vector.h> 42 42 43 43 namespace IPC { … … 112 112 113 113 #if USE(REQUEST_ANIMATION_FRAME_DISPLAY_MONITOR) 114 virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor( PlatformDisplayID);114 virtual RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID); 115 115 #endif 116 116 … … 183 183 static bool isType(const WebKit::DrawingArea& area) { return area.type() == WebKit::AreaType; } \ 184 184 SPECIALIZE_TYPE_TRAITS_END() 185 186 #endif // DrawingArea_h -
trunk/Source/WebKit2/WebProcess/WebPage/mac/RemoteLayerTreeDrawingArea.h
r199111 r201441 24 24 */ 25 25 26 #ifndef RemoteLayerTreeDrawingArea_h 27 #define RemoteLayerTreeDrawingArea_h 26 #pragma once 28 27 29 28 #include "DrawingArea.h" … … 75 74 void addTransactionCallbackID(uint64_t callbackID) override; 76 75 77 RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor( PlatformDisplayID) override;76 RefPtr<WebCore::DisplayRefreshMonitor> createDisplayRefreshMonitor(WebCore::PlatformDisplayID) override; 78 77 void willDestroyDisplayRefreshMonitor(WebCore::DisplayRefreshMonitor*); 79 78 … … 180 179 181 180 SPECIALIZE_TYPE_TRAITS_DRAWING_AREA(RemoteLayerTreeDrawingArea, DrawingAreaTypeRemoteLayerTree) 182 183 #endif // RemoteLayerTreeDrawingArea_h
Note: See TracChangeset
for help on using the changeset viewer.