Add zoom support (issue #514).

git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@695 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
Marshall Greenblatt 2012-06-12 19:50:24 +00:00
parent 85bf734046
commit fd5c3c0d75
12 changed files with 208 additions and 1 deletions

View File

@ -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;

View File

@ -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_

View File

@ -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.
// -----------------------------------------------------------------------------

View File

@ -105,6 +105,8 @@ class CefBrowserHostImpl : public CefBrowserHost,
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE;
virtual double GetZoomLevel() OVERRIDE;
virtual void SetZoomLevel(double zoomLevel) OVERRIDE;
// CefBrowser methods.
virtual CefRefPtr<CefBrowserHost> GetHost() OVERRIDE;

View File

@ -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

View File

@ -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<CefBrowserHostCToCpp, CefBrowserHost,

View File

@ -44,6 +44,8 @@ class CefBrowserHostCToCpp
virtual CefWindowHandle GetOpenerWindowHandle() OVERRIDE;
virtual CefRefPtr<CefClient> GetClient() OVERRIDE;
virtual CefString GetDevToolsURL(bool http_scheme) OVERRIDE;
virtual double GetZoomLevel() OVERRIDE;
virtual void SetZoomLevel(double zoomLevel) OVERRIDE;
};
#endif // USING_CEF_SHARED

View File

@ -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

View File

@ -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<CefBrowser> 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<CefBrowser> 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<CefBrowser> 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;
}

View File

@ -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<CefBrowser> browser = g_handler->GetBrowser();
browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() + 0.5);
}
}
- (IBAction)testZoomOut:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->GetHost()->SetZoomLevel(browser->GetHost()->GetZoomLevel() - 0.5);
}
}
- (IBAction)testZoomReset:(id)sender {
if (g_handler.get() && g_handler->GetBrowserId()) {
CefRefPtr<CefBrowser> browser = g_handler->GetBrowser();
browser->GetHost()->SetZoomLevel(0.0);
}
}
// Sent by the default notification center immediately before the application
// terminates.
- (void)applicationWillTerminate:(NSNotification *)aNotification {

View File

@ -180,6 +180,16 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) {
return TRUE;
}
// Change the zoom factor on the UI thread.
static 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));
}
}
//
// 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;
}

View File

@ -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