mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 1 | /* |
darin@apple.com | 48ac3c4 | 2008-06-14 08:46:51 +0000 | [diff] [blame] | 2 | * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved. |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions |
| 6 | * are met: |
| 7 | * 1. Redistributions of source code must retain the above copyright |
| 8 | * notice, this list of conditions and the following disclaimer. |
| 9 | * 2. Redistributions in binary form must reproduce the above copyright |
| 10 | * notice, this list of conditions and the following disclaimer in the |
| 11 | * documentation and/or other materials provided with the distribution. |
| 12 | * |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 13 | * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 14 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
mjs@apple.com | 9204733 | 2014-03-15 04:08:27 +0000 | [diff] [blame] | 16 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 17 | * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
| 18 | * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
| 19 | * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
| 20 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
| 21 | * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 23 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 24 | */ |
| 25 | |
mjs | b64c50a | 2005-10-03 21:13:12 +0000 | [diff] [blame] | 26 | #include "config.h" |
darin | a68e043 | 2006-02-14 21:40:54 +0000 | [diff] [blame] | 27 | #include "AppendNodeCommand.h" |
darin@apple.com | e95b53d | 2008-12-23 21:42:46 +0000 | [diff] [blame] | 28 | |
commit-queue@webkit.org | 2aa8d03 | 2010-09-22 20:43:26 +0000 | [diff] [blame] | 29 | #include "AXObjectCache.h" |
aperez@igalia.com | 0df1caf | 2021-04-21 19:42:35 +0000 | [diff] [blame] | 30 | #include "CompositeEditCommand.h" |
tonyg@chromium.org | 8d183cb | 2011-05-10 08:19:52 +0000 | [diff] [blame] | 31 | #include "Document.h" |
commit-queue@webkit.org | 02ea7a2 | 2017-03-03 06:35:25 +0000 | [diff] [blame] | 32 | #include "Editing.h" |
antti@apple.com | 1769de8 | 2013-12-29 22:40:04 +0000 | [diff] [blame] | 33 | #include "RenderElement.h" |
commit-queue@webkit.org | 2de6e05 | 2015-04-26 22:17:11 +0000 | [diff] [blame] | 34 | #include "Text.h" |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 35 | |
darin | 9aa45a4 | 2006-01-15 23:32:02 +0000 | [diff] [blame] | 36 | namespace WebCore { |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 37 | |
cdumez@apple.com | aac2e34 | 2017-05-02 17:41:46 +0000 | [diff] [blame] | 38 | AppendNodeCommand::AppendNodeCommand(Ref<ContainerNode>&& parent, Ref<Node>&& node, EditAction editingAction) |
commit-queue@webkit.org | 2de6e05 | 2015-04-26 22:17:11 +0000 | [diff] [blame] | 39 | : SimpleEditCommand(parent->document(), editingAction) |
cdumez@apple.com | aac2e34 | 2017-05-02 17:41:46 +0000 | [diff] [blame] | 40 | , m_parent(WTFMove(parent)) |
aestes@apple.com | 13aae08 | 2016-01-02 08:03:08 +0000 | [diff] [blame] | 41 | , m_node(WTFMove(node)) |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 42 | { |
dglazkov@chromium.org | e43caa7 | 2010-11-18 00:20:10 +0000 | [diff] [blame] | 43 | ASSERT(!m_node->parentNode()); |
antti@apple.com | 1769de8 | 2013-12-29 22:40:04 +0000 | [diff] [blame] | 44 | ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer()); |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 45 | } |
| 46 | |
| 47 | void AppendNodeCommand::doApply() |
| 48 | { |
antti@apple.com | 1769de8 | 2013-12-29 22:40:04 +0000 | [diff] [blame] | 49 | if (!m_parent->hasEditableStyle() && m_parent->renderer()) |
enrica@apple.com | d19cb88 | 2009-12-03 19:18:42 +0000 | [diff] [blame] | 50 | return; |
mkwst@chromium.org | 33cdf43 | 2013-02-08 14:21:48 +0000 | [diff] [blame] | 51 | |
darin@apple.com | 4a588ff | 2016-11-11 20:16:03 +0000 | [diff] [blame] | 52 | m_parent->appendChild(m_node); |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 53 | } |
| 54 | |
| 55 | void AppendNodeCommand::doUnapply() |
| 56 | { |
antti@apple.com | f02be1e | 2013-12-21 18:51:04 +0000 | [diff] [blame] | 57 | if (!m_parent->hasEditableStyle()) |
enrica@apple.com | d19cb88 | 2009-12-03 19:18:42 +0000 | [diff] [blame] | 58 | return; |
commit-queue@webkit.org | 2de6e05 | 2015-04-26 22:17:11 +0000 | [diff] [blame] | 59 | |
darin@apple.com | 66d4118 | 2016-10-29 02:32:20 +0000 | [diff] [blame] | 60 | m_node->remove(); |
mjs | c4e0d76 | 2005-05-12 04:00:20 +0000 | [diff] [blame] | 61 | } |
| 62 | |
rniwa@webkit.org | 3045bc3 | 2011-12-10 21:35:06 +0000 | [diff] [blame] | 63 | #ifndef NDEBUG |
achristensen@apple.com | 5aa5962 | 2021-05-12 18:40:38 +0000 | [diff] [blame] | 64 | void AppendNodeCommand::getNodesInCommand(HashSet<Ref<Node>>& nodes) |
rniwa@webkit.org | 3045bc3 | 2011-12-10 21:35:06 +0000 | [diff] [blame] | 65 | { |
cdumez@apple.com | aac2e34 | 2017-05-02 17:41:46 +0000 | [diff] [blame] | 66 | addNodeAndDescendants(m_parent.ptr(), nodes); |
cdumez@apple.com | c2ad848 | 2015-09-10 18:02:15 +0000 | [diff] [blame] | 67 | addNodeAndDescendants(m_node.ptr(), nodes); |
rniwa@webkit.org | 3045bc3 | 2011-12-10 21:35:06 +0000 | [diff] [blame] | 68 | } |
| 69 | #endif |
| 70 | |
darin | b9481ed | 2006-03-20 02:57:59 +0000 | [diff] [blame] | 71 | } // namespace WebCore |