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

Side by Side Diff: Source/core/dom/ViewportArguments.cpp

Issue 23604037: Recompute percentage based @viewport on resize. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed review issue Created 7 years, 3 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
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org) 2 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
3 * (C) 1999 Antti Koivisto (koivisto@kde.org) 3 * (C) 1999 Antti Koivisto (koivisto@kde.org)
4 * (C) 2001 Dirk Mueller (mueller@kde.org) 4 * (C) 2001 Dirk Mueller (mueller@kde.org)
5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org) 5 * (C) 2006 Alexey Proskuryakov (ap@webkit.org)
6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed. 6 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2011 Apple Inc. All rights reserv ed.
7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/) 7 * Copyright (C) 2008 Torch Mobile Inc. All rights reserved. (http://www.torchmo bile.com/)
8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) 8 * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies)
9 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved. 9 * Copyright (C) 2012-2013 Intel Corporation. All rights reserved.
10 * 10 *
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
63 { 63 {
64 ASSERT(value != ViewportArguments::ValueDeviceWidth); 64 ASSERT(value != ViewportArguments::ValueDeviceWidth);
65 ASSERT(value != ViewportArguments::ValueDeviceHeight); 65 ASSERT(value != ViewportArguments::ValueDeviceHeight);
66 66
67 // Limits as defined in the css-device-adapt spec. 67 // Limits as defined in the css-device-adapt spec.
68 if (value != ViewportArguments::ValueAuto) 68 if (value != ViewportArguments::ValueAuto)
69 return min(float(10), max(value, float(0.1))); 69 return min(float(10), max(value, float(0.1)));
70 return value; 70 return value;
71 } 71 }
72 72
73 float ViewportArguments::resolveViewportLength(const Length& length, const Float Size& initialViewportSize, Direction direction)
74 {
75 if (length.isAuto())
76 return ViewportArguments::ValueAuto;
77
78 if (length.isFixed())
79 return length.getFloatValue();
80
81 if (length.type() == ExtendToZoom)
82 return ViewportArguments::ValueExtendToZoom;
83
84 if ((length.type() == Percent && direction == Horizontal) || length.type() = = ViewportPercentageWidth)
85 return initialViewportSize.width() * length.getFloatValue() / 100.0f;
86
87 if ((length.type() == Percent && direction == Vertical) || length.type() == ViewportPercentageHeight)
88 return initialViewportSize.height() * length.getFloatValue() / 100.0f;
89
90 if (length.type() == ViewportPercentageMin)
91 return min(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f;
92
93 if (length.type() == ViewportPercentageMax)
94 return max(initialViewportSize.width(), initialViewportSize.height()) * length.viewportPercentageLength() / 100.0f;
95
96 ASSERT_NOT_REACHED();
97 return ViewportArguments::ValueAuto;
98 }
99
73 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, int defaultWidth) const 100 PageScaleConstraints ViewportArguments::resolve(const FloatSize& initialViewport Size, int defaultWidth) const
74 { 101 {
75 float resultWidth = width; 102 float resultWidth = width;
76 float resultMaxWidth = maxWidth;
77 float resultMinWidth = minWidth;
78 float resultHeight = height; 103 float resultHeight = height;
79 float resultMinHeight = minHeight;
80 float resultMaxHeight = maxHeight;
81
82 float resultZoom = zoom; 104 float resultZoom = zoom;
83 float resultMinZoom = minZoom; 105 float resultMinZoom = minZoom;
84 float resultMaxZoom = maxZoom; 106 float resultMaxZoom = maxZoom;
85 float resultUserZoom = userZoom; 107 float resultUserZoom = userZoom;
86 108
87 if (type == ViewportArguments::CSSDeviceAdaptation) { 109 if (type == ViewportArguments::CSSDeviceAdaptation) {
88 110
89 // device-width/device-height not supported for @viewport. 111 float resultMaxWidth = resolveViewportLength(maxWidth, initialViewportSi ze, Horizontal);
90 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceWidth); 112 float resultMinWidth = resolveViewportLength(minWidth, initialViewportSi ze, Horizontal);
91 ASSERT(resultMinWidth != ViewportArguments::ValueDeviceHeight); 113 float resultMaxHeight = resolveViewportLength(maxHeight, initialViewport Size, Vertical);
92 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceWidth); 114 float resultMinHeight = resolveViewportLength(minHeight, initialViewport Size, Vertical);
93 ASSERT(resultMaxWidth != ViewportArguments::ValueDeviceHeight);
94 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceWidth);
95 ASSERT(resultMinHeight != ViewportArguments::ValueDeviceHeight);
96 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceWidth);
97 ASSERT(resultMaxHeight != ViewportArguments::ValueDeviceHeight);
98 115
99 // 1. Resolve min-zoom and max-zoom values. 116 // 1. Resolve min-zoom and max-zoom values.
100 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto) 117 if (resultMinZoom != ViewportArguments::ValueAuto && resultMaxZoom != Vi ewportArguments::ValueAuto)
101 resultMaxZoom = max(resultMinZoom, resultMaxZoom); 118 resultMaxZoom = max(resultMinZoom, resultMaxZoom);
102 119
103 // 2. Constrain zoom value to the [min-zoom, max-zoom] range. 120 // 2. Constrain zoom value to the [min-zoom, max-zoom] range.
104 if (resultZoom != ViewportArguments::ValueAuto) 121 if (resultZoom != ViewportArguments::ValueAuto)
105 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max); 122 resultZoom = compareIgnoringAuto(resultMinZoom, compareIgnoringAuto( resultMaxZoom, resultZoom, min), max);
106 123
107 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min); 124 float extendZoom = compareIgnoringAuto(resultZoom, resultMaxZoom, min);
(...skipping 30 matching lines...) Expand all
138 // 4. Resolve initial width from min/max descriptors. 155 // 4. Resolve initial width from min/max descriptors.
139 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto) 156 if (resultMinWidth != ViewportArguments::ValueAuto || resultMaxWidth != ViewportArguments::ValueAuto)
140 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max); 157 resultWidth = compareIgnoringAuto(resultMinWidth, compareIgnoringAut o(resultMaxWidth, initialViewportSize.width(), min), max);
141 158
142 // 5. Resolve initial height from min/max descriptors. 159 // 5. Resolve initial height from min/max descriptors.
143 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto) 160 if (resultMinHeight != ViewportArguments::ValueAuto || resultMaxHeight ! = ViewportArguments::ValueAuto)
144 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max); 161 resultHeight = compareIgnoringAuto(resultMinHeight, compareIgnoringA uto(resultMaxHeight, initialViewportSize.height(), min), max);
145 162
146 // 6-7. Resolve width value. 163 // 6-7. Resolve width value.
147 if (resultWidth == ViewportArguments::ValueAuto) { 164 if (resultWidth == ViewportArguments::ValueAuto) {
148 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport Size .height()) 165 if (resultHeight == ViewportArguments::ValueAuto || !initialViewport Size.height())
149 resultWidth = initialViewportSize.width(); 166 resultWidth = initialViewportSize.width();
150 else 167 else
151 resultWidth = resultHeight * (initialViewportSize.width() / init ialViewportSize.height()); 168 resultWidth = resultHeight * (initialViewportSize.width() / init ialViewportSize.height());
152 } 169 }
153 170
154 // 8. Resolve height value. 171 // 8. Resolve height value.
155 if (resultHeight == ViewportArguments::ValueAuto) { 172 if (resultHeight == ViewportArguments::ValueAuto) {
156 if (!initialViewportSize.width()) 173 if (!initialViewportSize.width())
157 resultHeight = initialViewportSize.height(); 174 resultHeight = initialViewportSize.height();
158 else 175 else
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
446 if (!replacement1.isNull()) 463 if (!replacement1.isNull())
447 message.replace("%replacement1", replacement1); 464 message.replace("%replacement1", replacement1);
448 if (!replacement2.isNull()) 465 if (!replacement2.isNull())
449 message.replace("%replacement2", replacement2); 466 message.replace("%replacement2", replacement2);
450 467
451 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists. 468 // FIXME: This message should be moved off the console once a solution to ht tps://bugs.webkit.org/show_bug.cgi?id=103274 exists.
452 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message); 469 document->addConsoleMessage(RenderingMessageSource, viewportErrorMessageLeve l(errorCode), message);
453 } 470 }
454 471
455 } // namespace WebCore 472 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/dom/ViewportArguments.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698