KHtml

kjs_window.h
1 /*
2  * This file is part of the KDE libraries
3  * Copyright (C) 2000 Harri Porten ([email protected])
4  * Copyright (C) 2003 Apple Computer, Inc.
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Library General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Library General Public License for more details.
15  *
16  * You should have received a copy of the GNU Library General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef _KJS_WINDOW_H_
22 #define _KJS_WINDOW_H_
23 
24 #include <QObject>
25 #include <QPointer>
26 #include <QMap>
27 #include <QList>
28 #include <QDate>
29 
30 #include "khtmlpart_p.h"
31 #include "kjs_binding.h"
32 #include "kjs_views.h"
33 
34 class QTimer;
35 class KHTMLView;
36 class KHTMLPart;
37 
38 namespace KParts
39 {
40 class ReadOnlyPart;
41 }
42 
43 namespace khtml
44 {
45 class ChildFrame;
46 }
47 
48 namespace DOM
49 {
50 class EventImpl;
51 }
52 
53 namespace KJS
54 {
55 
56 class WindowFunc;
57 class WindowQObject;
58 class Location;
59 class History;
60 class External;
61 class ScheduledAction;
62 class JSEventListener;
63 class JSLazyEventListener;
64 
65 class Screen : public JSObject
66 {
67 public:
68  Screen(ExecState *exec);
69  enum {
70  Height, Width, ColorDepth, PixelDepth, AvailLeft, AvailTop, AvailHeight,
71  AvailWidth
72  };
73  using KJS::JSObject::getOwnPropertySlot;
74  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
75  JSValue *getValueProperty(ExecState *exec, int token) const;
76 private:
77  KHTMLView *view;
78  const ClassInfo *classInfo() const override
79  {
80  return &info;
81  }
82  static const ClassInfo info;
83 };
84 
85 class Console : public JSObject
86 {
87 public:
88  Console(ExecState *exec);
89  enum {
90  Assert, Log, Debug, Info, Warn, Error, Clear
91  };
92 
93  enum MessageType {
94  LogType = 1,
95  DebugType = 1 << 1,
96  InfoType = 1 << 2,
97  WarnType = 1 << 3,
98  ErrorType = 1 << 4
99  };
100  using KJS::JSObject::getOwnPropertySlot;
101  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
102 private:
103  const ClassInfo *classInfo() const override
104  {
105  return &info;
106  }
107  static const ClassInfo info;
108 };
109 
110 class Window : public JSGlobalObject
111 {
112  friend QPointer<KHTMLPart> getInstance();
113  friend class KJS::Location;
114  friend class KJS::WindowFunc;
115  friend class KJS::WindowQObject;
116  friend class KJS::ScheduledAction;
117 public:
118  Window(khtml::ChildFrame *p);
119 public:
120  ~Window();
126  static JSValue *retrieve(KParts::ReadOnlyPart *p);
130  static Window *retrieveWindow(KParts::ReadOnlyPart *p);
135  static Window *retrieveActive(ExecState *exec);
136  KParts::ReadOnlyPart *part() const
137  {
138  return m_frame.isNull() ? nullptr : m_frame->m_part.data();
139  }
140 
141  void mark() override;
142  JSValue *getValueProperty(ExecState *exec, int token);
143  using KJS::JSObject::getOwnPropertySlot;
144  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
145  using KJS::JSObject::put;
146  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
147  bool toBoolean(ExecState *exec) const override;
148  virtual DOM::AbstractViewImpl *toAbstractView() const;
149  void scheduleClose();
150  void closeNow();
151  void delayedGoHistory(int steps);
152  void goHistory(int steps);
153  void goURL(ExecState *exec, const QString &url, bool lockHistory = false);
154 
155  static bool targetIsExistingWindow(KHTMLPart *part, const QString &frameName);
156  JSValue *openWindow(ExecState *exec, const List &args);
157  JSValue *executeOpenWindow(ExecState *exec, const QUrl &url, const QString &frameName, const QString &features);
158  void resizeTo(QWidget *tl, int width, int height);
159  void afterScriptExecution();
160  bool isSafeScript(ExecState *exec) const
161  {
162  KParts::ReadOnlyPart *activePart = static_cast<KJS::ScriptInterpreter *>(exec->dynamicInterpreter())->part();
163  if (activePart == part()) {
164  return true;
165  }
166  return checkIsSafeScript(activePart);
167  }
168  Location *location() const;
169  JSEventListener *getJSEventListener(JSValue *val, bool html = false);
170  JSLazyEventListener *getJSLazyEventListener(const QString &code, const QString &sourceUrl, int lineNo,
171  const QString &name, DOM::NodeImpl *node, bool svg = false);
172  void clear(ExecState *exec);
173  UString toString(ExecState *exec) const override;
174 
175  // Set the current "event" object
176  void setCurrentEvent(DOM::EventImpl *evt);
177 
178  QHash<const QPair<void *, bool>, JSEventListener *> jsEventListeners;
179  const ClassInfo *classInfo() const override
180  {
181  return &info;
182  }
183  static const ClassInfo info;
184  enum { Closed, Crypto, DefaultStatus, Status, Document, Node, EventCtor, Range,
185  NodeFilter, NodeList, DOMException, RangeException, CSSRule, Frames, _History, _External, Event, InnerHeight,
186  InnerWidth, Length, _Location, Navigate, Name, _Navigator, _Konqueror, ClientInformation,
187  OffscreenBuffering, Opener, OuterHeight, OuterWidth, PageXOffset, PageYOffset,
188  Parent, Personalbar, ScreenX, ScreenY, Scrollbars, Scroll, ScrollBy,
189  ScreenTop, ScreenLeft, AToB, BToA, FrameElement, GetComputedStyle,
190  ScrollTo, ScrollX, ScrollY, MoveBy, MoveTo, PostMessage, ResizeBy, ResizeTo, Self, _Window, Top, _Screen,
191  _Console, Audio, Image, Option, Alert, Confirm, Prompt, Open, SetTimeout, ClearTimeout,
192  XMLHttpRequest, XMLSerializer, DOMParser, ArrayBuffer, Int8Array, Uint8Array,
193  Int16Array, Uint16Array, Int32Array, Uint32Array, Float32Array, Float64Array,
194  Focus, Blur, Close, SetInterval, ClearInterval, CaptureEvents, ReleaseEvents,
195  Print, AddEventListener, RemoveEventListener, SideBar, GetSelection,
196  ValueOf, ToString,
197  Onabort, Onblur,
198  Onchange, Onclick, Ondblclick, Ondragdrop, Onerror, Onfocus,
199  Onkeydown, Onkeypress, Onkeyup, Onload, Onmessage, Onmousedown, Onmousemove,
200  Onmouseout, Onmouseover, Onmouseup, Onmove, Onreset, Onresize,
201  Onscroll, Onselect, Onsubmit, Onunload, Onhashchange,
202  MutationEventCtor, MessageEventCtor, KeyboardEventCtor, EventExceptionCtor, HashChangeEventCtor,
203  ElementCtor, DocumentCtor, DocumentFragmentCtor, HTMLDocumentCtor,
204  HTMLElementCtor, HTMLHtmlElementCtor, HTMLHeadElementCtor, HTMLLinkElementCtor,
205  HTMLTitleElementCtor, HTMLMetaElementCtor, HTMLBaseElementCtor, HTMLIsIndexElementCtor,
206  HTMLStyleElementCtor, HTMLBodyElementCtor, HTMLFormElementCtor, HTMLSelectElementCtor,
207  HTMLOptGroupElementCtor, HTMLOptionElementCtor, HTMLInputElementCtor, HTMLTextAreaElementCtor,
208  HTMLButtonElementCtor, HTMLLabelElementCtor, HTMLFieldSetElementCtor, HTMLLegendElementCtor,
209  HTMLUListElementCtor, HTMLOListElementCtor, HTMLDListElementCtor, HTMLDirectoryElementCtor,
210  HTMLMenuElementCtor, HTMLLIElementCtor, HTMLDivElementCtor, HTMLParagraphElementCtor,
211  HTMLHeadingElementCtor, HTMLBlockQuoteElementCtor, HTMLQuoteElementCtor, HTMLPreElementCtor,
212  HTMLBRElementCtor, HTMLBaseFontElementCtor, HTMLFontElementCtor, HTMLHRElementCtor, HTMLModElementCtor,
213  HTMLAnchorElementCtor, HTMLImageElementCtor, HTMLObjectElementCtor, HTMLParamElementCtor,
214  HTMLAppletElementCtor, HTMLMapElementCtor, HTMLAreaElementCtor, HTMLScriptElementCtor,
215  HTMLTableElementCtor, HTMLTableCaptionElementCtor, HTMLTableColElementCtor,
216  HTMLTableSectionElementCtor, HTMLTableRowElementCtor, HTMLTableCellElementCtor,
217  HTMLFrameSetElementCtor, HTMLLayerElementCtor, HTMLFrameElementCtor, HTMLIFrameElementCtor,
218  HTMLCollectionCtor, StyleSheetCtor,
219  CSSStyleDeclarationCtor, HTMLCanvasElementCtor, Context2DCtor, SVGAngleCtor,
220  XPathResultCtor, XPathExpressionCtor, XPathNSResolverCtor
221  };
222  WindowQObject *winq;
223 
224  void forgetSuppressedWindows();
225  void showSuppressedWindows();
226 
227  JSValue *indexGetter(ExecState *exec, unsigned index);
228 
229  // updates window listeners.
230  JSValue *getListener(ExecState *exec, int eventId) const;
231  void setListener(ExecState *exec, int eventId, JSValue *func);
232 
233  struct DelayedAction {
234  virtual void mark() {}; // mark any JS objects we use
235  virtual bool execute(Window *) = 0; // returns whether to continue or not
236  virtual ~DelayedAction() {};
237  };
238 
239 private:
240  // Returns true if the particular method or property should be permitted
241  // to be accessed even across frames.
242  bool isCrossFrameAccessible(int token) const;
243 
244  KParts::ReadOnlyPart *frameByIndex(unsigned index);
245  static JSValue *framePartGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot &slot);
246  static JSValue *namedItemGetter(ExecState *exec, JSObject *, const Identifier &, const PropertySlot &slot);
247 
248  bool checkIsSafeScript(KParts::ReadOnlyPart *activePart) const;
249 
251  Screen *screen;
252  Console *console;
253  History *history;
254  External *external;
255  Location *loc;
256  DOM::EventImpl *m_evt;
257 
258  QList<DelayedAction *> m_delayed;
259 
260  struct SuppressedWindowInfo {
261  SuppressedWindowInfo() {} // for QValueList
262  SuppressedWindowInfo(QUrl u, QString fr, QString fe) : url(u), frameName(fr), features(fe) {}
263  QUrl url;
264  QString frameName;
265  QString features;
266  };
267  QList<SuppressedWindowInfo> m_suppressedWindowInfo;
268 };
269 
274 {
275  QDate mDate;
276  QTime mTime;
277 public:
278  DateTimeMS addMSecs(int s) const;
279  bool operator >(const DateTimeMS &other) const;
280  bool operator >=(const DateTimeMS &other) const;
281 
282  int msecsTo(const DateTimeMS &other) const;
283 
284  static DateTimeMS now();
285 };
286 
293 {
294 public:
295  ScheduledAction(JSObject *_func, const List &_args, const DateTimeMS &_nextTime, int _interval, bool _singleShot, int _timerId);
296  ScheduledAction(const QString &_code, const DateTimeMS &_nextTime, int _interval, bool _singleShot, int _timerId);
297  ~ScheduledAction();
298  bool execute(Window *window);
299  void mark();
300 
301  JSObject *func;
302  List args;
303  QString code;
304  bool isFunction;
305  bool singleShot;
306 
307  DateTimeMS nextTime;
308  int interval;
309  bool executing;
310  int timerId;
311 };
312 
313 class WindowQObject : public QObject
314 {
315  Q_OBJECT
316 public:
317  WindowQObject(Window *w);
318  ~WindowQObject();
319  int installTimeout(const Identifier &handler, int t, bool singleShot);
320  int installTimeout(JSValue *func, List args, int t, bool singleShot);
321  void clearTimeout(int timerId);
322  void mark();
323  bool hasTimers() const;
324 
325  void pauseTimers();
326  void resumeTimers();
327 public Q_SLOTS:
328  void timeoutClose();
329 protected Q_SLOTS:
330  void parentDestroyed();
331 protected:
332  void timerEvent(QTimerEvent *e) override;
333  void setNextTimer();
334  void killTimers();
335 private:
336  Window *parent;
337  QList<ScheduledAction *> scheduledActions;
338 
343  int pauseLevel;
344  DateTimeMS pauseStart;
345 
346  int lastTimerId;
347  QList<int> timerIds;
348  bool currentlyDispatching;
349 };
350 
355 {
356 public:
357  TimerPauser(ExecState *exec)
358  {
359  win = Window::retrieveActive(exec);
360  win->winq->pauseTimers();
361  }
362 
363  ~TimerPauser()
364  {
365  win->winq->resumeTimers();
366  }
367 private:
368  Window *win;
369 };
370 
371 class Location : public JSObject
372 {
373 public:
374  ~Location();
375 
376  JSValue *getValueProperty(ExecState *exec, int token) const;
377  using KJS::JSObject::getOwnPropertySlot;
378  bool getOwnPropertySlot(ExecState *exec, const Identifier &propertyName, PropertySlot &slot) override;
379  using KJS::JSObject::put;
380  void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None) override;
381  JSValue *toPrimitive(ExecState *exec, JSType preferred) const override;
382  UString toString(ExecState *exec) const override;
383  enum { Hash, Href, Hostname, Host, Pathname, Port, Protocol, Search, EqualEqual,
384  Assign, Replace, Reload, ToString
385  };
386  KParts::ReadOnlyPart *part() const;
387  const ClassInfo *classInfo() const override
388  {
389  return &info;
390  }
391  static const ClassInfo info;
392 private:
393  friend class Window;
394  Location(khtml::ChildFrame *f);
396 };
397 
398 } // namespace
399 
400 #endif
This file is part of the HTML rendering engine for KDE.
This class is khtml&#39;s main class.
Definition: khtml_part.h:208
QVariant location(const QVariant &res)
Renders and displays HTML in a QScrollArea.
Definition: khtmlview.h:97
We inherit from Interpreter, to save a pointer to the HTML part that the interpreter runs for...
Definition: kjs_binding.h:96
An action (either function or string) to be executed after a specified time interval, either once or repeatedly.
Definition: kjs_window.h:292
KIOCORE_EXPORT TransferJob * put(const QUrl &url, int permissions, JobFlags flags=DefaultFlags)
Width
This library provides a full-featured HTML parser and widget.
Top
char * toString(const T &value)
Helper for pausing/resuming timers.
Definition: kjs_window.h:354
like QDateTime, but properly handles milliseconds
Definition: kjs_window.h:273
Height
Window
Definition: kjs_window.h:393
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Nov 27 2020 22:47:45 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.