| 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 30 matching lines...) Expand all Loading... |
| 41 #include "htmlediting.h" | 41 #include "htmlediting.h" |
| 42 #include "visible_units.h" | 42 #include "visible_units.h" |
| 43 | 43 |
| 44 namespace WebCore { | 44 namespace WebCore { |
| 45 | 45 |
| 46 TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, con
st String &textToInsert, bool selectInsertedText, TextGranularity granularity, b
ool killRing) | 46 TypingCommand::TypingCommand(Document *document, ETypingCommand commandType, con
st String &textToInsert, bool selectInsertedText, TextGranularity granularity, b
ool killRing) |
| 47 : CompositeEditCommand(document), | 47 : CompositeEditCommand(document), |
| 48 m_commandType(commandType), | 48 m_commandType(commandType), |
| 49 m_textToInsert(textToInsert), | 49 m_textToInsert(textToInsert), |
| 50 m_openForMoreTyping(true), | 50 m_openForMoreTyping(true), |
| 51 m_applyEditing(false), | |
| 52 m_selectInsertedText(selectInsertedText), | 51 m_selectInsertedText(selectInsertedText), |
| 53 m_smartDelete(false), | 52 m_smartDelete(false), |
| 54 m_granularity(granularity), | 53 m_granularity(granularity), |
| 55 m_killRing(killRing), | 54 m_killRing(killRing), |
| 56 m_openedByBackwardDelete(false) | 55 m_openedByBackwardDelete(false) |
| 57 { | 56 { |
| 58 } | 57 } |
| 59 | 58 |
| 60 void TypingCommand::deleteSelection(Document* document, bool smartDelete) | 59 void TypingCommand::deleteSelection(Document* document, bool smartDelete) |
| 61 { | 60 { |
| (...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 293 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary); | 292 VisiblePosition p1 = startOfWord(previous, LeftWordIfOnBoundary); |
| 294 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary); | 293 VisiblePosition p2 = startOfWord(start, LeftWordIfOnBoundary); |
| 295 if (p1 != p2) | 294 if (p1 != p2) |
| 296 document()->frame()->editor()->markMisspellingsAfterTypingToPosition
(p1); | 295 document()->frame()->editor()->markMisspellingsAfterTypingToPosition
(p1); |
| 297 } | 296 } |
| 298 } | 297 } |
| 299 | 298 |
| 300 void TypingCommand::typingAddedToOpenCommand() | 299 void TypingCommand::typingAddedToOpenCommand() |
| 301 { | 300 { |
| 302 markMisspellingsAfterTyping(); | 301 markMisspellingsAfterTyping(); |
| 303 // Do not apply editing to the frame on the first time through. | 302 document()->frame()->editor()->appliedEditing(this); |
| 304 // The frame will get told in the same way as all other commands. | |
| 305 // But since this command stays open and is used for additional typing, | |
| 306 // we need to tell the frame here as other commands are added. | |
| 307 if (m_applyEditing) | |
| 308 document()->frame()->editor()->appliedEditing(this); | |
| 309 m_applyEditing = true; | |
| 310 } | 303 } |
| 311 | 304 |
| 312 void TypingCommand::insertText(const String &text, bool selectInsertedText) | 305 void TypingCommand::insertText(const String &text, bool selectInsertedText) |
| 313 { | 306 { |
| 314 // FIXME: Need to implement selectInsertedText for cases where more than one
insert is involved. | 307 // FIXME: Need to implement selectInsertedText for cases where more than one
insert is involved. |
| 315 // This requires support from insertTextRunWithoutNewlines and insertParagra
phSeparator for extending | 308 // This requires support from insertTextRunWithoutNewlines and insertParagra
phSeparator for extending |
| 316 // an existing selection; at the moment they can either put the caret after
what's inserted or | 309 // an existing selection; at the moment they can either put the caret after
what's inserted or |
| 317 // select what's inserted, but there's no way to "extend selection" to inclu
de both an old selection | 310 // select what's inserted, but there's no way to "extend selection" to inclu
de both an old selection |
| 318 // that ends just before where we want to insert text and the newly inserted
text. | 311 // that ends just before where we want to insert text and the newly inserted
text. |
| 319 int offset = 0; | 312 int offset = 0; |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 // We can't let the VisibleSelection class's validation kick in
or it'll adjust for us based on | 422 // We can't let the VisibleSelection class's validation kick in
or it'll adjust for us based on |
| 430 // the current state of the document and we'll get the wrong res
ult. | 423 // the current state of the document and we'll get the wrong res
ult. |
| 431 selectionAfterUndo.setWithoutValidation(startingSelection().end(
), selectionToDelete.extent()); | 424 selectionAfterUndo.setWithoutValidation(startingSelection().end(
), selectionToDelete.extent()); |
| 432 break; | 425 break; |
| 433 } | 426 } |
| 434 case VisibleSelection::NoSelection: | 427 case VisibleSelection::NoSelection: |
| 435 ASSERT_NOT_REACHED(); | 428 ASSERT_NOT_REACHED(); |
| 436 break; | 429 break; |
| 437 } | 430 } |
| 438 | 431 |
| 439 if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteS
election(selectionToDelete)) { | 432 ASSERT(!selectionToDelete.isNone()); |
| 440 if (killRing) | 433 if (selectionToDelete.isNone()) |
| 441 document()->frame()->editor()->addToKillRing(selectionToDelete.toNor
malizedRange().get(), false); | 434 return; |
| 442 // Make undo select everything that has been deleted, unless an undo wil
l undo more than just this deletion. | 435 |
| 443 // FIXME: This behaves like TextEdit except for the case where you open
with text insertion and then delete | 436 if (selectionToDelete.isCaret() || !document()->frame()->shouldDeleteSelecti
on(selectionToDelete)) |
| 444 // more text than you insert. In that case all of the text that was aro
und originally should be selected. | 437 return; |
| 445 if (m_openedByBackwardDelete) | 438 |
| 446 setStartingSelection(selectionAfterUndo); | 439 if (killRing) |
| 447 CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete); | 440 document()->frame()->editor()->addToKillRing(selectionToDelete.toNormali
zedRange().get(), false); |
| 448 setSmartDelete(false); | 441 // Make undo select everything that has been deleted, unless an undo will un
do more than just this deletion. |
| 449 typingAddedToOpenCommand(); | 442 // FIXME: This behaves like TextEdit except for the case where you open with
text insertion and then delete |
| 450 } | 443 // more text than you insert. In that case all of the text that was around
originally should be selected. |
| 444 if (m_openedByBackwardDelete) |
| 445 setStartingSelection(selectionAfterUndo); |
| 446 CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete); |
| 447 setSmartDelete(false); |
| 448 typingAddedToOpenCommand(); |
| 451 } | 449 } |
| 452 | 450 |
| 453 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool ki
llRing) | 451 void TypingCommand::forwardDeleteKeyPressed(TextGranularity granularity, bool ki
llRing) |
| 454 { | 452 { |
| 455 VisibleSelection selectionToDelete; | 453 VisibleSelection selectionToDelete; |
| 456 VisibleSelection selectionAfterUndo; | 454 VisibleSelection selectionAfterUndo; |
| 457 | 455 |
| 458 switch (endingSelection().selectionType()) { | 456 switch (endingSelection().selectionType()) { |
| 459 case VisibleSelection::RangeSelection: | 457 case VisibleSelection::RangeSelection: |
| 460 selectionToDelete = endingSelection(); | 458 selectionToDelete = endingSelection(); |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 } | 505 } |
| 508 selectionAfterUndo.setWithoutValidation(startingSelection().star
t(), extent); | 506 selectionAfterUndo.setWithoutValidation(startingSelection().star
t(), extent); |
| 509 } | 507 } |
| 510 break; | 508 break; |
| 511 } | 509 } |
| 512 case VisibleSelection::NoSelection: | 510 case VisibleSelection::NoSelection: |
| 513 ASSERT_NOT_REACHED(); | 511 ASSERT_NOT_REACHED(); |
| 514 break; | 512 break; |
| 515 } | 513 } |
| 516 | 514 |
| 517 if (selectionToDelete.isCaretOrRange() && document()->frame()->shouldDeleteS
election(selectionToDelete)) { | 515 ASSERT(!selectionToDelete.isNone()); |
| 518 if (killRing) | 516 if (selectionToDelete.isNone()) |
| 519 document()->frame()->editor()->addToKillRing(selectionToDelete.toNor
malizedRange().get(), false); | 517 return; |
| 520 // make undo select what was deleted | 518 |
| 521 setStartingSelection(selectionAfterUndo); | 519 if (selectionToDelete.isCaret() || !document()->frame()->shouldDeleteSelecti
on(selectionToDelete)) |
| 522 CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete); | 520 return; |
| 523 setSmartDelete(false); | 521 |
| 524 typingAddedToOpenCommand(); | 522 if (killRing) |
| 525 } | 523 document()->frame()->editor()->addToKillRing(selectionToDelete.toNormali
zedRange().get(), false); |
| 524 // make undo select what was deleted |
| 525 setStartingSelection(selectionAfterUndo); |
| 526 CompositeEditCommand::deleteSelection(selectionToDelete, m_smartDelete); |
| 527 setSmartDelete(false); |
| 528 typingAddedToOpenCommand(); |
| 526 } | 529 } |
| 527 | 530 |
| 528 void TypingCommand::deleteSelection(bool smartDelete) | 531 void TypingCommand::deleteSelection(bool smartDelete) |
| 529 { | 532 { |
| 530 CompositeEditCommand::deleteSelection(smartDelete); | 533 CompositeEditCommand::deleteSelection(smartDelete); |
| 531 typingAddedToOpenCommand(); | 534 typingAddedToOpenCommand(); |
| 532 } | 535 } |
| 533 | 536 |
| 534 bool TypingCommand::preservesTypingStyle() const | 537 bool TypingCommand::preservesTypingStyle() const |
| 535 { | 538 { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 548 return false; | 551 return false; |
| 549 } | 552 } |
| 550 | 553 |
| 551 bool TypingCommand::isTypingCommand() const | 554 bool TypingCommand::isTypingCommand() const |
| 552 { | 555 { |
| 553 return true; | 556 return true; |
| 554 } | 557 } |
| 555 | 558 |
| 556 } // namespace WebCore | 559 } // namespace WebCore |
| 557 | 560 |
| OLD | NEW |