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

Last change on this file was 294611, checked in by Chris Dumez, 3 years ago

Start preparing the code base for marking the StringView(const char*) constructor explicit
https://bugs.webkit.org/show_bug.cgi?id=240687

Reviewed by Darin Adler.

Start preparing the code base for marking the StringView(const char*) constructor explicit.
This encourages people to ensure ASCIILiteral / ""_s whenever possible.

  • Source/JavaScriptCore/API/JSAPIGlobalObject.mm:

(JSC::computeValidImportSpecifier):

  • Source/JavaScriptCore/inspector/agents/InspectorDebuggerAgent.cpp:

(Inspector::isWebKitInjectedScript):

  • Source/JavaScriptCore/jit/ExecutableAllocator.cpp:

(JSC::dumpJITMemory):

  • Source/JavaScriptCore/jsc.cpp:

(GlobalObject::moduleLoaderImportModule):
(GlobalObject::moduleLoaderResolve):

  • Source/JavaScriptCore/runtime/FileBasedFuzzerAgent.cpp:

(JSC::FileBasedFuzzerAgent::getPredictionInternal):

  • Source/JavaScriptCore/runtime/IntlLocale.cpp:

(JSC::IntlLocale::initializeLocale):

  • Source/JavaScriptCore/runtime/IntlObject.cpp:

(JSC::isValidTimeZoneNameFromICUTimeZone):

  • Source/JavaScriptCore/runtime/TypeProfiler.cpp:

(JSC::TypeProfiler::logTypesForTypeLocation):

  • Source/JavaScriptCore/testRegExp.cpp:

(parseRegExpLine):

  • Source/JavaScriptCore/yarr/YarrUnicodeProperties.cpp:

(JSC::Yarr::HashTable::entry const):

  • Source/WebKit/NetworkProcess/cocoa/NetworkDataTaskCocoa.mm:

(WebKit::NetworkDataTaskCocoa::willPerformHTTPRedirection):

  • Source/WebKit/UIProcess/PageLoadState.cpp:

(WebKit::PageLoadState::hasOnlySecureContent):

  • Source/WebKit/UIProcess/mac/WKImmediateActionController.mm:

(-[WKImmediateActionController _defaultAnimationController]):

  • Source/WebKitLegacy/mac/WebView/WebImmediateActionController.mm:

(-[WebImmediateActionController _defaultAnimationController]):

  • Source/WTF/wtf/DateMath.cpp:

(WTF::parseDateFromNullTerminatedCharacters):

  • Source/WTF/wtf/SortedArrayMap.h:

(WTF::operator<):

  • Source/WTF/wtf/URL.cpp:

(WTF::URL::hasSpecialScheme const):
(WTF::URL::setPath):
(WTF::protocolIsInternal):
(WTF::protocolIs):
(WTF::URL::isLocalFile const):
(WTF::protocolIsJavaScript):
(WTF::URL::protocolIsAbout const):
(WTF::portAllowed):
(WTF::mimeTypeFromDataURL):
(WTF::URL::isAboutBlank const):
(WTF::URL::isAboutSrcDoc const):

  • Source/WTF/wtf/URL.h:

(WTF::URL::protocolIsBlob const):
(WTF::URL::protocolIsData const):

  • Source/WTF/wtf/URLHelpers.cpp:

(WTF::URLHelpers::applyHostNameFunctionToURLString):

  • Source/WTF/wtf/URLParser.cpp:

(WTF::URLParser::copyBaseWindowsDriveLetter):
(WTF::URLParser::URLParser):
(WTF::URLParser::parse):

  • Source/WTF/wtf/text/ASCIILiteral.h:
  • Source/WTF/wtf/text/StringView.h:

(WTF::operator==):
(WTF::operator!=):
(WTF::equal):

  • Source/WebCore/Modules/applepay/PaymentSession.cpp:

(WebCore::isSecure):

  • Source/WebCore/Modules/entriesapi/DOMFileSystem.cpp:

(WebCore::resolveRelativeVirtualPath):
(WebCore::DOMFileSystem::getParent):

  • Source/WebCore/Modules/fetch/FetchBodyConsumer.cpp:

(WebCore::FetchBodyConsumer::packageFormData):

  • Source/WebCore/Modules/indexeddb/server/IDBServer.cpp:

(WebCore::IDBServer::removeAllDatabasesForFullOriginPath):

  • Source/WebCore/Modules/indexeddb/server/SQLiteIDBBackingStore.cpp:

(WebCore::IDBServer::SQLiteIDBBackingStore::databasesSizeForDirectory):

  • Source/WebCore/Modules/mediasource/MediaSource.cpp:

(WebCore::addVP9FullRangeVideoFlagToContentType):

  • Source/WebCore/Modules/mediastream/PeerConnectionBackend.cpp:

(WebCore::shouldIgnoreIceCandidate):

  • Source/WebCore/Modules/mediastream/RTCPeerConnection.cpp:

(WebCore::RTCPeerConnection::iceServersFromConfiguration):

  • Source/WebCore/Modules/paymentrequest/PaymentRequest.cpp:

(WebCore::isValidURLBasedPaymentMethodIdentifier):

  • Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp:

(WebCore::YouTubePluginReplacement::youTubeURLFromAbsoluteURL):

  • Source/WebCore/Modules/webauthn/AuthenticatorCoordinator.cpp:

(WebCore::AuthenticatorCoordinatorInternal::needsAppIdQuirks):

  • Source/WebCore/Modules/webdatabase/Database.cpp:

