📄 kjs_window.cpp
字号:
// -*- c-basic-offset: 2 -*-/* * This file is part of the KDE libraries * Copyright (C) 2000-2003 Harri Porten (porten@kde.org) * Copyright (C) 2001-2003 David Faure (faure@kde.org) * Copyright (C) 2003 Apple Computer, Inc. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */#include "config.h"#include "khtmlview.h"#include "khtml_part.h"#include "khtmlpart_p.h"#include "khtml_settings.h"#include "xml/dom2_eventsimpl.h"#include "xml/dom_docimpl.h"#include "misc/htmltags.h"#include "html/html_documentimpl.h"#include "rendering/render_frames.h"#include <qstylesheet.h>#include <qtimer.h>#include <qpaintdevicemetrics.h>#include <qapplication.h>#include <kdebug.h>#include <kmessagebox.h>#include <kinputdialog.h>#include <klocale.h>#include <kmdcodec.h>#include <kparts/browserinterface.h>#include <kwin.h>#if defined Q_WS_X11 && ! defined K_WS_QTONLY#include <kwinmodule.h> // schroder#endif#ifndef KONQ_EMBEDDED#include <kbookmarkmanager.h>#endif#include <kglobalsettings.h>#include <assert.h>#include <qstyle.h>#include <qobjectlist.h>#include <kstringhandler.h>#include "kjs_proxy.h"#include "kjs_window.h"#include "kjs_navigator.h"#include "kjs_mozilla.h"#include "kjs_html.h"#include "kjs_range.h"#include "kjs_traversal.h"#include "kjs_css.h"#include "kjs_events.h"#include "kjs_views.h"#include "xmlhttprequest.h"#include "xmlserializer.h"#include "domparser.h"using namespace KJS;namespace KJS { class History : public ObjectImp { friend class HistoryFunc; public: History(ExecState *exec, KHTMLPart *p) : ObjectImp(exec->interpreter()->builtinObjectPrototype()), part(p) { } virtual Value get(ExecState *exec, const Identifier &propertyName) const; Value getValueProperty(ExecState *exec, int token) const; virtual const ClassInfo* classInfo() const { return &info; } static const ClassInfo info; enum { Back, Forward, Go, Length }; private: QGuardedPtr<KHTMLPart> part; }; class External : public ObjectImp { friend class ExternalFunc; public: External(ExecState *exec, KHTMLPart *p) : ObjectImp(exec->interpreter()->builtinObjectPrototype()), part(p) { } virtual Value get(ExecState *exec, const Identifier &propertyName) const; virtual const ClassInfo* classInfo() const { return &info; } static const ClassInfo info; enum { AddFavorite }; private: QGuardedPtr<KHTMLPart> part; }; class FrameArray : public ObjectImp { public: FrameArray(ExecState *exec, KHTMLPart *p) : ObjectImp(exec->interpreter()->builtinObjectPrototype()), part(p) { } virtual Value get(ExecState *exec, const Identifier &propertyName) const; private: QGuardedPtr<KHTMLPart> part; };#ifdef Q_WS_QWS class KonquerorFunc : public DOMFunction { public: KonquerorFunc(ExecState *exec, const Konqueror* k, const char* name) : DOMFunction(exec), konqueror(k), m_name(name) { } virtual Value tryCall(ExecState *exec, Object &thisObj, const List &args); private: const Konqueror* konqueror; QCString m_name; };#endif} // namespace KJS#include "kjs_window.lut.h"#include "rendering/render_replaced.h"////////////////////// Screen Object ////////////////////////// table for screen object/*@begin ScreenTable 7 height Screen::Height DontEnum|ReadOnly width Screen::Width DontEnum|ReadOnly colorDepth Screen::ColorDepth DontEnum|ReadOnly pixelDepth Screen::PixelDepth DontEnum|ReadOnly availLeft Screen::AvailLeft DontEnum|ReadOnly availTop Screen::AvailTop DontEnum|ReadOnly availHeight Screen::AvailHeight DontEnum|ReadOnly availWidth Screen::AvailWidth DontEnum|ReadOnly@end*/const ClassInfo Screen::info = { "Screen", 0, &ScreenTable, 0 };// We set the object prototype so that toString is implementedScreen::Screen(ExecState *exec) : ObjectImp(exec->interpreter()->builtinObjectPrototype()) {}Value Screen::get(ExecState *exec, const Identifier &p) const{#ifdef KJS_VERBOSE kdDebug(6070) << "Screen::get " << p.qstring() << endl;#endif return lookupGetValue<Screen,ObjectImp>(exec,p,&ScreenTable,this);}Value Screen::getValueProperty(ExecState *exec, int token) const{#if defined Q_WS_X11 && ! defined K_WS_QTONLY KWinModule info(0, KWinModule::INFO_DESKTOP);#endif QWidget *thisWidget = Window::retrieveActive(exec)->part()->widget(); QRect sg = KGlobalSettings::desktopGeometry(thisWidget); switch( token ) { case Height: return Number(sg.height()); case Width: return Number(sg.width()); case ColorDepth: case PixelDepth: { QPaintDeviceMetrics m(QApplication::desktop()); return Number(m.depth()); } case AvailLeft: {#if defined Q_WS_X11 && ! defined K_WS_QTONLY QRect clipped = info.workArea().intersect(sg); return Number(clipped.x()-sg.x());#else return Number(10);#endif } case AvailTop: {#if defined Q_WS_X11 && ! defined K_WS_QTONLY QRect clipped = info.workArea().intersect(sg); return Number(clipped.y()-sg.y());#else return Number(10);#endif } case AvailHeight: {#if defined Q_WS_X11 && ! defined K_WS_QTONLY QRect clipped = info.workArea().intersect(sg); return Number(clipped.height());#else return Number(100);#endif } case AvailWidth: {#if defined Q_WS_X11 && ! defined K_WS_QTONLY QRect clipped = info.workArea().intersect(sg); return Number(clipped.width());#else return Number(100);#endif } default: kdDebug(6070) << "WARNING: Screen::getValueProperty unhandled token " << token << endl; return Undefined(); }}////////////////////// Window Object ////////////////////////const ClassInfo Window::info = { "Window", &DOMAbstractView::info, &WindowTable, 0 };/*@begin WindowTable 89 atob Window::AToB DontDelete|Function 1 btoa Window::BToA DontDelete|Function 1 closed Window::Closed DontDelete|ReadOnly crypto Window::Crypto DontDelete|ReadOnly defaultStatus Window::DefaultStatus DontDelete defaultstatus Window::DefaultStatus DontDelete status Window::Status DontDelete document Window::Document DontDelete|ReadOnly Node Window::Node DontDelete frameElement Window::FrameElement DontDelete|ReadOnly Event Window::EventCtor DontDelete Range Window::Range DontDelete NodeFilter Window::NodeFilter DontDelete DOMException Window::DOMException DontDelete CSSRule Window::CSSRule DontDelete frames Window::Frames DontDelete|ReadOnly history Window::_History DontDelete|ReadOnly external Window::_External DontDelete|ReadOnly event Window::Event DontDelete|ReadOnly innerHeight Window::InnerHeight DontDelete|ReadOnly innerWidth Window::InnerWidth DontDelete|ReadOnly length Window::Length DontDelete|ReadOnly location Window::_Location DontDelete name Window::Name DontDelete navigator Window::_Navigator DontDelete|ReadOnly clientInformation Window::ClientInformation DontDelete|ReadOnly konqueror Window::_Konqueror DontDelete|ReadOnly offscreenBuffering Window::OffscreenBuffering DontDelete|ReadOnly opener Window::Opener DontDelete|ReadOnly outerHeight Window::OuterHeight DontDelete|ReadOnly outerWidth Window::OuterWidth DontDelete|ReadOnly pageXOffset Window::PageXOffset DontDelete|ReadOnly pageYOffset Window::PageYOffset DontDelete|ReadOnly parent Window::Parent DontDelete|ReadOnly personalbar Window::Personalbar DontDelete|ReadOnly screenX Window::ScreenX DontDelete|ReadOnly screenY Window::ScreenY DontDelete|ReadOnly scrollbars Window::Scrollbars DontDelete|ReadOnly scroll Window::Scroll DontDelete|Function 2 scrollBy Window::ScrollBy DontDelete|Function 2 scrollTo Window::ScrollTo DontDelete|Function 2 scrollX Window::ScrollX DontDelete|ReadOnly scrollY Window::ScrollY DontDelete|ReadOnly moveBy Window::MoveBy DontDelete|Function 2 moveTo Window::MoveTo DontDelete|Function 2 resizeBy Window::ResizeBy DontDelete|Function 2 resizeTo Window::ResizeTo DontDelete|Function 2 self Window::Self DontDelete|ReadOnly window Window::_Window DontDelete|ReadOnly top Window::Top DontDelete|ReadOnly screen Window::_Screen DontDelete|ReadOnly Image Window::Image DontDelete|ReadOnly Option Window::Option DontDelete|ReadOnly XMLHttpRequest Window::XMLHttpRequest DontDelete|ReadOnly XMLSerializer Window::XMLSerializer DontDelete|ReadOnly DOMParser Window::DOMParser DontDelete|ReadOnly alert Window::Alert DontDelete|Function 1 confirm Window::Confirm DontDelete|Function 1 prompt Window::Prompt DontDelete|Function 2 open Window::Open DontDelete|Function 3 setTimeout Window::SetTimeout DontDelete|Function 2 clearTimeout Window::ClearTimeout DontDelete|Function 1 focus Window::Focus DontDelete|Function 0 blur Window::Blur DontDelete|Function 0 close Window::Close DontDelete|Function 0 setInterval Window::SetInterval DontDelete|Function 2 clearInterval Window::ClearInterval DontDelete|Function 1 captureEvents Window::CaptureEvents DontDelete|Function 0 releaseEvents Window::ReleaseEvents DontDelete|Function 0 print Window::Print DontDelete|Function 0 addEventListener Window::AddEventListener DontDelete|Function 3 removeEventListener Window::RemoveEventListener DontDelete|Function 3# IE extension navigate Window::Navigate DontDelete|Function 1# Mozilla extension sidebar Window::SideBar DontDelete|ReadOnly getComputedStyle Window::GetComputedStyle DontDelete|Function 2# Warning, when adding a function to this object you need to add a case in Window::get# Event handlers# IE also has: onactivate, onbefore/afterprint, onbeforedeactivate/unload, oncontrolselect,# ondeactivate, onhelp, onmovestart/end, onresizestart/end, onscroll.# It doesn't have onabort, onchange, ondragdrop (but NS has that last one). onabort Window::Onabort DontDelete onblur Window::Onblur DontDelete onchange Window::Onchange DontDelete onclick Window::Onclick DontDelete ondblclick Window::Ondblclick DontDelete ondragdrop Window::Ondragdrop DontDelete onerror Window::Onerror DontDelete onfocus Window::Onfocus DontDelete onkeydown Window::Onkeydown DontDelete onkeypress Window::Onkeypress DontDelete onkeyup Window::Onkeyup DontDelete onload Window::Onload DontDelete onmousedown Window::Onmousedown DontDelete onmousemove Window::Onmousemove DontDelete onmouseout Window::Onmouseout DontDelete onmouseover Window::Onmouseover DontDelete onmouseup Window::Onmouseup DontDelete onmove Window::Onmove DontDelete onreset Window::Onreset DontDelete onresize Window::Onresize DontDelete onselect Window::Onselect DontDelete onsubmit Window::Onsubmit DontDelete onunload Window::Onunload DontDelete@end*/IMPLEMENT_PROTOFUNC_DOM(WindowFunc)Window::Window(khtml::ChildFrame *p) : ObjectImp(/*no proto*/), m_frame(p), screen(0), history(0), external(0), m_frames(0), loc(0), m_evt(0){ winq = new WindowQObject(this); //kdDebug(6070) << "Window::Window this=" << this << " part=" << m_part << " " << m_part->name() << endl;}Window::~Window(){ delete winq;}Window *Window::retrieveWindow(KParts::ReadOnlyPart *p){ Object obj = Object::dynamicCast( retrieve( p ) );#ifndef NDEBUG // obj should never be null, except when javascript has been disabled in that part. KHTMLPart *part = ::qt_cast<KHTMLPart *>(p); if ( part && part->jScriptEnabled() ) { assert( obj.isValid() );#ifndef QWS assert( dynamic_cast<KJS::Window*>(obj.imp()) ); // type checking#endif }#endif if ( !obj.isValid() ) // JS disabled return 0; return static_cast<KJS::Window*>(obj.imp());}Window *Window::retrieveActive(ExecState *exec){ ValueImp *imp = exec->interpreter()->globalObject().imp(); assert( imp );#ifndef QWS assert( dynamic_cast<KJS::Window*>(imp) );#endif return static_cast<KJS::Window*>(imp);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -