File indexing completed on 2024-04-28 15:23:06

0001 /*
0002  *  This file is part of the KDE libraries
0003  *  Copyright (C) 2006 Germain Garand <germain@ebooksfrance.org>
0004  *  Copyright (C) 2007 Matthias Kretz <kretz@kde.org>
0005  *
0006  *  This library is free software; you can redistribute it and/or
0007  *  modify it under the terms of the GNU Lesser General Public
0008  *  License as published by the Free Software Foundation; either
0009  *  version 2 of the License, or (at your option) any later version.
0010  *
0011  *  This library is distributed in the hope that it will be useful,
0012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0014  *  Lesser General Public License for more details.
0015  *
0016  *  You should have received a copy of the GNU Lesser General Public
0017  *  License along with this library; if not, write to the Free Software
0018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
0019  */
0020 
0021 #include "ecma/kjs_audio.h"
0022 
0023 #include <html/HTMLAudioElement.h>
0024 
0025 namespace KJS
0026 {
0027 
0028 AudioConstructorImp::AudioConstructorImp(ExecState *exec, DOM::DocumentImpl *d)
0029     : JSObject(exec->lexicalInterpreter()->builtinObjectPrototype()), doc(d)
0030 {
0031 }
0032 
0033 bool AudioConstructorImp::implementsConstruct() const
0034 {
0035     return true;
0036 }
0037 
0038 JSObject *AudioConstructorImp::construct(ExecState *exec, const List &list)
0039 {
0040     khtml::HTMLAudioElement *audio = static_cast<khtml::HTMLAudioElement *>(doc->createElement("audio"));
0041 
0042     QString url;
0043     if (list.size() > 0) {
0044         url = list.at(0)->toString(exec).qstring();
0045         if (!url.isEmpty()) {
0046             audio->setSrc(url);
0047         }
0048     }
0049     return getDOMNode(exec, audio)->getObject();
0050 }
0051 
0052 } // namespace KJS
0053