⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 kjs_html.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
// -*- c-basic-offset: 2 -*-/* *  This file is part of the KDE libraries *  Copyright (C) 1999-2002 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 "misc/loader.h"#include "dom/html_block.h"#include "dom/html_head.h"#include "dom/html_image.h"#include "dom/html_inline.h"#include "dom/html_list.h"#include "dom/html_table.h"#include "dom/html_object.h"#include "dom/dom_exception.h"// ### HACK#include "html/html_baseimpl.h"#include "html/html_documentimpl.h"#include "html/html_imageimpl.h"#include "html/html_miscimpl.h"#include "xml/dom2_eventsimpl.h"#include <kparts/browserextension.h>#include "khtml_part.h"#include "khtmlview.h"#include "ecma/kjs_css.h"#include "ecma/kjs_events.h"#include "ecma/kjs_html.h"#include "ecma/kjs_window.h"#include "kjs_html.lut.h"#include "misc/htmltags.h"#include "misc/htmlattrs.h"#include "rendering/render_object.h"#include "rendering/render_canvas.h"#include "rendering/render_frames.h"#include "rendering/render_layer.h"#include "kmessagebox.h"#include <kstringhandler.h>#include <klocale.h>#include <kdebug.h>using namespace KJS;IMPLEMENT_PROTOFUNC_DOM(HTMLDocFunction)Value KJS::HTMLDocFunction::tryCall(ExecState *exec, Object &thisObj, const List &args){  KJS_CHECK_THIS( HTMLDocument, thisObj );  DOM::HTMLDocument doc = static_cast<KJS::HTMLDocument *>(thisObj.imp())->toDocument();  switch (id) {  case HTMLDocument::Clear: // even IE doesn't support that one...    //doc.clear(); // TODO    return Undefined();  case HTMLDocument::Open:    if (args.size() >= 3) // IE extension for document.open: it means window.open if it has 3 args or more    {      KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();      if ( view && view->part() ) {        Window* win = Window::retrieveWindow(view->part());        if( win ) {          win->openWindow(exec, args);        }      }    }    doc.open();    return Undefined();  case HTMLDocument::Close:    // see khtmltests/ecma/tokenizer-script-recursion.html    doc.close();    return Undefined();  case HTMLDocument::Write:  case HTMLDocument::WriteLn: {    // DOM only specifies single string argument, but NS & IE allow multiple    // or no arguments    UString str = "";    for (int i = 0; i < args.size(); i++)      str += args[i].toString(exec);    if (id == HTMLDocument::WriteLn)      str += "\n";#ifdef KJS_VERBOSE    kdDebug(6070) << "document.write: " << str.string().string() << endl;#endif    doc.write(str.string());    return Undefined();  }  case HTMLDocument::GetElementsByName:    return getDOMNodeList(exec,doc.getElementsByName(args[0].toString(exec).string()));  case HTMLDocument::GetSelection: {    // NS4 and Mozilla specific. IE uses document.selection.createRange()    // http://docs.sun.com/source/816-6408-10/document.htm#1195981    KHTMLView *view = static_cast<DOM::DocumentImpl*>(doc.handle())->view();    if ( view && view->part() )       return String(view->part()->selectedText());    else       return Undefined();  }  case HTMLDocument::CaptureEvents:  case HTMLDocument::ReleaseEvents:    // Do nothing for now. These are NS-specific legacy calls.    break;  }  return Undefined();}const ClassInfo KJS::HTMLDocument::info =  { "HTMLDocument", &DOMDocument::info, &HTMLDocumentTable, 0 };/* Source for HTMLDocumentTable.@begin HTMLDocumentTable 31  title			HTMLDocument::Title		DontDelete  referrer		HTMLDocument::Referrer		DontDelete|ReadOnly  domain		HTMLDocument::Domain		DontDelete  URL			HTMLDocument::URL		DontDelete|ReadOnly  body			HTMLDocument::Body		DontDelete  location		HTMLDocument::Location		DontDelete  cookie		HTMLDocument::Cookie		DontDelete  images		HTMLDocument::Images		DontDelete|ReadOnly  applets		HTMLDocument::Applets		DontDelete|ReadOnly  links			HTMLDocument::Links		DontDelete|ReadOnly  forms			HTMLDocument::Forms		DontDelete|ReadOnly  anchors		HTMLDocument::Anchors		DontDelete|ReadOnly  scripts		HTMLDocument::Scripts		DontDelete|ReadOnly  all			HTMLDocument::All		DontDelete|ReadOnly  clear			HTMLDocument::Clear		DontDelete|Function 0  open			HTMLDocument::Open		DontDelete|Function 0  close			HTMLDocument::Close		DontDelete|Function 0  write			HTMLDocument::Write		DontDelete|Function 1  writeln		HTMLDocument::WriteLn		DontDelete|Function 1  getElementsByName	HTMLDocument::GetElementsByName	DontDelete|Function 1  getSelection	HTMLDocument::GetSelection	DontDelete|Function 1  captureEvents		HTMLDocument::CaptureEvents	DontDelete|Function 0  releaseEvents		HTMLDocument::ReleaseEvents	DontDelete|Function 0  bgColor		HTMLDocument::BgColor		DontDelete  fgColor		HTMLDocument::FgColor		DontDelete  alinkColor		HTMLDocument::AlinkColor	DontDelete  linkColor		HTMLDocument::LinkColor		DontDelete  vlinkColor		HTMLDocument::VlinkColor	DontDelete  lastModified		HTMLDocument::LastModified	DontDelete|ReadOnly  height		HTMLDocument::Height		DontDelete|ReadOnly  width			HTMLDocument::Width		DontDelete|ReadOnly  dir			HTMLDocument::Dir		DontDelete  compatMode		HTMLDocument::CompatMode	DontDelete|ReadOnly#IE extension  frames		HTMLDocument::Frames		DontDelete|ReadOnly#NS4 extension  layers		HTMLDocument::Layers		DontDelete|ReadOnly#potentially obsolete array properties# plugins# tags#potentially obsolete properties# embeds# ids@end*/KJS::HTMLDocument::HTMLDocument(ExecState *exec, const DOM::HTMLDocument& d)  /*TODO pass HTMLDocumentProto::self(exec), but it needs to access DOMDocumentProto...*/  : DOMDocument(exec, d) { }bool KJS::HTMLDocument::hasProperty(ExecState *exec, const Identifier &p) const{#ifdef KJS_VERBOSE  //kdDebug(6070) << "KJS::HTMLDocument::hasProperty " << p.qstring() << endl;#endif  DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);  DOM::DocumentImpl* docImpl = static_cast<DOM::DocumentImpl*>(doc.handle());  KHTMLView *view = docImpl->view();  Window* win = view && view->part() ? Window::retrieveWindow(view->part()) : 0L;  if ( !win || !win->isSafeScript(exec) )    return false;  if ( docImpl->underDocNamedCache().contains( p.qstring() ) )    return true;  if ( view && view->part() )  {    KHTMLPart *kp = view->part()->findFrame( p.qstring() );    if (kp)      return true;  }  return DOMDocument::hasProperty(exec, p);}Value KJS::HTMLDocument::tryGet(ExecState *exec, const Identifier &propertyName) const{#ifdef KJS_VERBOSE  kdDebug(6070) << "KJS::HTMLDocument::tryGet " << propertyName.qstring() << endl;#endif  DOM::HTMLDocument doc = static_cast<DOM::HTMLDocument>(node);  DOM::DocumentImpl* docImpl = static_cast<DOM::DocumentImpl*>(doc.handle());  KHTMLView *view = docImpl->view();  Window* win = view && view->part() ? Window::retrieveWindow(view->part()) : 0L;  if ( !win || !win->isSafeScript(exec) )    return Undefined();  //Check for images, forms, objects, etc.  ElementMappingCache::ItemInfo* info = docImpl->underDocNamedCache().get(propertyName.qstring());  if (info) {    //May be a false positive, but we can try to avoid doing it the hard way in    //simpler cases. The trickiness here is that the cache is kept under both    //name and id, but we sometimes ignore id for IE compat    DOM::DOMString  propertyDOMString = propertyName.string();    if (info->nd && DOM::HTMLMappedNameCollectionImpl::matchesName(info->nd,                              HTMLCollectionImpl::DOCUMENT_NAMED_ITEMS, propertyDOMString)) {      return getDOMNode(exec, info->nd);    } else {      //Can't tell it just like that, so better go through collection and count stuff. This is the slow path...      DOM::HTMLMappedNameCollection coll(docImpl, HTMLCollectionImpl::DOCUMENT_NAMED_ITEMS, propertyDOMString);            if (coll.length() == 1) {        DOM::Node node = coll.firstItem();        return getDOMNode(exec, node);      } else if (coll.length() > 1) {        return getHTMLCollection(exec, coll);      }    }  }  // Check for frames/iframes with name==propertyName  if ( view && view->part() )  {    // ###### TODO return a collection in case several frames have the same name    // (IE does that). Hard to do with findFrame :}    KHTMLPart *kp = view->part()->findFrame( propertyName.qstring() );    if (kp)      return Window::retrieve(kp);  }  const HashEntry* entry = Lookup::findEntry(&HTMLDocumentTable, propertyName);  if (entry) {    switch (entry->value) {    case Title:      return String(doc.title());    case Referrer:      return String(doc.referrer());    case Domain:      return String(doc.domain());    case URL:      return String(doc.URL());    case Body:      return getDOMNode(exec,doc.body());    case Location:      if (win)        return Value(win->location());      else        return Undefined();    case Cookie:      return String(doc.cookie());    case Images:      return getHTMLCollection(exec,doc.images());    case Applets:      return getHTMLCollection(exec,doc.applets());    case Links:      return getHTMLCollection(exec,doc.links());    case Forms:      return getHTMLCollection(exec,doc.forms());    case Layers:      // ### Should not be hidden when we emulate Netscape4      return getHTMLCollection(exec,doc.layers(), true);    case Anchors:      return getHTMLCollection(exec,doc.anchors());    case Scripts: // TODO (IE-specific)    {      // Disable document.scripts unless we try to be IE-compatible      // Especially since it's not implemented, so      // if (document.scripts) shouldn't return true.      if ( exec->interpreter()->compatMode() != Interpreter::IECompat )        return Undefined();      // To be implemented. Meanwhile, return an object with a length property set to 0      // This gets some code going on IE-specific pages.      // The script object isn't really simple to implement though      // (http://msdn.microsoft.com/workshop/author/dhtml/reference/objects/script.asp)      kdDebug(6070) << "WARNING: KJS::HTMLDocument document.scripts called - not implemented" << endl;      Object obj( new ObjectImp() );      obj.put( exec, lengthPropertyName, Number(0) );      return obj;    }    case All:      // Disable document.all when we try to be Netscape-compatible      if ( exec->interpreter()->compatMode() == Interpreter::NetscapeCompat )        return Undefined();      else      if ( exec->interpreter()->compatMode() == Interpreter::IECompat )        return getHTMLCollection(exec,doc.all());      else // enabled but hidden        return getHTMLCollection(exec,doc.all(), true);    case Clear:    case Open:    case Close:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -