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

📄 kjs_window.cpp

📁 将konqueror浏览器移植到ARM9 2410中
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	    else	      goto boolargs;	    continue;	  } else {	    // leaving away the value gives true	    key = s.stripWhiteSpace().lower();	    val = "1";	  }	boolargs:	  if (key == "menubar")	    winargs.menuBarVisible = (val == "1" || val == "yes");	  else if (key == "toolbar")	    winargs.toolBarsVisible = (val == "1" || val == "yes");	  else if (key == "location")	// ### missing in WindowArgs	    winargs.toolBarsVisible = (val == "1" || val == "yes");	  else if (key == "status" || key == "statusbar")	    winargs.statusBarVisible = (val == "1" || val == "yes");	  else if (key == "resizable")	    winargs.resizable = (val == "1" || val == "yes");	  else if (key == "fullscreen")	    winargs.fullscreen = (val == "1" || val == "yes");	}      }        // prepare arguments        KURL url;        if (!str.isEmpty()) {            url = Window::retrieveActive()->part()->completeURL(str);        }        KParts::URLArgs uargs;        uargs.frameName = args[1].isDefined() ?			  args[1].toString().value().qstring()			  : QString("_blank");        uargs.serviceType = "text/html";        // request new window        KParts::ReadOnlyPart *newPart = 0L;        emit part->browserExtension()->createNewWindow("", uargs,winargs,newPart);        if (newPart && newPart->inherits("KHTMLPart")) {	  KHTMLPart *khtmlpart = static_cast<KHTMLPart*>(newPart);	    //qDebug("opener set to %p (this Window's part) in new Window %p  (this Window=%p)",part,win,window);            khtmlpart->setOpener(part);	    khtmlpart->setOpenedByJS(true);	    uargs.serviceType = QString::null;	    if (uargs.frameName == "_blank")              uargs.frameName = QString::null;	    emit khtmlpart->browserExtension()->openURLRequest(url,uargs);	    result = Window::retrieve(khtmlpart); // global object        } else            result = Undefined();     }  delete config;  break;  }  case ScrollBy:    if(args.size() == 2 && widget)      widget->scrollBy(args[0].toInt32(), args[1].toInt32());    result = Undefined();    break;  case ScrollTo:    if(args.size() == 2 && widget)      widget->setContentsPos(args[0].toInt32(), args[1].toInt32());    result = Undefined();    break;#ifndef KONQ_EMBEDDED // No window manipulations in the embedded browser  case MoveBy:    if(args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QPoint dest = tl->pos() + QPoint( args[0].toInt32(), args[1].toInt32() );      // Security check (the spec talks about UniversalBrowserWrite to disable this check...)      if ( dest.x() >= 0 && dest.y() >= 0 &&           dest.x()+tl->width() <= QApplication::desktop()->width() &&           dest.y()+tl->height() <= QApplication::desktop()->height() )          tl->move( dest );    }    break;  case MoveTo:    if(args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QPoint dest = QPoint( args[0].toInt32(), args[1].toInt32() );      // Security check (the spec talks about UniversalBrowserWrite to disable this check...)      if ( dest.x() >= 0 && dest.y() >= 0 &&           dest.x()+tl->width() <= QApplication::desktop()->width() &&           dest.y()+tl->height() <= QApplication::desktop()->height() )          tl->move( dest );    }    break;  case ResizeBy:    if(args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QSize dest = tl->size() + QSize( args[0].toInt32(), args[1].toInt32() );      // Security check: within desktop limits and bigger than 100x100 (per spec)      if ( tl->x()+dest.width() <= QApplication::desktop()->width() &&           tl->y()+dest.height() <= QApplication::desktop()->height() &&           dest.width() >= 100 && dest.height() >= 100 )          tl->resize( dest );    }    break;  case ResizeTo:    if(args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QSize dest = QSize( args[0].toInt32(), args[1].toInt32() );      // Security check: within desktop limits and bigger than 100x100 (per spec)      if ( tl->x()+dest.width() <= QApplication::desktop()->width() &&           tl->y()+dest.height() <= QApplication::desktop()->height() &&           dest.width() >= 100 && dest.height() >= 100 )          tl->resize( dest );    }    break;#endif  case SetTimeout:  case SetInterval:    if (args.size() == 2 && v.isA(StringType)) {      int i = args[1].toInt32();      int r = (const_cast<Window*>(window))->installTimeout(s.value(), i, (SetTimeout == id));      result = Number(r);    } else      result = Undefined();    break;  case ClearTimeout:  case ClearInterval:    result = Undefined();    (const_cast<Window*>(window))->clearTimeout(v.toInt32());    break;  case Focus:    if (widget)      widget->setActiveWindow();    result = Undefined();    break;  case Blur:    result = Undefined();    // TODO    break;  case Close:      /* From http://developer.netscape.com/docs/manuals/js/client/jsref/window.htm :        The close method closes only windows opened by JavaScript using the open method.        If you attempt to close any other window, a confirm is generated, which        lets the user choose whether the window closes.        This is a security feature to prevent "mail bombs" containing self.close().        However, if the window has only one document (the current one) in its        session history, the close is allowed without any confirm. This is a        special case for one-off windows that need to open other windows and        then dispose of themselves.        */    if (!window->m_part->openedByJS())    {        // To conform to the SPEC, we only ask if the window        // has more than one entry in the history (NS does that too).        History history(part);        if ( history.get( "length" ).toInt32() <= 1 ||             KMessageBox::questionYesNo( window->part()->widget(), i18n("Close window ?"), i18n("Confirmation required") ) == KMessageBox::Yes )            (const_cast<Window*>(window))->scheduleClose();    }    else    {        (const_cast<Window*>(window))->scheduleClose();    }    result = Undefined();    break;  case ToString:    result = window->toString();    break;  }  if (KJScript::current() != currentScript)    KJScript::setCurrent(currentScript);  return Completion(ReturnValue, result);}WindowQObject::WindowQObject(Window *w)  : parent(w){  part = parent->m_part;  connect( parent->m_part, SIGNAL( destroyed() ),           this, SLOT( parentDestroyed() ) );}WindowQObject::~WindowQObject(){  killTimers();}void WindowQObject::parentDestroyed(){  killTimers();  map.clear();}int WindowQObject::installTimeout(const UString &handler, int t, bool singleShot){  int id = startTimer(t);  QString hnd = handler.qstring();  // prepend 0 or 1 to differentiate between single timeouts and intervals  hnd.prepend(singleShot ? "0" : "1");  map.insert(id, hnd);  return id;}void WindowQObject::clearTimeout(int timerId){  killTimer(timerId);  map.remove(timerId);}void WindowQObject::timerEvent(QTimerEvent *e){  if (!parent->part().isNull()) {    QString hnd = map[e->timerId()];    // remove single shots installed by setTimeout()    if (hnd.startsWith("0"))      clearTimeout(e->timerId());    parent->part()->executeScript(hnd.mid(1));  }}void WindowQObject::timeoutClose(){  if (!parent->part().isNull())  {    kdDebug(6070) << "WindowQObject::timeoutClose -> closing window" << endl;    delete parent->m_part;  }}KJSO FrameArray::get(const UString &p) const{  //kdDebug() << "FrameArray::get " << p.qstring() << " part=" << (void*)part << endl;  if (part.isNull())    return Undefined();  QList<KParts::ReadOnlyPart> frames = part->frames();  int len = frames.count();  if (p == "length")    return Number(len);  // check for the name or number  KParts::ReadOnlyPart *frame = part->findFrame(p.qstring());  if (!frame) {    int i = (int)p.toDouble();    if (i >= 0 && i < len)      frame = frames.at(i);  }  // we are potentially fetching a reference to a another Window object here.  // i.e. we may be accessing objects from another interpreter instance.  // Therefore we have to be a bit careful with memory managment.  if (frame && frame->inherits("KHTMLPart")) {    const KHTMLPart *khtml = static_cast<const KHTMLPart*>(frame);    return KJSO(Window::retrieve(const_cast<KHTMLPart*>(khtml)));  }  return HostImp::get(p);}////////////////////// Location Object ////////////////////////Location::Location(KHTMLPart *p) : m_part(p) { }KJSO Location::get(const UString &p) const{  //kdDebug() << "Location::get " << p.qstring() << " m_part=" << (void*)m_part << endl;  if (m_part.isNull())    return Undefined();  KURL url = m_part->url();  QString str;  if (p == "hash")    str = url.ref().isNull() ? QString("") : "#" + url.ref();  else if (p == "host") {    str = url.host();    if (url.port())      str += ":" + QString::number((int)url.port());  } else if (p == "hostname")    str = url.host();  else if (p == "href"){      if (!url.hasPath())          str = url.prettyURL()+"/";      else          str = url.prettyURL();  }  else if (p == "pathname")    str = url.path().isEmpty() ? QString("/") : url.path();  else if (p == "port")    str = url.port() ? QString::number((int)url.port()) : QString::fromLatin1("");  else if (p == "protocol")    str = url.protocol()+":";  else if (p == "search")    str = url.query();  else if (p == "[[==]]")    return toString();  else if (p == "toString")    return Function(new LocationFunc(this, LocationFunc::ToString));  else if (HostImp::hasProperty(p))    return HostImp::get(p);  else if (p == "replace")    return Function(new LocationFunc(this, LocationFunc::Replace));  else if (p == "reload")    return Function(new LocationFunc(this, LocationFunc::Reload));  else    return Undefined();  return String(str);}void Location::put(const UString &p, const KJSO &v){  if (m_part.isNull())    return;  QString str = v.toString().value().qstring();  KURL url;  if (p == "href")       url = Window::retrieveActive()->part()->completeURL(str);  else {    url = m_part->url();    if (p == "hash") url.setRef(str);    else if (p == "host") {      QString host = str.left(str.find(":"));      QString port = str.mid(str.find(":")+1);      url.setHost(host);      url.setPort(port.toUInt());    } else if (p == "hostname") url.setHost(str);    else if (p == "pathname") url.setPath(str);    else if (p == "port") url.setPort(str.toUInt());    else if (p == "protocol")  url.setProtocol(str);    else if (p == "search") url.setQuery(str);    else {      HostImp::put(p, v);      return;    }  }  m_part->scheduleRedirection(0, url.url().prepend( "target://_self/#" ) );}KJSO Location::toPrimitive(Type) const{    return toString();}String Location::toString() const{ if (!m_part->url().hasPath())        return String(m_part->url().prettyURL()+"/");    else        return String(m_part->url().prettyURL());}LocationFunc::LocationFunc( const Location* loc, int i) : location(loc), id(i) { };Completion LocationFunc::tryExecute(const List &args){  KHTMLPart *part = location->part();  if (part) {    switch (id) {    case Replace:    {      QString str = args[0].toString().value().qstring();      part->scheduleRedirection(0, Window::retrieveActive()->part()->                              completeURL(str).url().prepend( "target://_self/#" ));      break;    }    case Reload:      part->scheduleRedirection(0, part->url().url().prepend( "target://_self/#" ) );      break;    case ToString:      KJSO result = location->toString();      return Completion(ReturnValue, result);    }  } else    kdDebug(6070) << "LocationFunc::tryExecute - no part!" << endl;  return Completion(Normal);}////////////////////// History Object ////////////////////////bool History::hasProperty(const UString &p, bool recursive) const{  if (p == "back" ||      p == "forward" ||      p == "go" ||      p == "length")      return true;  return HostImp::hasProperty(p, recursive);}KJSO History::get(const UString &p) const{  if (p == "back")    return Function(new HistoryFunc(this, HistoryFunc::Back));  else if (p == "forward")    return Function(new HistoryFunc(this, HistoryFunc::Forward));  else if (p == "go")    return Function(new HistoryFunc(this, HistoryFunc::Go));  else if (p == "length")  {      KParts::BrowserExtension *ext = part->browserExtension();      if ( !ext )          return Number( 0 );      KParts::BrowserInterface *iface = ext->browserInterface();      if ( !iface )          return Number( 0 );      QVariant length = iface->property( "historyLength" );      if ( length.type() != QVariant::UInt )          return Number( 0 );      return Number( length.toUInt() );  }  else    return HostImp::get(p);}Completion HistoryFunc::tryExecute(const List &args){  KParts::BrowserExtension *ext = history->part->browserExtension();  KJSO v = args[0];  Number n;  if(!v.isNull())    n = v.toInteger();  if(!ext)    return Completion(Normal);  KParts::BrowserInterface *iface = ext->browserInterface();  if ( !iface )      return Completion(Normal);  switch (id) {  case Back:      iface->callMethod( "goHistory(int)", -1 );//      emit ext->goHistory(-1);      break;  case Forward:      iface->callMethod( "goHistory(int)", (int)1 );//      emit ext->goHistory(1);      break;  case Go:      iface->callMethod( "goHistory(int)", n.intValue() );//      emit ext->goHistory(n.intValue());      break;  default:    break;  }  return Completion(Normal);}#include "kjs_window.moc"

⌨️ 快捷键说明

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