| 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 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 270 DidFinishDOMMutation(); | 270 DidFinishDOMMutation(); |
| 271 return; | 271 return; |
| 272 } | 272 } |
| 273 const Position& new_base = UpdatePositionAfterAdoptingTextReplacement( | 273 const Position& new_base = UpdatePositionAfterAdoptingTextReplacement( |
| 274 selection_.base_, node, offset, old_length, new_length); | 274 selection_.base_, node, offset, old_length, new_length); |
| 275 const Position& new_extent = UpdatePositionAfterAdoptingTextReplacement( | 275 const Position& new_extent = UpdatePositionAfterAdoptingTextReplacement( |
| 276 selection_.extent_, node, offset, old_length, new_length); | 276 selection_.extent_, node, offset, old_length, new_length); |
| 277 DidFinishTextChange(new_base, new_extent); | 277 DidFinishTextChange(new_base, new_extent); |
| 278 } | 278 } |
| 279 | 279 |
| 280 // TODO(yosin): We should introduce |Position(const Text&, int)| to avoid | |
| 281 // |const_cast<Text*>|. | |
| 282 static Position UpdatePostionAfterAdoptingTextNodesMerged( | 280 static Position UpdatePostionAfterAdoptingTextNodesMerged( |
| 283 const Position& position, | 281 const Position& position, |
| 284 const Text& merged_node, | 282 const Text& merged_node, |
| 285 const NodeWithIndex& node_to_be_removed_with_index, | 283 const NodeWithIndex& node_to_be_removed_with_index, |
| 286 unsigned old_length) { | 284 unsigned old_length) { |
| 287 Node* const anchor_node = position.AnchorNode(); | 285 Node* const anchor_node = position.AnchorNode(); |
| 288 const Node& node_to_be_removed = node_to_be_removed_with_index.GetNode(); | 286 const Node& node_to_be_removed = node_to_be_removed_with_index.GetNode(); |
| 289 switch (position.AnchorType()) { | 287 switch (position.AnchorType()) { |
| 290 case PositionAnchorType::kBeforeChildren: | 288 case PositionAnchorType::kBeforeChildren: |
| 291 case PositionAnchorType::kAfterChildren: | 289 case PositionAnchorType::kAfterChildren: |
| 292 return position; | 290 return position; |
| 293 case PositionAnchorType::kBeforeAnchor: | 291 case PositionAnchorType::kBeforeAnchor: |
| 294 if (anchor_node == node_to_be_removed) | 292 if (anchor_node == node_to_be_removed) |
| 295 return Position(const_cast<Text*>(&merged_node), merged_node.length()); | 293 return Position(merged_node, merged_node.length()); |
| 296 return position; | 294 return position; |
| 297 case PositionAnchorType::kAfterAnchor: | 295 case PositionAnchorType::kAfterAnchor: |
| 298 if (anchor_node == node_to_be_removed) | 296 if (anchor_node == node_to_be_removed) |
| 299 return Position(const_cast<Text*>(&merged_node), merged_node.length()); | 297 return Position(merged_node, merged_node.length()); |
| 300 if (anchor_node == merged_node) | 298 if (anchor_node == merged_node) |
| 301 return Position(const_cast<Text*>(&merged_node), old_length); | 299 return Position(merged_node, old_length); |
| 302 return position; | 300 return position; |
| 303 case PositionAnchorType::kOffsetInAnchor: { | 301 case PositionAnchorType::kOffsetInAnchor: { |
| 304 const int offset = position.OffsetInContainerNode(); | 302 const int offset = position.OffsetInContainerNode(); |
| 305 if (anchor_node == node_to_be_removed) | 303 if (anchor_node == node_to_be_removed) |
| 306 return Position(const_cast<Text*>(&merged_node), old_length + offset); | 304 return Position(merged_node, old_length + offset); |
| 307 if (anchor_node == node_to_be_removed.parentNode() && | 305 if (anchor_node == node_to_be_removed.parentNode() && |
| 308 offset == node_to_be_removed_with_index.Index()) { | 306 offset == node_to_be_removed_with_index.Index()) { |
| 309 return Position(const_cast<Text*>(&merged_node), old_length); | 307 return Position(merged_node, old_length); |
| 310 } | 308 } |
| 311 return position; | 309 return position; |
| 312 } | 310 } |
| 313 } | 311 } |
| 314 NOTREACHED() << position; | 312 NOTREACHED() << position; |
| 315 return position; | 313 return position; |
| 316 } | 314 } |
| 317 | 315 |
| 318 void SelectionEditor::DidMergeTextNodes( | 316 void SelectionEditor::DidMergeTextNodes( |
| 319 const Text& merged_node, | 317 const Text& merged_node, |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 444 DEFINE_TRACE(SelectionEditor) { | 442 DEFINE_TRACE(SelectionEditor) { |
| 445 visitor->Trace(frame_); | 443 visitor->Trace(frame_); |
| 446 visitor->Trace(selection_); | 444 visitor->Trace(selection_); |
| 447 visitor->Trace(cached_visible_selection_in_dom_tree_); | 445 visitor->Trace(cached_visible_selection_in_dom_tree_); |
| 448 visitor->Trace(cached_visible_selection_in_flat_tree_); | 446 visitor->Trace(cached_visible_selection_in_flat_tree_); |
| 449 visitor->Trace(cached_range_); | 447 visitor->Trace(cached_range_); |
| 450 SynchronousMutationObserver::Trace(visitor); | 448 SynchronousMutationObserver::Trace(visitor); |
| 451 } | 449 } |
| 452 | 450 |
| 453 } // namespace blink | 451 } // namespace blink |
| OLD | NEW |