1 /* 2 * Copyright (C) Research In Motion Limited 2010. All rights reserved. 3 * 4 * This library is free software; you can redistribute it and/or 5 * modify it under the terms of the GNU Library General Public 6 * License as published by the Free Software Foundation; either 7 * version 2 of the License, or (at your option) any later version. 8 * 9 * This library is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 * Library General Public License for more details. 13 * 14 * You should have received a copy of the GNU Library General Public License 15 * along with this library; see the file COPYING.LIB. If not, write to 16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 17 * Boston, MA 02110-1301, USA. 18 */ 19 20 #include "config.h" 21 #include "WebDOMNode.h" 22 23 #include "Node.h" 24 #include "WebDOMEventListener.h" 25 #include "WebExceptionHandler.h" 26 #include "WebNativeEventListener.h" 27 28 WebDOMNode WebDOMNode::insertBefore(const WebDOMNode& newChild, const WebDOMNode& refChild) 29 { 30 if (!impl()) 31 return WebDOMNode(); 32 33 WebCore::ExceptionCode ec = 0; 34 if (impl()->insertBefore(toWebCore(newChild), toWebCore(refChild), ec, true)) 35 return newChild; 36 37 webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec)); 38 return WebDOMNode(); 39 } 40 41 WebDOMNode WebDOMNode::replaceChild(const WebDOMNode& newChild, const WebDOMNode& oldChild) 42 { 43 if (!impl()) 44 return WebDOMNode(); 45 46 WebCore::ExceptionCode ec = 0; 47 if (impl()->replaceChild(toWebCore(newChild), toWebCore(oldChild), ec, true)) 48 return oldChild; 49 50 webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec)); 51 return WebDOMNode(); 52 } 53 54 WebDOMNode WebDOMNode::removeChild(const WebDOMNode& oldChild) 55 { 56 if (!impl()) 57 return WebDOMNode(); 58 59 WebCore::ExceptionCode ec = 0; 60 if (impl()->removeChild(toWebCore(oldChild), ec)) 61 return oldChild; 62 63 webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec)); 64 return WebDOMNode(); 65 } 66 67 WebDOMNode WebDOMNode::appendChild(const WebDOMNode& newChild) 68 { 69 if (!impl()) 70 return WebDOMNode(); 71 72 WebCore::ExceptionCode ec = 0; 73 if (impl()->appendChild(toWebCore(newChild), ec, true)) 74 return newChild; 75 76 webDOMRaiseError(static_cast<WebDOMExceptionCode>(ec)); 77 return WebDOMNode(); 78 } 79 80 void WebDOMNode::addEventListener(const WebDOMString& type, const WebDOMEventListener& listener, bool useCapture) 81 { 82 if (!impl()) 83 return; 84 85 if (toWebCore(listener)) 86 impl()->addEventListener(type, toWebCore(listener), useCapture); 87 } 88 89 void WebDOMNode::removeEventListener(const WebDOMString& type, const WebDOMEventListener& listener, bool useCapture) 90 { 91 if (!impl()) 92 return; 93 94 if (toWebCore(listener)) 95 impl()->removeEventListener(type, toWebCore(listener), useCapture); 96 } 97