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

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

Limit the deprecated CSSOMPrimitiveValue to formerly standardized unit types
https://bugs.webkit.org/show_bug.cgi?id=233651
<rdar://problem/85878291>

Reviewed by Darin Adler.

Source/WebCore:

This removes support, and makes it clear that these deprecated APIs shouldn't be exposing
anything more modern than what is standardized in DOM Level 2 Style. Hopefully this avoids
others in future adding support for new units.

Other changes included as they are necessary to make improved test not assert.

Test: fast/css/CSSPrimitiveValue-modern-length.html

  • css/CSSUnits.cpp:

(WebCore::unitCategory): Ensure this is complete for all units.
(WebCore::canonicalUnitTypeForCategory): Ensure this is complete for all unit categories.

  • css/DeprecatedCSSOMPrimitiveValue.cpp:

(WebCore::DeprecatedCSSOMPrimitiveValue::primitiveType const): Remove post-DOM Level 2 Style values.
(WebCore::DeprecatedCSSOMPrimitiveValue::getFloatValue const): Remove post-DOM Level 2 Style values.
(WebCore::DeprecatedCSSOMPrimitiveValue::getStringValue const): Add comment.

  • css/DeprecatedCSSOMPrimitiveValue.h: Remove post-DOM Level 2 Style constants.
  • css/DeprecatedCSSOMPrimitiveValue.idl: Remove post-DOM Level 2 Style constants.
  • css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor.
(WebCore::CSSPrimitiveValue::doubleValueInternal const): Handle std::optional return.

  • css/CSSPrimitiveValue.h:

(WebCore::CSSPrimitiveValue::conversionToCanonicalUnitsScaleFactor): Change to return std::optional, making explicit when there is no scaling factor.

  • page/PrintContext.cpp:

(WebCore::PrintContext::computedPageMargin): Handle std::optional return.

LayoutTests:

Updated/moved test to cover all modern length units, not just ic.

  • fast/css/CSSPrimitiveValue-ic-expected.txt: Removed.
  • fast/css/CSSPrimitiveValue-ic.html: Removed.
  • fast/css/CSSPrimitiveValue-modern-length-expected.txt: Added.
  • fast/css/CSSPrimitiveValue-modern-length.html: Added.
File size: 4.0 KB
Line 
1/*
2 * Copyright (C) 2016 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 *
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26#pragma once
27
28#include "CSSPrimitiveValue.h"
29#include "DeprecatedCSSOMValue.h"
30
31namespace WebCore {
32
33class DeprecatedCSSOMCounter;
34class DeprecatedCSSOMRGBColor;
35class DeprecatedCSSOMRect;
36
37class DeprecatedCSSOMPrimitiveValue : public DeprecatedCSSOMValue {
38public:
39 // Only expose what's in the IDL file.
40 enum UnitType {
41 CSS_UNKNOWN = 0,
42 CSS_NUMBER = 1,
43 CSS_PERCENTAGE = 2,
44 CSS_EMS = 3,
45 CSS_EXS = 4,
46 CSS_PX = 5,
47 CSS_CM = 6,
48 CSS_MM = 7,
49 CSS_IN = 8,
50 CSS_PT = 9,
51 CSS_PC = 10,
52 CSS_DEG = 11,
53 CSS_RAD = 12,
54 CSS_GRAD = 13,
55 CSS_MS = 14,
56 CSS_S = 15,
57 CSS_HZ = 16,
58 CSS_KHZ = 17,
59 CSS_DIMENSION = 18,
60 CSS_STRING = 19,
61 CSS_URI = 20,
62 CSS_IDENT = 21,
63 CSS_ATTR = 22,
64 CSS_COUNTER = 23,
65 CSS_RECT = 24,
66 CSS_RGBCOLOR = 25
67 // Do not add new units here; this is deprecated and we shouldn't expose anything not in DOM Level 2 Style.
68 };
69
70 static Ref<DeprecatedCSSOMPrimitiveValue> create(const CSSPrimitiveValue& value, CSSStyleDeclaration& owner)
71 {
72 return adoptRef(*new DeprecatedCSSOMPrimitiveValue(value, owner));
73 }
74
75 bool equals(const DeprecatedCSSOMPrimitiveValue& other) const { return m_value->equals(other.m_value); }
76 String cssText() const { return m_value->cssText(); }
77
78 WEBCORE_EXPORT unsigned short primitiveType() const;
79 WEBCORE_EXPORT ExceptionOr<float> getFloatValue(unsigned short unitType) const;
80 WEBCORE_EXPORT ExceptionOr<String> getStringValue() const;
81 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMCounter>> getCounterValue() const;
82 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMRect>> getRectValue() const;
83 WEBCORE_EXPORT ExceptionOr<Ref<DeprecatedCSSOMRGBColor>> getRGBColorValue() const;
84
85 static ExceptionOr<void> setFloatValue(unsigned short, double) { return Exception { NoModificationAllowedError }; }
86 static ExceptionOr<void> setStringValue(unsigned short, const String&) { return Exception { NoModificationAllowedError }; }
87
88 String stringValue() const { return m_value->stringValue(); }
89 bool isCSSWideKeyword() const { return m_value->isCSSWideKeyword(); }
90 unsigned cssValueType() const { return m_value->cssValueType(); }
91
92private:
93 DeprecatedCSSOMPrimitiveValue(const CSSPrimitiveValue& value, CSSStyleDeclaration& owner)
94 : DeprecatedCSSOMValue(DeprecatedPrimitiveValueClass, owner)
95 , m_value(const_cast<CSSPrimitiveValue&>(value))
96 {
97 }
98
99 Ref<CSSPrimitiveValue> m_value;
100};
101
102} // namespace WebCore
103
104SPECIALIZE_TYPE_TRAITS_CSSOM_VALUE(DeprecatedCSSOMPrimitiveValue, isPrimitiveValue())
Note: See TracBrowser for help on using the repository browser.