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

Side by Side Diff: third_party/WebKit/Source/core/editing/FrameSelection.cpp

Issue 2710883002: Expand FrameSeleciton::isNone() to increase chances of hoisting update layout (Closed)
Patch Set: 2017-02-23T16:27:43 rebase to resolve conflict with DOMSelection in r452402 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) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple 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 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 1. Redistributions of source code must retain the above copyright 7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer. 8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright 9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the 10 * notice, this list of conditions and the following disclaimer in the
(...skipping 811 matching lines...) Expand 10 before | Expand all | Expand 10 after
822 if (!n) 822 if (!n)
823 return false; 823 return false;
824 LayoutObject* layoutObject = n->layoutObject(); 824 LayoutObject* layoutObject = n->layoutObject();
825 if (!layoutObject || !layoutObject->isLayoutPart()) 825 if (!layoutObject || !layoutObject->isLayoutPart())
826 return false; 826 return false;
827 Widget* widget = toLayoutPart(layoutObject)->widget(); 827 Widget* widget = toLayoutPart(layoutObject)->widget();
828 return widget && widget->isFrameView(); 828 return widget && widget->isFrameView();
829 } 829 }
830 830
831 void FrameSelection::setFocusedNodeIfNeeded() { 831 void FrameSelection::setFocusedNodeIfNeeded() {
832 if (isNone() || !isFocused()) 832 if (computeVisibleSelectionInDOMTreeDeprecated().isNone() || !isFocused())
833 return; 833 return;
834 834
835 if (Element* target = 835 if (Element* target =
836 computeVisibleSelectionInDOMTreeDeprecated().rootEditableElement()) { 836 computeVisibleSelectionInDOMTreeDeprecated().rootEditableElement()) {
837 // Walk up the DOM tree to search for a node to focus. 837 // Walk up the DOM tree to search for a node to focus.
838 document().updateStyleAndLayoutTreeIgnorePendingStylesheets(); 838 document().updateStyleAndLayoutTreeIgnorePendingStylesheets();
839 while (target) { 839 while (target) {
840 // We don't want to set focus on a subframe when selecting in a parent 840 // We don't want to set focus on a subframe when selecting in a parent
841 // frame, so add the !isFrameElement check here. There's probably a better 841 // frame, so add the !isFrameElement check here. There's probably a better
842 // way to make this work in the long term, but this is the safest fix at 842 // way to make this work in the long term, but this is the safest fix at
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
995 alignment)) 995 alignment))
996 updateAppearance(); 996 updateAppearance();
997 } 997 }
998 } 998 }
999 999
1000 void FrameSelection::setSelectionFromNone() { 1000 void FrameSelection::setSelectionFromNone() {
1001 // Put a caret inside the body if the entire frame is editable (either the 1001 // Put a caret inside the body if the entire frame is editable (either the
1002 // entire WebView is editable or designMode is on for this document). 1002 // entire WebView is editable or designMode is on for this document).
1003 1003
1004 Document* document = m_frame->document(); 1004 Document* document = m_frame->document();
1005 if (!isNone() || !(blink::hasEditableStyle(*document))) 1005 if (!computeVisibleSelectionInDOMTreeDeprecated().isNone() ||
1006 !(blink::hasEditableStyle(*document)))
1006 return; 1007 return;
1007 1008
1008 Element* documentElement = document->documentElement(); 1009 Element* documentElement = document->documentElement();
1009 if (!documentElement) 1010 if (!documentElement)
1010 return; 1011 return;
1011 if (HTMLBodyElement* body = 1012 if (HTMLBodyElement* body =
1012 Traversal<HTMLBodyElement>::firstChild(*documentElement)) { 1013 Traversal<HTMLBodyElement>::firstChild(*documentElement)) {
1013 setSelection(SelectionInDOMTree::Builder() 1014 setSelection(SelectionInDOMTree::Builder()
1014 .collapse(firstPositionInOrBeforeNode(body)) 1015 .collapse(firstPositionInOrBeforeNode(body))
1015 .build()); 1016 .build());
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 return m_granularityStrategy.get(); 1097 return m_granularityStrategy.get();
1097 1098
1098 if (strategyType == SelectionStrategy::Direction) 1099 if (strategyType == SelectionStrategy::Direction)
1099 m_granularityStrategy = WTF::makeUnique<DirectionGranularityStrategy>(); 1100 m_granularityStrategy = WTF::makeUnique<DirectionGranularityStrategy>();
1100 else 1101 else
1101 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>(); 1102 m_granularityStrategy = WTF::makeUnique<CharacterGranularityStrategy>();
1102 return m_granularityStrategy.get(); 1103 return m_granularityStrategy.get();
1103 } 1104 }
1104 1105
1105 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) { 1106 void FrameSelection::moveRangeSelectionExtent(const IntPoint& contentsPoint) {
1106 if (isNone()) 1107 if (computeVisibleSelectionInDOMTreeDeprecated().isNone())
1107 return; 1108 return;
1108 1109
1109 VisibleSelection newSelection = 1110 VisibleSelection newSelection =
1110 granularityStrategy()->updateExtent(contentsPoint, m_frame); 1111 granularityStrategy()->updateExtent(contentsPoint, m_frame);
1111 setSelection(newSelection, HandleVisibility::Visible, 1112 setSelection(newSelection, HandleVisibility::Visible,
1112 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle | 1113 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle |
1113 FrameSelection::DoNotClearStrategy | UserTriggered, 1114 FrameSelection::DoNotClearStrategy | UserTriggered,
1114 CursorAlignOnScroll::IfNeeded, CharacterGranularity); 1115 CursorAlignOnScroll::IfNeeded, CharacterGranularity);
1115 } 1116 }
1116 1117
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1175 } 1176 }
1176 1177
1177 void showTree(const blink::FrameSelection* sel) { 1178 void showTree(const blink::FrameSelection* sel) {
1178 if (sel) 1179 if (sel)
1179 sel->showTreeForThis(); 1180 sel->showTreeForThis();
1180 else 1181 else
1181 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1182 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1182 } 1183 }
1183 1184
1184 #endif 1185 #endif
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/core/editing/FrameSelection.h ('k') | third_party/WebKit/Source/core/editing/FrameSelectionTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698