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

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

Issue 23819007: Have Node::document() return a reference instead of a pointer (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Rebase on master Created 7 years, 3 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 | Annotate | Revision Log
« no previous file with comments | « Source/core/editing/EditingStyle.cpp ('k') | Source/core/editing/EditorCommand.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) 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 820 matching lines...) Expand 10 before | Expand all | Expand 10 after
831 831
832 if (!text.isEmpty()) 832 if (!text.isEmpty())
833 updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0])); 833 updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[0]));
834 834
835 // Get the selection to use for the event that triggered this insertText. 835 // Get the selection to use for the event that triggered this insertText.
836 // If the event handler changed the selection, we may want to use a differen t selection 836 // If the event handler changed the selection, we may want to use a differen t selection
837 // that is contained in the event target. 837 // that is contained in the event target.
838 selection = selectionForCommand(triggeringEvent); 838 selection = selectionForCommand(triggeringEvent);
839 if (selection.isContentEditable()) { 839 if (selection.isContentEditable()) {
840 if (Node* selectionStart = selection.start().deprecatedNode()) { 840 if (Node* selectionStart = selection.start().deprecatedNode()) {
841 RefPtr<Document> document = selectionStart->document(); 841 RefPtr<Document> document = &selectionStart->document();
842 842
843 // Insert the text 843 // Insert the text
844 TypingCommand::Options options = 0; 844 TypingCommand::Options options = 0;
845 if (selectInsertedText) 845 if (selectInsertedText)
846 options |= TypingCommand::SelectInsertedText; 846 options |= TypingCommand::SelectInsertedText;
847 TypingCommand::insertText(document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextComposi tionConfirm : TypingCommand::TextCompositionNone); 847 TypingCommand::insertText(document.get(), text, selection, options, triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextComposi tionConfirm : TypingCommand::TextCompositionNone);
848 848
849 // Reveal the current selection 849 // Reveal the current selection
850 if (Frame* editedFrame = document->frame()) { 850 if (Frame* editedFrame = document->frame()) {
851 if (Page* page = editedFrame->page()) 851 if (Page* page = editedFrame->page())
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
974 // clear the "start new kill ring sequence" setting, because it was set to t rue 974 // clear the "start new kill ring sequence" setting, because it was set to t rue
975 // when the selection was updated by deleting the range 975 // when the selection was updated by deleting the range
976 setStartNewKillRingSequence(false); 976 setStartNewKillRingSequence(false);
977 } 977 }
978 978
979 void Editor::simplifyMarkup(Node* startNode, Node* endNode) 979 void Editor::simplifyMarkup(Node* startNode, Node* endNode)
980 { 980 {
981 if (!startNode) 981 if (!startNode)
982 return; 982 return;
983 if (endNode) { 983 if (endNode) {
984 if (startNode->document() != endNode->document()) 984 if (&startNode->document() != &endNode->document())
985 return; 985 return;
986 // check if start node is before endNode 986 // check if start node is before endNode
987 Node* node = startNode; 987 Node* node = startNode;
988 while (node && node != endNode) 988 while (node && node != endNode)
989 node = NodeTraversal::next(node); 989 node = NodeTraversal::next(node);
990 if (!node) 990 if (!node)
991 return; 991 return;
992 } 992 }
993 993
994 applyCommand(SimplifyMarkupCommand::create(m_frame->document(), startNode, ( endNode) ? NodeTraversal::next(endNode) : 0)); 994 applyCommand(SimplifyMarkupCommand::create(m_frame->document(), startNode, ( endNode) ? NodeTraversal::next(endNode) : 0));
(...skipping 600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1595 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset; 1595 bool resultEndsAtAmbiguousBoundary = ambiguousBoundaryOffset >= 0 && res ultLocation + resultLength == ambiguousBoundaryOffset;
1596 1596
1597 // Only mark misspelling if: 1597 // Only mark misspelling if:
1598 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false. 1598 // 1. Current text checking isn't done for autocorrection, in which case shouldMarkSpelling is false.
1599 // 2. Result falls within spellingRange. 1599 // 2. Result falls within spellingRange.
1600 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark 1600 // 3. The word in question doesn't end at an ambiguous boundary. For ins tance, we would not mark
1601 // "wouldn'" as misspelled right after apostrophe is typed. 1601 // "wouldn'" as misspelled right after apostrophe is typed.
1602 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) { 1602 if (shouldMarkSpelling && result->type == TextCheckingTypeSpelling && re sultLocation >= paragraph.checkingStart() && resultLocation + resultLength <= sp ellingRangeEndOffset && !resultEndsAtAmbiguousBoundary) {
1603 ASSERT(resultLength > 0 && resultLocation >= 0); 1603 ASSERT(resultLength > 0 && resultLocation >= 0);
1604 RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength); 1604 RefPtr<Range> misspellingRange = paragraph.subrange(resultLocation, resultLength);
1605 misspellingRange->startContainer()->document()->markers()->addMarker (misspellingRange.get(), DocumentMarker::Spelling, result->replacement, result-> hash); 1605 misspellingRange->startContainer()->document().markers()->addMarker( misspellingRange.get(), DocumentMarker::Spelling, result->replacement, result->h ash);
1606 } else if (shouldMarkGrammar && result->type == TextCheckingTypeGrammar && paragraph.checkingRangeCovers(resultLocation, resultLength)) { 1606 } else if (shouldMarkGrammar && result->type == TextCheckingTypeGrammar && paragraph.checkingRangeCovers(resultLocation, resultLength)) {
1607 ASSERT(resultLength > 0 && resultLocation >= 0); 1607 ASSERT(resultLength > 0 && resultLocation >= 0);
1608 for (unsigned j = 0; j < result->details.size(); j++) { 1608 for (unsigned j = 0; j < result->details.size(); j++) {
1609 const GrammarDetail* detail = &result->details[j]; 1609 const GrammarDetail* detail = &result->details[j];
1610 ASSERT(detail->length > 0 && detail->location >= 0); 1610 ASSERT(detail->length > 0 && detail->location >= 0);
1611 if (paragraph.checkingRangeCovers(resultLocation + detail->locat ion, detail->length)) { 1611 if (paragraph.checkingRangeCovers(resultLocation + detail->locat ion, detail->length)) {
1612 RefPtr<Range> badGrammarRange = paragraph.subrange(resultLoc ation + detail->location, detail->length); 1612 RefPtr<Range> badGrammarRange = paragraph.subrange(resultLoc ation + detail->location, detail->length);
1613 badGrammarRange->startContainer()->document()->markers()->ad dMarker(badGrammarRange.get(), DocumentMarker::Grammar, detail->userDescription, result->hash); 1613 badGrammarRange->startContainer()->document().markers()->add Marker(badGrammarRange.get(), DocumentMarker::Grammar, detail->userDescription, result->hash);
1614 } 1614 }
1615 } 1615 }
1616 } 1616 }
1617 } 1617 }
1618 1618
1619 if (selectionChanged) { 1619 if (selectionChanged) {
1620 TextCheckingParagraph extendedParagraph(paragraph); 1620 TextCheckingParagraph extendedParagraph(paragraph);
1621 // Restore the caret position if we have made any replacements 1621 // Restore the caret position if we have made any replacements
1622 extendedParagraph.expandRangeToNextEnd(); 1622 extendedParagraph.expandRangeToNextEnd();
1623 if (restoreSelectionAfterChange && selectionOffset >= 0 && selectionOffs et <= extendedParagraph.rangeLength()) { 1623 if (restoreSelectionAfterChange && selectionOffset >= 0 && selectionOffs et <= extendedParagraph.rangeLength()) {
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
2202 return WebCore::unifiedTextCheckerEnabled(m_frame); 2202 return WebCore::unifiedTextCheckerEnabled(m_frame);
2203 } 2203 }
2204 2204
2205 void Editor::toggleOverwriteModeEnabled() 2205 void Editor::toggleOverwriteModeEnabled()
2206 { 2206 {
2207 m_overwriteModeEnabled = !m_overwriteModeEnabled; 2207 m_overwriteModeEnabled = !m_overwriteModeEnabled;
2208 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled); 2208 frame().selection()->setShouldShowBlockCursor(m_overwriteModeEnabled);
2209 }; 2209 };
2210 2210
2211 } // namespace WebCore 2211 } // namespace WebCore
OLDNEW
« no previous file with comments | « Source/core/editing/EditingStyle.cpp ('k') | Source/core/editing/EditorCommand.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698