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 |
|
---|
38 | namespace WebCore {
|
---|
39 |
|
---|
40 | class Element;
|
---|
41 | class FloatSize;
|
---|
42 | class RenderStyle;
|
---|
43 | class RenderView;
|
---|
44 |
|
---|
45 | namespace Style {
|
---|
46 | struct BuilderContext;
|
---|
47 | };
|
---|
48 |
|
---|
49 | class CSSToLengthConversionData {
|
---|
50 | public:
|
---|
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 |
|
---|
99 | private:
|
---|
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
|
---|