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

📄 kjs_window.cpp

📁 khtml在gtk上的移植版本
💻 CPP
📖 第 1 页 / 共 5 页
字号:
#else    return Boolean((KMessageBox::warningYesNo(widget, QStyleSheet::convertFromPlainText(str), "JavaScript",                                                i18n("OK"), i18n("Cancel")) == KMessageBox::Yes));#endif  case Window::Prompt:    if (part && part->xmlDocImpl())      part->xmlDocImpl()->updateRendering();    bool ok;#if APPLE_CHANGES    ok = KWQ(part)->runJavaScriptPrompt(str, args.size() >= 2 ? args[1].toString(exec).qstring() : QString::null, str2);#else    if (args.size() >= 2)      str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),                                   QStyleSheet::convertFromPlainText(str),                                   QLineEdit::Normal,                                   args[1].toString(exec).qstring(), &ok);    else      str2 = QInputDialog::getText(i18n("Konqueror: Prompt"),                                   QStyleSheet::convertFromPlainText(str),                                   QLineEdit::Normal,                                   QString::null, &ok);#endif    if ( ok )        return String(str2);    else        return Null();  case Window::Open:  {    KConfig *config = new KConfig("konquerorrc");    config->setGroup("Java/JavaScript Settings");#if !APPLE_CHANGES    int policy = config->readUnsignedNumEntry( "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart#else        int policy = config->readUnsignedNumEntry( part->settings(), "WindowOpenPolicy", 0 ); // 0=allow, 1=ask, 2=deny, 3=smart#endif    delete config;    if ( policy == 1 ) {#if !APPLE_CHANGES      if ( KMessageBox::questionYesNo(widget,                                      i18n( "This site is trying to open up a new browser "                                            "window using Javascript.\n"                                            "Do you want to allow this?" ),                                      i18n( "Confirmation: Javascript Popup" ) ) == KMessageBox::Yes )#endif        policy = 0;    } else if ( policy == 3 ) // smart    {      // window.open disabled unless from a key/mouse event      if (static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture())#if !APPLE_CHANGES        policy = 0;#else      {        policy = 0;	LOG(PopupBlocking, "Allowed JavaScript window open of %s", args[0].toString(exec).qstring().ascii());      } else {	LOG(PopupBlocking, "Blocked JavaScript window open of %s", args[0].toString(exec).qstring().ascii());      }#endif    }    QString frameName = !args[1].isNull() && args[1].type() != UndefinedType ?                        args[1].toString(exec).qstring()                        : QString("_blank");    if ( policy != 0 && !(part->findFrame(frameName) || frameName == "_top" || frameName == "_parent" || frameName == "_self")) {      return Undefined();    } else {      if (v.type() == UndefinedType)        str = QString();      KParts::WindowArgs winargs;      // scan feature argument      v = args[2];      QString features;      if (!v.isNull() && v.type() != UndefinedType && v.toString(exec).size() > 0) {        features = v.toString(exec).qstring();        // specifying window params means false defaults        winargs.menuBarVisible = false;        winargs.toolBarsVisible = false;        winargs.statusBarVisible = false;#if APPLE_CHANGES	winargs.scrollbarsVisible = true;#endif        QStringList flist = QStringList::split(',', features);        QStringList::ConstIterator it = flist.begin();        while (it != flist.end()) {          QString s = *it++;          QString key, val;          int pos = s.find('=');          if (pos >= 0) {            key = s.left(pos).stripWhiteSpace().lower();            val = s.mid(pos + 1).stripWhiteSpace().lower();	    int spacePos = val.find(' ');	    if (spacePos != -1) {	      val = val.left(spacePos);	    }            int scnum = QApplication::desktop()->screenNumber(widget->topLevelWidget());	    QRect screen = QApplication::desktop()->screenGeometry(scnum);            if (key == "left" || key == "screenx") {              bool ok;              double d = val.toDouble(&ok);              if (d != 0 || ok) {                d += screen.x();                if (d < screen.x() || d > screen.right())		  d = screen.x(); // only safe choice until size is determined                winargs.x = (int)d;#if APPLE_CHANGES	        winargs.xSet = true;#endif            } else if (key == "top" || key == "screeny") {              bool ok;              double d = val.toDouble(&ok);              if (d != 0 || ok) {                d += screen.y();                if (d < screen.y() || d > screen.bottom())		  d = screen.y(); // only safe choice until size is determined                winargs.y = (int)d;#if APPLE_CHANGES	        winargs.ySet = true;#endif              }            } else if (key == "height") {              bool ok;              double d = val.toDouble(&ok);              if (d != 0 || ok) {#if !APPLE_CHANGES                d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;#endif	        if (d > screen.height())  // should actually check workspace		  d = screen.height();                if (d < 100)		  d = 100;                winargs.height = (int)d;#if APPLE_CHANGES	        winargs.heightSet = true;#endif              }            } else if (key == "width") {              bool ok;              double d = val.toDouble(&ok);              if (d != 0 || ok) {#if !APPLE_CHANGES                d += 2*qApp->style().pixelMetric( QStyle::PM_DefaultFrameWidth ) + 2;#endif	        if (d > screen.width())    // should actually check workspace		  d = screen.width();                if (d < 100)		  d = 100;                winargs.width = (int)d;#if APPLE_CHANGES	        winargs.widthSet = true;#endif              }            } 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");#if APPLE_CHANGES          else if (key == "scrollbars")            winargs.scrollbarsVisible = !(val == "0" || val == "no");#endif        }      }      // prepare arguments      KURL url;      if (!str.isEmpty())      {        KHTMLPart* p = Window::retrieveActive(exec)->m_part;        if ( p )          url = p->htmlDocument().completeURL(str).string();      }      KParts::URLArgs uargs;      uargs.frameName = frameName;      if ( uargs.frameName == "_top" )      {	  // FIXME: referrer?          while ( part->parentPart() )              part = part->parentPart();          bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();          part->scheduleRedirection(0, url.url(), false/*don't lock history*/, userGesture);          return Window::retrieve(part);      }      if ( uargs.frameName == "_parent" )      {	  // FIXME: referrer?          if ( part->parentPart() )              part = part->parentPart();          bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();          part->scheduleRedirection(0, url.url(), false/*don't lock history*/, userGesture);          return Window::retrieve(part);      }      uargs.serviceType = "text/html";      // request window (new or existing if framename is set)      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);        if (khtmlpart->document().isNull()) {          khtmlpart->begin();          khtmlpart->write("<HTML><BODY>");          khtmlpart->end();          if (part->xmlDocImpl()) {            kdDebug(6070) << "Setting domain to " << part->xmlDocImpl()->domain().string() << endl;            khtmlpart->xmlDocImpl()->setDomain( part->docImpl()->domain(), true );          }                    if ( part->docImpl() )            khtmlpart->docImpl()->setBaseURL( part->docImpl()->baseURL() );        }#if APPLE_CHANGES        if (!url.isEmpty()) {          bool userGesture = static_cast<ScriptInterpreter *>(exec->dynamicInterpreter())->wasRunByUserGesture();          // FIXME: Need to pass referrer here.          khtmlpart->scheduleRedirection(0, url.url(), false, userGesture);	}#else        uargs.serviceType = QString::null;        if (uargs.frameName == "_blank")          uargs.frameName = QString::null;        if (!url.isEmpty())	  // FIXME: need to pass referrer here          emit khtmlpart->browserExtension()->openURLRequest(url,uargs);#endif        return Window::retrieve(khtmlpart); // global object      } else        return Undefined();      }    }  }    #if APPLE_CHANGES  case Window::Print:    part->print();    return Undefined();#endif  case Window::ScrollBy:    window->updateLayout();    if(args.size() >= 2 && widget)      widget->scrollBy(args[0].toInt32(exec), args[1].toInt32(exec));    return Undefined();  case Window::Scroll:  case Window::ScrollTo:    window->updateLayout();    if(args.size() >= 2 && widget)      widget->setContentsPos(args[0].toInt32(exec), args[1].toInt32(exec));    return Undefined();  case Window::MoveBy:    if(args.size() >= 2 && widget)    {      QWidget * tl = widget->topLevelWidget();	  QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(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() )        tl->move( dest );    }    return Undefined();  case Window::MoveTo:    if(args.size() >= 2 && widget)    {      QWidget * tl = widget->topLevelWidget();	  QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(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() )        tl->move( dest );    }    return Undefined();  case Window::ResizeBy:    if(args.size() >= 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QSize dest = tl->size() + QSize( args[0].toInt32(exec), args[1].toInt32(exec) );	  QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));      // Security check: within desktop limits and bigger than 100x100 (per spec)      if ( tl->x()+dest.width() <= sg.x()+sg.width() &&           tl->y()+dest.height() <= sg.y()+sg.height() &&           dest.width() >= 100 && dest.height() >= 100 )      {        // Take into account the window frame        int deltaWidth = tl->frameGeometry().width() - tl->width();        int deltaHeight = tl->frameGeometry().height() - tl->height();        tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );      }    }    return Undefined();  case Window::ResizeTo:    if(args.size() >= 2 && widget)    {      QWidget * tl = widget->topLevelWidget();      QSize dest = QSize( args[0].toInt32(exec), args[1].toInt32(exec) );	  QRect sg = QApplication::desktop()->screenGeometry(QApplication::desktop()->screenNumber(tl));      // Security check: within desktop limits and bigger than 100x100 (per spec)      if ( tl->x()+dest.width() <= sg.x()+sg.width() &&           tl->y()+dest.height() <= sg.y()+sg.height() &&           dest.width() >= 100 && dest.height() >= 100 )      {        // Take into account the window frame        int deltaWidth = tl->frameGeometry().width() - tl->width();        int deltaHeight = tl->frameGeometry().height() - tl->height();        tl->resize( dest.width() - deltaWidth, dest.height() - deltaHeight );      }    }    return Undefined();  case Window::SetTimeout:    if (!window->isSafeScript(exec))        return Undefined();    if (args.size() >= 2 && v.isA(StringType)) {      int i = args[1].toInt32(exec);      int r = (const_cast<Window*>(window))->installTimeout(s, i, true /*single shot*/);      return Number(r);    }    else if (args.size() >= 2 && v.isA(ObjectType) && Object::dynamicCast(v).implementsCall()) {      Value func = args[0];      int i = args[1].toInt32(exec);      // All arguments after the second should go to the function      // FIXME: could be more efficient      List funcArgs = args.copyTail().copyTail();      int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, true /*single shot*/);      return Number(r);    }    else      return Undefined();  case Window::SetInterval:    if (!window->isSafeScript(exec))        return Undefined();    if (args.size() >= 2 && v.isA(StringType)) {      int i = args[1].toInt32(exec);      int r = (const_cast<Window*>(window))->installTimeout(s, i, false);      return Number(r);    }    else if (args.size() >= 2 && !Object::dynamicCast(v).isNull() &&	     Object::dynamicCast(v).implementsCall()) {      Value func = args[0];      int i = args[1].toInt32(exec);      // All arguments after the second should go to the function      // FIXME: could be more efficient      List funcArgs = args.copyTail().copyTail();      int r = (const_cast<Window*>(window))->installTimeout(func, funcArgs, i, false);      return Number(r);    }    else      return Undefined();  case Window::ClearTimeout:  case Window::ClearInterval:    if (!window->isSafeScript(exec))        return Undefined();    (const_cast<Window*>(window))->clearTimeout(v.toInt32(exec));    return Undefined();  case Window::Focus:    if (widget)      widget->setActiveWindow();    return Undefined();

⌨️ 快捷键说明

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