| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. | 2 * Copyright (C) 2004, 2008, 2009, 2010 Apple Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions | 5 * modification, are permitted provided that the following conditions |
| 6 * are met: | 6 * are met: |
| 7 * 1. Redistributions of source code must retain the above copyright | 7 * 1. Redistributions of source code must retain the above copyright |
| 8 * notice, this list of conditions and the following disclaimer. | 8 * notice, this list of conditions and the following disclaimer. |
| 9 * 2. Redistributions in binary form must reproduce the above copyright | 9 * 2. Redistributions in binary form must reproduce the above copyright |
| 10 * notice, this list of conditions and the following disclaimer in the | 10 * notice, this list of conditions and the following disclaimer in the |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 m_selection = VisibleSelection(); | 43 m_selection = VisibleSelection(); |
| 44 m_selectionInFlatTree = VisibleSelectionInFlatTree(); | 44 m_selectionInFlatTree = VisibleSelectionInFlatTree(); |
| 45 if (!shouldAlwaysUseDirectionalSelection()) | 45 if (!shouldAlwaysUseDirectionalSelection()) |
| 46 return; | 46 return; |
| 47 m_selection.setIsDirectional(true); | 47 m_selection.setIsDirectional(true); |
| 48 m_selectionInFlatTree.setIsDirectional(true); | 48 m_selectionInFlatTree.setIsDirectional(true); |
| 49 } | 49 } |
| 50 | 50 |
| 51 void SelectionEditor::dispose() { | 51 void SelectionEditor::dispose() { |
| 52 resetLogicalRange(); | 52 resetLogicalRange(); |
| 53 clearDocumentCachedRange(); |
| 53 clearVisibleSelection(); | 54 clearVisibleSelection(); |
| 54 } | 55 } |
| 55 | 56 |
| 56 const Document& SelectionEditor::document() const { | 57 const Document& SelectionEditor::document() const { |
| 57 DCHECK(m_document); | 58 DCHECK(m_document); |
| 58 return *m_document; | 59 return *m_document; |
| 59 } | 60 } |
| 60 | 61 |
| 61 template <> | 62 template <> |
| 62 const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() | 63 const VisibleSelection& SelectionEditor::visibleSelection<EditingStrategy>() |
| (...skipping 15 matching lines...) Expand all Loading... |
| 78 return m_selectionInFlatTree; | 79 return m_selectionInFlatTree; |
| 79 DCHECK_EQ(m_selectionInFlatTree.base().document(), document()); | 80 DCHECK_EQ(m_selectionInFlatTree.base().document(), document()); |
| 80 return m_selectionInFlatTree; | 81 return m_selectionInFlatTree; |
| 81 } | 82 } |
| 82 | 83 |
| 83 void SelectionEditor::setVisibleSelection( | 84 void SelectionEditor::setVisibleSelection( |
| 84 const VisibleSelection& newSelection, | 85 const VisibleSelection& newSelection, |
| 85 FrameSelection::SetSelectionOptions options) { | 86 FrameSelection::SetSelectionOptions options) { |
| 86 DCHECK(newSelection.isValidFor(document())) << newSelection; | 87 DCHECK(newSelection.isValidFor(document())) << newSelection; |
| 87 resetLogicalRange(); | 88 resetLogicalRange(); |
| 89 clearDocumentCachedRange(); |
| 90 |
| 88 m_selection = newSelection; | 91 m_selection = newSelection; |
| 89 if (options & FrameSelection::DoNotAdjustInFlatTree) { | 92 if (options & FrameSelection::DoNotAdjustInFlatTree) { |
| 90 m_selectionInFlatTree.setWithoutValidation( | 93 m_selectionInFlatTree.setWithoutValidation( |
| 91 toPositionInFlatTree(m_selection.base()), | 94 toPositionInFlatTree(m_selection.base()), |
| 92 toPositionInFlatTree(m_selection.extent())); | 95 toPositionInFlatTree(m_selection.extent())); |
| 93 return; | 96 return; |
| 94 } | 97 } |
| 95 | 98 |
| 96 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, | 99 SelectionAdjuster::adjustSelectionInFlatTree(&m_selectionInFlatTree, |
| 97 m_selection); | 100 m_selection); |
| 98 } | 101 } |
| 99 | 102 |
| 100 void SelectionEditor::setVisibleSelection( | 103 void SelectionEditor::setVisibleSelection( |
| 101 const VisibleSelectionInFlatTree& newSelection, | 104 const VisibleSelectionInFlatTree& newSelection, |
| 102 FrameSelection::SetSelectionOptions options) { | 105 FrameSelection::SetSelectionOptions options) { |
| 103 DCHECK(newSelection.isValidFor(document())) << newSelection; | 106 DCHECK(newSelection.isValidFor(document())) << newSelection; |
| 104 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); | 107 DCHECK(!(options & FrameSelection::DoNotAdjustInFlatTree)); |
| 105 resetLogicalRange(); | 108 resetLogicalRange(); |
| 109 clearDocumentCachedRange(); |
| 110 |
| 106 m_selectionInFlatTree = newSelection; | 111 m_selectionInFlatTree = newSelection; |
| 107 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, | 112 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, |
| 108 m_selectionInFlatTree); | 113 m_selectionInFlatTree); |
| 109 } | 114 } |
| 110 | 115 |
| 111 void SelectionEditor::setWithoutValidation(const Position& base, | 116 void SelectionEditor::setWithoutValidation(const Position& base, |
| 112 const Position& extent) { | 117 const Position& extent) { |
| 113 resetLogicalRange(); | 118 resetLogicalRange(); |
| 114 if (base.isNotNull()) | 119 if (base.isNotNull()) |
| 115 DCHECK_EQ(base.document(), document()); | 120 DCHECK_EQ(base.document(), document()); |
| 116 if (extent.isNotNull()) | 121 if (extent.isNotNull()) |
| 117 DCHECK_EQ(extent.document(), document()); | 122 DCHECK_EQ(extent.document(), document()); |
| 123 clearDocumentCachedRange(); |
| 124 |
| 118 m_selection.setWithoutValidation(base, extent); | 125 m_selection.setWithoutValidation(base, extent); |
| 119 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), | 126 m_selectionInFlatTree.setWithoutValidation(toPositionInFlatTree(base), |
| 120 toPositionInFlatTree(extent)); | 127 toPositionInFlatTree(extent)); |
| 121 } | 128 } |
| 122 | 129 |
| 123 void SelectionEditor::documentAttached(Document* document) { | 130 void SelectionEditor::documentAttached(Document* document) { |
| 124 DCHECK(document); | 131 DCHECK(document); |
| 125 DCHECK(!m_document) << m_document; | 132 DCHECK(!m_document) << m_document; |
| 126 m_document = document; | 133 m_document = document; |
| 127 } | 134 } |
| (...skipping 29 matching lines...) Expand all Loading... |
| 157 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional(); | 164 return frame()->editor().behavior().shouldConsiderSelectionAsDirectional(); |
| 158 } | 165 } |
| 159 | 166 |
| 160 void SelectionEditor::updateIfNeeded() { | 167 void SelectionEditor::updateIfNeeded() { |
| 161 DCHECK(m_selection.isValidFor(document())) << m_selection; | 168 DCHECK(m_selection.isValidFor(document())) << m_selection; |
| 162 DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection; | 169 DCHECK(m_selectionInFlatTree.isValidFor(document())) << m_selection; |
| 163 m_selection.updateIfNeeded(); | 170 m_selection.updateIfNeeded(); |
| 164 m_selectionInFlatTree.updateIfNeeded(); | 171 m_selectionInFlatTree.updateIfNeeded(); |
| 165 } | 172 } |
| 166 | 173 |
| 174 void SelectionEditor::cacheRangeOfDocument(Range* range) { |
| 175 m_cachedRange = range; |
| 176 } |
| 177 |
| 178 Range* SelectionEditor::documentCachedRange() const { |
| 179 return m_cachedRange; |
| 180 } |
| 181 |
| 182 void SelectionEditor::clearDocumentCachedRange() { |
| 183 m_cachedRange = nullptr; |
| 184 } |
| 185 |
| 167 DEFINE_TRACE(SelectionEditor) { | 186 DEFINE_TRACE(SelectionEditor) { |
| 168 visitor->trace(m_document); | 187 visitor->trace(m_document); |
| 169 visitor->trace(m_frame); | 188 visitor->trace(m_frame); |
| 170 visitor->trace(m_selection); | 189 visitor->trace(m_selection); |
| 171 visitor->trace(m_selectionInFlatTree); | 190 visitor->trace(m_selectionInFlatTree); |
| 172 visitor->trace(m_logicalRange); | 191 visitor->trace(m_logicalRange); |
| 192 visitor->trace(m_cachedRange); |
| 173 } | 193 } |
| 174 | 194 |
| 175 } // namespace blink | 195 } // namespace blink |
| OLD | NEW |