| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights | 2 * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights |
| 3 * reserved. | 3 * reserved. |
| 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 |
| 11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
| 12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
| 13 * | 13 * |
| 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
| 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
| 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 17 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
| 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 18 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 19 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 20 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 21 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 22 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 24 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 */ | 25 */ |
| 26 | 26 |
| 27 #ifndef SelectionEditor_h | 27 #ifndef SelectionEditor_h |
| 28 #define SelectionEditor_h | 28 #define SelectionEditor_h |
| 29 | 29 |
| 30 #include "core/dom/SynchronousMutationObserver.h" | |
| 31 #include "core/editing/FrameSelection.h" | 30 #include "core/editing/FrameSelection.h" |
| 32 #include "core/editing/SelectionTemplate.h" | |
| 33 #include "core/events/EventDispatchResult.h" | 31 #include "core/events/EventDispatchResult.h" |
| 34 | 32 |
| 35 namespace blink { | 33 namespace blink { |
| 36 | 34 |
| 37 // TODO(yosin): We will rename |SelectionEditor| to appropriate name since | 35 // TODO(yosin): We will rename |SelectionEditor| to appropriate name since |
| 38 // it is no longer have a changing selection functionality, it was moved to | 36 // it is no longer have a changing selection functionality, it was moved to |
| 39 // |SelectionModifier| class. | 37 // |SelectionModifier| class. |
| 40 class SelectionEditor final : public GarbageCollectedFinalized<SelectionEditor>, | 38 class SelectionEditor final |
| 41 public SynchronousMutationObserver { | 39 : public GarbageCollectedFinalized<SelectionEditor> { |
| 42 WTF_MAKE_NONCOPYABLE(SelectionEditor); | 40 WTF_MAKE_NONCOPYABLE(SelectionEditor); |
| 43 USING_GARBAGE_COLLECTED_MIXIN(SelectionEditor); | |
| 44 | 41 |
| 45 public: | 42 public: |
| 46 static SelectionEditor* create(LocalFrame& frame) { | 43 static SelectionEditor* create(LocalFrame& frame) { |
| 47 return new SelectionEditor(frame); | 44 return new SelectionEditor(frame); |
| 48 } | 45 } |
| 49 virtual ~SelectionEditor(); | 46 virtual ~SelectionEditor(); |
| 50 void dispose(); | 47 void dispose(); |
| 51 | 48 |
| 52 bool hasEditableStyle() const; | 49 bool hasEditableStyle() const { return m_selection.hasEditableStyle(); } |
| 53 bool isContentEditable() const; | 50 bool isContentEditable() const { return m_selection.isContentEditable(); } |
| 54 bool isContentRichlyEditable() const; | 51 bool isContentRichlyEditable() const { |
| 52 return m_selection.isContentRichlyEditable(); |
| 53 } |
| 54 |
| 55 bool setSelectedRange(const EphemeralRange&, |
| 56 TextAffinity, |
| 57 SelectionDirectionalMode, |
| 58 FrameSelection::SetSelectionOptions); |
| 55 | 59 |
| 56 template <typename Strategy> | 60 template <typename Strategy> |
| 57 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; | 61 const VisibleSelectionTemplate<Strategy>& visibleSelection() const; |
| 58 const SelectionInDOMTree& selectionInDOMTree() const; | 62 void setVisibleSelection(const VisibleSelection&, |
| 63 FrameSelection::SetSelectionOptions); |
| 64 void setVisibleSelection(const VisibleSelectionInFlatTree&, |
| 65 FrameSelection::SetSelectionOptions); |
| 59 | 66 |
| 60 const VisibleSelection& computeVisibleSelectionInDOMTree() const; | 67 void setWithoutValidation(const Position& base, const Position& extent); |
| 61 const VisibleSelectionInFlatTree& computeVisibleSelectionInFlatTree() const; | |
| 62 void setSelection(const SelectionInDOMTree&); | |
| 63 | 68 |
| 64 void documentAttached(Document*); | 69 void documentAttached(Document*); |
| 70 void documentDetached(const Document&); |
| 65 | 71 |
| 66 // If this FrameSelection has a logical range which is still valid, this | 72 // If this FrameSelection has a logical range which is still valid, this |
| 67 // function return its clone. Otherwise, the return value from underlying | 73 // function return its clone. Otherwise, the return value from underlying |
| 68 // |VisibleSelection|'s |firstRange()| is returned. | 74 // |VisibleSelection|'s |firstRange()| is returned. |
| 69 Range* firstRange() const; | 75 Range* firstRange() const; |
| 70 | 76 |
| 71 // There functions are exposed for |FrameSelection|. | 77 // There functions are exposed for |FrameSelection|. |
| 72 void resetLogicalRange(); | 78 void resetLogicalRange(); |
| 73 void setLogicalRange(Range*); | 79 void setLogicalRange(Range*); |
| 74 | 80 |
| 75 // Updates |m_selection| and |m_selectionInFlatTree| with up-to-date | 81 // Updates |m_selection| and |m_selectionInFlatTree| with up-to-date |
| 76 // layout if needed. | 82 // layout if needed. |
| 77 void updateIfNeeded(); | 83 void updateIfNeeded(); |
| 78 | 84 |
| 79 void cacheRangeOfDocument(Range*); | 85 void cacheRangeOfDocument(Range*); |
| 80 Range* documentCachedRange() const; | 86 Range* documentCachedRange() const; |
| 81 void clearDocumentCachedRange(); | 87 void clearDocumentCachedRange(); |
| 82 | 88 |
| 83 DECLARE_TRACE(); | 89 DECLARE_TRACE(); |
| 84 | 90 |
| 85 private: | 91 private: |
| 86 explicit SelectionEditor(LocalFrame&); | 92 explicit SelectionEditor(LocalFrame&); |
| 87 | 93 |
| 88 Document& document() const; | 94 const Document& document() const; |
| 89 LocalFrame* frame() const { return m_frame.get(); } | 95 LocalFrame* frame() const { return m_frame.get(); } |
| 90 | 96 |
| 91 void assertSelectionValid() const; | |
| 92 void clearVisibleSelection(); | 97 void clearVisibleSelection(); |
| 93 void markCacheDirty(); | |
| 94 bool shouldAlwaysUseDirectionalSelection() const; | 98 bool shouldAlwaysUseDirectionalSelection() const; |
| 95 | 99 |
| 96 // VisibleSelection cache related | 100 Member<Document> m_document; |
| 97 bool needsUpdateVisibleSelection() const; | |
| 98 void updateCachedVisibleSelectionIfNeeded() const; | |
| 99 | |
| 100 void didFinishTextChange(const Position& base, const Position& extent); | |
| 101 void didFinishDOMMutation(); | |
| 102 | |
| 103 // Implementation of |SynchronousMutationObsderver| member functions. | |
| 104 void contextDestroyed(Document*) final; | |
| 105 void didChangeChildren(const ContainerNode&) final; | |
| 106 void didMergeTextNodes(const Text& mergedNode, | |
| 107 const NodeWithIndex& nodeToBeRemovedWithIndex, | |
| 108 unsigned oldLength) final; | |
| 109 void didSplitTextNode(const Text&) final; | |
| 110 void didUpdateCharacterData(CharacterData*, | |
| 111 unsigned offset, | |
| 112 unsigned oldLength, | |
| 113 unsigned newLength) final; | |
| 114 void nodeChildrenWillBeRemoved(ContainerNode&) final; | |
| 115 void nodeWillBeRemoved(Node&) final; | |
| 116 | |
| 117 Member<LocalFrame> m_frame; | 101 Member<LocalFrame> m_frame; |
| 118 | 102 |
| 119 SelectionInDOMTree m_selection; | 103 VisibleSelection m_selection; |
| 104 VisibleSelectionInFlatTree m_selectionInFlatTree; |
| 105 bool m_observingVisibleSelection; |
| 120 | 106 |
| 121 // TODO(editing-dev): Removing |m_logicalRange| | 107 // TODO(editing-dev): Removing |m_logicalRange| |
| 122 // The range specified by the user, which may not be visually canonicalized | 108 // The range specified by the user, which may not be visually canonicalized |
| 123 // (hence "logical"). This will be invalidated if the underlying | 109 // (hence "logical"). This will be invalidated if the underlying |
| 124 // |VisibleSelection| changes. If that happens, this variable will | 110 // |VisibleSelection| changes. If that happens, this variable will |
| 125 // become |nullptr|, in which case logical positions == visible positions. | 111 // become |nullptr|, in which case logical positions == visible positions. |
| 126 Member<Range> m_logicalRange; | 112 Member<Range> m_logicalRange; |
| 127 | |
| 128 // If document is root, document.getSelection().addRange(range) is cached on | 113 // If document is root, document.getSelection().addRange(range) is cached on |
| 129 // this. | 114 // this. |
| 130 Member<Range> m_cachedRange; | 115 Member<Range> m_cachedRange; |
| 131 | |
| 132 mutable VisibleSelection m_cachedVisibleSelectionInDOMTree; | |
| 133 mutable VisibleSelectionInFlatTree m_cachedVisibleSelectionInFlatTree; | |
| 134 mutable uint64_t m_styleVersion = static_cast<uint64_t>(-1); | |
| 135 mutable bool m_cacheIsDirty = false; | |
| 136 }; | 116 }; |
| 137 | 117 |
| 138 } // namespace blink | 118 } // namespace blink |
| 139 | 119 |
| 140 #endif // SelectionEditor_h | 120 #endif // SelectionEditor_h |
| OLD | NEW |