| OLD | NEW |
| 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 Loading... |
| 51 if (!parent || !HasEditableStyle(*parent)) | 51 if (!parent || !HasEditableStyle(*parent)) |
| 52 return; | 52 return; |
| 53 | 53 |
| 54 String prefix_text = | 54 String prefix_text = |
| 55 text2_->substringData(0, offset_, IGNORE_EXCEPTION_FOR_TESTING); | 55 text2_->substringData(0, offset_, IGNORE_EXCEPTION_FOR_TESTING); |
| 56 if (prefix_text.IsEmpty()) | 56 if (prefix_text.IsEmpty()) |
| 57 return; | 57 return; |
| 58 | 58 |
| 59 text1_ = Text::Create(GetDocument(), prefix_text); | 59 text1_ = Text::Create(GetDocument(), prefix_text); |
| 60 DCHECK(text1_); | 60 DCHECK(text1_); |
| 61 GetDocument().Markers().CopyMarkers(text2_.Get(), 0, offset_, text1_.Get(), | 61 GetDocument().Markers().MoveMarkers(text2_.Get(), offset_, text1_.Get()); |
| 62 0); | |
| 63 | 62 |
| 64 InsertText1AndTrimText2(); | 63 InsertText1AndTrimText2(); |
| 65 } | 64 } |
| 66 | 65 |
| 67 void SplitTextNodeCommand::DoUnapply() { | 66 void SplitTextNodeCommand::DoUnapply() { |
| 68 if (!text1_ || !HasEditableStyle(*text1_)) | 67 if (!text1_ || !HasEditableStyle(*text1_)) |
| 69 return; | 68 return; |
| 70 | 69 |
| 71 DCHECK_EQ(text1_->GetDocument(), GetDocument()); | 70 DCHECK_EQ(text1_->GetDocument(), GetDocument()); |
| 72 | 71 |
| 73 String prefix_text = text1_->data(); | 72 String prefix_text = text1_->data(); |
| 74 | 73 |
| 75 text2_->insertData(0, prefix_text, ASSERT_NO_EXCEPTION); | 74 text2_->insertData(0, prefix_text, ASSERT_NO_EXCEPTION); |
| 76 GetDocument().UpdateStyleAndLayout(); | 75 GetDocument().UpdateStyleAndLayout(); |
| 77 | 76 |
| 78 GetDocument().Markers().CopyMarkers(text1_.Get(), 0, prefix_text.length(), | 77 GetDocument().Markers().MoveMarkers(text1_.Get(), prefix_text.length(), |
| 79 text2_.Get(), 0); | 78 text2_.Get()); |
| 80 text1_->remove(ASSERT_NO_EXCEPTION); | 79 text1_->remove(ASSERT_NO_EXCEPTION); |
| 81 } | 80 } |
| 82 | 81 |
| 83 void SplitTextNodeCommand::DoReapply() { | 82 void SplitTextNodeCommand::DoReapply() { |
| 84 if (!text1_ || !text2_) | 83 if (!text1_ || !text2_) |
| 85 return; | 84 return; |
| 86 | 85 |
| 87 ContainerNode* parent = text2_->parentNode(); | 86 ContainerNode* parent = text2_->parentNode(); |
| 88 if (!parent || !HasEditableStyle(*parent)) | 87 if (!parent || !HasEditableStyle(*parent)) |
| 89 return; | 88 return; |
| 90 | 89 |
| 90 GetDocument().Markers().MoveMarkers(text2_.Get(), offset_, text1_.Get()); |
| 91 |
| 91 InsertText1AndTrimText2(); | 92 InsertText1AndTrimText2(); |
| 92 } | 93 } |
| 93 | 94 |
| 94 void SplitTextNodeCommand::InsertText1AndTrimText2() { | 95 void SplitTextNodeCommand::InsertText1AndTrimText2() { |
| 95 DummyExceptionStateForTesting exception_state; | 96 DummyExceptionStateForTesting exception_state; |
| 96 text2_->parentNode()->InsertBefore(text1_.Get(), text2_.Get(), | 97 text2_->parentNode()->InsertBefore(text1_.Get(), text2_.Get(), |
| 97 exception_state); | 98 exception_state); |
| 98 if (exception_state.HadException()) | 99 if (exception_state.HadException()) |
| 99 return; | 100 return; |
| 100 text2_->deleteData(0, offset_, exception_state); | 101 text2_->deleteData(0, offset_, exception_state); |
| 101 GetDocument().UpdateStyleAndLayout(); | 102 GetDocument().UpdateStyleAndLayout(); |
| 102 } | 103 } |
| 103 | 104 |
| 104 DEFINE_TRACE(SplitTextNodeCommand) { | 105 DEFINE_TRACE(SplitTextNodeCommand) { |
| 105 visitor->Trace(text1_); | 106 visitor->Trace(text1_); |
| 106 visitor->Trace(text2_); | 107 visitor->Trace(text2_); |
| 107 SimpleEditCommand::Trace(visitor); | 108 SimpleEditCommand::Trace(visitor); |
| 108 } | 109 } |
| 109 | 110 |
| 110 } // namespace blink | 111 } // namespace blink |
| OLD | NEW |