(WebCore::fullyQualifiedInfoTableName):

  • Source/WebCore/Modules/webdatabase/DatabaseTracker.cpp:

(WebCore::DatabaseTracker::usage):

  • Source/WebCore/Modules/websockets/ThreadableWebSocketChannel.cpp:

(WebCore::ThreadableWebSocketChannel::validateURL):

  • Source/WebCore/Modules/websockets/WebSocket.cpp:

(WebCore::WebSocket::connect):
(WebCore::WebSocket::didUpgradeURL):

  • Source/WebCore/Modules/websockets/WebSocketHandshake.cpp:

(WebCore::hostName):
(WebCore::WebSocketHandshake::WebSocketHandshake):
(WebCore::WebSocketHandshake::httpURLForAuthenticationAndCookies const):
(WebCore::headerHasValidHTTPVersion):

  • Source/WebCore/accessibility/AXObjectCache.cpp:

(WebCore::AXObjectCache::handleAttributeChange):

  • Source/WebCore/accessibility/AccessibilityNodeObject.cpp:

(WebCore::AccessibilityNodeObject::isSearchField const):

  • Source/WebCore/accessibility/AccessibilityObject.cpp:

(WebCore::AccessibilityObject::ariaLandmarkRoleDescription const):

  • Source/WebCore/accessibility/mac/AccessibilityObjectMac.mm:

(WebCore::AccessibilityObject::rolePlatformDescription const):

  • Source/WebCore/animation/KeyframeEffect.cpp:

(WebCore::KeyframeEffect::setPseudoElement):

  • Source/WebCore/bindings/js/ScriptModuleLoader.cpp:

(WebCore::resolveModuleSpecifier):

  • Source/WebCore/contentextensions/ContentExtensionsBackend.cpp:

(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForLoad):
(WebCore::ContentExtensions::ContentExtensionsBackend::processContentRuleListsForPingLoad):
(WebCore::ContentExtensions::applyResultsToRequest):

  • Source/WebCore/css/CSSFontFaceSrcValue.cpp:

(WebCore::CSSFontFaceSrcValue::isSupportedFormat const):

  • Source/WebCore/css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::formatInfiniteOrNanValue const):
(WebCore::CSSPrimitiveValue::formatNumberValue const):
(WebCore::CSSPrimitiveValue::formatIntegerValue const):
(WebCore::CSSPrimitiveValue::formatNumberForCustomCSSText const):

  • Source/WebCore/css/CSSPrimitiveValue.h:
  • Source/WebCore/css/CSSSelector.cpp:

(WebCore::CSSSelector::parsePseudoElementType):

  • Source/WebCore/css/ContainerQueryParser.cpp:

(WebCore::ContainerQueryParser::consumePlainSizeFeature):

  • Source/WebCore/css/DOMCSSNamespace.cpp:

(WebCore::valueWithoutImportant):

  • Source/WebCore/css/parser/CSSPropertyParserHelpers.cpp:

(WebCore::CSSPropertyParserHelpers::consumeDashedIdent):

  • Source/WebCore/css/parser/CSSSelectorParser.cpp:

(WebCore::consumeLangArgumentList):

  • Source/WebCore/css/typedom/CSSOMVariableReferenceValue.cpp:

(WebCore::CSSOMVariableReferenceValue::create):
(WebCore::CSSOMVariableReferenceValue::setVariable):

  • Source/WebCore/dom/ConstantPropertyMap.cpp:

(WebCore::variableDataForPositivePixelLength):
(WebCore::variableDataForPositiveDuration):

  • Source/WebCore/dom/DataTransfer.cpp:

(WebCore::normalizeType):

  • Source/WebCore/dom/Document.cpp:

(WebCore::Document::isCookieAverse const):

  • Source/WebCore/dom/Element.cpp:

(WebCore::Element::isEventHandlerAttribute const):

  • Source/WebCore/dom/TextDecoder.cpp:

(WebCore::TextDecoder::encoding const):

  • Source/WebCore/editing/cocoa/HTMLConverter.mm:

(HTMLConverterCaches::isBlockElement):
(HTMLConverter::computedAttributesForElement):
(HTMLConverter::_processText):

  • Source/WebCore/editing/cocoa/WebContentReaderCocoa.mm:

(WebCore::stripMicrosoftPrefix):

  • Source/WebCore/editing/markup.cpp:

(WebCore::shouldPreserveMSOLists):

  • Source/WebCore/fileapi/BlobURL.cpp:
  • Source/WebCore/html/FeaturePolicy.cpp:

(WebCore::FeaturePolicy::parse):

  • Source/WebCore/html/HTMLAnchorElement.cpp:

(WebCore::HTMLAnchorElement::parseAttribute):

  • Source/WebCore/html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::formWouldHaveSecureSubmission):

  • Source/WebCore/html/HTMLLinkElement.cpp:

(WebCore::HTMLLinkElement::process):

  • Source/WebCore/html/HTMLMediaElement.cpp:
  • Source/WebCore/html/HTMLObjectElement.cpp:

(WebCore::HTMLObjectElement::hasValidClassId):

  • Source/WebCore/html/HTMLPlugInImageElement.cpp:

(WebCore::HTMLPlugInImageElement::isImageType):

  • Source/WebCore/html/TextFieldInputType.cpp:

(WebCore::TextFieldInputType::handleBeforeTextInsertedEvent):

  • Source/WebCore/html/URLDecomposition.cpp:

