OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved. | 2 * Copyright (C) 2005, 2006, 2007, 2008 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 22 matching lines...) Expand all Loading... |
33 #include "core/editing/BreakBlockquoteCommand.h" | 33 #include "core/editing/BreakBlockquoteCommand.h" |
34 #include "core/editing/Editor.h" | 34 #include "core/editing/Editor.h" |
35 #include "core/editing/FrameSelection.h" | 35 #include "core/editing/FrameSelection.h" |
36 #include "core/editing/InsertLineBreakCommand.h" | 36 #include "core/editing/InsertLineBreakCommand.h" |
37 #include "core/editing/InsertParagraphSeparatorCommand.h" | 37 #include "core/editing/InsertParagraphSeparatorCommand.h" |
38 #include "core/editing/InsertTextCommand.h" | 38 #include "core/editing/InsertTextCommand.h" |
39 #include "core/editing/SpellChecker.h" | 39 #include "core/editing/SpellChecker.h" |
40 #include "core/editing/VisiblePosition.h" | 40 #include "core/editing/VisiblePosition.h" |
41 #include "core/editing/VisibleUnits.h" | 41 #include "core/editing/VisibleUnits.h" |
42 #include "core/editing/htmlediting.h" | 42 #include "core/editing/htmlediting.h" |
| 43 #include "core/frame/FrameProtector.h" |
43 #include "core/frame/LocalFrame.h" | 44 #include "core/frame/LocalFrame.h" |
44 #include "core/html/HTMLBRElement.h" | 45 #include "core/html/HTMLBRElement.h" |
45 #include "core/rendering/RenderObject.h" | 46 #include "core/rendering/RenderObject.h" |
46 | 47 |
47 namespace blink { | 48 namespace blink { |
48 | 49 |
49 using namespace HTMLNames; | 50 using namespace HTMLNames; |
50 | 51 |
51 class TypingCommandLineOperation | 52 class TypingCommandLineOperation |
52 { | 53 { |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 | 163 |
163 if (!text.isEmpty()) | 164 if (!text.isEmpty()) |
164 document.frame()->spellChecker().updateMarkersForWordsAffectedByEditing(
isSpaceOrNewline(text[0])); | 165 document.frame()->spellChecker().updateMarkersForWordsAffectedByEditing(
isSpaceOrNewline(text[0])); |
165 | 166 |
166 insertText(document, text, frame->selection().selection(), options, composit
ion); | 167 insertText(document, text, frame->selection().selection(), options, composit
ion); |
167 } | 168 } |
168 | 169 |
169 // FIXME: We shouldn't need to take selectionForInsertion. It should be identica
l to FrameSelection's current selection. | 170 // FIXME: We shouldn't need to take selectionForInsertion. It should be identica
l to FrameSelection's current selection. |
170 void TypingCommand::insertText(Document& document, const String& text, const Vis
ibleSelection& selectionForInsertion, Options options, TextCompositionType compo
sitionType) | 171 void TypingCommand::insertText(Document& document, const String& text, const Vis
ibleSelection& selectionForInsertion, Options options, TextCompositionType compo
sitionType) |
171 { | 172 { |
172 RefPtr<LocalFrame> frame = document.frame(); | 173 LocalFrame* frame = document.frame(); |
| 174 FrameProtector protect(frame); |
173 ASSERT(frame); | 175 ASSERT(frame); |
174 | 176 |
175 VisibleSelection currentSelection = frame->selection().selection(); | 177 VisibleSelection currentSelection = frame->selection().selection(); |
176 | 178 |
177 String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion
, compositionType == TextCompositionUpdate); | 179 String newText = dispatchBeforeTextInsertedEvent(text, selectionForInsertion
, compositionType == TextCompositionUpdate); |
178 | 180 |
179 // Set the starting and ending selection appropriately if we are using a sel
ection | 181 // Set the starting and ending selection appropriately if we are using a sel
ection |
180 // that is different from the current selection. In the future, we should c
hange EditCommand | 182 // that is different from the current selection. In the future, we should c
hange EditCommand |
181 // to deal with custom selections in a general way that can be used by all o
f the commands. | 183 // to deal with custom selections in a general way that can be used by all o
f the commands. |
182 if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandI
fStillOpenForTyping(frame.get())) { | 184 if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandI
fStillOpenForTyping(frame)) { |
183 if (lastTypingCommand->endingSelection() != selectionForInsertion) { | 185 if (lastTypingCommand->endingSelection() != selectionForInsertion) { |
184 lastTypingCommand->setStartingSelection(selectionForInsertion); | 186 lastTypingCommand->setStartingSelection(selectionForInsertion); |
185 lastTypingCommand->setEndingSelection(selectionForInsertion); | 187 lastTypingCommand->setEndingSelection(selectionForInsertion); |
186 } | 188 } |
187 | 189 |
188 lastTypingCommand->setCompositionType(compositionType); | 190 lastTypingCommand->setCompositionType(compositionType); |
189 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); | 191 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); |
190 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellC
hecking); | 192 lastTypingCommand->setShouldPreventSpellChecking(options & PreventSpellC
hecking); |
191 lastTypingCommand->insertText(newText, options & SelectInsertedText); | 193 lastTypingCommand->insertText(newText, options & SelectInsertedText); |
192 return; | 194 return; |
193 } | 195 } |
194 | 196 |
195 RefPtrWillBeRawPtr<TypingCommand> cmd = TypingCommand::create(document, Inse
rtText, newText, options, compositionType); | 197 RefPtrWillBeRawPtr<TypingCommand> cmd = TypingCommand::create(document, Inse
rtText, newText, options, compositionType); |
196 applyTextInsertionCommand(frame.get(), cmd, selectionForInsertion, currentSe
lection); | 198 applyTextInsertionCommand(frame, cmd, selectionForInsertion, currentSelectio
n); |
197 } | 199 } |
198 | 200 |
199 void TypingCommand::insertLineBreak(Document& document, Options options) | 201 void TypingCommand::insertLineBreak(Document& document, Options options) |
200 { | 202 { |
201 if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandI
fStillOpenForTyping(document.frame())) { | 203 if (RefPtrWillBeRawPtr<TypingCommand> lastTypingCommand = lastTypingCommandI
fStillOpenForTyping(document.frame())) { |
202 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); | 204 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); |
203 lastTypingCommand->insertLineBreak(); | 205 lastTypingCommand->insertLineBreak(); |
204 return; | 206 return; |
205 } | 207 } |
206 | 208 |
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 ASSERT_NOT_REACHED(); | 626 ASSERT_NOT_REACHED(); |
625 m_preservesTypingStyle = false; | 627 m_preservesTypingStyle = false; |
626 } | 628 } |
627 | 629 |
628 bool TypingCommand::isTypingCommand() const | 630 bool TypingCommand::isTypingCommand() const |
629 { | 631 { |
630 return true; | 632 return true; |
631 } | 633 } |
632 | 634 |
633 } // namespace blink | 635 } // namespace blink |
OLD | NEW |