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

📄 kjs_window.cpp

📁 konqueror3 embedded版本, KDE环境下的当家浏览器的嵌入式版本源码包.
💻 CPP
📖 第 1 页 / 共 5 页
字号:
      //qDebug("opener set to %p (this Window's part) in new Window %p  (this Window=%p)",part,win,window);      khtmlpart->setOpener(p);      khtmlpart->setOpenedByJS(true);      if (khtmlpart->document().isNull()) {        khtmlpart->begin();        khtmlpart->write("<HTML><BODY>");        khtmlpart->end();        if ( p->docImpl() ) {          //kdDebug(6070) << "Setting domain to " << p->docImpl()->domain().string() << endl;          khtmlpart->docImpl()->setDomain( p->docImpl()->domain());          khtmlpart->docImpl()->setBaseURL( p->docImpl()->baseURL() );        }      }      uargs.serviceType = QString::null;      if (uargs.frameName.lower() == "_blank")        uargs.frameName = QString::null;      if (!url.isEmpty())        emit khtmlpart->browserExtension()->openURLRequest(url,uargs);      return Window::retrieve(khtmlpart); // global object    } else      return Undefined();}void Window::forgetSuppressedWindows(){  m_suppressedWindowInfo.clear();}void Window::showSuppressedWindows(){  KHTMLPart *part = ::qt_cast<KHTMLPart *>( m_frame->m_part );  KJS::Interpreter *interpreter = part->jScript()->interpreter();  ExecState *exec = interpreter->globalExec();  QValueList<SuppressedWindowInfo> suppressedWindowInfo = m_suppressedWindowInfo;  m_suppressedWindowInfo.clear();  QValueList<SuppressedWindowInfo>::Iterator it = suppressedWindowInfo.begin();  for ( ; it != suppressedWindowInfo.end() ; ++it ) {    executeOpenWindow(exec, (*it).url, (*it).frameName, (*it).features);  }}Value WindowFunc::tryCall(ExecState *exec, Object &thisObj, const List &args){  KJS_CHECK_THIS( Window, thisObj );  Window *window = static_cast<Window *>(thisObj.imp());  QString str, str2;  KHTMLPart *part = ::qt_cast<KHTMLPart *>(window->m_frame->m_part);  if (!part)    return Undefined();  KHTMLView *widget = part->view();  Value v = args[0];  UString s = v.toString(exec);  str = s.qstring();  QString caption;  if (part && !part->url().host().isEmpty())    caption = part->url().host() + " - ";  caption += "JavaScript"; // TODO: i18n  // functions that work everywhere  switch(id) {  case Window::Alert:    if (!widget->dialogsAllowed())      return Undefined();    if ( part && part->xmlDocImpl() )      part->xmlDocImpl()->updateRendering();    if ( part )      emit part->browserExtension()->requestFocus(part);    KMessageBox::error(widget, QStyleSheet::convertFromPlainText(str), caption);    return Undefined();  case Window::Confirm:    if (!widget->dialogsAllowed())      return Undefined();    if ( part && part->xmlDocImpl() )      part->xmlDocImpl()->updateRendering();    if ( part )      emit part->browserExtension()->requestFocus(part);    return Boolean((KMessageBox::warningYesNo(widget, QStyleSheet::convertFromPlainText(str), caption,                                                KStdGuiItem::ok(), KStdGuiItem::cancel()) == KMessageBox::Yes));  case Window::Prompt:#ifndef KONQ_EMBEDDED    if (!widget->dialogsAllowed())      return Undefined();    if ( part && part->xmlDocImpl() )      part->xmlDocImpl()->updateRendering();    if ( part )      emit part->browserExtension()->requestFocus(part);    bool ok;    if (args.size() >= 2)      str2 = KInputDialog::getText(caption,                                   QStyleSheet::convertFromPlainText(str),                                   args[1].toString(exec).qstring(), &ok, widget);    else      str2 = KInputDialog::getText(caption,                                   QStyleSheet::convertFromPlainText(str),                                   QString::null, &ok, widget);    if ( ok )        return String(str2);    else        return Null();#else    return Undefined();#endif  case Window::GetComputedStyle:  {       if ( !part || !part->xmlDocImpl() )         return Undefined();        DOM::Node arg0 = toNode(args[0]);        if (arg0.nodeType() != DOM::Node::ELEMENT_NODE)          return Undefined(); // throw exception?        else          return getDOMCSSStyleDeclaration(exec, part->document().defaultView().getComputedStyle(static_cast<DOM::Element>(arg0),                                                                              args[1].toString(exec).string()));      }  case Window::Open:    return window->openWindow(exec, args);  case Window::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.    */    bool doClose = false;    if (!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(exec,part);      if ( history.get( exec, "length" ).toInt32(exec) <= 1 )      {        doClose = true;      }      else      {        // Can we get this dialog with tabs??? Does it close the window or the tab in that case?        emit part->browserExtension()->requestFocus(part);        if ( KMessageBox::questionYesNo( window->part()->widget(),                                         i18n("Close window?"), i18n("Confirmation Required"),                                         KStdGuiItem::close(), KStdGuiItem::cancel() )             == KMessageBox::Yes )          doClose = true;      }    }    else      doClose = true;    if (doClose)    {      // If this is the current window (the one the interpreter runs in),      // then schedule a delayed close (so that the script terminates first).      // But otherwise, close immediately. This fixes w=window.open("","name");w.close();window.open("name");      if ( Window::retrieveActive(exec) == window ) {        if (widget) {          // quit all dialogs of this view          // this fixes 'setTimeout('self.close()',1000); alert("Hi");' crash          widget->closeChildDialogs();        }        //kdDebug() << "scheduling delayed close"  << endl;        // We'll close the window at the end of the script execution        Window* w = const_cast<Window*>(window);        w->m_delayed.append( Window::DelayedAction( Window::DelayedClose ) );      } else {        //kdDebug() << "closing NOW"  << endl;        (const_cast<Window*>(window))->closeNow();      }    }    return Undefined();  }  case Window::Navigate:    window->goURL(exec, args[0].toString(exec).qstring(), false /*don't lock history*/);    return Undefined();  case Window::Focus: {    KHTMLSettings::KJSWindowFocusPolicy policy =		part->settings()->windowFocusPolicy(part->url().host());    if(policy == KHTMLSettings::KJSWindowFocusAllow && widget) {      widget->topLevelWidget()->raise();      KWin::deIconifyWindow( widget->topLevelWidget()->winId() );      widget->setActiveWindow();      emit part->browserExtension()->requestFocus(part);    }    return Undefined();  }  case Window::Blur:    // TODO    return Undefined();  case Window::BToA:  case Window::AToB: {      if (!s.is8Bit())          return Undefined();       QByteArray  in, out;       char *binData = s.ascii();       in.setRawData( binData, s.size() );       if (id == Window::AToB)           KCodecs::base64Decode( in, out );       else           KCodecs::base64Encode( in, out );       in.resetRawData( binData, s.size() );       UChar *d = new UChar[out.size()];       for (uint i = 0; i < out.size(); i++)           d[i].uc = (uchar) out[i];       UString ret(d, out.size(), false /*no copy*/);       return String(ret);  }  };  // now unsafe functions..  if (!window->isSafeScript(exec))    return Undefined();  switch (id) {  case Window::ScrollBy:    if(args.size() == 2 && widget)      widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));    return Undefined();  case Window::Scroll:  case Window::ScrollTo:    if(args.size() == 2 && widget)      widget->setContentsPos(args[0].toInt32(exec), args[1].toInt32(exec));    return Undefined();  case Window::MoveBy: {    KHTMLSettings::KJSWindowMovePolicy policy =		part->settings()->windowMovePolicy(part->url().host());    if(policy == KHTMLSettings::KJSWindowMoveAllow && args.size() == 2 && widget)    {      KParts::BrowserExtension *ext = part->browserExtension();      if (ext) {        QWidget * tl = widget->topLevelWidget();        QRect sg = KGlobalSettings::desktopGeometry(tl);        QPoint dest = tl->pos() + QPoint( args[0].toInt32(exec), args[1].toInt32(exec) );        // Security check (the spec talks about UniversalBrowserWrite to disable this check...)        if ( dest.x() >= sg.x() && dest.y() >= sg.x() &&             dest.x()+tl->width() <= sg.width()+sg.x() &&             dest.y()+tl->height() <= sg.height()+sg.y() )          emit ext->moveTopLevelWidget( dest.x(), dest.y() );      }    }    return Undefined();  }  case Window::MoveTo: {    KHTMLSettings::KJSWindowMovePolicy policy =		part->settings()->windowMovePolicy(part->url().host());    if(policy == KHTMLSettings::KJSWindowMoveAllow && args.size() == 2 && widget)    {      KParts::BrowserExtension *ext = part->browserExtension();      if (ext) {        QWidget * tl = widget->topLevelWidget();        QRect sg = KGlobalSettings::desktopGeometry(tl);        QPoint dest( args[0].toInt32(exec)+sg.x(), args[1].toInt32(exec)+sg.y() );        // Security check (the spec talks about UniversalBrowserWrite to disable this check...)        if ( dest.x() >= sg.x() && dest.y() >= sg.y() &&             dest.x()+tl->width() <= sg.width()+sg.x() &&             dest.y()+tl->height() <= sg.height()+sg.y() )		emit ext->moveTopLevelWidget( dest.x(), dest.y() );      }    }    return Undefined();  }  case Window::ResizeBy: {    KHTMLSettings::KJSWindowResizePolicy policy =		part->settings()->windowResizePolicy(part->url().host());    if(policy == KHTMLSettings::KJSWindowResizeAllow    		&& args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QRect geom = tl->frameGeometry();      window->resizeTo( tl,                        geom.width() + args[0].toInt32(exec),                        geom.height() + args[1].toInt32(exec) );    }    return Undefined();  }  case Window::ResizeTo: {    KHTMLSettings::KJSWindowResizePolicy policy =               part->settings()->windowResizePolicy(part->url().host());    if(policy == KHTMLSettings::KJSWindowResizeAllow               && args.size() == 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      window->resizeTo( tl, args[0].toInt32(exec), args[1].toInt32(exec) );    }    return Undefined();  }  case Window::SetTimeout:  case Window::SetInterval: {    bool singleShot;    int i; // timeout interval    if (args.size() == 0)      return Undefined();    if (args.size() > 1) {      singleShot = (id == Window::SetTimeout);      i = args[1].toInt32(exec);    } else {      // second parameter is missing. Emulate Mozilla behavior.      singleShot = true;      i = 4;    }    if (v.isA(StringType)) {      int r = (const_cast<Window*>(window))->winq->installTimeout(Identifier(s), i, singleShot );      return Number(r);    }    else if (v.isA(ObjectType) && Object::dynamicCast(v).implementsCall()) {      Object func = Object::dynamicCast(v);      List funcArgs;      ListIterator it = args.begin();      int argno = 0;      while (it != args.end()) {	Value arg = it++;	if (argno++ >= 2)	    funcArgs.append(arg);      }      if (args.size() < 2)	funcArgs.append(Number(i));      int r = (const_cast<Window*>(window))->winq->installTimeout(func, funcArgs, i, singleShot );      return Number(r);    }    else      return Undefined();  }  case Window::ClearTimeout:  case Window::ClearInterval:    (const_cast<Window*>(window))->winq->clearTimeout(v.toInt32(exec));    return Undefined();  case Window::Print:    if ( widget ) {      // ### TODO emit onbeforeprint event      widget->print();      // ### TODO emit onafterprint event    }  case Window::CaptureEvents:  case Window::ReleaseEvents:    // Do nothing for now. These are NS-specific legacy calls.    break;  case Window::AddEventListener: {        JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);        if (listener) {	    DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());            docimpl->addWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));        }        return Undefined();    }  case Window::RemoveEventListener: {        JSEventListener *listener = Window::retrieveActive(exec)->getJSEventListener(args[1]);        if (listener) {	    DOM::DocumentImpl* docimpl = static_cast<DOM::DocumentImpl *>(part->document().handle());            docimpl->removeWindowEventListener(DOM::EventImpl::typeToId(args[0].toString(exec).string()),listener,args[2].toBoolean(exec));        }        return Undefined();    }  }  return Undefined();}////////////////////// ScheduledAction ////////////////////////// KDE 4: Make those parameters const ... &ScheduledAction::ScheduledAction(Object _func, List _args, QTime _nextTime, int _interval, bool _singleShot,				  int _timerId){  //kdDebug(6070) << "ScheduledAction::ScheduledAction(isF

⌨️ 快捷键说明

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