Add fullscreen API support (issue #562)

This commit is contained in:
Marshall Greenblatt 2015-06-04 18:33:24 -04:00
parent 85f83680d7
commit d820080479
17 changed files with 255 additions and 49 deletions

View File

@ -76,6 +76,17 @@ typedef struct _cef_display_handler_t {
void (CEF_CALLBACK *on_favicon_urlchange)(struct _cef_display_handler_t* self,
struct _cef_browser_t* browser, cef_string_list_t icon_urls);
///
// Called when web content in the page has toggled fullscreen mode. If
// |fullscreen| is true (1) the content will automatically be sized to fill
// the browser content area. If |fullscreen| is false (0) the content will
// automatically return to its original size and position. The client is
// responsible for resizing the browser if desired.
///
void (CEF_CALLBACK *on_fullscreen_mode_change)(
struct _cef_display_handler_t* self, struct _cef_browser_t* browser,
int fullscreen);
///
// Called when the browser is about to display a tooltip. |text| contains the
// text that will be displayed in the tooltip. To handle the display of the

View File

@ -71,6 +71,17 @@ class CefDisplayHandler : public virtual CefBase {
virtual void OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
const std::vector<CefString>& icon_urls) {}
///
// Called when web content in the page has toggled fullscreen mode. If
// |fullscreen| is true the content will automatically be sized to fill the
// browser content area. If |fullscreen| is false the content will
// automatically return to its original size and position. The client is
// responsible for resizing the browser if desired.
///
/*--cef()--*/
virtual void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
bool fullscreen) {}
///
// Called when the browser is about to display a tooltip. |text| contains the
// text that will be displayed in the tooltip. To handle the display of the

View File

@ -1012,11 +1012,6 @@ void CefBrowserHostImpl::AddWordToDictionary(const CefString& word) {
}
void CefBrowserHostImpl::WasResized() {
if (!IsWindowless()) {
NOTREACHED() << "Window rendering is not disabled";
return;
}
if (!CEF_CURRENTLY_ON_UIT()) {
CEF_POST_TASK(CEF_UIT, base::Bind(&CefBrowserHostImpl::WasResized, this));
return;
@ -1025,11 +1020,18 @@ void CefBrowserHostImpl::WasResized() {
if (!web_contents())
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
if (view)
view->WasResized();
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
if (!IsWindowless()) {
host->WasResized();
} else {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->WasResized();
}
}
void CefBrowserHostImpl::WasHidden(bool hidden) {
@ -1047,9 +1049,12 @@ void CefBrowserHostImpl::WasHidden(bool hidden) {
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view) {
if (hidden)
view->Hide();
@ -1073,9 +1078,12 @@ void CefBrowserHostImpl::NotifyScreenInfoChanged() {
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->OnScreenInfoChanged();
}
@ -1095,9 +1103,12 @@ void CefBrowserHostImpl::Invalidate(PaintElementType type) {
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->Invalidate(type);
}
@ -1109,20 +1120,21 @@ void CefBrowserHostImpl::SendKeyEvent(const CefKeyEvent& event) {
return;
}
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
content::NativeWebKeyboardEvent web_event;
PlatformTranslateKeyEvent(web_event, event);
if (!IsWindowless()) {
content::RenderWidgetHost* widget = web_contents()->GetRenderViewHost();
if (widget)
widget->ForwardKeyboardEvent(web_event);
host->ForwardKeyboardEvent(web_event);
} else {
if (!web_contents())
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->SendKeyEvent(web_event);
}
@ -1167,20 +1179,21 @@ void CefBrowserHostImpl::SendMouseWheelEvent(const CefMouseEvent& event,
return;
}
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
blink::WebMouseWheelEvent web_event;
PlatformTranslateWheelEvent(web_event, event, deltaX, deltaY);
if (!IsWindowless()) {
content::RenderWidgetHost* widget = web_contents()->GetRenderViewHost();
if (widget)
widget->ForwardWheelEvent(web_event);
host->ForwardWheelEvent(web_event);
} else {
if (!web_contents())
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->SendMouseWheelEvent(web_event);
}
@ -1217,17 +1230,18 @@ int CefBrowserHostImpl::TranslateModifiers(uint32 cef_modifiers) {
}
void CefBrowserHostImpl::SendMouseEvent(const blink::WebMouseEvent& event) {
if (!IsWindowless()) {
content::RenderWidgetHost* widget = web_contents()->GetRenderViewHost();
if (widget)
widget->ForwardMouseEvent(event);
} else {
if (!web_contents())
return;
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
if (!IsWindowless()) {
host->ForwardMouseEvent(event);
} else {
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->SendMouseEvent(event);
}
@ -1246,9 +1260,12 @@ void CefBrowserHostImpl::SendFocusEvent(bool setFocus) {
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->SendFocusEvent(setFocus);
}
@ -1281,9 +1298,9 @@ void CefBrowserHostImpl::NotifyMoveOrResizeStarted() {
return;
// Dismiss any existing popups.
content::RenderViewHost* rvh = web_contents()->GetRenderViewHost();
if (rvh)
rvh->NotifyMoveOrResizeStarted();
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (host)
host->NotifyMoveOrResizeStarted();
PlatformNotifyMoveOrResizeStarted();
}
@ -1315,9 +1332,12 @@ void CefBrowserHostImpl::SetWindowlessFrameRate(int frame_rate) {
if (!web_contents())
return;
content::RenderViewHost* host = web_contents()->GetRenderViewHost();
if (!host)
return;
CefRenderWidgetHostViewOSR* view =
static_cast<CefRenderWidgetHostViewOSR*>(
web_contents()->GetRenderViewHost()->GetView());
static_cast<CefRenderWidgetHostViewOSR*>(host->GetView());
if (view)
view->UpdateFrameRate();
}
@ -1871,6 +1891,28 @@ void CefBrowserHostImpl::RunFileChooser(
callback));
}
void CefBrowserHostImpl::EnterFullscreenModeForTab(
content::WebContents* web_contents,
const GURL& origin) {
OnFullscreenModeChange(true);
}
void CefBrowserHostImpl::ExitFullscreenModeForTab(
content::WebContents* web_contents) {
OnFullscreenModeChange(false);
}
bool CefBrowserHostImpl::IsFullscreenForTabOrPending(
const content::WebContents* web_contents) const {
return is_fullscreen_;
}
blink::WebDisplayMode CefBrowserHostImpl::GetDisplayMode(
const content::WebContents* web_contents) const {
return is_fullscreen_ ? blink::WebDisplayModeFullscreen :
blink::WebDisplayModeBrowser;
}
void CefBrowserHostImpl::FindReply(
content::WebContents* web_contents,
int request_id,
@ -2860,6 +2902,7 @@ CefBrowserHostImpl::CefBrowserHostImpl(
can_go_back_(false),
can_go_forward_(false),
has_document_(false),
is_fullscreen_(false),
queue_messages_(true),
main_frame_id_(CefFrameHostImpl::kInvalidFrameId),
focused_frame_id_(CefFrameHostImpl::kInvalidFrameId),
@ -3062,6 +3105,20 @@ void CefBrowserHostImpl::OnLoadEnd(CefRefPtr<CefFrame> frame,
}
}
void CefBrowserHostImpl::OnFullscreenModeChange(bool fullscreen) {
if (is_fullscreen_ == fullscreen)
return;
is_fullscreen_ = fullscreen;
WasResized();
if (client_.get()) {
CefRefPtr<CefDisplayHandler> handler = client_->GetDisplayHandler();
if (handler.get())
handler->OnFullscreenModeChange(this, fullscreen);
}
}
void CefBrowserHostImpl::RunFileChooserOnUIThread(
const FileChooserParams& params,
const RunFileChooserCallback& callback) {

View File

@ -405,6 +405,13 @@ class CefBrowserHostImpl : public CefBrowserHost,
void RunFileChooser(
content::WebContents* web_contents,
const content::FileChooserParams& params) override;
void EnterFullscreenModeForTab(content::WebContents* web_contents,
const GURL& origin) override;
void ExitFullscreenModeForTab(content::WebContents* web_contents) override;
bool IsFullscreenForTabOrPending(
const content::WebContents* web_contents) const override;
blink::WebDisplayMode GetDisplayMode(
const content::WebContents* web_contents) const override;
void FindReply(
content::WebContents* web_contents,
int request_id,
@ -413,7 +420,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
int active_match_ordinal,
bool final_update) override;
void UpdatePreferredSize(content::WebContents* source,
const gfx::Size& pref_size) override;
const gfx::Size& pref_size) override;
void RequestMediaAccessPermission(
content::WebContents* web_contents,
const content::MediaStreamRequest& request,
@ -575,6 +582,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
void OnLoadEnd(CefRefPtr<CefFrame> frame,
const GURL& url,
int http_status_code);
void OnFullscreenModeChange(bool fullscreen);
// Continuation from RunFileChooser.
void RunFileChooserOnUIThread(const FileChooserParams& params,
@ -621,6 +629,7 @@ class CefBrowserHostImpl : public CefBrowserHost,
bool can_go_back_;
bool can_go_forward_;
bool has_document_;
bool is_fullscreen_;
// Messages we queue while waiting for the RenderView to be ready. We queue
// them here instead of in the RenderProcessHost to ensure that they're sent

View File

@ -92,6 +92,25 @@ void CEF_CALLBACK display_handler_on_favicon_urlchange(
icon_urlsList);
}
void CEF_CALLBACK display_handler_on_fullscreen_mode_change(
struct _cef_display_handler_t* self, cef_browser_t* browser,
int fullscreen) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
DCHECK(self);
if (!self)
return;
// Verify param: browser; type: refptr_diff
DCHECK(browser);
if (!browser)
return;
// Execute
CefDisplayHandlerCppToC::Get(self)->OnFullscreenModeChange(
CefBrowserCToCpp::Wrap(browser),
fullscreen?true:false);
}
int CEF_CALLBACK display_handler_on_tooltip(struct _cef_display_handler_t* self,
cef_browser_t* browser, cef_string_t* text) {
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
@ -171,6 +190,8 @@ CefDisplayHandlerCppToC::CefDisplayHandlerCppToC() {
GetStruct()->on_address_change = display_handler_on_address_change;
GetStruct()->on_title_change = display_handler_on_title_change;
GetStruct()->on_favicon_urlchange = display_handler_on_favicon_urlchange;
GetStruct()->on_fullscreen_mode_change =
display_handler_on_fullscreen_mode_change;
GetStruct()->on_tooltip = display_handler_on_tooltip;
GetStruct()->on_status_message = display_handler_on_status_message;
GetStruct()->on_console_message = display_handler_on_console_message;

View File

@ -96,6 +96,25 @@ void CefDisplayHandlerCToCpp::OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
cef_string_list_free(icon_urlsList);
}
void CefDisplayHandlerCToCpp::OnFullscreenModeChange(
CefRefPtr<CefBrowser> browser, bool fullscreen) {
cef_display_handler_t* _struct = GetStruct();
if (CEF_MEMBER_MISSING(_struct, on_fullscreen_mode_change))
return;
// AUTO-GENERATED CONTENT - DELETE THIS COMMENT BEFORE MODIFYING
// Verify param: browser; type: refptr_diff
DCHECK(browser.get());
if (!browser.get())
return;
// Execute
_struct->on_fullscreen_mode_change(_struct,
CefBrowserCppToC::Wrap(browser),
fullscreen);
}
bool CefDisplayHandlerCToCpp::OnTooltip(CefRefPtr<CefBrowser> browser,
CefString& text) {
cef_display_handler_t* _struct = GetStruct();

View File

@ -38,6 +38,8 @@ class CefDisplayHandlerCToCpp
const CefString& title) override;
void OnFaviconURLChange(CefRefPtr<CefBrowser> browser,
const std::vector<CefString>& icon_urls) override;
void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
bool fullscreen) override;
bool OnTooltip(CefRefPtr<CefBrowser> browser, CefString& text) override;
void OnStatusMessage(CefRefPtr<CefBrowser> browser,
const CefString& value) override;

View File

@ -61,6 +61,11 @@ void BrowserWindow::OnSetTitle(const std::string& title) {
delegate_->OnSetTitle(title);
}
void BrowserWindow::OnSetFullscreen(bool fullscreen) {
REQUIRE_MAIN_THREAD();
delegate_->OnSetFullscreen(fullscreen);
}
void BrowserWindow::OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {

View File

@ -34,6 +34,9 @@ class BrowserWindow : public ClientHandler::Delegate {
// Set the window title.
virtual void OnSetTitle(const std::string& title) = 0;
// Set fullscreen mode.
virtual void OnSetFullscreen(bool fullscreen) = 0;
// Set the loading state.
virtual void OnSetLoadingState(bool isLoading,
bool canGoBack,
@ -102,6 +105,7 @@ class BrowserWindow : public ClientHandler::Delegate {
void OnBrowserClosed(CefRefPtr<CefBrowser> browser) OVERRIDE;
void OnSetAddress(const std::string& url) OVERRIDE;
void OnSetTitle(const std::string& title) OVERRIDE;
void OnSetFullscreen(bool fullscreen) OVERRIDE;
void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;

View File

@ -230,6 +230,13 @@ void ClientHandler::OnTitleChange(CefRefPtr<CefBrowser> browser,
NotifyTitle(title);
}
void ClientHandler::OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
bool fullscreen) {
CEF_REQUIRE_UI_THREAD();
NotifyFullscreen(fullscreen);
}
bool ClientHandler::OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
@ -683,6 +690,18 @@ void ClientHandler::NotifyTitle(const CefString& title) {
delegate_->OnSetTitle(title);
}
void ClientHandler::NotifyFullscreen(bool fullscreen) {
if (!CURRENTLY_ON_MAIN_THREAD()) {
// Execute this method on the main thread.
MAIN_POST_CLOSURE(
base::Bind(&ClientHandler::NotifyFullscreen, this, fullscreen));
return;
}
if (delegate_)
delegate_->OnSetFullscreen(fullscreen);
}
void ClientHandler::NotifyLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {

View File

@ -53,6 +53,9 @@ class ClientHandler : public CefClient,
// Set the window title.
virtual void OnSetTitle(const std::string& title) = 0;
// Set fullscreen mode.
virtual void OnSetFullscreen(bool fullscreen) = 0;
// Set the loading state.
virtual void OnSetLoadingState(bool isLoading,
bool canGoBack,
@ -136,6 +139,8 @@ class ClientHandler : public CefClient,
const CefString& url) OVERRIDE;
void OnTitleChange(CefRefPtr<CefBrowser> browser,
const CefString& title) OVERRIDE;
void OnFullscreenModeChange(CefRefPtr<CefBrowser> browser,
bool fullscreen) OVERRIDE;
bool OnConsoleMessage(CefRefPtr<CefBrowser> browser,
const CefString& message,
const CefString& source,
@ -274,6 +279,7 @@ class ClientHandler : public CefClient,
void NotifyBrowserClosed(CefRefPtr<CefBrowser> browser);
void NotifyAddress(const CefString& url);
void NotifyTitle(const CefString& title);
void NotifyFullscreen(bool fullscreen);
void NotifyLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward);

View File

@ -19,6 +19,7 @@
#include "cefclient/browser/main_message_loop.h"
#include "cefclient/browser/resource.h"
#include "cefclient/browser/temp_window.h"
#include "cefclient/browser/window_test.h"
#include "cefclient/common/client_switches.h"
namespace client {
@ -374,6 +375,18 @@ void RootWindowGtk::OnSetTitle(const std::string& title) {
}
}
void RootWindowGtk::OnSetFullscreen(bool fullscreen) {
REQUIRE_MAIN_THREAD();
CefRefPtr<CefBrowser> browser = GetBrowser();
if (browser) {
if (fullscreen)
window_test::Maximize(browser);
else
window_test::Restore(browser);
}
}
void RootWindowGtk::OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {

View File

@ -55,6 +55,7 @@ class RootWindowGtk : public RootWindow,
void OnBrowserWindowDestroyed() OVERRIDE;
void OnSetAddress(const std::string& url) OVERRIDE;
void OnSetTitle(const std::string& title) OVERRIDE;
void OnSetFullscreen(bool fullscreen) OVERRIDE;
void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;

View File

@ -61,6 +61,7 @@ class RootWindowMac : public RootWindow,
void OnBrowserWindowDestroyed() OVERRIDE;
void OnSetAddress(const std::string& url) OVERRIDE;
void OnSetTitle(const std::string& title) OVERRIDE;
void OnSetFullscreen(bool fullscreen) OVERRIDE;
void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;

View File

@ -12,6 +12,7 @@
#include "cefclient/browser/main_context.h"
#include "cefclient/browser/main_message_loop.h"
#include "cefclient/browser/temp_window.h"
#include "cefclient/browser/window_test.h"
#include "cefclient/common/client_switches.h"
// Receives notifications from controls and the browser window. Will delete
@ -592,6 +593,18 @@ void RootWindowMac::OnSetTitle(const std::string& title) {
}
}
void RootWindowMac::OnSetFullscreen(bool fullscreen) {
REQUIRE_MAIN_THREAD();
CefRefPtr<CefBrowser> browser = GetBrowser();
if (browser) {
if (fullscreen)
window_test::Maximize(browser);
else
window_test::Restore(browser);
}
}
void RootWindowMac::OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {

View File

@ -14,6 +14,7 @@
#include "cefclient/browser/resource.h"
#include "cefclient/browser/temp_window.h"
#include "cefclient/browser/util_win.h"
#include "cefclient/browser/window_test.h"
#include "cefclient/common/client_switches.h"
#define MAX_URL_LENGTH 255
@ -772,6 +773,18 @@ void RootWindowWin::OnSetTitle(const std::string& title) {
SetWindowText(hwnd_, CefString(title).ToWString().c_str());
}
void RootWindowWin::OnSetFullscreen(bool fullscreen) {
REQUIRE_MAIN_THREAD();
CefRefPtr<CefBrowser> browser = GetBrowser();
if (browser) {
if (fullscreen)
window_test::Maximize(browser);
else
window_test::Restore(browser);
}
}
void RootWindowWin::OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) {

View File

@ -87,6 +87,7 @@ class RootWindowWin : public RootWindow,
void OnBrowserWindowDestroyed() OVERRIDE;
void OnSetAddress(const std::string& url) OVERRIDE;
void OnSetTitle(const std::string& title) OVERRIDE;
void OnSetFullscreen(bool fullscreen) OVERRIDE;
void OnSetLoadingState(bool isLoading,
bool canGoBack,
bool canGoForward) OVERRIDE;