khtml Library API Documentation

kjs_views.cpp

00001 // -*- c-basic-offset: 2 -*-
00002 /*
00003  *  This file is part of the KDE libraries
00004  *  Copyright (C) 2001 Peter Kelly (pmk@post.com)
00005  *
00006  *  This library is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU Library General Public
00008  *  License as published by the Free Software Foundation; either
00009  *  version 2 of the License, or (at your option) any later version.
00010  *
00011  *  This library is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00014  *  Library General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU Library General Public
00017  *  License along with this library; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00019  */
00020 
00021 #include "ecma/kjs_views.h"
00022 #include "ecma/kjs_views.lut.h"
00023 #include "ecma/kjs_css.h"
00024 
00025 using namespace KJS;
00026 
00027 // -------------------------------------------------------------------------
00028 
00029 const ClassInfo DOMAbstractView::info = { "AbstractView", 0, &DOMAbstractViewTable, 0 };
00030 /*
00031 @begin DOMAbstractViewTable 2
00032   document      DOMAbstractView::Document       DontDelete|ReadOnly
00033   getComputedStyle  DOMAbstractView::GetComputedStyle   DontDelete|Function 2
00034 @end
00035 */
00036 IMPLEMENT_PROTOFUNC_DOM(DOMAbstractViewFunc)
00037 
00038 DOMAbstractView::DOMAbstractView(ExecState *exec, DOM::AbstractView av)
00039   : DOMObject(exec->interpreter()->builtinObjectPrototype()), abstractView(av) {}
00040 
00041 DOMAbstractView::~DOMAbstractView()
00042 {
00043   ScriptInterpreter::forgetDOMObject(abstractView.handle());
00044 }
00045 
00046 Value DOMAbstractView::tryGet(ExecState *exec, const UString &p) const
00047 {
00048   if ( p == "document" )
00049     return getDOMNode(exec,abstractView.document());
00050   else if ( p == "getComputedStyle" )
00051     return lookupOrCreateFunction<DOMAbstractViewFunc>(exec,p,this,DOMAbstractView::GetComputedStyle,2,DontDelete|Function);
00052   else
00053     return DOMObject::tryGet(exec,p);
00054 }
00055 
00056 Value DOMAbstractViewFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00057 {
00058   KJS_CHECK_THIS( KJS::DOMAbstractView, thisObj );
00059   DOM::AbstractView abstractView = static_cast<DOMAbstractView *>(thisObj.imp())->toAbstractView();
00060   switch (id) {
00061     case DOMAbstractView::GetComputedStyle: {
00062         DOM::Node arg0 = toNode(args[0]);
00063         if (arg0.nodeType() != DOM::Node::ELEMENT_NODE)
00064           return Undefined(); // throw exception?
00065         else
00066           return getDOMCSSStyleDeclaration(exec,abstractView.getComputedStyle(static_cast<DOM::Element>(arg0),
00067                                                                               args[1].toString(exec).string()));
00068       }
00069   }
00070   return Undefined();
00071 }
00072 
00073 Value KJS::getDOMAbstractView(ExecState *exec, DOM::AbstractView av)
00074 {
00075   return cacheDOMObject<DOM::AbstractView, DOMAbstractView>(exec, av);
00076 }
00077 
00078 DOM::AbstractView KJS::toAbstractView (const Value& val)
00079 {
00080   Object obj = Object::dynamicCast(val);
00081   if (obj.isNull() || !obj.inherits(&DOMAbstractView::info))
00082     return DOM::AbstractView ();
00083 
00084   const DOMAbstractView  *dobj = static_cast<const DOMAbstractView *>(obj.imp());
00085   return dobj->toAbstractView ();
00086 }
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.4.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Sun Feb 27 22:16:38 2005 by doxygen 1.3.4 written by Dimitri van Heesch, © 1997-2001