mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-02-02 12:17:15 +01:00
Add zoom support (issue #116).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@167 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
parent
8420cbbff1
commit
c9b8e88dd9
2
cef.gyp
2
cef.gyp
@ -502,6 +502,8 @@
|
||||
'libcef/browser_webkit_init.h',
|
||||
'libcef/browser_webview_delegate.cc',
|
||||
'libcef/browser_webview_delegate.h',
|
||||
'libcef/browser_zoom_map.cc',
|
||||
'libcef/browser_zoom_map.h',
|
||||
'libcef/cef_context.cc',
|
||||
'libcef/cef_context.h',
|
||||
'libcef/cef_process.cc',
|
||||
|
@ -433,6 +433,14 @@ public:
|
||||
// Cancel all searches that are currently going on.
|
||||
/*--cef()--*/
|
||||
virtual void StopFinding(bool clearSelection) =0;
|
||||
|
||||
// Get the zoom level.
|
||||
/*--cef()--*/
|
||||
virtual double GetZoomLevel() =0;
|
||||
|
||||
// Change the zoom level to the specified value.
|
||||
/*--cef()--*/
|
||||
virtual void SetZoomLevel(double zoomLevel) =0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -256,6 +256,13 @@ typedef struct _cef_browser_t
|
||||
void (CEF_CALLBACK *stop_finding)(struct _cef_browser_t* self,
|
||||
int clearSelection);
|
||||
|
||||
// Get the zoom level.
|
||||
double (CEF_CALLBACK *get_zoom_level)(struct _cef_browser_t* self);
|
||||
|
||||
// Change the zoom level to the specified value.
|
||||
void (CEF_CALLBACK *set_zoom_level)(struct _cef_browser_t* self,
|
||||
double zoomLevel);
|
||||
|
||||
} cef_browser_t;
|
||||
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include "cef_context.h"
|
||||
#include "browser_impl.h"
|
||||
#include "browser_webkit_glue.h"
|
||||
#include "browser_zoom_map.h"
|
||||
#include "request_impl.h"
|
||||
#include "stream_impl.h"
|
||||
|
||||
@ -478,6 +479,24 @@ CefString CefBrowserImpl::GetURL(CefRefPtr<CefFrame> frame)
|
||||
return CefString();
|
||||
}
|
||||
|
||||
double CefBrowserImpl::GetZoomLevel()
|
||||
{
|
||||
WebKit::WebFrame* web_frame = GetWebFrame(this->GetMainFrame());
|
||||
|
||||
if(web_frame && web_frame->view())
|
||||
return web_frame->view()->zoomLevel();
|
||||
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
void CefBrowserImpl::SetZoomLevel(double zoomLevel)
|
||||
{
|
||||
CefRefPtr<CefFrame> frame = this->GetMainFrame();
|
||||
frame->AddRef();
|
||||
CefThread::PostTask(CefThread::UI, FROM_HERE, NewRunnableMethod(this,
|
||||
&CefBrowserImpl::UIT_SetZoomLevel, frame.get(), zoomLevel));
|
||||
}
|
||||
|
||||
// static
|
||||
bool CefBrowser::CreateBrowser(CefWindowInfo& windowInfo, bool popup,
|
||||
CefRefPtr<CefHandler> handler,
|
||||
@ -1139,6 +1158,18 @@ void CefBrowserImpl::UIT_NotifyFindStatus(int identifier, int count,
|
||||
}
|
||||
}
|
||||
|
||||
void CefBrowserImpl::UIT_SetZoomLevel(CefFrame* frame, double zoomLevel)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
WebKit::WebFrame* web_frame = GetWebFrame(frame);
|
||||
|
||||
if(web_frame && web_frame->view()) {
|
||||
web_frame->view()->setZoomLevel(false, zoomLevel);
|
||||
ZoomMap::GetInstance()->set(web_frame->url(), zoomLevel);
|
||||
}
|
||||
|
||||
frame->Release();
|
||||
}
|
||||
|
||||
// CefFrameImpl
|
||||
|
||||
|
@ -63,7 +63,9 @@ public:
|
||||
virtual void Find(int identifier, const CefString& searchText,
|
||||
bool forward, bool matchCase, bool findNext);
|
||||
virtual void StopFinding(bool clearSelection);
|
||||
|
||||
virtual double GetZoomLevel();
|
||||
virtual void SetZoomLevel(double zoomLevel);
|
||||
|
||||
// CefFrames are light-weight objects managed by the browser and loosely
|
||||
// coupled to a WebFrame object by name. If a CefFrame object does not
|
||||
// already exist for the specified WebFrame one will be created. There is no
|
||||
@ -229,6 +231,7 @@ public:
|
||||
void UIT_NotifyFindStatus(int identifier, int count,
|
||||
const WebKit::WebRect& selection_rect,
|
||||
int active_match_ordinal, bool final_update);
|
||||
void UIT_SetZoomLevel(CefFrame* frame, double zoomLevel);
|
||||
|
||||
static bool ImplementsThreadSafeReferenceCounting() { return true; }
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
#include "browser_impl.h"
|
||||
#include "browser_navigation_controller.h"
|
||||
#include "browser_web_worker.h"
|
||||
#include "browser_zoom_map.h"
|
||||
#include "cef_context.h"
|
||||
#include "request_impl.h"
|
||||
#include "v8_impl.h"
|
||||
@ -723,6 +724,16 @@ void BrowserWebViewDelegate::didCommitProvisionalLoad(
|
||||
(frame == top_loading_frame_) ? NULL : browser_->GetCefFrame(frame),
|
||||
is_main_content_);
|
||||
}
|
||||
|
||||
// Apply zoom settings only on top-level frames.
|
||||
if(frame->parent() == NULL) {
|
||||
// Restore the zoom value that we have for this URL, if any.
|
||||
double zoomLevel;
|
||||
if(ZoomMap::GetInstance()->get(frame->url(), zoomLevel))
|
||||
frame->view()->setZoomLevel(false, zoomLevel);
|
||||
else
|
||||
frame->view()->setZoomLevel(false, 0.0);
|
||||
}
|
||||
}
|
||||
|
||||
void BrowserWebViewDelegate::didClearWindowObject(WebFrame* frame) {
|
||||
|
38
libcef/browser_zoom_map.cc
Normal file
38
libcef/browser_zoom_map.cc
Normal file
@ -0,0 +1,38 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#include "browser_zoom_map.h"
|
||||
#include "cef_thread.h"
|
||||
|
||||
ZoomMap* ZoomMap::GetInstance()
|
||||
{
|
||||
return Singleton<ZoomMap>::get();
|
||||
}
|
||||
|
||||
void ZoomMap::set(const GURL& url, double zoomLevel)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
if (zoomLevel == 0.) {
|
||||
// Remove the entry for this host.
|
||||
Map::iterator iter = map_.find(url.host());
|
||||
if (iter != map_.end())
|
||||
map_.erase(iter);
|
||||
} else {
|
||||
// Update the entry for this host.
|
||||
map_[url.host()] = zoomLevel;
|
||||
}
|
||||
}
|
||||
|
||||
bool ZoomMap::get(const GURL& url, double& zoomLevel)
|
||||
{
|
||||
REQUIRE_UIT();
|
||||
|
||||
Map::const_iterator iter = map_.find(url.host());
|
||||
if (iter == map_.end())
|
||||
return false;
|
||||
|
||||
zoomLevel = iter->second;
|
||||
return true;
|
||||
}
|
43
libcef/browser_zoom_map.h
Normal file
43
libcef/browser_zoom_map.h
Normal file
@ -0,0 +1,43 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that can
|
||||
// be found in the LICENSE file.
|
||||
|
||||
#ifndef _BROWSER_ZOOM_MAP_H
|
||||
#define _BROWSER_ZOOM_MAP_H
|
||||
|
||||
#include "include/cef_string.h"
|
||||
#include "base/singleton.h"
|
||||
#include "googleurl/src/gurl.h"
|
||||
|
||||
#include <map>
|
||||
#include <string>
|
||||
|
||||
// Maps the host/domain of a URL to a zoom value.
|
||||
// NOTE: This class is not thread-safe. It is assumed that the methods will be
|
||||
// called from the UI thread.
|
||||
class ZoomMap
|
||||
{
|
||||
public:
|
||||
// Returns the static ZoomMap instance.
|
||||
static ZoomMap* GetInstance();
|
||||
|
||||
// Store |zoomLevel| with key |url|.
|
||||
void set(const GURL& url, double zoomLevel);
|
||||
|
||||
// Returns true if there is a |zoomLevel| keyed with |url|, false otherwise.
|
||||
// |zoomLevel| is the "out" variable.
|
||||
bool get(const GURL& url, double& zoomLevel);
|
||||
|
||||
private:
|
||||
typedef std::map<std::string, double> Map;
|
||||
Map map_;
|
||||
|
||||
friend struct DefaultSingletonTraits<ZoomMap>;
|
||||
|
||||
ZoomMap() {}
|
||||
virtual ~ZoomMap() {}
|
||||
|
||||
DISALLOW_COPY_AND_ASSIGN(ZoomMap);
|
||||
};
|
||||
|
||||
#endif // _BROWSER_ZOOM_MAP_H
|
@ -238,6 +238,25 @@ void CEF_CALLBACK browser_stop_finding(struct _cef_browser_t* self,
|
||||
CefBrowserCppToC::Get(self)->StopFinding(clearSelection?true:false);
|
||||
}
|
||||
|
||||
double CEF_CALLBACK browser_get_zoom_level(struct _cef_browser_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
return 0.0;
|
||||
|
||||
return CefBrowserCppToC::Get(self)->GetZoomLevel();
|
||||
}
|
||||
|
||||
void CEF_CALLBACK browser_set_zoom_level(struct _cef_browser_t* self,
|
||||
double zoomLevel)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
return;
|
||||
|
||||
return CefBrowserCppToC::Get(self)->SetZoomLevel(zoomLevel);
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
@ -261,6 +280,8 @@ CefBrowserCppToC::CefBrowserCppToC(CefBrowser* cls)
|
||||
struct_.struct_.get_frame_names = browser_get_frame_names;
|
||||
struct_.struct_.find = browser_find;
|
||||
struct_.struct_.stop_finding = browser_stop_finding;
|
||||
struct_.struct_.get_zoom_level = browser_get_zoom_level;
|
||||
struct_.struct_.set_zoom_level = browser_set_zoom_level;
|
||||
}
|
||||
|
||||
#ifdef _DEBUG
|
||||
|
@ -196,6 +196,22 @@ void CefBrowserCToCpp::StopFinding(bool clearSelection)
|
||||
struct_->stop_finding(struct_, clearSelection);
|
||||
}
|
||||
|
||||
double CefBrowserCToCpp::GetZoomLevel()
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, get_zoom_level))
|
||||
return 0.0;
|
||||
|
||||
return struct_->get_zoom_level(struct_);
|
||||
}
|
||||
|
||||
void CefBrowserCToCpp::SetZoomLevel(double zoomLevel)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, set_zoom_level))
|
||||
return;
|
||||
|
||||
return struct_->set_zoom_level(struct_, zoomLevel);
|
||||
}
|
||||
|
||||
|
||||
#ifdef _DEBUG
|
||||
template<> long CefCToCpp<CefBrowserCToCpp, CefBrowser,
|
||||
|
@ -49,6 +49,8 @@ public:
|
||||
virtual void Find(int identifier, const CefString& searchText, bool forward,
|
||||
bool matchCase, bool findNext);
|
||||
virtual void StopFinding(bool clearSelection);
|
||||
virtual double GetZoomLevel();
|
||||
virtual void SetZoomLevel(double zoomLevel);
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
|
@ -81,6 +81,9 @@ BEGIN
|
||||
MENUITEM "Accelerated Layers", ID_TESTS_ACCELERATEDLAYERS
|
||||
MENUITEM "WebGL", ID_TESTS_WEBGL
|
||||
MENUITEM "HTML5 Video", ID_TESTS_HTML5VIDEO
|
||||
MENUITEM "Zoom In", ID_TESTS_ZOOM_IN
|
||||
MENUITEM "Zoom Out", ID_TESTS_ZOOM_OUT
|
||||
MENUITEM "Reset Zoom", ID_TESTS_ZOOM_RESET
|
||||
END
|
||||
END
|
||||
|
||||
|
@ -573,6 +573,18 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
if(browser.get())
|
||||
RunXMLHTTPRequestTest(browser);
|
||||
return 0;
|
||||
case ID_TESTS_ZOOM_IN:
|
||||
if(browser.get())
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() + 0.5);
|
||||
return 0;
|
||||
case ID_TESTS_ZOOM_OUT:
|
||||
if(browser.get())
|
||||
browser->SetZoomLevel(browser->GetZoomLevel() - 0.5);
|
||||
return 0;
|
||||
case ID_TESTS_ZOOM_RESET:
|
||||
if(browser.get())
|
||||
browser->SetZoomLevel(0.0);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -42,6 +42,9 @@
|
||||
#define ID_TESTS_WEBGL 32782
|
||||
#define ID_TESTS_HTML5VIDEO 32783
|
||||
#define ID_TESTS_XMLHTTPREQUEST 32784
|
||||
#define ID_TESTS_ZOOM_IN 32785
|
||||
#define ID_TESTS_ZOOM_OUT 32786
|
||||
#define ID_TESTS_ZOOM_RESET 32787
|
||||
#define IDC_STATIC -1
|
||||
#define IDS_LOGO 1000
|
||||
#define IDS_UIPLUGIN 1001
|
||||
@ -58,7 +61,7 @@
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NO_MFC 1
|
||||
#define _APS_NEXT_RESOURCE_VALUE 130
|
||||
#define _APS_NEXT_COMMAND_VALUE 32773
|
||||
#define _APS_NEXT_COMMAND_VALUE 32788
|
||||
#define _APS_NEXT_CONTROL_VALUE 1000
|
||||
#define _APS_NEXT_SYMED_VALUE 110
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user