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

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

Issue 14813025: Refactor viewport initialization logic out of WebViewImpl. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Add tests for new behavior Created 7 years, 7 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 | Annotate | Revision Log
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 196 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 207
208 namespace WebKit { 208 namespace WebKit {
209 209
210 // Change the text zoom level by kTextSizeMultiplierRatio each time the user 210 // Change the text zoom level by kTextSizeMultiplierRatio each time the user
211 // zooms text in or out (ie., change by 20%). The min and max values limit 211 // zooms text in or out (ie., change by 20%). The min and max values limit
212 // text zoom to half and 3x the original text size. These three values match 212 // text zoom to half and 3x the original text size. These three values match
213 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm 213 // those in Apple's port in WebKit/WebKit/WebView/WebView.mm
214 const double WebView::textSizeMultiplierRatio = 1.2; 214 const double WebView::textSizeMultiplierRatio = 1.2;
215 const double WebView::minTextSizeMultiplier = 0.5; 215 const double WebView::minTextSizeMultiplier = 0.5;
216 const double WebView::maxTextSizeMultiplier = 3.0; 216 const double WebView::maxTextSizeMultiplier = 3.0;
217 const float WebView::minPageScaleFactor = 0.25f;
218 const float WebView::maxPageScaleFactor = 4.0f;
219 217
220 // Used to defer all page activity in cases where the embedder wishes to run 218 // Used to defer all page activity in cases where the embedder wishes to run
221 // a nested event loop. Using a stack enables nesting of message loop invocation s. 219 // a nested event loop. Using a stack enables nesting of message loop invocation s.
222 static Vector<PageGroupLoadDeferrer*>& pageGroupLoadDeferrerStack() 220 static Vector<PageGroupLoadDeferrer*>& pageGroupLoadDeferrerStack()
223 { 221 {
224 DEFINE_STATIC_LOCAL(Vector<PageGroupLoadDeferrer*>, deferrerStack, ()); 222 DEFINE_STATIC_LOCAL(Vector<PageGroupLoadDeferrer*>, deferrerStack, ());
225 return deferrerStack; 223 return deferrerStack;
226 } 224 }
227 225
228 // Ensure that the WebDragOperation enum values stay in sync with the original 226 // Ensure that the WebDragOperation enum values stay in sync with the original
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after
382 , m_inspectorClientImpl(this) 380 , m_inspectorClientImpl(this)
383 , m_backForwardClientImpl(this) 381 , m_backForwardClientImpl(this)
384 , m_shouldAutoResize(false) 382 , m_shouldAutoResize(false)
385 , m_observedNewNavigation(false) 383 , m_observedNewNavigation(false)
386 #ifndef NDEBUG 384 #ifndef NDEBUG
387 , m_newNavigationLoader(0) 385 , m_newNavigationLoader(0)
388 #endif 386 #endif
389 , m_zoomLevel(0) 387 , m_zoomLevel(0)
390 , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier)) 388 , m_minimumZoomLevel(zoomFactorToZoomLevel(minTextSizeMultiplier))
391 , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier)) 389 , m_maximumZoomLevel(zoomFactorToZoomLevel(maxTextSizeMultiplier))
392 , m_pageDefinedMinimumPageScaleFactor(-1)
393 , m_pageDefinedMaximumPageScaleFactor(-1)
394 , m_minimumPageScaleFactor(minPageScaleFactor)
395 , m_maximumPageScaleFactor(maxPageScaleFactor)
396 , m_initialPageScaleFactorOverride(-1)
397 , m_initialPageScaleFactor(-1)
398 , m_ignoreViewportTagMaximumScale(false)
399 , m_pageScaleFactorIsSet(false)
400 , m_savedPageScaleFactor(0) 390 , m_savedPageScaleFactor(0)
401 , m_doubleTapZoomPageScaleFactor(0) 391 , m_doubleTapZoomPageScaleFactor(0)
402 , m_doubleTapZoomPending(false) 392 , m_doubleTapZoomPending(false)
403 , m_enableFakeDoubleTapAnimationForTesting(false) 393 , m_enableFakeDoubleTapAnimationForTesting(false)
404 , m_fakeDoubleTapPageScaleFactor(0) 394 , m_fakeDoubleTapPageScaleFactor(0)
405 , m_fakeDoubleTapUseAnchor(false) 395 , m_fakeDoubleTapUseAnchor(false)
406 , m_contextMenuAllowed(false) 396 , m_contextMenuAllowed(false)
407 , m_doingDragAndDrop(false) 397 , m_doingDragAndDrop(false)
408 , m_ignoreInputEvents(false) 398 , m_ignoreInputEvents(false)
409 , m_suppressNextKeypressEvent(false) 399 , m_suppressNextKeypressEvent(false)
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 #if ENABLE(BATTERY_STATUS) 473 #if ENABLE(BATTERY_STATUS)
484 provideBatteryTo(m_page.get(), m_batteryClient.get()); 474 provideBatteryTo(m_page.get(), m_batteryClient.get());
485 m_batteryClient->setController(BatteryController::from(m_page.get())); 475 m_batteryClient->setController(BatteryController::from(m_page.get()));
486 #endif 476 #endif
487 477
488 m_page->setGroupType(Page::SharedPageGroup); 478 m_page->setGroupType(Page::SharedPageGroup);
489 479
490 unsigned layoutMilestones = DidFirstLayout | DidFirstVisuallyNonEmptyLayout; 480 unsigned layoutMilestones = DidFirstLayout | DidFirstVisuallyNonEmptyLayout;
491 m_page->addLayoutMilestones(static_cast<LayoutMilestones>(layoutMilestones)) ; 481 m_page->addLayoutMilestones(static_cast<LayoutMilestones>(layoutMilestones)) ;
492 482
493 if (m_client) 483 if (m_client) {
484 setDeviceScaleFactor(m_client->screenInfo().deviceScaleFactor);
dshwang 2013/05/13 12:38:01 Could you explain what this code results?
aelias_OOO_until_Jul13 2013/05/13 18:13:06 This setDeviceScaleFactor() call previously happen
494 setVisibilityState(m_client->visibilityState(), true); 485 setVisibilityState(m_client->visibilityState(), true);
486 }
495 487
496 m_inspectorSettingsMap = adoptPtr(new SettingsMap); 488 m_inspectorSettingsMap = adoptPtr(new SettingsMap);
497 } 489 }
498 490
499 WebViewImpl::~WebViewImpl() 491 WebViewImpl::~WebViewImpl()
500 { 492 {
501 ASSERT(!m_page); 493 ASSERT(!m_page);
502 } 494 }
503 495
504 RenderTheme* WebViewImpl::theme() const 496 RenderTheme* WebViewImpl::theme() const
(...skipping 295 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 m_contextMenuAllowed = false; 792 m_contextMenuAllowed = false;
801 793
802 break; 794 break;
803 } 795 }
804 case WebInputEvent::GestureTapDown: { 796 case WebInputEvent::GestureTapDown: {
805 m_client->cancelScheduledContentIntents(); 797 m_client->cancelScheduledContentIntents();
806 eventSwallowed = mainFrameImpl()->frame()->eventHandler()->handleGesture Event(platformEvent); 798 eventSwallowed = mainFrameImpl()->frame()->eventHandler()->handleGesture Event(platformEvent);
807 break; 799 break;
808 } 800 }
809 case WebInputEvent::GestureDoubleTap: 801 case WebInputEvent::GestureDoubleTap:
810 if (m_webSettings->doubleTapToZoomEnabled() && m_minimumPageScaleFactor != m_maximumPageScaleFactor) { 802 if (m_webSettings->doubleTapToZoomEnabled() && minimumPageScaleFactor() != maximumPageScaleFactor()) {
811 m_client->cancelScheduledContentIntents(); 803 m_client->cancelScheduledContentIntents();
812 animateZoomAroundPoint(platformEvent.position(), DoubleTap); 804 animateZoomAroundPoint(platformEvent.position(), DoubleTap);
813 } 805 }
814 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore, 806 // GestureDoubleTap is currently only used by Android for zooming. For W ebCore,
815 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here. 807 // GestureTap with tap count = 2 is used instead. So we drop GestureDoub leTap here.
816 eventSwallowed = true; 808 eventSwallowed = true;
817 break; 809 break;
818 case WebInputEvent::GestureScrollBegin: 810 case WebInputEvent::GestureScrollBegin:
819 case WebInputEvent::GesturePinchBegin: 811 case WebInputEvent::GesturePinchBegin:
820 m_client->cancelScheduledContentIntents(); 812 m_client->cancelScheduledContentIntents();
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
1173 // be visible). FIXME: Revisit this if it isn't always true. 1165 // be visible). FIXME: Revisit this if it isn't always true.
1174 return; 1166 return;
1175 } 1167 }
1176 1168
1177 bool scaleUnchanged = true; 1169 bool scaleUnchanged = true;
1178 if (!rect.isEmpty()) { 1170 if (!rect.isEmpty()) {
1179 // Pages should be as legible as on desktop when at dpi scale, so no 1171 // Pages should be as legible as on desktop when at dpi scale, so no
1180 // need to zoom in further when automatically determining zoom level 1172 // need to zoom in further when automatically determining zoom level
1181 // (after double tap, find in page, etc), though the user should still 1173 // (after double tap, find in page, etc), though the user should still
1182 // be allowed to manually pinch zoom in further if they desire. 1174 // be allowed to manually pinch zoom in further if they desire.
1183 const float defaultScaleWhenAlreadyLegible = m_minimumPageScaleFactor * doubleTapZoomAlreadyLegibleRatio; 1175 const float defaultScaleWhenAlreadyLegible = minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio;
1184 float legibleScale = 1; 1176 float legibleScale = 1;
1185 if (page() && page()->settings()) 1177 if (page() && page()->settings())
1186 legibleScale *= page()->settings()->textAutosizingFontScaleFactor(); 1178 legibleScale *= page()->settings()->textAutosizingFontScaleFactor();
1187 if (legibleScale < defaultScaleWhenAlreadyLegible) 1179 if (legibleScale < defaultScaleWhenAlreadyLegible)
1188 legibleScale = (scale == m_minimumPageScaleFactor) ? defaultScaleWhe nAlreadyLegible : m_minimumPageScaleFactor; 1180 legibleScale = (scale == minimumPageScaleFactor()) ? defaultScaleWhe nAlreadyLegible : minimumPageScaleFactor();
kenneth.r.christiansen 2013/05/13 11:00:18 Why are these changes not in a separate patch
aelias_OOO_until_Jul13 2013/05/13 18:13:06 Because the field m_minimumScaleFactor was deleted
1189 1181
1190 float defaultMargin = doubleTapZoomContentDefaultMargin; 1182 float defaultMargin = doubleTapZoomContentDefaultMargin;
1191 float minimumMargin = doubleTapZoomContentMinimumMargin; 1183 float minimumMargin = doubleTapZoomContentMinimumMargin;
1192 // We want the margins to have the same physical size, which means we 1184 // We want the margins to have the same physical size, which means we
1193 // need to express them in post-scale size. To do that we'd need to know 1185 // need to express them in post-scale size. To do that we'd need to know
1194 // the scale we're scaling to, but that depends on the margins. Instead 1186 // the scale we're scaling to, but that depends on the margins. Instead
1195 // we express them as a fraction of the target rectangle: this will be 1187 // we express them as a fraction of the target rectangle: this will be
1196 // correct if we end up fully zooming to it, and won't matter if we 1188 // correct if we end up fully zooming to it, and won't matter if we
1197 // don't. 1189 // don't.
1198 rect = widenRectWithinPageBounds(rect, 1190 rect = widenRectWithinPageBounds(rect,
1199 static_cast<int>(defaultMargin * rect.width / m_size.width), 1191 static_cast<int>(defaultMargin * rect.width / m_size.width),
1200 static_cast<int>(minimumMargin * rect.width / m_size.width)); 1192 static_cast<int>(minimumMargin * rect.width / m_size.width));
1201 // Fit block to screen, respecting limits. 1193 // Fit block to screen, respecting limits.
1202 scale = static_cast<float>(m_size.width) / rect.width; 1194 scale = static_cast<float>(m_size.width) / rect.width;
1203 scale = min(scale, legibleScale); 1195 scale = min(scale, legibleScale);
1204 scale = clampPageScaleFactorToLimits(scale); 1196 scale = clampPageScaleFactorToLimits(scale);
1205 1197
1206 scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference; 1198 scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference;
1207 } 1199 }
1208 1200
1209 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa geScaleFactor 1201 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa geScaleFactor
1210 && m_doubleTapZoomPageScaleFactor != m_minimumPageScaleFactor) 1202 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor())
1211 || m_doubleTapZoomPending; 1203 || m_doubleTapZoomPending;
1212 if (zoomType == DoubleTap && (rect.isEmpty() || scaleUnchanged || stillAtPre viousDoubleTapScale)) { 1204 if (zoomType == DoubleTap && (rect.isEmpty() || scaleUnchanged || stillAtPre viousDoubleTapScale)) {
1213 // Zoom out to minimum scale. 1205 // Zoom out to minimum scale.
1214 scale = m_minimumPageScaleFactor; 1206 scale = minimumPageScaleFactor();
1215 scroll = WebPoint(hitRect.x, hitRect.y); 1207 scroll = WebPoint(hitRect.x, hitRect.y);
1216 isAnchor = true; 1208 isAnchor = true;
1217 } else { 1209 } else {
1218 // FIXME: If this is being called for auto zoom during find in page, 1210 // FIXME: If this is being called for auto zoom during find in page,
1219 // then if the user manually zooms in it'd be nice to preserve the 1211 // then if the user manually zooms in it'd be nice to preserve the
1220 // relative increase in zoom they caused (if they zoom out then it's ok 1212 // relative increase in zoom they caused (if they zoom out then it's ok
1221 // to zoom them back in again). This isn't compatible with our current 1213 // to zoom them back in again). This isn't compatible with our current
1222 // double-tap zoom strategy (fitting the containing block to the screen) 1214 // double-tap zoom strategy (fitting the containing block to the screen)
1223 // though. 1215 // though.
1224 1216
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 1635
1644 m_size = newSize; 1636 m_size = newSize;
1645 1637
1646 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth; 1638 bool shouldAnchorAndRescaleViewport = settings()->viewportEnabled() && oldSi ze.width && oldContentsWidth;
1647 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler()); 1639 ViewportAnchor viewportAnchor(mainFrameImpl()->frame()->eventHandler());
1648 if (shouldAnchorAndRescaleViewport) { 1640 if (shouldAnchorAndRescaleViewport) {
1649 viewportAnchor.setAnchor(view->visibleContentRect(), 1641 viewportAnchor.setAnchor(view->visibleContentRect(),
1650 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord)); 1642 FloatSize(viewportAnchorXCoord, viewportAnchorY Coord));
1651 } 1643 }
1652 1644
1653 ViewportArguments viewportArguments = mainFrameImpl()->frame()->document()-> viewportArguments(); 1645 // Set the fixed layout size from the viewport attributes before resizing.
1654 m_page->chrome()->client()->dispatchViewportPropertiesDidChange(viewportArgu ments); 1646 updatePageDefinedViewportAttributes(mainFrameImpl()->frame()->document()->vi ewportArguments());
1655 1647
1656 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate(); 1648 WebDevToolsAgentPrivate* agentPrivate = devToolsAgentPrivate();
1657 if (agentPrivate) 1649 if (agentPrivate)
1658 agentPrivate->webViewResized(newSize); 1650 agentPrivate->webViewResized(newSize);
1659 if (!agentPrivate || !agentPrivate->metricsOverridden()) { 1651 if (!agentPrivate || !agentPrivate->metricsOverridden()) {
1660 WebFrameImpl* webFrame = mainFrameImpl(); 1652 WebFrameImpl* webFrame = mainFrameImpl();
1661 if (webFrame->frameView()) 1653 if (webFrame->frameView())
1662 webFrame->frameView()->resize(m_size); 1654 webFrame->frameView()->resize(m_size);
1663 } 1655 }
1664 1656
(...skipping 1180 matching lines...) Expand 10 before | Expand all | Expand 10 after
2845 { 2837 {
2846 return pow(textSizeMultiplierRatio, zoomLevel); 2838 return pow(textSizeMultiplierRatio, zoomLevel);
2847 } 2839 }
2848 2840
2849 double WebView::zoomFactorToZoomLevel(double factor) 2841 double WebView::zoomFactorToZoomLevel(double factor)
2850 { 2842 {
2851 // Since factor = 1.2^level, level = log(factor) / log(1.2) 2843 // Since factor = 1.2^level, level = log(factor) / log(1.2)
2852 return log(factor) / log(textSizeMultiplierRatio); 2844 return log(factor) / log(textSizeMultiplierRatio);
2853 } 2845 }
2854 2846
2855 void WebViewImpl::setInitialPageScaleOverride(float initialPageScaleFactorOverri de)
2856 {
2857 if (m_initialPageScaleFactorOverride == initialPageScaleFactorOverride)
2858 return;
2859 m_initialPageScaleFactorOverride = initialPageScaleFactorOverride;
2860 m_pageScaleFactorIsSet = false;
2861 computePageScaleFactorLimits();
2862 }
2863
2864 float WebViewImpl::pageScaleFactor() const 2847 float WebViewImpl::pageScaleFactor() const
2865 { 2848 {
2866 if (!page()) 2849 if (!page())
2867 return 1; 2850 return 1;
2868 2851
2869 return page()->pageScaleFactor(); 2852 return page()->pageScaleFactor();
2870 } 2853 }
2871 2854
2872 bool WebViewImpl::isPageScaleFactorSet() const 2855 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) const
2873 { 2856 {
2874 return m_pageScaleFactorIsSet; 2857 return m_viewportAttributesManager.finalAttributes().clampToConstraints(scal eFactor);
2875 } 2858 }
2876 2859
2877 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) 2860 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale)
2878 { 2861 {
2879 return min(max(scaleFactor, m_minimumPageScaleFactor), m_maximumPageScaleFac tor); 2862 FrameView* view = mainFrameImpl()->frameView();
2880 } 2863 if (!view)
2864 return offset;
2881 2865
2882 IntPoint WebViewImpl::clampOffsetAtScale(const IntPoint& offset, float scale) co nst
2883 {
2884 IntPoint clampedOffset = offset; 2866 IntPoint clampedOffset = offset;
2885 clampedOffset = clampedOffset.shrunkTo(IntPoint(contentsSize() - scaledSize( scale))); 2867
2886 clampedOffset.clampNegativeToZero(); 2868 IntSize maxScrollExtent = contentsSize();
2869 clampedOffset = clampedOffset.shrunkTo(IntPoint(maxScrollExtent - scaledSize (scale)));
2870 clampedOffset = clampedOffset.expandedTo(-view->scrollOrigin());
2887 2871
2888 return clampedOffset; 2872 return clampedOffset;
2889 } 2873 }
2890 2874
2891 void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
2892 {
2893 scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
2894
2895 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->scroll Offset().height);
2896 scrollOffset = clampOffsetAtScale(scrollOffset, scaleFactor);
2897
2898 setPageScaleFactor(scaleFactor, scrollOffset);
2899 }
2900
2901 void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin) 2875 void WebViewImpl::setPageScaleFactor(float scaleFactor, const WebPoint& origin)
2902 { 2876 {
2903 if (!page()) 2877 if (!page())
2904 return; 2878 return;
2905 2879
2906 if (!scaleFactor)
2907 scaleFactor = 1;
2908
2909 IntPoint newScrollOffset = origin; 2880 IntPoint newScrollOffset = origin;
2910 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); 2881 scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
2911 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor); 2882 newScrollOffset = clampOffsetAtScale(newScrollOffset, scaleFactor);
2912 2883
2913 Frame* frame = page()->mainFrame(); 2884 page()->setPageScaleFactor(scaleFactor, newScrollOffset);
2914 FrameView* view = frame->view(); 2885 }
2915 IntPoint oldScrollOffset = view->scrollPosition();
2916 2886
2917 // Adjust the page scale in two steps. First, without change to scroll 2887 void WebViewImpl::setPageScaleFactorPreservingScrollOffset(float scaleFactor)
2918 // position, and then with a user scroll to the desired position. 2888 {
2919 // We do this because Page::setPageScaleFactor calls 2889 IntPoint scrollOffset(mainFrame()->scrollOffset().width, mainFrame()->scroll Offset().height);
2920 // FrameView::setScrollPosition which is a programmatic scroll 2890 setPageScaleFactor(scaleFactor, scrollOffset);
2921 // and we need this method to perform only user scrolls.
2922 page()->setPageScaleFactor(scaleFactor, oldScrollOffset);
2923 if (newScrollOffset != oldScrollOffset)
2924 updateMainFrameScrollPosition(newScrollOffset, false);
2925
2926 m_pageScaleFactorIsSet = true;
2927 } 2891 }
2928 2892
2929 float WebViewImpl::deviceScaleFactor() const 2893 float WebViewImpl::deviceScaleFactor() const
2930 { 2894 {
2931 if (!page()) 2895 if (!page())
2932 return 1; 2896 return 1;
2933 2897
2934 return page()->deviceScaleFactor(); 2898 return page()->deviceScaleFactor();
2935 } 2899 }
2936 2900
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
2981 m_maxAutoSize = maxSize; 2945 m_maxAutoSize = maxSize;
2982 configureAutoResizeMode(); 2946 configureAutoResizeMode();
2983 } 2947 }
2984 2948
2985 void WebViewImpl::disableAutoResizeMode() 2949 void WebViewImpl::disableAutoResizeMode()
2986 { 2950 {
2987 m_shouldAutoResize = false; 2951 m_shouldAutoResize = false;
2988 configureAutoResizeMode(); 2952 configureAutoResizeMode();
2989 } 2953 }
2990 2954
2955 void WebViewImpl::overridePageScaleConstraints(ViewportAttributes newConstraints )
kenneth.r.christiansen 2013/05/13 11:00:18 Here the methods is called overwriteSomething
aelias_OOO_until_Jul13 2013/05/13 18:13:06 I renamed this to setUserAgentViewportConstraints.
2956 {
2957 if (newConstraints == m_viewportAttributesManager.embedderConstraints())
2958 return;
2959
2960 m_viewportAttributesManager.setEmbedderConstraints(newConstraints);
2961
2962 if (!mainFrameImpl() || !mainFrameImpl()->frameView())
2963 return;
2964
2965 mainFrameImpl()->frameView()->setNeedsLayout();
2966 }
2967
2968 void WebViewImpl::setInitialPageScaleOverride(float initialPageScaleFactorOverri de)
kenneth.r.christiansen 2013/05/13 11:00:18 here setSomethingOverride.. why the inconsistency?
2969 {
2970 ViewportAttributes constraints = m_viewportAttributesManager.embedderConstra ints();
2971 constraints.initialScale = initialPageScaleFactorOverride;
2972
2973 if (constraints == m_viewportAttributesManager.embedderConstraints())
2974 return;
2975
2976 m_viewportAttributesManager.setNeedsReset(true);
2977 overridePageScaleConstraints(constraints);
2978 }
2979
2991 void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScal e) 2980 void WebViewImpl::setPageScaleFactorLimits(float minPageScale, float maxPageScal e)
2992 { 2981 {
2993 if (minPageScale == m_pageDefinedMinimumPageScaleFactor && maxPageScale == m _pageDefinedMaximumPageScaleFactor) 2982 ViewportAttributes constraints = m_viewportAttributesManager.embedderConstra ints();
2983 constraints.minimumScale = minPageScale;
2984 constraints.maximumScale = maxPageScale;
2985 overridePageScaleConstraints(constraints);
2986 }
2987
2988 void WebViewImpl::setIgnoreViewportTagScaleLimits(bool ignore)
2989 {
2990 ViewportAttributes constraints = m_viewportAttributesManager.embedderConstra ints();
2991 if (ignore) {
2992 constraints.minimumScale = m_viewportAttributesManager.defaultConstraint s().minimumScale;
2993 constraints.maximumScale = m_viewportAttributesManager.defaultConstraint s().maximumScale;
2994 } else {
2995 constraints.minimumScale = -1;
2996 constraints.maximumScale = -1;
2997 }
2998 overridePageScaleConstraints(constraints);
2999 }
3000
3001 void WebViewImpl::refreshPageScaleFactorAfterLayout()
3002 {
3003 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()- >view())
3004 return;
3005 FrameView* view = page()->mainFrame()->view();
3006
3007 updatePageDefinedViewportAttributes(mainFrameImpl()->frame()->document()->vi ewportArguments());
kenneth.r.christiansen 2013/05/13 11:00:18 why bother with all this if viewportEnabled() is n
aelias_OOO_until_Jul13 2013/05/13 18:13:06 Because we want to support pinch zoom on touch-ena
3008 m_viewportAttributesManager.computeFinalAttributes();
3009
3010 if (settings()->viewportEnabled() || settingsImpl()->supportDeprecatedTarget DensityDPI()) {
3011 int verticalScrollbarWidth = 0;
3012 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc rollbar())
3013 verticalScrollbarWidth = view->verticalScrollbar()->width();
3014 m_viewportAttributesManager.adjustFinalAttributesToContentsSize(m_size, contentsSize(), verticalScrollbarWidth);
3015 }
3016
3017 float newPageScaleFactor = pageScaleFactor();
3018 if (m_viewportAttributesManager.needsReset() && m_viewportAttributesManager. finalAttributes().initialScale != -1) {
3019 newPageScaleFactor = m_viewportAttributesManager.finalAttributes().initi alScale;
3020 m_viewportAttributesManager.setNeedsReset(false);
3021 }
3022 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor);
3023
3024 updateLayerTreeViewport();
3025
3026 // Relayout immediately to avoid violating the rule that needsLayout()
3027 // isn't set at the end of a layout.
3028 if (view->needsLayout())
3029 view->layout();
3030 }
3031
3032 void WebViewImpl::updatePageDefinedViewportAttributes(const ViewportArguments& a rguments)
3033 {
3034 if (!settings()->viewportEnabled() || !isFixedLayoutModeEnabled() || !page() || !m_size.width || !m_size.height)
2994 return; 3035 return;
2995 3036
2996 m_pageDefinedMinimumPageScaleFactor = minPageScale; 3037 m_viewportAttributesManager.updatePageDefined(arguments, m_size, page()->set tings()->layoutFallbackWidth());
2997 m_pageDefinedMaximumPageScaleFactor = maxPageScale;
2998 3038
2999 if (settings()->viewportEnabled()) { 3039 if (settingsImpl()->supportDeprecatedTargetDensityDPI())
3000 // If we're in viewport tag mode, we need to layout to obtain the latest 3040 m_viewportAttributesManager.adjustPageDefinedForAndroidWebView(arguments , m_size, page()->settings()->layoutFallbackWidth(), deviceScaleFactor(), settin gsImpl()->useWideViewport(), settingsImpl()->initializeAtMinimumPageScale());
3001 // contents size and compute the final limits.
3002 FrameView* view = mainFrameImpl()->frameView();
3003 if (view)
3004 view->setNeedsLayout();
3005 } else {
3006 // Otherwise just compute the limits immediately.
3007 computePageScaleFactorLimits();
3008 }
3009 }
3010 3041
3011 void WebViewImpl::setIgnoreViewportTagMaximumScale(bool flag) 3042 setFixedLayoutSize(flooredIntSize(m_viewportAttributesManager.pageDefined(). layoutSize));
3012 {
3013 m_ignoreViewportTagMaximumScale = flag;
3014
3015 if (!page() || !page()->mainFrame())
3016 return;
3017
3018 m_page->chrome()->client()->dispatchViewportPropertiesDidChange(page()->main Frame()->document()->viewportArguments());
3019 } 3043 }
3020 3044
3021 IntSize WebViewImpl::contentsSize() const 3045 IntSize WebViewImpl::contentsSize() const
3022 { 3046 {
3023 RenderView* root = page()->mainFrame()->contentRenderer(); 3047 RenderView* root = page()->mainFrame()->contentRenderer();
3024 if (!root) 3048 if (!root)
3025 return IntSize(); 3049 return IntSize();
3026 return root->documentRect().size(); 3050 return root->documentRect().size();
3027 } 3051 }
3028 3052
3029 void WebViewImpl::computePageScaleFactorLimits()
3030 {
3031 if (!mainFrame() || !page() || !page()->mainFrame() || !page()->mainFrame()- >view())
3032 return;
3033
3034 FrameView* view = page()->mainFrame()->view();
3035
3036 if (m_pageDefinedMinimumPageScaleFactor == -1 || m_pageDefinedMaximumPageSca leFactor == -1) {
3037 m_minimumPageScaleFactor = minPageScaleFactor;
3038 m_maximumPageScaleFactor = maxPageScaleFactor;
3039 } else {
3040 m_minimumPageScaleFactor = min(max(m_pageDefinedMinimumPageScaleFactor, minPageScaleFactor), maxPageScaleFactor);
3041 m_maximumPageScaleFactor = max(min(m_pageDefinedMaximumPageScaleFactor, maxPageScaleFactor), minPageScaleFactor);
3042 }
3043
3044 if (settings()->viewportEnabled()) {
3045 if (!contentsSize().width() || !m_size.width)
3046 return;
3047
3048 // When viewport tag is enabled, the scale needed to see the full
3049 // content width is the default minimum.
3050 int viewWidthNotIncludingScrollbars = m_size.width;
3051 if (view->verticalScrollbar() && !view->verticalScrollbar()->isOverlaySc rollbar())
3052 viewWidthNotIncludingScrollbars -= view->verticalScrollbar()->width( );
3053 m_minimumPageScaleFactor = max(m_minimumPageScaleFactor, static_cast<flo at>(viewWidthNotIncludingScrollbars) / contentsSize().width());
3054 m_maximumPageScaleFactor = max(m_minimumPageScaleFactor, m_maximumPageSc aleFactor);
3055 if (m_initialPageScaleFactorOverride != -1) {
3056 m_minimumPageScaleFactor = min(m_minimumPageScaleFactor, m_initialPa geScaleFactorOverride);
3057 m_maximumPageScaleFactor = max(m_maximumPageScaleFactor, m_initialPa geScaleFactorOverride);
3058 }
3059 }
3060 ASSERT(m_minimumPageScaleFactor <= m_maximumPageScaleFactor);
3061
3062 // Initialize and/or clamp the page scale factor if needed.
3063 float initialPageScaleFactor = m_initialPageScaleFactor;
3064 if (!settings()->viewportEnabled())
3065 initialPageScaleFactor = 1;
3066 if (m_initialPageScaleFactorOverride != -1)
3067 initialPageScaleFactor = m_initialPageScaleFactorOverride;
3068 float newPageScaleFactor = pageScaleFactor();
3069 if (!m_pageScaleFactorIsSet && initialPageScaleFactor != -1) {
3070 newPageScaleFactor = initialPageScaleFactor;
3071 m_pageScaleFactorIsSet = true;
3072 }
3073 newPageScaleFactor = clampPageScaleFactorToLimits(newPageScaleFactor);
3074 if (m_layerTreeView)
3075 m_layerTreeView->setPageScaleFactorAndLimits(newPageScaleFactor, m_minim umPageScaleFactor, m_maximumPageScaleFactor);
3076 if (newPageScaleFactor != pageScaleFactor())
3077 setPageScaleFactorPreservingScrollOffset(newPageScaleFactor);
3078 }
3079
3080 float WebViewImpl::minimumPageScaleFactor() const 3053 float WebViewImpl::minimumPageScaleFactor() const
3081 { 3054 {
3082 return m_minimumPageScaleFactor; 3055 return m_viewportAttributesManager.finalAttributes().minimumScale;
3083 } 3056 }
3084 3057
3085 float WebViewImpl::maximumPageScaleFactor() const 3058 float WebViewImpl::maximumPageScaleFactor() const
3086 { 3059 {
3087 return m_maximumPageScaleFactor; 3060 return m_viewportAttributesManager.finalAttributes().maximumScale;
3088 } 3061 }
3089 3062
3090 void WebViewImpl::saveScrollAndScaleState() 3063 void WebViewImpl::saveScrollAndScaleState()
3091 { 3064 {
3092 m_savedPageScaleFactor = pageScaleFactor(); 3065 m_savedPageScaleFactor = pageScaleFactor();
3093 m_savedScrollOffset = mainFrame()->scrollOffset(); 3066 m_savedScrollOffset = mainFrame()->scrollOffset();
3094 } 3067 }
3095 3068
3096 void WebViewImpl::restoreScrollAndScaleState() 3069 void WebViewImpl::restoreScrollAndScaleState()
3097 { 3070 {
(...skipping 11 matching lines...) Expand all
3109 } 3082 }
3110 3083
3111 void WebViewImpl::resetScrollAndScaleState() 3084 void WebViewImpl::resetScrollAndScaleState()
3112 { 3085 {
3113 page()->setPageScaleFactor(1, IntPoint()); 3086 page()->setPageScaleFactor(1, IntPoint());
3114 3087
3115 // Clear out the values for the current history item. This will prevent the history item from clobbering the 3088 // Clear out the values for the current history item. This will prevent the history item from clobbering the
3116 // value determined during page scale initialization, which may be less than 1. 3089 // value determined during page scale initialization, which may be less than 1.
3117 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState(); 3090 page()->mainFrame()->loader()->history()->saveDocumentAndScrollState();
3118 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState(); 3091 page()->mainFrame()->loader()->history()->clearScrollPositionAndViewState();
3119 m_pageScaleFactorIsSet = false; 3092 m_viewportAttributesManager.setNeedsReset(true);
3120 3093
3121 // Clobber saved scales and scroll offsets. 3094 // Clobber saved scales and scroll offsets.
3122 if (FrameView* view = page()->mainFrame()->document()->view()) 3095 if (FrameView* view = page()->mainFrame()->document()->view())
3123 view->cacheCurrentScrollPosition(); 3096 view->cacheCurrentScrollPosition();
3124 resetSavedScrollAndScaleState(); 3097 resetSavedScrollAndScaleState();
3125 } 3098 }
3126 3099
3127 WebSize WebViewImpl::fixedLayoutSize() const 3100 WebSize WebViewImpl::fixedLayoutSize() const
3128 { 3101 {
3129 if (!page()) 3102 if (!page())
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after
3641 if (isNewNavigation) 3614 if (isNewNavigation)
3642 *isNewNavigation = m_observedNewNavigation; 3615 *isNewNavigation = m_observedNewNavigation;
3643 3616
3644 #ifndef NDEBUG 3617 #ifndef NDEBUG
3645 ASSERT(!m_observedNewNavigation 3618 ASSERT(!m_observedNewNavigation
3646 || m_page->mainFrame()->loader()->documentLoader() == m_newNavigationLoa der); 3619 || m_page->mainFrame()->loader()->documentLoader() == m_newNavigationLoa der);
3647 m_newNavigationLoader = 0; 3620 m_newNavigationLoader = 0;
3648 #endif 3621 #endif
3649 m_observedNewNavigation = false; 3622 m_observedNewNavigation = false;
3650 if (*isNewNavigation && !isNavigationWithinPage) 3623 if (*isNewNavigation && !isNavigationWithinPage)
3651 m_pageScaleFactorIsSet = false; 3624 m_viewportAttributesManager.setNeedsReset(true);
3652 3625
3653 // Make sure link highlight from previous page is cleared. 3626 // Make sure link highlight from previous page is cleared.
3654 m_linkHighlight.clear(); 3627 m_linkHighlight.clear();
3655 m_gestureAnimation.clear(); 3628 m_gestureAnimation.clear();
3656 if (m_layerTreeView) 3629 if (m_layerTreeView)
3657 m_layerTreeView->didStopFlinging(); 3630 m_layerTreeView->didStopFlinging();
3658 resetSavedScrollAndScaleState(); 3631 resetSavedScrollAndScaleState();
3659 } 3632 }
3660 3633
3661 void WebViewImpl::layoutUpdated(WebFrameImpl* webframe) 3634 void WebViewImpl::layoutUpdated(WebFrameImpl* webframe)
3662 { 3635 {
3663 if (!m_client || webframe != mainFrameImpl()) 3636 if (!m_client || webframe != mainFrameImpl())
3664 return; 3637 return;
3665 3638
3666 if (m_shouldAutoResize && mainFrameImpl()->frame() && mainFrameImpl()->frame ()->view()) { 3639 if (m_shouldAutoResize && mainFrameImpl()->frame() && mainFrameImpl()->frame ()->view()) {
3667 WebSize frameSize = mainFrameImpl()->frame()->view()->frameRect().size() ; 3640 WebSize frameSize = mainFrameImpl()->frame()->view()->frameRect().size() ;
3668 if (frameSize != m_size) { 3641 if (frameSize != m_size) {
3669 m_size = frameSize; 3642 m_size = frameSize;
3670 m_client->didAutoResize(m_size); 3643 m_client->didAutoResize(m_size);
3671 sendResizeEventAndRepaint(); 3644 sendResizeEventAndRepaint();
3672 } 3645 }
3673 } 3646 }
3674 3647
3675 if (settings()->viewportEnabled()) { 3648 if (m_viewportAttributesManager.constraintsDirty())
3676 if (!isPageScaleFactorSet()) { 3649 refreshPageScaleFactorAfterLayout();
3677 // If the viewport tag failed to be processed earlier, we need
3678 // to recompute it now.
3679 ViewportArguments viewportArguments = mainFrameImpl()->frame()->docu ment()->viewportArguments();
3680 m_page->chrome()->client()->dispatchViewportPropertiesDidChange(view portArguments);
3681 }
3682
3683 // Contents size is an input to the page scale limits, so a good time to
3684 // recalculate is after layout has occurred.
3685 computePageScaleFactorLimits();
3686
3687 // Relayout immediately to avoid violating the rule that needsLayout()
3688 // isn't set at the end of a layout.
3689 FrameView* view = mainFrameImpl()->frameView();
3690 if (view && view->needsLayout())
3691 view->layout();
3692 }
3693 3650
3694 m_client->didUpdateLayout(); 3651 m_client->didUpdateLayout();
3695
3696 } 3652 }
3697 3653
3698 void WebViewImpl::didChangeContentsSize() 3654 void WebViewImpl::didChangeContentsSize()
3699 { 3655 {
3656 m_viewportAttributesManager.didChangeContentsSize(contentsSize(), pageScaleF actor());
3700 } 3657 }
3701 3658
3702 void WebViewImpl::deviceOrPageScaleFactorChanged() 3659 void WebViewImpl::deviceOrPageScaleFactorChanged()
3703 { 3660 {
3704 if (pageScaleFactor() && pageScaleFactor() != 1) 3661 if (pageScaleFactor() && pageScaleFactor() != 1)
3705 enterForceCompositingMode(true); 3662 enterForceCompositingMode(true);
3663 m_viewportAttributesManager.setNeedsReset(false);
3706 updateLayerTreeViewport(); 3664 updateLayerTreeViewport();
3707 } 3665 }
3708 3666
3709 bool WebViewImpl::useExternalPopupMenus() 3667 bool WebViewImpl::useExternalPopupMenus()
3710 { 3668 {
3711 return shouldUseExternalPopupMenus; 3669 return shouldUseExternalPopupMenus;
3712 } 3670 }
3713 3671
3714 void WebViewImpl::setEmulatedTextZoomFactor(float textZoomFactor) 3672 void WebViewImpl::setEmulatedTextZoomFactor(float textZoomFactor)
3715 { 3673 {
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
4018 m_nonCompositedContentHost->setOpaque(!isTransparent()); 3976 m_nonCompositedContentHost->setOpaque(!isTransparent());
4019 3977
4020 m_client->initializeLayerTreeView(); 3978 m_client->initializeLayerTreeView();
4021 m_layerTreeView = m_client->layerTreeView(); 3979 m_layerTreeView = m_client->layerTreeView();
4022 if (m_layerTreeView) { 3980 if (m_layerTreeView) {
4023 m_layerTreeView->setRootLayer(*m_rootLayer); 3981 m_layerTreeView->setRootLayer(*m_rootLayer);
4024 3982
4025 bool visible = page()->visibilityState() == PageVisibilityStateVisib le; 3983 bool visible = page()->visibilityState() == PageVisibilityStateVisib le;
4026 m_layerTreeView->setVisible(visible); 3984 m_layerTreeView->setVisible(visible);
4027 m_layerTreeView->setDeviceScaleFactor(page()->deviceScaleFactor()); 3985 m_layerTreeView->setDeviceScaleFactor(page()->deviceScaleFactor());
4028 m_layerTreeView->setPageScaleFactorAndLimits(pageScaleFactor(), m_mi nimumPageScaleFactor, m_maximumPageScaleFactor);
4029 m_layerTreeView->setHasTransparentBackground(isTransparent()); 3986 m_layerTreeView->setHasTransparentBackground(isTransparent());
4030 updateLayerTreeViewport(); 3987 updateLayerTreeViewport();
4031 m_client->didActivateCompositor(m_inputHandlerIdentifier); 3988 m_client->didActivateCompositor(m_inputHandlerIdentifier);
4032 m_isAcceleratedCompositingActive = true; 3989 m_isAcceleratedCompositingActive = true;
4033 m_compositorCreationFailed = false; 3990 m_compositorCreationFailed = false;
4034 if (m_pageOverlays) 3991 if (m_pageOverlays)
4035 m_pageOverlays->update(); 3992 m_pageOverlays->update();
4036 m_layerTreeView->setShowFPSCounter(m_showFPSCounter); 3993 m_layerTreeView->setShowFPSCounter(m_showFPSCounter);
4037 m_layerTreeView->setShowPaintRects(m_showPaintRects); 3994 m_layerTreeView->setShowPaintRects(m_showPaintRects);
4038 m_layerTreeView->setShowDebugBorders(m_showDebugBorders); 3995 m_layerTreeView->setShowDebugBorders(m_showDebugBorders);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
4107 m_pageOverlays->update(); 4064 m_pageOverlays->update();
4108 } 4065 }
4109 4066
4110 void WebViewImpl::updateLayerTreeViewport() 4067 void WebViewImpl::updateLayerTreeViewport()
4111 { 4068 {
4112 if (!page() || !m_nonCompositedContentHost || !m_layerTreeView) 4069 if (!page() || !m_nonCompositedContentHost || !m_layerTreeView)
4113 return; 4070 return;
4114 4071
4115 FrameView* view = page()->mainFrame()->view(); 4072 FrameView* view = page()->mainFrame()->view();
4116 m_nonCompositedContentHost->setViewport(m_size, view->contentsSize(), view-> scrollPosition(), view->scrollOrigin()); 4073 m_nonCompositedContentHost->setViewport(m_size, view->contentsSize(), view-> scrollPosition(), view->scrollOrigin());
4117 m_layerTreeView->setPageScaleFactorAndLimits(pageScaleFactor(), m_minimumPag eScaleFactor, m_maximumPageScaleFactor); 4074 m_layerTreeView->setPageScaleFactorAndLimits(pageScaleFactor(), minimumPageS caleFactor(), maximumPageScaleFactor());
4118 } 4075 }
4119 4076
4120 void WebViewImpl::selectAutofillSuggestionAtIndex(unsigned listIndex) 4077 void WebViewImpl::selectAutofillSuggestionAtIndex(unsigned listIndex)
4121 { 4078 {
4122 if (m_autofillPopupClient && listIndex < m_autofillPopupClient->getSuggestio nsCount()) 4079 if (m_autofillPopupClient && listIndex < m_autofillPopupClient->getSuggestio nsCount())
4123 m_autofillPopupClient->valueChanged(listIndex); 4080 m_autofillPopupClient->valueChanged(listIndex);
4124 } 4081 }
4125 4082
4126 bool WebViewImpl::detectContentOnTouch(const WebPoint& position) 4083 bool WebViewImpl::detectContentOnTouch(const WebPoint& position)
4127 { 4084 {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
4213 } 4170 }
4214 4171
4215 bool WebViewImpl::shouldDisableDesktopWorkarounds() 4172 bool WebViewImpl::shouldDisableDesktopWorkarounds()
4216 { 4173 {
4217 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments(); 4174 ViewportArguments arguments = mainFrameImpl()->frame()->document()->viewport Arguments();
4218 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom 4175 return arguments.width == ViewportArguments::ValueDeviceWidth || !arguments. userZoom
4219 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto); 4176 || (arguments.minZoom == arguments.maxZoom && arguments.minZoom != Viewp ortArguments::ValueAuto);
4220 } 4177 }
4221 4178
4222 } // namespace WebKit 4179 } // namespace WebKit
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698