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 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
154 | 154 |
155 #if USE(DEFAULT_RENDER_THEME) | 155 #if USE(DEFAULT_RENDER_THEME) |
156 #include "core/rendering/RenderThemeChromiumDefault.h" | 156 #include "core/rendering/RenderThemeChromiumDefault.h" |
157 #endif | 157 #endif |
158 | 158 |
159 // Get rid of WTF's pow define so we can use std::pow. | 159 // Get rid of WTF's pow define so we can use std::pow. |
160 #undef pow | 160 #undef pow |
161 #include <cmath> // for std::pow | 161 #include <cmath> // for std::pow |
162 | 162 |
163 using namespace WebCore; | 163 using namespace WebCore; |
| 164 using namespace std; |
164 | 165 |
165 // The following constants control parameters for automated scaling of webpages | 166 // The following constants control parameters for automated scaling of webpages |
166 // (such as due to a double tap gesture or find in page etc.). These are | 167 // (such as due to a double tap gesture or find in page etc.). These are |
167 // experimentally determined. | 168 // experimentally determined. |
168 static const int touchPointPadding = 32; | 169 static const int touchPointPadding = 32; |
169 static const int nonUserInitiatedPointPadding = 11; | 170 static const int nonUserInitiatedPointPadding = 11; |
170 static const float minScaleDifference = 0.01f; | 171 static const float minScaleDifference = 0.01f; |
171 static const float doubleTapZoomContentDefaultMargin = 5; | 172 static const float doubleTapZoomContentDefaultMargin = 5; |
172 static const float doubleTapZoomContentMinimumMargin = 2; | 173 static const float doubleTapZoomContentMinimumMargin = 2; |
173 static const double doubleTapZoomAnimationDurationInSeconds = 0.25; | 174 static const double doubleTapZoomAnimationDurationInSeconds = 0.25; |
(...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1057 maxSize = mainFrame()->contentsSize(); | 1058 maxSize = mainFrame()->contentsSize(); |
1058 IntSize scrollOffset; | 1059 IntSize scrollOffset; |
1059 if (mainFrame()) | 1060 if (mainFrame()) |
1060 scrollOffset = mainFrame()->scrollOffset(); | 1061 scrollOffset = mainFrame()->scrollOffset(); |
1061 int leftMargin = targetMargin; | 1062 int leftMargin = targetMargin; |
1062 int rightMargin = targetMargin; | 1063 int rightMargin = targetMargin; |
1063 | 1064 |
1064 const int absoluteSourceX = source.x + scrollOffset.width(); | 1065 const int absoluteSourceX = source.x + scrollOffset.width(); |
1065 if (leftMargin > absoluteSourceX) { | 1066 if (leftMargin > absoluteSourceX) { |
1066 leftMargin = absoluteSourceX; | 1067 leftMargin = absoluteSourceX; |
1067 rightMargin = std::max(leftMargin, minimumMargin); | 1068 rightMargin = max(leftMargin, minimumMargin); |
1068 } | 1069 } |
1069 | 1070 |
1070 const int maximumRightMargin = maxSize.width - (source.width + absoluteSourc
eX); | 1071 const int maximumRightMargin = maxSize.width - (source.width + absoluteSourc
eX); |
1071 if (rightMargin > maximumRightMargin) { | 1072 if (rightMargin > maximumRightMargin) { |
1072 rightMargin = maximumRightMargin; | 1073 rightMargin = maximumRightMargin; |
1073 leftMargin = std::min(leftMargin, std::max(rightMargin, minimumMargin)); | 1074 leftMargin = min(leftMargin, max(rightMargin, minimumMargin)); |
1074 } | 1075 } |
1075 | 1076 |
1076 const int newWidth = source.width + leftMargin + rightMargin; | 1077 const int newWidth = source.width + leftMargin + rightMargin; |
1077 const int newX = source.x - leftMargin; | 1078 const int newX = source.x - leftMargin; |
1078 | 1079 |
1079 ASSERT(newWidth >= 0); | 1080 ASSERT(newWidth >= 0); |
1080 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); | 1081 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); |
1081 | 1082 |
1082 return WebRect(newX, source.y, newWidth, source.height); | 1083 return WebRect(newX, source.y, newWidth, source.height); |
1083 } | 1084 } |
(...skipping 24 matching lines...) Expand all Loading... |
1108 // need to express them in post-scale size. To do that we'd need to know | 1109 // need to express them in post-scale size. To do that we'd need to know |
1109 // the scale we're scaling to, but that depends on the margins. Instead | 1110 // the scale we're scaling to, but that depends on the margins. Instead |
1110 // we express them as a fraction of the target rectangle: this will be | 1111 // we express them as a fraction of the target rectangle: this will be |
1111 // correct if we end up fully zooming to it, and won't matter if we | 1112 // correct if we end up fully zooming to it, and won't matter if we |
1112 // don't. | 1113 // don't. |
1113 rect = widenRectWithinPageBounds(rect, | 1114 rect = widenRectWithinPageBounds(rect, |
1114 static_cast<int>(defaultMargin * rect.width / m_size.width), | 1115 static_cast<int>(defaultMargin * rect.width / m_size.width), |
1115 static_cast<int>(minimumMargin * rect.width / m_size.width)); | 1116 static_cast<int>(minimumMargin * rect.width / m_size.width)); |
1116 // Fit block to screen, respecting limits. | 1117 // Fit block to screen, respecting limits. |
1117 scale = static_cast<float>(m_size.width) / rect.width; | 1118 scale = static_cast<float>(m_size.width) / rect.width; |
1118 scale = std::min(scale, legibleScale()); | 1119 scale = min(scale, legibleScale()); |
1119 if (pageScaleFactor() < defaultScaleWhenAlreadyLegible) | 1120 if (pageScaleFactor() < defaultScaleWhenAlreadyLegible) |
1120 scale = std::max(scale, defaultScaleWhenAlreadyLegible); | 1121 scale = max(scale, defaultScaleWhenAlreadyLegible); |
1121 scale = clampPageScaleFactorToLimits(scale); | 1122 scale = clampPageScaleFactorToLimits(scale); |
1122 } | 1123 } |
1123 | 1124 |
1124 // FIXME: If this is being called for auto zoom during find in page, | 1125 // FIXME: If this is being called for auto zoom during find in page, |
1125 // then if the user manually zooms in it'd be nice to preserve the | 1126 // then if the user manually zooms in it'd be nice to preserve the |
1126 // relative increase in zoom they caused (if they zoom out then it's ok | 1127 // relative increase in zoom they caused (if they zoom out then it's ok |
1127 // to zoom them back in again). This isn't compatible with our current | 1128 // to zoom them back in again). This isn't compatible with our current |
1128 // double-tap zoom strategy (fitting the containing block to the screen) | 1129 // double-tap zoom strategy (fitting the containing block to the screen) |
1129 // though. | 1130 // though. |
1130 | 1131 |
1131 float screenWidth = m_size.width / scale; | 1132 float screenWidth = m_size.width / scale; |
1132 float screenHeight = m_size.height / scale; | 1133 float screenHeight = m_size.height / scale; |
1133 | 1134 |
1134 // Scroll to vertically align the block. | 1135 // Scroll to vertically align the block. |
1135 if (rect.height < screenHeight) { | 1136 if (rect.height < screenHeight) { |
1136 // Vertically center short blocks. | 1137 // Vertically center short blocks. |
1137 rect.y -= 0.5 * (screenHeight - rect.height); | 1138 rect.y -= 0.5 * (screenHeight - rect.height); |
1138 } else { | 1139 } else { |
1139 // Ensure position we're zooming to (+ padding) isn't off the bottom of | 1140 // Ensure position we're zooming to (+ padding) isn't off the bottom of |
1140 // the screen. | 1141 // the screen. |
1141 rect.y = std::max<float>(rect.y, hitPoint.y + padding - screenHeight); | 1142 rect.y = max<float>(rect.y, hitPoint.y + padding - screenHeight); |
1142 } // Otherwise top align the block. | 1143 } // Otherwise top align the block. |
1143 | 1144 |
1144 // Do the same thing for horizontal alignment. | 1145 // Do the same thing for horizontal alignment. |
1145 if (rect.width < screenWidth) | 1146 if (rect.width < screenWidth) |
1146 rect.x -= 0.5 * (screenWidth - rect.width); | 1147 rect.x -= 0.5 * (screenWidth - rect.width); |
1147 else | 1148 else |
1148 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); | 1149 rect.x = max<float>(rect.x, hitPoint.x + padding - screenWidth); |
1149 scroll.x = rect.x; | 1150 scroll.x = rect.x; |
1150 scroll.y = rect.y; | 1151 scroll.y = rect.y; |
1151 | 1152 |
1152 scale = clampPageScaleFactorToLimits(scale); | 1153 scale = clampPageScaleFactorToLimits(scale); |
1153 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); | 1154 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); |
1154 scroll = clampOffsetAtScale(scroll, scale); | 1155 scroll = clampOffsetAtScale(scroll, scale); |
1155 } | 1156 } |
1156 | 1157 |
1157 static bool invokesHandCursor(Node* node, LocalFrame* frame) | 1158 static bool invokesHandCursor(Node* node, LocalFrame* frame) |
1158 { | 1159 { |
(...skipping 1439 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2598 | 2599 |
2599 int viewWidth = m_size.width / newScale; | 2600 int viewWidth = m_size.width / newScale; |
2600 int viewHeight = m_size.height / newScale; | 2601 int viewHeight = m_size.height / newScale; |
2601 | 2602 |
2602 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { | 2603 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { |
2603 // Field is narrower than screen. Try to leave padding on left so field'
s | 2604 // Field is narrower than screen. Try to leave padding on left so field'
s |
2604 // label is visible, but it's more important to ensure entire field is | 2605 // label is visible, but it's more important to ensure entire field is |
2605 // onscreen. | 2606 // onscreen. |
2606 int idealLeftPadding = viewWidth * leftBoxRatio; | 2607 int idealLeftPadding = viewWidth * leftBoxRatio; |
2607 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); | 2608 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); |
2608 newScroll.setX(textboxRectInDocumentCoordinates.x() - std::min<int>(idea
lLeftPadding, maxLeftPaddingKeepingBoxOnscreen)); | 2609 newScroll.setX(textboxRectInDocumentCoordinates.x() - min<int>(idealLeft
Padding, maxLeftPaddingKeepingBoxOnscreen)); |
2609 } else { | 2610 } else { |
2610 // Field is wider than screen. Try to left-align field, unless caret wou
ld | 2611 // Field is wider than screen. Try to left-align field, unless caret wou
ld |
2611 // be offscreen, in which case right-align the caret. | 2612 // be offscreen, in which case right-align the caret. |
2612 newScroll.setX(std::max<int>(textboxRectInDocumentCoordinates.x(), caret
InDocumentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding -
viewWidth)); | 2613 newScroll.setX(max<int>(textboxRectInDocumentCoordinates.x(), caretInDoc
umentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding - viewW
idth)); |
2613 } | 2614 } |
2614 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { | 2615 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { |
2615 // Field is shorter than screen. Vertically center it. | 2616 // Field is shorter than screen. Vertically center it. |
2616 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); | 2617 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); |
2617 } else { | 2618 } else { |
2618 // Field is taller than screen. Try to top align field, unless caret wou
ld | 2619 // Field is taller than screen. Try to top align field, unless caret wou
ld |
2619 // be offscreen, in which case bottom-align the caret. | 2620 // be offscreen, in which case bottom-align the caret. |
2620 newScroll.setY(std::max<int>(textboxRectInDocumentCoordinates.y(), caret
InDocumentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding -
viewHeight)); | 2621 newScroll.setY(max<int>(textboxRectInDocumentCoordinates.y(), caretInDoc
umentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding - view
Height)); |
2621 } | 2622 } |
2622 | 2623 |
2623 needAnimation = false; | 2624 needAnimation = false; |
2624 // If we are at less than the target zoom level, zoom in. | 2625 // If we are at less than the target zoom level, zoom in. |
2625 if (deltaScale > minScaleChangeToTriggerZoom) | 2626 if (deltaScale > minScaleChangeToTriggerZoom) |
2626 needAnimation = true; | 2627 needAnimation = true; |
2627 // If the caret is offscreen, then animate. | 2628 // If the caret is offscreen, then animate. |
2628 IntRect sizeRect(0, 0, viewWidth, viewHeight); | 2629 IntRect sizeRect(0, 0, viewWidth, viewHeight); |
2629 if (!sizeRect.contains(caret)) | 2630 if (!sizeRect.contains(caret)) |
2630 needAnimation = true; | 2631 needAnimation = true; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2687 frame->setTextZoomFactor(textZoomFactor); | 2688 frame->setTextZoomFactor(textZoomFactor); |
2688 | 2689 |
2689 return textZoomFactor; | 2690 return textZoomFactor; |
2690 } | 2691 } |
2691 | 2692 |
2692 void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel) | 2693 void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel) |
2693 { | 2694 { |
2694 if (zoomLevel == m_zoomLevel) | 2695 if (zoomLevel == m_zoomLevel) |
2695 return; | 2696 return; |
2696 | 2697 |
2697 m_zoomLevel = std::max(std::min(zoomLevel, m_maximumZoomLevel), m_minimumZoo
mLevel); | 2698 m_zoomLevel = max(min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel); |
2698 m_client->zoomLevelChanged(); | 2699 m_client->zoomLevelChanged(); |
2699 } | 2700 } |
2700 | 2701 |
2701 double WebView::zoomLevelToZoomFactor(double zoomLevel) | 2702 double WebView::zoomLevelToZoomFactor(double zoomLevel) |
2702 { | 2703 { |
2703 return pow(textSizeMultiplierRatio, zoomLevel); | 2704 return pow(textSizeMultiplierRatio, zoomLevel); |
2704 } | 2705 } |
2705 | 2706 |
2706 double WebView::zoomFactorToZoomLevel(double factor) | 2707 double WebView::zoomFactorToZoomLevel(double factor) |
2707 { | 2708 { |
(...skipping 1395 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4103 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4104 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4104 | 4105 |
4105 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4106 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4106 return false; | 4107 return false; |
4107 | 4108 |
4108 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4109 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4109 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4110 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4110 } | 4111 } |
4111 | 4112 |
4112 } // namespace blink | 4113 } // namespace blink |
OLD | NEW |