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

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

Issue 1990553002: Remove RenderViewImpl::GetFocusedElement. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Really works now. Created 4 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
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 958 matching lines...) Expand 10 before | Expand all | Expand 10 after
969 if (m_gestureAnimation) { 969 if (m_gestureAnimation) {
970 m_gestureAnimation.clear(); 970 m_gestureAnimation.clear();
971 m_flingSourceDevice = WebGestureDeviceUninitialized; 971 m_flingSourceDevice = WebGestureDeviceUninitialized;
972 if (m_layerTreeView) 972 if (m_layerTreeView)
973 m_layerTreeView->didStopFlinging(); 973 m_layerTreeView->didStopFlinging();
974 return true; 974 return true;
975 } 975 }
976 return false; 976 return false;
977 } 977 }
978 978
979 bool WebViewImpl::startPageScaleAnimation(const IntPoint& targetPosition, bool u seAnchor, float newScale, double durationInSeconds) 979 void WebViewImpl::startPageScaleAnimation(const IntPoint& targetPosition, bool u seAnchor, float newScale, double durationInSeconds)
980 { 980 {
981 VisualViewport& visualViewport = page()->frameHost().visualViewport(); 981 VisualViewport& visualViewport = page()->frameHost().visualViewport();
982 WebPoint clampedPoint = targetPosition; 982 WebPoint clampedPoint = targetPosition;
983 if (!useAnchor) { 983 if (!useAnchor) {
984 clampedPoint = visualViewport.clampDocumentOffsetAtScale(targetPosition, newScale); 984 clampedPoint = visualViewport.clampDocumentOffsetAtScale(targetPosition, newScale);
985 if (!durationInSeconds) { 985 if (!durationInSeconds) {
986 setPageScaleFactor(newScale); 986 setPageScaleFactor(newScale);
987 987
988 FrameView* view = mainFrameImpl()->frameView(); 988 FrameView* view = mainFrameImpl()->frameView();
989 if (view && view->getScrollableArea()) 989 if (view && view->getScrollableArea())
990 view->getScrollableArea()->setScrollPosition(DoublePoint(clamped Point.x, clampedPoint.y), ProgrammaticScroll); 990 view->getScrollableArea()->setScrollPosition(DoublePoint(clamped Point.x, clampedPoint.y), ProgrammaticScroll);
991
992 return false;
993 } 991 }
994 } 992 }
995 if (useAnchor && newScale == pageScaleFactor()) 993 if (useAnchor && newScale == pageScaleFactor())
996 return false; 994 return;
997 995
998 if (m_enableFakePageScaleAnimationForTesting) { 996 if (m_enableFakePageScaleAnimationForTesting) {
999 m_fakePageScaleAnimationTargetPosition = targetPosition; 997 m_fakePageScaleAnimationTargetPosition = targetPosition;
1000 m_fakePageScaleAnimationUseAnchor = useAnchor; 998 m_fakePageScaleAnimationUseAnchor = useAnchor;
1001 m_fakePageScaleAnimationPageScaleFactor = newScale; 999 m_fakePageScaleAnimationPageScaleFactor = newScale;
1002 } else { 1000 } else if (m_layerTreeView) {
1003 if (!m_layerTreeView)
1004 return false;
1005 m_layerTreeView->startPageScaleAnimation(targetPosition, useAnchor, newS cale, durationInSeconds); 1001 m_layerTreeView->startPageScaleAnimation(targetPosition, useAnchor, newS cale, durationInSeconds);
1006 } 1002 }
1007 return true;
1008 } 1003 }
1009 1004
1010 void WebViewImpl::enableFakePageScaleAnimationForTesting(bool enable) 1005 void WebViewImpl::enableFakePageScaleAnimationForTesting(bool enable)
1011 { 1006 {
1012 m_enableFakePageScaleAnimationForTesting = enable; 1007 m_enableFakePageScaleAnimationForTesting = enable;
1013 } 1008 }
1014 1009
1015 void WebViewImpl::setShowFPSCounter(bool show) 1010 void WebViewImpl::setShowFPSCounter(bool show)
1016 { 1011 {
1017 if (m_layerTreeView) { 1012 if (m_layerTreeView) {
(...skipping 424 matching lines...) Expand 10 before | Expand all | Expand 10 after
1442 1437
1443 computeScaleAndScrollForBlockRect(pointInRootFrame, blockBounds, touchPointP adding, minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio, scale, scro ll); 1438 computeScaleAndScrollForBlockRect(pointInRootFrame, blockBounds, touchPointP adding, minimumPageScaleFactor() * doubleTapZoomAlreadyLegibleRatio, scale, scro ll);
1444 1439
1445 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa geScaleFactor 1440 bool stillAtPreviousDoubleTapScale = (pageScaleFactor() == m_doubleTapZoomPa geScaleFactor
1446 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor()) 1441 && m_doubleTapZoomPageScaleFactor != minimumPageScaleFactor())
1447 || m_doubleTapZoomPending; 1442 || m_doubleTapZoomPending;
1448 1443
1449 bool scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference; 1444 bool scaleUnchanged = fabs(pageScaleFactor() - scale) < minScaleDifference;
1450 bool shouldZoomOut = blockBounds.isEmpty() || scaleUnchanged || stillAtPrevi ousDoubleTapScale; 1445 bool shouldZoomOut = blockBounds.isEmpty() || scaleUnchanged || stillAtPrevi ousDoubleTapScale;
1451 1446
1452 bool isAnimating;
1453
1454 if (shouldZoomOut) { 1447 if (shouldZoomOut) {
1455 scale = minimumPageScaleFactor(); 1448 scale = minimumPageScaleFactor();
1456 IntPoint targetPosition = mainFrameImpl()->frameView()->rootFrameToConte nts(pointInRootFrame); 1449 IntPoint targetPosition = mainFrameImpl()->frameView()->rootFrameToConte nts(pointInRootFrame);
1457 isAnimating = startPageScaleAnimation(targetPosition, true, scale, doubl eTapZoomAnimationDurationInSeconds); 1450 startPageScaleAnimation(targetPosition, true, scale, doubleTapZoomAnimat ionDurationInSeconds);
1458 } else { 1451 } else {
1459 isAnimating = startPageScaleAnimation(scroll, false, scale, doubleTapZoo mAnimationDurationInSeconds); 1452 startPageScaleAnimation(scroll, false, scale, doubleTapZoomAnimationDura tionInSeconds);
1460 } 1453 }
1461 1454
1462 if (isAnimating) { 1455 if (m_layerTreeView->hasPendingPageScaleAnimation()) {
1463 m_doubleTapZoomPageScaleFactor = scale; 1456 m_doubleTapZoomPageScaleFactor = scale;
1464 m_doubleTapZoomPending = true; 1457 m_doubleTapZoomPending = true;
1465 } 1458 }
1466 } 1459 }
1467 1460
1468 void WebViewImpl::zoomToFindInPageRect(const WebRect& rectInRootFrame) 1461 void WebViewImpl::zoomToFindInPageRect(const WebRect& rectInRootFrame)
1469 { 1462 {
1470 if (!mainFrameImpl()) 1463 if (!mainFrameImpl())
1471 return; 1464 return;
1472 1465
(...skipping 1458 matching lines...) Expand 10 before | Expand all | Expand 10 after
2931 return; 2924 return;
2932 2925
2933 // If a text field has focus, we need to make sure the selection controller 2926 // If a text field has focus, we need to make sure the selection controller
2934 // knows to remove selection from it. Otherwise, the text field is still 2927 // knows to remove selection from it. Otherwise, the text field is still
2935 // processing keyboard events even though focus has been moved to the page a nd 2928 // processing keyboard events even though focus has been moved to the page a nd
2936 // keystrokes get eaten as a result. 2929 // keystrokes get eaten as a result.
2937 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol()) 2930 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol())
2938 localFrame->selection().clear(); 2931 localFrame->selection().clear();
2939 } 2932 }
2940 2933
2941 bool WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rectInViewport) 2934 // TODO(dglazkov): Remove and replace with Node:hasEditableStyle.
2935 // http://crbug.com/612560
2936 static bool isElementEditable(const Element* element)
2937 {
2938 if (element->isContentEditable())
2939 return true;
2940
2941 if (element->isTextFormControl()) {
2942 const HTMLTextFormControlElement* input = toHTMLTextFormControlElement(e lement);
2943 if (!input->isDisabledOrReadOnly())
2944 return true;
2945 }
2946
2947 return equalIgnoringCase(element->getAttribute(HTMLNames::roleAttr), "textbo x");
2948 }
2949
2950 bool WebViewImpl::scrollFocusedEditableElementIntoRect(const WebRect& rectInView port)
2942 { 2951 {
2943 LocalFrame* frame = page()->mainFrame() && page()->mainFrame()->isLocalFrame () 2952 LocalFrame* frame = page()->mainFrame() && page()->mainFrame()->isLocalFrame ()
2944 ? page()->deprecatedLocalMainFrame() : nullptr; 2953 ? page()->deprecatedLocalMainFrame() : nullptr;
2945 Element* element = focusedElement(); 2954 Element* element = focusedElement();
2946 if (!frame || !frame->view() || !element) 2955 if (!frame || !frame->view() || !element)
2947 return false; 2956 return false;
2948 2957
2958 if (!isElementEditable(element))
2959 return false;
2960
2949 element->document().updateLayoutIgnorePendingStylesheets(); 2961 element->document().updateLayoutIgnorePendingStylesheets();
2950 2962
2951 bool zoomInToLegibleScale = m_webSettings->autoZoomFocusedNodeToLegibleScale () 2963 bool zoomInToLegibleScale = m_webSettings->autoZoomFocusedNodeToLegibleScale ()
2952 && !page()->frameHost().visualViewport().shouldDisableDesktopWorkarounds (); 2964 && !page()->frameHost().visualViewport().shouldDisableDesktopWorkarounds ();
2953 2965
2954 if (zoomInToLegibleScale) { 2966 if (zoomInToLegibleScale) {
2955 // When deciding whether to zoom in on a focused text box, we should dec ide not to 2967 // When deciding whether to zoom in on a focused text box, we should dec ide not to
2956 // zoom in if the user won't be able to zoom out. e.g if the textbox is within a 2968 // zoom in if the user won't be able to zoom out. e.g if the textbox is within a
2957 // touch-action: none container the user can't zoom back out. 2969 // touch-action: none container the user can't zoom back out.
2958 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*eleme nt); 2970 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*eleme nt);
2959 if (!(action & TouchActionPinchZoom)) 2971 if (!(action & TouchActionPinchZoom))
2960 zoomInToLegibleScale = false; 2972 zoomInToLegibleScale = false;
2961 } 2973 }
2962 2974
2963 float scale; 2975 float scale;
2964 IntPoint scroll; 2976 IntPoint scroll;
2965 bool needAnimation; 2977 bool needAnimation;
2966 computeScaleAndScrollForFocusedNode(element, zoomInToLegibleScale, scale, sc roll, needAnimation); 2978 computeScaleAndScrollForFocusedNode(element, zoomInToLegibleScale, scale, sc roll, needAnimation);
2967 if (needAnimation) 2979 if (needAnimation)
2968 return startPageScaleAnimation(scroll, false, scale, scrollAndScaleAnima tionDurationInSeconds); 2980 startPageScaleAnimation(scroll, false, scale, scrollAndScaleAnimationDur ationInSeconds);
2969 2981
2970 return false; 2982 return true;
2971 } 2983 }
2972 2984
2973 void WebViewImpl::smoothScroll(int targetX, int targetY, long durationMs) 2985 void WebViewImpl::smoothScroll(int targetX, int targetY, long durationMs)
2974 { 2986 {
2975 IntPoint targetPosition(targetX, targetY); 2987 IntPoint targetPosition(targetX, targetY);
2976 startPageScaleAnimation(targetPosition, false, pageScaleFactor(), (double)du rationMs / 1000); 2988 startPageScaleAnimation(targetPosition, false, pageScaleFactor(), (double)du rationMs / 1000);
2977 } 2989 }
2978 2990
2979 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, bool zo omInToLegibleScale, float& newScale, IntPoint& newScroll, bool& needAnimation) 2991 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, bool zo omInToLegibleScale, float& newScale, IntPoint& newScroll, bool& needAnimation)
2980 { 2992 {
(...skipping 1541 matching lines...) Expand 10 before | Expand all | Expand 10 after
4522 { 4534 {
4523 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4535 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4524 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4536 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4525 if (!page()) 4537 if (!page())
4526 return 1; 4538 return 1;
4527 4539
4528 return page()->deviceScaleFactor(); 4540 return page()->deviceScaleFactor();
4529 } 4541 }
4530 4542
4531 } // namespace blink 4543 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698