Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(410)

Side by Side Diff: Source/WebKit/chromium/src/WebViewImpl.cpp

Issue 13704012: Improve mobile device rotation behavior. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixing rebase and nits Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
65 #include "GeolocationClientProxy.h" 65 #include "GeolocationClientProxy.h"
66 #include "GeolocationController.h" 66 #include "GeolocationController.h"
67 #include "GraphicsContext.h" 67 #include "GraphicsContext.h"
68 #include "GraphicsContext3D.h" 68 #include "GraphicsContext3D.h"
69 #include "GraphicsContext3DPrivate.h" 69 #include "GraphicsContext3DPrivate.h"
70 #include "GraphicsLayerFactoryChromium.h" 70 #include "GraphicsLayerFactoryChromium.h"
71 #include "HTMLInputElement.h" 71 #include "HTMLInputElement.h"
72 #include "HTMLMediaElement.h" 72 #include "HTMLMediaElement.h"
73 #include "HTMLNames.h" 73 #include "HTMLNames.h"
74 #include "HTMLTextAreaElement.h" 74 #include "HTMLTextAreaElement.h"
75 #include "HitTestResult.h"
76 #include "Image.h" 75 #include "Image.h"
77 #include "ImageBuffer.h" 76 #include "ImageBuffer.h"
78 #include "InspectorController.h" 77 #include "InspectorController.h"
79 #include "InspectorInstrumentation.h" 78 #include "InspectorInstrumentation.h"
80 #include "KeyboardCodes.h" 79 #include "KeyboardCodes.h"
81 #include "KeyboardEvent.h" 80 #include "KeyboardEvent.h"
82 #include "LayerPainterChromium.h" 81 #include "LayerPainterChromium.h"
83 #include "LinkHighlight.h" 82 #include "LinkHighlight.h"
84 #include "MIMETypeRegistry.h" 83 #include "MIMETypeRegistry.h"
85 #include "NodeRenderStyle.h" 84 #include "NodeRenderStyle.h"
(...skipping 25 matching lines...) Expand all
111 #include "SpeechInputClientImpl.h" 110 #include "SpeechInputClientImpl.h"
112 #include "SpeechRecognitionClientProxy.h" 111 #include "SpeechRecognitionClientProxy.h"
113 #include "StyleResolver.h" 112 #include "StyleResolver.h"
114 #include "Text.h" 113 #include "Text.h"
115 #include "TextFieldDecoratorImpl.h" 114 #include "TextFieldDecoratorImpl.h"
116 #include "TextIterator.h" 115 #include "TextIterator.h"
117 #include "Timer.h" 116 #include "Timer.h"
118 #include "TouchDisambiguation.h" 117 #include "TouchDisambiguation.h"
119 #include "TraceEvent.h" 118 #include "TraceEvent.h"
120 #include "ValidationMessageClientImpl.h" 119 #include "ValidationMessageClientImpl.h"
120 #include "ViewportAnchor.h"
121 #include "WebAccessibilityObject.h" 121 #include "WebAccessibilityObject.h"
122 #include "WebActiveWheelFlingParameters.h" 122 #include "WebActiveWheelFlingParameters.h"
123 #include "WebAutofillClient.h" 123 #include "WebAutofillClient.h"
124 #include "WebCompositorInputHandlerImpl.h" 124 #include "WebCompositorInputHandlerImpl.h"
125 #include "WebDevToolsAgentImpl.h" 125 #include "WebDevToolsAgentImpl.h"
126 #include "WebDevToolsAgentPrivate.h" 126 #include "WebDevToolsAgentPrivate.h"
127 #include "WebFrameImpl.h" 127 #include "WebFrameImpl.h"
128 #include "WebHelperPluginImpl.h" 128 #include "WebHelperPluginImpl.h"
129 #include "WebHitTestResult.h" 129 #include "WebHitTestResult.h"
130 #include "WebInputElement.h" 130 #include "WebInputElement.h"
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
189 // (such as due to a double tap gesture or find in page etc.). These are 189 // (such as due to a double tap gesture or find in page etc.). These are
190 // experimentally determined. 190 // experimentally determined.
191 static const int touchPointPadding = 32; 191 static const int touchPointPadding = 32;
192 static const int nonUserInitiatedPointPadding = 11; 192 static const int nonUserInitiatedPointPadding = 11;
193 static const float minScaleDifference = 0.01f; 193 static const float minScaleDifference = 0.01f;
194 static const float doubleTapZoomContentDefaultMargin = 5; 194 static const float doubleTapZoomContentDefaultMargin = 5;
195 static const float doubleTapZoomContentMinimumMargin = 2; 195 static const float doubleTapZoomContentMinimumMargin = 2;
196 static const double doubleTapZoomAnimationDurationInSeconds = 0.25; 196 static const double doubleTapZoomAnimationDurationInSeconds = 0.25;
197 static const float doubleTapZoomAlreadyLegibleRatio = 1.2f; 197 static const float doubleTapZoomAlreadyLegibleRatio = 1.2f;
198 198
199 // Constants for viewport anchoring on resize.
200 static const float viewportAnchorXCoord = 0.5f;
201 static const float viewportAnchorYCoord = 0;
202
199 // Constants for zooming in on a focused text field. 203 // Constants for zooming in on a focused text field.
200 static const double scrollAndScaleAnimationDurationInSeconds = 0.2; 204 static const double scrollAndScaleAnimationDurationInSeconds = 0.2;
201 static const int minReadableCaretHeight = 18; 205 static const int minReadableCaretHeight = 18;
202 static const float minScaleChangeToTriggerZoom = 1.05f; 206 static const float minScaleChangeToTriggerZoom = 1.05f;
203 static const float leftBoxRatio = 0.3f; 207 static const float leftBoxRatio = 0.3f;
204 static const int caretPadding = 10; 208 static const int caretPadding = 10;
205 209
206 namespace WebKit { 210 namespace WebKit {
207 211
208 // Change the text zoom level by kTextSizeMultiplierRatio each time the user 212 // Change the text zoom level by kTextSizeMultiplierRatio each time the user
(...skipping 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 { 1650 {
1647 if (m_shouldAutoResize || m_size == newSize) 1651 if (m_shouldAutoResize || m_size == newSize)
1648 return; 1652 return;
1649 1653
1650 FrameView* view = mainFrameImpl()->frameView(); 1654 FrameView* view = mainFrameImpl()->frameView();
1651 if (!view) 1655 if (!view)
1652 return; 1656 return;
1653 1657
1654 WebSize oldSize = m_size; 1658 WebSize oldSize = m_size;
1655 float oldPageScaleFactor = pageScaleFactor(); 1659 float oldPageScaleFactor = pageScaleFactor();
1656 IntSize oldScrollOffset = view->scrollOffset(); 1660 int oldContentsWidth = contentsSize().width();
1657 int oldFixedLayoutWidth = fixedLayoutSize().width;
1658 1661
1659 m_size = newSize; 1662 m_size = newSize;
1660 1663
1661 #if ENABLE(VIEWPORT) 1664 #if ENABLE(VIEWPORT)
1665 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth;
1666 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
1667 if (shouldAnchorAndRescaleViewport)
abarth-chromium 2013/04/18 05:33:04 Multiline if statements request { } even if they c
jdduke (slow) 2013/04/18 16:20:07 Done.
1668 viewportAnchor.setAnchor(view->visibleContentRect(),
1669 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord));
1670
1662 ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()-> viewportArguments(); 1671 ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()-> viewportArguments();
1663 m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArgu ments); 1672 m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArgu ments);
1664 #endif 1673 #endif
1665 1674
1666 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); 1675 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
1667 if (agentPrivate) 1676 if (agentPrivate)
1668 agentPrivate->webViewResized(newSize); 1677 agentPrivate->webViewResized(newSize);
1669 if (!agentPrivate || !agentPrivate->metricsOverridden()) { 1678 if (!agentPrivate || !agentPrivate->metricsOverridden()) {
1670 WebFrameImpl* webFrame = mainFrameImpl(); 1679 WebFrameImpl* webFrame = mainFrameImpl();
1671 if (webFrame->frameView()) 1680 if (webFrame->frameView())
1672 webFrame->frameView()->resize(m_size); 1681 webFrame->frameView()->resize(m_size);
1673 } 1682 }
1674 1683
1675 #if ENABLE(VIEWPORT) 1684 #if ENABLE(VIEWPORT)
1676 if (settings()->viewportEnabled()) { 1685 if (settings()->viewportEnabled()) {
1677 // Relayout immediately to recalculate the minimum scale limit. 1686 // Relayout immediately to recalculate the minimum scale limit.
1678 if (view->needsLayout()) 1687 if (view->needsLayout())
1679 view->layout(); 1688 view->layout();
1680 1689
1681 // When the device rotates: 1690 if (shouldAnchorAndRescaleViewport) {
1682 // - If the page width is unchanged, then zoom by new width/old width 1691 float viewportWidthRatio = static_cast<float>(newSize.width) / oldSi ze.width;
1683 // such as to keep the same content horizontally onscreen. 1692 float contentsWidthRatio = static_cast<float>(contentsSize().width() ) / oldContentsWidth;
1684 // - If the page width stretches proportionally to the change in 1693 float scaleMultiplier = viewportWidthRatio / contentsWidthRatio;
1685 // screen width, then don't zoom at all (assuming the content has 1694
1686 // scaled uniformly, then the same content will be horizontally 1695 IntSize viewportSize = view->visibleContentRect().size();
1687 // onscreen). 1696 if (scaleMultiplier != 1) {
1688 // - If the page width partially stretches, then zoom partially to 1697 float newPageScaleFactor = oldPageScaleFactor * scaleMultiplier;
1689 // make up the difference. 1698 viewportSize.scale(pageScaleFactor() / newPageScaleFactor);
1690 // In all cases try to keep the same content at the top of the screen. 1699 IntPoint scrollOffsetAtNewScale = viewportAnchor.computeOrigin(v iewportSize);
1691 float viewportWidthRatio = !oldSize.width ? 1 : newSize.width / (float) oldSize.width; 1700 setPageScaleFactor(newPageScaleFactor, scrollOffsetAtNewScale);
1692 float fixedLayoutWidthRatio = !oldFixedLayoutWidth ? 1 : fixedLayoutSize ().width / (float) oldFixedLayoutWidth; 1701 } else {
1693 float scaleMultiplier = viewportWidthRatio / fixedLayoutWidthRatio; 1702 IntPoint scrollOffsetAtNewScale = clampOffsetAtScale(viewportAnc hor.computeOrigin(viewportSize), pageScaleFactor());
1694 if (scaleMultiplier != 1) 1703 updateMainFrameScrollPosition(scrollOffsetAtNewScale, false);
1695 setPageScaleFactor(oldPageScaleFactor * scaleMultiplier, WebPoint(ol dScrollOffset.width(), oldScrollOffset.height())); 1704 }
1705 }
1696 } 1706 }
1697 #endif 1707 #endif
1698 1708
1699 sendResizeEventAndRepaint(); 1709 sendResizeEventAndRepaint();
1700 } 1710 }
1701 1711
1702 void WebViewImpl::willEndLiveResize() 1712 void WebViewImpl::willEndLiveResize()
1703 { 1713 {
1704 if (mainFrameImpl() && mainFrameImpl()->frameView()) 1714 if (mainFrameImpl() && mainFrameImpl()->frameView())
1705 mainFrameImpl()->frameView()->willEndLiveResize(); 1715 mainFrameImpl()->frameView()->willEndLiveResize();
(...skipping 2490 matching lines...) Expand 10 before | Expand all | Expand 10 after
4196 } 4206 }
4197 4207
4198 bool WebViewImpl::shouldDisableDesktopWorkarounds() 4208 bool WebViewImpl::shouldDisableDesktopWorkarounds()
4199 { 4209 {
4200 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); 4210 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments();
4201 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom 4211 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom
4202 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); 4212 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto);
4203 } 4213 }
4204 4214
4205 } // namespace WebKit 4215 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698