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

Side by Side Diff: Source/core/editing/Editor.cpp

Issue 224113002: Oilpan: move Range object to the oilpan heap. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Use STACK_ALLOCATED() + incorporate ager's overview of macros in this area. Created 6 years, 8 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) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved. 2 * Copyright (C) 2006, 2007, 2008, 2011 Apple Inc. All rights reserved.
3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies) 3 * Copyright (C) 2008 Nokia Corporation and/or its subsidiary(-ies)
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 * 1. Redistributions of source code must retain the above copyright 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
110 VisibleSelection Editor::selectionForCommand(Event* event) 110 VisibleSelection Editor::selectionForCommand(Event* event)
111 { 111 {
112 VisibleSelection selection = m_frame.selection().selection(); 112 VisibleSelection selection = m_frame.selection().selection();
113 if (!event) 113 if (!event)
114 return selection; 114 return selection;
115 // If the target is a text control, and the current selection is outside of its shadow tree, 115 // If the target is a text control, and the current selection is outside of its shadow tree,
116 // then use the saved selection for that text control. 116 // then use the saved selection for that text control.
117 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start()); 117 HTMLTextFormControlElement* textFormControlOfSelectionStart = enclosingTextF ormControl(selection.start());
118 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target( )->toNode()) : 0; 118 HTMLTextFormControlElement* textFromControlOfTarget = isHTMLTextFormControlE lement(*event->target()->toNode()) ? toHTMLTextFormControlElement(event->target( )->toNode()) : 0;
119 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro lOfTarget != textFormControlOfSelectionStart)) { 119 if (textFromControlOfTarget && (selection.start().isNull() || textFromContro lOfTarget != textFormControlOfSelectionStart)) {
120 if (RefPtr<Range> range = textFromControlOfTarget->selection()) 120 if (RefPtrWillBeRawPtr<Range> range = textFromControlOfTarget->selection ())
121 return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirecti onal()); 121 return VisibleSelection(range.get(), DOWNSTREAM, selection.isDirecti onal());
122 } 122 }
123 return selection; 123 return selection;
124 } 124 }
125 125
126 // Function considers Mac editing behavior a fallback when Page or Settings is n ot available. 126 // Function considers Mac editing behavior a fallback when Page or Settings is n ot available.
127 EditingBehavior Editor::behavior() const 127 EditingBehavior Editor::behavior() const
128 { 128 {
129 if (!m_frame.settings()) 129 if (!m_frame.settings())
130 return EditingBehavior(EditingMacBehavior); 130 return EditingBehavior(EditingMacBehavior);
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
380 } 380 }
381 381
382 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard) 382 void Editor::pasteAsPlainTextWithPasteboard(Pasteboard* pasteboard)
383 { 383 {
384 String text = pasteboard->plainText(); 384 String text = pasteboard->plainText();
385 pasteAsPlainText(text, canSmartReplaceWithPasteboard(pasteboard)); 385 pasteAsPlainText(text, canSmartReplaceWithPasteboard(pasteboard));
386 } 386 }
387 387
388 void Editor::pasteWithPasteboard(Pasteboard* pasteboard) 388 void Editor::pasteWithPasteboard(Pasteboard* pasteboard)
389 { 389 {
390 RefPtr<Range> range = selectedRange(); 390 RefPtrWillBeRawPtr<Range> range = selectedRange();
391 RefPtr<DocumentFragment> fragment; 391 RefPtr<DocumentFragment> fragment;
392 bool chosePlainText = false; 392 bool chosePlainText = false;
393 393
394 if (pasteboard->isHTMLAvailable()) { 394 if (pasteboard->isHTMLAvailable()) {
395 unsigned fragmentStart = 0; 395 unsigned fragmentStart = 0;
396 unsigned fragmentEnd = 0; 396 unsigned fragmentEnd = 0;
397 KURL url; 397 KURL url;
398 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd); 398 String markup = pasteboard->readHTML(url, fragmentStart, fragmentEnd);
399 if (!markup.isEmpty()) { 399 if (!markup.isEmpty()) {
400 ASSERT(m_frame.document()); 400 ASSERT(m_frame.document());
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
502 if (m_frame.selection().isInPasswordField() || !spellChecker().isContinuousS pellCheckingEnabled()) 502 if (m_frame.selection().isInPasswordField() || !spellChecker().isContinuousS pellCheckingEnabled())
503 return; 503 return;
504 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(m_frame.selection(). rootEditableElement()); 504 spellChecker().chunkAndMarkAllMisspellingsAndBadGrammar(m_frame.selection(). rootEditableElement());
505 } 505 }
506 506
507 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace) 507 void Editor::replaceSelectionWithText(const String& text, bool selectReplacement , bool smartReplace)
508 { 508 {
509 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true); 509 replaceSelectionWithFragment(createFragmentFromText(selectedRange().get(), t ext), selectReplacement, smartReplace, true);
510 } 510 }
511 511
512 PassRefPtr<Range> Editor::selectedRange() 512 PassRefPtrWillBeRawPtr<Range> Editor::selectedRange()
513 { 513 {
514 return m_frame.selection().toNormalizedRange(); 514 return m_frame.selection().toNormalizedRange();
515 } 515 }
516 516
517 bool Editor::shouldDeleteRange(Range* range) const 517 bool Editor::shouldDeleteRange(Range* range) const
518 { 518 {
519 if (!range || range->collapsed(IGNORE_EXCEPTION)) 519 if (!range || range->collapsed(IGNORE_EXCEPTION))
520 return false; 520 return false;
521 521
522 return canDeleteRange(range); 522 return canDeleteRange(range);
(...skipping 254 matching lines...) Expand 10 before | Expand all | Expand 10 after
777 } 777 }
778 778
779 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent) 779 bool Editor::insertTextWithoutSendingTextEvent(const String& text, bool selectIn sertedText, TextEvent* triggeringEvent)
780 { 780 {
781 if (text.isEmpty()) 781 if (text.isEmpty())
782 return false; 782 return false;
783 783
784 VisibleSelection selection = selectionForCommand(triggeringEvent); 784 VisibleSelection selection = selectionForCommand(triggeringEvent);
785 if (!selection.isContentEditable()) 785 if (!selection.isContentEditable())
786 return false; 786 return false;
787 RefPtr<Range> range = selection.toNormalizedRange();
Mads Ager (chromium) 2014/04/04 07:48:38 Range is unused, are we sure this is not a protect
788 787
789 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[ 0])); 788 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[ 0]));
790 789
791 // Get the selection to use for the event that triggered this insertText. 790 // Get the selection to use for the event that triggered this insertText.
792 // If the event handler changed the selection, we may want to use a differen t selection 791 // If the event handler changed the selection, we may want to use a differen t selection
793 // that is contained in the event target. 792 // that is contained in the event target.
794 selection = selectionForCommand(triggeringEvent); 793 selection = selectionForCommand(triggeringEvent);
795 if (selection.isContentEditable()) { 794 if (selection.isContentEditable()) {
796 if (Node* selectionStart = selection.start().deprecatedNode()) { 795 if (Node* selectionStart = selection.start().deprecatedNode()) {
797 RefPtr<Document> document(selectionStart->document()); 796 RefPtr<Document> document(selectionStart->document());
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
843 842
844 return true; 843 return true;
845 } 844 }
846 845
847 void Editor::cut() 846 void Editor::cut()
848 { 847 {
849 if (tryDHTMLCut()) 848 if (tryDHTMLCut())
850 return; // DHTML did the whole operation 849 return; // DHTML did the whole operation
851 if (!canCut()) 850 if (!canCut())
852 return; 851 return;
853 RefPtr<Range> selection = selectedRange(); 852 RefPtrWillBeRawPtr<Range> selection = selectedRange();
854 if (shouldDeleteRange(selection.get())) { 853 if (shouldDeleteRange(selection.get())) {
855 spellChecker().updateMarkersForWordsAffectedByEditing(true); 854 spellChecker().updateMarkersForWordsAffectedByEditing(true);
856 String plainText = m_frame.selectedTextForClipboard(); 855 String plainText = m_frame.selectedTextForClipboard();
857 if (enclosingTextFormControl(m_frame.selection().start())) { 856 if (enclosingTextFormControl(m_frame.selection().start())) {
858 Pasteboard::generalPasteboard()->writePlainText(plainText, 857 Pasteboard::generalPasteboard()->writePlainText(plainText,
859 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); 858 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace);
860 } else { 859 } else {
861 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText); 860 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText);
862 } 861 }
863 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); 862 deleteSelectionWithSmartDelete(canSmartCopyOrDelete());
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
987 986
988 // Make a selection that goes back one character and forward two characters. 987 // Make a selection that goes back one character and forward two characters.
989 VisiblePosition caret = selection.visibleStart(); 988 VisiblePosition caret = selection.visibleStart();
990 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); 989 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next();
991 VisiblePosition previous = next.previous(); 990 VisiblePosition previous = next.previous();
992 if (next == previous) 991 if (next == previous)
993 return; 992 return;
994 previous = previous.previous(); 993 previous = previous.previous();
995 if (!inSameParagraph(next, previous)) 994 if (!inSameParagraph(next, previous))
996 return; 995 return;
997 RefPtr<Range> range = makeRange(previous, next); 996 RefPtrWillBeRawPtr<Range> range = makeRange(previous, next);
998 if (!range) 997 if (!range)
999 return; 998 return;
1000 VisibleSelection newSelection(range.get(), DOWNSTREAM); 999 VisibleSelection newSelection(range.get(), DOWNSTREAM);
1001 1000
1002 // Transpose the two characters. 1001 // Transpose the two characters.
1003 String text = plainText(range.get()); 1002 String text = plainText(range.get());
1004 if (text.length() != 2) 1003 if (text.length() != 2)
1005 return; 1004 return;
1006 String transposed = text.right(1) + text.left(1); 1005 String transposed = text.right(1) + text.left(1);
1007 1006
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after
1108 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) 1107 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection)
1109 { 1108 {
1110 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; 1109 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ;
1111 return findString(target, options); 1110 return findString(target, options);
1112 } 1111 }
1113 1112
1114 bool Editor::findString(const String& target, FindOptions options) 1113 bool Editor::findString(const String& target, FindOptions options)
1115 { 1114 {
1116 VisibleSelection selection = m_frame.selection().selection(); 1115 VisibleSelection selection = m_frame.selection().selection();
1117 1116
1118 RefPtr<Range> resultRange = rangeOfString(target, selection.firstRange().get (), options); 1117 RefPtrWillBeRawPtr<Range> resultRange = rangeOfString(target, selection.firs tRange().get(), options);
1119 1118
1120 if (!resultRange) 1119 if (!resultRange)
1121 return false; 1120 return false;
1122 1121
1123 m_frame.selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR EAM)); 1122 m_frame.selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR EAM));
1124 m_frame.selection().revealSelection(); 1123 m_frame.selection().revealSelection();
1125 return true; 1124 return true;
1126 } 1125 }
1127 1126
1128 PassRefPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Ran ge* previousMatch, FindOptions options) 1127 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* previousMatch, FindOptions options)
1129 { 1128 {
1130 RefPtr<Range> nextMatch = rangeOfString(target, previousMatch, options); 1129 RefPtrWillBeRawPtr<Range> nextMatch = rangeOfString(target, previousMatch, o ptions);
1131 if (!nextMatch) 1130 if (!nextMatch)
1132 return nullptr; 1131 return nullptr;
1133 1132
1134 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(), 1133 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(),
1135 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed); 1134 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed);
1136 1135
1137 return nextMatch.release(); 1136 return nextMatch.release();
1138 } 1137 }
1139 1138
1140 PassRefPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRa nge, FindOptions options) 1139 PassRefPtrWillBeRawPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRange, FindOptions options)
1141 { 1140 {
1142 if (target.isEmpty()) 1141 if (target.isEmpty())
1143 return nullptr; 1142 return nullptr;
1144 1143
1145 // Start from an edge of the reference range, if there's a reference range t hat's not in shadow content. Which edge 1144 // Start from an edge of the reference range, if there's a reference range t hat's not in shadow content. Which edge
1146 // is used depends on whether we're searching forward or backward, and wheth er startInSelection is set. 1145 // is used depends on whether we're searching forward or backward, and wheth er startInSelection is set.
1147 RefPtr<Range> searchRange(rangeOfContents(m_frame.document())); 1146 RefPtrWillBeRawPtr<Range> searchRange(rangeOfContents(m_frame.document()));
1148 1147
1149 bool forward = !(options & Backwards); 1148 bool forward = !(options & Backwards);
1150 bool startInReferenceRange = referenceRange && (options & StartInSelection); 1149 bool startInReferenceRange = referenceRange && (options & StartInSelection);
1151 if (referenceRange) { 1150 if (referenceRange) {
1152 if (forward) 1151 if (forward)
1153 searchRange->setStart(startInReferenceRange ? referenceRange->startP osition() : referenceRange->endPosition()); 1152 searchRange->setStart(startInReferenceRange ? referenceRange->startP osition() : referenceRange->endPosition());
1154 else 1153 else
1155 searchRange->setEnd(startInReferenceRange ? referenceRange->endPosit ion() : referenceRange->startPosition()); 1154 searchRange->setEnd(startInReferenceRange ? referenceRange->endPosit ion() : referenceRange->startPosition());
1156 } 1155 }
1157 1156
1158 RefPtr<Node> shadowTreeRoot = referenceRange && referenceRange->startContain er() ? referenceRange->startContainer()->nonBoundaryShadowTreeRootNode() : 0; 1157 RefPtr<Node> shadowTreeRoot = referenceRange && referenceRange->startContain er() ? referenceRange->startContainer()->nonBoundaryShadowTreeRootNode() : 0;
1159 if (shadowTreeRoot) { 1158 if (shadowTreeRoot) {
1160 if (forward) 1159 if (forward)
1161 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChild ren()); 1160 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChild ren());
1162 else 1161 else
1163 searchRange->setStart(shadowTreeRoot.get(), 0); 1162 searchRange->setStart(shadowTreeRoot.get(), 0);
1164 } 1163 }
1165 1164
1166 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, options)) ; 1165 RefPtrWillBeRawPtr<Range> resultRange(findPlainText(searchRange.get(), targe t, options));
1167 // If we started in the reference range and the found range exactly matches the reference range, find again. 1166 // If we started in the reference range and the found range exactly matches the reference range, find again.
1168 // Build a selection with the found range to remove collapsed whitespace. 1167 // Build a selection with the found range to remove collapsed whitespace.
1169 // Compare ranges instead of selection objects to ignore the way that the cu rrent selection was made. 1168 // Compare ranges instead of selection objects to ignore the way that the cu rrent selection was made.
1170 if (startInReferenceRange && areRangesEqual(VisibleSelection(resultRange.get ()).toNormalizedRange().get(), referenceRange)) { 1169 if (startInReferenceRange && areRangesEqual(VisibleSelection(resultRange.get ()).toNormalizedRange().get(), referenceRange)) {
1171 searchRange = rangeOfContents(m_frame.document()); 1170 searchRange = rangeOfContents(m_frame.document());
1172 if (forward) 1171 if (forward)
1173 searchRange->setStart(referenceRange->endPosition()); 1172 searchRange->setStart(referenceRange->endPosition());
1174 else 1173 else
1175 searchRange->setEnd(referenceRange->startPosition()); 1174 searchRange->setEnd(referenceRange->startPosition());
1176 1175
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1229 return m_frame.spellChecker(); 1228 return m_frame.spellChecker();
1230 } 1229 }
1231 1230
1232 void Editor::toggleOverwriteModeEnabled() 1231 void Editor::toggleOverwriteModeEnabled()
1233 { 1232 {
1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; 1233 m_overwriteModeEnabled = !m_overwriteModeEnabled;
1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); 1234 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled);
1236 } 1235 }
1237 1236
1238 } // namespace WebCore 1237 } // namespace WebCore
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698