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

Last change on this file was 295675, checked in by Antti Koivisto, 3 years ago

[CSS Container Queries] Container units don't work in gradients
https://bugs.webkit.org/show_bug.cgi?id=241780

Reviewed by Tim Nguyen.

  • LayoutTests/TestExpectations:
  • Source/WebCore/css/CSSGradientValue.cpp:

(WebCore::CSSLinearGradientValue::createGradient):
(WebCore::CSSRadialGradientValue::createGradient):
(WebCore::CSSConicGradientValue::createGradient):

Provide the element to CSSToLengthConversionData so a container can be selected.

  • Source/WebCore/css/CSSPrimitiveValue.cpp:

(WebCore::CSSPrimitiveValue::computeNonCalcLengthDouble):

  • Source/WebCore/css/CSSToLengthConversionData.cpp:

(WebCore::CSSToLengthConversionData::CSSToLengthConversionData):

  • Source/WebCore/css/CSSToLengthConversionData.h:

(WebCore::CSSToLengthConversionData::elementForContainerUnitResolution const):
(WebCore::CSSToLengthConversionData::element const): Deleted.

Rename for clarity.

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

File size: 4.3 KB
Line 
1/*
2 * Copyright (C) 2013 Google 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 are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#pragma once
32
33#include "CSSPropertyNames.h"
34#include "Element.h"
35#include <optional>
36#include <wtf/Assertions.h>
37
38namespace WebCore {
39
40class Element;
41class FloatSize;
42class RenderStyle;
43class RenderView;
44
45namespace Style {
46struct BuilderContext;
47};
48
49class CSSToLengthConversionData {
50public:
51 // This is used during style building. The 'zoom' property is taken into account.
52 CSSToLengthConversionData(const RenderStyle&, const Style::BuilderContext&);
53 // This constructor ignores the `zoom` property.
54 CSSToLengthConversionData(const RenderStyle&, const RenderStyle* rootStyle, const RenderStyle* parentStyle, const RenderView*, const Element* elementForContainerUnitResolution = nullptr);
55
56 CSSToLengthConversionData() = default;
57
58 const RenderStyle* style() const { return m_style; }
59 const RenderStyle* rootStyle() const { return m_rootStyle; }
60 const RenderStyle* parentStyle() const { return m_parentStyle; }
61 float zoom() const;
62 bool computingFontSize() const { return m_propertyToCompute == CSSPropertyFontSize; }
63 bool computingLineHeight() const { return m_propertyToCompute == CSSPropertyLineHeight; }
64 CSSPropertyID propertyToCompute() const { return m_propertyToCompute.value_or(CSSPropertyInvalid); }
65 const RenderView* renderView() const { return m_renderView; }
66 const Element* elementForContainerUnitResolution() const { return m_elementForContainerUnitResolution.get(); }
67
68 FloatSize defaultViewportFactor() const;
69 FloatSize smallViewportFactor() const;
70 FloatSize largeViewportFactor() const;
71 FloatSize dynamicViewportFactor() const;
72
73 CSSToLengthConversionData copyForFontSizeWithParentStyle() const
74 {
75 CSSToLengthConversionData copy(*this);
76 copy.m_style = parentStyle();
77 copy.m_zoom = 1.f;
78 copy.m_propertyToCompute = CSSPropertyFontSize;
79 return copy;
80 };
81
82 CSSToLengthConversionData copyWithAdjustedZoom(float zoom) const
83 {
84 CSSToLengthConversionData copy(*this);
85 copy.m_zoom = zoom;
86 return copy;
87 }
88
89 CSSToLengthConversionData copyForLineHeight(float zoom) const
90 {
91 CSSToLengthConversionData copy(*this);
92 copy.m_zoom = zoom;
93 copy.m_propertyToCompute = CSSPropertyLineHeight;
94 return copy;
95 }
96
97 void setUsesContainerUnits() const;
98
99private:
100 const RenderStyle* m_style { nullptr };
101 const RenderStyle* m_rootStyle { nullptr };
102 const RenderStyle* m_parentStyle { nullptr };
103 const RenderView* m_renderView { nullptr };
104 RefPtr<const Element> m_elementForContainerUnitResolution;
105 std::optional<float> m_zoom;
106 std::optional<CSSPropertyID> m_propertyToCompute;
107 // FIXME: Remove this hack.
108 RenderStyle* m_viewportDependencyDetectionStyle { nullptr };
109};
110
111} // namespace WebCore
Note: See TracBrowser for help on using the repository browser.