QWebPage* WebPage::createWindow(QWebPage::WebWindowType)
{
    // check if this is a satellite window
    if (!pendingSatelliteWindow_.isEmpty())
    {
        // capture pending window params then clear them (one time only)
        QString name = pendingSatelliteWindow_.name;
        MainWindow* pMainWindow = pendingSatelliteWindow_.pMainWindow;

        // get width and height, and adjust for high DPI
        double dpiZoomScaling = getDpiZoomScaling();
        int width = pendingSatelliteWindow_.width * dpiZoomScaling;
        int height = pendingSatelliteWindow_.height * dpiZoomScaling;

        pendingSatelliteWindow_ = PendingSatelliteWindow();

        // check for an existing window of this name
        BrowserWindow* pSatellite = s_windowTracker.getWindow(name);
        if (pSatellite)
        {
            // activate the browser then return NULL to indicate
            // we didn't create a new WebView
            desktop::raiseAndActivateWindow(pSatellite);
            return NULL;
        }
        // create a new window if we didn't find one
        else
        {
            // create and size
            pSatellite = new SatelliteWindow(pMainWindow);
            pSatellite->resize(width, height);

            // try to tile the window (but leave pdf window alone
            // since it is so large)
            if (name != QString::fromAscii("pdf"))
            {
                // calculate location to move to

                // y always attempts to be 25 pixels above then faults back
                // to 25 pixels below if that would be offscreen
                const int OVERLAP = 25;
                int moveY = pMainWindow->y() - OVERLAP;
                if (moveY < 0)
                    moveY = pMainWindow->y() + OVERLAP;

                // x is based on centering over main window
                int moveX = pMainWindow->x() +
                            (pMainWindow->width() / 2) -
                            (width / 2);

                // perform movve
                pSatellite->move(moveX, moveY);
            }

            // add to tracker
            s_windowTracker.addWindow(name, pSatellite);

            // show and return the browser
            pSatellite->show();
            return pSatellite->webView()->webPage();
        }
    }
    else
    {
        SecondaryWindow* pWindow = new SecondaryWindow(baseUrl_);
        pWindow->show();
        return pWindow->webView()->webPage();
    }
}
Exemple #2
0
QWebView* WebView::createWindow(QWebPage::WebWindowType)
{
   SecondaryWindow* pWindow = new SecondaryWindow(baseUrl_);
   pWindow->show();
   return pWindow->webView();
}
Exemple #3
0
void GwtCallback::browseUrl(QString url)
{
   QUrl qurl(url);

#ifdef Q_WS_MAC
   if (qurl.scheme() == QString::fromAscii("file"))
   {
      QProcess open;
      QStringList args;
      // force use of Preview for PDFs (Adobe Reader 10.01 crashes)
      if (url.toLower().endsWith(QString::fromAscii(".pdf")))
      {
         args.append(QString::fromAscii("-a"));
         args.append(QString::fromAscii("Preview"));
         args.append(url);
      }
      else
      {
         args.append(url);
      }
      open.start(QString::fromAscii("open"), args);
      open.waitForFinished(5000);
      if (open.exitCode() != 0)
      {
         // Probably means that the file doesn't have a registered
         // application or something.
         QProcess reveal;
         reveal.startDetached(QString::fromAscii("open"), QStringList() << QString::fromAscii("-R") << url);
      }
      return;
   }
#endif

   if (qurl.isRelative())
   {
      // TODO: this should really be handled within GlobalDisplay -- rather
      // than checking for a relative URL here GlobalDisplay should determine
      // that a URL is relative and do the right thing (note this needs to
      // account for our policy regarding /custom/* urls -- below we allow
      // these to be opened in a standard browser window to match the
      // behavior of standard CRAN desktop R).

      // compute local url
      QUrl localUrl;
      localUrl.setScheme(QString::fromAscii("http"));
      localUrl.setHost(QString::fromAscii("localhost"));
      localUrl.setPort(options().portNumber().toInt());
      localUrl.setEncodedPath(url.toAscii());

      // show it in a browser or a secondary window as appropriate
      if (url.startsWith(QString::fromAscii("custom/")) ||
          url.startsWith(QString::fromAscii("help/")))
      {
         QDesktopServices::openUrl(localUrl);
      }
      else
      {
         SecondaryWindow* pBrowser = new SecondaryWindow(localUrl);
         pBrowser->webView()->load(localUrl);
         pBrowser->show();
         pBrowser->activateWindow();
      }
   }
   else
   {
      QDesktopServices::openUrl(qurl);
   };
}