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

Side by Side Diff: third_party/WebKit/Source/core/editing/DOMSelection.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, 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
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/Editor.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. 2 * Copyright (C) 2007, 2009 Apple Inc. All rights reserved.
3 * Copyright (C) 2012 Google Inc. All rights reserved. 3 * Copyright (C) 2012 Google Inc. All rights reserved.
4 * 4 *
5 * Redistribution and use in source and binary forms, with or without 5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions 6 * modification, are permitted provided that the following conditions
7 * are met: 7 * are met:
8 * 8 *
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
197 if (isCollapsed()) 197 if (isCollapsed())
198 return "Caret"; 198 return "Caret";
199 return "Range"; 199 return "Range";
200 } 200 }
201 201
202 unsigned DOMSelection::rangeCount() const { 202 unsigned DOMSelection::rangeCount() const {
203 if (!isAvailable()) 203 if (!isAvailable())
204 return 0; 204 return 0;
205 if (documentCachedRange()) 205 if (documentCachedRange())
206 return 1; 206 return 1;
207 if (frame()->selection().isNone()) 207 if (frame()
208 ->selection()
209 .computeVisibleSelectionInDOMTreeDeprecated()
210 .isNone())
208 return 0; 211 return 0;
209 // Any selection can be adjusted to Range for Document. 212 // Any selection can be adjusted to Range for Document.
210 if (isSelectionOfDocument()) 213 if (isSelectionOfDocument())
211 return 1; 214 return 1;
212 // In ShadowRoot, we need to try adjustment. 215 // In ShadowRoot, we need to try adjustment.
213 return createRangeFromSelectionEditor() ? 1 : 0; 216 return createRangeFromSelectionEditor() ? 1 : 0;
214 } 217 }
215 218
216 // https://www.w3.org/TR/selection-api/#dom-selection-collapse 219 // https://www.w3.org/TR/selection-api/#dom-selection-collapse
217 void DOMSelection::collapse(Node* node, 220 void DOMSelection::collapse(Node* node,
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and 459 // 3. Let oldAnchor and oldFocus be the context object's anchor and focus, and
457 // let newFocus be the boundary point (node, offset). 460 // let newFocus be the boundary point (node, offset).
458 const Position& oldAnchor = anchorPosition(); 461 const Position& oldAnchor = anchorPosition();
459 // TODO(tkent): Diagnostic checks for crbug.com/693578. They should be 462 // TODO(tkent): Diagnostic checks for crbug.com/693578. They should be
460 // removed before M58 branch. 463 // removed before M58 branch.
461 if (oldAnchor.isNull()) { 464 if (oldAnchor.isNull()) {
462 if (Range* range = documentCachedRange()) { 465 if (Range* range = documentCachedRange()) {
463 LOG(FATAL) 466 LOG(FATAL)
464 << "Selection has a cached Range, but anchorPosition is null. start=" 467 << "Selection has a cached Range, but anchorPosition is null. start="
465 << range->startContainer() << " end=" << range->endContainer(); 468 << range->startContainer() << " end=" << range->endContainer();
466 } else if (frame() && !frame()->selection().isNone()) { 469 } else if (frame() &&
470 !frame()
471 ->selection()
472 .computeVisibleSelectionInDOMTreeDeprecated()
473 .isNone()) {
467 LOG(FATAL) << "FrameSelection is not none, but anchorPosition is null."; 474 LOG(FATAL) << "FrameSelection is not none, but anchorPosition is null.";
468 } 475 }
469 } 476 }
470 DCHECK(!oldAnchor.isNull()); 477 DCHECK(!oldAnchor.isNull());
471 const Position newFocus(node, offset); 478 const Position newFocus(node, offset);
472 479
473 clearCachedRangeIfSelectionOfDocument(); 480 clearCachedRangeIfSelectionOfDocument();
474 481
475 // 4. Let newRange be a new range. 482 // 4. Let newRange be a new range.
476 Range* newRange = Range::create(*frame()->document()); 483 Range* newRange = Range::create(*frame()->document());
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
642 return; 649 return;
643 } 650 }
644 651
645 // The following code is necessary for 652 // The following code is necessary for
646 // editing/selection/deleteFromDocument-crash.html, which assumes 653 // editing/selection/deleteFromDocument-crash.html, which assumes
647 // deleteFromDocument() for text selection in a TEXTAREA deletes the TEXTAREA 654 // deleteFromDocument() for text selection in a TEXTAREA deletes the TEXTAREA
648 // value. 655 // value.
649 656
650 FrameSelection& selection = frame()->selection(); 657 FrameSelection& selection = frame()->selection();
651 658
652 if (selection.isNone()) 659 if (selection.computeVisibleSelectionInDOMTreeDeprecated().isNone())
653 return; 660 return;
654 661
655 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets 662 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets
656 // needs to be audited. See http://crbug.com/590369 for more details. 663 // needs to be audited. See http://crbug.com/590369 for more details.
657 // |VisibleSelection::toNormalizedEphemeralRange| requires clean layout. 664 // |VisibleSelection::toNormalizedEphemeralRange| requires clean layout.
658 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets(); 665 frame()->document()->updateStyleAndLayoutIgnorePendingStylesheets();
659 666
660 Range* selectedRange = 667 Range* selectedRange =
661 createRange(selection.computeVisibleSelectionInDOMTreeDeprecated() 668 createRange(selection.computeVisibleSelectionInDOMTreeDeprecated()
662 .toNormalizedEphemeralRange()); 669 .toNormalizedEphemeralRange());
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
800 m_treeScope->document().addConsoleMessage( 807 m_treeScope->document().addConsoleMessage(
801 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message)); 808 ConsoleMessage::create(JSMessageSource, ErrorMessageLevel, message));
802 } 809 }
803 810
804 DEFINE_TRACE(DOMSelection) { 811 DEFINE_TRACE(DOMSelection) {
805 visitor->trace(m_treeScope); 812 visitor->trace(m_treeScope);
806 ContextClient::trace(visitor); 813 ContextClient::trace(visitor);
807 } 814 }
808 815
809 } // namespace blink 816 } // namespace blink
OLDNEW
« no previous file with comments | « no previous file | third_party/WebKit/Source/core/editing/Editor.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698