(WebCore::URLDecomposition::setUsername):
(WebCore::URLDecomposition::setPassword):
(WebCore::URLDecomposition::setHost):
(WebCore::URLDecomposition::setHostname):

  • Source/WebCore/html/canvas/CanvasRenderingContext2DBase.cpp:

(WebCore::CanvasRenderingContext2DBase::State::fontString const):

  • Source/WebCore/html/canvas/WebGLRenderingContextBase.cpp:

(WebCore::WebGLRenderingContextBase::getActiveUniform):
(WebCore::WebGLRenderingContextBase::getUniformLocation):

  • Source/WebCore/html/parser/CSSPreloadScanner.cpp:

(WebCore::hasValidImportConditions):

  • Source/WebCore/html/parser/HTMLMetaCharsetParser.cpp:

(WebCore::extractCharset):

  • Source/WebCore/html/parser/HTMLPreloadScanner.cpp:

(WebCore::TokenPreloadScanner::StartTagScanner::shouldPreload):

  • Source/WebCore/html/track/WebVTTParser.cpp:
  • Source/WebCore/inspector/DOMPatchSupport.cpp:
  • Source/WebCore/inspector/InspectorFrontendHost.cpp:

(WebCore::InspectorFrontendHost::revealFileExternally):

  • Source/WebCore/inspector/InspectorStyleSheet.cpp:

(WebCore::StyleSheetHandler::observeComment):
(WebCore::lowercasePropertyName):
(WebCore::selectorsFromSource):

  • Source/WebCore/loader/CookieJar.cpp:

(WebCore::CookieJar::shouldIncludeSecureCookies):

  • Source/WebCore/loader/CustomHeaderFields.cpp:

(WebCore::CustomHeaderFields::thirdPartyDomainsMatch const):

  • Source/WebCore/loader/FormSubmission.cpp:

(WebCore::FormSubmission::create):

  • Source/WebCore/loader/FrameLoader.cpp:

(WebCore::FrameLoader::open):

  • Source/WebCore/loader/PolicyChecker.cpp:

(WebCore::FrameLoader::PolicyChecker::checkNavigationPolicy):

  • Source/WebCore/loader/PrivateClickMeasurement.cpp:

(WebCore::PrivateClickMeasurement::parseAttributionRequest):

  • Source/WebCore/loader/ResourceLoader.cpp:

(WebCore::ResourceLoader::isPDFJSResourceLoad const):

  • Source/WebCore/loader/appcache/ApplicationCacheManifestParser.cpp:

(WebCore::parseApplicationCacheManifest):

  • Source/WebCore/loader/archive/ArchiveResourceCollection.cpp:

(WebCore::ArchiveResourceCollection::archiveResourceForURL):

  • Source/WebCore/loader/cache/CachedResource.cpp:

(WebCore::CachedResource::makeRevalidationDecision const):

  • Source/WebCore/loader/cache/CachedResourceLoader.cpp:

(WebCore::CachedResourceLoader::requestResource):

  • Source/WebCore/page/ContextMenuController.cpp:

(WebCore::ContextMenuController::checkOrEnableIfNeeded const):

  • Source/WebCore/page/EventHandler.cpp:

(WebCore::hasDropZoneType):

  • Source/WebCore/page/Frame.cpp:

(WebCore::createRegExpForLabels):
(WebCore::matchLabelsAgainstString):

  • Source/WebCore/page/Page.cpp:

(WebCore::Page::userStyleSheetLocationChanged):
(WebCore::Page::allowsLoadFromURL const):

  • Source/WebCore/page/Quirks.cpp:

(WebCore::isYahooMail):
(WebCore::Quirks::shouldDisableContentChangeObserverTouchEventAdjustment const):
(WebCore::Quirks::shouldHideSearchFieldResultsButton const):
(WebCore::Quirks::isAmazon const):
(WebCore::Quirks::isGoogleMaps const):
(WebCore::Quirks::shouldDispatchSimulatedMouseEvents const):
(WebCore::Quirks::shouldDispatchedSimulatedMouseEventsAssumeDefaultPrevented const):
(WebCore::Quirks::simulatedMouseEventTypeForTarget const):
(WebCore::Quirks::shouldPreventPointerMediaQueryFromEvaluatingToCoarse const):
(WebCore::Quirks::shouldAvoidResizingWhenInputViewBoundsChange const):
(WebCore::Quirks::shouldDisablePointerEventsQuirk const):
(WebCore::Quirks::needsInputModeNoneImplicitly const):
(WebCore::Quirks::needsFullscreenDisplayNoneQuirk const):
(WebCore::Quirks::shouldSilenceWindowResizeEvents const):
(WebCore::Quirks::shouldSilenceMediaQueryListChangeEvents const):
(WebCore::Quirks::shouldUseLegacySelectPopoverDismissalBehaviorInDataActivation const):
(WebCore::Quirks::shouldOpenAsAboutBlank const):
(WebCore::Quirks::shouldBypassBackForwardCache const):
(WebCore::Quirks::shouldBypassAsyncScriptDeferring const):
(WebCore::Quirks::shouldMakeEventListenerPassive):
(WebCore::Quirks::shouldDisableElementFullscreenQuirk const):
(WebCore::Quirks::needsCanPlayAfterSeekedQuirk const):
(WebCore::Quirks::shouldLayOutAtMinimumWindowWidthWhenIgnoringScalingConstraints const):
(WebCore::Quirks::shouldIgnoreContentObservationForSyntheticClick const):
(WebCore::isKinjaLoginAvatarElement):
(WebCore::Quirks::isMicrosoftTeamsRedirectURL):
(WebCore::Quirks::needsBlackFullscreenBackgroundQuirk const):
(WebCore::Quirks::needsToForceUserSelectAndUserDragWhenInstallingImageOverlay const):

  • Source/WebCore/page/SecurityOrigin.cpp:

