| 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 716 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 727 return false; | 727 return false; |
| 728 | 728 |
| 729 Node* startContainer = range.startPosition().computeContainerNode(); | 729 Node* startContainer = range.startPosition().computeContainerNode(); |
| 730 Node* endContainer = range.endPosition().computeContainerNode(); | 730 Node* endContainer = range.endPosition().computeContainerNode(); |
| 731 if (!startContainer || !endContainer) | 731 if (!startContainer || !endContainer) |
| 732 return false; | 732 return false; |
| 733 | 733 |
| 734 return hasEditableStyle(*startContainer) && hasEditableStyle(*endContainer); | 734 return hasEditableStyle(*startContainer) && hasEditableStyle(*endContainer); |
| 735 } | 735 } |
| 736 | 736 |
| 737 void Editor::respondToChangedContents(const VisibleSelection& endingSelection) { | 737 void Editor::respondToChangedContents(const Position& position) { |
| 738 if (frame().settings() && frame().settings()->getAccessibilityEnabled()) { | 738 if (frame().settings() && frame().settings()->getAccessibilityEnabled()) { |
| 739 Node* node = endingSelection.start().anchorNode(); | 739 Node* node = position.anchorNode(); |
| 740 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) | 740 if (AXObjectCache* cache = frame().document()->existingAXObjectCache()) |
| 741 cache->handleEditableTextContentChanged(node); | 741 cache->handleEditableTextContentChanged(node); |
| 742 } | 742 } |
| 743 | 743 |
| 744 spellChecker().updateMarkersForWordsAffectedByEditing(true); | 744 spellChecker().updateMarkersForWordsAffectedByEditing(true); |
| 745 client().respondToChangedContents(); | 745 client().respondToChangedContents(); |
| 746 } | 746 } |
| 747 | 747 |
| 748 void Editor::removeFormattingAndStyle() { | 748 void Editor::removeFormattingAndStyle() { |
| 749 DCHECK(frame().document()); | 749 DCHECK(frame().document()); |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 910 if (!m_lastEditCommand->undoStep()) | 910 if (!m_lastEditCommand->undoStep()) |
| 911 m_undoStack->registerUndoStep(m_lastEditCommand->ensureUndoStep()); | 911 m_undoStack->registerUndoStep(m_lastEditCommand->ensureUndoStep()); |
| 912 m_lastEditCommand->appendCommandToUndoStep(cmd); | 912 m_lastEditCommand->appendCommandToUndoStep(cmd); |
| 913 } else { | 913 } else { |
| 914 // Only register a new undo command if the command passed in is | 914 // Only register a new undo command if the command passed in is |
| 915 // different from the last command | 915 // different from the last command |
| 916 m_lastEditCommand = cmd; | 916 m_lastEditCommand = cmd; |
| 917 m_undoStack->registerUndoStep(m_lastEditCommand->ensureUndoStep()); | 917 m_undoStack->registerUndoStep(m_lastEditCommand->ensureUndoStep()); |
| 918 } | 918 } |
| 919 | 919 |
| 920 respondToChangedContents(newSelection); | 920 respondToChangedContents(newSelection.start()); |
| 921 } | 921 } |
| 922 | 922 |
| 923 static VisibleSelection correctedVisibleSelection( | 923 static VisibleSelection correctedVisibleSelection( |
| 924 const VisibleSelection& passedSelection) { | 924 const VisibleSelection& passedSelection) { |
| 925 if (!passedSelection.base().isConnected() || | 925 if (!passedSelection.base().isConnected() || |
| 926 !passedSelection.extent().isConnected()) | 926 !passedSelection.extent().isConnected()) |
| 927 return VisibleSelection(); | 927 return VisibleSelection(); |
| 928 DCHECK(!passedSelection.base().document()->needsLayoutTreeUpdate()); | 928 DCHECK(!passedSelection.base().document()->needsLayoutTreeUpdate()); |
| 929 VisibleSelection correctedSelection = passedSelection; | 929 VisibleSelection correctedSelection = passedSelection; |
| 930 correctedSelection.updateIfNeeded(); | 930 correctedSelection.updateIfNeeded(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 951 correctedVisibleSelection(cmd->startingSelection()); | 951 correctedVisibleSelection(cmd->startingSelection()); |
| 952 DCHECK(newSelection.isValidFor(*frame().document())) << newSelection; | 952 DCHECK(newSelection.isValidFor(*frame().document())) << newSelection; |
| 953 if (!newSelection.isNone()) { | 953 if (!newSelection.isNone()) { |
| 954 changeSelectionAfterCommand( | 954 changeSelectionAfterCommand( |
| 955 newSelection, | 955 newSelection, |
| 956 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); | 956 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
| 957 } | 957 } |
| 958 | 958 |
| 959 m_lastEditCommand = nullptr; | 959 m_lastEditCommand = nullptr; |
| 960 m_undoStack->registerRedoStep(cmd); | 960 m_undoStack->registerRedoStep(cmd); |
| 961 respondToChangedContents(newSelection); | 961 respondToChangedContents(newSelection.start()); |
| 962 } | 962 } |
| 963 | 963 |
| 964 void Editor::reappliedEditing(UndoStep* cmd) { | 964 void Editor::reappliedEditing(UndoStep* cmd) { |
| 965 EventQueueScope scope; | 965 EventQueueScope scope; |
| 966 | 966 |
| 967 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), | 967 dispatchEditableContentChangedEvents(cmd->startingRootEditableElement(), |
| 968 cmd->endingRootEditableElement()); | 968 cmd->endingRootEditableElement()); |
| 969 dispatchInputEventEditableContentChanged( | 969 dispatchInputEventEditableContentChanged( |
| 970 cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), | 970 cmd->startingRootEditableElement(), cmd->endingRootEditableElement(), |
| 971 InputEvent::InputType::HistoryRedo, nullAtom, | 971 InputEvent::InputType::HistoryRedo, nullAtom, |
| 972 InputEvent::EventIsComposing::NotComposing); | 972 InputEvent::EventIsComposing::NotComposing); |
| 973 | 973 |
| 974 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets | 974 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets |
| 975 // needs to be audited. See http://crbug.com/590369 for more details. | 975 // needs to be audited. See http://crbug.com/590369 for more details. |
| 976 // In the long term, we should stop editing commands from storing | 976 // In the long term, we should stop editing commands from storing |
| 977 // VisibleSelections as starting and ending selections. | 977 // VisibleSelections as starting and ending selections. |
| 978 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 978 frame().document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
| 979 const VisibleSelection& newSelection = | 979 const VisibleSelection& newSelection = |
| 980 correctedVisibleSelection(cmd->endingSelection()); | 980 correctedVisibleSelection(cmd->endingSelection()); |
| 981 DCHECK(newSelection.isValidFor(*frame().document())) << newSelection; | 981 DCHECK(newSelection.isValidFor(*frame().document())) << newSelection; |
| 982 if (!newSelection.isNone()) { | 982 if (!newSelection.isNone()) { |
| 983 changeSelectionAfterCommand( | 983 changeSelectionAfterCommand( |
| 984 newSelection, | 984 newSelection, |
| 985 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); | 985 FrameSelection::CloseTyping | FrameSelection::ClearTypingStyle); |
| 986 } | 986 } |
| 987 | 987 |
| 988 m_lastEditCommand = nullptr; | 988 m_lastEditCommand = nullptr; |
| 989 m_undoStack->registerUndoStep(cmd); | 989 m_undoStack->registerUndoStep(cmd); |
| 990 respondToChangedContents(newSelection); | 990 respondToChangedContents(newSelection.start()); |
| 991 } | 991 } |
| 992 | 992 |
| 993 Editor* Editor::create(LocalFrame& frame) { | 993 Editor* Editor::create(LocalFrame& frame) { |
| 994 return new Editor(frame); | 994 return new Editor(frame); |
| 995 } | 995 } |
| 996 | 996 |
| 997 Editor::Editor(LocalFrame& frame) | 997 Editor::Editor(LocalFrame& frame) |
| 998 : m_frame(&frame), | 998 : m_frame(&frame), |
| 999 m_undoStack(UndoStack::create()), | 999 m_undoStack(UndoStack::create()), |
| 1000 m_preventRevealSelection(0), | 1000 m_preventRevealSelection(0), |
| (...skipping 765 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1766 | 1766 |
| 1767 DEFINE_TRACE(Editor) { | 1767 DEFINE_TRACE(Editor) { |
| 1768 visitor->trace(m_frame); | 1768 visitor->trace(m_frame); |
| 1769 visitor->trace(m_lastEditCommand); | 1769 visitor->trace(m_lastEditCommand); |
| 1770 visitor->trace(m_undoStack); | 1770 visitor->trace(m_undoStack); |
| 1771 visitor->trace(m_mark); | 1771 visitor->trace(m_mark); |
| 1772 visitor->trace(m_typingStyle); | 1772 visitor->trace(m_typingStyle); |
| 1773 } | 1773 } |
| 1774 | 1774 |
| 1775 } // namespace blink | 1775 } // namespace blink |
| OLD | NEW |