| 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 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 | 188 |
| 189 static const double multipleTargetsZoomAnimationDurationInSeconds = 0.25; | 189 static const double multipleTargetsZoomAnimationDurationInSeconds = 0.25; |
| 190 static const double findInPageAnimationDurationInSeconds = 0; | 190 static const double findInPageAnimationDurationInSeconds = 0; |
| 191 | 191 |
| 192 // Constants for viewport anchoring on resize. | 192 // Constants for viewport anchoring on resize. |
| 193 static const float viewportAnchorXCoord = 0.5f; | 193 static const float viewportAnchorXCoord = 0.5f; |
| 194 static const float viewportAnchorYCoord = 0; | 194 static const float viewportAnchorYCoord = 0; |
| 195 | 195 |
| 196 // Constants for zooming in on a focused text field. | 196 // Constants for zooming in on a focused text field. |
| 197 static const double scrollAndScaleAnimationDurationInSeconds = 0.2; | 197 static const double scrollAndScaleAnimationDurationInSeconds = 0.2; |
| 198 static const int minReadableCaretHeight = 18; | 198 static const int minReadableCaretHeight = 16; |
| 199 static const float minScaleChangeToTriggerZoom = 1.05f; | 199 static const int minReadableCaretHeightForTextArea = 13; |
| 200 static const float minScaleChangeToTriggerZoom = 1.5f; |
| 200 static const float leftBoxRatio = 0.3f; | 201 static const float leftBoxRatio = 0.3f; |
| 201 static const int caretPadding = 10; | 202 static const int caretPadding = 10; |
| 202 | 203 |
| 203 namespace blink { | 204 namespace blink { |
| 204 | 205 |
| 205 // Change the text zoom level by kTextSizeMultiplierRatio each time the user | 206 // Change the text zoom level by kTextSizeMultiplierRatio each time the user |
| 206 // zooms text in or out (ie., change by 20%). The min and max values limit | 207 // zooms text in or out (ie., change by 20%). The min and max values limit |
| 207 // text zoom to half and 3x the original text size. These three values match | 208 // text zoom to half and 3x the original text size. These three values match |
| 208 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm | 209 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm |
| 209 const double WebView::textSizeMultiplierRatio = 1.2; | 210 const double WebView::textSizeMultiplierRatio = 1.2; |
| (...skipping 2640 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2850 focusedNode->document().updateLayoutIgnorePendingStylesheets(); | 2851 focusedNode->document().updateLayoutIgnorePendingStylesheets(); |
| 2851 | 2852 |
| 2852 // 'caret' is rect encompassing the blinking cursor. | 2853 // 'caret' is rect encompassing the blinking cursor. |
| 2853 IntRect textboxRect = focusedNode->document().view()->contentsToWindow(pixel
SnappedIntRect(focusedNode->Node::boundingBox())); | 2854 IntRect textboxRect = focusedNode->document().view()->contentsToWindow(pixel
SnappedIntRect(focusedNode->Node::boundingBox())); |
| 2854 WebRect caret, unusedEnd; | 2855 WebRect caret, unusedEnd; |
| 2855 selectionBounds(caret, unusedEnd); | 2856 selectionBounds(caret, unusedEnd); |
| 2856 IntRect unscaledCaret = caret; | 2857 IntRect unscaledCaret = caret; |
| 2857 unscaledCaret.scale(1 / pageScaleFactor()); | 2858 unscaledCaret.scale(1 / pageScaleFactor()); |
| 2858 caret = unscaledCaret; | 2859 caret = unscaledCaret; |
| 2859 | 2860 |
| 2860 // Pick a scale which is reasonably readable. This is the scale at which | 2861 if (shouldDisableDesktopWorkarounds()) { |
| 2861 // the caret height will become minReadableCaretHeight (adjusted for dpi | 2862 newScale = pageScaleFactor(); |
| 2862 // and font scale factor). | 2863 } else { |
| 2863 newScale = clampPageScaleFactorToLimits(legibleScale() * minReadableCaretHei
ght / caret.height); | 2864 // Pick a scale which is reasonably readable. This is the scale at which |
| 2864 newScale = std::max(newScale, pageScaleFactor()); | 2865 // the caret height will become minReadableCaretHeightForNode (adjusted |
| 2866 // for dpi and font scale factor). |
| 2867 const int minReadableCaretHeightForNode = textboxRect.height() >= 2 * ca
ret.height ? minReadableCaretHeightForTextArea : minReadableCaretHeight; |
| 2868 newScale = clampPageScaleFactorToLimits(legibleScale() * minReadableCare
tHeightForNode / caret.height); |
| 2869 newScale = std::max(newScale, pageScaleFactor()); |
| 2870 } |
| 2865 const float deltaScale = newScale / pageScaleFactor(); | 2871 const float deltaScale = newScale / pageScaleFactor(); |
| 2866 | 2872 |
| 2873 needAnimation = false; |
| 2874 // If we are at less than the target zoom level, zoom in. |
| 2875 if (deltaScale > minScaleChangeToTriggerZoom) |
| 2876 needAnimation = true; |
| 2877 else |
| 2878 newScale = pageScaleFactor(); |
| 2879 |
| 2867 // Convert the rects to absolute space in the new scale. | 2880 // Convert the rects to absolute space in the new scale. |
| 2868 IntRect textboxRectInDocumentCoordinates = textboxRect; | 2881 IntRect textboxRectInDocumentCoordinates = textboxRect; |
| 2869 textboxRectInDocumentCoordinates.move(mainFrame()->scrollOffset()); | 2882 textboxRectInDocumentCoordinates.move(mainFrame()->scrollOffset()); |
| 2870 IntRect caretInDocumentCoordinates = caret; | 2883 IntRect caretInDocumentCoordinates = caret; |
| 2871 caretInDocumentCoordinates.move(mainFrame()->scrollOffset()); | 2884 caretInDocumentCoordinates.move(mainFrame()->scrollOffset()); |
| 2872 | 2885 |
| 2873 int viewWidth = m_size.width / newScale; | 2886 int viewWidth = m_size.width / newScale; |
| 2874 int viewHeight = m_size.height / newScale; | 2887 int viewHeight = m_size.height / newScale; |
| 2875 | 2888 |
| 2889 // If the caret is offscreen, then animate. |
| 2890 IntRect sizeRect(0, 0, viewWidth, viewHeight); |
| 2891 sizeRect.scale(newScale / pageScaleFactor()); |
| 2892 if (!sizeRect.contains(caret)) |
| 2893 needAnimation = true; |
| 2894 |
| 2895 // If the box is partially offscreen and it's possible to bring it fully |
| 2896 // onscreen, then animate. |
| 2897 if (sizeRect.contains(textboxRectInDocumentCoordinates.width(), textboxRectI
nDocumentCoordinates.height()) && !sizeRect.contains(textboxRect)) |
| 2898 needAnimation = true; |
| 2899 |
| 2900 if (!needAnimation) |
| 2901 return; |
| 2902 |
| 2876 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { | 2903 if (textboxRectInDocumentCoordinates.width() <= viewWidth) { |
| 2877 // Field is narrower than screen. Try to leave padding on left so field'
s | 2904 // Field is narrower than screen. Try to leave padding on left so field'
s |
| 2878 // label is visible, but it's more important to ensure entire field is | 2905 // label is visible, but it's more important to ensure entire field is |
| 2879 // onscreen. | 2906 // onscreen. |
| 2880 int idealLeftPadding = viewWidth * leftBoxRatio; | 2907 int idealLeftPadding = viewWidth * leftBoxRatio; |
| 2881 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); | 2908 int maxLeftPaddingKeepingBoxOnscreen = viewWidth - textboxRectInDocument
Coordinates.width(); |
| 2882 newScroll.setX(textboxRectInDocumentCoordinates.x() - std::min<int>(idea
lLeftPadding, maxLeftPaddingKeepingBoxOnscreen)); | 2909 newScroll.setX(textboxRectInDocumentCoordinates.x() - std::min<int>(idea
lLeftPadding, maxLeftPaddingKeepingBoxOnscreen)); |
| 2883 } else { | 2910 } else { |
| 2884 // Field is wider than screen. Try to left-align field, unless caret wou
ld | 2911 // Field is wider than screen. Try to left-align field, unless caret wou
ld |
| 2885 // be offscreen, in which case right-align the caret. | 2912 // be offscreen, in which case right-align the caret. |
| 2886 newScroll.setX(std::max<int>(textboxRectInDocumentCoordinates.x(), caret
InDocumentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding -
viewWidth)); | 2913 newScroll.setX(std::max<int>(textboxRectInDocumentCoordinates.x(), caret
InDocumentCoordinates.x() + caretInDocumentCoordinates.width() + caretPadding -
viewWidth)); |
| 2887 } | 2914 } |
| 2888 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { | 2915 if (textboxRectInDocumentCoordinates.height() <= viewHeight) { |
| 2889 // Field is shorter than screen. Vertically center it. | 2916 // Field is shorter than screen. Vertically center it. |
| 2890 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); | 2917 newScroll.setY(textboxRectInDocumentCoordinates.y() - (viewHeight - text
boxRectInDocumentCoordinates.height()) / 2); |
| 2891 } else { | 2918 } else { |
| 2892 // Field is taller than screen. Try to top align field, unless caret wou
ld | 2919 // Field is taller than screen. Try to top align field, unless caret wou
ld |
| 2893 // be offscreen, in which case bottom-align the caret. | 2920 // be offscreen, in which case bottom-align the caret. |
| 2894 newScroll.setY(std::max<int>(textboxRectInDocumentCoordinates.y(), caret
InDocumentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding -
viewHeight)); | 2921 newScroll.setY(std::max<int>(textboxRectInDocumentCoordinates.y(), caret
InDocumentCoordinates.y() + caretInDocumentCoordinates.height() + caretPadding -
viewHeight)); |
| 2895 } | 2922 } |
| 2896 | |
| 2897 needAnimation = false; | |
| 2898 // If we are at less than the target zoom level, zoom in. | |
| 2899 if (deltaScale > minScaleChangeToTriggerZoom) | |
| 2900 needAnimation = true; | |
| 2901 // If the caret is offscreen, then animate. | |
| 2902 IntRect sizeRect(0, 0, viewWidth, viewHeight); | |
| 2903 sizeRect.scale(newScale / pageScaleFactor()); | |
| 2904 if (!sizeRect.contains(caret)) | |
| 2905 needAnimation = true; | |
| 2906 // If the box is partially offscreen and it's possible to bring it fully | |
| 2907 // onscreen, then animate. | |
| 2908 if (sizeRect.contains(textboxRectInDocumentCoordinates.width(), textboxRectI
nDocumentCoordinates.height()) && !sizeRect.contains(textboxRect)) | |
| 2909 needAnimation = true; | |
| 2910 } | 2923 } |
| 2911 | 2924 |
| 2912 void WebViewImpl::advanceFocus(bool reverse) | 2925 void WebViewImpl::advanceFocus(bool reverse) |
| 2913 { | 2926 { |
| 2914 page()->focusController().advanceFocus(reverse ? FocusTypeBackward : FocusTy
peForward); | 2927 page()->focusController().advanceFocus(reverse ? FocusTypeBackward : FocusTy
peForward); |
| 2915 } | 2928 } |
| 2916 | 2929 |
| 2917 double WebViewImpl::zoomLevel() | 2930 double WebViewImpl::zoomLevel() |
| 2918 { | 2931 { |
| 2919 return m_zoomLevel; | 2932 return m_zoomLevel; |
| (...skipping 1605 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4525 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width | 4538 return mainFrameImpl()->frameView()->layoutSize().width() == m_size.width |
| 4526 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); | 4539 || (constraints.minimumScale == constraints.maximumScale && constraints.
minimumScale != -1); |
| 4527 } | 4540 } |
| 4528 | 4541 |
| 4529 void WebViewImpl::forceNextWebGLContextCreationToFail() | 4542 void WebViewImpl::forceNextWebGLContextCreationToFail() |
| 4530 { | 4543 { |
| 4531 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); | 4544 WebGLRenderingContext::forceNextWebGLContextCreationToFail(); |
| 4532 } | 4545 } |
| 4533 | 4546 |
| 4534 } // namespace blink | 4547 } // namespace blink |
| OLD | NEW |