OLD | NEW |
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 1034 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1045 return nullptr; | 1045 return nullptr; |
1046 } else if (IsEndOfEditableOrNonEditableContent(visible_end)) { | 1046 } else if (IsEndOfEditableOrNonEditableContent(visible_end)) { |
1047 // At the end of the editable region. We can bail here as well. | 1047 // At the end of the editable region. We can bail here as well. |
1048 return nullptr; | 1048 return nullptr; |
1049 } | 1049 } |
1050 } | 1050 } |
1051 | 1051 |
1052 if (visible_paragraph_end.IsNull()) | 1052 if (visible_paragraph_end.IsNull()) |
1053 return nullptr; | 1053 return nullptr; |
1054 | 1054 |
1055 HTMLElement* new_block = | 1055 HTMLElement* const new_block = |
1056 InsertNewDefaultParagraphElementAt(upstream_start, editing_state); | 1056 InsertNewDefaultParagraphElementAt(upstream_start, editing_state); |
1057 if (editing_state->IsAborted()) | 1057 if (editing_state->IsAborted()) |
1058 return nullptr; | 1058 return nullptr; |
| 1059 DCHECK(new_block); |
1059 | 1060 |
1060 bool end_was_br = | 1061 bool end_was_br = |
1061 isHTMLBRElement(*visible_paragraph_end.DeepEquivalent().AnchorNode()); | 1062 isHTMLBRElement(*visible_paragraph_end.DeepEquivalent().AnchorNode()); |
1062 | 1063 |
1063 // Inserting default paragraph element can change visible position. We | 1064 // Inserting default paragraph element can change visible position. We |
1064 // should update visible positions before use them. | 1065 // should update visible positions before use them. |
1065 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1066 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
1066 visible_pos = CreateVisiblePosition(pos, VP_DEFAULT_AFFINITY); | 1067 visible_pos = CreateVisiblePosition(pos, VP_DEFAULT_AFFINITY); |
1067 visible_paragraph_start = StartOfParagraph(visible_pos); | 1068 visible_paragraph_start = StartOfParagraph(visible_pos); |
1068 visible_paragraph_end = EndOfParagraph(visible_pos); | 1069 visible_paragraph_end = EndOfParagraph(visible_pos); |
1069 MoveParagraphs(visible_paragraph_start, visible_paragraph_end, | 1070 MoveParagraphs(visible_paragraph_start, visible_paragraph_end, |
1070 VisiblePosition::FirstPositionInNode(new_block), | 1071 VisiblePosition::FirstPositionInNode(*new_block), |
1071 editing_state); | 1072 editing_state); |
1072 if (editing_state->IsAborted()) | 1073 if (editing_state->IsAborted()) |
1073 return nullptr; | 1074 return nullptr; |
1074 | 1075 |
1075 if (new_block->lastChild() && isHTMLBRElement(*new_block->lastChild()) && | 1076 if (new_block->lastChild() && isHTMLBRElement(*new_block->lastChild()) && |
1076 !end_was_br) { | 1077 !end_was_br) { |
1077 RemoveNode(new_block->lastChild(), editing_state); | 1078 RemoveNode(new_block->lastChild(), editing_state); |
1078 if (editing_state->IsAborted()) | 1079 if (editing_state->IsAborted()) |
1079 return nullptr; | 1080 return nullptr; |
1080 } | 1081 } |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1791 Element* enclosing_anchor = EnclosingAnchorElement(original); | 1792 Element* enclosing_anchor = EnclosingAnchorElement(original); |
1792 Position result = original; | 1793 Position result = original; |
1793 | 1794 |
1794 if (!enclosing_anchor) | 1795 if (!enclosing_anchor) |
1795 return result; | 1796 return result; |
1796 | 1797 |
1797 // Don't avoid block level anchors, because that would insert content into the | 1798 // Don't avoid block level anchors, because that would insert content into the |
1798 // wrong paragraph. | 1799 // wrong paragraph. |
1799 if (enclosing_anchor && !IsEnclosingBlock(enclosing_anchor)) { | 1800 if (enclosing_anchor && !IsEnclosingBlock(enclosing_anchor)) { |
1800 VisiblePosition first_in_anchor = | 1801 VisiblePosition first_in_anchor = |
1801 VisiblePosition::FirstPositionInNode(enclosing_anchor); | 1802 VisiblePosition::FirstPositionInNode(*enclosing_anchor); |
1802 VisiblePosition last_in_anchor = | 1803 VisiblePosition last_in_anchor = |
1803 VisiblePosition::LastPositionInNode(enclosing_anchor); | 1804 VisiblePosition::LastPositionInNode(enclosing_anchor); |
1804 // If visually just after the anchor, insert *inside* the anchor unless it's | 1805 // If visually just after the anchor, insert *inside* the anchor unless it's |
1805 // the last VisiblePosition in the document, to match NSTextView. | 1806 // the last VisiblePosition in the document, to match NSTextView. |
1806 if (visible_pos.DeepEquivalent() == last_in_anchor.DeepEquivalent()) { | 1807 if (visible_pos.DeepEquivalent() == last_in_anchor.DeepEquivalent()) { |
1807 // Make sure anchors are pushed down before avoiding them so that we don't | 1808 // Make sure anchors are pushed down before avoiding them so that we don't |
1808 // also avoid structural elements like lists and blocks (5142012). | 1809 // also avoid structural elements like lists and blocks (5142012). |
1809 if (original.AnchorNode() != enclosing_anchor && | 1810 if (original.AnchorNode() != enclosing_anchor && |
1810 original.AnchorNode()->parentNode() != enclosing_anchor) { | 1811 original.AnchorNode()->parentNode() != enclosing_anchor) { |
1811 PushAnchorElementDown(enclosing_anchor, editing_state); | 1812 PushAnchorElementDown(enclosing_anchor, editing_state); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1875 for (node = start; node->parentNode() != end_node; | 1876 for (node = start; node->parentNode() != end_node; |
1876 node = node->parentNode()) { | 1877 node = node->parentNode()) { |
1877 Element* parent_element = node->parentElement(); | 1878 Element* parent_element = node->parentElement(); |
1878 if (!parent_element) | 1879 if (!parent_element) |
1879 break; | 1880 break; |
1880 | 1881 |
1881 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); | 1882 GetDocument().UpdateStyleAndLayoutIgnorePendingStylesheets(); |
1882 | 1883 |
1883 // Do not split a node when doing so introduces an empty node. | 1884 // Do not split a node when doing so introduces an empty node. |
1884 VisiblePosition position_in_parent = | 1885 VisiblePosition position_in_parent = |
1885 VisiblePosition::FirstPositionInNode(parent_element); | 1886 VisiblePosition::FirstPositionInNode(*parent_element); |
1886 VisiblePosition position_in_node = | 1887 VisiblePosition position_in_node = |
1887 CreateVisiblePosition(FirstPositionInOrBeforeNode(node)); | 1888 CreateVisiblePosition(FirstPositionInOrBeforeNode(node)); |
1888 if (position_in_parent.DeepEquivalent() != | 1889 if (position_in_parent.DeepEquivalent() != |
1889 position_in_node.DeepEquivalent()) | 1890 position_in_node.DeepEquivalent()) |
1890 SplitElement(parent_element, node); | 1891 SplitElement(parent_element, node); |
1891 } | 1892 } |
1892 | 1893 |
1893 return node; | 1894 return node; |
1894 } | 1895 } |
1895 | 1896 |
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1974 | 1975 |
1975 DEFINE_TRACE(CompositeEditCommand) { | 1976 DEFINE_TRACE(CompositeEditCommand) { |
1976 visitor->Trace(commands_); | 1977 visitor->Trace(commands_); |
1977 visitor->Trace(starting_selection_); | 1978 visitor->Trace(starting_selection_); |
1978 visitor->Trace(ending_selection_); | 1979 visitor->Trace(ending_selection_); |
1979 visitor->Trace(undo_step_); | 1980 visitor->Trace(undo_step_); |
1980 EditCommand::Trace(visitor); | 1981 EditCommand::Trace(visitor); |
1981 } | 1982 } |
1982 | 1983 |
1983 } // namespace blink | 1984 } // namespace blink |
OLD | NEW |