| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 1106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1117 | 1117 |
| 1118 const int newWidth = source.width + leftMargin + rightMargin; | 1118 const int newWidth = source.width + leftMargin + rightMargin; |
| 1119 const int newX = source.x - leftMargin; | 1119 const int newX = source.x - leftMargin; |
| 1120 | 1120 |
| 1121 ASSERT(newWidth >= 0); | 1121 ASSERT(newWidth >= 0); |
| 1122 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); | 1122 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); |
| 1123 | 1123 |
| 1124 return WebRect(newX, source.y, newWidth, source.height); | 1124 return WebRect(newX, source.y, newWidth, source.height); |
| 1125 } | 1125 } |
| 1126 | 1126 |
| 1127 void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, fl
oat padding, float& scale, WebPoint& scroll, bool& doubleTapShouldZoomOut) | 1127 float WebViewImpl::legibleScale() const |
| 1128 { |
| 1129 // Pages should be as legible as on desktop when at dpi scale, so no |
| 1130 // need to zoom in further when automatically determining zoom level |
| 1131 // (after double tap, find in page, etc), though the user should still |
| 1132 // be allowed to manually pinch zoom in further if they desire. |
| 1133 float legibleScale = 1; |
| 1134 if (page() && page()->settings().textAutosizingEnabled()) |
| 1135 legibleScale *= page()->settings().textAutosizingFontScaleFactor(); |
| 1136 return legibleScale; |
| 1137 } |
| 1138 |
| 1139 void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, fl
oat padding, float defaultScaleWhenAlreadyLegible, float& scale, WebPoint& scrol
l) |
| 1128 { | 1140 { |
| 1129 scale = pageScaleFactor(); | 1141 scale = pageScaleFactor(); |
| 1130 scroll.x = scroll.y = 0; | 1142 scroll.x = scroll.y = 0; |
| 1131 | 1143 |
| 1132 WebRect rect = blockRect; | 1144 WebRect rect = blockRect; |
| 1133 | 1145 |
| 1134 bool scaleUnchanged = true; | |
| 1135 if (!rect.isEmpty()) { | 1146 if (!rect.isEmpty()) { |
| 1136 // Pages should be as legible as on desktop when at dpi scale, so no | |
| 1137 // need to zoom in further when automatically determining zoom level | |
| 1138 // (after double tap, find in page, etc), though the user should still | |
| 1139 // be allowed to manually pinch zoom in further if they desire. | |
| 1140 const float defaultScaleWhenAlreadyLegible = minimumPageScaleFactor() *
doubleTapZoomAlreadyLegibleRatio; | |
| 1141 float legibleScale = 1; | |
| 1142 if (page()) | |
| 1143 legibleScale *= page()->settings().textAutosizingFontScaleFactor(); | |
| 1144 if (legibleScale < defaultScaleWhenAlreadyLegible) | |
| 1145 legibleScale = (scale == minimumPageScaleFactor()) ? defaultScaleWhe
nAlreadyLegible : minimumPageScaleFactor(); | |
| 1146 | |
| 1147 float defaultMargin = doubleTapZoomContentDefaultMargin; | 1147 float defaultMargin = doubleTapZoomContentDefaultMargin; |
| 1148 float minimumMargin = doubleTapZoomContentMinimumMargin; | 1148 float minimumMargin = doubleTapZoomContentMinimumMargin; |
| 1149 // We want the margins to have the same physical size, which means we | 1149 // We want the margins to have the same physical size, which means we |
| 1150 // need to express them in post-scale size. To do that we'd need to know | 1150 // need to express them in post-scale size. To do that we'd need to know |
| 1151 // the scale we're scaling to, but that depends on the margins. Instead | 1151 // the scale we're scaling to, but that depends on the margins. Instead |
| 1152 // we express them as a fraction of the target rectangle: this will be | 1152 // we express them as a fraction of the target rectangle: this will be |
| 1153 // correct if we end up fully zooming to it, and won't matter if we | 1153 // correct if we end up fully zooming to it, and won't matter if we |
| 1154 // don't. | 1154 // don't. |
| 1155 rect = widenRectWithinPageBounds(rect, | 1155 rect = widenRectWithinPageBounds(rect, |
| 1156 static_cast<int>(defaultMargin * rect.width / m_size.width), | 1156 static_cast<int>(defaultMargin * rect.width / m_size.width), |
| 1157 static_cast<int>(minimumMargin * rect.width / m_size.width)); | 1157 static_cast<int>(minimumMargin * rect.width / m_size.width)); |
| 1158 // Fit block to screen, respecting limits. | 1158 // Fit block to screen, respecting limits. |
| 1159 scale = static_cast<float>(m_size.width) / rect.width; | 1159 scale = static_cast<float>(m_size.width) / rect.width; |
| 1160 scale = min(scale, legibleScale); | 1160 scale = min(scale, legibleScale()); |
| 1161 if (pageScaleFactor() < defaultScaleWhenAlreadyLegible) |
| 1162 scale = max(scale, defaultScaleWhenAlreadyLegible); |
| 1161 scale = clampPageScaleFactorToLimits(scale); | 1163 scale = clampPageScaleFactorToLimits(scale); |
| 1162 | |
| 1163 scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference; | |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa
geScaleFactor | |
| 1167 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor()) | |
| 1168 || m_doubleTapZoomPending; | |
| 1169 | |
| 1170 doubleTapShouldZoomOut = rect.isEmpty() || scaleUnchanged || stillAtPrevious
DoubleTapScale; | |
| 1171 | |
| 1172 // FIXME: If this is being called for auto zoom during find in page, | 1166 // FIXME: If this is being called for auto zoom during find in page, |
| 1173 // then if the user manually zooms in it'd be nice to preserve the | 1167 // then if the user manually zooms in it'd be nice to preserve the |
| 1174 // relative increase in zoom they caused (if they zoom out then it's ok | 1168 // relative increase in zoom they caused (if they zoom out then it's ok |
| 1175 // to zoom them back in again). This isn't compatible with our current | 1169 // to zoom them back in again). This isn't compatible with our current |
| 1176 // double-tap zoom strategy (fitting the containing block to the screen) | 1170 // double-tap zoom strategy (fitting the containing block to the screen) |
| 1177 // though. | 1171 // though. |
| 1178 | 1172 |
| 1179 float screenWidth = m_size.width / scale; | 1173 float screenWidth = m_size.width / scale; |
| 1180 float screenHeight = m_size.height / scale; | 1174 float screenHeight = m_size.height / scale; |
| 1181 | 1175 |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1261 void WebViewImpl::animateDoubleTapZoom(const IntPoint& point) | 1255 void WebViewImpl::animateDoubleTapZoom(const IntPoint& point) |
| 1262 { | 1256 { |
| 1263 if (!mainFrameImpl()) | 1257 if (!mainFrameImpl()) |
| 1264 return; | 1258 return; |
| 1265 | 1259 |
| 1266 WebRect rect(point.x(), point.y(), touchPointPadding, touchPointPadding); | 1260 WebRect rect(point.x(), point.y(), touchPointPadding, touchPointPadding); |
| 1267 WebRect blockBounds = computeBlockBounds(rect, false); | 1261 WebRect blockBounds = computeBlockBounds(rect, false); |
| 1268 | 1262 |
| 1269 float scale; | 1263 float scale; |
| 1270 WebPoint scroll; | 1264 WebPoint scroll; |
| 1271 bool doubleTapShouldZoomOut; | |
| 1272 | 1265 |
| 1273 computeScaleAndScrollForBlockRect(blockBounds, touchPointPadding, scale, scr
oll, doubleTapShouldZoomOut); | 1266 computeScaleAndScrollForBlockRect(blockBounds, touchPointPadding, minimumPag
eScaleFactor() * doubleTapZoomAlreadyLegibleRatio, scale, scroll); |
| 1267 |
| 1268 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa
geScaleFactor |
| 1269 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor()) |
| 1270 || m_doubleTapZoomPending; |
| 1271 |
| 1272 bool scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference; |
| 1273 bool shouldZoomOut = blockBounds.isEmpty() || scaleUnchanged || stillAtPrevi
ousDoubleTapScale; |
| 1274 | 1274 |
| 1275 bool isAnimating; | 1275 bool isAnimating; |
| 1276 | 1276 |
| 1277 if (doubleTapShouldZoomOut) { | 1277 if (shouldZoomOut) { |
| 1278 scale = minimumPageScaleFactor(); | 1278 scale = minimumPageScaleFactor(); |
| 1279 isAnimating = startPageScaleAnimation(mainFrameImpl()->frameView()->wind
owToContents(point), true, scale, doubleTapZoomAnimationDurationInSeconds); | 1279 isAnimating = startPageScaleAnimation(mainFrameImpl()->frameView()->wind
owToContents(point), true, scale, doubleTapZoomAnimationDurationInSeconds); |
| 1280 } else { | 1280 } else { |
| 1281 isAnimating = startPageScaleAnimation(scroll, false, scale, doubleTapZoo
mAnimationDurationInSeconds); | 1281 isAnimating = startPageScaleAnimation(scroll, false, scale, doubleTapZoo
mAnimationDurationInSeconds); |
| 1282 } | 1282 } |
| 1283 | 1283 |
| 1284 if (isAnimating) { | 1284 if (isAnimating) { |
| 1285 m_doubleTapZoomPageScaleFactor = scale; | 1285 m_doubleTapZoomPageScaleFactor = scale; |
| 1286 m_doubleTapZoomPending = true; | 1286 m_doubleTapZoomPending = true; |
| 1287 } | 1287 } |
| 1288 } | 1288 } |
| 1289 | 1289 |
| 1290 void WebViewImpl::zoomToFindInPageRect(const WebRect& rect) | 1290 void WebViewImpl::zoomToFindInPageRect(const WebRect& rect) |
| 1291 { | 1291 { |
| 1292 if (!mainFrameImpl()) | 1292 if (!mainFrameImpl()) |
| 1293 return; | 1293 return; |
| 1294 | 1294 |
| 1295 WebRect blockBounds = computeBlockBounds(rect, true); | 1295 WebRect blockBounds = computeBlockBounds(rect, true); |
| 1296 | 1296 |
| 1297 if (blockBounds.isEmpty()) { | 1297 if (blockBounds.isEmpty()) { |
| 1298 // Keep current scale (no need to scroll as x,y will normally already | 1298 // Keep current scale (no need to scroll as x,y will normally already |
| 1299 // be visible). FIXME: Revisit this if it isn't always true. | 1299 // be visible). FIXME: Revisit this if it isn't always true. |
| 1300 return; | 1300 return; |
| 1301 } | 1301 } |
| 1302 | 1302 |
| 1303 float scale; | 1303 float scale; |
| 1304 WebPoint scroll; | 1304 WebPoint scroll; |
| 1305 bool doubleTapShouldZoomOut; | |
| 1306 | 1305 |
| 1307 computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding,
scale, scroll, doubleTapShouldZoomOut); | 1306 computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding,
minimumPageScaleFactor(), scale, scroll); |
| 1308 | 1307 |
| 1309 startPageScaleAnimation(scroll, false, scale, findInPageAnimationDurationInS
econds); | 1308 startPageScaleAnimation(scroll, false, scale, findInPageAnimationDurationInS
econds); |
| 1310 } | 1309 } |
| 1311 | 1310 |
| 1312 bool WebViewImpl::zoomToMultipleTargetsRect(const WebRect& rect) | 1311 bool WebViewImpl::zoomToMultipleTargetsRect(const WebRect& rect) |
| 1313 { | 1312 { |
| 1314 if (!mainFrameImpl()) | 1313 if (!mainFrameImpl()) |
| 1315 return false; | 1314 return false; |
| 1316 | 1315 |
| 1317 float scale; | 1316 float scale; |
| 1318 WebPoint scroll; | 1317 WebPoint scroll; |
| 1319 bool doubleTapShouldZoomOut; | |
| 1320 | 1318 |
| 1321 computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, scale,
scroll, doubleTapShouldZoomOut); | 1319 computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, minimu
mPageScaleFactor(), scale, scroll); |
| 1322 | 1320 |
| 1323 if (scale <= pageScaleFactor()) | 1321 if (scale <= pageScaleFactor()) |
| 1324 return false; | 1322 return false; |
| 1325 | 1323 |
| 1326 startPageScaleAnimation(scroll, false, scale, multipleTargetsZoomAnimationDu
rationInSeconds); | 1324 startPageScaleAnimation(scroll, false, scale, multipleTargetsZoomAnimationDu
rationInSeconds); |
| 1327 return true; | 1325 return true; |
| 1328 } | 1326 } |
| 1329 | 1327 |
| 1330 void WebViewImpl::numberOfWheelEventHandlersChanged(unsigned numberOfWheelHandle
rs) | 1328 void WebViewImpl::numberOfWheelEventHandlersChanged(unsigned numberOfWheelHandle
rs) |
| 1331 { | 1329 { |
| (...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4111 } | 4109 } |
| 4112 | 4110 |
| 4113 bool WebViewImpl::shouldDisableDesktopWorkarounds() | 4111 bool WebViewImpl::shouldDisableDesktopWorkarounds() |
| 4114 { | 4112 { |
| 4115 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport
Arguments(); | 4113 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport
Arguments(); |
| 4116 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments.
userZoom | 4114 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments.
userZoom |
| 4117 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp
ortArguments::ValueAuto); | 4115 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp
ortArguments::ValueAuto); |
| 4118 } | 4116 } |
| 4119 | 4117 |
| 4120 } // namespace WebKit | 4118 } // namespace WebKit |
| OLD | NEW |