Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(44)

Side by Side Diff: Source/core/page/PageScaleConstraintsSet.cpp

Issue 14813025: Refactor viewport initialization logic out of WebViewImpl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix webkit_unit_tests Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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 "PageScaleConstraintsSet.h"
33
34 namespace WebCore {
35
36 static const float defaultMinimumScale = 0.25f;
37 static const float defaultMaximumScale = 5.0f;
38
39 PageScaleConstraintsSet::PageScaleConstraintsSet()
40 : m_lastContentsWidth(0)
41 , m_needsReset(false)
42 , m_constraintsDirty(false)
43 {
44 m_finalConstraints = defaultConstraints();
45 }
46
47 PageScaleConstraints PageScaleConstraintsSet::defaultConstraints() const
48 {
49 return PageScaleConstraints(-1, defaultMinimumScale, defaultMaximumScale);
50 }
51
52 void PageScaleConstraintsSet::updatePageDefinedConstraints(const ViewportArgumen ts& arguments, IntSize viewSize, int layoutFallbackWidth)
53 {
54 m_pageDefinedConstraints = arguments.resolve(viewSize, viewSize, layoutFallb ackWidth);
55
56 m_constraintsDirty = true;
57 }
58
59 void PageScaleConstraintsSet::setUserAgentConstraints(const PageScaleConstraints & userAgentConstraints)
60 {
61 m_userAgentConstraints = userAgentConstraints;
62 m_constraintsDirty = true;
63 }
64
65 void PageScaleConstraintsSet::computeFinalConstraints()
66 {
67 m_finalConstraints = defaultConstraints();
68 m_finalConstraints.overrideWith(m_pageDefinedConstraints);
69 m_finalConstraints.overrideWith(m_userAgentConstraints);
70
71 m_constraintsDirty = false;
72 }
73
74 void PageScaleConstraintsSet::adjustFinalConstraintsToContentsSize(IntSize viewS ize, IntSize contentsSize, int nonOverlayScrollbarWidth)
75 {
76 m_finalConstraints.fitToContentsWidth(contentsSize.width(), viewSize.width() - nonOverlayScrollbarWidth);
77 }
78
79 void PageScaleConstraintsSet::setNeedsReset(bool needsReset)
80 {
81 m_needsReset = needsReset;
82 if (needsReset)
83 m_constraintsDirty = true;
84 }
85
86 void PageScaleConstraintsSet::didChangeContentsSize(IntSize contentsSize, float pageScaleFactor)
87 {
88 // If a large fixed-width element expanded the size of the document
89 // late in loading and our initial scale is not constrained, reset the
90 // page scale factor to the new minimum scale.
91 if (contentsSize.width() > m_lastContentsWidth
92 && pageScaleFactor == finalConstraints().minimumScale
93 && userAgentConstraints().initialScale == -1 && pageDefinedConstraints() .initialScale == -1)
94 setNeedsReset(true);
95
96 m_constraintsDirty = true;
97 m_lastContentsWidth = contentsSize.width();
98 }
99
100 static float computeDeprecatedTargetDensityDPIFactor(const ViewportArguments& ar guments, float deviceScaleFactor)
101 {
102 if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueDeviceDP I)
103 return 1.0f / deviceScaleFactor;
104
105 float targetDPI = -1.0f;
106 if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueLowDPI)
107 targetDPI = 120.0f;
108 else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueMed iumDPI)
109 targetDPI = 160.0f;
110 else if (arguments.deprecatedTargetDensityDPI == ViewportArguments::ValueHig hDPI)
111 targetDPI = 240.0f;
112 else if (arguments.deprecatedTargetDensityDPI != ViewportArguments::ValueAut o)
113 targetDPI = arguments.deprecatedTargetDensityDPI;
114 return targetDPI > 0 ? (deviceScaleFactor * 120.0f) / targetDPI : 1.0f;
115 }
116
117 static float getLayoutWidthForNonWideViewport(const FloatSize& deviceSize, float initialScale)
118 {
119 return initialScale == -1 ? deviceSize.width() : deviceSize.width() / initia lScale;
120 }
121
122 void PageScaleConstraintsSet::adjustPageDefinedConstraintsForAndroidWebView(cons t ViewportArguments& arguments, IntSize viewSize, int layoutFallbackWidth, float deviceScaleFactor, bool useWideViewport, bool loadWithOverviewMode)
123 {
124 float initialScale = m_pageDefinedConstraints.initialScale;
125 if (arguments.zoom == -1 && !loadWithOverviewMode) {
126 if (arguments.width == -1 || (useWideViewport && arguments.width != View portArguments::ValueDeviceWidth))
127 m_pageDefinedConstraints.initialScale = 1.0f;
128 }
129
130 float targetDensityDPIFactor = computeDeprecatedTargetDensityDPIFactor(argum ents, deviceScaleFactor);
131 if (m_pageDefinedConstraints.initialScale != -1)
132 m_pageDefinedConstraints.initialScale *= targetDensityDPIFactor;
133 m_pageDefinedConstraints.minimumScale *= targetDensityDPIFactor;
134 m_pageDefinedConstraints.maximumScale *= targetDensityDPIFactor;
135
136 if (useWideViewport && arguments.width == -1 && arguments.zoom != 1.0f)
137 m_pageDefinedConstraints.layoutSize.setWidth(layoutFallbackWidth);
138 else {
139 if (!useWideViewport)
140 m_pageDefinedConstraints.layoutSize.setWidth(getLayoutWidthForNonWid eViewport(viewSize, initialScale));
141 if (!useWideViewport || arguments.width == -1 || arguments.width == View portArguments::ValueDeviceWidth)
142 m_pageDefinedConstraints.layoutSize.scale(1.0f / targetDensityDPIFac tor);
143 }
144 }
145
146 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698