void OSRWindow::Invalidate() {
  if (!CefCurrentlyOn(TID_UI)) {
    CefPostTask(TID_UI, base::Bind(&OSRWindow::Invalidate, this));
    return;
  }

  // Don't post another task if the previous task is still pending.
  if (render_task_pending_)
    return;

  render_task_pending_ = true;

  // Render at 30fps.
  static const int kRenderDelay = 1000 / 30;
  CefPostDelayedTask(TID_UI, base::Bind(&OSRWindow::Render, this),
                     kRenderDelay);
}
Ejemplo n.º 2
0
void SetBrowserDpiSettings(CefRefPtr<CefBrowser> cefBrowser,
        CefString autoZooming) {
    // Setting zoom level immediately after browser was created
    // won't work. We need to wait a moment before we can set it.
    REQUIRE_UI_THREAD();

    double oldZoomLevel = cefBrowser->GetHost()->GetZoomLevel();
    double newZoomLevel = 0.0;

    int dpix = 0;
    int dpiy = 0;
    GetSystemDpi(&dpix, &dpiy);

    if (autoZooming.ToString() == "system_dpi") {
        // Using only "dpix" value to calculate zoom level. All
        // modern displays have equal horizontal/vertical resolution.
        // Examples:
        //   dpix=96 zoom=0.0
        //   dpix=120 zoom=1.0
        //   dpix=144 zoom=2.0
        //   dpix=72 zoom=-1.0
        newZoomLevel = (dpix - DEFAULT_DPIX) / 24;
    } else {
        // When atof() fails converting string to double, then
        // 0.0 is returned.
        newZoomLevel = atof(autoZooming.ToString().c_str());
    }

    if (oldZoomLevel != newZoomLevel) {
        cefBrowser->GetHost()->SetZoomLevel(newZoomLevel);
        if (cefBrowser->GetHost()->GetZoomLevel() != oldZoomLevel) {
            // OK succes.
            LOG_DEBUG << "Browser: SetBrowserDpiSettings: "
                    << "DPI=" << dpix << " "
                    << "zoom=" << cefBrowser->GetHost()->GetZoomLevel();
        }
    } else {
        // This code block running can also be a result of executing
        // SetZoomLevel(), as GetZoomLevel() didn't return the new
        // value that was set. Documentation says that if SetZoomLevel
        // is called on the UI thread, then GetZoomLevel should
        // immediately return the same value that was set. Unfortunately
        // this seems not to be true.
        static bool already_logged = false;
        if (!already_logged) {
            already_logged = true;
            // OK success.
            LOG_DEBUG << "Browser: SetBrowserDpiSettings: "
                    << "DPI=" << dpix << " "
                    << "zoom=" << cefBrowser->GetHost()->GetZoomLevel();
        }
    }
    // We need to check zooming constantly, during loading of pages.
    // If we set zooming to 2.0 for localhost/ and then it navigates
    // to google.com, then the zomming is back at 0.0 and needs to
    // be set again.
    CefPostDelayedTask(
            TID_UI,
            NewCefRunnableFunction(&SetBrowserDpiSettings, cefBrowser,
                autoZooming),
            50);
}