Implement HTML5 fullscreen in CommonWebContentsDelegate
This commit is contained in:
parent
05468cc3fa
commit
8f9a109fa6
6 changed files with 72 additions and 86 deletions
|
@ -223,32 +223,13 @@ void WebContents::HandleKeyboardEvent(
|
||||||
|
|
||||||
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
const GURL& origin) {
|
const GURL& origin) {
|
||||||
auto window = GetWindowFromGuest(source);
|
CommonWebContentsDelegate::EnterFullscreenModeForTab(source, origin);
|
||||||
if (window) {
|
Emit("enter-html-full-screen");
|
||||||
window->SetHtmlApiFullscreen(true);
|
|
||||||
window->NotifyWindowEnterHtmlFullScreen();
|
|
||||||
source->GetRenderViewHost()->WasResized();
|
|
||||||
Emit("enter-html-full-screen");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
|
||||||
auto window = GetWindowFromGuest(source);
|
CommonWebContentsDelegate::ExitFullscreenModeForTab(source);
|
||||||
if (window) {
|
Emit("leave-html-full-screen");
|
||||||
window->SetHtmlApiFullscreen(false);
|
|
||||||
window->NotifyWindowLeaveHtmlFullScreen();
|
|
||||||
source->GetRenderViewHost()->WasResized();
|
|
||||||
Emit("leave-html-full-screen");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool WebContents::IsFullscreenForTabOrPending(
|
|
||||||
const content::WebContents* source) const {
|
|
||||||
auto window = GetWindowFromGuest(source);
|
|
||||||
if (window)
|
|
||||||
return window->is_html_api_fullscreen();
|
|
||||||
else
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
|
||||||
|
|
|
@ -158,8 +158,6 @@ class WebContents : public mate::EventEmitter,
|
||||||
void EnterFullscreenModeForTab(content::WebContents* source,
|
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
const GURL& origin) override;
|
const GURL& origin) override;
|
||||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||||
bool IsFullscreenForTabOrPending(
|
|
||||||
const content::WebContents* source) const override;
|
|
||||||
|
|
||||||
// content::WebContentsObserver:
|
// content::WebContentsObserver:
|
||||||
void RenderViewDeleted(content::RenderViewHost*) override;
|
void RenderViewDeleted(content::RenderViewHost*) override;
|
||||||
|
|
|
@ -87,7 +87,9 @@ base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) {
|
||||||
|
|
||||||
CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest)
|
CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest)
|
||||||
: is_guest_(is_guest),
|
: is_guest_(is_guest),
|
||||||
owner_window_(nullptr) {
|
owner_window_(nullptr),
|
||||||
|
html_fullscreen_(false),
|
||||||
|
native_fullscreen_(false) {
|
||||||
}
|
}
|
||||||
|
|
||||||
CommonWebContentsDelegate::~CommonWebContentsDelegate() {
|
CommonWebContentsDelegate::~CommonWebContentsDelegate() {
|
||||||
|
@ -108,6 +110,19 @@ void CommonWebContentsDelegate::DestroyWebContents() {
|
||||||
web_contents_.reset();
|
web_contents_.reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
|
||||||
|
if (!web_contents_)
|
||||||
|
return nullptr;
|
||||||
|
return web_contents_->GetWebContents();
|
||||||
|
}
|
||||||
|
|
||||||
|
content::WebContents*
|
||||||
|
CommonWebContentsDelegate::GetDevToolsWebContents() const {
|
||||||
|
if (!web_contents_)
|
||||||
|
return nullptr;
|
||||||
|
return web_contents_->GetDevToolsWebContents();
|
||||||
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::RequestToLockMouse(
|
void CommonWebContentsDelegate::RequestToLockMouse(
|
||||||
content::WebContents* web_contents,
|
content::WebContents* web_contents,
|
||||||
bool user_gesture,
|
bool user_gesture,
|
||||||
|
@ -156,17 +171,27 @@ void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest,
|
||||||
web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
|
web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
|
void CommonWebContentsDelegate::EnterFullscreenModeForTab(
|
||||||
if (!web_contents_)
|
content::WebContents* source, const GURL& origin) {
|
||||||
return nullptr;
|
if (!owner_window_)
|
||||||
return web_contents_->GetWebContents();
|
return;
|
||||||
|
SetHtmlApiFullscreen(true);
|
||||||
|
owner_window_->NotifyWindowEnterHtmlFullScreen();
|
||||||
|
source->GetRenderViewHost()->WasResized();
|
||||||
}
|
}
|
||||||
|
|
||||||
content::WebContents*
|
void CommonWebContentsDelegate::ExitFullscreenModeForTab(
|
||||||
CommonWebContentsDelegate::GetDevToolsWebContents() const {
|
content::WebContents* source) {
|
||||||
if (!web_contents_)
|
if (!owner_window_)
|
||||||
return nullptr;
|
return;
|
||||||
return web_contents_->GetDevToolsWebContents();
|
SetHtmlApiFullscreen(false);
|
||||||
|
owner_window_->NotifyWindowLeaveHtmlFullScreen();
|
||||||
|
source->GetRenderViewHost()->WasResized();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CommonWebContentsDelegate::IsFullscreenForTabOrPending(
|
||||||
|
const content::WebContents* source) const {
|
||||||
|
return html_fullscreen_;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommonWebContentsDelegate::DevToolsSaveToFile(
|
void CommonWebContentsDelegate::DevToolsSaveToFile(
|
||||||
|
@ -269,4 +294,23 @@ void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
|
||||||
nullptr);
|
nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CommonWebContentsDelegate::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
||||||
|
// Window is already in fullscreen mode, save the state.
|
||||||
|
if (enter_fullscreen && owner_window_->IsFullscreen()) {
|
||||||
|
native_fullscreen_ = true;
|
||||||
|
html_fullscreen_ = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Exit html fullscreen state but not window's fullscreen mode.
|
||||||
|
if (!enter_fullscreen && native_fullscreen_) {
|
||||||
|
html_fullscreen_ = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
owner_window_->SetFullScreen(enter_fullscreen);
|
||||||
|
html_fullscreen_ = enter_fullscreen;
|
||||||
|
native_fullscreen_ = false;
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -64,6 +64,11 @@ class CommonWebContentsDelegate
|
||||||
void EnumerateDirectory(content::WebContents* web_contents,
|
void EnumerateDirectory(content::WebContents* web_contents,
|
||||||
int request_id,
|
int request_id,
|
||||||
const base::FilePath& path) override;
|
const base::FilePath& path) override;
|
||||||
|
void EnterFullscreenModeForTab(content::WebContents* source,
|
||||||
|
const GURL& origin) override;
|
||||||
|
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
||||||
|
bool IsFullscreenForTabOrPending(
|
||||||
|
const content::WebContents* source) const override;
|
||||||
|
|
||||||
// brightray::InspectableWebContentsDelegate:
|
// brightray::InspectableWebContentsDelegate:
|
||||||
void DevToolsSaveToFile(const std::string& url,
|
void DevToolsSaveToFile(const std::string& url,
|
||||||
|
@ -75,12 +80,21 @@ class CommonWebContentsDelegate
|
||||||
void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
|
void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// Set fullscreen mode triggered by html api.
|
||||||
|
void SetHtmlApiFullscreen(bool enter_fullscreen);
|
||||||
|
|
||||||
// Whether this is guest WebContents or NativeWindow.
|
// Whether this is guest WebContents or NativeWindow.
|
||||||
const bool is_guest_;
|
const bool is_guest_;
|
||||||
|
|
||||||
// The window that this WebContents belongs to.
|
// The window that this WebContents belongs to.
|
||||||
NativeWindow* owner_window_;
|
NativeWindow* owner_window_;
|
||||||
|
|
||||||
|
// Whether window is fullscreened by HTML5 api.
|
||||||
|
bool html_fullscreen_;
|
||||||
|
|
||||||
|
// Whether window is fullscreened by window api.
|
||||||
|
bool native_fullscreen_;
|
||||||
|
|
||||||
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
scoped_ptr<WebDialogHelper> web_dialog_helper_;
|
||||||
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
scoped_ptr<AtomJavaScriptDialogManager> dialog_manager_;
|
||||||
|
|
||||||
|
|
|
@ -94,8 +94,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
|
||||||
is_closed_(false),
|
is_closed_(false),
|
||||||
node_integration_(true),
|
node_integration_(true),
|
||||||
has_dialog_attached_(false),
|
has_dialog_attached_(false),
|
||||||
html_fullscreen_(false),
|
|
||||||
native_fullscreen_(false),
|
|
||||||
zoom_factor_(1.0),
|
zoom_factor_(1.0),
|
||||||
weak_factory_(this) {
|
weak_factory_(this) {
|
||||||
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
|
||||||
|
@ -431,25 +429,6 @@ void NativeWindow::OverrideWebkitPrefs(content::WebPreferences* prefs) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::SetHtmlApiFullscreen(bool enter_fullscreen) {
|
|
||||||
// Window is already in fullscreen mode, save the state.
|
|
||||||
if (enter_fullscreen && IsFullscreen()) {
|
|
||||||
native_fullscreen_ = true;
|
|
||||||
html_fullscreen_ = true;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exit html fullscreen state but not window's fullscreen mode.
|
|
||||||
if (!enter_fullscreen && native_fullscreen_) {
|
|
||||||
html_fullscreen_ = false;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
SetFullScreen(enter_fullscreen);
|
|
||||||
html_fullscreen_ = enter_fullscreen;
|
|
||||||
native_fullscreen_ = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::NotifyWindowClosed() {
|
void NativeWindow::NotifyWindowClosed() {
|
||||||
if (is_closed_)
|
if (is_closed_)
|
||||||
return;
|
return;
|
||||||
|
@ -647,20 +626,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
|
||||||
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
FOR_EACH_OBSERVER(NativeWindowObserver, observers_, OnRendererResponsive());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindow::EnterFullscreenModeForTab(content::WebContents* source,
|
|
||||||
const GURL& origin) {
|
|
||||||
SetHtmlApiFullscreen(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::ExitFullscreenModeForTab(content::WebContents* source) {
|
|
||||||
SetHtmlApiFullscreen(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool NativeWindow::IsFullscreenForTabOrPending(
|
|
||||||
const content::WebContents* source) const {
|
|
||||||
return is_html_api_fullscreen();
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
|
||||||
// Do nothing, we override this method just to avoid compilation error since
|
// Do nothing, we override this method just to avoid compilation error since
|
||||||
// there are two virtual functions named BeforeUnloadFired.
|
// there are two virtual functions named BeforeUnloadFired.
|
||||||
|
|
|
@ -179,9 +179,6 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
|
void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
|
||||||
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
void OverrideWebkitPrefs(content::WebPreferences* prefs);
|
||||||
|
|
||||||
// Set fullscreen mode triggered by html api.
|
|
||||||
void SetHtmlApiFullscreen(bool enter_fullscreen);
|
|
||||||
|
|
||||||
// Public API used by platform-dependent delegates and observers to send UI
|
// Public API used by platform-dependent delegates and observers to send UI
|
||||||
// related notifications.
|
// related notifications.
|
||||||
void NotifyWindowClosed();
|
void NotifyWindowClosed();
|
||||||
|
@ -213,8 +210,6 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
|
|
||||||
bool has_frame() const { return has_frame_; }
|
bool has_frame() const { return has_frame_; }
|
||||||
|
|
||||||
bool is_html_api_fullscreen() const { return html_fullscreen_; }
|
|
||||||
|
|
||||||
void set_has_dialog_attached(bool has_dialog_attached) {
|
void set_has_dialog_attached(bool has_dialog_attached) {
|
||||||
has_dialog_attached_ = has_dialog_attached;
|
has_dialog_attached_ = has_dialog_attached;
|
||||||
}
|
}
|
||||||
|
@ -250,11 +245,6 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
void CloseContents(content::WebContents* source) override;
|
void CloseContents(content::WebContents* source) override;
|
||||||
void RendererUnresponsive(content::WebContents* source) override;
|
void RendererUnresponsive(content::WebContents* source) override;
|
||||||
void RendererResponsive(content::WebContents* source) override;
|
void RendererResponsive(content::WebContents* source) override;
|
||||||
void EnterFullscreenModeForTab(content::WebContents* source,
|
|
||||||
const GURL& origin) override;
|
|
||||||
void ExitFullscreenModeForTab(content::WebContents* source) override;
|
|
||||||
bool IsFullscreenForTabOrPending(
|
|
||||||
const content::WebContents* source) const override;
|
|
||||||
|
|
||||||
// Implementations of content::WebContentsObserver.
|
// Implementations of content::WebContentsObserver.
|
||||||
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
void RenderViewCreated(content::RenderViewHost* render_view_host) override;
|
||||||
|
@ -310,12 +300,6 @@ class NativeWindow : public CommonWebContentsDelegate,
|
||||||
// There is a dialog that has been attached to window.
|
// There is a dialog that has been attached to window.
|
||||||
bool has_dialog_attached_;
|
bool has_dialog_attached_;
|
||||||
|
|
||||||
// Whether window is fullscreened by HTML5 api.
|
|
||||||
bool html_fullscreen_;
|
|
||||||
|
|
||||||
// Whether window is fullscreened by window api.
|
|
||||||
bool native_fullscreen_;
|
|
||||||
|
|
||||||
// Closure that would be called when window is unresponsive when closing,
|
// Closure that would be called when window is unresponsive when closing,
|
||||||
// it should be cancelled when we can prove that the window is responsive.
|
// it should be cancelled when we can prove that the window is responsive.
|
||||||
base::CancelableClosure window_unresposive_closure_;
|
base::CancelableClosure window_unresposive_closure_;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue