| 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 632 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 EditingStyle::styleAtSelectionStart(m_frame.selection().selection(), pro
pertyID == CSSPropertyBackgroundColor).get()); | 643 EditingStyle::styleAtSelectionStart(m_frame.selection().selection(), pro
pertyID == CSSPropertyBackgroundColor).get()); |
| 644 } | 644 } |
| 645 | 645 |
| 646 TriState Editor::selectionHasStyle(CSSPropertyID propertyID, const String& value
) const | 646 TriState Editor::selectionHasStyle(CSSPropertyID propertyID, const String& value
) const |
| 647 { | 647 { |
| 648 return EditingStyle::create(propertyID, value)->triStateOfStyle(m_frame.sele
ction().selection()); | 648 return EditingStyle::create(propertyID, value)->triStateOfStyle(m_frame.sele
ction().selection()); |
| 649 } | 649 } |
| 650 | 650 |
| 651 String Editor::selectionStartCSSPropertyValue(CSSPropertyID propertyID) | 651 String Editor::selectionStartCSSPropertyValue(CSSPropertyID propertyID) |
| 652 { | 652 { |
| 653 RefPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelectionStart(m_
frame.selection().selection(), | 653 RefPtrWillBeRawPtr<EditingStyle> selectionStyle = EditingStyle::styleAtSelec
tionStart(m_frame.selection().selection(), |
| 654 propertyID == CSSPropertyBackgroundColor); | 654 propertyID == CSSPropertyBackgroundColor); |
| 655 if (!selectionStyle || !selectionStyle->style()) | 655 if (!selectionStyle || !selectionStyle->style()) |
| 656 return String(); | 656 return String(); |
| 657 | 657 |
| 658 if (propertyID == CSSPropertyFontSize) | 658 if (propertyID == CSSPropertyFontSize) |
| 659 return String::number(selectionStyle->legacyFontSize(m_frame.document())
); | 659 return String::number(selectionStyle->legacyFontSize(m_frame.document())
); |
| 660 return selectionStyle->style()->getPropertyValue(propertyID); | 660 return selectionStyle->style()->getPropertyValue(propertyID); |
| 661 } | 661 } |
| 662 | 662 |
| 663 void Editor::indent() | 663 void Editor::indent() |
| 664 { | 664 { |
| 665 ASSERT(m_frame.document()); | 665 ASSERT(m_frame.document()); |
| 666 IndentOutdentCommand::create(*m_frame.document(), IndentOutdentCommand::Inde
nt)->apply(); | 666 IndentOutdentCommand::create(*m_frame.document(), IndentOutdentCommand::Inde
nt)->apply(); |
| 667 } | 667 } |
| 668 | 668 |
| 669 void Editor::outdent() | 669 void Editor::outdent() |
| 670 { | 670 { |
| 671 ASSERT(m_frame.document()); | 671 ASSERT(m_frame.document()); |
| 672 IndentOutdentCommand::create(*m_frame.document(), IndentOutdentCommand::Outd
ent)->apply(); | 672 IndentOutdentCommand::create(*m_frame.document(), IndentOutdentCommand::Outd
ent)->apply(); |
| 673 } | 673 } |
| 674 | 674 |
| 675 static void dispatchEditableContentChangedEvents(PassRefPtr<Element> startRoot,
PassRefPtr<Element> endRoot) | 675 static void dispatchEditableContentChangedEvents(PassRefPtrWillBeRawPtr<Element>
startRoot, PassRefPtrWillBeRawPtr<Element> endRoot) |
| 676 { | 676 { |
| 677 if (startRoot) | 677 if (startRoot) |
| 678 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged), IGNORE_EXCEPTION); | 678 startRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableCon
tentChanged), IGNORE_EXCEPTION); |
| 679 if (endRoot && endRoot != startRoot) | 679 if (endRoot && endRoot != startRoot) |
| 680 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged), IGNORE_EXCEPTION); | 680 endRoot->dispatchEvent(Event::create(EventTypeNames::webkitEditableConte
ntChanged), IGNORE_EXCEPTION); |
| 681 } | 681 } |
| 682 | 682 |
| 683 void Editor::appliedEditing(PassRefPtr<CompositeEditCommand> cmd) | 683 void Editor::appliedEditing(PassRefPtrWillBeRawPtr<CompositeEditCommand> cmd) |
| 684 { | 684 { |
| 685 EventQueueScope scope; | 685 EventQueueScope scope; |
| 686 m_frame.document()->updateLayout(); | 686 m_frame.document()->updateLayout(); |
| 687 | 687 |
| 688 EditCommandComposition* composition = cmd->composition(); | 688 EditCommandComposition* composition = cmd->composition(); |
| 689 ASSERT(composition); | 689 ASSERT(composition); |
| 690 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); | 690 dispatchEditableContentChangedEvents(composition->startingRootEditableElemen
t(), composition->endingRootEditableElement()); |
| 691 VisibleSelection newSelection(cmd->endingSelection()); | 691 VisibleSelection newSelection(cmd->endingSelection()); |
| 692 | 692 |
| 693 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. | 693 // Don't clear the typing style with this selection change. We do those thin
gs elsewhere if necessary. |
| 694 changeSelectionAfterCommand(newSelection, 0); | 694 changeSelectionAfterCommand(newSelection, 0); |
| 695 | 695 |
| 696 if (!cmd->preservesTypingStyle()) | 696 if (!cmd->preservesTypingStyle()) |
| 697 m_frame.selection().clearTypingStyle(); | 697 m_frame.selection().clearTypingStyle(); |
| 698 | 698 |
| 699 // Command will be equal to last edit command only in the case of typing | 699 // Command will be equal to last edit command only in the case of typing |
| 700 if (m_lastEditCommand.get() == cmd) { | 700 if (m_lastEditCommand.get() == cmd) { |
| 701 ASSERT(cmd->isTypingCommand()); | 701 ASSERT(cmd->isTypingCommand()); |
| 702 } else { | 702 } else { |
| 703 // Only register a new undo command if the command passed in is | 703 // Only register a new undo command if the command passed in is |
| 704 // different from the last command | 704 // different from the last command |
| 705 m_lastEditCommand = cmd; | 705 m_lastEditCommand = cmd; |
| 706 if (UndoStack* undoStack = this->undoStack()) | 706 if (UndoStack* undoStack = this->undoStack()) |
| 707 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); | 707 undoStack->registerUndoStep(m_lastEditCommand->ensureComposition()); |
| 708 } | 708 } |
| 709 | 709 |
| 710 respondToChangedContents(newSelection); | 710 respondToChangedContents(newSelection); |
| 711 } | 711 } |
| 712 | 712 |
| 713 void Editor::unappliedEditing(PassRefPtr<EditCommandComposition> cmd) | 713 void Editor::unappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd
) |
| 714 { | 714 { |
| 715 EventQueueScope scope; | 715 EventQueueScope scope; |
| 716 m_frame.document()->updateLayout(); | 716 m_frame.document()->updateLayout(); |
| 717 | 717 |
| 718 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); | 718 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); |
| 719 | 719 |
| 720 VisibleSelection newSelection(cmd->startingSelection()); | 720 VisibleSelection newSelection(cmd->startingSelection()); |
| 721 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); | 721 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); |
| 722 | 722 |
| 723 m_lastEditCommand = nullptr; | 723 m_lastEditCommand = nullptr; |
| 724 if (UndoStack* undoStack = this->undoStack()) | 724 if (UndoStack* undoStack = this->undoStack()) |
| 725 undoStack->registerRedoStep(cmd); | 725 undoStack->registerRedoStep(cmd); |
| 726 respondToChangedContents(newSelection); | 726 respondToChangedContents(newSelection); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void Editor::reappliedEditing(PassRefPtr<EditCommandComposition> cmd) | 729 void Editor::reappliedEditing(PassRefPtrWillBeRawPtr<EditCommandComposition> cmd
) |
| 730 { | 730 { |
| 731 EventQueueScope scope; | 731 EventQueueScope scope; |
| 732 m_frame.document()->updateLayout(); | 732 m_frame.document()->updateLayout(); |
| 733 | 733 |
| 734 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); | 734 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), cmd
->endingRootEditableElement()); |
| 735 | 735 |
| 736 VisibleSelection newSelection(cmd->endingSelection()); | 736 VisibleSelection newSelection(cmd->endingSelection()); |
| 737 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); | 737 changeSelectionAfterCommand(newSelection, FrameSelection::CloseTyping | Fram
eSelection::ClearTypingStyle); |
| 738 | 738 |
| 739 m_lastEditCommand = nullptr; | 739 m_lastEditCommand = nullptr; |
| 740 if (UndoStack* undoStack = this->undoStack()) | 740 if (UndoStack* undoStack = this->undoStack()) |
| 741 undoStack->registerUndoStep(cmd); | 741 undoStack->registerUndoStep(cmd); |
| 742 respondToChangedContents(newSelection); | 742 respondToChangedContents(newSelection); |
| 743 } | 743 } |
| 744 | 744 |
| 745 PassOwnPtr<Editor> Editor::create(LocalFrame& frame) | 745 PassOwnPtrWillBeRawPtr<Editor> Editor::create(LocalFrame& frame) |
| 746 { | 746 { |
| 747 return adoptPtr(new Editor(frame)); | 747 return adoptPtrWillBeNoop(new Editor(frame)); |
| 748 } | 748 } |
| 749 | 749 |
| 750 Editor::Editor(LocalFrame& frame) | 750 Editor::Editor(LocalFrame& frame) |
| 751 : m_frame(frame) | 751 : m_frame(frame) |
| 752 , m_preventRevealSelection(0) | 752 , m_preventRevealSelection(0) |
| 753 , m_shouldStartNewKillRingSequence(false) | 753 , m_shouldStartNewKillRingSequence(false) |
| 754 // This is off by default, since most editors want this behavior (this match
es IE but not FF). | 754 // This is off by default, since most editors want this behavior (this match
es IE but not FF). |
| 755 , m_shouldStyleWithCSS(false) | 755 , m_shouldStyleWithCSS(false) |
| 756 , m_killRing(adoptPtr(new KillRing)) | 756 , m_killRing(adoptPtr(new KillRing)) |
| 757 , m_areMarkedTextMatchesHighlighted(false) | 757 , m_areMarkedTextMatchesHighlighted(false) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 786 return false; | 786 return false; |
| 787 | 787 |
| 788 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[
0])); | 788 spellChecker().updateMarkersForWordsAffectedByEditing(isSpaceOrNewline(text[
0])); |
| 789 | 789 |
| 790 // Get the selection to use for the event that triggered this insertText. | 790 // Get the selection to use for the event that triggered this insertText. |
| 791 // If the event handler changed the selection, we may want to use a differen
t selection | 791 // If the event handler changed the selection, we may want to use a differen
t selection |
| 792 // that is contained in the event target. | 792 // that is contained in the event target. |
| 793 selection = selectionForCommand(triggeringEvent); | 793 selection = selectionForCommand(triggeringEvent); |
| 794 if (selection.isContentEditable()) { | 794 if (selection.isContentEditable()) { |
| 795 if (Node* selectionStart = selection.start().deprecatedNode()) { | 795 if (Node* selectionStart = selection.start().deprecatedNode()) { |
| 796 RefPtr<Document> document(selectionStart->document()); | 796 RefPtrWillBeRawPtr<Document> document(selectionStart->document()); |
| 797 | 797 |
| 798 // Insert the text | 798 // Insert the text |
| 799 TypingCommand::Options options = 0; | 799 TypingCommand::Options options = 0; |
| 800 if (selectInsertedText) | 800 if (selectInsertedText) |
| 801 options |= TypingCommand::SelectInsertedText; | 801 options |= TypingCommand::SelectInsertedText; |
| 802 TypingCommand::insertText(*document.get(), text, selection, options,
triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompos
itionConfirm : TypingCommand::TextCompositionNone); | 802 TypingCommand::insertText(*document.get(), text, selection, options,
triggeringEvent && triggeringEvent->isComposition() ? TypingCommand::TextCompos
itionConfirm : TypingCommand::TextCompositionNone); |
| 803 | 803 |
| 804 // Reveal the current selection | 804 // Reveal the current selection |
| 805 if (LocalFrame* editedFrame = document->frame()) { | 805 if (LocalFrame* editedFrame = document->frame()) { |
| 806 if (Page* page = editedFrame->page()) | 806 if (Page* page = editedFrame->page()) |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1076 } | 1076 } |
| 1077 | 1077 |
| 1078 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin
gAction) | 1078 void Editor::computeAndSetTypingStyle(StylePropertySet* style, EditAction editin
gAction) |
| 1079 { | 1079 { |
| 1080 if (!style || style->isEmpty()) { | 1080 if (!style || style->isEmpty()) { |
| 1081 m_frame.selection().clearTypingStyle(); | 1081 m_frame.selection().clearTypingStyle(); |
| 1082 return; | 1082 return; |
| 1083 } | 1083 } |
| 1084 | 1084 |
| 1085 // Calculate the current typing style. | 1085 // Calculate the current typing style. |
| 1086 RefPtr<EditingStyle> typingStyle; | 1086 RefPtrWillBeRawPtr<EditingStyle> typingStyle = nullptr; |
| 1087 if (m_frame.selection().typingStyle()) { | 1087 if (m_frame.selection().typingStyle()) { |
| 1088 typingStyle = m_frame.selection().typingStyle()->copy(); | 1088 typingStyle = m_frame.selection().typingStyle()->copy(); |
| 1089 typingStyle->overrideWithStyle(style); | 1089 typingStyle->overrideWithStyle(style); |
| 1090 } else { | 1090 } else { |
| 1091 typingStyle = EditingStyle::create(style); | 1091 typingStyle = EditingStyle::create(style); |
| 1092 } | 1092 } |
| 1093 | 1093 |
| 1094 typingStyle->prepareToApplyAt(m_frame.selection().selection().visibleStart()
.deepEquivalent(), EditingStyle::PreserveWritingDirection); | 1094 typingStyle->prepareToApplyAt(m_frame.selection().selection().visibleStart()
.deepEquivalent(), EditingStyle::PreserveWritingDirection); |
| 1095 | 1095 |
| 1096 // Handle block styles, substracting these from the typing style. | 1096 // Handle block styles, substracting these from the typing style. |
| 1097 RefPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveBlockProperti
es(); | 1097 RefPtrWillBeRawPtr<EditingStyle> blockStyle = typingStyle->extractAndRemoveB
lockProperties(); |
| 1098 if (!blockStyle->isEmpty()) { | 1098 if (!blockStyle->isEmpty()) { |
| 1099 ASSERT(m_frame.document()); | 1099 ASSERT(m_frame.document()); |
| 1100 ApplyStyleCommand::create(*m_frame.document(), blockStyle.get(), editing
Action)->apply(); | 1100 ApplyStyleCommand::create(*m_frame.document(), blockStyle.get(), editing
Action)->apply(); |
| 1101 } | 1101 } |
| 1102 | 1102 |
| 1103 // Set the remaining style as the typing style. | 1103 // Set the remaining style as the typing style. |
| 1104 m_frame.selection().setTypingStyle(typingStyle); | 1104 m_frame.selection().setTypingStyle(typingStyle); |
| 1105 } | 1105 } |
| 1106 | 1106 |
| 1107 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool
wrapFlag, bool startInSelection) | 1107 bool Editor::findString(const String& target, bool forward, bool caseFlag, bool
wrapFlag, bool startInSelection) |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 { | 1228 { |
| 1229 return m_frame.spellChecker(); | 1229 return m_frame.spellChecker(); |
| 1230 } | 1230 } |
| 1231 | 1231 |
| 1232 void Editor::toggleOverwriteModeEnabled() | 1232 void Editor::toggleOverwriteModeEnabled() |
| 1233 { | 1233 { |
| 1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; | 1234 m_overwriteModeEnabled = !m_overwriteModeEnabled; |
| 1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); | 1235 frame().selection().setShouldShowBlockCursor(m_overwriteModeEnabled); |
| 1236 } | 1236 } |
| 1237 | 1237 |
| 1238 void Editor::trace(Visitor* visitor) |
| 1239 { |
| 1240 visitor->trace(m_lastEditCommand); |
| 1241 visitor->trace(m_mark); |
| 1242 } |
| 1243 |
| 1238 } // namespace WebCore | 1244 } // namespace WebCore |
| OLD | NEW |