(WebCore::schemeRequiresHost):
(WebCore::SecurityOrigin::shouldIgnoreHost):
(WebCore::shouldTreatAsUniqueOrigin):
(WebCore::isLoopbackIPAddress):
(WebCore::SecurityOrigin::isLocalHostOrLoopbackIPAddress):

  • Source/WebCore/page/SecurityPolicy.cpp:

(WebCore::SecurityPolicy::shouldHideReferrer):
(WebCore::SecurityPolicy::generateOriginHeader):

  • Source/WebCore/page/UserContentURLPattern.cpp:

(WebCore::UserContentURLPattern::parse):

  • Source/WebCore/page/cocoa/ResourceUsageThreadCocoa.mm:

(WebCore::ResourceUsageThread::platformCollectCPUData):

  • Source/WebCore/page/csp/ContentSecurityPolicy.cpp:

(WebCore::shouldReportProtocolOnly):
(WebCore::ContentSecurityPolicy::upgradeInsecureRequestIfNeeded const):
(WebCore::ContentSecurityPolicy::setUpgradeInsecureRequests):

  • Source/WebCore/page/csp/ContentSecurityPolicySource.cpp:

(WebCore::ContentSecurityPolicySource::portMatches const):

  • Source/WebCore/page/csp/ContentSecurityPolicySourceList.cpp:

(WebCore::ContentSecurityPolicySourceList::isProtocolAllowedByStar const):

  • Source/WebCore/platform/MIMETypeRegistry.cpp:

(WebCore::MIMETypeRegistry::isSupportedJSONMIMEType):
(WebCore::MIMETypeRegistry::isXMLMIMEType):

  • Source/WebCore/platform/cocoa/RuntimeApplicationChecksCocoa.mm:

(WebCore::MacApplication::isSafari):

  • Source/WebCore/platform/graphics/Image.cpp:

(WebCore::Image::isPDFResource):
(WebCore::Image::isPostScriptResource):

  • Source/WebCore/platform/graphics/avfoundation/CDMFairPlayStreaming.cpp:

(WebCore::CDMFactoryFairPlayStreaming::supportsKeySystem):

  • Source/WebCore/platform/graphics/avfoundation/MediaPlayerPrivateAVFoundation.cpp:

(WebCore::MediaPlayerPrivateAVFoundation::isUnsupportedMIMEType):

  • Source/WebCore/platform/graphics/avfoundation/objc/AVAssetMIMETypeCache.mm:

(WebCore::AVAssetMIMETypeCache::isUnsupportedContainerType):

  • Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::fontWithFamilySpecialCase):

  • Source/WebCore/platform/graphics/cocoa/MediaEngineConfigurationFactoryCocoa.cpp:

(WebCore::videoCodecTypeFromRFC4281Type):
(WebCore::computeMediaCapabilitiesInfo):

  • Source/WebCore/platform/graphics/cocoa/SourceBufferParserWebM.cpp:

(WebCore::SourceBufferParserWebM::isContentTypeSupported):

  • Source/WebCore/platform/mac/UserAgentMac.mm:

(WebCore::standardUserAgentWithApplicationName):

  • Source/WebCore/platform/mediastream/mac/CoreAudioCaptureDeviceManager.cpp:

(WebCore::isValidCaptureDevice):

  • Source/WebCore/platform/network/CacheValidation.cpp:

(WebCore::parseCacheControlDirectives):
(WebCore::cookieRequestHeaderFieldValue):

  • Source/WebCore/platform/network/DataURLDecoder.cpp:

(WebCore::DataURLDecoder::DecodeTask::process):

  • Source/WebCore/platform/network/HTTPParsers.cpp:

(WebCore::extractCharsetFromMediaType):

  • Source/WebCore/platform/network/ParsedContentRange.cpp:

(WebCore::parseContentRange):

  • Source/WebCore/platform/network/ParsedRequestRange.cpp:

(WebCore::ParsedRequestRange::parse):

  • Source/WebCore/platform/network/ResourceHandle.cpp:

(WebCore::ResourceHandle::shouldContentSniffURL):

  • Source/WebCore/platform/network/ResourceRequestBase.cpp:

(WebCore::ResourceRequestBase::redirectedRequest const):

  • Source/WebCore/platform/network/ResourceResponseBase.cpp:

(WebCore::ResourceResponseBase::isHTTP09 const):

  • Source/WebCore/platform/network/cf/SocketStreamHandleImpl.h:

(WebCore::SocketStreamHandleImpl::shouldUseSSL const):

  • Source/WebCore/platform/network/cf/SocketStreamHandleImplCFNet.cpp:

(WebCore::SocketStreamHandleImpl::SocketStreamHandleImpl):

  • Source/WebCore/platform/network/mac/ResourceHandleMac.mm:

(WebCore::ResourceHandle::willSendRequest):

  • Source/WebCore/plugins/PluginData.cpp:

(WebCore::shouldBePubliclyVisible):

  • Source/WebCore/rendering/HitTestResult.cpp:

(WebCore::HitTestResult::absolutePDFURL const):

  • Source/WebCore/rendering/RenderListMarker.cpp:

