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

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: 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 2920 matching lines...) Expand 10 before | Expand all | Expand 10 after
2931 return; 2931 return;
2932 2932
2933 // If a text field has focus, we need to make sure the selection controller 2933 // 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 2934 // 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 2935 // processing keyboard events even though focus has been moved to the page a nd
2936 // keystrokes get eaten as a result. 2936 // keystrokes get eaten as a result.
2937 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol()) 2937 if (oldFocusedElement->isContentEditable() || oldFocusedElement->isTextFormC ontrol())
2938 localFrame->selection().clear(); 2938 localFrame->selection().clear();
2939 } 2939 }
2940 2940
2941 bool WebViewImpl::scrollFocusedNodeIntoRect(const WebRect& rectInViewport) 2941 // TODO(dglazkov): Remove and replace with Node:hasEditableStyle.
2942 // http://crbug.com/612560
2943 static bool isElementEditable(const Element* element)
2944 {
2945 if (element->isContentEditable())
dglazkov 2016/05/17 22:00:15 Not loving this duplication. I can try to fold rem
esprehn 2016/05/17 22:16:43 Nah, lets do that next. Feels more likely to break
2946 return true;
2947
2948 if (element->isTextFormControl()) {
2949 const HTMLTextFormControlElement* input = toHTMLTextFormControlElement(e lement);
2950 if (!input->isDisabledOrReadOnly())
2951 return true;
2952 }
2953
2954 return equalIgnoringCase(element->getAttribute(HTMLNames::roleAttr), "textbo x");
2955 }
2956
2957 bool WebViewImpl::scrollFocusedEditableElementIntoRect(const WebRect& rectInView port, bool& willAnimate)
2942 { 2958 {
2943 LocalFrame* frame = page()->mainFrame() && page()->mainFrame()->isLocalFrame () 2959 LocalFrame* frame = page()->mainFrame() && page()->mainFrame()->isLocalFrame ()
2944 ? page()->deprecatedLocalMainFrame() : nullptr; 2960 ? page()->deprecatedLocalMainFrame() : nullptr;
2945 Element* element = focusedElement(); 2961 Element* element = focusedElement();
2946 if (!frame || !frame->view() || !element) 2962 if (!frame || !frame->view() || !element)
2947 return false; 2963 return false;
2948 2964
2965 if (!isElementEditable(element))
2966 return false;
2967
2949 element->document().updateLayoutIgnorePendingStylesheets(); 2968 element->document().updateLayoutIgnorePendingStylesheets();
2950 2969
2951 bool zoomInToLegibleScale = m_webSettings->autoZoomFocusedNodeToLegibleScale () 2970 bool zoomInToLegibleScale = m_webSettings->autoZoomFocusedNodeToLegibleScale ()
2952 && !page()->frameHost().visualViewport().shouldDisableDesktopWorkarounds (); 2971 && !page()->frameHost().visualViewport().shouldDisableDesktopWorkarounds ();
2953 2972
2954 if (zoomInToLegibleScale) { 2973 if (zoomInToLegibleScale) {
2955 // When deciding whether to zoom in on a focused text box, we should dec ide not to 2974 // 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 2975 // 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. 2976 // touch-action: none container the user can't zoom back out.
2958 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*eleme nt); 2977 TouchAction action = TouchActionUtil::computeEffectiveTouchAction(*eleme nt);
2959 if (!(action & TouchActionPinchZoom)) 2978 if (!(action & TouchActionPinchZoom))
2960 zoomInToLegibleScale = false; 2979 zoomInToLegibleScale = false;
2961 } 2980 }
2962 2981
2963 float scale; 2982 float scale;
2964 IntPoint scroll; 2983 IntPoint scroll;
2965 bool needAnimation; 2984 bool needAnimation;
2966 computeScaleAndScrollForFocusedNode(element, zoomInToLegibleScale, scale, sc roll, needAnimation); 2985 computeScaleAndScrollForFocusedNode(element, zoomInToLegibleScale, scale, sc roll, needAnimation);
2967 if (needAnimation) 2986 willAnimate = needAnimation ? startPageScaleAnimation(scroll, false, scale, scrollAndScaleAnimationDurationInSeconds) : false;
2968 return startPageScaleAnimation(scroll, false, scale, scrollAndScaleAnima tionDurationInSeconds);
2969 2987
2970 return false; 2988 return true;
2971 } 2989 }
2972 2990
2973 void WebViewImpl::smoothScroll(int targetX, int targetY, long durationMs) 2991 void WebViewImpl::smoothScroll(int targetX, int targetY, long durationMs)
2974 { 2992 {
2975 IntPoint targetPosition(targetX, targetY); 2993 IntPoint targetPosition(targetX, targetY);
2976 startPageScaleAnimation(targetPosition, false, pageScaleFactor(), (double)du rationMs / 1000); 2994 startPageScaleAnimation(targetPosition, false, pageScaleFactor(), (double)du rationMs / 1000);
2977 } 2995 }
2978 2996
2979 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, bool zo omInToLegibleScale, float& newScale, IntPoint& newScroll, bool& needAnimation) 2997 void WebViewImpl::computeScaleAndScrollForFocusedNode(Node* focusedNode, bool zo omInToLegibleScale, float& newScale, IntPoint& newScroll, bool& needAnimation)
2980 { 2998 {
(...skipping 1543 matching lines...) Expand 10 before | Expand all | Expand 10 after
4524 { 4542 {
4525 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than 4543 // TODO(oshima): Investigate if this should return the ScreenInfo's scale fa ctor rather than
4526 // page's scale factor, which can be 1 in use-zoom-for-dsf mode. 4544 // page's scale factor, which can be 1 in use-zoom-for-dsf mode.
4527 if (!page()) 4545 if (!page())
4528 return 1; 4546 return 1;
4529 4547
4530 return page()->deviceScaleFactor(); 4548 return page()->deviceScaleFactor();
4531 } 4549 }
4532 4550
4533 } // namespace blink 4551 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698