]> khamidou — GitHub mirrors - electron.git/commitdiff
Implement HTML5 fullscreen in CommonWebContentsDelegate
authorCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 09:27:24 +0000 (17:27 +0800)
committerCheng Zhao <zcbenz@gmail.com>
Fri, 5 Jun 2015 09:27:24 +0000 (17:27 +0800)
atom/browser/api/atom_api_web_contents.cc
atom/browser/api/atom_api_web_contents.h
atom/browser/common_web_contents_delegate.cc
atom/browser/common_web_contents_delegate.h
atom/browser/native_window.cc
atom/browser/native_window.h

index 49b0a89d836235c9d713a6ef2affb6fac50dbfc5..18bfc7a53f5fe8452b109f3bf1c97e2034d1b5b4 100644 (file)
@@ -223,32 +223,13 @@ void WebContents::HandleKeyboardEvent(
 
 void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
                                             const GURL& origin) {
-  auto window = GetWindowFromGuest(source);
-  if (window) {
-    window->SetHtmlApiFullscreen(true);
-    window->NotifyWindowEnterHtmlFullScreen();
-    source->GetRenderViewHost()->WasResized();
-    Emit("enter-html-full-screen");
-  }
+  CommonWebContentsDelegate::EnterFullscreenModeForTab(source, origin);
+  Emit("enter-html-full-screen");
 }
 
 void WebContents::ExitFullscreenModeForTab(content::WebContents* source) {
-  auto window = GetWindowFromGuest(source);
-  if (window) {
-    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;
+  CommonWebContentsDelegate::ExitFullscreenModeForTab(source);
+  Emit("leave-html-full-screen");
 }
 
 void WebContents::RenderViewDeleted(content::RenderViewHost* render_view_host) {
index f16680b53d00ca42193cfc10573edee36cad38f2..58059d9e9262566ba3195dfef213ce3307ab984f 100644 (file)
@@ -158,8 +158,6 @@ class WebContents : public mate::EventEmitter,
   void EnterFullscreenModeForTab(content::WebContents* source,
                                  const GURL& origin) override;
   void ExitFullscreenModeForTab(content::WebContents* source) override;
-  bool IsFullscreenForTabOrPending(
-      const content::WebContents* source) const override;
 
   // content::WebContentsObserver:
   void RenderViewDeleted(content::RenderViewHost*) override;
index 1a64f2498582d2bbe92d15723edf29bf79bb0205..564efe7edd15e2eff587b7df2b882bb8d81c96d3 100644 (file)
@@ -87,7 +87,9 @@ base::DictionaryValue* CreateFileSystemValue(const FileSystem& file_system) {
 
 CommonWebContentsDelegate::CommonWebContentsDelegate(bool is_guest)
     : is_guest_(is_guest),
-      owner_window_(nullptr) {
+      owner_window_(nullptr),
+      html_fullscreen_(false),
+      native_fullscreen_(false) {
 }
 
 CommonWebContentsDelegate::~CommonWebContentsDelegate() {
@@ -108,6 +110,19 @@ void CommonWebContentsDelegate::DestroyWebContents() {
   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(
     content::WebContents* web_contents,
     bool user_gesture,
@@ -156,17 +171,27 @@ void CommonWebContentsDelegate::EnumerateDirectory(content::WebContents* guest,
   web_dialog_helper_->EnumerateDirectory(guest, request_id, path);
 }
 
-content::WebContents* CommonWebContentsDelegate::GetWebContents() const {
-  if (!web_contents_)
-    return nullptr;
-  return web_contents_->GetWebContents();
+void CommonWebContentsDelegate::EnterFullscreenModeForTab(
+    content::WebContents* source, const GURL& origin) {
+  if (!owner_window_)
+    return;
+  SetHtmlApiFullscreen(true);
+  owner_window_->NotifyWindowEnterHtmlFullScreen();
+  source->GetRenderViewHost()->WasResized();
 }
 
-content::WebContents*
-CommonWebContentsDelegate::GetDevToolsWebContents() const {
-  if (!web_contents_)
-    return nullptr;
-  return web_contents_->GetDevToolsWebContents();
+void CommonWebContentsDelegate::ExitFullscreenModeForTab(
+    content::WebContents* source) {
+  if (!owner_window_)
+    return;
+  SetHtmlApiFullscreen(false);
+  owner_window_->NotifyWindowLeaveHtmlFullScreen();
+  source->GetRenderViewHost()->WasResized();
+}
+
+bool CommonWebContentsDelegate::IsFullscreenForTabOrPending(
+    const content::WebContents* source) const {
+  return html_fullscreen_;
 }
 
 void CommonWebContentsDelegate::DevToolsSaveToFile(
@@ -269,4 +294,23 @@ void CommonWebContentsDelegate::DevToolsRemoveFileSystem(
        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
index 8909d193145711aca2b290eeec079bb3cd885335..30545e2e40432ed6b442f2e09fe5b0dddb635f51 100644 (file)
@@ -64,6 +64,11 @@ class CommonWebContentsDelegate
   void EnumerateDirectory(content::WebContents* web_contents,
                           int request_id,
                           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:
   void DevToolsSaveToFile(const std::string& url,
@@ -75,12 +80,21 @@ class CommonWebContentsDelegate
   void DevToolsRemoveFileSystem(const std::string& file_system_path) override;
 
  private:
+  // Set fullscreen mode triggered by html api.
+  void SetHtmlApiFullscreen(bool enter_fullscreen);
+
   // Whether this is guest WebContents or NativeWindow.
   const bool is_guest_;
 
   // The window that this WebContents belongs to.
   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<AtomJavaScriptDialogManager> dialog_manager_;
 
index 07ad83f1acee556738f60150b65545296bbdfcf4..60a9eb27f2d25eeb4b96227dbe9f207679f5466f 100644 (file)
@@ -94,8 +94,6 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       is_closed_(false),
       node_integration_(true),
       has_dialog_attached_(false),
-      html_fullscreen_(false),
-      native_fullscreen_(false),
       zoom_factor_(1.0),
       weak_factory_(this) {
   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() {
   if (is_closed_)
     return;
@@ -647,20 +626,6 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
   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) {
   // Do nothing, we override this method just to avoid compilation error since
   // there are two virtual functions named BeforeUnloadFired.
index 191e326df06d71d5b64ce27d0c4a93f485cabd6f..2038775f8d9a53a2fd41c7f9e06f6b28f9d9d060 100644 (file)
@@ -179,9 +179,6 @@ class NativeWindow : public CommonWebContentsDelegate,
   void AppendExtraCommandLineSwitches(base::CommandLine* command_line);
   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
   // related notifications.
   void NotifyWindowClosed();
@@ -213,8 +210,6 @@ class NativeWindow : public CommonWebContentsDelegate,
 
   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) {
     has_dialog_attached_ = has_dialog_attached;
   }
@@ -250,11 +245,6 @@ class NativeWindow : public CommonWebContentsDelegate,
   void CloseContents(content::WebContents* source) override;
   void RendererUnresponsive(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.
   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.
   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,
   // it should be cancelled when we can prove that the window is responsive.
   base::CancelableClosure window_unresposive_closure_;