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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include "ecma/kjs_views.h"
00022 #include "ecma/kjs_css.h"
00023 #include "ecma/kjs_window.h"
00024 #include "kjs_views.lut.h"
00025 
00026 using namespace KJS;
00027 
00028 // -------------------------------------------------------------------------
00029 
00030 const ClassInfo DOMAbstractView::info = { "AbstractView", 0, &DOMAbstractViewTable, 0 };
00031 /*
00032 @begin DOMAbstractViewTable 2
00033   document      DOMAbstractView::Document       DontDelete|ReadOnly
00034   getComputedStyle  DOMAbstractView::GetComputedStyle   DontDelete|Function 2
00035 @end
00036 */
00037 IMPLEMENT_PROTOFUNC_DOM(DOMAbstractViewFunc)
00038 
00039 DOMAbstractView::DOMAbstractView(ExecState *exec, DOM::AbstractView av)
00040   : DOMObject(exec->interpreter()->builtinObjectPrototype()), abstractView(av) {}
00041 
00042 DOMAbstractView::~DOMAbstractView()
00043 {
00044   ScriptInterpreter::forgetDOMObject(abstractView.handle());
00045 }
00046 
00047 Value DOMAbstractView::tryGet(ExecState *exec, const Identifier &p) const
00048 {
00049   if ( p == "document" )
00050     return getDOMNode(exec,abstractView.document());
00051   else if ( p == "getComputedStyle" )
00052     return lookupOrCreateFunction<DOMAbstractViewFunc>(exec,p,this,DOMAbstractView::GetComputedStyle,2,DontDelete|Function);
00053   else
00054     return DOMObject::tryGet(exec,p);
00055 }
00056 
00057 Value DOMAbstractViewFunc::tryCall(ExecState *exec, Object &thisObj, const List &args)
00058 {
00059   KJS_CHECK_THIS( KJS::DOMAbstractView, thisObj );
00060   DOM::AbstractView abstractView = static_cast<DOMAbstractView *>(thisObj.imp())->toAbstractView();
00061   switch (id) {
00062     case DOMAbstractView::GetComputedStyle: {
00063         DOM::Node arg0 = toNode(args[0]);
00064         if (arg0.nodeType() != DOM::Node::ELEMENT_NODE)
00065           return Undefined(); // throw exception?
00066         else
00067           return getDOMCSSStyleDeclaration(exec,abstractView.getComputedStyle(static_cast<DOM::Element>(arg0),
00068                                                                               args[1].toString(exec).string()));
00069       }
00070   }
00071   return Undefined();
00072 }
00073 
00074 Value KJS::getDOMAbstractView(ExecState *exec, DOM::AbstractView av)
00075 {
00076   return cacheDOMObject<DOM::AbstractView, DOMAbstractView>(exec, av);
00077 }
00078 
00079 DOM::AbstractView KJS::toAbstractView (const Value& val)
00080 {
00081   Object obj = Object::dynamicCast(val);
00082   if (!obj.isValid() || !obj.inherits(&DOMAbstractView::info))
00083     return DOM::AbstractView ();
00084 
00085   // the Window object is considered for all practical purposes as a descendant of AbstractView
00086   if (obj.inherits(&Window::info))
00087      return static_cast<const Window *>(obj.imp())->toAbstractView(); 
00088 
00089   const DOMAbstractView  *dobj = static_cast<const DOMAbstractView *>(obj.imp());
00090   return dobj->toAbstractView ();
00091 }
KDE Home | KDE Accessibility Home | Description of Access Keys