| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef SynchronousMutationObserver_h | 5 #ifndef SynchronousMutationObserver_h |
| 6 #define SynchronousMutationObserver_h | 6 #define SynchronousMutationObserver_h |
| 7 | 7 |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "core/CoreExport.h" | 9 #include "core/CoreExport.h" |
| 10 #include "platform/LifecycleObserver.h" | 10 #include "platform/LifecycleObserver.h" |
| 11 | 11 |
| 12 namespace blink { | 12 namespace blink { |
| 13 | 13 |
| 14 class CharacterData; | 14 class CharacterData; |
| 15 class ContainerNode; | 15 class ContainerNode; |
| 16 class Document; | 16 class Document; |
| 17 class Element; |
| 18 class Node; |
| 19 class NodeWithIndex; |
| 17 class Text; | 20 class Text; |
| 18 | 21 |
| 19 // This class is a base class for classes which observe DOM tree mutation | 22 // This class is a base class for classes which observe DOM tree mutation |
| 20 // synchronously. If you want to observe DOM tree mutation asynchronously see | 23 // synchronously. If you want to observe DOM tree mutation asynchronously see |
| 21 // MutationObserver Web API. | 24 // MutationObserver Web API. |
| 22 // | |
| 23 // TODO(yosin): Following classes should be derived from this class to | |
| 24 // simplify Document class. | |
| 25 // - DragCaretController | |
| 26 // - DocumentMarkerController | |
| 27 // - EventHandler | |
| 28 // - FrameCaret | |
| 29 // - InputMethodController | |
| 30 // - SelectionController | |
| 31 // - Range set | |
| 32 // - NodeIterator set | |
| 33 class CORE_EXPORT SynchronousMutationObserver | 25 class CORE_EXPORT SynchronousMutationObserver |
| 34 : public LifecycleObserver<Document, SynchronousMutationObserver> { | 26 : public LifecycleObserver<Document, SynchronousMutationObserver> { |
| 35 public: | 27 public: |
| 36 // TODO(yosin): We will have following member functions: | 28 // Called just after attribute is changed. |
| 37 // - dataWillBeChanged(const CharacterData&); | 29 virtual void didChangeAttribute(const Element&); |
| 38 // - didMoveTreeToNewDocument(const Node& root); | |
| 39 // - didInsertText(Node*, unsigned offset, unsigned length); | |
| 40 // - didRemoveText(Node*, unsigned offset, unsigned length); | |
| 41 | 30 |
| 42 // Called after child nodes changed. | 31 // Called after child nodes changed. |
| 43 virtual void didChangeChildren(const ContainerNode&); | 32 virtual void didChangeChildren(const ContainerNode&); |
| 44 | 33 |
| 45 // TODO(yosin): We should use |const Text& oldNode|. | 34 // Called after characters in |nodeToBeRemoved| is appended into |mergedNode|. |
| 46 // Called after characters in |oldNode| is appended at |offset| in | 35 // |oldLength| holds length of |mergedNode| before merge. |
| 47 // |oldNdoe->previousSibling()|. | 36 virtual void didMergeTextNodes(const Text& mergedNode, |
| 48 virtual void didMergeTextNodes(Text& oldNode, unsigned offset); | 37 const NodeWithIndex& nodeToBeRemovedWithIndex, |
| 38 unsigned oldLength); |
| 49 | 39 |
| 50 // Called when |Text| node is split, next sibling |oldNode| contains | 40 // Called just after node tree is moved to new document. |
| 51 // characters after split point. | 41 virtual void didMoveTreeToNewDocument(); |
| 52 virtual void didSplitTextNode(const Text& oldNode); | 42 |
| 43 // Called after |Text| node is split, |splitNode->nextSibling()| contains |
| 44 // character after split offset. |
| 45 virtual void didSplitTextNode(const Text& splitNode); |
| 53 | 46 |
| 54 // Called when |CharacterData| is updated at |offset|, |oldLength| is a | 47 // Called when |CharacterData| is updated at |offset|, |oldLength| is a |
| 55 // number of deleted character and |newLength| is a number of added | 48 // number of deleted character and |newLength| is a number of added |
| 56 // characters. | 49 // characters. |
| 57 virtual void didUpdateCharacterData(CharacterData*, | 50 virtual void didUpdateCharacterData(CharacterData*, |
| 58 unsigned offset, | 51 unsigned offset, |
| 59 unsigned oldLength, | 52 unsigned oldLength, |
| 60 unsigned newLength); | 53 unsigned newLength); |
| 61 | 54 |
| 62 // Called before removing container node. | 55 // Called before removing container node. |
| 63 virtual void nodeChildrenWillBeRemoved(ContainerNode&); | 56 virtual void nodeChildrenWillBeRemoved(ContainerNode&); |
| 64 | 57 |
| 65 // Called before removing node. | 58 // Called before removing node. |
| 66 virtual void nodeWillBeRemoved(Node&); | 59 virtual void nodeWillBeRemoved(Node&); |
| 67 | 60 |
| 68 // Called when detaching document. | 61 // Called when detaching document. |
| 69 virtual void contextDestroyed(Document*) {} | 62 virtual void contextDestroyed(Document*) {} |
| 70 | 63 |
| 71 protected: | 64 protected: |
| 72 SynchronousMutationObserver(); | 65 SynchronousMutationObserver(); |
| 73 | 66 |
| 74 private: | 67 private: |
| 75 DISALLOW_COPY_AND_ASSIGN(SynchronousMutationObserver); | 68 DISALLOW_COPY_AND_ASSIGN(SynchronousMutationObserver); |
| 76 }; | 69 }; |
| 77 | 70 |
| 78 } // namespace blink | 71 } // namespace blink |
| 79 | 72 |
| 80 #endif // SynchronousMutationObserver_h | 73 #endif // SynchronousMutationObserver_h |
| OLD | NEW |