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

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

Issue 2698793003: Get rid of redundant layout tree update related to selection (Closed)
Patch Set: 2017-02-17T16:13:56 selectionTypeWithLegacyGranularity() Created 3 years, 10 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 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
223 if (shouldClearTypingStyle) 223 if (shouldClearTypingStyle)
224 m_frame->editor().clearTypingStyle(); 224 m_frame->editor().clearTypingStyle();
225 225
226 const SelectionInDOMTree oldSelectionInDOMTree = 226 const SelectionInDOMTree oldSelectionInDOMTree =
227 m_selectionEditor->selectionInDOMTree(); 227 m_selectionEditor->selectionInDOMTree();
228 if (oldSelectionInDOMTree == newSelection) 228 if (oldSelectionInDOMTree == newSelection)
229 return; 229 return;
230 m_selectionEditor->setSelection(newSelection); 230 m_selectionEditor->setSelection(newSelection);
231 scheduleVisualUpdateForPaintInvalidationIfNeeded(); 231 scheduleVisualUpdateForPaintInvalidationIfNeeded();
232 232
233 // TODO(yosin): The use of updateStyleAndLayoutIgnorePendingStylesheets
234 // needs to be audited. see http://crbug.com/590369 for more details.
235 document().updateStyleAndLayoutIgnorePendingStylesheets();
236
237 const Document& currentDocument = document(); 233 const Document& currentDocument = document();
238 // TODO(yosin): We should get rid of unsued |options| for 234 // TODO(yosin): We should get rid of unsued |options| for
239 // |Editor::respondToChangedSelection()|. 235 // |Editor::respondToChangedSelection()|.
240 // Note: Since, setting focus can modify DOM tree, we should use 236 // Note: Since, setting focus can modify DOM tree, we should use
241 // |oldSelection| before setting focus 237 // |oldSelection| before setting focus
242 m_frame->editor().respondToChangedSelection( 238 m_frame->editor().respondToChangedSelection(
243 createVisibleSelection(oldSelectionInDOMTree).start(), options); 239 oldSelectionInDOMTree.computeStartPosition(), options);
244 DCHECK_EQ(currentDocument, document()); 240 DCHECK_EQ(currentDocument, document());
245 241
246 if (!computeVisibleSelectionInDOMTree().isNone() && 242 if (!selectionInDOMTree().isNone() && !(options & DoNotSetFocus)) {
247 !(options & DoNotSetFocus)) {
248 setFocusedNodeIfNeeded(); 243 setFocusedNodeIfNeeded();
249 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and 244 // |setFocusedNodeIfNeeded()| dispatches sync events "FocusOut" and
250 // "FocusIn", |m_frame| may associate to another document. 245 // "FocusIn", |m_frame| may associate to another document.
251 if (!isAvailable() || document() != currentDocument) { 246 if (!isAvailable() || document() != currentDocument) {
252 // Once we get test case to reach here, we should change this 247 // Once we get test case to reach here, we should change this
253 // if-statement to |DCHECK()|. 248 // if-statement to |DCHECK()|.
254 NOTREACHED(); 249 NOTREACHED();
255 return; 250 return;
256 } 251 }
257 } 252 }
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 // Find the parent frame; if there is none, then we have nothing to do. 774 // Find the parent frame; if there is none, then we have nothing to do.
780 Frame* parent = m_frame->tree().parent(); 775 Frame* parent = m_frame->tree().parent();
781 if (!parent) 776 if (!parent)
782 return; 777 return;
783 Page* page = m_frame->page(); 778 Page* page = m_frame->page();
784 if (!page) 779 if (!page)
785 return; 780 return;
786 781
787 // Check if the selection contains the entire frame contents; if not, then 782 // Check if the selection contains the entire frame contents; if not, then
788 // there is nothing to do. 783 // there is nothing to do.
789 if (!isRange()) 784 if (selectionInDOMTree().selectionTypeWithLegacyGranularity() !=
785 RangeSelection) {
790 return; 786 return;
787 }
791 788
792 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 789 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
793 // needs to be audited. See http://crbug.com/590369 for more details. 790 // needs to be audited. See http://crbug.com/590369 for more details.
794 document().updateStyleAndLayoutIgnorePendingStylesheets(); 791 document().updateStyleAndLayoutIgnorePendingStylesheets();
795 792
796 if (!isStartOfDocument(selection().visibleStart())) 793 if (!isStartOfDocument(selection().visibleStart()))
797 return; 794 return;
798 if (!isEndOfDocument(selection().visibleEnd())) 795 if (!isEndOfDocument(selection().visibleEnd()))
799 return; 796 return;
800 797
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
929 return m_selectionEditor->firstRange(); 926 return m_selectionEditor->firstRange();
930 } 927 }
931 928
932 bool FrameSelection::isInPasswordField() const { 929 bool FrameSelection::isInPasswordField() const {
933 TextControlElement* textControl = enclosingTextControl(start()); 930 TextControlElement* textControl = enclosingTextControl(start());
934 return isHTMLInputElement(textControl) && 931 return isHTMLInputElement(textControl) &&
935 toHTMLInputElement(textControl)->type() == InputTypeNames::password; 932 toHTMLInputElement(textControl)->type() == InputTypeNames::password;
936 } 933 }
937 934
938 void FrameSelection::notifyAccessibilityForSelectionChange() { 935 void FrameSelection::notifyAccessibilityForSelectionChange() {
939 if (selection().start().isNotNull() && selection().end().isNotNull()) { 936 if (selectionInDOMTree().isNone())
940 if (AXObjectCache* cache = document().existingAXObjectCache()) 937 return;
941 cache->selectionChanged(selection().start().computeContainerNode()); 938 AXObjectCache* cache = document().existingAXObjectCache();
942 } 939 if (!cache)
940 return;
941 const Position& start = selectionInDOMTree().computeStartPosition();
942 cache->selectionChanged(start.computeContainerNode());
943 } 943 }
944 944
945 void FrameSelection::notifyCompositorForSelectionChange() { 945 void FrameSelection::notifyCompositorForSelectionChange() {
946 if (!RuntimeEnabledFeatures::compositedSelectionUpdateEnabled()) 946 if (!RuntimeEnabledFeatures::compositedSelectionUpdateEnabled())
947 return; 947 return;
948 948
949 scheduleVisualUpdate(); 949 scheduleVisualUpdate();
950 } 950 }
951 951
952 void FrameSelection::notifyEventHandlerForSelectionChange() { 952 void FrameSelection::notifyEventHandlerForSelectionChange() {
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
1038 } 1038 }
1039 1039
1040 void FrameSelection::updateAppearance() { 1040 void FrameSelection::updateAppearance() {
1041 DCHECK(!m_frame->contentLayoutItem().isNull()); 1041 DCHECK(!m_frame->contentLayoutItem().isNull());
1042 m_frameCaret->scheduleVisualUpdateForPaintInvalidationIfNeeded(); 1042 m_frameCaret->scheduleVisualUpdateForPaintInvalidationIfNeeded();
1043 m_pendingSelection->setHasPendingSelection(); 1043 m_pendingSelection->setHasPendingSelection();
1044 } 1044 }
1045 1045
1046 void FrameSelection::notifyLayoutObjectOfSelectionChange( 1046 void FrameSelection::notifyLayoutObjectOfSelectionChange(
1047 EUserTriggered userTriggered) { 1047 EUserTriggered userTriggered) {
1048 if (TextControlElement* textControl = enclosingTextControl(start())) 1048 TextControlElement* textControl =
1049 textControl->selectionChanged(userTriggered == UserTriggered); 1049 enclosingTextControl(selectionInDOMTree().base());
1050 if (!textControl)
1051 return;
1052 textControl->selectionChanged(userTriggered == UserTriggered);
1050 } 1053 }
1051 1054
1052 // Helper function that tells whether a particular node is an element that has 1055 // Helper function that tells whether a particular node is an element that has
1053 // an entire LocalFrame and FrameView, a <frame>, <iframe>, or <object>. 1056 // an entire LocalFrame and FrameView, a <frame>, <iframe>, or <object>.
1054 static bool isFrameElement(const Node* n) { 1057 static bool isFrameElement(const Node* n) {
1055 if (!n) 1058 if (!n)
1056 return false; 1059 return false;
1057 LayoutObject* layoutObject = n->layoutObject(); 1060 LayoutObject* layoutObject = n->layoutObject();
1058 if (!layoutObject || !layoutObject->isLayoutPart()) 1061 if (!layoutObject || !layoutObject->isLayoutPart())
1059 return false; 1062 return false;
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after
1407 } 1410 }
1408 1411
1409 void showTree(const blink::FrameSelection* sel) { 1412 void showTree(const blink::FrameSelection* sel) {
1410 if (sel) 1413 if (sel)
1411 sel->showTreeForThis(); 1414 sel->showTreeForThis();
1412 else 1415 else
1413 LOG(INFO) << "Cannot showTree for <null> FrameSelection."; 1416 LOG(INFO) << "Cannot showTree for <null> FrameSelection.";
1414 } 1417 }
1415 1418
1416 #endif 1419 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698