KHtml

kjs_views.cpp
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2001 Peter Kelly ([email protected])
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Library General Public
7  * License as published by the Free Software Foundation; either
8  * version 2 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Library General Public License for more details.
14  *
15  * You should have received a copy of the GNU Library General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "ecma/kjs_views.h"
21 #include "ecma/kjs_css.h"
22 #include "ecma/kjs_window.h"
23 #include "kjs_views.lut.h"
24 
25 using namespace KJS;
26 
27 // -------------------------------------------------------------------------
28 
29 const ClassInfo DOMAbstractView::info = { "AbstractView", nullptr, &DOMAbstractViewTable, nullptr };
30 
31 /*
32 @begin DOMAbstractViewTable 2
33  document DOMAbstractView::Document DontDelete|ReadOnly
34 @end
35 @begin DOMAbstractViewProtoTable 1
36  getComputedStyle DOMAbstractView::GetComputedStyle DontDelete|Function 2
37 @end
38 */
39 
40 KJS_DEFINE_PROTOTYPE(DOMAbstractViewProto)
41 KJS_IMPLEMENT_PROTOFUNC(DOMAbstractViewProtoFunc)
42 KJS_IMPLEMENT_PROTOTYPE("DOMAbstractView", DOMAbstractViewProto, DOMAbstractViewProtoFunc, ObjectPrototype)
43 
44 DOMAbstractView::DOMAbstractView(ExecState *exec, DOM::AbstractViewImpl *av)
45  : m_impl(av)
46 {
47  setPrototype(exec->lexicalInterpreter()->builtinObjectPrototype());
48 }
49 
50 DOMAbstractView::~DOMAbstractView()
51 {
52  ScriptInterpreter::forgetDOMObject(m_impl.get());
53 }
54 
55 JSValue *DOMAbstractView::getValueProperty(ExecState *exec, int token)
56 {
57  assert(token == Document);
58  Q_UNUSED(token);
59  return getDOMNode(exec, impl()->document());
60 }
61 
62 bool DOMAbstractView::getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot)
63 {
64  return getStaticValueSlot<DOMAbstractView, DOMObject>(exec, &DOMAbstractViewTable, this, propertyName, slot);
65 }
66 
67 JSValue *DOMAbstractViewProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args)
68 {
69  KJS_CHECK_THIS(KJS::DOMAbstractView, thisObj);
70  DOM::AbstractViewImpl &abstractView = *static_cast<DOMAbstractView *>(thisObj)->impl();
71  switch (id) {
72  case DOMAbstractView::GetComputedStyle: {
73  DOM::ElementImpl *arg0 = toElement(args[0]);
74  if (!arg0) {
75  return jsUndefined(); // throw exception?
76  } else {
77  return getDOMCSSStyleDeclaration(exec, abstractView.getComputedStyle(arg0, args[1]->toString(exec).domString().implementation()));
78  }
79  }
80  }
81  return jsUndefined();
82 }
83 
84 JSValue *KJS::getDOMAbstractView(ExecState *exec, DOM::AbstractViewImpl *av)
85 {
86  return cacheDOMObject<DOM::AbstractViewImpl, DOMAbstractView>(exec, av);
87 }
88 
89 DOM::AbstractViewImpl *KJS::toAbstractView(JSValue *val)
90 {
91  JSObject *obj = val->getObject();
92  if (!obj) {
93  return nullptr;
94  }
95 
96  // the Window object is considered for all practical purposes as a descendant of AbstractView
97  if (obj->inherits(&Window::info)) {
98  return static_cast<const Window *>(obj)->toAbstractView();
99  }
100 
101  if (obj->inherits(&DOMAbstractView::info)) {
102  return static_cast<const DOMAbstractView *>(obj)->impl();
103  }
104 
105  return nullptr;
106 }
This library provides a full-featured HTML parser and widget.
Window
Definition: kjs_window.h:393
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Tue Oct 26 2021 22:48:05 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.