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

Side by Side Diff: third_party/WebKit/Source/web/WebViewImpl.cpp

Issue 2730573003: Moved FrameHost::m_visualViewport to Page (Closed)
Patch Set: Fixed some compile errors on mac and android Created 3 years, 9 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 818 matching lines...) Expand 10 before | Expand all | Expand 10 after
829 break; 829 break;
830 } 830 }
831 831
832 // Don't trigger a disambiguation popup on sites designed for mobile 832 // Don't trigger a disambiguation popup on sites designed for mobile
833 // devices. Instead, assume that the page has been designed with big 833 // devices. Instead, assume that the page has been designed with big
834 // enough buttons and links. Don't trigger a disambiguation popup when 834 // enough buttons and links. Don't trigger a disambiguation popup when
835 // screencasting, since it's implemented outside of compositor pipeline 835 // screencasting, since it's implemented outside of compositor pipeline
836 // and is not being screencasted itself. This leads to bad user 836 // and is not being screencasted itself. This leads to bad user
837 // experience. 837 // experience.
838 WebDevToolsAgentImpl* devTools = mainFrameDevToolsAgentImpl(); 838 WebDevToolsAgentImpl* devTools = mainFrameDevToolsAgentImpl();
839 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 839 VisualViewport& visualViewport = page()->visualViewport();
840 bool screencastEnabled = devTools && devTools->screencastEnabled(); 840 bool screencastEnabled = devTools && devTools->screencastEnabled();
841 if (event.data.tap.width > 0 && 841 if (event.data.tap.width > 0 &&
842 !visualViewport.shouldDisableDesktopWorkarounds() && 842 !visualViewport.shouldDisableDesktopWorkarounds() &&
843 !screencastEnabled) { 843 !screencastEnabled) {
844 IntRect boundingBox(visualViewport.viewportToRootFrame( 844 IntRect boundingBox(visualViewport.viewportToRootFrame(
845 IntRect(event.x - event.data.tap.width / 2, 845 IntRect(event.x - event.data.tap.width / 2,
846 event.y - event.data.tap.height / 2, event.data.tap.width, 846 event.y - event.data.tap.height / 2, event.data.tap.width,
847 event.data.tap.height))); 847 event.data.tap.height)));
848 848
849 // TODO(bokan): We shouldn't pass details of the VisualViewport offset 849 // TODO(bokan): We shouldn't pass details of the VisualViewport offset
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
1001 m_layerTreeView->didStopFlinging(); 1001 m_layerTreeView->didStopFlinging();
1002 return true; 1002 return true;
1003 } 1003 }
1004 return false; 1004 return false;
1005 } 1005 }
1006 1006
1007 bool WebViewImpl::startPageScaleAnimation(const IntPoint& targetPosition, 1007 bool WebViewImpl::startPageScaleAnimation(const IntPoint& targetPosition,
1008 bool useAnchor, 1008 bool useAnchor,
1009 float newScale, 1009 float newScale,
1010 double durationInSeconds) { 1010 double durationInSeconds) {
1011 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1011 VisualViewport& visualViewport = page()->visualViewport();
1012 WebPoint clampedPoint = targetPosition; 1012 WebPoint clampedPoint = targetPosition;
1013 if (!useAnchor) { 1013 if (!useAnchor) {
1014 clampedPoint = 1014 clampedPoint =
1015 visualViewport.clampDocumentOffsetAtScale(targetPosition, newScale); 1015 visualViewport.clampDocumentOffsetAtScale(targetPosition, newScale);
1016 if (!durationInSeconds) { 1016 if (!durationInSeconds) {
1017 setPageScaleFactor(newScale); 1017 setPageScaleFactor(newScale);
1018 1018
1019 FrameView* view = mainFrameImpl()->frameView(); 1019 FrameView* view = mainFrameImpl()->frameView();
1020 if (view && view->getScrollableArea()) { 1020 if (view && view->getScrollableArea()) {
1021 view->getScrollableArea()->setScrollOffset( 1021 view->getScrollableArea()->setScrollOffset(
(...skipping 366 matching lines...) Expand 10 before | Expand all | Expand 10 after
1388 if (rect.width < screenWidth) 1388 if (rect.width < screenWidth)
1389 rect.x -= 0.5 * (screenWidth - rect.width); 1389 rect.x -= 0.5 * (screenWidth - rect.width);
1390 else 1390 else
1391 rect.x = 1391 rect.x =
1392 std::max<float>(rect.x, hitPointInRootFrame.x + padding - screenWidth); 1392 std::max<float>(rect.x, hitPointInRootFrame.x + padding - screenWidth);
1393 scroll.x = rect.x; 1393 scroll.x = rect.x;
1394 scroll.y = rect.y; 1394 scroll.y = rect.y;
1395 1395
1396 scale = clampPageScaleFactorToLimits(scale); 1396 scale = clampPageScaleFactorToLimits(scale);
1397 scroll = mainFrameImpl()->frameView()->rootFrameToContents(scroll); 1397 scroll = mainFrameImpl()->frameView()->rootFrameToContents(scroll);
1398 scroll = page()->frameHost().visualViewport().clampDocumentOffsetAtScale( 1398 scroll = page()->visualViewport().clampDocumentOffsetAtScale(scroll, scale);
1399 scroll, scale);
1400 } 1399 }
1401 1400
1402 static Node* findCursorDefiningAncestor(Node* node, LocalFrame* frame) { 1401 static Node* findCursorDefiningAncestor(Node* node, LocalFrame* frame) {
1403 // Go up the tree to find the node that defines a mouse cursor style 1402 // Go up the tree to find the node that defines a mouse cursor style
1404 while (node) { 1403 while (node) {
1405 if (node->layoutObject()) { 1404 if (node->layoutObject()) {
1406 ECursor cursor = node->layoutObject()->style()->cursor(); 1405 ECursor cursor = node->layoutObject()->style()->cursor();
1407 if (cursor != ECursor::kAuto || 1406 if (cursor != ECursor::kAuto ||
1408 frame->eventHandler().useHandCursor(node, node->isLink())) 1407 frame->eventHandler().useHandCursor(node, node->isLink()))
1409 break; 1408 break;
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after
1766 m_client = nullptr; 1765 m_client = nullptr;
1767 1766
1768 deref(); // Balances ref() acquired in WebView::create 1767 deref(); // Balances ref() acquired in WebView::create
1769 } 1768 }
1770 1769
1771 WebSize WebViewImpl::size() { 1770 WebSize WebViewImpl::size() {
1772 return m_size; 1771 return m_size;
1773 } 1772 }
1774 1773
1775 void WebViewImpl::resizeVisualViewport(const WebSize& newSize) { 1774 void WebViewImpl::resizeVisualViewport(const WebSize& newSize) {
1776 page()->frameHost().visualViewport().setSize(newSize); 1775 page()->visualViewport().setSize(newSize);
1777 page()->frameHost().visualViewport().clampToBoundaries(); 1776 page()->visualViewport().clampToBoundaries();
1778 } 1777 }
1779 1778
1780 void WebViewImpl::performResize() { 1779 void WebViewImpl::performResize() {
1781 // We'll keep the initial containing block size from changing when the top 1780 // We'll keep the initial containing block size from changing when the top
1782 // controls hide so that the ICB will always be the same size as the 1781 // controls hide so that the ICB will always be the same size as the
1783 // viewport with the browser controls shown. 1782 // viewport with the browser controls shown.
1784 IntSize ICBSize = m_size; 1783 IntSize ICBSize = m_size;
1785 if (RuntimeEnabledFeatures::inertTopControlsEnabled() && 1784 if (RuntimeEnabledFeatures::inertTopControlsEnabled() &&
1786 browserControls().permittedState() == WebBrowserControlsBoth && 1785 browserControls().permittedState() == WebBrowserControlsBoth &&
1787 !browserControls().shrinkViewport()) 1786 !browserControls().shrinkViewport())
1788 ICBSize.expand(0, -browserControls().height()); 1787 ICBSize.expand(0, -browserControls().height());
1789 1788
1790 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(ICBSize); 1789 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(ICBSize);
1791 1790
1792 updatePageDefinedViewportConstraints( 1791 updatePageDefinedViewportConstraints(
1793 mainFrameImpl()->frame()->document()->viewportDescription()); 1792 mainFrameImpl()->frame()->document()->viewportDescription());
1794 updateMainFrameLayoutSize(); 1793 updateMainFrameLayoutSize();
1795 1794
1796 page()->frameHost().visualViewport().setSize(m_size); 1795 page()->visualViewport().setSize(m_size);
1797 1796
1798 if (mainFrameImpl()->frameView()) { 1797 if (mainFrameImpl()->frameView()) {
1799 mainFrameImpl()->frameView()->setInitialViewportSize(ICBSize); 1798 mainFrameImpl()->frameView()->setInitialViewportSize(ICBSize);
1800 if (!mainFrameImpl()->frameView()->needsLayout()) 1799 if (!mainFrameImpl()->frameView()->needsLayout())
1801 postLayoutResize(mainFrameImpl()); 1800 postLayoutResize(mainFrameImpl());
1802 } 1801 }
1803 } 1802 }
1804 1803
1805 void WebViewImpl::updateBrowserControlsState(WebBrowserControlsState constraint, 1804 void WebViewImpl::updateBrowserControlsState(WebBrowserControlsState constraint,
1806 WebBrowserControlsState current, 1805 WebBrowserControlsState current,
(...skipping 27 matching lines...) Expand all
1834 } 1833 }
1835 1834
1836 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1835 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1837 if (!mainFrame) 1836 if (!mainFrame)
1838 return; 1837 return;
1839 1838
1840 FrameView* view = mainFrame->frameView(); 1839 FrameView* view = mainFrame->frameView();
1841 if (!view) 1840 if (!view)
1842 return; 1841 return;
1843 1842
1844 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1843 VisualViewport& visualViewport = page()->visualViewport();
1845 1844
1846 { 1845 {
1847 // This object will save the current visual viewport offset w.r.t. the 1846 // This object will save the current visual viewport offset w.r.t. the
1848 // document and restore it when the object goes out of scope. It's 1847 // document and restore it when the object goes out of scope. It's
1849 // needed since the browser controls adjustment will change the maximum 1848 // needed since the browser controls adjustment will change the maximum
1850 // scroll offset and we may need to reposition them to keep the user's 1849 // scroll offset and we may need to reposition them to keep the user's
1851 // apparent position unchanged. 1850 // apparent position unchanged.
1852 ResizeViewportAnchor::ResizeScope resizeScope(*m_resizeViewportAnchor); 1851 ResizeViewportAnchor::ResizeScope resizeScope(*m_resizeViewportAnchor);
1853 1852
1854 float browserControlsViewportAdjustment = 1853 float browserControlsViewportAdjustment =
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
1895 browserControls().shrinkViewport() == browserControlsShrinkLayout) 1894 browserControls().shrinkViewport() == browserControlsShrinkLayout)
1896 return; 1895 return;
1897 1896
1898 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) { 1897 if (page()->mainFrame() && !page()->mainFrame()->isLocalFrame()) {
1899 // Viewport resize for a remote main frame does not require any 1898 // Viewport resize for a remote main frame does not require any
1900 // particular action, but the state needs to reflect the correct size 1899 // particular action, but the state needs to reflect the correct size
1901 // so that it can be used for initalization if the main frame gets 1900 // so that it can be used for initalization if the main frame gets
1902 // swapped to a LocalFrame at a later time. 1901 // swapped to a LocalFrame at a later time.
1903 m_size = newSize; 1902 m_size = newSize;
1904 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size); 1903 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size);
1905 page()->frameHost().visualViewport().setSize(m_size); 1904 page()->visualViewport().setSize(m_size);
1906 return; 1905 return;
1907 } 1906 }
1908 1907
1909 WebLocalFrameImpl* mainFrame = mainFrameImpl(); 1908 WebLocalFrameImpl* mainFrame = mainFrameImpl();
1910 if (!mainFrame) 1909 if (!mainFrame)
1911 return; 1910 return;
1912 1911
1913 FrameView* view = mainFrame->frameView(); 1912 FrameView* view = mainFrame->frameView();
1914 if (!view) 1913 if (!view)
1915 return; 1914 return;
1916 1915
1917 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 1916 VisualViewport& visualViewport = page()->visualViewport();
1918 1917
1919 bool isRotation = 1918 bool isRotation =
1920 page()->settings().getMainFrameResizesAreOrientationChanges() && 1919 page()->settings().getMainFrameResizesAreOrientationChanges() &&
1921 m_size.width && contentsSize().width() && newSize.width != m_size.width && 1920 m_size.width && contentsSize().width() && newSize.width != m_size.width &&
1922 !m_fullscreenController->isFullscreen(); 1921 !m_fullscreenController->isFullscreen();
1923 m_size = newSize; 1922 m_size = newSize;
1924 1923
1925 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY); 1924 FloatSize viewportAnchorCoords(viewportAnchorCoordX, viewportAnchorCoordY);
1926 if (isRotation) { 1925 if (isRotation) {
1927 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoords, 1926 RotationViewportAnchor anchor(*view, visualViewport, viewportAnchorCoords,
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
2133 // on the page. There is a single input event, GestureTap, which can both 2132 // on the page. There is a single input event, GestureTap, which can both
2134 // be the first event after page load, and cause a form submission. In that 2133 // be the first event after page load, and cause a form submission. In that
2135 // case, the form submission happens before the autofill client is told 2134 // case, the form submission happens before the autofill client is told
2136 // to unblock the password values, and so the password values are not 2135 // to unblock the password values, and so the password values are not
2137 // submitted. To avoid that, GestureTap is handled explicitly: 2136 // submitted. To avoid that, GestureTap is handled explicitly:
2138 if (inputEvent.type() == WebInputEvent::GestureTap && autofillClient) { 2137 if (inputEvent.type() == WebInputEvent::GestureTap && autofillClient) {
2139 m_userGestureObserved = true; 2138 m_userGestureObserved = true;
2140 autofillClient->firstUserGestureObserved(); 2139 autofillClient->firstUserGestureObserved();
2141 } 2140 }
2142 2141
2143 page()->frameHost().visualViewport().startTrackingPinchStats(); 2142 page()->visualViewport().startTrackingPinchStats();
2144 2143
2145 TRACE_EVENT1("input,rail", "WebViewImpl::handleInputEvent", "type", 2144 TRACE_EVENT1("input,rail", "WebViewImpl::handleInputEvent", "type",
2146 WebInputEvent::GetName(inputEvent.type())); 2145 WebInputEvent::GetName(inputEvent.type()));
2147 2146
2148 // If a drag-and-drop operation is in progress, ignore input events. 2147 // If a drag-and-drop operation is in progress, ignore input events.
2149 if (mainFrameImpl()->frameWidget()->doingDragAndDrop()) 2148 if (mainFrameImpl()->frameWidget()->doingDragAndDrop())
2150 return WebInputEventResult::HandledSuppressed; 2149 return WebInputEventResult::HandledSuppressed;
2151 2150
2152 if (m_devToolsEmulator->handleInputEvent(inputEvent)) 2151 if (m_devToolsEmulator->handleInputEvent(inputEvent))
2153 return WebInputEventResult::HandledSuppressed; 2152 return WebInputEventResult::HandledSuppressed;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
2237 // as touch events would have already been sent for the gesture. 2236 // as touch events would have already been sent for the gesture.
2238 if (pinchEvent.sourceDevice == WebGestureDeviceTouchpad) { 2237 if (pinchEvent.sourceDevice == WebGestureDeviceTouchpad) {
2239 result = handleSyntheticWheelFromTouchpadPinchEvent(pinchEvent); 2238 result = handleSyntheticWheelFromTouchpadPinchEvent(pinchEvent);
2240 if (result != WebInputEventResult::NotHandled) 2239 if (result != WebInputEventResult::NotHandled)
2241 return result; 2240 return result;
2242 } 2241 }
2243 2242
2244 if (pinchEvent.data.pinchUpdate.zoomDisabled) 2243 if (pinchEvent.data.pinchUpdate.zoomDisabled)
2245 return WebInputEventResult::NotHandled; 2244 return WebInputEventResult::NotHandled;
2246 2245
2247 if (page()->frameHost().visualViewport().magnifyScaleAroundAnchor( 2246 if (page()->visualViewport().magnifyScaleAroundAnchor(
2248 pinchEvent.data.pinchUpdate.scale, 2247 pinchEvent.data.pinchUpdate.scale,
2249 FloatPoint(pinchEvent.x, pinchEvent.y))) 2248 FloatPoint(pinchEvent.x, pinchEvent.y)))
2250 return WebInputEventResult::HandledSystem; 2249 return WebInputEventResult::HandledSystem;
2251 } 2250 }
2252 2251
2253 return WebInputEventResult::NotHandled; 2252 return WebInputEventResult::NotHandled;
2254 } 2253 }
2255 2254
2256 void WebViewImpl::setCursorVisibilityState(bool isVisible) { 2255 void WebViewImpl::setCursorVisibilityState(bool isVisible) {
2257 if (m_page) 2256 if (m_page)
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after
2726 if (!frame || !frame->view() || !element) 2725 if (!frame || !frame->view() || !element)
2727 return false; 2726 return false;
2728 2727
2729 if (!isElementEditable(element)) 2728 if (!isElementEditable(element))
2730 return false; 2729 return false;
2731 2730
2732 element->document().updateStyleAndLayoutIgnorePendingStylesheets(); 2731 element->document().updateStyleAndLayoutIgnorePendingStylesheets();
2733 2732
2734 bool zoomInToLegibleScale = 2733 bool zoomInToLegibleScale =
2735 m_webSettings->autoZoomFocusedNodeToLegibleScale() && 2734 m_webSettings->autoZoomFocusedNodeToLegibleScale() &&
2736 !page()->frameHost().visualViewport().shouldDisableDesktopWorkarounds(); 2735 !page()->visualViewport().shouldDisableDesktopWorkarounds();
2737 2736
2738 if (zoomInToLegibleScale) { 2737 if (zoomInToLegibleScale) {
2739 // When deciding whether to zoom in on a focused text box, we should decide 2738 // When deciding whether to zoom in on a focused text box, we should decide
2740 // not to zoom in if the user won't be able to zoom out. e.g if the textbox 2739 // not to zoom in if the user won't be able to zoom out. e.g if the textbox
2741 // is within a touch-action: none container the user can't zoom back out. 2740 // is within a touch-action: none container the user can't zoom back out.
2742 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*element); 2741 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*element);
2743 if (!(action & TouchActionPinchZoom)) 2742 if (!(action & TouchActionPinchZoom))
2744 zoomInToLegibleScale = false; 2743 zoomInToLegibleScale = false;
2745 } 2744 }
2746 2745
(...skipping 13 matching lines...) Expand all
2760 IntPoint targetPosition(targetX, targetY); 2759 IntPoint targetPosition(targetX, targetY);
2761 startPageScaleAnimation(targetPosition, false, pageScaleFactor(), 2760 startPageScaleAnimation(targetPosition, false, pageScaleFactor(),
2762 (double)durationMs / 1000); 2761 (double)durationMs / 1000);
2763 } 2762 }
2764 2763
2765 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, 2764 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode,
2766 bool zoomInToLegibleScale, 2765 bool zoomInToLegibleScale,
2767 float& newScale, 2766 float& newScale,
2768 IntPoint& newScroll, 2767 IntPoint& newScroll,
2769 bool& needAnimation) { 2768 bool& needAnimation) {
2770 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 2769 VisualViewport& visualViewport = page()->visualViewport();
2771 2770
2772 WebRect caretInViewport, unusedEnd; 2771 WebRect caretInViewport, unusedEnd;
2773 selectionBounds(caretInViewport, unusedEnd); 2772 selectionBounds(caretInViewport, unusedEnd);
2774 2773
2775 // 'caretInDocument' is rect encompassing the blinking cursor relative to the 2774 // 'caretInDocument' is rect encompassing the blinking cursor relative to the
2776 // root document. 2775 // root document.
2777 IntRect caretInDocument = mainFrameImpl()->frameView()->frameToContents( 2776 IntRect caretInDocument = mainFrameImpl()->frameView()->frameToContents(
2778 visualViewport.viewportToRootFrame(caretInViewport)); 2777 visualViewport.viewportToRootFrame(caretInViewport));
2779 IntRect textboxRectInDocument = mainFrameImpl()->frameView()->frameToContents( 2778 IntRect textboxRectInDocument = mainFrameImpl()->frameView()->frameToContents(
2780 focusedNode->document().view()->contentsToRootFrame( 2779 focusedNode->document().view()->contentsToRootFrame(
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
2943 2942
2944 double WebView::zoomFactorToZoomLevel(double factor) { 2943 double WebView::zoomFactorToZoomLevel(double factor) {
2945 // Since factor = 1.2^level, level = log(factor) / log(1.2) 2944 // Since factor = 1.2^level, level = log(factor) / log(1.2)
2946 return log(factor) / log(textSizeMultiplierRatio); 2945 return log(factor) / log(textSizeMultiplierRatio);
2947 } 2946 }
2948 2947
2949 float WebViewImpl::pageScaleFactor() const { 2948 float WebViewImpl::pageScaleFactor() const {
2950 if (!page()) 2949 if (!page())
2951 return 1; 2950 return 1;
2952 2951
2953 return page()->frameHost().visualViewport().scale(); 2952 return page()->visualViewport().scale();
2954 } 2953 }
2955 2954
2956 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) const { 2955 float WebViewImpl::clampPageScaleFactorToLimits(float scaleFactor) const {
2957 return pageScaleConstraintsSet().finalConstraints().clampToConstraints( 2956 return pageScaleConstraintsSet().finalConstraints().clampToConstraints(
2958 scaleFactor); 2957 scaleFactor);
2959 } 2958 }
2960 2959
2961 void WebViewImpl::setVisualViewportOffset(const WebFloatPoint& offset) { 2960 void WebViewImpl::setVisualViewportOffset(const WebFloatPoint& offset) {
2962 DCHECK(page()); 2961 DCHECK(page());
2963 page()->frameHost().visualViewport().setLocation(offset); 2962 page()->visualViewport().setLocation(offset);
2964 } 2963 }
2965 2964
2966 WebFloatPoint WebViewImpl::visualViewportOffset() const { 2965 WebFloatPoint WebViewImpl::visualViewportOffset() const {
2967 DCHECK(page()); 2966 DCHECK(page());
2968 return page()->frameHost().visualViewport().visibleRect().location(); 2967 return page()->visualViewport().visibleRect().location();
2969 } 2968 }
2970 2969
2971 WebFloatSize WebViewImpl::visualViewportSize() const { 2970 WebFloatSize WebViewImpl::visualViewportSize() const {
2972 DCHECK(page()); 2971 DCHECK(page());
2973 return page()->frameHost().visualViewport().visibleRect().size(); 2972 return page()->visualViewport().visibleRect().size();
2974 } 2973 }
2975 2974
2976 void WebViewImpl::scrollAndRescaleViewports( 2975 void WebViewImpl::scrollAndRescaleViewports(
2977 float scaleFactor, 2976 float scaleFactor,
2978 const IntPoint& mainFrameOrigin, 2977 const IntPoint& mainFrameOrigin,
2979 const FloatPoint& visualViewportOrigin) { 2978 const FloatPoint& visualViewportOrigin) {
2980 if (!page()) 2979 if (!page())
2981 return; 2980 return;
2982 2981
2983 if (!mainFrameImpl()) 2982 if (!mainFrameImpl())
2984 return; 2983 return;
2985 2984
2986 FrameView* view = mainFrameImpl()->frameView(); 2985 FrameView* view = mainFrameImpl()->frameView();
2987 if (!view) 2986 if (!view)
2988 return; 2987 return;
2989 2988
2990 // Order is important: visual viewport location is clamped based on 2989 // Order is important: visual viewport location is clamped based on
2991 // main frame scroll position and visual viewport scale. 2990 // main frame scroll position and visual viewport scale.
2992 2991
2993 view->setScrollOffset(toScrollOffset(mainFrameOrigin), ProgrammaticScroll); 2992 view->setScrollOffset(toScrollOffset(mainFrameOrigin), ProgrammaticScroll);
2994 2993
2995 setPageScaleFactor(scaleFactor); 2994 setPageScaleFactor(scaleFactor);
2996 2995
2997 page()->frameHost().visualViewport().setLocation(visualViewportOrigin); 2996 page()->visualViewport().setLocation(visualViewportOrigin);
2998 } 2997 }
2999 2998
3000 void WebViewImpl::setPageScaleFactorAndLocation(float scaleFactor, 2999 void WebViewImpl::setPageScaleFactorAndLocation(float scaleFactor,
3001 const FloatPoint& location) { 3000 const FloatPoint& location) {
3002 DCHECK(page()); 3001 DCHECK(page());
3003 3002
3004 page()->frameHost().visualViewport().setScaleAndLocation( 3003 page()->visualViewport().setScaleAndLocation(
3005 clampPageScaleFactorToLimits(scaleFactor), location); 3004 clampPageScaleFactorToLimits(scaleFactor), location);
3006 } 3005 }
3007 3006
3008 void WebViewImpl::setPageScaleFactor(float scaleFactor) { 3007 void WebViewImpl::setPageScaleFactor(float scaleFactor) {
3009 DCHECK(page()); 3008 DCHECK(page());
3010 3009
3011 scaleFactor = clampPageScaleFactorToLimits(scaleFactor); 3010 scaleFactor = clampPageScaleFactorToLimits(scaleFactor);
3012 if (scaleFactor == pageScaleFactor()) 3011 if (scaleFactor == pageScaleFactor())
3013 return; 3012 return;
3014 3013
3015 page()->frameHost().visualViewport().setScale(scaleFactor); 3014 page()->visualViewport().setScale(scaleFactor);
3016 } 3015 }
3017 3016
3018 void WebViewImpl::setDeviceScaleFactor(float scaleFactor) { 3017 void WebViewImpl::setDeviceScaleFactor(float scaleFactor) {
3019 if (!page()) 3018 if (!page())
3020 return; 3019 return;
3021 3020
3022 page()->setDeviceScaleFactorDeprecated(scaleFactor); 3021 page()->setDeviceScaleFactorDeprecated(scaleFactor);
3023 3022
3024 if (m_layerTreeView) 3023 if (m_layerTreeView)
3025 updateLayerTreeDeviceScaleFactor(); 3024 updateLayerTreeDeviceScaleFactor();
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 3284
3286 float WebViewImpl::maximumPageScaleFactor() const { 3285 float WebViewImpl::maximumPageScaleFactor() const {
3287 return pageScaleConstraintsSet().finalConstraints().maximumScale; 3286 return pageScaleConstraintsSet().finalConstraints().maximumScale;
3288 } 3287 }
3289 3288
3290 void WebViewImpl::resetScaleStateImmediately() { 3289 void WebViewImpl::resetScaleStateImmediately() {
3291 pageScaleConstraintsSet().setNeedsReset(true); 3290 pageScaleConstraintsSet().setNeedsReset(true);
3292 } 3291 }
3293 3292
3294 void WebViewImpl::resetScrollAndScaleState() { 3293 void WebViewImpl::resetScrollAndScaleState() {
3295 page()->frameHost().visualViewport().reset(); 3294 page()->visualViewport().reset();
3296 3295
3297 if (!page()->mainFrame()->isLocalFrame()) 3296 if (!page()->mainFrame()->isLocalFrame())
3298 return; 3297 return;
3299 3298
3300 if (FrameView* frameView = toLocalFrame(page()->mainFrame())->view()) { 3299 if (FrameView* frameView = toLocalFrame(page()->mainFrame())->view()) {
3301 ScrollableArea* scrollableArea = frameView->layoutViewportScrollableArea(); 3300 ScrollableArea* scrollableArea = frameView->layoutViewportScrollableArea();
3302 3301
3303 if (!scrollableArea->getScrollOffset().isZero()) 3302 if (!scrollableArea->getScrollOffset().isZero())
3304 scrollableArea->setScrollOffset(ScrollOffset(), ProgrammaticScroll); 3303 scrollableArea->setScrollOffset(ScrollOffset(), ProgrammaticScroll);
3305 } 3304 }
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
3636 m_shouldDispatchFirstLayoutAfterFinishedParsing = true; 3635 m_shouldDispatchFirstLayoutAfterFinishedParsing = true;
3637 m_shouldDispatchFirstLayoutAfterFinishedLoading = true; 3636 m_shouldDispatchFirstLayoutAfterFinishedLoading = true;
3638 3637
3639 if (isNewNavigation) { 3638 if (isNewNavigation) {
3640 pageScaleConstraintsSet().setNeedsReset(true); 3639 pageScaleConstraintsSet().setNeedsReset(true);
3641 m_pageImportanceSignals.onCommitLoad(); 3640 m_pageImportanceSignals.onCommitLoad();
3642 } 3641 }
3643 } 3642 }
3644 3643
3645 // Give the visual viewport's scroll layer its initial size. 3644 // Give the visual viewport's scroll layer its initial size.
3646 page()->frameHost().visualViewport().mainFrameDidChangeSize(); 3645 page()->visualViewport().mainFrameDidChangeSize();
3647 3646
3648 // Make sure link highlight from previous page is cleared. 3647 // Make sure link highlight from previous page is cleared.
3649 m_linkHighlights.clear(); 3648 m_linkHighlights.clear();
3650 endActiveFlingAnimation(); 3649 endActiveFlingAnimation();
3651 m_userGestureObserved = false; 3650 m_userGestureObserved = false;
3652 } 3651 }
3653 3652
3654 void WebViewImpl::postLayoutResize(WebLocalFrameImpl* webframe) { 3653 void WebViewImpl::postLayoutResize(WebLocalFrameImpl* webframe) {
3655 FrameView* view = webframe->frame()->view(); 3654 FrameView* view = webframe->frame()->view();
3656 if (webframe == mainFrame()) 3655 if (webframe == mainFrame())
3657 m_resizeViewportAnchor->resizeFrameView(mainFrameSize()); 3656 m_resizeViewportAnchor->resizeFrameView(mainFrameSize());
3658 else 3657 else
3659 view->resize(webframe->frameView()->size()); 3658 view->resize(webframe->frameView()->size());
3660 } 3659 }
3661 3660
3662 void WebViewImpl::layoutUpdated(WebLocalFrameImpl* webframe) { 3661 void WebViewImpl::layoutUpdated(WebLocalFrameImpl* webframe) {
3663 LocalFrame* frame = webframe->frame(); 3662 LocalFrame* frame = webframe->frame();
3664 if (!m_client || !frame->isMainFrame()) 3663 if (!m_client || !frame->isMainFrame())
3665 return; 3664 return;
3666 3665
3667 if (m_shouldAutoResize) { 3666 if (m_shouldAutoResize) {
3668 WebSize frameSize = frame->view()->frameRect().size(); 3667 WebSize frameSize = frame->view()->frameRect().size();
3669 if (frameSize != m_size) { 3668 if (frameSize != m_size) {
3670 m_size = frameSize; 3669 m_size = frameSize;
3671 3670
3672 page()->frameHost().visualViewport().setSize(m_size); 3671 page()->visualViewport().setSize(m_size);
3673 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size); 3672 pageScaleConstraintsSet().didChangeInitialContainingBlockSize(m_size);
3674 frame->view()->setInitialViewportSize(m_size); 3673 frame->view()->setInitialViewportSize(m_size);
3675 3674
3676 m_client->didAutoResize(m_size); 3675 m_client->didAutoResize(m_size);
3677 sendResizeEventAndRepaint(); 3676 sendResizeEventAndRepaint();
3678 } 3677 }
3679 } 3678 }
3680 3679
3681 if (pageScaleConstraintsSet().constraintsDirty()) 3680 if (pageScaleConstraintsSet().constraintsDirty())
3682 refreshPageScaleFactorAfterLayout(); 3681 refreshPageScaleFactorAfterLayout();
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
3756 Document* document = frame->document(); 3755 Document* document = frame->document();
3757 if (!document) 3756 if (!document)
3758 return nullptr; 3757 return nullptr;
3759 3758
3760 return document->focusedElement(); 3759 return document->focusedElement();
3761 } 3760 }
3762 3761
3763 HitTestResult WebViewImpl::hitTestResultForViewportPos( 3762 HitTestResult WebViewImpl::hitTestResultForViewportPos(
3764 const IntPoint& posInViewport) { 3763 const IntPoint& posInViewport) {
3765 IntPoint rootFramePoint( 3764 IntPoint rootFramePoint(
3766 m_page->frameHost().visualViewport().viewportToRootFrame(posInViewport)); 3765 m_page->visualViewport().viewportToRootFrame(posInViewport));
3767 return hitTestResultForRootFramePos(rootFramePoint); 3766 return hitTestResultForRootFramePos(rootFramePoint);
3768 } 3767 }
3769 3768
3770 HitTestResult WebViewImpl::hitTestResultForRootFramePos( 3769 HitTestResult WebViewImpl::hitTestResultForRootFramePos(
3771 const IntPoint& posInRootFrame) { 3770 const IntPoint& posInRootFrame) {
3772 if (!m_page->mainFrame()->isLocalFrame()) 3771 if (!m_page->mainFrame()->isLocalFrame())
3773 return HitTestResult(); 3772 return HitTestResult();
3774 IntPoint docPoint( 3773 IntPoint docPoint(
3775 m_page->deprecatedLocalMainFrame()->view()->rootFrameToContents( 3774 m_page->deprecatedLocalMainFrame()->view()->rootFrameToContents(
3776 posInRootFrame)); 3775 posInRootFrame));
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
3830 3829
3831 DCHECK(document); 3830 DCHECK(document);
3832 3831
3833 // Get the outer viewport scroll layer. 3832 // Get the outer viewport scroll layer.
3834 GraphicsLayer* layoutViewportScrollLayer = 3833 GraphicsLayer* layoutViewportScrollLayer =
3835 page()->frameHost().globalRootScrollerController().rootScrollerLayer(); 3834 page()->frameHost().globalRootScrollerController().rootScrollerLayer();
3836 WebLayer* layoutViewportWebLayer = 3835 WebLayer* layoutViewportWebLayer =
3837 layoutViewportScrollLayer ? layoutViewportScrollLayer->platformLayer() 3836 layoutViewportScrollLayer ? layoutViewportScrollLayer->platformLayer()
3838 : nullptr; 3837 : nullptr;
3839 3838
3840 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 3839 VisualViewport& visualViewport = page()->visualViewport();
3841 3840
3842 // TODO(bokan): This was moved here from when registerViewportLayers was a 3841 // TODO(bokan): This was moved here from when registerViewportLayers was a
3843 // part of VisualViewport and maybe doesn't belong here. See comment inside 3842 // part of VisualViewport and maybe doesn't belong here. See comment inside
3844 // the mehtod. 3843 // the mehtod.
3845 visualViewport.setScrollLayerOnScrollbars(layoutViewportWebLayer); 3844 visualViewport.setScrollLayerOnScrollbars(layoutViewportWebLayer);
3846 3845
3847 m_layerTreeView->registerViewportLayers( 3846 m_layerTreeView->registerViewportLayers(
3848 visualViewport.overscrollElasticityLayer()->platformLayer(), 3847 visualViewport.overscrollElasticityLayer()->platformLayer(),
3849 visualViewport.pageScaleLayer()->platformLayer(), 3848 visualViewport.pageScaleLayer()->platformLayer(),
3850 visualViewport.scrollLayer()->platformLayer(), layoutViewportWebLayer); 3849 visualViewport.scrollLayer()->platformLayer(), layoutViewportWebLayer);
3851 } 3850 }
3852 3851
3853 void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* graphicsLayer) { 3852 void WebViewImpl::setRootGraphicsLayer(GraphicsLayer* graphicsLayer) {
3854 if (!m_layerTreeView) 3853 if (!m_layerTreeView)
3855 return; 3854 return;
3856 3855
3857 // In SPv2, setRootLayer is used instead. 3856 // In SPv2, setRootLayer is used instead.
3858 DCHECK(!RuntimeEnabledFeatures::slimmingPaintV2Enabled()); 3857 DCHECK(!RuntimeEnabledFeatures::slimmingPaintV2Enabled());
3859 3858
3860 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 3859 VisualViewport& visualViewport = page()->visualViewport();
3861 visualViewport.attachLayerTree(graphicsLayer); 3860 visualViewport.attachLayerTree(graphicsLayer);
3862 if (graphicsLayer) { 3861 if (graphicsLayer) {
3863 m_rootGraphicsLayer = visualViewport.rootGraphicsLayer(); 3862 m_rootGraphicsLayer = visualViewport.rootGraphicsLayer();
3864 m_visualViewportContainerLayer = visualViewport.containerLayer(); 3863 m_visualViewportContainerLayer = visualViewport.containerLayer();
3865 m_rootLayer = m_rootGraphicsLayer->platformLayer(); 3864 m_rootLayer = m_rootGraphicsLayer->platformLayer();
3866 updateDeviceEmulationTransform(); 3865 updateDeviceEmulationTransform();
3867 m_layerTreeView->setRootLayer(*m_rootLayer); 3866 m_layerTreeView->setRootLayer(*m_rootLayer);
3868 // We register viewport layers here since there may not be a layer 3867 // We register viewport layers here since there may not be a layer
3869 // tree view prior to this point. 3868 // tree view prior to this point.
3870 registerViewportLayersWithCompositor(); 3869 registerViewportLayersWithCompositor();
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
3985 } 3984 }
3986 3985
3987 void WebViewImpl::applyViewportDeltas( 3986 void WebViewImpl::applyViewportDeltas(
3988 const WebFloatSize& visualViewportDelta, 3987 const WebFloatSize& visualViewportDelta,
3989 // TODO(bokan): This parameter is to be removed but requires adjusting many 3988 // TODO(bokan): This parameter is to be removed but requires adjusting many
3990 // callsites. 3989 // callsites.
3991 const WebFloatSize&, 3990 const WebFloatSize&,
3992 const WebFloatSize& elasticOverscrollDelta, 3991 const WebFloatSize& elasticOverscrollDelta,
3993 float pageScaleDelta, 3992 float pageScaleDelta,
3994 float browserControlsShownRatioDelta) { 3993 float browserControlsShownRatioDelta) {
3995 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 3994 VisualViewport& visualViewport = page()->visualViewport();
3996 3995
3997 // Store the desired offsets the visual viewport before setting the top 3996 // Store the desired offsets the visual viewport before setting the top
3998 // controls ratio since doing so will change the bounds and move the 3997 // controls ratio since doing so will change the bounds and move the
3999 // viewports to keep the offsets valid. The compositor may have already 3998 // viewports to keep the offsets valid. The compositor may have already
4000 // done that so we don't want to double apply the deltas here. 3999 // done that so we don't want to double apply the deltas here.
4001 FloatPoint visualViewportOffset = visualViewport.visibleRect().location(); 4000 FloatPoint visualViewportOffset = visualViewport.visibleRect().location();
4002 visualViewportOffset.move(visualViewportDelta.width, 4001 visualViewportOffset.move(visualViewportDelta.width,
4003 visualViewportDelta.height); 4002 visualViewportDelta.height);
4004 4003
4005 browserControls().setShownRatio(browserControls().shownRatio() + 4004 browserControls().setShownRatio(browserControls().shownRatio() +
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
4180 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame()) 4179 if (focusedFrame->localFrameRoot() != mainFrameImpl()->frame())
4181 return nullptr; 4180 return nullptr;
4182 return focusedFrame; 4181 return focusedFrame;
4183 } 4182 }
4184 4183
4185 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const { 4184 LocalFrame* WebViewImpl::focusedLocalFrameAvailableForIme() const {
4186 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr; 4185 return m_imeAcceptEvents ? focusedLocalFrameInWidget() : nullptr;
4187 } 4186 }
4188 4187
4189 } // namespace blink 4188 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/web/WebPagePopupImpl.cpp ('k') | third_party/WebKit/Source/web/mac/WebSubstringUtil.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698