(WebCore::listMarkerSuffix):

  • Source/WebCore/svg/SVGSVGElement.cpp:

(WebCore::SVGSVGElement::scrollToFragment):

  • Source/WebCore/svg/animation/SVGSMILElement.cpp:

(WebCore::SVGSMILElement::parseOffsetValue):
(WebCore::SVGSMILElement::parseCondition):

  • Source/WebCore/workers/Worker.cpp:

(WebCore::Worker::didReceiveResponse):

  • Source/WebCore/workers/service/ServiceWorkerContainer.cpp:

(WebCore::ServiceWorkerContainer::addRegistration):

  • Source/WebCore/xml/parser/XMLDocumentParserLibxml2.cpp:

(WebCore::shouldAllowExternalLoad):

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

  • Property svn:eol-style set to native
File size: 17.7 KB
Line 
1/*
2 * (C) 1999-2003 Lars Knoll ([email protected])
3 * Copyright (C) 2004, 2005, 2006, 2008 Apple Inc. All rights reserved.
4 * Copyright (C) 2007 Alexey Proskuryakov <[email protected]>
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 */
21
22#pragma once
23
24#include "CSSPropertyNames.h"
25#include "CSSUnits.h"
26#include "CSSValue.h"
27#include "CSSValueKeywords.h"
28#include "Color.h"
29#include "ExceptionOr.h"
30#include "LayoutUnit.h"
31#include <utility>
32#include <wtf/Forward.h>
33#include <wtf/MathExtras.h>
34
35namespace WebCore {
36
37class CSSBasicShape;
38class CSSCalcValue;
39class CSSToLengthConversionData;
40class Counter;
41class DeprecatedCSSOMPrimitiveValue;
42class FontCascadeDescription;
43class FontMetrics;
44class Pair;
45class Quad;
46class RGBColor;
47class Rect;
48class RenderStyle;
49class RenderView;
50
51struct CSSFontFamily;
52struct Length;
53struct LengthSize;
54
55// Max/min values for CSS, needs to slightly smaller/larger than the true max/min values to allow for rounding without overflowing.
56// Subtract two (rather than one) to allow for values to be converted to float and back without exceeding the LayoutUnit::max.
57const int maxValueForCssLength = intMaxForLayoutUnit - 2;
58const int minValueForCssLength = intMinForLayoutUnit + 2;
59
60// Dimension calculations are imprecise, often resulting in values of e.g.
61// 44.99998. We need to round if we're really close to the next integer value.
62template<typename T> inline T roundForImpreciseConversion(double value)
63{
64 value += (value < 0) ? -0.01 : +0.01;
65 return ((value > std::numeric_limits<T>::max()) || (value < std::numeric_limits<T>::min())) ? 0 : static_cast<T>(value);
66}
67
68template<> inline float roundForImpreciseConversion(double value)
69{
70 double ceiledValue = ceil(value);
71 double proximityToNextInt = ceiledValue - value;
72 if (proximityToNextInt <= 0.01 && value > 0)
73 return static_cast<float>(ceiledValue);
74 if (proximityToNextInt >= 0.99 && value < 0)
75 return static_cast<float>(floor(value));
76 return static_cast<float>(value);
77}
78
79class CSSPrimitiveValue final : public CSSValue {
80public:
81 static constexpr bool isLength(CSSUnitType);
82 static double computeDegrees(CSSUnitType, double angle);
83
84 // FIXME: Some of these use primitiveUnitType() and some use primitiveType(). Many that use primitiveUnitType() are likely broken with calc().
85 bool isAngle() const { return unitCategory(primitiveType()) == CSSUnitCategory::Angle; }
86 bool isAttr() const { return primitiveUnitType() == CSSUnitType::CSS_ATTR; }
87 bool isCounter() const { return primitiveUnitType() == CSSUnitType::CSS_COUNTER; }
88 bool isFontIndependentLength() const { return isFontIndependentLength(primitiveUnitType()); }
89 bool isFontRelativeLength() const { return isFontRelativeLength(primitiveUnitType()); }
90 bool isQuirkyEms() const { return primitiveType() == CSSUnitType::CSS_QUIRKY_EMS; }
91 bool isLength() const { return isLength(static_cast<CSSUnitType>(primitiveType())); }
92 bool isNumber() const { return primitiveType() == CSSUnitType::CSS_NUMBER; }
93 bool isInteger() const { return primitiveType() == CSSUnitType::CSS_INTEGER; }
94 bool isNumberOrInteger() const { return isNumber() || isInteger(); }
95 bool isPercentage() const { return primitiveType() == CSSUnitType::CSS_PERCENTAGE; }
96 bool isPx() const { return primitiveType() == CSSUnitType::CSS_PX; }
97 bool isRect() const { return primitiveUnitType() == CSSUnitType::CSS_RECT; }
98 bool isPair() const { return primitiveUnitType() == CSSUnitType::CSS_PAIR; }
99 bool isPropertyID() const { return primitiveUnitType() == CSSUnitType::CSS_PROPERTY_ID; }
100 bool isRGBColor() const { return primitiveUnitType() == CSSUnitType::CSS_RGBCOLOR; }
101 bool isShape() const { return primitiveUnitType() == CSSUnitType::CSS_SHAPE; }
102 bool isString() const { return primitiveUnitType() == CSSUnitType::CSS_STRING; }
103 bool isFontFamily() const { return primitiveUnitType() == CSSUnitType::CSS_FONT_FAMILY; }
104 bool isTime() const { return unitCategory(primitiveUnitType()) == CSSUnitCategory::Time; }
105 bool isFrequency() const { return unitCategory(primitiveType()) == CSSUnitCategory::Frequency; }
106 bool isURI() const { return primitiveUnitType() == CSSUnitType::CSS_URI; }
107 bool isCalculated() const { return primitiveUnitType() == CSSUnitType::CSS_CALC; }
108 bool isCalculatedPercentageWithNumber() const { return primitiveType() == CSSUnitType::CSS_CALC_PERCENTAGE_WITH_NUMBER; }
109 bool isCalculatedPercentageWithLength() const { return primitiveType() == CSSUnitType::CSS_CALC_PERCENTAGE_WITH_LENGTH; }
110 bool isDotsPerInch() const { return primitiveType() == CSSUnitType::CSS_DPI; }
111 bool isDotsPerPixel() const { return primitiveType() == CSSUnitType::CSS_DPPX; }
112 bool isDotsPerCentimeter() const { return primitiveType() == CSSUnitType::CSS_DPCM; }
113 bool isX() const { return primitiveType() == CSSUnitType::CSS_X; }
114 bool isResolution() const { return unitCategory(primitiveType()) == CSSUnitCategory::Resolution; }
115 bool isViewportPercentageLength() const { return isViewportPercentageLength(primitiveUnitType()); }
116 bool isValueID() const { return primitiveUnitType() == CSSUnitType::CSS_VALUE_ID; }
117 bool isFlex() const { return primitiveType() == CSSUnitType::CSS_FR; }
118 bool isCustomIdent() const { return primitiveUnitType() == CSSUnitType::CustomIdent; }
119
120 bool isInitialValue() const { return valueID() == CSSValueInitial; }
121 bool isImplicitInitialValue() const { return isInitialValue() && m_isImplicit; }
122 bool isInheritValue() const { return valueID() == CSSValueInherit; }
123 bool isUnsetValue() const { return valueID() == CSSValueUnset; }
124 bool isRevertValue() const { return valueID() == CSSValueRevert; }
125 bool isRevertLayerValue() const { return valueID() == CSSValueRevertLayer; }
126 bool isCSSWideKeyword() const;
127
128 static Ref<CSSPrimitiveValue> createIdentifier(CSSValueID valueID) { return adoptRef(*new CSSPrimitiveValue(valueID)); }
129 static Ref<CSSPrimitiveValue> createIdentifier(CSSPropertyID propertyID) { return adoptRef(*new CSSPrimitiveValue(propertyID)); }
130
131 static Ref<CSSPrimitiveValue> create(double value, CSSUnitType type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
132 static Ref<CSSPrimitiveValue> create(const String& value, CSSUnitType type) { return adoptRef(*new CSSPrimitiveValue(value, type)); }
133 static Ref<CSSPrimitiveValue> create(const Length& value, const RenderStyle& style) { return adoptRef(*new CSSPrimitiveValue(value, style)); }
134 static Ref<CSSPrimitiveValue> create(const LengthSize& value, const RenderStyle& style) { return adoptRef(*new CSSPrimitiveValue(value, style)); }
135
136 template<typename T> static Ref<CSSPrimitiveValue> create(T&&);
137 template<typename T> static Ref<CSSPrimitiveValue> create(T&&, CSSPropertyID);
138
139 ~CSSPrimitiveValue();
140
141 void cleanup();
142
143 CSSUnitType primitiveType() const;
144 ExceptionOr<float> getFloatValue(CSSUnitType) const;
145
146 double computeDegrees() const;
147
148 enum TimeUnit { Seconds, Milliseconds };
149 template<typename T, TimeUnit timeUnit> T computeTime() const;
150
151 template<typename T> T computeLength(const CSSToLengthConversionData&) const;
152 template<int> Length convertToLength(const CSSToLengthConversionData&) const;
153
154 bool convertingToLengthRequiresNonNullStyle(int lengthConversion) const;
155
156 double doubleValue(CSSUnitType) const;
157
158 // It's usually wrong to call this; it can trigger type conversion in calc without sufficient context to resolve relative length units.
159 double doubleValue() const;
160
161 double doubleValueDividingBy100IfPercentage() const;
162
163 // These return nullopt for calc, for which range checking is not done at parse time: <https://www.w3.org/TR/css3-values/#calc-range>.
164 std::optional<bool> isZero() const;
165 std::optional<bool> isPositive() const;
166 std::optional<bool> isNegative() const;
167 bool isCenterPosition() const;
168
169 template<typename T> inline T value(CSSUnitType type) const { return clampTo<T>(doubleValue(type)); }
170 template<typename T> inline T value() const { return clampTo<T>(doubleValue()); }
171
172 float floatValue(CSSUnitType type) const { return value<float>(type); }
173 float floatValue() const { return value<float>(); }
174
175 int intValue(CSSUnitType type) const { return value<int>(type); }
176 int intValue() const { return value<int>(); }
177
178 WEBCORE_EXPORT String stringValue() const;
179
180 const Color& color() const { ASSERT(primitiveUnitType() == CSSUnitType::CSS_RGBCOLOR); return *m_value.color; }
181 Counter* counterValue() const { return primitiveUnitType() != CSSUnitType::CSS_COUNTER ? nullptr : m_value.counter; }
182 CSSCalcValue* cssCalcValue() const { return primitiveUnitType() != CSSUnitType::CSS_CALC ? nullptr : m_value.calc; }
183 const CSSFontFamily& fontFamily() const { ASSERT(primitiveUnitType() == CSSUnitType::CSS_FONT_FAMILY); return *m_value.fontFamily; }
184 Pair* pairValue() const { return primitiveUnitType() != CSSUnitType::CSS_PAIR ? nullptr : m_value.pair; }
185 CSSPropertyID propertyID() const { return primitiveUnitType() == CSSUnitType::CSS_PROPERTY_ID ? m_value.propertyID : CSSPropertyInvalid; }
186 Quad* quadValue() const { return primitiveUnitType() != CSSUnitType::CSS_QUAD ? nullptr : m_value.quad; }
187 Rect* rectValue() const { return primitiveUnitType() != CSSUnitType::CSS_RECT ? nullptr : m_value.rect; }
188 CSSBasicShape* shapeValue() const { return primitiveUnitType() != CSSUnitType::CSS_SHAPE ? nullptr : m_value.shape; }
189 CSSValueID valueID() const { return primitiveUnitType() == CSSUnitType::CSS_VALUE_ID ? m_value.valueID : CSSValueInvalid; }
190
191 template<typename T> inline operator T() const; // Defined in CSSPrimitiveValueMappings.h
192
193 String customCSSText(Document* = nullptr) const;
194
195 bool equals(const CSSPrimitiveValue&) const;
196
197 static std::optional<double> conversionToCanonicalUnitsScaleFactor(CSSUnitType);
198 static ASCIILiteral unitTypeString(CSSUnitType);
199
200 static double computeUnzoomedNonCalcLengthDouble(CSSUnitType, double value, CSSPropertyID, const FontMetrics* = nullptr, const FontCascadeDescription* = nullptr, const FontCascadeDescription* rootFontDescription = nullptr, const RenderView* = nullptr);
201 static double computeNonCalcLengthDouble(const CSSToLengthConversionData&, CSSUnitType, double value);
202 // True if computeNonCalcLengthDouble would produce identical results when resolved against both these styles.
203 static bool equalForLengthResolution(const RenderStyle&, const RenderStyle&);
204
205 Ref<DeprecatedCSSOMPrimitiveValue> createDeprecatedCSSOMPrimitiveWrapper(CSSStyleDeclaration&) const;
206
207 void collectDirectComputationalDependencies(HashSet<CSSPropertyID>&) const;
208 void collectDirectRootComputationalDependencies(HashSet<CSSPropertyID>&) const;
209
210private:
211 friend class CSSValuePool;
212 friend class StaticCSSValuePool;
213 friend LazyNeverDestroyed<CSSPrimitiveValue>;
214
215 CSSPrimitiveValue(CSSValueID);
216 CSSPrimitiveValue(CSSPropertyID);
217 CSSPrimitiveValue(const Color&);
218 CSSPrimitiveValue(const Length&);
219 CSSPrimitiveValue(const Length&, const RenderStyle&);
220 CSSPrimitiveValue(const LengthSize&, const RenderStyle&);
221 CSSPrimitiveValue(const String&, CSSUnitType);
222 CSSPrimitiveValue(double, CSSUnitType);
223
224 CSSPrimitiveValue(StaticCSSValueTag, CSSValueID);
225 CSSPrimitiveValue(StaticCSSValueTag, const Color&);
226 CSSPrimitiveValue(StaticCSSValueTag, double, CSSUnitType);
227 enum ImplicitInitialValueTag { ImplicitInitialValue };
228 CSSPrimitiveValue(StaticCSSValueTag, ImplicitInitialValueTag);
229
230 template<typename T> CSSPrimitiveValue(T); // Defined in CSSPrimitiveValueMappings.h
231 template<typename T> CSSPrimitiveValue(T, CSSPropertyID); // Defined in CSSPrimitiveValueMappings.h
232 template<typename T> CSSPrimitiveValue(RefPtr<T>&&);
233 template<typename T> CSSPrimitiveValue(Ref<T>&&);
234
235 static void create(int); // compile-time guard
236 static void create(unsigned); // compile-time guard
237 template<typename T> operator T*(); // compile-time guard
238
239 void init(const Length&);
240 void init(const LengthSize&, const RenderStyle&);
241 void init(Ref<CSSBasicShape>&&);
242 void init(RefPtr<CSSCalcValue>&&);
243 void init(Ref<Counter>&&);
244 void init(Ref<Pair>&&);
245 void init(Ref<Quad>&&);
246 void init(Ref<Rect>&&);
247
248 CSSUnitType primitiveUnitType() const { return static_cast<CSSUnitType>(m_primitiveUnitType); }
249 void setPrimitiveUnitType(CSSUnitType type) { m_primitiveUnitType = static_cast<unsigned>(type); }
250
251 std::optional<double> doubleValueInternal(CSSUnitType targetUnitType) const;
252
253 double computeLengthDouble(const CSSToLengthConversionData&) const;
254
255 ALWAYS_INLINE String formatNumberForCustomCSSText() const;
256 NEVER_INLINE String formatNumberValue(ASCIILiteral suffix) const;
257 NEVER_INLINE String formatIntegerValue(ASCIILiteral suffix) const;
258 NEVER_INLINE String formatInfiniteOrNanValue(ASCIILiteral suffix) const;
259 static constexpr bool isFontIndependentLength(CSSUnitType);
260 static constexpr bool isFontRelativeLength(CSSUnitType);
261 static constexpr bool isResolution(CSSUnitType);
262 static constexpr bool isViewportPercentageLength(CSSUnitType);
263
264 union {
265 CSSPropertyID propertyID;
266 CSSValueID valueID;
267 double num;
268 StringImpl* string;
269 Counter* counter;
270 Rect* rect;
271 Quad* quad;
272 const Color* color;
273 Pair* pair;
274 CSSBasicShape* shape;
275 CSSCalcValue* calc;
276 const CSSFontFamily* fontFamily;
277 } m_value;
278};
279
280constexpr bool CSSPrimitiveValue::isFontIndependentLength(CSSUnitType type)
281{
282 return type == CSSUnitType::CSS_PX
283 || type == CSSUnitType::CSS_CM
284 || type == CSSUnitType::CSS_MM
285 || type == CSSUnitType::CSS_IN
286 || type == CSSUnitType::CSS_PT
287 || type == CSSUnitType::CSS_PC;
288}
289
290constexpr bool CSSPrimitiveValue::isFontRelativeLength(CSSUnitType type)
291{
292 return type == CSSUnitType::CSS_EMS
293 || type == CSSUnitType::CSS_EXS
294 || type == CSSUnitType::CSS_LHS
295 || type == CSSUnitType::CSS_RLHS
296 || type == CSSUnitType::CSS_REMS
297 || type == CSSUnitType::CSS_CHS
298 || type == CSSUnitType::CSS_IC
299 || type == CSSUnitType::CSS_QUIRKY_EMS;
300}
301
302constexpr bool CSSPrimitiveValue::isLength(CSSUnitType type)
303{
304 return type == CSSUnitType::CSS_EMS
305 || type == CSSUnitType::CSS_EXS
306 || type == CSSUnitType::CSS_PX
307 || type == CSSUnitType::CSS_CM
308 || type == CSSUnitType::CSS_MM
309 || type == CSSUnitType::CSS_IN
310 || type == CSSUnitType::CSS_PT
311 || type == CSSUnitType::CSS_PC
312 || type == CSSUnitType::CSS_REMS
313 || type == CSSUnitType::CSS_CHS
314 || type == CSSUnitType::CSS_IC
315 || type == CSSUnitType::CSS_Q
316 || type == CSSUnitType::CSS_LHS
317 || type == CSSUnitType::CSS_RLHS
318 || type == CSSUnitType::CSS_CQW
319 || type == CSSUnitType::CSS_CQH
320 || type == CSSUnitType::CSS_CQI
321 || type == CSSUnitType::CSS_CQB
322 || type == CSSUnitType::CSS_CQMIN
323 || type == CSSUnitType::CSS_CQMAX
324 || isViewportPercentageLength(type)
325 || type == CSSUnitType::CSS_QUIRKY_EMS;
326}
327
328constexpr bool CSSPrimitiveValue::isResolution(CSSUnitType type)
329{
330 return type == CSSUnitType::CSS_DPPX
331 || type == CSSUnitType::CSS_DPI
332 || type == CSSUnitType::CSS_DPCM;
333}
334
335constexpr bool CSSPrimitiveValue::isViewportPercentageLength(CSSUnitType type)
336{
337 return type >= CSSUnitType::FirstViewportCSSUnitType && type <= CSSUnitType::LastViewporCSSUnitType;
338}
339
340template<typename T> inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::create(T&& value)
341{
342 return adoptRef(*new CSSPrimitiveValue(std::forward<T>(value)));
343}
344
345template<typename T> inline Ref<CSSPrimitiveValue> CSSPrimitiveValue::create(T&& value, CSSPropertyID propertyID)
346{
347 return adoptRef(*new CSSPrimitiveValue(std::forward<T>(value), propertyID));
348}
349
350template<typename T, CSSPrimitiveValue::TimeUnit timeUnit> inline T CSSPrimitiveValue::computeTime() const
351{
352 if (timeUnit == Seconds && primitiveType() == CSSUnitType::CSS_S)
353 return value<T>();
354 if (timeUnit == Seconds && primitiveType() == CSSUnitType::CSS_MS)
355 return value<T>() / 1000;
356 if (timeUnit == Milliseconds && primitiveType() == CSSUnitType::CSS_MS)
357 return value<T>();
358 if (timeUnit == Milliseconds && primitiveType() == CSSUnitType::CSS_S)
359 return value<T>() * 1000;
360 ASSERT_NOT_REACHED();
361 return 0;
362}
363
364template<typename T> inline CSSPrimitiveValue::CSSPrimitiveValue(RefPtr<T>&& value)
365 : CSSValue(PrimitiveClass)
366{
367 init(WTFMove(value));
368}
369
370template<typename T> inline CSSPrimitiveValue::CSSPrimitiveValue(Ref<T>&& value)
371 : CSSValue(PrimitiveClass)
372{
373 init(WTFMove(value));
374}
375
376inline double CSSPrimitiveValue::computeDegrees(CSSUnitType type, double angle)
377{
378 switch (type) {
379 case CSSUnitType::CSS_DEG:
380 return angle;
381 case CSSUnitType::CSS_RAD:
382 return rad2deg(angle);
383 case CSSUnitType::CSS_GRAD:
384 return grad2deg(angle);
385 case CSSUnitType::CSS_TURN:
386 return turn2deg(angle);
387 default:
388 ASSERT_NOT_REACHED();
389 return 0;
390 }
391}
392
393} // namespace WebCore
394
395SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSPrimitiveValue, isPrimitiveValue())
Note: See TracBrowser for help on using the repository browser.