Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(175)

Side by Side Diff: third_party/WebKit/Source/core/editing/commands/ReplaceSelectionCommand.cpp

Issue 2958483003: Make VisiblePosition::BeforeNode() to take const Node& instead of Node* (Closed)
Patch Set: 017-06-23T18:57:25 Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights reserved. 3 * Copyright (C) 2009, 2010, 2011 Google Inc. All rights 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 916 matching lines...) Expand 10 before | Expand all | Expand 10 after
927 InsertNodeBefore(placeholder, 927 InsertNodeBefore(placeholder,
928 start_of_paragraph_to_move.DeepEquivalent().AnchorNode(), 928 start_of_paragraph_to_move.DeepEquivalent().AnchorNode(),
929 editing_state); 929 editing_state);
930 if (editing_state->IsAborted()) 930 if (editing_state->IsAborted())
931 return; 931 return;
932 932
933 // TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets() 933 // TODO(editing-dev): Use of updateStyleAndLayoutIgnorePendingStylesheets()
934 // needs to be audited. See http://crbug.com/590369 for more details. 934 // needs to be audited. See http://crbug.com/590369 for more details.
935 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 935 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
936 936
937 destination = VisiblePosition::BeforeNode(placeholder); 937 destination = VisiblePosition::BeforeNode(*placeholder);
938 start_of_paragraph_to_move = CreateVisiblePosition( 938 start_of_paragraph_to_move = CreateVisiblePosition(
939 start_of_paragraph_to_move.ToPositionWithAffinity()); 939 start_of_paragraph_to_move.ToPositionWithAffinity());
940 } 940 }
941 941
942 MoveParagraph(start_of_paragraph_to_move, 942 MoveParagraph(start_of_paragraph_to_move,
943 EndOfParagraph(start_of_paragraph_to_move), destination, 943 EndOfParagraph(start_of_paragraph_to_move), destination,
944 editing_state); 944 editing_state);
945 if (editing_state->IsAborted()) 945 if (editing_state->IsAborted())
946 return; 946 return;
947 947
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
1177 // changed to mean the last position after p that maps to the same visible 1177 // changed to mean the last position after p that maps to the same visible
1178 // position as p (since in the case where a br is at the end of a block and 1178 // position as p (since in the case where a br is at the end of a block and
1179 // collapsed away, there are positions after the br which map to the same 1179 // collapsed away, there are positions after the br which map to the same
1180 // visible position as [br, 0]). 1180 // visible position as [br, 0]).
1181 HTMLBRElement* end_br = 1181 HTMLBRElement* end_br =
1182 isHTMLBRElement(*MostForwardCaretPosition(insertion_pos).AnchorNode()) 1182 isHTMLBRElement(*MostForwardCaretPosition(insertion_pos).AnchorNode())
1183 ? toHTMLBRElement( 1183 ? toHTMLBRElement(
1184 MostForwardCaretPosition(insertion_pos).AnchorNode()) 1184 MostForwardCaretPosition(insertion_pos).AnchorNode())
1185 : 0; 1185 : 0;
1186 VisiblePosition original_vis_pos_before_end_br; 1186 VisiblePosition original_vis_pos_before_end_br;
1187 if (end_br) 1187 if (end_br) {
1188 original_vis_pos_before_end_br = 1188 original_vis_pos_before_end_br =
1189 PreviousPositionOf(VisiblePosition::BeforeNode(end_br)); 1189 PreviousPositionOf(VisiblePosition::BeforeNode(*end_br));
1190 }
1190 1191
1191 Element* enclosing_block_of_insertion_pos = 1192 Element* enclosing_block_of_insertion_pos =
1192 EnclosingBlock(insertion_pos.AnchorNode()); 1193 EnclosingBlock(insertion_pos.AnchorNode());
1193 1194
1194 // Adjust |enclosingBlockOfInsertionPos| to prevent nesting. 1195 // Adjust |enclosingBlockOfInsertionPos| to prevent nesting.
1195 // If the start was in a Mail blockquote, we will have already handled 1196 // If the start was in a Mail blockquote, we will have already handled
1196 // adjusting |enclosingBlockOfInsertionPos| above. 1197 // adjusting |enclosingBlockOfInsertionPos| above.
1197 if (prevent_nesting_ && enclosing_block_of_insertion_pos && 1198 if (prevent_nesting_ && enclosing_block_of_insertion_pos &&
1198 enclosing_block_of_insertion_pos != current_root && 1199 enclosing_block_of_insertion_pos != current_root &&
1199 !IsTableCell(enclosing_block_of_insertion_pos) && 1200 !IsTableCell(enclosing_block_of_insertion_pos) &&
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after
1590 1591
1591 CompleteHTMLReplacement(last_position_to_select, editing_state); 1592 CompleteHTMLReplacement(last_position_to_select, editing_state);
1592 } 1593 }
1593 1594
1594 bool ReplaceSelectionCommand::ShouldRemoveEndBR( 1595 bool ReplaceSelectionCommand::ShouldRemoveEndBR(
1595 HTMLBRElement* end_br, 1596 HTMLBRElement* end_br,
1596 const VisiblePosition& original_vis_pos_before_end_br) { 1597 const VisiblePosition& original_vis_pos_before_end_br) {
1597 if (!end_br || !end_br->isConnected()) 1598 if (!end_br || !end_br->isConnected())
1598 return false; 1599 return false;
1599 1600
1600 VisiblePosition visible_pos = VisiblePosition::BeforeNode(end_br); 1601 VisiblePosition visible_pos = VisiblePosition::BeforeNode(*end_br);
1601 1602
1602 // Don't remove the br if nothing was inserted. 1603 // Don't remove the br if nothing was inserted.
1603 if (PreviousPositionOf(visible_pos).DeepEquivalent() == 1604 if (PreviousPositionOf(visible_pos).DeepEquivalent() ==
1604 original_vis_pos_before_end_br.DeepEquivalent()) 1605 original_vis_pos_before_end_br.DeepEquivalent())
1605 return false; 1606 return false;
1606 1607
1607 // Remove the br if it is collapsed away and so is unnecessary. 1608 // Remove the br if it is collapsed away and so is unnecessary.
1608 if (!GetDocument().InNoQuirksMode() && IsEndOfBlock(visible_pos) && 1609 if (!GetDocument().InNoQuirksMode() && IsEndOfBlock(visible_pos) &&
1609 !IsStartOfParagraph(visible_pos)) 1610 !IsStartOfParagraph(visible_pos))
1610 return true; 1611 return true;
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
1973 Position end = ReplaceSelectedTextInNode(text_node->data()); 1974 Position end = ReplaceSelectedTextInNode(text_node->data());
1974 if (end.IsNull()) 1975 if (end.IsNull())
1975 return false; 1976 return false;
1976 1977
1977 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 1978 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
1978 1979
1979 if (node_after_insertion_pos && node_after_insertion_pos->parentNode() && 1980 if (node_after_insertion_pos && node_after_insertion_pos->parentNode() &&
1980 isHTMLBRElement(*node_after_insertion_pos) && 1981 isHTMLBRElement(*node_after_insertion_pos) &&
1981 ShouldRemoveEndBR( 1982 ShouldRemoveEndBR(
1982 toHTMLBRElement(node_after_insertion_pos), 1983 toHTMLBRElement(node_after_insertion_pos),
1983 VisiblePosition::BeforeNode(node_after_insertion_pos))) { 1984 VisiblePosition::BeforeNode(*node_after_insertion_pos))) {
1984 RemoveNodeAndPruneAncestors(node_after_insertion_pos, editing_state); 1985 RemoveNodeAndPruneAncestors(node_after_insertion_pos, editing_state);
1985 if (editing_state->IsAborted()) 1986 if (editing_state->IsAborted())
1986 return false; 1987 return false;
1987 } 1988 }
1988 1989
1989 start_of_inserted_range_ = start; 1990 start_of_inserted_range_ = start;
1990 end_of_inserted_range_ = end; 1991 end_of_inserted_range_ = end;
1991 1992
1992 SetEndingSelection( 1993 SetEndingSelection(
1993 SelectionInDOMTree::Builder() 1994 SelectionInDOMTree::Builder()
(...skipping 15 matching lines...) Expand all
2009 visitor->Trace(start_of_inserted_content_); 2010 visitor->Trace(start_of_inserted_content_);
2010 visitor->Trace(end_of_inserted_content_); 2011 visitor->Trace(end_of_inserted_content_);
2011 visitor->Trace(insertion_style_); 2012 visitor->Trace(insertion_style_);
2012 visitor->Trace(document_fragment_); 2013 visitor->Trace(document_fragment_);
2013 visitor->Trace(start_of_inserted_range_); 2014 visitor->Trace(start_of_inserted_range_);
2014 visitor->Trace(end_of_inserted_range_); 2015 visitor->Trace(end_of_inserted_range_);
2015 CompositeEditCommand::Trace(visitor); 2016 CompositeEditCommand::Trace(visitor);
2016 } 2017 }
2017 2018
2018 } // namespace blink 2019 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698