Setup zoom at start-up based on command line parameter

1,115 views
Skip to first unread message

Paul. F

unread,
Jun 19, 2013, 12:09:26 PM6/19/13
to cef...@googlegroups.com
Hi, I'm trying to setup the zoom level during the start-up of the cefclient app based on a command line parameter such as zoom=-0.5 (will zoom out).
I thought about reading the zoom parameter on int APIENTRY wWinMain() by parsing lpCmdLine and then I would store that zoom level (double) on a global? variable but at that moment the browser is not ready yet to accept zoom changes.
I'm not sure when is the right moment to call ModifyZoom(browser, myGlobalVarWithZoomLevel);, as a C# programmer I'm not even sure where to save that zoom variable.
Could you give me a hint?
Thanks

Paul. F

unread,
Jun 19, 2013, 12:19:52 PM6/19/13
to cef...@googlegroups.com
that would be modifying the zoom "outside the UI thread"?

Dmitry Azaraev

unread,
Jun 19, 2013, 12:57:05 PM6/19/13
to cef...@googlegroups.com
I think that you can call CefBrowserHost.SetZoomLevel once browser created (CefLifeSpanHandler.OnAfterCreated).
It can be called from any thread, but when you call it from CEF UI thread - it applied immediately, otherwise zoom change request will be queued on ui thread and applied when ui thread will be ready.


--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best regards,
   Dmitry

Paul. F

unread,
Jun 19, 2013, 1:17:06 PM6/19/13
to cef...@googlegroups.com, dmitry....@gmail.com
Thank you Dmitry, I suck at C++ so at my first attempt just using the zoom code there were no errors, the app ran but the zoom was unchanged:

browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + -0.5);

Then I tried to copy the method "ModifyZoom" from cefclient_win.cpp to client_handler.cpp and it throws "error C3861: 'ModifyZoom': identifier not found", looks like this:

void ClientHandler::OnAfterCreated(CefRefPtr<CefBrowser> browser) {
  REQUIRE_UI_THREAD();
  // Disable mouse cursor change if requested via the command-line flag.
  if (m_bMouseCursorChangeDisabled)
    browser->GetHost()->SetMouseCursorChangeDisabled(true);
  AutoLock lock_scope(this);
  if (!m_Browser.get())   {
    // We need to keep the main child window, but not popup windows
    m_Browser = browser;
    m_BrowserId = browser->GetIdentifier();

//Zoom
ModifyZoom(browser, -0.5);
  } else if (browser->IsPopup()) {
    // Add to the list of popup browsers.
    m_PopupBrowsers.push_back(browser);
  }
  m_BrowserCount++;
}
// Change the zoom factor on the UI thread.
void ModifyZoom(CefRefPtr<CefBrowser> browser, double delta) {
  if (CefCurrentlyOn(TID_UI)) {
    browser->GetHost()->SetZoomLevel(
        browser->GetHost()->GetZoomLevel() + delta);
  } else {
    CefPostTask(TID_UI, NewCefRunnableFunction(ModifyZoom, browser, delta));
  }
}

Could you help me out? 

Dmitry Azaraev

unread,
Jun 19, 2013, 2:07:01 PM6/19/13
to cef...@googlegroups.com
Hm. I'm not sure why you ask me, there is CefGlue (C# binding) specific forum.
Error happened 'cause you are trying to accessing (calling) ModifyZoom without define their's prototype. C/C++ doesn't allow simple forward declarations (like in C#), without defining prototype (like in header files).


--
You received this message because you are subscribed to the Google Groups "CefGlue" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefglue+u...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
 
 



--
Best regards,
   Dmitry

Paul. F

unread,
Jun 19, 2013, 2:21:24 PM6/19/13
to cef...@googlegroups.com, dmitry....@gmail.com
I ask you because I'm trying to tweak the C++ source instead of using a .NET wrapper, I had many issue trying to run the wrapper and the C++ code worked out of the box with the sample app.
I added the prototype and the code runs without errors but still the zoom won't change, I debugged and this is the line of code that gets executed but doesn't affect the zoom at all:

browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + delta);

Dmitry Azaraev

unread,
Jun 19, 2013, 3:23:11 PM6/19/13
to cef...@googlegroups.com
In any case, try set zoom little later, but so early as possible. May be some other event can be useful.

Paul. F

unread,
Jun 19, 2013, 4:52:52 PM6/19/13
to cef...@googlegroups.com, dmitry....@gmail.com
solution:

void ClientHandler::OnLoadEnd(CefRefPtr<CefBrowser> browser,
                              CefRefPtr<CefFrame> frame,
                              int httpStatusCode) {
  ... 
//Zoom out
if (browser->GetHost()->GetZoomLevel() == 0)
ModifyZoom(browser, -1.5);
  }
}

Dmitry Azaraev

unread,
Jun 19, 2013, 5:36:36 PM6/19/13
to cef...@googlegroups.com
Did you try make it in OnLoadStart? Rendering begins without waiting that full document loaded and parsed (onloadend).

Paul. F

unread,
Jun 20, 2013, 1:02:29 PM6/20/13
to cef...@googlegroups.com, dmitry....@gmail.com
Hi Dmitry, switching to OnLoadStart worked very well indeed, now the page displays automatically at the zoom level I specify, before I could see the zoom changing.
Thanka a lot.
Reply all
Reply to author
Forward
0 new messages