diff --git a/include/capi/cef_browser_capi.h b/include/capi/cef_browser_capi.h index 89107fbf6..10ba46f24 100644 --- a/include/capi/cef_browser_capi.h +++ b/include/capi/cef_browser_capi.h @@ -171,6 +171,8 @@ typedef struct _cef_browser_t { /// // Structure used to represent the browser process aspects of a browser window. // The functions of this structure can only be called in the browser process. +// They may be called on any thread in that process unless otherwise indicated +// in the comments. /// typedef struct _cef_browser_host_t { /// @@ -234,6 +236,17 @@ typedef struct _cef_browser_host_t { // The resulting string must be freed by calling cef_string_userfree_free(). cef_string_userfree_t (CEF_CALLBACK *get_dev_tools_url)( struct _cef_browser_host_t* self, int http_scheme); + + /// + // Get the zoom level. This function can only be called on the UI thread. + /// + double (CEF_CALLBACK *get_zoom_level)(struct _cef_browser_host_t* self); + + /// + // Change the zoom level to the specified value. + /// + void (CEF_CALLBACK *set_zoom_level)(struct _cef_browser_host_t* self, + double zoomLevel); } cef_browser_host_t; diff --git a/include/cef_browser.h b/include/cef_browser.h index 3a6f4d2c0..a5178f903 100644 --- a/include/cef_browser.h +++ b/include/cef_browser.h @@ -181,7 +181,9 @@ class CefBrowser : public virtual CefBase { /// // Class used to represent the browser process aspects of a browser window. The -// methods of this class can only be called in the browser process. +// methods of this class can only be called in the browser process. They may be +// called on any thread in that process unless otherwise indicated in the +// comments. /// /*--cef(source=library)--*/ class CefBrowserHost : public virtual CefBase { @@ -267,6 +269,18 @@ class CefBrowserHost : public virtual CefBase { /// /*--cef()--*/ virtual CefString GetDevToolsURL(bool http_scheme) =0; + + /// + // Get the zoom level. This method can only be called on the UI thread. + /// + /*--cef()--*/ + virtual double GetZoomLevel() =0; + + /// + // Change the zoom level to the specified value. + /// + /*--cef()--*/ + virtual void SetZoomLevel(double zoomLevel) =0; }; #endif // CEF_INCLUDE_CEF_BROWSER_H_ diff --git a/libcef/browser/browser_host_impl.cc b/libcef/browser/browser_host_impl.cc index 7f1ec618e..80e424e7d 100644 --- a/libcef/browser/browser_host_impl.cc +++ b/libcef/browser/browser_host_impl.cc @@ -335,6 +335,29 @@ CefString CefBrowserHostImpl::GetDevToolsURL(bool http_scheme) { return (http_scheme ? devtools_url_http_ : devtools_url_chrome_); } +double CefBrowserHostImpl::GetZoomLevel() { + // Verify that this method is being called on the UI thread. + if (!CEF_CURRENTLY_ON_UIT()) { + NOTREACHED() << "called on invalid thread"; + return 0; + } + + if (web_contents_.get()) + return web_contents_->GetZoomLevel(); + + return 0; +} + +void CefBrowserHostImpl::SetZoomLevel(double zoomLevel) { + if (CEF_CURRENTLY_ON_UIT()) { + if (web_contents_.get() && web_contents_->GetRenderViewHost()) + web_contents_->GetRenderViewHost()->SetZoomLevel(zoomLevel); + } else { + CEF_POST_TASK(CEF_UIT, + base::Bind(&CefBrowserHostImpl::SetZoomLevel, this, zoomLevel)); + } +} + // CefBrowser methods. // ----------------------------------------------------------------------------- diff --git a/libcef/browser/browser_host_impl.h b/libcef/browser/browser_host_impl.h index 1d2fdf7b0..0cf3bdfd9 100644 --- a/libcef/browser/browser_host_impl.h +++ b/libcef/browser/browser_host_impl.h @@ -105,6 +105,8 @@ class CefBrowserHostImpl : public CefBrowserHost, virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE; virtual CefRefPtr GetClient() OVERRIDE; virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE; + virtual double GetZoomLevel() OVERRIDE; + virtual void SetZoomLevel(double zoomLevel) OVERRIDE; // CefBrowser methods. virtual CefRefPtr GetHost() OVERRIDE; diff --git a/libcef_dll/cpptoc/browser_host_cpptoc.cc b/libcef_dll/cpptoc/browser_host_cpptoc.cc index 6f3d58db3..7110b3f49 100644 --- a/libcef_dll/cpptoc/browser_host_cpptoc.cc +++ b/libcef_dll/cpptoc/browser_host_cpptoc.cc @@ -212,6 +212,34 @@ cef_string_userfree_t CEF_CALLBACK browser_host_get_dev_tools_url( return _retval.DetachToUserFree(); } +double CEF_CALLBACK browser_host_get_zoom_level( + struct _cef_browser_host_t* self) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return 0; + + // Execute + double _retval = CefBrowserHostCppToC::Get(self)->GetZoomLevel(); + + // Return type: simple + return _retval; +} + +void CEF_CALLBACK browser_host_set_zoom_level(struct _cef_browser_host_t* self, + double zoomLevel) { + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + DCHECK(self); + if (!self) + return; + + // Execute + CefBrowserHostCppToC::Get(self)->SetZoomLevel( + zoomLevel); +} + // CONSTRUCTOR - Do not edit by hand. @@ -227,6 +255,8 @@ CefBrowserHostCppToC::CefBrowserHostCppToC(CefBrowserHost* cls) browser_host_get_opener_window_handle; struct_.struct_.get_client = browser_host_get_client; struct_.struct_.get_dev_tools_url = browser_host_get_dev_tools_url; + struct_.struct_.get_zoom_level = browser_host_get_zoom_level; + struct_.struct_.set_zoom_level = browser_host_set_zoom_level; } #ifndef NDEBUG diff --git a/libcef_dll/ctocpp/browser_host_ctocpp.cc b/libcef_dll/ctocpp/browser_host_ctocpp.cc index 04e57c86b..c1ce07257 100644 --- a/libcef_dll/ctocpp/browser_host_ctocpp.cc +++ b/libcef_dll/ctocpp/browser_host_ctocpp.cc @@ -163,6 +163,30 @@ CefString CefBrowserHostCToCpp::GetDevToolsURL(bool http_scheme) { return _retvalStr; } +double CefBrowserHostCToCpp::GetZoomLevel() { + if (CEF_MEMBER_MISSING(struct_, get_zoom_level)) + return 0; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + double _retval = struct_->get_zoom_level(struct_); + + // Return type: simple + return _retval; +} + +void CefBrowserHostCToCpp::SetZoomLevel(double zoomLevel) { + if (CEF_MEMBER_MISSING(struct_, set_zoom_level)) + return; + + // AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING + + // Execute + struct_->set_zoom_level(struct_, + zoomLevel); +} + #ifndef NDEBUG template<> long CefCToCpp GetClient() OVERRIDE; virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE; + virtual double GetZoomLevel() OVERRIDE; + virtual void SetZoomLevel(double zoomLevel) OVERRIDE; }; #endif // USING_CEF_SHARED diff --git a/tests/cefclient/cefclient.rc b/tests/cefclient/cefclient.rc index 66c8f176c..c56c72659 100644 --- a/tests/cefclient/cefclient.rc +++ b/tests/cefclient/cefclient.rc @@ -80,6 +80,9 @@ BEGIN MENUITEM "HTML5 Video", ID_TESTS_HTML5VIDEO MENUITEM "Drag && Drop", ID_TESTS_DRAGDROP MENUITEM "Geolocation", ID_TESTS_GEOLOCATION + MENUITEM "Zoom In", ID_TESTS_ZOOM_IN + MENUITEM "Zoom Out", ID_TESTS_ZOOM_OUT + MENUITEM "Zoom Reset", ID_TESTS_ZOOM_RESET END END diff --git a/tests/cefclient/cefclient_gtk.cpp b/tests/cefclient/cefclient_gtk.cpp index 0cb4d3940..05c1e7d87 100644 --- a/tests/cefclient/cefclient_gtk.cpp +++ b/tests/cefclient/cefclient_gtk.cpp @@ -150,6 +150,37 @@ gboolean HTML5DragDropActivated(GtkWidget* widget) { return FALSE; // Don't stop this message. } + +// Callback for Debug > Zoom In... menu item. +gboolean ZoomInActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + 0.5); + } + + return FALSE; // Don't stop this message. +} + +// Callback for Debug > Zoom Out... menu item. +gboolean ZoomOutActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() - 0.5); + } + + return FALSE; // Don't stop this message. +} + +// Callback for Debug > Zoom Reset... menu item. +gboolean ZoomResetActivated(GtkWidget* widget) { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(0.0); + } + + return FALSE; // Don't stop this message. +} + // Callback for when you click the back button. void BackButtonClicked(GtkButton* button) { if (g_handler.get() && g_handler->GetBrowserId()) @@ -235,6 +266,12 @@ GtkWidget* CreateMenuBar() { G_CALLBACK(HTML5VideoActivated)); AddMenuEntry(debug_menu, "HTML5 Drag & Drop", G_CALLBACK(HTML5DragDropActivated)); + AddMenuEntry(debug_menu, "Zoom In", + G_CALLBACK(ZoomInActivated)); + AddMenuEntry(debug_menu, "Zoom Out", + G_CALLBACK(ZoomOutActivated)); + AddMenuEntry(debug_menu, "Zoom Reset", + G_CALLBACK(ZoomResetActivated)); return menu_bar; } diff --git a/tests/cefclient/cefclient_mac.mm b/tests/cefclient/cefclient_mac.mm index 54528e45b..324ce5455 100644 --- a/tests/cefclient/cefclient_mac.mm +++ b/tests/cefclient/cefclient_mac.mm @@ -203,6 +203,9 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { - (IBAction)testWebGL:(id)sender; - (IBAction)testHTML5Video:(id)sender; - (IBAction)testDragDrop:(id)sender; +- (IBAction)testZoomIn:(id)sender; +- (IBAction)testZoomOut:(id)sender; +- (IBAction)testZoomReset:(id)sender; @end @implementation ClientAppDelegate @@ -269,6 +272,15 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { [testMenu addItemWithTitle:@"Drag & Drop" action:@selector(testDragDrop:) keyEquivalent:@""]; + [testMenu addItemWithTitle:@"Zoom In" + action:@selector(testZoomIn:) + keyEquivalent:@""]; + [testMenu addItemWithTitle:@"Zoom Out" + action:@selector(testZoomOut:) + keyEquivalent:@""]; + [testMenu addItemWithTitle:@"Zoom Reset" + action:@selector(testZoomReset:) + keyEquivalent:@""]; [testItem setSubmenu:testMenu]; [menubar addItem:testItem]; @@ -440,6 +452,28 @@ NSButton* MakeButton(NSRect* rect, NSString* title, NSView* parent) { RunDragDropTest(g_handler->GetBrowser()); } +- (IBAtion)testZoomIn:(id)sender { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + 0.5); + } +} + +- (IBAction)testZoomOut:(id)sender { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() - 0.5); + } +} + +- (IBAction)testZoomReset:(id)sender { + if (g_handler.get() && g_handler->GetBrowserId()) { + CefRefPtr browser = g_handler->GetBrowser(); + browser->GetHost()->SetZoomLevel(0.0); + } +} + + // Sent by the default notification center immediately before the application // terminates. - (void)applicationWillTerminate:(NSNotification *)aNotification { diff --git a/tests/cefclient/cefclient_win.cpp b/tests/cefclient/cefclient_win.cpp index a1dd1aec0..9e2a4427c 100644 --- a/tests/cefclient/cefclient_win.cpp +++ b/tests/cefclient/cefclient_win.cpp @@ -180,6 +180,16 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { return TRUE; } +// Change the zoom factor on the UI thread. +static void ModifyZoom(CefRefPtr browser, double delta) { + if (CefCurrentlyOn(TID_UI)) { + browser->GetHost()->SetZoomLevel( + browser->GetHost()->GetZoomLevel() + delta); + } else { + CefPostTask(TID_UI, NewCefRunnableFunction(ModifyZoom, browser, delta)); + } +} + // // FUNCTION: WndProc(HWND, UINT, WPARAM, LPARAM) // @@ -422,6 +432,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, if (browser.get()) RunGeolocationTest(browser); return 0; + case ID_TESTS_ZOOM_IN: + if (browser.get()) + ModifyZoom(browser, 0.5); + return 0; + case ID_TESTS_ZOOM_OUT: + if (browser.get()) + ModifyZoom(browser, -0.5); + return 0; + case ID_TESTS_ZOOM_RESET: + if (browser.get()) + browser->GetHost()->SetZoomLevel(0.0); + return 0; } break; } diff --git a/tests/cefclient/resource.h b/tests/cefclient/resource.h index 74c35fae8..dd6988e3b 100644 --- a/tests/cefclient/resource.h +++ b/tests/cefclient/resource.h @@ -41,6 +41,9 @@ #define ID_TESTS_DIALOGS 32774 #define ID_TESTS_PLUGIN_INFO 32775 #define ID_TESTS_DOM_ACCESS 32776 +#define ID_TESTS_ZOOM_IN 32777 +#define ID_TESTS_ZOOM_OUT 32778 +#define ID_TESTS_ZOOM_RESET 32779 #define IDC_STATIC -1 #define IDS_BINDING 1000 #define IDS_DIALOGS 1001