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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
203 ASSERT(document); | 203 ASSERT(document); |
204 if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenFo
rTyping(document->frame())) { | 204 if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenFo
rTyping(document->frame())) { |
205 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); | 205 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); |
206 lastTypingCommand->insertLineBreak(); | 206 lastTypingCommand->insertLineBreak(); |
207 return; | 207 return; |
208 } | 208 } |
209 | 209 |
210 applyCommand(TypingCommand::create(document, InsertLineBreak, "", options)); | 210 applyCommand(TypingCommand::create(document, InsertLineBreak, "", options)); |
211 } | 211 } |
212 | 212 |
213 void TypingCommand::insertParagraphSeparatorInQuotedContent(Document *document) | |
214 { | |
215 ASSERT(document); | |
216 if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenFo
rTyping(document->frame())) { | |
217 lastTypingCommand->insertParagraphSeparatorInQuotedContent(); | |
218 return; | |
219 } | |
220 | |
221 applyCommand(TypingCommand::create(document, InsertParagraphSeparatorInQuote
dContent)); | |
222 } | |
223 | |
224 void TypingCommand::insertParagraphSeparator(Document *document, Options options
) | 213 void TypingCommand::insertParagraphSeparator(Document *document, Options options
) |
225 { | 214 { |
226 ASSERT(document); | 215 ASSERT(document); |
227 if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenFo
rTyping(document->frame())) { | 216 if (RefPtr<TypingCommand> lastTypingCommand = lastTypingCommandIfStillOpenFo
rTyping(document->frame())) { |
228 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); | 217 lastTypingCommand->setShouldRetainAutocorrectionIndicator(options & Reta
inAutocorrectionIndicator); |
229 lastTypingCommand->insertParagraphSeparator(); | 218 lastTypingCommand->insertParagraphSeparator(); |
230 return; | 219 return; |
231 } | 220 } |
232 | 221 |
233 applyCommand(TypingCommand::create(document, InsertParagraphSeparator, "", o
ptions)); | 222 applyCommand(TypingCommand::create(document, InsertParagraphSeparator, "", o
ptions)); |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
268 return; | 257 return; |
269 case ForwardDeleteKey: | 258 case ForwardDeleteKey: |
270 forwardDeleteKeyPressed(m_granularity, m_killRing); | 259 forwardDeleteKeyPressed(m_granularity, m_killRing); |
271 return; | 260 return; |
272 case InsertLineBreak: | 261 case InsertLineBreak: |
273 insertLineBreak(); | 262 insertLineBreak(); |
274 return; | 263 return; |
275 case InsertParagraphSeparator: | 264 case InsertParagraphSeparator: |
276 insertParagraphSeparator(); | 265 insertParagraphSeparator(); |
277 return; | 266 return; |
278 case InsertParagraphSeparatorInQuotedContent: | |
279 insertParagraphSeparatorInQuotedContent(); | |
280 return; | |
281 case InsertText: | 267 case InsertText: |
282 insertText(m_textToInsert, m_selectInsertedText); | 268 insertText(m_textToInsert, m_selectInsertedText); |
283 return; | 269 return; |
284 } | 270 } |
285 | 271 |
286 ASSERT_NOT_REACHED(); | 272 ASSERT_NOT_REACHED(); |
287 } | 273 } |
288 | 274 |
289 EditAction TypingCommand::editingAction() const | 275 EditAction TypingCommand::editingAction() const |
290 { | 276 { |
(...skipping 22 matching lines...) Expand all Loading... |
313 // see if typing made a new word that is not in the current selection. Basic
ally, you | 299 // see if typing made a new word that is not in the current selection. Basic
ally, you |
314 // get this by being at the end of a word and typing a space. | 300 // get this by being at the end of a word and typing a space. |
315 VisiblePosition start(endingSelection().start(), endingSelection().affinity(
)); | 301 VisiblePosition start(endingSelection().start(), endingSelection().affinity(
)); |
316 VisiblePosition previous = start.previous(); | 302 VisiblePosition previous = start.previous(); |
317 if (previous.isNotNull()) { | 303 if (previous.isNotNull()) { |
318 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary); | 304 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary); |
319 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary); | 305 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary); |
320 if (p1 != p2) { | 306 if (p1 != p2) { |
321 RefPtr<Range> range = makeRange(p1, p2); | 307 RefPtr<Range> range = makeRange(p1, p2); |
322 String strippedPreviousWord; | 308 String strippedPreviousWord; |
323 if (range && (commandType == TypingCommand::InsertText || commandTyp
e == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParag
raphSeparator || commandType == TypingCommand::InsertParagraphSeparatorInQuotedC
ontent)) | 309 if (range && (commandType == TypingCommand::InsertText || commandTyp
e == TypingCommand::InsertLineBreak || commandType == TypingCommand::InsertParag
raphSeparator)) |
324 strippedPreviousWord = plainText(range.get()).stripWhiteSpace(); | 310 strippedPreviousWord = plainText(range.get()).stripWhiteSpace(); |
325 frame->editor()->markMisspellingsAfterTypingToWord(p1, endingSelecti
on(), !strippedPreviousWord.isEmpty()); | 311 frame->editor()->markMisspellingsAfterTypingToWord(p1, endingSelecti
on(), !strippedPreviousWord.isEmpty()); |
326 } else if (commandType == TypingCommand::InsertText) | 312 } else if (commandType == TypingCommand::InsertText) |
327 frame->editor()->startAlternativeTextUITimer(); | 313 frame->editor()->startAlternativeTextUITimer(); |
328 } | 314 } |
329 } | 315 } |
330 | 316 |
331 void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedT
yping) | 317 void TypingCommand::typingAddedToOpenCommand(ETypingCommand commandTypeForAddedT
yping) |
332 { | 318 { |
333 Frame* frame = document()->frame(); | 319 Frame* frame = document()->frame(); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 | 366 |
381 void TypingCommand::insertParagraphSeparator() | 367 void TypingCommand::insertParagraphSeparator() |
382 { | 368 { |
383 if (!canAppendNewLineFeedToSelection(endingSelection())) | 369 if (!canAppendNewLineFeedToSelection(endingSelection())) |
384 return; | 370 return; |
385 | 371 |
386 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document()))
; | 372 applyCommandToComposite(InsertParagraphSeparatorCommand::create(document()))
; |
387 typingAddedToOpenCommand(InsertParagraphSeparator); | 373 typingAddedToOpenCommand(InsertParagraphSeparator); |
388 } | 374 } |
389 | 375 |
390 void TypingCommand::insertParagraphSeparatorInQuotedContent() | |
391 { | |
392 // If the selection starts inside a table, just insert the paragraph separat
or normally | |
393 // Breaking the blockquote would also break apart the table, which is uneces
sary when inserting a newline | |
394 if (enclosingNodeOfType(endingSelection().start(), &isTableStructureNode)) { | |
395 insertParagraphSeparator(); | |
396 return; | |
397 } | |
398 | |
399 applyCommandToComposite(BreakBlockquoteCommand::create(document())); | |
400 typingAddedToOpenCommand(InsertParagraphSeparatorInQuotedContent); | |
401 } | |
402 | |
403 bool TypingCommand::makeEditableRootEmpty() | 376 bool TypingCommand::makeEditableRootEmpty() |
404 { | 377 { |
405 Element* root = endingSelection().rootEditableElement(); | 378 Element* root = endingSelection().rootEditableElement(); |
406 if (!root || !root->firstChild()) | 379 if (!root || !root->firstChild()) |
407 return false; | 380 return false; |
408 | 381 |
409 if (root->firstChild() == root->lastChild() && root->firstElementChild() &&
root->firstElementChild()->hasTagName(brTag)) { | 382 if (root->firstChild() == root->lastChild() && root->firstElementChild() &&
root->firstElementChild()->hasTagName(brTag)) { |
410 // If there is a single child and it could be a placeholder, leave it al
one. | 383 // If there is a single child and it could be a placeholder, leave it al
one. |
411 if (root->renderer() && root->renderer()->isBlockFlow()) | 384 if (root->renderer() && root->renderer()->isBlockFlow()) |
412 return false; | 385 return false; |
(...skipping 18 matching lines...) Expand all Loading... |
431 | 404 |
432 VisibleSelection selectionToDelete; | 405 VisibleSelection selectionToDelete; |
433 VisibleSelection selectionAfterUndo; | 406 VisibleSelection selectionAfterUndo; |
434 | 407 |
435 switch (endingSelection().selectionType()) { | 408 switch (endingSelection().selectionType()) { |
436 case VisibleSelection::RangeSelection: | 409 case VisibleSelection::RangeSelection: |
437 selectionToDelete = endingSelection(); | 410 selectionToDelete = endingSelection(); |
438 selectionAfterUndo = selectionToDelete; | 411 selectionAfterUndo = selectionToDelete; |
439 break; | 412 break; |
440 case VisibleSelection::CaretSelection: { | 413 case VisibleSelection::CaretSelection: { |
441 // After breaking out of an empty mail blockquote, we still want continu
e with the deletion | |
442 // so actual content will get deleted, and not just the quote style. | |
443 if (breakOutOfEmptyMailBlockquotedParagraph()) | |
444 typingAddedToOpenCommand(DeleteKey); | |
445 | |
446 m_smartDelete = false; | 414 m_smartDelete = false; |
447 | 415 |
448 FrameSelection selection; | 416 FrameSelection selection; |
449 selection.setSelection(endingSelection()); | 417 selection.setSelection(endingSelection()); |
450 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, gr
anularity); | 418 selection.modify(FrameSelection::AlterationExtend, DirectionBackward, gr
anularity); |
451 if (killRing && selection.isCaret() && granularity != CharacterGranulari
ty) | 419 if (killRing && selection.isCaret() && granularity != CharacterGranulari
ty) |
452 selection.modify(FrameSelection::AlterationExtend, DirectionBackward
, CharacterGranularity); | 420 selection.modify(FrameSelection::AlterationExtend, DirectionBackward
, CharacterGranularity); |
453 | 421 |
454 if (endingSelection().visibleStart().previous(CannotCrossEditingBoundary
).isNull()) { | 422 if (endingSelection().visibleStart().previous(CannotCrossEditingBoundary
).isNull()) { |
455 // When the caret is at the start of the editable area in an empty l
ist item, break out of the list item. | 423 // When the caret is at the start of the editable area in an empty l
ist item, break out of the list item. |
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
624 void TypingCommand::updatePreservesTypingStyle(ETypingCommand commandType) | 592 void TypingCommand::updatePreservesTypingStyle(ETypingCommand commandType) |
625 { | 593 { |
626 switch (commandType) { | 594 switch (commandType) { |
627 case DeleteSelection: | 595 case DeleteSelection: |
628 case DeleteKey: | 596 case DeleteKey: |
629 case ForwardDeleteKey: | 597 case ForwardDeleteKey: |
630 case InsertParagraphSeparator: | 598 case InsertParagraphSeparator: |
631 case InsertLineBreak: | 599 case InsertLineBreak: |
632 m_preservesTypingStyle = true; | 600 m_preservesTypingStyle = true; |
633 return; | 601 return; |
634 case InsertParagraphSeparatorInQuotedContent: | |
635 case InsertText: | 602 case InsertText: |
636 m_preservesTypingStyle = false; | 603 m_preservesTypingStyle = false; |
637 return; | 604 return; |
638 } | 605 } |
639 ASSERT_NOT_REACHED(); | 606 ASSERT_NOT_REACHED(); |
640 m_preservesTypingStyle = false; | 607 m_preservesTypingStyle = false; |
641 } | 608 } |
642 | 609 |
643 bool TypingCommand::isTypingCommand() const | 610 bool TypingCommand::isTypingCommand() const |
644 { | 611 { |
645 return true; | 612 return true; |
646 } | 613 } |
647 | 614 |
648 } // namespace WebCore | 615 } // namespace WebCore |
OLD | NEW |