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

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

Issue 2810463002: Clean up DocumentMarkerController::copyMarkers() (now it's moveMarkers()) (Closed)
Patch Set: Created 3 years, 8 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, 2008 Apple Inc. All rights reserved. 2 * Copyright (C) 2005, 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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 if (!parent || !hasEditableStyle(*parent)) 51 if (!parent || !hasEditableStyle(*parent))
52 return; 52 return;
53 53
54 String prefixText = 54 String prefixText =
55 m_text2->substringData(0, m_offset, IGNORE_EXCEPTION_FOR_TESTING); 55 m_text2->substringData(0, m_offset, IGNORE_EXCEPTION_FOR_TESTING);
56 if (prefixText.isEmpty()) 56 if (prefixText.isEmpty())
57 return; 57 return;
58 58
59 m_text1 = Text::create(document(), prefixText); 59 m_text1 = Text::create(document(), prefixText);
60 DCHECK(m_text1); 60 DCHECK(m_text1);
61 document().markers().copyMarkers(m_text2.get(), 0, m_offset, m_text1.get(), 61 document().markers().moveMarkers(m_text2.get(), 0, m_offset, m_text1.get(),
62 0); 62 0);
63 63
64 insertText1AndTrimText2(); 64 insertText1AndTrimText2();
65 } 65 }
66 66
67 void SplitTextNodeCommand::doUnapply() { 67 void SplitTextNodeCommand::doUnapply() {
68 if (!m_text1 || !hasEditableStyle(*m_text1)) 68 if (!m_text1 || !hasEditableStyle(*m_text1))
69 return; 69 return;
70 70
71 DCHECK_EQ(m_text1->document(), document()); 71 DCHECK_EQ(m_text1->document(), document());
72 72
73 String prefixText = m_text1->data(); 73 String prefixText = m_text1->data();
74 74
75 m_text2->insertData(0, prefixText, ASSERT_NO_EXCEPTION); 75 m_text2->insertData(0, prefixText, ASSERT_NO_EXCEPTION);
76 document().updateStyleAndLayout(); 76 document().updateStyleAndLayout();
77 77
78 document().markers().copyMarkers(m_text1.get(), 0, prefixText.length(), 78 document().markers().moveMarkers(m_text1.get(), 0, prefixText.length(),
79 m_text2.get(), 0); 79 m_text2.get(), 0);
80 m_text1->remove(ASSERT_NO_EXCEPTION); 80 m_text1->remove(ASSERT_NO_EXCEPTION);
81 } 81 }
82 82
83 void SplitTextNodeCommand::doReapply() { 83 void SplitTextNodeCommand::doReapply() {
84 if (!m_text1 || !m_text2) 84 if (!m_text1 || !m_text2)
85 return; 85 return;
86 86
87 ContainerNode* parent = m_text2->parentNode(); 87 ContainerNode* parent = m_text2->parentNode();
88 if (!parent || !hasEditableStyle(*parent)) 88 if (!parent || !hasEditableStyle(*parent))
89 return; 89 return;
90 90
91 document().markers().moveMarkers(m_text2.get(), 0, m_offset, m_text1.get(),
rlanday 2017/04/08 02:30:09 I'm glad I wrote the test case in the dependent CL
Xiaocheng 2017/04/08 02:46:40 Good catch!
92 0);
91 insertText1AndTrimText2(); 93 insertText1AndTrimText2();
92 } 94 }
93 95
94 void SplitTextNodeCommand::insertText1AndTrimText2() { 96 void SplitTextNodeCommand::insertText1AndTrimText2() {
95 DummyExceptionStateForTesting exceptionState; 97 DummyExceptionStateForTesting exceptionState;
96 m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(), 98 m_text2->parentNode()->insertBefore(m_text1.get(), m_text2.get(),
97 exceptionState); 99 exceptionState);
98 if (exceptionState.hadException()) 100 if (exceptionState.hadException())
99 return; 101 return;
100 m_text2->deleteData(0, m_offset, exceptionState); 102 m_text2->deleteData(0, m_offset, exceptionState);
101 document().updateStyleAndLayout(); 103 document().updateStyleAndLayout();
102 } 104 }
103 105
104 DEFINE_TRACE(SplitTextNodeCommand) { 106 DEFINE_TRACE(SplitTextNodeCommand) {
105 visitor->trace(m_text1); 107 visitor->trace(m_text1);
106 visitor->trace(m_text2); 108 visitor->trace(m_text2);
107 SimpleEditCommand::trace(visitor); 109 SimpleEditCommand::trace(visitor);
108 } 110 }
109 111
110 } // namespace blink 112 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698