| 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 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 InputEvent::InputType inputType, | 381 InputEvent::InputType inputType, |
| 382 const Position& referenceMovePosition) { | 382 const Position& referenceMovePosition) { |
| 383 if (frame().selection().isNone()) | 383 if (frame().selection().isNone()) |
| 384 return; | 384 return; |
| 385 | 385 |
| 386 const bool kMergeBlocksAfterDelete = true; | 386 const bool kMergeBlocksAfterDelete = true; |
| 387 const bool kExpandForSpecialElements = false; | 387 const bool kExpandForSpecialElements = false; |
| 388 const bool kSanitizeMarkup = true; | 388 const bool kSanitizeMarkup = true; |
| 389 DCHECK(frame().document()); | 389 DCHECK(frame().document()); |
| 390 DeleteSelectionCommand::create( | 390 DeleteSelectionCommand::create( |
| 391 *frame().document(), deleteMode == DeleteMode::Smart, | 391 *frame().document(), source, deleteMode == DeleteMode::Smart, |
| 392 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, | 392 kMergeBlocksAfterDelete, kExpandForSpecialElements, kSanitizeMarkup, |
| 393 inputType, referenceMovePosition) | 393 inputType, referenceMovePosition) |
| 394 ->apply(source); | 394 ->apply(); |
| 395 } | 395 } |
| 396 | 396 |
| 397 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { | 397 void Editor::pasteAsPlainText(const String& pastingText, bool smartReplace) { |
| 398 Element* target = findEventTargetFromSelection(); | 398 Element* target = findEventTargetFromSelection(); |
| 399 if (!target) | 399 if (!target) |
| 400 return; | 400 return; |
| 401 target->dispatchEvent(TextEvent::createForPlainTextPaste( | 401 target->dispatchEvent(TextEvent::createForPlainTextPaste( |
| 402 frame().domWindow(), pastingText, smartReplace)); | 402 frame().domWindow(), pastingText, smartReplace)); |
| 403 } | 403 } |
| 404 | 404 |
| (...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 583 ReplaceSelectionCommand::CommandOptions options = | 583 ReplaceSelectionCommand::CommandOptions options = |
| 584 ReplaceSelectionCommand::PreventNesting | | 584 ReplaceSelectionCommand::PreventNesting | |
| 585 ReplaceSelectionCommand::SanitizeFragment; | 585 ReplaceSelectionCommand::SanitizeFragment; |
| 586 if (selectReplacement) | 586 if (selectReplacement) |
| 587 options |= ReplaceSelectionCommand::SelectReplacement; | 587 options |= ReplaceSelectionCommand::SelectReplacement; |
| 588 if (smartReplace) | 588 if (smartReplace) |
| 589 options |= ReplaceSelectionCommand::SmartReplace; | 589 options |= ReplaceSelectionCommand::SmartReplace; |
| 590 if (matchStyle) | 590 if (matchStyle) |
| 591 options |= ReplaceSelectionCommand::MatchStyle; | 591 options |= ReplaceSelectionCommand::MatchStyle; |
| 592 DCHECK(frame().document()); | 592 DCHECK(frame().document()); |
| 593 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 593 ReplaceSelectionCommand::create(*frame().document(), source, fragment, |
| 594 inputType) | 594 options, inputType) |
| 595 ->apply(source); | 595 ->apply(); |
| 596 revealSelectionAfterEditingOperation(); | 596 revealSelectionAfterEditingOperation(); |
| 597 } | 597 } |
| 598 | 598 |
| 599 void Editor::replaceSelectionWithText(EditCommandSource source, | 599 void Editor::replaceSelectionWithText(EditCommandSource source, |
| 600 const String& text, | 600 const String& text, |
| 601 bool selectReplacement, | 601 bool selectReplacement, |
| 602 bool smartReplace, | 602 bool smartReplace, |
| 603 InputEvent::InputType inputType) { | 603 InputEvent::InputType inputType) { |
| 604 replaceSelectionWithFragment( | 604 replaceSelectionWithFragment( |
| 605 source, createFragmentFromText(selectedRange(), text), selectReplacement, | 605 source, createFragmentFromText(selectedRange(), text), selectReplacement, |
| 606 smartReplace, true, inputType); | 606 smartReplace, true, inputType); |
| 607 } | 607 } |
| 608 | 608 |
| 609 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. | 609 // TODO(xiaochengh): Merge it with |replaceSelectionWithFragment()|. |
| 610 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, | 610 void Editor::replaceSelectionAfterDragging(DocumentFragment* fragment, |
| 611 InsertMode insertMode, | 611 InsertMode insertMode, |
| 612 DragSourceType dragSourceType) { | 612 DragSourceType dragSourceType) { |
| 613 ReplaceSelectionCommand::CommandOptions options = | 613 ReplaceSelectionCommand::CommandOptions options = |
| 614 ReplaceSelectionCommand::SelectReplacement | | 614 ReplaceSelectionCommand::SelectReplacement | |
| 615 ReplaceSelectionCommand::PreventNesting; | 615 ReplaceSelectionCommand::PreventNesting; |
| 616 if (insertMode == InsertMode::Smart) | 616 if (insertMode == InsertMode::Smart) |
| 617 options |= ReplaceSelectionCommand::SmartReplace; | 617 options |= ReplaceSelectionCommand::SmartReplace; |
| 618 if (dragSourceType == DragSourceType::PlainTextSource) | 618 if (dragSourceType == DragSourceType::PlainTextSource) |
| 619 options |= ReplaceSelectionCommand::MatchStyle; | 619 options |= ReplaceSelectionCommand::MatchStyle; |
| 620 DCHECK(frame().document()); | 620 DCHECK(frame().document()); |
| 621 ReplaceSelectionCommand::create(*frame().document(), fragment, options, | 621 ReplaceSelectionCommand::create( |
| 622 InputEvent::InputType::InsertFromDrop) | 622 *frame().document(), EditCommandSource::kMenuOrKeyBinding, fragment, |
| 623 ->apply(EditCommandSource::kMenuOrKeyBinding); | 623 options, InputEvent::InputType::InsertFromDrop) |
| 624 ->apply(); |
| 624 } | 625 } |
| 625 | 626 |
| 626 bool Editor::deleteSelectionAfterDraggingWithEvents( | 627 bool Editor::deleteSelectionAfterDraggingWithEvents( |
| 627 Element* dragSource, | 628 Element* dragSource, |
| 628 DeleteMode deleteMode, | 629 DeleteMode deleteMode, |
| 629 const Position& referenceMovePosition) { | 630 const Position& referenceMovePosition) { |
| 630 if (!dragSource || !dragSource->isConnected()) | 631 if (!dragSource || !dragSource->isConnected()) |
| 631 return true; | 632 return true; |
| 632 | 633 |
| 633 // Dispatch 'beforeinput'. | 634 // Dispatch 'beforeinput'. |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 702 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) | 703 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) |
| 703 cache->handleEditableTextContentChanged(node); | 704 cache->handleEditableTextContentChanged(node); |
| 704 } | 705 } |
| 705 | 706 |
| 706 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 707 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 707 client().respondToChangedContents(); | 708 client().respondToChangedContents(); |
| 708 } | 709 } |
| 709 | 710 |
| 710 void Editor::removeFormattingAndStyle(EditCommandSource source) { | 711 void Editor::removeFormattingAndStyle(EditCommandSource source) { |
| 711 DCHECK(frame().document()); | 712 DCHECK(frame().document()); |
| 712 RemoveFormatCommand::create(*frame().document())->apply(source); | 713 RemoveFormatCommand::create(*frame().document(), source)->apply(); |
| 713 } | 714 } |
| 714 | 715 |
| 715 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { | 716 void Editor::registerCommandGroup(CompositeEditCommand* commandGroupWrapper) { |
| 716 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); | 717 DCHECK(commandGroupWrapper->isCommandGroupWrapper()); |
| 717 m_lastEditCommand = commandGroupWrapper; | 718 m_lastEditCommand = commandGroupWrapper; |
| 718 } | 719 } |
| 719 | 720 |
| 720 void Editor::clearLastEditCommand() { | 721 void Editor::clearLastEditCommand() { |
| 721 m_lastEditCommand.clear(); | 722 m_lastEditCommand.clear(); |
| 722 } | 723 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 739 switch (frame().selection().getSelectionType()) { | 740 switch (frame().selection().getSelectionType()) { |
| 740 case NoSelection: | 741 case NoSelection: |
| 741 // do nothing | 742 // do nothing |
| 742 break; | 743 break; |
| 743 case CaretSelection: | 744 case CaretSelection: |
| 744 computeAndSetTypingStyle(source, style, inputType); | 745 computeAndSetTypingStyle(source, style, inputType); |
| 745 break; | 746 break; |
| 746 case RangeSelection: | 747 case RangeSelection: |
| 747 if (style) { | 748 if (style) { |
| 748 DCHECK(frame().document()); | 749 DCHECK(frame().document()); |
| 749 ApplyStyleCommand::create(*frame().document(), | 750 ApplyStyleCommand::create(*frame().document(), source, |
| 750 EditingStyle::create(style), inputType) | 751 EditingStyle::create(style), inputType) |
| 751 ->apply(source); | 752 ->apply(); |
| 752 } | 753 } |
| 753 break; | 754 break; |
| 754 } | 755 } |
| 755 } | 756 } |
| 756 | 757 |
| 757 void Editor::applyParagraphStyle(EditCommandSource source, | 758 void Editor::applyParagraphStyle(EditCommandSource source, |
| 758 StylePropertySet* style, | 759 StylePropertySet* style, |
| 759 InputEvent::InputType inputType) { | 760 InputEvent::InputType inputType) { |
| 760 if (frame().selection().isNone() || !style) | 761 if (frame().selection().isNone() || !style) |
| 761 return; | 762 return; |
| 762 DCHECK(frame().document()); | 763 DCHECK(frame().document()); |
| 763 ApplyStyleCommand::create(*frame().document(), EditingStyle::create(style), | 764 ApplyStyleCommand::create(*frame().document(), source, |
| 764 inputType, ApplyStyleCommand::ForceBlockProperties) | 765 EditingStyle::create(style), inputType, |
| 765 ->apply(source); | 766 ApplyStyleCommand::ForceBlockProperties) |
| 767 ->apply(); |
| 766 } | 768 } |
| 767 | 769 |
| 768 void Editor::applyStyleToSelection(EditCommandSource source, | 770 void Editor::applyStyleToSelection(EditCommandSource source, |
| 769 StylePropertySet* style, | 771 StylePropertySet* style, |
| 770 InputEvent::InputType inputType) { | 772 InputEvent::InputType inputType) { |
| 771 if (!style || style->isEmpty() || !canEditRichly()) | 773 if (!style || style->isEmpty() || !canEditRichly()) |
| 772 return; | 774 return; |
| 773 | 775 |
| 774 applyStyle(source, style, inputType); | 776 applyStyle(source, style, inputType); |
| 775 } | 777 } |
| (...skipping 661 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1437 } | 1439 } |
| 1438 | 1440 |
| 1439 typingStyle->prepareToApplyAt( | 1441 typingStyle->prepareToApplyAt( |
| 1440 frame().selection().selection().visibleStart().deepEquivalent(), | 1442 frame().selection().selection().visibleStart().deepEquivalent(), |
| 1441 EditingStyle::PreserveWritingDirection); | 1443 EditingStyle::PreserveWritingDirection); |
| 1442 | 1444 |
| 1443 // Handle block styles, substracting these from the typing style. | 1445 // Handle block styles, substracting these from the typing style. |
| 1444 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); | 1446 EditingStyle* blockStyle = typingStyle->extractAndRemoveBlockProperties(); |
| 1445 if (!blockStyle->isEmpty()) { | 1447 if (!blockStyle->isEmpty()) { |
| 1446 DCHECK(frame().document()); | 1448 DCHECK(frame().document()); |
| 1447 ApplyStyleCommand::create(*frame().document(), blockStyle, inputType) | 1449 ApplyStyleCommand::create(*frame().document(), source, blockStyle, |
| 1448 ->apply(source); | 1450 inputType) |
| 1451 ->apply(); |
| 1449 } | 1452 } |
| 1450 | 1453 |
| 1451 // Set the remaining style as the typing style. | 1454 // Set the remaining style as the typing style. |
| 1452 frame().selection().setTypingStyle(typingStyle); | 1455 frame().selection().setTypingStyle(typingStyle); |
| 1453 } | 1456 } |
| 1454 | 1457 |
| 1455 bool Editor::findString(const String& target, FindOptions options) { | 1458 bool Editor::findString(const String& target, FindOptions options) { |
| 1456 VisibleSelection selection = frame().selection().selection(); | 1459 VisibleSelection selection = frame().selection().selection(); |
| 1457 | 1460 |
| 1458 // TODO(yosin) We should make |findRangeOfString()| to return | 1461 // TODO(yosin) We should make |findRangeOfString()| to return |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1707 } | 1710 } |
| 1708 | 1711 |
| 1709 DEFINE_TRACE(Editor) { | 1712 DEFINE_TRACE(Editor) { |
| 1710 visitor->trace(m_frame); | 1713 visitor->trace(m_frame); |
| 1711 visitor->trace(m_lastEditCommand); | 1714 visitor->trace(m_lastEditCommand); |
| 1712 visitor->trace(m_undoStack); | 1715 visitor->trace(m_undoStack); |
| 1713 visitor->trace(m_mark); | 1716 visitor->trace(m_mark); |
| 1714 } | 1717 } |
| 1715 | 1718 |
| 1716 } // namespace blink | 1719 } // namespace blink |
| OLD | NEW |