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

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

Issue 2955823002: Make VisiblePosition::FirstPositionInNode() to take const Node& instead of Node* (Closed)
Patch Set: 2017-06-26T13:57:23 Created 3 years, 5 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, 2007, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 2006, 2007, 2008 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 1049 matching lines...) Expand 10 before | Expand all | Expand 10 after
1060 bool end_was_br = 1060 bool end_was_br =
1061 isHTMLBRElement(*visible_paragraph_end.DeepEquivalent().AnchorNode()); 1061 isHTMLBRElement(*visible_paragraph_end.DeepEquivalent().AnchorNode());
1062 1062
1063 // Inserting default paragraph element can change visible position. We 1063 // Inserting default paragraph element can change visible position. We
1064 // should update visible positions before use them. 1064 // should update visible positions before use them.
1065 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 1065 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
1066 visible_pos = CreateVisiblePosition(pos, VP_DEFAULT_AFFINITY); 1066 visible_pos = CreateVisiblePosition(pos, VP_DEFAULT_AFFINITY);
1067 visible_paragraph_start = StartOfParagraph(visible_pos); 1067 visible_paragraph_start = StartOfParagraph(visible_pos);
1068 visible_paragraph_end = EndOfParagraph(visible_pos); 1068 visible_paragraph_end = EndOfParagraph(visible_pos);
1069 MoveParagraphs(visible_paragraph_start, visible_paragraph_end, 1069 MoveParagraphs(visible_paragraph_start, visible_paragraph_end,
1070 VisiblePosition::FirstPositionInNode(new_block), 1070 VisiblePosition::FirstPositionInNode(*new_block),
tkent 2017/06/26 08:08:22 Is new_block always non-null?
yosin_UTC9 2017/06/26 08:53:52 Yes, |new_block| holds return value of InsertNewDe
1071 editing_state); 1071 editing_state);
1072 if (editing_state->IsAborted()) 1072 if (editing_state->IsAborted())
1073 return nullptr; 1073 return nullptr;
1074 1074
1075 if (new_block->lastChild() && isHTMLBRElement(*new_block->lastChild()) && 1075 if (new_block->lastChild() && isHTMLBRElement(*new_block->lastChild()) &&
1076 !end_was_br) { 1076 !end_was_br) {
1077 RemoveNode(new_block->lastChild(), editing_state); 1077 RemoveNode(new_block->lastChild(), editing_state);
1078 if (editing_state->IsAborted()) 1078 if (editing_state->IsAborted())
1079 return nullptr; 1079 return nullptr;
1080 } 1080 }
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
1791 Element* enclosing_anchor = EnclosingAnchorElement(original); 1791 Element* enclosing_anchor = EnclosingAnchorElement(original);
1792 Position result = original; 1792 Position result = original;
1793 1793
1794 if (!enclosing_anchor) 1794 if (!enclosing_anchor)
1795 return result; 1795 return result;
1796 1796
1797 // Don't avoid block level anchors, because that would insert content into the 1797 // Don't avoid block level anchors, because that would insert content into the
1798 // wrong paragraph. 1798 // wrong paragraph.
1799 if (enclosing_anchor && !IsEnclosingBlock(enclosing_anchor)) { 1799 if (enclosing_anchor && !IsEnclosingBlock(enclosing_anchor)) {
1800 VisiblePosition first_in_anchor = 1800 VisiblePosition first_in_anchor =
1801 VisiblePosition::FirstPositionInNode(enclosing_anchor); 1801 VisiblePosition::FirstPositionInNode(*enclosing_anchor);
1802 VisiblePosition last_in_anchor = 1802 VisiblePosition last_in_anchor =
1803 VisiblePosition::LastPositionInNode(enclosing_anchor); 1803 VisiblePosition::LastPositionInNode(enclosing_anchor);
1804 // If visually just after the anchor, insert *inside* the anchor unless it's 1804 // If visually just after the anchor, insert *inside* the anchor unless it's
1805 // the last VisiblePosition in the document, to match NSTextView. 1805 // the last VisiblePosition in the document, to match NSTextView.
1806 if (visible_pos.DeepEquivalent() == last_in_anchor.DeepEquivalent()) { 1806 if (visible_pos.DeepEquivalent() == last_in_anchor.DeepEquivalent()) {
1807 // Make sure anchors are pushed down before avoiding them so that we don't 1807 // Make sure anchors are pushed down before avoiding them so that we don't
1808 // also avoid structural elements like lists and blocks (5142012). 1808 // also avoid structural elements like lists and blocks (5142012).
1809 if (original.AnchorNode() != enclosing_anchor && 1809 if (original.AnchorNode() != enclosing_anchor &&
1810 original.AnchorNode()->parentNode() != enclosing_anchor) { 1810 original.AnchorNode()->parentNode() != enclosing_anchor) {
1811 PushAnchorElementDown(enclosing_anchor, editing_state); 1811 PushAnchorElementDown(enclosing_anchor, editing_state);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1875 for (node = start; node->parentNode() != end_node; 1875 for (node = start; node->parentNode() != end_node;
1876 node = node->parentNode()) { 1876 node = node->parentNode()) {
1877 Element* parent_element = node->parentElement(); 1877 Element* parent_element = node->parentElement();
1878 if (!parent_element) 1878 if (!parent_element)
1879 break; 1879 break;
1880 1880
1881 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); 1881 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets();
1882 1882
1883 // Do not split a node when doing so introduces an empty node. 1883 // Do not split a node when doing so introduces an empty node.
1884 VisiblePosition position_in_parent = 1884 VisiblePosition position_in_parent =
1885 VisiblePosition::FirstPositionInNode(parent_element); 1885 VisiblePosition::FirstPositionInNode(*parent_element);
1886 VisiblePosition position_in_node = 1886 VisiblePosition position_in_node =
1887 CreateVisiblePosition(FirstPositionInOrBeforeNode(node)); 1887 CreateVisiblePosition(FirstPositionInOrBeforeNode(node));
1888 if (position_in_parent.DeepEquivalent() != 1888 if (position_in_parent.DeepEquivalent() !=
1889 position_in_node.DeepEquivalent()) 1889 position_in_node.DeepEquivalent())
1890 SplitElement(parent_element, node); 1890 SplitElement(parent_element, node);
1891 } 1891 }
1892 1892
1893 return node; 1893 return node;
1894 } 1894 }
1895 1895
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
1974 1974
1975 DEFINE_TRACE(CompositeEditCommand) { 1975 DEFINE_TRACE(CompositeEditCommand) {
1976 visitor->Trace(commands_); 1976 visitor->Trace(commands_);
1977 visitor->Trace(starting_selection_); 1977 visitor->Trace(starting_selection_);
1978 visitor->Trace(ending_selection_); 1978 visitor->Trace(ending_selection_);
1979 visitor->Trace(undo_step_); 1979 visitor->Trace(undo_step_);
1980 EditCommand::Trace(visitor); 1980 EditCommand::Trace(visitor);
1981 } 1981 }
1982 1982
1983 } // namespace blink 1983 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698