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 |
11 * documentation and/or other materials provided with the distribution. | 11 * documentation and/or other materials provided with the distribution. |
12 * | 12 * |
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY | 13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY |
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | 15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR | 16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR |
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, | 17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, | 18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR | 19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY | 20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "core/editing/SelectionEditor.h" | 26 #include "core/editing/SelectionEditor.h" |
27 | 27 |
28 #include "core/editing/EditingUtilities.h" | 28 #include "core/editing/EditingUtilities.h" |
29 #include "core/editing/Editor.h" | 29 #include "core/editing/Editor.h" |
30 #include "core/editing/SelectionAdjuster.h" | |
31 #include "core/events/Event.h" | 30 #include "core/events/Event.h" |
32 #include "core/frame/LocalFrame.h" | 31 #include "core/frame/LocalFrame.h" |
33 #include "core/frame/Settings.h" | 32 #include "core/frame/Settings.h" |
34 #include "core/layout/LayoutBlock.h" | 33 #include "core/layout/LayoutBlock.h" |
35 #include "core/layout/line/InlineTextBox.h" | 34 #include "core/layout/line/InlineTextBox.h" |
36 #include "core/page/SpatialNavigation.h" | 35 #include "core/page/SpatialNavigation.h" |
37 | 36 |
38 namespace blink { | 37 namespace blink { |
39 | 38 |
40 static inline LayoutUnit NoXPosForVerticalArrowNavigation() | 39 static inline LayoutUnit NoXPosForVerticalArrowNavigation() |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 SelectionAdjuster::adjustSelectionInComposedTree(&m_selectionInComposedTree,
m_selection); | 90 SelectionAdjuster::adjustSelectionInComposedTree(&m_selectionInComposedTree,
m_selection); |
92 } | 91 } |
93 | 92 |
94 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree&
newSelection, FrameSelection::SetSelectionOptions options) | 93 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree&
newSelection, FrameSelection::SetSelectionOptions options) |
95 { | 94 { |
96 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree)); | 95 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree)); |
97 m_selectionInComposedTree = newSelection; | 96 m_selectionInComposedTree = newSelection; |
98 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInCompo
sedTree); | 97 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInCompo
sedTree); |
99 } | 98 } |
100 | 99 |
| 100 // TODO(yosin): We should move |
| 101 // |SelectionAdjuster::adjustSelectionInComposedTree()| to |
| 102 // "SelectionAdjuster.cpp" |
| 103 // Updates |selectionInComposedTree| to match with |selection|. |
| 104 void SelectionAdjuster::adjustSelectionInComposedTree(VisibleSelectionInComposed
Tree* selectionInComposedTree, const VisibleSelection& selection) |
| 105 { |
| 106 if (selection.isNone()) { |
| 107 *selectionInComposedTree = VisibleSelectionInComposedTree(); |
| 108 return; |
| 109 } |
| 110 |
| 111 const PositionInComposedTree& base = toPositionInComposedTree(selection.base
()); |
| 112 const PositionInComposedTree& extent = toPositionInComposedTree(selection.ex
tent()); |
| 113 const PositionInComposedTree& position1 = toPositionInComposedTree(selection
.start()); |
| 114 const PositionInComposedTree& position2 = toPositionInComposedTree(selection
.end()); |
| 115 position1.anchorNode()->updateDistribution(); |
| 116 position2.anchorNode()->updateDistribution(); |
| 117 selectionInComposedTree->m_base = base; |
| 118 selectionInComposedTree->m_extent = extent; |
| 119 selectionInComposedTree->m_affinity = selection.m_affinity; |
| 120 selectionInComposedTree->m_isDirectional = selection.m_isDirectional; |
| 121 selectionInComposedTree->m_baseIsFirst = base.isNull() || base.compareTo(ext
ent) <= 0; |
| 122 if (position1.compareTo(position2) <= 0) { |
| 123 selectionInComposedTree->m_start = position1; |
| 124 selectionInComposedTree->m_end = position2; |
| 125 } else { |
| 126 selectionInComposedTree->m_start = position2; |
| 127 selectionInComposedTree->m_end = position1; |
| 128 } |
| 129 selectionInComposedTree->updateSelectionType(); |
| 130 } |
| 131 |
| 132 static bool isCrossingShadowBoundaries(const VisibleSelectionInComposedTree& sel
ection) |
| 133 { |
| 134 if (!selection.isRange()) |
| 135 return false; |
| 136 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); |
| 137 return selection.extent().anchorNode()->treeScope() != treeScope |
| 138 || selection.start().anchorNode()->treeScope() != treeScope |
| 139 || selection.end().anchorNode()->treeScope() != treeScope; |
| 140 } |
| 141 |
| 142 // TODO(yosin): We should move |
| 143 // |SelectionAdjuster::adjustSelectionInDOMTree()| to |
| 144 // "SelectionAdjuster.cpp" |
| 145 void SelectionAdjuster::adjustSelectionInDOMTree(VisibleSelection* selection, co
nst VisibleSelectionInComposedTree& selectionInComposedTree) |
| 146 { |
| 147 if (selectionInComposedTree.isNone()) { |
| 148 *selection = VisibleSelection(); |
| 149 return; |
| 150 } |
| 151 |
| 152 const Position& base = toPositionInDOMTree(selectionInComposedTree.base()); |
| 153 const Position& extent = toPositionInDOMTree(selectionInComposedTree.extent(
)); |
| 154 |
| 155 if (isCrossingShadowBoundaries(selectionInComposedTree)) { |
| 156 *selection = VisibleSelection(base, extent); |
| 157 return; |
| 158 } |
| 159 |
| 160 const Position& position1 = toPositionInDOMTree(selectionInComposedTree.star
t()); |
| 161 const Position& position2 = toPositionInDOMTree(selectionInComposedTree.end(
)); |
| 162 selection->m_base = base; |
| 163 selection->m_extent = extent; |
| 164 selection->m_affinity = selectionInComposedTree.m_affinity; |
| 165 selection->m_isDirectional = selectionInComposedTree.m_isDirectional; |
| 166 selection->m_baseIsFirst = base.isNull() || base.compareTo(extent) <= 0; |
| 167 if (position1.compareTo(position2) <= 0) { |
| 168 selection->m_start = position1; |
| 169 selection->m_end = position2; |
| 170 } else { |
| 171 selection->m_start = position2; |
| 172 selection->m_end = position1; |
| 173 } |
| 174 selection->updateSelectionType(); |
| 175 } |
| 176 |
101 void SelectionEditor::resetXPosForVerticalArrowNavigation() | 177 void SelectionEditor::resetXPosForVerticalArrowNavigation() |
102 { | 178 { |
103 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); | 179 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); |
104 } | 180 } |
105 | 181 |
106 void SelectionEditor::setIsDirectional(bool isDirectional) | 182 void SelectionEditor::setIsDirectional(bool isDirectional) |
107 { | 183 { |
108 m_selection.setIsDirectional(isDirectional); | 184 m_selection.setIsDirectional(isDirectional); |
109 m_selectionInComposedTree.setIsDirectional(isDirectional); | 185 m_selectionInComposedTree.setIsDirectional(isDirectional); |
110 } | 186 } |
(...skipping 775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 DEFINE_TRACE(SelectionEditor) | 962 DEFINE_TRACE(SelectionEditor) |
887 { | 963 { |
888 visitor->trace(m_frameSelection); | 964 visitor->trace(m_frameSelection); |
889 visitor->trace(m_selection); | 965 visitor->trace(m_selection); |
890 visitor->trace(m_selectionInComposedTree); | 966 visitor->trace(m_selectionInComposedTree); |
891 visitor->trace(m_logicalRange); | 967 visitor->trace(m_logicalRange); |
892 VisibleSelectionChangeObserver::trace(visitor); | 968 VisibleSelectionChangeObserver::trace(visitor); |
893 } | 969 } |
894 | 970 |
895 } // namespace blink | 971 } // namespace blink |
OLD | NEW |