blob: 4486ddaf249db43aacdf8434ededbb2d4f510a42 [file] [log] [blame]
mjsc4e0d762005-05-12 04:00:20 +00001/*
darin@apple.com48ac3c42008-06-14 08:46:51 +00002 * Copyright (C) 2005, 2006, 2008 Apple Inc. All rights reserved.
mjsc4e0d762005-05-12 04:00:20 +00003 *
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.com92047332014-03-15 04:08:27 +000013 * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
mjsc4e0d762005-05-12 04:00:20 +000014 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
mjs@apple.com92047332014-03-15 04:08:27 +000016 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
mjsc4e0d762005-05-12 04:00:20 +000017 * 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
mjsb64c50a2005-10-03 21:13:12 +000026#include "config.h"
darina68e0432006-02-14 21:40:54 +000027#include "AppendNodeCommand.h"
darin@apple.come95b53d2008-12-23 21:42:46 +000028
commit-queue@webkit.org2aa8d032010-09-22 20:43:26 +000029#include "AXObjectCache.h"
aperez@igalia.com0df1caf2021-04-21 19:42:35 +000030#include "CompositeEditCommand.h"
tonyg@chromium.org8d183cb2011-05-10 08:19:52 +000031#include "Document.h"
commit-queue@webkit.org02ea7a22017-03-03 06:35:25 +000032#include "Editing.h"
antti@apple.com1769de82013-12-29 22:40:04 +000033#include "RenderElement.h"
commit-queue@webkit.org2de6e052015-04-26 22:17:11 +000034#include "Text.h"
mjsc4e0d762005-05-12 04:00:20 +000035
darin9aa45a42006-01-15 23:32:02 +000036namespace WebCore {
mjsc4e0d762005-05-12 04:00:20 +000037
cdumez@apple.comaac2e342017-05-02 17:41:46 +000038AppendNodeCommand::AppendNodeCommand(Ref<ContainerNode>&& parent, Ref<Node>&& node, EditAction editingAction)
commit-queue@webkit.org2de6e052015-04-26 22:17:11 +000039 : SimpleEditCommand(parent->document(), editingAction)
cdumez@apple.comaac2e342017-05-02 17:41:46 +000040 , m_parent(WTFMove(parent))
aestes@apple.com13aae082016-01-02 08:03:08 +000041 , m_node(WTFMove(node))
mjsc4e0d762005-05-12 04:00:20 +000042{
dglazkov@chromium.orge43caa72010-11-18 00:20:10 +000043 ASSERT(!m_node->parentNode());
antti@apple.com1769de82013-12-29 22:40:04 +000044 ASSERT(m_parent->hasEditableStyle() || !m_parent->renderer());
mjsc4e0d762005-05-12 04:00:20 +000045}
46
47void AppendNodeCommand::doApply()
48{
antti@apple.com1769de82013-12-29 22:40:04 +000049 if (!m_parent->hasEditableStyle() && m_parent->renderer())
enrica@apple.comd19cb882009-12-03 19:18:42 +000050 return;
mkwst@chromium.org33cdf432013-02-08 14:21:48 +000051
darin@apple.com4a588ff2016-11-11 20:16:03 +000052 m_parent->appendChild(m_node);
mjsc4e0d762005-05-12 04:00:20 +000053}
54
55void AppendNodeCommand::doUnapply()
56{
antti@apple.comf02be1e2013-12-21 18:51:04 +000057 if (!m_parent->hasEditableStyle())
enrica@apple.comd19cb882009-12-03 19:18:42 +000058 return;
commit-queue@webkit.org2de6e052015-04-26 22:17:11 +000059
darin@apple.com66d41182016-10-29 02:32:20 +000060 m_node->remove();
mjsc4e0d762005-05-12 04:00:20 +000061}
62
rniwa@webkit.org3045bc32011-12-10 21:35:06 +000063#ifndef NDEBUG
achristensen@apple.com5aa59622021-05-12 18:40:38 +000064void AppendNodeCommand::getNodesInCommand(HashSet<Ref<Node>>& nodes)
rniwa@webkit.org3045bc32011-12-10 21:35:06 +000065{
cdumez@apple.comaac2e342017-05-02 17:41:46 +000066 addNodeAndDescendants(m_parent.ptr(), nodes);
cdumez@apple.comc2ad8482015-09-10 18:02:15 +000067 addNodeAndDescendants(m_node.ptr(), nodes);
rniwa@webkit.org3045bc32011-12-10 21:35:06 +000068}
69#endif
70
darinb9481ed2006-03-20 02:57:59 +000071} // namespace WebCore