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 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 #if USE(DEFAULT_RENDER_THEME) | 156 #if USE(DEFAULT_RENDER_THEME) |
157 #include "core/rendering/RenderThemeChromiumDefault.h" | 157 #include "core/rendering/RenderThemeChromiumDefault.h" |
158 #endif | 158 #endif |
159 | 159 |
160 // Get rid of WTF's pow define so we can use std::pow. | 160 // Get rid of WTF's pow define so we can use std::pow. |
161 #undef pow | 161 #undef pow |
162 #include <cmath> // for std::pow | 162 #include <cmath> // for std::pow |
163 | 163 |
164 using namespace WebCore; | 164 using namespace WebCore; |
165 using namespace std; | |
166 | 165 |
167 // The following constants control parameters for automated scaling of webpages | 166 // The following constants control parameters for automated scaling of webpages |
168 // (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 |
169 // experimentally determined. | 168 // experimentally determined. |
170 static const int touchPointPadding = 32; | 169 static const int touchPointPadding = 32; |
171 static const int nonUserInitiatedPointPadding = 11; | 170 static const int nonUserInitiatedPointPadding = 11; |
172 static const float minScaleDifference = 0.01f; | 171 static const float minScaleDifference = 0.01f; |
173 static const float doubleTapZoomContentDefaultMargin = 5; | 172 static const float doubleTapZoomContentDefaultMargin = 5; |
174 static const float doubleTapZoomContentMinimumMargin = 2; | 173 static const float doubleTapZoomContentMinimumMargin = 2; |
175 static const double doubleTapZoomAnimationDurationInSeconds = 0.25; | 174 static const double doubleTapZoomAnimationDurationInSeconds = 0.25; |
(...skipping 886 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1062 maxSize = mainFrame()->contentsSize(); | 1061 maxSize = mainFrame()->contentsSize(); |
1063 IntSize scrollOffset; | 1062 IntSize scrollOffset; |
1064 if (mainFrame()) | 1063 if (mainFrame()) |
1065 scrollOffset = mainFrame()->scrollOffset(); | 1064 scrollOffset = mainFrame()->scrollOffset(); |
1066 int leftMargin = targetMargin; | 1065 int leftMargin = targetMargin; |
1067 int rightMargin = targetMargin; | 1066 int rightMargin = targetMargin; |
1068 | 1067 |
1069 const int absoluteSourceX = source.x + scrollOffset.width(); | 1068 const int absoluteSourceX = source.x + scrollOffset.width(); |
1070 if (leftMargin > absoluteSourceX) { | 1069 if (leftMargin > absoluteSourceX) { |
1071 leftMargin = absoluteSourceX; | 1070 leftMargin = absoluteSourceX; |
1072 rightMargin = max(leftMargin, minimumMargin); | 1071 rightMargin = std::max(leftMargin, minimumMargin); |
1073 } | 1072 } |
1074 | 1073 |
1075 const int maximumRightMargin = maxSize.width - (source.width + absoluteSourc
eX); | 1074 const int maximumRightMargin = maxSize.width - (source.width + absoluteSourc
eX); |
1076 if (rightMargin > maximumRightMargin) { | 1075 if (rightMargin > maximumRightMargin) { |
1077 rightMargin = maximumRightMargin; | 1076 rightMargin = maximumRightMargin; |
1078 leftMargin = min(leftMargin, max(rightMargin, minimumMargin)); | 1077 leftMargin = std::min(leftMargin, std::max(rightMargin, minimumMargin)); |
1079 } | 1078 } |
1080 | 1079 |
1081 const int newWidth = source.width + leftMargin + rightMargin; | 1080 const int newWidth = source.width + leftMargin + rightMargin; |
1082 const int newX = source.x - leftMargin; | 1081 const int newX = source.x - leftMargin; |
1083 | 1082 |
1084 ASSERT(newWidth >= 0); | 1083 ASSERT(newWidth >= 0); |
1085 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); | 1084 ASSERT(scrollOffset.width() + newX + newWidth <= maxSize.width); |
1086 | 1085 |
1087 return WebRect(newX, source.y, newWidth, source.height); | 1086 return WebRect(newX, source.y, newWidth, source.height); |
1088 } | 1087 } |
(...skipping 24 matching lines...) Expand all Loading... |
1113 // need to express them in post-scale size. To do that we'd need to know | 1112 // need to express them in post-scale size. To do that we'd need to know |
1114 // the scale we're scaling to, but that depends on the margins. Instead | 1113 // the scale we're scaling to, but that depends on the margins. Instead |
1115 // we express them as a fraction of the target rectangle: this will be | 1114 // we express them as a fraction of the target rectangle: this will be |
1116 // correct if we end up fully zooming to it, and won't matter if we | 1115 // correct if we end up fully zooming to it, and won't matter if we |
1117 // don't. | 1116 // don't. |
1118 rect = widenRectWithinPageBounds(rect, | 1117 rect = widenRectWithinPageBounds(rect, |
1119 static_cast<int>(defaultMargin * rect.width / m_size.width), | 1118 static_cast<int>(defaultMargin * rect.width / m_size.width), |
1120 static_cast<int>(minimumMargin * rect.width / m_size.width)); | 1119 static_cast<int>(minimumMargin * rect.width / m_size.width)); |
1121 // Fit block to screen, respecting limits. | 1120 // Fit block to screen, respecting limits. |
1122 scale = static_cast<float>(m_size.width) / rect.width; | 1121 scale = static_cast<float>(m_size.width) / rect.width; |
1123 scale = min(scale, legibleScale()); | 1122 scale = std::min(scale, legibleScale()); |
1124 if (pageScaleFactor() < defaultScaleWhenAlreadyLegible) | 1123 if (pageScaleFactor() < defaultScaleWhenAlreadyLegible) |
1125 scale = max(scale, defaultScaleWhenAlreadyLegible); | 1124 scale = std::max(scale, defaultScaleWhenAlreadyLegible); |
1126 scale = clampPageScaleFactorToLimits(scale); | 1125 scale = clampPageScaleFactorToLimits(scale); |
1127 } | 1126 } |
1128 | 1127 |
1129 // FIXME: If this is being called for auto zoom during find in page, | 1128 // FIXME: If this is being called for auto zoom during find in page, |
1130 // then if the user manually zooms in it'd be nice to preserve the | 1129 // then if the user manually zooms in it'd be nice to preserve the |
1131 // relative increase in zoom they caused (if they zoom out then it's ok | 1130 // relative increase in zoom they caused (if they zoom out then it's ok |
1132 // to zoom them back in again). This isn't compatible with our current | 1131 // to zoom them back in again). This isn't compatible with our current |
1133 // double-tap zoom strategy (fitting the containing block to the screen) | 1132 // double-tap zoom strategy (fitting the containing block to the screen) |
1134 // though. | 1133 // though. |
1135 | 1134 |
1136 float screenWidth = m_size.width / scale; | 1135 float screenWidth = m_size.width / scale; |
1137 float screenHeight = m_size.height / scale; | 1136 float screenHeight = m_size.height / scale; |
1138 | 1137 |
1139 // Scroll to vertically align the block. | 1138 // Scroll to vertically align the block. |
1140 if (rect.height < screenHeight) { | 1139 if (rect.height < screenHeight) { |
1141 // Vertically center short blocks. | 1140 // Vertically center short blocks. |
1142 rect.y -= 0.5 * (screenHeight - rect.height); | 1141 rect.y -= 0.5 * (screenHeight - rect.height); |
1143 } else { | 1142 } else { |
1144 // Ensure position we're zooming to (+ padding) isn't off the bottom of | 1143 // Ensure position we're zooming to (+ padding) isn't off the bottom of |
1145 // the screen. | 1144 // the screen. |
1146 rect.y = max<float>(rect.y, hitPoint.y + padding - screenHeight); | 1145 rect.y = std::max<float>(rect.y, hitPoint.y + padding - screenHeight); |
1147 } // Otherwise top align the block. | 1146 } // Otherwise top align the block. |
1148 | 1147 |
1149 // Do the same thing for horizontal alignment. | 1148 // Do the same thing for horizontal alignment. |
1150 if (rect.width < screenWidth) | 1149 if (rect.width < screenWidth) |
1151 rect.x -= 0.5 * (screenWidth - rect.width); | 1150 rect.x -= 0.5 * (screenWidth - rect.width); |
1152 else | 1151 else |
1153 rect.x = max<float>(rect.x, hitPoint.x + padding - screenWidth); | 1152 rect.x = std::max<float>(rect.x, hitPoint.x + padding - screenWidth); |
1154 scroll.x = rect.x; | 1153 scroll.x = rect.x; |
1155 scroll.y = rect.y; | 1154 scroll.y = rect.y; |
1156 | 1155 |
1157 scale = clampPageScaleFactorToLimits(scale); | 1156 scale = clampPageScaleFactorToLimits(scale); |
1158 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); | 1157 scroll = mainFrameImpl()->frameView()->windowToContents(scroll); |
1159 scroll = clampOffsetAtScale(scroll, scale); | 1158 scroll = clampOffsetAtScale(scroll, scale); |
1160 } | 1159 } |
1161 | 1160 |
1162 static bool invokesHandCursor(Node* node, LocalFrame* frame) | 1161 static bool invokesHandCursor(Node* node, LocalFrame* frame) |
1163 { | 1162 { |
(...skipping 1457 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2621 | 2620 |
2622 int viewWidth = m_size.width / newScale; | 2621 int viewWidth = m_size.width / newScale; |
2623 int viewHeight = m_size.height / newScale; | 2622 int viewHeight = m_size.height / newScale; |
2624 | 2623 |
2625 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { | 2624 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { |
2626 // Field is narrower than screen. Try to leave padding on left so field'
s | 2625 // Field is narrower than screen. Try to leave padding on left so field'
s |
2627 // label is visible, but it's more important to ensure entire field is | 2626 // label is visible, but it's more important to ensure entire field is |
2628 // onscreen. | 2627 // onscreen. |
2629 int idealLeftPadding = viewWidth * leftBoxRatio; | 2628 int idealLeftPadding = viewWidth * leftBoxRatio; |
2630 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); | 2629 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); |
2631 newScroll.setX(textboxRectInDocumentCoordinates.x() - min<int>(idealLeft
Padding, maxLeftPaddingKeepingBoxOnscreen)); | 2630 newScroll.setX(textboxRectInDocumentCoordinates.x() - std::min<int>(idea
lLeftPadding, maxLeftPaddingKeepingBoxOnscreen)); |
2632 } else { | 2631 } else { |
2633 // Field is wider than screen. Try to left-align field, unless caret wou
ld | 2632 // Field is wider than screen. Try to left-align field, unless caret wou
ld |
2634 // be offscreen, in which case right-align the caret. | 2633 // be offscreen, in which case right-align the caret. |
2635 newScroll.setX(max<int>(textboxRectInDocumentCoordinates.x(), caretInDoc
umentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding - viewW
idth)); | 2634 newScroll.setX(std::max<int>(textboxRectInDocumentCoordinates.x(), caret
InDocumentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding -
viewWidth)); |
2636 } | 2635 } |
2637 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { | 2636 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { |
2638 // Field is shorter than screen. Vertically center it. | 2637 // Field is shorter than screen. Vertically center it. |
2639 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); | 2638 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); |
2640 } else { | 2639 } else { |
2641 // Field is taller than screen. Try to top align field, unless caret wou
ld | 2640 // Field is taller than screen. Try to top align field, unless caret wou
ld |
2642 // be offscreen, in which case bottom-align the caret. | 2641 // be offscreen, in which case bottom-align the caret. |
2643 newScroll.setY(max<int>(textboxRectInDocumentCoordinates.y(), caretInDoc
umentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding - view
Height)); | 2642 newScroll.setY(std::max<int>(textboxRectInDocumentCoordinates.y(), caret
InDocumentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding -
viewHeight)); |
2644 } | 2643 } |
2645 | 2644 |
2646 needAnimation = false; | 2645 needAnimation = false; |
2647 // If we are at less than the target zoom level, zoom in. | 2646 // If we are at less than the target zoom level, zoom in. |
2648 if (deltaScale > minScaleChangeToTriggerZoom) | 2647 if (deltaScale > minScaleChangeToTriggerZoom) |
2649 needAnimation = true; | 2648 needAnimation = true; |
2650 // If the caret is offscreen, then animate. | 2649 // If the caret is offscreen, then animate. |
2651 IntRect sizeRect(0, 0, viewWidth, viewHeight); | 2650 IntRect sizeRect(0, 0, viewWidth, viewHeight); |
2652 if (!sizeRect.contains(caret)) | 2651 if (!sizeRect.contains(caret)) |
2653 needAnimation = true; | 2652 needAnimation = true; |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2710 frame->setTextZoomFactor(textZoomFactor); | 2709 frame->setTextZoomFactor(textZoomFactor); |
2711 | 2710 |
2712 return textZoomFactor; | 2711 return textZoomFactor; |
2713 } | 2712 } |
2714 | 2713 |
2715 void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel) | 2714 void WebViewImpl::fullFramePluginZoomLevelChanged(double zoomLevel) |
2716 { | 2715 { |
2717 if (zoomLevel == m_zoomLevel) | 2716 if (zoomLevel == m_zoomLevel) |
2718 return; | 2717 return; |
2719 | 2718 |
2720 m_zoomLevel = max(min(zoomLevel, m_maximumZoomLevel), m_minimumZoomLevel); | 2719 m_zoomLevel = std::max(std::min(zoomLevel, m_maximumZoomLevel), m_minimumZoo
mLevel); |
2721 m_client->zoomLevelChanged(); | 2720 m_client->zoomLevelChanged(); |
2722 } | 2721 } |
2723 | 2722 |
2724 double WebView::zoomLevelToZoomFactor(double zoomLevel) | 2723 double WebView::zoomLevelToZoomFactor(double zoomLevel) |
2725 { | 2724 { |
2726 return pow(textSizeMultiplierRatio, zoomLevel); | 2725 return pow(textSizeMultiplierRatio, zoomLevel); |
2727 } | 2726 } |
2728 | 2727 |
2729 double WebView::zoomFactorToZoomLevel(double factor) | 2728 double WebView::zoomFactorToZoomLevel(double factor) |
2730 { | 2729 { |
(...skipping 1412 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4143 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); | 4142 const PageScaleConstraints& constraints = m_pageScaleConstraintsSet.pageDefi
nedConstraints(); |
4144 | 4143 |
4145 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) | 4144 if (!mainFrameImpl() || !mainFrameImpl()->frameView()) |
4146 return false; | 4145 return false; |
4147 | 4146 |
4148 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4147 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
4149 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4148 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
4150 } | 4149 } |
4151 | 4150 |
4152 } // namespace blink | 4151 } // namespace blink |
OLD | NEW |