Chromium Code Reviews| 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::computeLegibleScale() |
| 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 const float defaultScaleWhenAlreadyLegible = minimumPageScaleFactor() * doub leTapZoomAlreadyLegibleRatio; | |
| 1134 float legibleScale = 1; | |
| 1135 if (page()) | |
| 1136 legibleScale *= page()->settings().textAutosizingFontScaleFactor(); | |
| 1137 if (legibleScale < defaultScaleWhenAlreadyLegible) | |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
Delete these two lines.
| |
| 1138 legibleScale = (pageScaleFactor() == minimumPageScaleFactor()) ? default ScaleWhenAlreadyLegible : minimumPageScaleFactor(); | |
| 1139 return legibleScale; | |
| 1140 } | |
| 1141 | |
| 1142 void WebViewImpl::computeScaleAndScrollForBlockRect(const WebRect& blockRect, fl oat padding, float& scale, WebPoint& scroll) | |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
Come to think of it, the defaultScaleWhenAlreadyLe
| |
| 1128 { | 1143 { |
| 1129 scale = pageScaleFactor(); | 1144 scale = pageScaleFactor(); |
| 1130 scroll.x = scroll.y = 0; | 1145 scroll.x = scroll.y = 0; |
| 1131 | 1146 |
| 1132 WebRect rect = blockRect; | 1147 WebRect rect = blockRect; |
| 1133 | 1148 |
| 1134 bool scaleUnchanged = true; | |
| 1135 if (!rect.isEmpty()) { | 1149 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; | 1150 float defaultMargin = doubleTapZoomContentDefaultMargin; |
| 1148 float minimumMargin = doubleTapZoomContentMinimumMargin; | 1151 float minimumMargin = doubleTapZoomContentMinimumMargin; |
| 1149 // We want the margins to have the same physical size, which means we | 1152 // 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 | 1153 // 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 | 1154 // 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 | 1155 // 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 | 1156 // correct if we end up fully zooming to it, and won't matter if we |
| 1154 // don't. | 1157 // don't. |
| 1155 rect = widenRectWithinPageBounds(rect, | 1158 rect = widenRectWithinPageBounds(rect, |
| 1156 static_cast<int>(defaultMargin * rect.width / m_size.width), | 1159 static_cast<int>(defaultMargin * rect.width / m_size.width), |
| 1157 static_cast<int>(minimumMargin * rect.width / m_size.width)); | 1160 static_cast<int>(minimumMargin * rect.width / m_size.width)); |
| 1158 // Fit block to screen, respecting limits. | 1161 // Fit block to screen, respecting limits. |
| 1159 scale = static_cast<float>(m_size.width) / rect.width; | 1162 scale = static_cast<float>(m_size.width) / rect.width; |
| 1160 scale = min(scale, legibleScale); | 1163 scale = min(scale, computeLegibleScale()); |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
Immediately after this line add the lines:
if (pa
| |
| 1161 scale = clampPageScaleFactorToLimits(scale); | 1164 scale = clampPageScaleFactorToLimits(scale); |
| 1162 | |
| 1163 scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference; | |
| 1164 } | 1165 } |
| 1165 | 1166 |
| 1166 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa geScaleFactor | |
| 1167 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor()) | |
| 1168 || m_doubleTapZoomPending; | |
| 1169 | |
| 1170 doubleTapShouldZoomOut = rect.isEmpty() || scaleUnchanged || stillAtPrevious DoubleTapScale; | |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
Good idea, there was no reason to keep this in thi
| |
| 1171 | |
| 1172 // FIXME: If this is being called for auto zoom during find in page, | 1167 // 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 | 1168 // 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 | 1169 // 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 | 1170 // 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) | 1171 // double-tap zoom strategy (fitting the containing block to the screen) |
| 1177 // though. | 1172 // though. |
| 1178 | 1173 |
| 1179 float screenWidth = m_size.width / scale; | 1174 float screenWidth = m_size.width / scale; |
| 1180 float screenHeight = m_size.height / scale; | 1175 float screenHeight = m_size.height / scale; |
| 1181 | 1176 |
| 1182 // Scroll to vertically align the block. | 1177 // Scroll to vertically align the block. |
| 1183 if (rect.height < screenHeight) { | 1178 if (rect.height < screenHeight) { |
| 1184 // Vertically center short blocks. | 1179 // Vertically center short blocks. |
| 1185 rect.y -= 0.5 * (screenHeight - rect.height); | 1180 rect.y -= 0.5 * (screenHeight - rect.height); |
| 1186 } else { | 1181 } else { |
| 1187 // Ensure position we're zooming to (+ padding) isn't off the bottom of | 1182 // Ensure position we're zooming to (+ padding) isn't off the bottom of |
| 1188 // the screen. | 1183 // the screen. |
| 1189 rect.y = max<float>(rect.y, blockRect.y + padding - screenHeight); | 1184 rect.y = max<float>(rect.y, blockRect.y + padding - screenHeight); |
| 1190 } // Otherwise top align the block. | 1185 } // Otherwise top align the block. |
| 1191 | 1186 |
| 1192 // Do the same thing for horizontal alignment. | 1187 // Do the same thing for horizontal alignment. |
| 1193 if (rect.width < screenWidth) | 1188 if (rect.width < screenWidth) |
| 1194 rect.x -= 0.5 * (screenWidth - rect.width); | 1189 rect.x -= 0.5 * (screenWidth - rect.width); |
| 1195 else | 1190 else |
| 1196 rect.x = max<float>(rect.x, blockRect.x + padding - screenWidth); | 1191 rect.x = max<float>(rect.x, blockRect.x + padding - screenWidth); |
| 1197 scroll.x = rect.x; | 1192 scroll.x = rect.x; |
| 1198 scroll.y = rect.y; | 1193 scroll.y = rect.y; |
| 1199 | 1194 |
| 1200 scale = clampPageScaleFactorToLimits(scale); | |
| 1201 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); | 1195 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); |
| 1202 scroll = clampOffsetAtScale(scroll, scale); | 1196 scroll = clampOffsetAtScale(scroll, scale); |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
The amount of scaling must be finalized before thi
| |
| 1203 } | 1197 } |
| 1204 | 1198 |
| 1205 static bool invokesHandCursor(Node* node, bool shiftKey, Frame* frame) | 1199 static bool invokesHandCursor(Node* node, bool shiftKey, Frame* frame) |
| 1206 { | 1200 { |
| 1207 if (!node || !node->renderer()) | 1201 if (!node || !node->renderer()) |
| 1208 return false; | 1202 return false; |
| 1209 | 1203 |
| 1210 ECursor cursor = node->renderer()->style()->cursor(); | 1204 ECursor cursor = node->renderer()->style()->cursor(); |
| 1211 return cursor == CURSOR_POINTER | 1205 return cursor == CURSOR_POINTER |
| 1212 || (cursor == CURSOR_AUTO && frame->eventHandler()->useHandCursor(node, node->isLink(), shiftKey)); | 1206 || (cursor == CURSOR_AUTO && frame->eventHandler()->useHandCursor(node, node->isLink(), shiftKey)); |
| (...skipping 48 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, scale, scr oll); |
| 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 | |
| 1275 if ((blockBounds.isEmpty() || scaleUnchanged) && fabs(scale - minimumPageSca leFactor()) < minScaleDifference) { | |
|
aelias_OOO_until_Jul13
2013/08/29 00:19:32
Delete this block.
| |
| 1276 scale = computeLegibleScale(); | |
| 1277 shouldZoomOut = false; | |
| 1278 } | |
| 1274 | 1279 |
| 1275 bool isAnimating; | 1280 bool isAnimating; |
| 1276 | 1281 |
| 1277 if (doubleTapShouldZoomOut) { | 1282 if (shouldZoomOut) { |
| 1278 scale = minimumPageScaleFactor(); | 1283 scale = minimumPageScaleFactor(); |
| 1279 isAnimating = startPageScaleAnimation(mainFrameImpl()->frameView()->wind owToContents(point), true, scale, doubleTapZoomAnimationDurationInSeconds); | 1284 isAnimating = startPageScaleAnimation(mainFrameImpl()->frameView()->wind owToContents(point), true, scale, doubleTapZoomAnimationDurationInSeconds); |
| 1280 } else { | 1285 } else { |
| 1281 isAnimating = startPageScaleAnimation(scroll, false, scale, doubleTapZoo mAnimationDurationInSeconds); | 1286 isAnimating = startPageScaleAnimation(scroll, false, scale, doubleTapZoo mAnimationDurationInSeconds); |
| 1282 } | 1287 } |
| 1283 | 1288 |
| 1284 if (isAnimating) { | 1289 if (isAnimating) { |
| 1285 m_doubleTapZoomPageScaleFactor = scale; | 1290 m_doubleTapZoomPageScaleFactor = scale; |
| 1286 m_doubleTapZoomPending = true; | 1291 m_doubleTapZoomPending = true; |
| 1287 } | 1292 } |
| 1288 } | 1293 } |
| 1289 | 1294 |
| 1290 void WebViewImpl::zoomToFindInPageRect(const WebRect& rect) | 1295 void WebViewImpl::zoomToFindInPageRect(const WebRect& rect) |
| 1291 { | 1296 { |
| 1292 if (!mainFrameImpl()) | 1297 if (!mainFrameImpl()) |
| 1293 return; | 1298 return; |
| 1294 | 1299 |
| 1295 WebRect blockBounds = computeBlockBounds(rect, true); | 1300 WebRect blockBounds = computeBlockBounds(rect, true); |
| 1296 | 1301 |
| 1297 if (blockBounds.isEmpty()) { | 1302 if (blockBounds.isEmpty()) { |
| 1298 // Keep current scale (no need to scroll as x,y will normally already | 1303 // 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. | 1304 // be visible). FIXME: Revisit this if it isn't always true. |
| 1300 return; | 1305 return; |
| 1301 } | 1306 } |
| 1302 | 1307 |
| 1303 float scale; | 1308 float scale; |
| 1304 WebPoint scroll; | 1309 WebPoint scroll; |
| 1305 bool doubleTapShouldZoomOut; | |
| 1306 | 1310 |
| 1307 computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding, scale, scroll, doubleTapShouldZoomOut); | 1311 computeScaleAndScrollForBlockRect(blockBounds, nonUserInitiatedPointPadding, scale, scroll); |
| 1308 | 1312 |
| 1309 startPageScaleAnimation(scroll, false, scale, findInPageAnimationDurationInS econds); | 1313 startPageScaleAnimation(scroll, false, scale, findInPageAnimationDurationInS econds); |
| 1310 } | 1314 } |
| 1311 | 1315 |
| 1312 bool WebViewImpl::zoomToMultipleTargetsRect(const WebRect& rect) | 1316 bool WebViewImpl::zoomToMultipleTargetsRect(const WebRect& rect) |
| 1313 { | 1317 { |
| 1314 if (!mainFrameImpl()) | 1318 if (!mainFrameImpl()) |
| 1315 return false; | 1319 return false; |
| 1316 | 1320 |
| 1317 float scale; | 1321 float scale; |
| 1318 WebPoint scroll; | 1322 WebPoint scroll; |
| 1319 bool doubleTapShouldZoomOut; | |
| 1320 | 1323 |
| 1321 computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, scale, scroll, doubleTapShouldZoomOut); | 1324 computeScaleAndScrollForBlockRect(rect, nonUserInitiatedPointPadding, scale, scroll); |
| 1322 | 1325 |
| 1323 if (scale <= pageScaleFactor()) | 1326 if (scale <= pageScaleFactor()) |
| 1324 return false; | 1327 return false; |
| 1325 | 1328 |
| 1326 startPageScaleAnimation(scroll, false, scale, multipleTargetsZoomAnimationDu rationInSeconds); | 1329 startPageScaleAnimation(scroll, false, scale, multipleTargetsZoomAnimationDu rationInSeconds); |
| 1327 return true; | 1330 return true; |
| 1328 } | 1331 } |
| 1329 | 1332 |
| 1330 void WebViewImpl::numberOfWheelEventHandlersChanged(unsigned numberOfWheelHandle rs) | 1333 void WebViewImpl::numberOfWheelEventHandlersChanged(unsigned numberOfWheelHandle rs) |
| 1331 { | 1334 { |
| (...skipping 2779 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4111 } | 4114 } |
| 4112 | 4115 |
| 4113 bool WebViewImpl::shouldDisableDesktopWorkarounds() | 4116 bool WebViewImpl::shouldDisableDesktopWorkarounds() |
| 4114 { | 4117 { |
| 4115 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); | 4118 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); |
| 4116 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom | 4119 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom |
| 4117 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); | 4120 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); |
| 4118 } | 4121 } |
| 4119 | 4122 |
| 4120 } // namespace WebKit | 4123 } // namespace WebKit |
| OLD | NEW |