📄 kjs_window.cpp
字号:
// -*- c-basic-offset: 2 -*-
/*
* This file is part of the KDE libraries
* Copyright (C) 2000 Harri Porten (porten@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 Lesser 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <qstylesheet.h>
#include <qtimer.h>
#include <qinputdialog.h>
#include <qpaintdevicemetrics.h>
#include <qapplication.h>
#include <kdebug.h>
#include <kmessagebox.h>
#include <klocale.h>
#include <kparts/browserinterface.h>
#include <kwin.h>
#include <kwinmodule.h>
#include <kconfig.h>
#include <assert.h>
#include <qstyle.h>
#include "rendering/render_canvas.h"
#if APPLE_CHANGES
#include "KWQLogging.h"
#include "KWQKConfigBase.h"
#endif
#include <kjs/collector.h>
#include "kjs_proxy.h"
#include "kjs_window.h"
#include "kjs_navigator.h"
#include "kjs_html.h"
#include "kjs_range.h"
#include "kjs_traversal.h"
#include "kjs_css.h"
#include "kjs_events.h"
#include "xmlhttprequest.h"
#include "xmlserializer.h"
#include "khtmlview.h"
#include "khtml_part.h"
#include "dom/dom_string.h"
#include "dom/dom_node.h"
#include "editing/htmlediting.h"
#include "editing/selection.h"
#include "xml/dom2_eventsimpl.h"
#include "xml/dom_docimpl.h"
#include "xml/dom_position.h"
#include "html/html_documentimpl.h"
#include "misc/htmltags.h"
using DOM::DocumentImpl;
using DOM::DOMString;
using DOM::Node;
using DOM::Position;
using khtml::TypingCommand;
using namespace KJS;
namespace KJS {
////////////////////// History Object ////////////////////////
class History : public ObjectImp {
friend class HistoryFunc;
public:
History(ExecState *exec, KHTMLPart *p)
: ObjectImp(exec->lexicalInterpreter()->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 };
virtual UString toString(ExecState *exec) const;
private:
QGuardedPtr<KHTMLPart> part;
};
class FrameArray : public ObjectImp {
public:
FrameArray(ExecState *exec, KHTMLPart *p)
: ObjectImp(exec->lexicalInterpreter()->builtinObjectPrototype()), part(p) { }
virtual Value get(ExecState *exec, const Identifier &propertyName) const;
virtual UString toString(ExecState *exec) const;
private:
QGuardedPtr<KHTMLPart> part;
};
#ifdef Q_WS_QWS
class KonquerorFunc : public DOMFunction {
public:
KonquerorFunc(const Konqueror* k, const char* name)
: DOMFunction(), 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"
////////////////////// 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 implemented
Screen::Screen(ExecState *exec)
: ObjectImp(exec->lexicalInterpreter()->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
{
KWinModule info;
QWidget *thisWidget = Window::retrieveActive(exec)->part()->view();
QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(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: {
QRect clipped = info.workArea().intersect(sg);
return Number(clipped.x()-sg.x());
}
case AvailTop: {
QRect clipped = info.workArea().intersect(sg);
return Number(clipped.y()-sg.y());
}
case AvailHeight: {
QRect clipped = info.workArea().intersect(sg);
return Number(clipped.height());
}
case AvailWidth: {
QRect clipped = info.workArea().intersect(sg);
return Number(clipped.width());
}
default:
kdWarning() << "Screen::getValueProperty unhandled token " << token << endl;
return Undefined();
}
}
////////////////////// Window Object ////////////////////////
const ClassInfo Window::info = { "Window", 0, &WindowTable, 0 };
/*
@begin WindowTable 91
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
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
event Window::Event DontDelete
innerHeight Window::InnerHeight DontDelete|ReadOnly
innerWidth Window::InnerWidth DontDelete|ReadOnly
length Window::Length DontDelete|ReadOnly
location Window::_Location DontDelete
locationbar Window::Locationbar DontDelete
name Window::Name DontDelete
navigator Window::_Navigator DontDelete|ReadOnly
clientInformation Window::ClientInformation DontDelete|ReadOnly
konqueror Window::_Konqueror DontDelete|ReadOnly
menubar Window::Menubar 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
screenLeft Window::ScreenLeft DontDelete|ReadOnly
screenTop Window::ScreenTop DontDelete|ReadOnly
scrollbars Window::Scrollbars DontDelete|ReadOnly
statusbar Window::Statusbar DontDelete|ReadOnly
toolbar Window::Toolbar 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
alert Window::Alert DontDelete|Function 1
confirm Window::Confirm DontDelete|Function 1
prompt Window::Prompt DontDelete|Function 2
open Window::Open DontDelete|Function 3
print Window::Print DontDelete|Function 2
setTimeout Window::SetTimeout DontDelete|Function 2
clearTimeout Window::ClearTimeout DontDelete|Function 1
focus Window::Focus DontDelete|Function 0
getSelection Window::GetSelection 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
# Warning, when adding a function to this object you need to add a case in Window::get
addEventListener Window::AddEventListener DontDelete|Function 3
removeEventListener Window::RemoveEventListener DontDelete|Function 3
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
onscroll Window::Onscroll DontDelete
onsearch Window::Onsearch DontDelete
onselect Window::Onselect DontDelete
onsubmit Window::Onsubmit DontDelete
onunload Window::Onunload DontDelete
@end
*/
IMPLEMENT_PROTOFUNC(WindowFunc)
Window::Window(KHTMLPart *p)
: ObjectImp(/*no proto*/)
, m_part(p)
, screen(0)
, history(0)
, frames(0)
, loc(0)
, m_selection(0)
, m_locationbar(0)
, m_menubar(0)
, m_personalbar(0)
, m_scrollbars(0)
, m_statusbar(0)
, m_toolbar(0)
, m_evt(0)
{
winq = new WindowQObject(this);
//kdDebug(6070) << "Window::Window this=" << this << " part=" << m_part << " " << m_part->name() << endl;
}
Window::~Window()
{
kdDebug(6070) << "Window::~Window this=" << this << " part=" << m_part << endl;
delete winq;
}
KJS::Interpreter *Window::interpreter() const
{
return KJSProxy::proxy( m_part )->interpreter();
}
Window *Window::retrieveWindow(KHTMLPart *p)
{
Object obj = Object::dynamicCast( retrieve( p ) );
#ifndef NDEBUG
// obj should never be null, except when javascript has been disabled in that part.
if ( p && p->jScriptEnabled() )
{
assert( !obj.isNull() );
#ifndef QWS
//assert( dynamic_cast<KJS::Window*>(obj.imp()) ); // type checking
#endif
}
#endif
if ( obj.isNull() ) // JS disabled
return 0;
return static_cast<KJS::Window*>(obj.imp());
}
Window *Window::retrieveActive(ExecState *exec)
{
ValueImp *imp = exec->dynamicInterpreter()->globalObject().imp();
assert( imp );
#ifndef QWS
//assert( dynamic_cast<KJS::Window*>(imp) );
#endif
return static_cast<KJS::Window*>(imp);
}
Value Window::retrieve(KHTMLPart *p)
{
assert(p);
KJSProxy *proxy = KJSProxy::proxy( p );
if (proxy) {
#ifdef KJS_VERBOSE
kdDebug(6070) << "Window::retrieve part=" << p << " interpreter=" << proxy->interpreter() << " window=" << proxy->interpreter()->globalObject().imp() << endl;
#endif
return proxy->interpreter()->globalObject(); // the Global object is the "window"
} else
return Undefined(); // This can happen with JS disabled on the domain of that window
}
Location *Window::location() const
{
if (!loc)
const_cast<Window*>(this)->loc = new Location(m_part);
return loc;
}
Selection *Window::selection() const
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -