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(); } }
QWebEnginePage* WebPage::createWindow(QWebEnginePage::WebWindowType type) { std::lock_guard<std::mutex> lock(s_mutex); QString name; bool isSatellite = false; bool showToolbar = true; bool allowExternalNavigate = false; int width = 0; int height = 0; int x = -1; int y = -1; MainWindow* pMainWindow = nullptr; BrowserWindow* pWindow = nullptr; bool show = true; // check if this is target="_blank"; if (type == QWebEnginePage::WebWindowType::WebBrowserTab) { // QtWebEngine behavior is to open a new browser window and send it the // acceptNavigationRequest we use to redirect to system browser; don't want // that to be visible show = false; name = tr("_blank_redirector"); // check for an existing hidden window pWindow = s_windowTracker.getWindow(name); if (pWindow) { return pWindow->webView()->webPage(); } } // check if we have a satellite window waiting to come up if (!pendingWindows_.empty()) { // retrieve the window PendingWindow pendingWindow = pendingWindows_.front(); pendingWindows_.pop(); // capture pending window params then clear them (one time only) name = pendingWindow.name; isSatellite = pendingWindow.isSatellite; showToolbar = pendingWindow.showToolbar; pMainWindow = pendingWindow.pMainWindow; allowExternalNavigate = pendingWindow.allowExternalNavigate; // get width and height, and adjust for high DPI double dpiZoomScaling = getDpiZoomScaling(); width = pendingWindow.width * dpiZoomScaling; height = pendingWindow.height * dpiZoomScaling; x = pendingWindow.x; y = pendingWindow.y; // check for an existing window of this name pWindow = s_windowTracker.getWindow(name); if (pWindow) { // activate the browser then return NULL to indicate // we didn't create a new WebView desktop::raiseAndActivateWindow(pWindow); return nullptr; } } if (isSatellite) { // create and size pWindow = new SatelliteWindow(pMainWindow, name, this); pWindow->resize(width, height); if (x >= 0 && y >= 0) { // if the window specified its location, use it pWindow->move(x, y); } else if (name != QString::fromUtf8("pdf")) { // window location was left for us to determine; try to tile the window // (but leave pdf window alone since it is so large) // 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 move pWindow->move(moveX, moveY); } } else { pWindow = new SecondaryWindow(showToolbar, name, baseUrl_, nullptr, this, allowExternalNavigate); } // if we have a name set, start tracking this window if (!name.isEmpty()) { s_windowTracker.addWindow(name, pWindow); } // show and return the browser if (show) pWindow->show(); return pWindow->webView()->webPage(); }