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 |
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 static bool isCrossingShadowBoundaries( | 190 static bool isCrossingShadowBoundaries( |
191 const VisibleSelectionInFlatTree& selection) { | 191 const VisibleSelectionInFlatTree& selection) { |
192 if (!selection.isRange()) | 192 if (!selection.isRange()) |
193 return false; | 193 return false; |
194 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); | 194 TreeScope& treeScope = selection.base().anchorNode()->treeScope(); |
195 return selection.extent().anchorNode()->treeScope() != treeScope || | 195 return selection.extent().anchorNode()->treeScope() != treeScope || |
196 selection.start().anchorNode()->treeScope() != treeScope || | 196 selection.start().anchorNode()->treeScope() != treeScope || |
197 selection.end().anchorNode()->treeScope() != treeScope; | 197 selection.end().anchorNode()->treeScope() != treeScope; |
198 } | 198 } |
199 | 199 |
| 200 // TODO(yosin): We should make |adjustSelectionInDOMTree()| to return |
| 201 // |VisibleSelection| once |VisibleSelection| constructor doesn't call |
| 202 // |validate()|. |
200 void SelectionAdjuster::adjustSelectionInDOMTree( | 203 void SelectionAdjuster::adjustSelectionInDOMTree( |
201 VisibleSelection* selection, | 204 VisibleSelection* selection, |
202 const VisibleSelectionInFlatTree& selectionInFlatTree) { | 205 const VisibleSelectionInFlatTree& selectionInFlatTree) { |
203 if (selectionInFlatTree.isNone()) { | 206 if (selectionInFlatTree.isNone()) { |
204 *selection = VisibleSelection(); | 207 *selection = VisibleSelection(); |
205 return; | 208 return; |
206 } | 209 } |
207 | 210 |
208 const Position& base = toPositionInDOMTree(selectionInFlatTree.base()); | 211 const Position& base = toPositionInDOMTree(selectionInFlatTree.base()); |
209 const Position& extent = toPositionInDOMTree(selectionInFlatTree.extent()); | 212 const Position& extent = toPositionInDOMTree(selectionInFlatTree.extent()); |
210 | 213 |
211 if (isCrossingShadowBoundaries(selectionInFlatTree)) { | 214 if (isCrossingShadowBoundaries(selectionInFlatTree)) { |
212 DCHECK(base.document()); | 215 DCHECK(base.document()); |
213 | 216 |
214 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets | 217 // TODO(xiaochengh): The use of updateStyleAndLayoutIgnorePendingStylesheets |
215 // needs to be audited. See http://crbug.com/590369 for more details. | 218 // needs to be audited. See http://crbug.com/590369 for more details. |
216 // This layout update call cannot be hoisted out of the |if|, otherwise it's | 219 // This layout update call cannot be hoisted out of the |if|, otherwise it's |
217 // going to cause performance regression (http://crbug.com/652301). | 220 // going to cause performance regression (http://crbug.com/652301). |
218 // TODO(yosin): Implement and apply lazy visible selection validation so | 221 // TODO(yosin): Implement and apply lazy visible selection validation so |
219 // that we don't need to update layout here. | 222 // that we don't need to update layout here. |
220 base.document()->updateStyleAndLayoutIgnorePendingStylesheets(); | 223 base.document()->updateStyleAndLayoutIgnorePendingStylesheets(); |
221 | 224 |
222 *selection = createVisibleSelection(base, extent); | 225 *selection = createVisibleSelection( |
| 226 SelectionInDOMTree::Builder().setBaseAndExtent(base, extent).build()); |
223 return; | 227 return; |
224 } | 228 } |
225 | 229 |
226 const Position& position1 = toPositionInDOMTree(selectionInFlatTree.start()); | 230 const Position& position1 = toPositionInDOMTree(selectionInFlatTree.start()); |
227 const Position& position2 = toPositionInDOMTree(selectionInFlatTree.end()); | 231 const Position& position2 = toPositionInDOMTree(selectionInFlatTree.end()); |
228 selection->m_base = base; | 232 selection->m_base = base; |
229 selection->m_extent = extent; | 233 selection->m_extent = extent; |
230 selection->m_affinity = selectionInFlatTree.m_affinity; | 234 selection->m_affinity = selectionInFlatTree.m_affinity; |
231 selection->m_isDirectional = selectionInFlatTree.m_isDirectional; | 235 selection->m_isDirectional = selectionInFlatTree.m_isDirectional; |
232 selection->m_granularity = selectionInFlatTree.m_granularity; | 236 selection->m_granularity = selectionInFlatTree.m_granularity; |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 return; | 294 return; |
291 } | 295 } |
292 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; | 296 Node* const shadowHost = shadowHostEnd ? shadowHostEnd : shadowHostStart; |
293 const PositionInFlatTree& newStart = | 297 const PositionInFlatTree& newStart = |
294 adjustPositionInFlatTreeForStart(selection->start(), shadowHost); | 298 adjustPositionInFlatTreeForStart(selection->start(), shadowHost); |
295 selection->m_extent = newStart; | 299 selection->m_extent = newStart; |
296 selection->m_start = newStart; | 300 selection->m_start = newStart; |
297 } | 301 } |
298 | 302 |
299 } // namespace blink | 303 } // namespace blink |
OLD | NEW |