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 | #include "config.h"
|
---|
32 | #include "CSSToLengthConversionData.h"
|
---|
33 |
|
---|
34 | #include "FloatSize.h"
|
---|
35 | #include "RenderStyle.h"
|
---|
36 | #include "RenderView.h"
|
---|
37 | #include "StyleBuilderState.h"
|
---|
38 |
|
---|
39 | namespace WebCore {
|
---|
40 |
|
---|
41 | CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle& style, const Style::BuilderContext& builderContext)
|
---|
42 | : m_style(&style)
|
---|
43 | , m_rootStyle(builderContext.rootElementStyle)
|
---|
44 | , m_parentStyle(&builderContext.parentStyle)
|
---|
45 | , m_renderView(builderContext.document->renderView())
|
---|
46 | , m_elementForContainerUnitResolution(builderContext.element)
|
---|
47 | , m_viewportDependencyDetectionStyle(const_cast<RenderStyle*>(m_style))
|
---|
48 | {
|
---|
49 | }
|
---|
50 |
|
---|
51 | CSSToLengthConversionData::CSSToLengthConversionData(const RenderStyle& style, const RenderStyle* rootStyle, const RenderStyle* parentStyle, const RenderView* renderView, const Element* elementForContainerUnitResolution)
|
---|
52 | : m_style(&style)
|
---|
53 | , m_rootStyle(rootStyle)
|
---|
54 | , m_parentStyle(parentStyle)
|
---|
55 | , m_renderView(renderView)
|
---|
56 | , m_elementForContainerUnitResolution(elementForContainerUnitResolution)
|
---|
57 | , m_zoom(1.f)
|
---|
58 | , m_viewportDependencyDetectionStyle(const_cast<RenderStyle*>(m_style))
|
---|
59 | {
|
---|
60 | }
|
---|
61 |
|
---|
62 | float CSSToLengthConversionData::zoom() const
|
---|
63 | {
|
---|
64 | return m_zoom.value_or(m_style ? m_style->effectiveZoom() : 1.f);
|
---|
65 | }
|
---|
66 |
|
---|
67 | FloatSize CSSToLengthConversionData::defaultViewportFactor() const
|
---|
68 | {
|
---|
69 | if (m_viewportDependencyDetectionStyle)
|
---|
70 | m_viewportDependencyDetectionStyle->setUsesViewportUnits();
|
---|
71 |
|
---|
72 | if (!m_renderView)
|
---|
73 | return { };
|
---|
74 |
|
---|
75 | return m_renderView->sizeForCSSDefaultViewportUnits() / 100.0;
|
---|
76 | }
|
---|
77 |
|
---|
78 | FloatSize CSSToLengthConversionData::smallViewportFactor() const
|
---|
79 | {
|
---|
80 | if (m_viewportDependencyDetectionStyle)
|
---|
81 | m_viewportDependencyDetectionStyle->setUsesViewportUnits();
|
---|
82 |
|
---|
83 | if (!m_renderView)
|
---|
84 | return { };
|
---|
85 |
|
---|
86 | return m_renderView->sizeForCSSSmallViewportUnits() / 100.0;
|
---|
87 | }
|
---|
88 |
|
---|
89 | FloatSize CSSToLengthConversionData::largeViewportFactor() const
|
---|
90 | {
|
---|
91 | if (m_viewportDependencyDetectionStyle)
|
---|
92 | m_viewportDependencyDetectionStyle->setUsesViewportUnits();
|
---|
93 |
|
---|
94 | if (!m_renderView)
|
---|
95 | return { };
|
---|
96 |
|
---|
97 | return m_renderView->sizeForCSSLargeViewportUnits() / 100.0;
|
---|
98 | }
|
---|
99 |
|
---|
100 | FloatSize CSSToLengthConversionData::dynamicViewportFactor() const
|
---|
101 | {
|
---|
102 | if (m_viewportDependencyDetectionStyle)
|
---|
103 | m_viewportDependencyDetectionStyle->setUsesViewportUnits();
|
---|
104 |
|
---|
105 | if (!m_renderView)
|
---|
106 | return { };
|
---|
107 |
|
---|
108 | return m_renderView->sizeForCSSDynamicViewportUnits() / 100.0;
|
---|
109 | }
|
---|
110 |
|
---|
111 | void CSSToLengthConversionData::setUsesContainerUnits() const
|
---|
112 | {
|
---|
113 | if (m_viewportDependencyDetectionStyle)
|
---|
114 | m_viewportDependencyDetectionStyle->setUsesContainerUnits();
|
---|
115 | }
|
---|
116 |
|
---|
117 | } // namespace WebCore
|
---|