OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2013 Google Inc. All rights reserved. | 2 * Copyright (C) 2013 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
47 , m_constraintsDirty(false) | 47 , m_constraintsDirty(false) |
48 { | 48 { |
49 m_finalConstraints = defaultConstraints(); | 49 m_finalConstraints = defaultConstraints(); |
50 } | 50 } |
51 | 51 |
52 PageScaleConstraints PageScaleConstraintsSet::defaultConstraints() const | 52 PageScaleConstraints PageScaleConstraintsSet::defaultConstraints() const |
53 { | 53 { |
54 return PageScaleConstraints(-1, defaultMinimumScale, defaultMaximumScale); | 54 return PageScaleConstraints(-1, defaultMinimumScale, defaultMaximumScale); |
55 } | 55 } |
56 | 56 |
57 void PageScaleConstraintsSet::updatePageDefinedConstraints(const ViewportDescrip
tion& description, IntSize viewSize, Length legacyFallbackWidth) | 57 void PageScaleConstraintsSet::updatePageDefinedConstraints(const ViewportDescrip
tion& description, Length legacyFallbackWidth) |
58 { | 58 { |
59 m_pageDefinedConstraints = description.resolve(viewSize, legacyFallbackWidth
); | 59 m_pageDefinedConstraints = description.resolve(m_viewSize, legacyFallbackWid
th); |
60 | 60 |
61 m_constraintsDirty = true; | 61 m_constraintsDirty = true; |
62 } | 62 } |
63 | 63 |
64 void PageScaleConstraintsSet::setUserAgentConstraints(const PageScaleConstraints
& userAgentConstraints) | 64 void PageScaleConstraintsSet::setUserAgentConstraints(const PageScaleConstraints
& userAgentConstraints) |
65 { | 65 { |
66 m_userAgentConstraints = userAgentConstraints; | 66 m_userAgentConstraints = userAgentConstraints; |
67 m_constraintsDirty = true; | 67 m_constraintsDirty = true; |
68 } | 68 } |
69 | 69 |
70 PageScaleConstraints PageScaleConstraintsSet::computeConstraintsStack() const | 70 PageScaleConstraints PageScaleConstraintsSet::computeConstraintsStack() const |
71 { | 71 { |
72 PageScaleConstraints constraints = defaultConstraints(); | 72 PageScaleConstraints constraints = defaultConstraints(); |
73 constraints.overrideWith(m_pageDefinedConstraints); | 73 constraints.overrideWith(m_pageDefinedConstraints); |
74 constraints.overrideWith(m_userAgentConstraints); | 74 constraints.overrideWith(m_userAgentConstraints); |
75 return constraints; | 75 return constraints; |
76 } | 76 } |
77 | 77 |
78 void PageScaleConstraintsSet::computeFinalConstraints() | 78 void PageScaleConstraintsSet::computeFinalConstraints() |
79 { | 79 { |
80 m_finalConstraints = computeConstraintsStack(); | 80 m_finalConstraints = computeConstraintsStack(); |
81 | 81 |
82 m_constraintsDirty = false; | 82 m_constraintsDirty = false; |
83 } | 83 } |
84 | 84 |
85 void PageScaleConstraintsSet::adjustFinalConstraintsToContentsSize(IntSize viewS
ize, IntSize contentsSize, int nonOverlayScrollbarWidth) | 85 void PageScaleConstraintsSet::adjustFinalConstraintsToContentsSize(IntSize conte
ntsSize, int nonOverlayScrollbarWidth) |
86 { | 86 { |
87 m_finalConstraints.fitToContentsWidth(contentsSize.width(), viewSize.width()
- nonOverlayScrollbarWidth); | 87 m_finalConstraints.fitToContentsWidth(contentsSize.width(), m_viewSize.width
() - nonOverlayScrollbarWidth); |
88 } | 88 } |
89 | 89 |
90 void PageScaleConstraintsSet::setNeedsReset(bool needsReset) | 90 void PageScaleConstraintsSet::setNeedsReset(bool needsReset) |
91 { | 91 { |
92 m_needsReset = needsReset; | 92 m_needsReset = needsReset; |
93 if (needsReset) | 93 if (needsReset) |
94 m_constraintsDirty = true; | 94 m_constraintsDirty = true; |
95 } | 95 } |
96 | 96 |
97 void PageScaleConstraintsSet::didChangeContentsSize(IntSize contentsSize, float
pageScaleFactor) | 97 void PageScaleConstraintsSet::didChangeContentsSize(IntSize contentsSize, float
pageScaleFactor) |
(...skipping 30 matching lines...) Expand all Loading... |
128 static float getLayoutWidthForNonWideViewport(const FloatSize& deviceSize, float
initialScale) | 128 static float getLayoutWidthForNonWideViewport(const FloatSize& deviceSize, float
initialScale) |
129 { | 129 { |
130 return initialScale == -1 ? deviceSize.width() : deviceSize.width() / initia
lScale; | 130 return initialScale == -1 ? deviceSize.width() : deviceSize.width() / initia
lScale; |
131 } | 131 } |
132 | 132 |
133 static float computeHeightByAspectRatio(float width, const FloatSize& deviceSize
) | 133 static float computeHeightByAspectRatio(float width, const FloatSize& deviceSize
) |
134 { | 134 { |
135 return width * (deviceSize.height() / deviceSize.width()); | 135 return width * (deviceSize.height() / deviceSize.width()); |
136 } | 136 } |
137 | 137 |
138 IntSize PageScaleConstraintsSet::mainFrameSize(const IntSize& viewportSize, cons
t IntSize& contentsSize) const | 138 void PageScaleConstraintsSet::didChangeViewSize(const IntSize& size) |
| 139 { |
| 140 if (m_viewSize == size) |
| 141 return; |
| 142 |
| 143 m_viewSize = size; |
| 144 m_constraintsDirty = true; |
| 145 } |
| 146 |
| 147 IntSize PageScaleConstraintsSet::mainFrameSize(const IntSize& contentsSize) cons
t |
139 { | 148 { |
140 // If there's no explicit minimum scale factor set, size the frame so that i
ts width == content width | 149 // If there's no explicit minimum scale factor set, size the frame so that i
ts width == content width |
141 // so there's no horizontal scrolling at the minimum scale. | 150 // so there's no horizontal scrolling at the minimum scale. |
142 if (m_pageDefinedConstraints.minimumScale < finalConstraints().minimumScale | 151 if (m_pageDefinedConstraints.minimumScale < finalConstraints().minimumScale |
143 && m_userAgentConstraints.minimumScale < finalConstraints().minimumScale | 152 && m_userAgentConstraints.minimumScale < finalConstraints().minimumScale |
144 && contentsSize.width() | 153 && contentsSize.width() |
145 && viewportSize.width()) | 154 && m_viewSize.width()) |
146 return IntSize(contentsSize.width(), computeHeightByAspectRatio(contents
Size.width(), viewportSize)); | 155 return IntSize(contentsSize.width(), computeHeightByAspectRatio(contents
Size.width(), m_viewSize)); |
147 | 156 |
148 // If there is a minimum scale (or there's no content size yet), the frame s
ize should match the viewport | 157 // If there is a minimum scale (or there's no content size yet), the frame s
ize should match the viewport |
149 // size at minimum scale, since the viewport must always be contained by the
frame. | 158 // size at minimum scale, since the viewport must always be contained by the
frame. |
150 IntSize frameSize(viewportSize); | 159 IntSize frameSize(m_viewSize); |
151 frameSize.scale(1 / finalConstraints().minimumScale); | 160 frameSize.scale(1 / finalConstraints().minimumScale); |
152 return frameSize; | 161 return frameSize; |
153 } | 162 } |
154 | 163 |
155 void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescri
ption& description, IntSize viewSize, int layoutFallbackWidth, float deviceScale
Factor, bool supportTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWid
eViewport, bool loadWithOverviewMode, bool nonUserScalableQuirkEnabled) | 164 void PageScaleConstraintsSet::adjustForAndroidWebViewQuirks(const ViewportDescri
ption& description, int layoutFallbackWidth, float deviceScaleFactor, bool suppo
rtTargetDensityDPI, bool wideViewportQuirkEnabled, bool useWideViewport, bool lo
adWithOverviewMode, bool nonUserScalableQuirkEnabled) |
156 { | 165 { |
157 if (!supportTargetDensityDPI && !wideViewportQuirkEnabled && loadWithOvervie
wMode && !nonUserScalableQuirkEnabled) | 166 if (!supportTargetDensityDPI && !wideViewportQuirkEnabled && loadWithOvervie
wMode && !nonUserScalableQuirkEnabled) |
158 return; | 167 return; |
159 | 168 |
160 const float oldInitialScale = m_pageDefinedConstraints.initialScale; | 169 const float oldInitialScale = m_pageDefinedConstraints.initialScale; |
161 if (!loadWithOverviewMode) { | 170 if (!loadWithOverviewMode) { |
162 bool resetInitialScale = false; | 171 bool resetInitialScale = false; |
163 if (description.zoom == -1) { | 172 if (description.zoom == -1) { |
164 if (description.maxWidth.isAuto() || description.maxWidth.type() ==
ExtendToZoom) | 173 if (description.maxWidth.isAuto() || description.maxWidth.type() ==
ExtendToZoom) |
165 resetInitialScale = true; | 174 resetInitialScale = true; |
(...skipping 18 matching lines...) Expand all Loading... |
184 m_pageDefinedConstraints.maximumScale *= targetDensityDPIFactor; | 193 m_pageDefinedConstraints.maximumScale *= targetDensityDPIFactor; |
185 if (wideViewportQuirkEnabled && (!useWideViewport || description.maxWidt
h.type() == DeviceWidth)) { | 194 if (wideViewportQuirkEnabled && (!useWideViewport || description.maxWidt
h.type() == DeviceWidth)) { |
186 adjustedLayoutSizeWidth /= targetDensityDPIFactor; | 195 adjustedLayoutSizeWidth /= targetDensityDPIFactor; |
187 adjustedLayoutSizeHeight /= targetDensityDPIFactor; | 196 adjustedLayoutSizeHeight /= targetDensityDPIFactor; |
188 } | 197 } |
189 } | 198 } |
190 | 199 |
191 if (wideViewportQuirkEnabled) { | 200 if (wideViewportQuirkEnabled) { |
192 if (useWideViewport && (description.maxWidth.isAuto() || description.max
Width.type() == ExtendToZoom) && description.zoom != 1.0f) { | 201 if (useWideViewport && (description.maxWidth.isAuto() || description.max
Width.type() == ExtendToZoom) && description.zoom != 1.0f) { |
193 adjustedLayoutSizeWidth = layoutFallbackWidth; | 202 adjustedLayoutSizeWidth = layoutFallbackWidth; |
194 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, viewSize); | 203 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, m_viewSize); |
195 } else if (!useWideViewport) { | 204 } else if (!useWideViewport) { |
196 const float nonWideScale = description.zoom < 1 && description.maxWi
dth.type() != DeviceWidth && description.maxWidth.type() != DeviceHeight ? -1 :
oldInitialScale; | 205 const float nonWideScale = description.zoom < 1 && description.maxWi
dth.type() != DeviceWidth && description.maxWidth.type() != DeviceHeight ? -1 :
oldInitialScale; |
197 adjustedLayoutSizeWidth = getLayoutWidthForNonWideViewport(viewSize,
nonWideScale) / targetDensityDPIFactor; | 206 adjustedLayoutSizeWidth = getLayoutWidthForNonWideViewport(m_viewSiz
e, nonWideScale) / targetDensityDPIFactor; |
198 float newInitialScale = targetDensityDPIFactor; | 207 float newInitialScale = targetDensityDPIFactor; |
199 if (m_userAgentConstraints.initialScale != -1 && (description.maxWid
th.type() == DeviceWidth || ((description.maxWidth.isAuto() || description.maxWi
dth.type() == ExtendToZoom) && description.zoom == -1))) { | 208 if (m_userAgentConstraints.initialScale != -1 && (description.maxWid
th.type() == DeviceWidth || ((description.maxWidth.isAuto() || description.maxWi
dth.type() == ExtendToZoom) && description.zoom == -1))) { |
200 adjustedLayoutSizeWidth /= m_userAgentConstraints.initialScale; | 209 adjustedLayoutSizeWidth /= m_userAgentConstraints.initialScale; |
201 newInitialScale = m_userAgentConstraints.initialScale; | 210 newInitialScale = m_userAgentConstraints.initialScale; |
202 } | 211 } |
203 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, viewSize); | 212 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, m_viewSize); |
204 if (description.zoom < 1) { | 213 if (description.zoom < 1) { |
205 m_pageDefinedConstraints.initialScale = newInitialScale; | 214 m_pageDefinedConstraints.initialScale = newInitialScale; |
206 if (m_pageDefinedConstraints.minimumScale != -1) | 215 if (m_pageDefinedConstraints.minimumScale != -1) |
207 m_pageDefinedConstraints.minimumScale = std::min<float>(m_pa
geDefinedConstraints.minimumScale, m_pageDefinedConstraints.initialScale); | 216 m_pageDefinedConstraints.minimumScale = std::min<float>(m_pa
geDefinedConstraints.minimumScale, m_pageDefinedConstraints.initialScale); |
208 if (m_pageDefinedConstraints.maximumScale != -1) | 217 if (m_pageDefinedConstraints.maximumScale != -1) |
209 m_pageDefinedConstraints.maximumScale = std::max<float>(m_pa
geDefinedConstraints.maximumScale, m_pageDefinedConstraints.initialScale); | 218 m_pageDefinedConstraints.maximumScale = std::max<float>(m_pa
geDefinedConstraints.maximumScale, m_pageDefinedConstraints.initialScale); |
210 } | 219 } |
211 } | 220 } |
212 } | 221 } |
213 | 222 |
214 if (nonUserScalableQuirkEnabled && !description.userZoom) { | 223 if (nonUserScalableQuirkEnabled && !description.userZoom) { |
215 m_pageDefinedConstraints.initialScale = targetDensityDPIFactor; | 224 m_pageDefinedConstraints.initialScale = targetDensityDPIFactor; |
216 m_pageDefinedConstraints.minimumScale = m_pageDefinedConstraints.initial
Scale; | 225 m_pageDefinedConstraints.minimumScale = m_pageDefinedConstraints.initial
Scale; |
217 m_pageDefinedConstraints.maximumScale = m_pageDefinedConstraints.initial
Scale; | 226 m_pageDefinedConstraints.maximumScale = m_pageDefinedConstraints.initial
Scale; |
218 if (description.maxWidth.isAuto() || description.maxWidth.type() == Exte
ndToZoom || description.maxWidth.type() == DeviceWidth) { | 227 if (description.maxWidth.isAuto() || description.maxWidth.type() == Exte
ndToZoom || description.maxWidth.type() == DeviceWidth) { |
219 adjustedLayoutSizeWidth = viewSize.width() / targetDensityDPIFactor; | 228 adjustedLayoutSizeWidth = m_viewSize.width() / targetDensityDPIFacto
r; |
220 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, viewSize); | 229 adjustedLayoutSizeHeight = computeHeightByAspectRatio(adjustedLayout
SizeWidth, m_viewSize); |
221 } | 230 } |
222 } | 231 } |
223 | 232 |
224 m_pageDefinedConstraints.layoutSize.setWidth(adjustedLayoutSizeWidth); | 233 m_pageDefinedConstraints.layoutSize.setWidth(adjustedLayoutSizeWidth); |
225 m_pageDefinedConstraints.layoutSize.setHeight(adjustedLayoutSizeHeight); | 234 m_pageDefinedConstraints.layoutSize.setHeight(adjustedLayoutSizeHeight); |
226 } | 235 } |
227 | 236 |
228 } // namespace WebCore | 237 } // namespace WebCore |
OLD | NEW |