Ben Murdoch | 591b958 | 2013-07-10 11:41:44 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 1999 Lars Knoll (knoll@kde.org) |
| 3 | * (C) 1999 Antti Koivisto (koivisto@kde.org) |
| 4 | * (C) 2001 Dirk Mueller (mueller@kde.org) |
| 5 | * (C) 2006 Alexey Proskuryakov (ap@webkit.org) |
| 6 | * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009, 2011, 2012 Apple Inc. All rights reserved. |
| 7 | * Copyright (C) 2008, 2009 Torch Mobile Inc. All rights reserved. (http://www.torchmobile.com/) |
| 8 | * Copyright (C) 2008, 2009, 2011, 2012 Google Inc. All rights reserved. |
| 9 | * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) |
| 10 | * Copyright (C) 2013 Google Inc. All rights reserved. |
| 11 | * |
| 12 | * This library is free software; you can redistribute it and/or |
| 13 | * modify it under the terms of the GNU Library General Public |
| 14 | * License as published by the Free Software Foundation; either |
| 15 | * version 2 of the License, or (at your option) any later version. |
| 16 | * |
| 17 | * This library is distributed in the hope that it will be useful, |
| 18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 20 | * Library General Public License for more details. |
| 21 | * |
| 22 | * You should have received a copy of the GNU Library General Public License |
| 23 | * along with this library; see the file COPYING.LIB. If not, write to |
| 24 | * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
| 25 | * Boston, MA 02110-1301, USA. |
| 26 | */ |
| 27 | |
| 28 | #include "config.h" |
| 29 | #include "core/dom/DocumentOrderedList.h" |
| 30 | |
| 31 | #include "core/dom/Node.h" |
| 32 | |
| 33 | namespace WebCore { |
| 34 | |
| 35 | void DocumentOrderedList::add(Node* node) |
| 36 | { |
| 37 | if (m_nodes.isEmpty()) { |
| 38 | m_nodes.add(node); |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | // Determine an appropriate insertion point. |
| 43 | iterator begin = m_nodes.begin(); |
| 44 | iterator end = m_nodes.end(); |
| 45 | iterator it = end; |
| 46 | Node* followingNode = 0; |
| 47 | do { |
| 48 | --it; |
| 49 | Node* n = *it; |
| 50 | unsigned short position = n->compareDocumentPositionInternal(node, Node::TreatShadowTreesAsComposed); |
| 51 | if (position & Node::DOCUMENT_POSITION_FOLLOWING) { |
| 52 | m_nodes.insertBefore(followingNode, node); |
| 53 | return; |
| 54 | } |
| 55 | followingNode = n; |
| 56 | } while (it != begin); |
| 57 | |
| 58 | m_nodes.insertBefore(followingNode, node); |
| 59 | } |
| 60 | |
| 61 | void DocumentOrderedList::parserAdd(Node* node) |
| 62 | { |
| 63 | ASSERT(m_nodes.isEmpty() || m_nodes.last()->compareDocumentPositionInternal(node, Node::TreatShadowTreesAsComposed) & Node::DOCUMENT_POSITION_FOLLOWING); |
| 64 | m_nodes.add(node); |
| 65 | } |
| 66 | |
| 67 | void DocumentOrderedList::remove(Node* node) |
| 68 | { |
| 69 | m_nodes.remove(node); |
| 70 | } |
| 71 | |
| 72 | } |
| 73 | |