| 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 } | 80 } |
| 81 | 81 |
| 82 void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection,
FrameSelection::SetSelectionOptions options) | 82 void SelectionEditor::setVisibleSelection(const VisibleSelection& newSelection,
FrameSelection::SetSelectionOptions options) |
| 83 { | 83 { |
| 84 m_selection = newSelection; | 84 m_selection = newSelection; |
| 85 if (options & FrameSelection::DoNotAdjustInComposedTree) { | 85 if (options & FrameSelection::DoNotAdjustInComposedTree) { |
| 86 m_selectionInComposedTree.setWithoutValidation(toPositionInComposedTree(
m_selection.base()), toPositionInComposedTree(m_selection.extent())); | 86 m_selectionInComposedTree.setWithoutValidation(toPositionInComposedTree(
m_selection.base()), toPositionInComposedTree(m_selection.extent())); |
| 87 return; | 87 return; |
| 88 } | 88 } |
| 89 | 89 |
| 90 SelectionAdjuster::adjustSelectionInComposedTree(&m_selectionInComposedTree,
m_selection); | 90 adjustVisibleSelectionInComposedTree(); |
| 91 } | 91 } |
| 92 | 92 |
| 93 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree&
newSelection, FrameSelection::SetSelectionOptions options) | 93 void SelectionEditor::setVisibleSelection(const VisibleSelectionInComposedTree&
newSelection, FrameSelection::SetSelectionOptions options) |
| 94 { | 94 { |
| 95 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree)); | 95 ASSERT(!(options & FrameSelection::DoNotAdjustInComposedTree)); |
| 96 m_selectionInComposedTree = newSelection; | 96 m_selectionInComposedTree = newSelection; |
| 97 SelectionAdjuster::adjustSelectionInDOMTree(&m_selection, m_selectionInCompo
sedTree); | 97 adjustVisibleSelectionInDOMTree(); |
| 98 } | 98 } |
| 99 | 99 |
| 100 // TODO(yosin): We should move | 100 // Updates |m_selectionInComposedTree| to match with |m_selection|. |
| 101 // |SelectionAdjuster::adjustSelectionInComposedTree()| to | 101 void SelectionEditor::adjustVisibleSelectionInComposedTree() |
| 102 // "SelectionAdjuster.cpp" | |
| 103 // Updates |selectionInComposedTree| to match with |selection|. | |
| 104 void SelectionAdjuster::adjustSelectionInComposedTree(VisibleSelectionInComposed
Tree* selectionInComposedTree, const VisibleSelection& selection) | |
| 105 { | 102 { |
| 106 if (selection.isNone()) { | 103 if (m_selection.isNone()) { |
| 107 *selectionInComposedTree = VisibleSelectionInComposedTree(); | 104 m_selectionInComposedTree = VisibleSelectionInComposedTree(); |
| 108 return; | 105 return; |
| 109 } | 106 } |
| 110 | 107 |
| 111 const PositionInComposedTree& base = toPositionInComposedTree(selection.base
()); | 108 const PositionInComposedTree base = toPositionInComposedTree(m_selection.bas
e()); |
| 112 const PositionInComposedTree& extent = toPositionInComposedTree(selection.ex
tent()); | 109 const PositionInComposedTree extent = toPositionInComposedTree(m_selection.e
xtent()); |
| 113 const PositionInComposedTree& position1 = toPositionInComposedTree(selection
.start()); | 110 const PositionInComposedTree position1 = toPositionInComposedTree(m_selectio
n.start()); |
| 114 const PositionInComposedTree& position2 = toPositionInComposedTree(selection
.end()); | 111 const PositionInComposedTree position2 = toPositionInComposedTree(m_selectio
n.end()); |
| 115 position1.anchorNode()->updateDistribution(); | 112 position1.anchorNode()->updateDistribution(); |
| 116 position2.anchorNode()->updateDistribution(); | 113 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) { | 114 if (position1.compareTo(position2) <= 0) { |
| 123 selectionInComposedTree->m_start = position1; | 115 m_selectionInComposedTree = VisibleSelectionInComposedTree::createWithou
tValidation(base, extent, position1, position2, m_selection.affinity(), m_select
ion.isDirectional()); |
| 124 selectionInComposedTree->m_end = position2; | 116 return; |
| 125 } else { | |
| 126 selectionInComposedTree->m_start = position2; | |
| 127 selectionInComposedTree->m_end = position1; | |
| 128 } | 117 } |
| 129 selectionInComposedTree->updateSelectionType(); | 118 m_selectionInComposedTree = VisibleSelectionInComposedTree::createWithoutVal
idation(base, extent, position2, position1, m_selection.affinity(), m_selection.
isDirectional()); |
| 130 } | 119 } |
| 131 | 120 |
| 132 static bool isCrossingShadowBoundaries(const VisibleSelectionInComposedTree& sel
ection) | 121 static bool isCrossingShadowBoundaries(const VisibleSelectionInComposedTree& sel
ection) |
| 133 { | 122 { |
| 134 if (!selection.isRange()) | 123 if (!selection.isRange()) |
| 135 return false; | 124 return false; |
| 136 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); | 125 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); |
| 137 return selection.extent().anchorNode()->treeScope() != treeScope | 126 return selection.extent().anchorNode()->treeScope() != treeScope |
| 138 || selection.start().anchorNode()->treeScope() != treeScope | 127 || selection.start().anchorNode()->treeScope() != treeScope |
| 139 || selection.end().anchorNode()->treeScope() != treeScope; | 128 || selection.end().anchorNode()->treeScope() != treeScope; |
| 140 } | 129 } |
| 141 | 130 |
| 142 // TODO(yosin): We should move | 131 void SelectionEditor::adjustVisibleSelectionInDOMTree() |
| 143 // |SelectionAdjuster::adjustSelectionInDOMTree()| to | |
| 144 // "SelectionAdjuster.cpp" | |
| 145 void SelectionAdjuster::adjustSelectionInDOMTree(VisibleSelection* selection, co
nst VisibleSelectionInComposedTree& selectionInComposedTree) | |
| 146 { | 132 { |
| 147 if (selectionInComposedTree.isNone()) { | 133 if (m_selectionInComposedTree.isNone()) { |
| 148 *selection = VisibleSelection(); | 134 m_selection = VisibleSelection(); |
| 149 return; | 135 return; |
| 150 } | 136 } |
| 151 | 137 |
| 152 const Position& base = toPositionInDOMTree(selectionInComposedTree.base()); | 138 const Position base = toPositionInDOMTree(m_selectionInComposedTree.base()); |
| 153 const Position& extent = toPositionInDOMTree(selectionInComposedTree.extent(
)); | 139 const Position extent = toPositionInDOMTree(m_selectionInComposedTree.extent
()); |
| 154 | 140 |
| 155 if (isCrossingShadowBoundaries(selectionInComposedTree)) { | 141 if (isCrossingShadowBoundaries(m_selectionInComposedTree)) { |
| 156 *selection = VisibleSelection(base, extent); | 142 m_selection = VisibleSelection(base, extent); |
| 157 return; | 143 return; |
| 158 } | 144 } |
| 159 | 145 |
| 160 const Position& position1 = toPositionInDOMTree(selectionInComposedTree.star
t()); | 146 const Position start = toPositionInDOMTree(m_selectionInComposedTree.start()
); |
| 161 const Position& position2 = toPositionInDOMTree(selectionInComposedTree.end(
)); | 147 const Position end = toPositionInDOMTree(m_selectionInComposedTree.end()); |
| 162 selection->m_base = base; | 148 const TextAffinity affinity = m_selectionInComposedTree.affinity(); |
| 163 selection->m_extent = extent; | 149 const bool isDirectional = m_selectionInComposedTree.isDirectional(); |
| 164 selection->m_affinity = selectionInComposedTree.m_affinity; | 150 if (start.compareTo(end) <= 0) { |
| 165 selection->m_isDirectional = selectionInComposedTree.m_isDirectional; | 151 m_selection = VisibleSelection::createWithoutValidation(base, extent, st
art, end, affinity, isDirectional); |
| 166 selection->m_baseIsFirst = base.isNull() || base.compareTo(extent) <= 0; | 152 return; |
| 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 } | 153 } |
| 174 selection->updateSelectionType(); | 154 m_selection = VisibleSelection::createWithoutValidation(base, extent, end, s
tart, affinity, isDirectional); |
| 175 } | 155 } |
| 176 | 156 |
| 177 void SelectionEditor::resetXPosForVerticalArrowNavigation() | 157 void SelectionEditor::resetXPosForVerticalArrowNavigation() |
| 178 { | 158 { |
| 179 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); | 159 m_xPosForVerticalArrowNavigation = NoXPosForVerticalArrowNavigation(); |
| 180 } | 160 } |
| 181 | 161 |
| 182 void SelectionEditor::setIsDirectional(bool isDirectional) | 162 void SelectionEditor::setIsDirectional(bool isDirectional) |
| 183 { | 163 { |
| 184 m_selection.setIsDirectional(isDirectional); | 164 m_selection.setIsDirectional(isDirectional); |
| (...skipping 777 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 962 DEFINE_TRACE(SelectionEditor) | 942 DEFINE_TRACE(SelectionEditor) |
| 963 { | 943 { |
| 964 visitor->trace(m_frameSelection); | 944 visitor->trace(m_frameSelection); |
| 965 visitor->trace(m_selection); | 945 visitor->trace(m_selection); |
| 966 visitor->trace(m_selectionInComposedTree); | 946 visitor->trace(m_selectionInComposedTree); |
| 967 visitor->trace(m_logicalRange); | 947 visitor->trace(m_logicalRange); |
| 968 VisibleSelectionChangeObserver::trace(visitor); | 948 VisibleSelectionChangeObserver::trace(visitor); |
| 969 } | 949 } |
| 970 | 950 |
| 971 } // namespace blink | 951 } // namespace blink |
| OLD | NEW |