Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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 Loading... | |
| 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(); | 787 RefPtrWillBeRawPtr<Range> ALLOW_UNUSED range = selection.toNormalizedRange() ; |
|
tkent
2014/04/04 01:56:56
I wonder if we can remove it.
Yuta Kitamura
2014/04/04 02:37:25
It's probably OK to completely remove this line.
sof
2014/04/04 05:32:02
Great, will do that - it wasn't clear if it had a
sof
2014/04/04 07:33:23
Now done.
| |
| 788 | 788 |
| 789 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[ 0])); | 789 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[ 0])); |
| 790 | 790 |
| 791 // Get the selection to use for the event that triggered this insertText. | 791 // 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 | 792 // If the event handler changed the selection, we may want to use a differen t selection |
| 793 // that is contained in the event target. | 793 // that is contained in the event target. |
| 794 selection = selectionForCommand(triggeringEvent); | 794 selection = selectionForCommand(triggeringEvent); |
| 795 if (selection.isContentEditable()) { | 795 if (selection.isContentEditable()) { |
| 796 if (Node* selectionStart = selection.start().deprecatedNode()) { | 796 if (Node* selectionStart = selection.start().deprecatedNode()) { |
| 797 RefPtr<Document> document(selectionStart->document()); | 797 RefPtr<Document> document(selectionStart->document()); |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 843 | 843 |
| 844 return true; | 844 return true; |
| 845 } | 845 } |
| 846 | 846 |
| 847 void Editor::cut() | 847 void Editor::cut() |
| 848 { | 848 { |
| 849 if (tryDHTMLCut()) | 849 if (tryDHTMLCut()) |
| 850 return; // DHTML did the whole operation | 850 return; // DHTML did the whole operation |
| 851 if (!canCut()) | 851 if (!canCut()) |
| 852 return; | 852 return; |
| 853 RefPtr<Range> selection = selectedRange(); | 853 RefPtrWillBeRawPtr<Range> selection = selectedRange(); |
| 854 if (shouldDeleteRange(selection.get())) { | 854 if (shouldDeleteRange(selection.get())) { |
| 855 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 855 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 856 String plainText = m_frame.selectedTextForClipboard(); | 856 String plainText = m_frame.selectedTextForClipboard(); |
| 857 if (enclosingTextFormControl(m_frame.selection().start())) { | 857 if (enclosingTextFormControl(m_frame.selection().start())) { |
| 858 Pasteboard::generalPasteboard()->writePlainText(plainText, | 858 Pasteboard::generalPasteboard()->writePlainText(plainText, |
| 859 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); | 859 canSmartCopyOrDelete() ? Pasteboard::CanSmartReplace : Pasteboar d::CannotSmartReplace); |
| 860 } else { | 860 } else { |
| 861 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText); | 861 writeSelectionToPasteboard(Pasteboard::generalPasteboard(), selectio n.get(), plainText); |
| 862 } | 862 } |
| 863 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); | 863 deleteSelectionWithSmartDelete(canSmartCopyOrDelete()); |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 987 | 987 |
| 988 // Make a selection that goes back one character and forward two characters. | 988 // Make a selection that goes back one character and forward two characters. |
| 989 VisiblePosition caret = selection.visibleStart(); | 989 VisiblePosition caret = selection.visibleStart(); |
| 990 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); | 990 VisiblePosition next = isEndOfParagraph(caret) ? caret : caret.next(); |
| 991 VisiblePosition previous = next.previous(); | 991 VisiblePosition previous = next.previous(); |
| 992 if (next == previous) | 992 if (next == previous) |
| 993 return; | 993 return; |
| 994 previous = previous.previous(); | 994 previous = previous.previous(); |
| 995 if (!inSameParagraph(next, previous)) | 995 if (!inSameParagraph(next, previous)) |
| 996 return; | 996 return; |
| 997 RefPtr<Range> range = makeRange(previous, next); | 997 RefPtrWillBeRawPtr<Range> range = makeRange(previous, next); |
| 998 if (!range) | 998 if (!range) |
| 999 return; | 999 return; |
| 1000 VisibleSelection newSelection(range.get(), DOWNSTREAM); | 1000 VisibleSelection newSelection(range.get(), DOWNSTREAM); |
| 1001 | 1001 |
| 1002 // Transpose the two characters. | 1002 // Transpose the two characters. |
| 1003 String text = plainText(range.get()); | 1003 String text = plainText(range.get()); |
| 1004 if (text.length() != 2) | 1004 if (text.length() != 2) |
| 1005 return; | 1005 return; |
| 1006 String transposed = text.right(1) + text.left(1); | 1006 String transposed = text.right(1) + text.left(1); |
| 1007 | 1007 |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1108 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) | 1108 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool wrapFlag, bool startInSelection) |
| 1109 { | 1109 { |
| 1110 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; | 1110 FindOptions options = (forward ? 0 : Backwards) | (caseFlag ? 0 : CaseInsens itive) | (wrapFlag ? WrapAround : 0) | (startInSelection ? StartInSelection : 0) ; |
| 1111 return findString(target, options); | 1111 return findString(target, options); |
| 1112 } | 1112 } |
| 1113 | 1113 |
| 1114 bool Editor::findString(const String& target, FindOptions options) | 1114 bool Editor::findString(const String& target, FindOptions options) |
| 1115 { | 1115 { |
| 1116 VisibleSelection selection = m_frame.selection().selection(); | 1116 VisibleSelection selection = m_frame.selection().selection(); |
| 1117 | 1117 |
| 1118 RefPtr<Range> resultRange = rangeOfString(target, selection.firstRange().get (), options); | 1118 RefPtrWillBeRawPtr<Range> resultRange = rangeOfString(target, selection.firs tRange().get(), options); |
| 1119 | 1119 |
| 1120 if (!resultRange) | 1120 if (!resultRange) |
| 1121 return false; | 1121 return false; |
| 1122 | 1122 |
| 1123 m_frame.selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR EAM)); | 1123 m_frame.selection().setSelection(VisibleSelection(resultRange.get(), DOWNSTR EAM)); |
| 1124 m_frame.selection().revealSelection(); | 1124 m_frame.selection().revealSelection(); |
| 1125 return true; | 1125 return true; |
| 1126 } | 1126 } |
| 1127 | 1127 |
| 1128 PassRefPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Ran ge* previousMatch, FindOptions options) | 1128 PassRefPtrWillBeRawPtr<Range> Editor::findStringAndScrollToVisible(const String& target, Range* previousMatch, FindOptions options) |
| 1129 { | 1129 { |
| 1130 RefPtr<Range> nextMatch = rangeOfString(target, previousMatch, options); | 1130 RefPtrWillBeRawPtr<Range> nextMatch = rangeOfString(target, previousMatch, o ptions); |
| 1131 if (!nextMatch) | 1131 if (!nextMatch) |
| 1132 return nullptr; | 1132 return nullptr; |
| 1133 | 1133 |
| 1134 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(), | 1134 nextMatch->firstNode()->renderer()->scrollRectToVisible(nextMatch->boundingB ox(), |
| 1135 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed); | 1135 ScrollAlignment::alignCenterIfNeeded, ScrollAlignment::alignCenterIfNeed ed); |
| 1136 | 1136 |
| 1137 return nextMatch.release(); | 1137 return nextMatch.release(); |
| 1138 } | 1138 } |
| 1139 | 1139 |
| 1140 PassRefPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRa nge, FindOptions options) | 1140 PassRefPtrWillBeRawPtr<Range> Editor::rangeOfString(const String& target, Range* referenceRange, FindOptions options) |
| 1141 { | 1141 { |
| 1142 if (target.isEmpty()) | 1142 if (target.isEmpty()) |
| 1143 return nullptr; | 1143 return nullptr; |
| 1144 | 1144 |
| 1145 // Start from an edge of the reference range, if there's a reference range t hat's not in shadow content. Which edge | 1145 // 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. | 1146 // 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())); | 1147 RefPtrWillBeRawPtr<Range> searchRange(rangeOfContents(m_frame.document())); |
| 1148 | 1148 |
| 1149 bool forward = !(options & Backwards); | 1149 bool forward = !(options & Backwards); |
| 1150 bool startInReferenceRange = referenceRange && (options & StartInSelection); | 1150 bool startInReferenceRange = referenceRange && (options & StartInSelection); |
| 1151 if (referenceRange) { | 1151 if (referenceRange) { |
| 1152 if (forward) | 1152 if (forward) |
| 1153 searchRange->setStart(startInReferenceRange ? referenceRange->startP osition() : referenceRange->endPosition()); | 1153 searchRange->setStart(startInReferenceRange ? referenceRange->startP osition() : referenceRange->endPosition()); |
| 1154 else | 1154 else |
| 1155 searchRange->setEnd(startInReferenceRange ? referenceRange->endPosit ion() : referenceRange->startPosition()); | 1155 searchRange->setEnd(startInReferenceRange ? referenceRange->endPosit ion() : referenceRange->startPosition()); |
| 1156 } | 1156 } |
| 1157 | 1157 |
| 1158 RefPtr<Node> shadowTreeRoot = referenceRange && referenceRange->startContain er() ? referenceRange->startContainer()->nonBoundaryShadowTreeRootNode() : 0; | 1158 RefPtr<Node> shadowTreeRoot = referenceRange && referenceRange->startContain er() ? referenceRange->startContainer()->nonBoundaryShadowTreeRootNode() : 0; |
| 1159 if (shadowTreeRoot) { | 1159 if (shadowTreeRoot) { |
| 1160 if (forward) | 1160 if (forward) |
| 1161 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChild ren()); | 1161 searchRange->setEnd(shadowTreeRoot.get(), shadowTreeRoot->countChild ren()); |
| 1162 else | 1162 else |
| 1163 searchRange->setStart(shadowTreeRoot.get(), 0); | 1163 searchRange->setStart(shadowTreeRoot.get(), 0); |
| 1164 } | 1164 } |
| 1165 | 1165 |
| 1166 RefPtr<Range> resultRange(findPlainText(searchRange.get(), target, options)) ; | 1166 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. | 1167 // 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. | 1168 // 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. | 1169 // 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)) { | 1170 if (startInReferenceRange && areRangesEqual(VisibleSelection(resultRange.get ()).toNormalizedRange().get(), referenceRange)) { |
| 1171 searchRange = rangeOfContents(m_frame.document()); | 1171 searchRange = rangeOfContents(m_frame.document()); |
| 1172 if (forward) | 1172 if (forward) |
| 1173 searchRange->setStart(referenceRange->endPosition()); | 1173 searchRange->setStart(referenceRange->endPosition()); |
| 1174 else | 1174 else |
| 1175 searchRange->setEnd(referenceRange->startPosition()); | 1175 searchRange->setEnd(referenceRange->startPosition()); |
| 1176 | 1176 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1229 return m_frame.spellChecker(); | 1229 return m_frame.spellChecker(); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 void Editor::toggleOverwriteModeEnabled() | 1232 void Editor::toggleOverwriteModeEnabled() |
| 1233 { | 1233 { |
| 1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 } // namespace WebCore | 1238 } // namespace WebCore |
| OLD | NEW |