]> khamidou — GitHub mirrors - electron.git/commitdiff
also emit html fullscreen notification on windows when its webview contents trigger it
authordeepak1556 <hop2deep@gmail.com>
Thu, 21 May 2015 05:09:31 +0000 (10:39 +0530)
committerdeepak1556 <hop2deep@gmail.com>
Thu, 21 May 2015 05:11:53 +0000 (10:41 +0530)
atom/browser/api/atom_api_web_contents.cc
atom/browser/native_window.cc
atom/browser/native_window.h

index f72a4c4d168375860efb91d286dabee0f53daa18..734434aff1ae1d5eaae1a5f062b8e82319362247 100644 (file)
@@ -220,6 +220,7 @@ void WebContents::EnterFullscreenModeForTab(content::WebContents* source,
   auto window = GetWindowFromGuest(source);
   if (window) {
     window->SetHtmlApiFullscreen(true);
+    window->NotifyWindowEnterHtmlFullScreen();
     source->GetRenderViewHost()->WasResized();
     Emit("enter-html-full-screen");
   }
@@ -229,6 +230,7 @@ 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");
   }
@@ -238,7 +240,7 @@ bool WebContents::IsFullscreenForTabOrPending(
     const content::WebContents* source) const {
   auto window = GetWindowFromGuest(source);
   if (window)
-    return window->IsHtmlApiFullscreen();
+    return window->is_html_api_fullscreen();
   else
     return false;
 }
index 79ea407f3da4bfb88e937af585a40637728f5a36..e937bbdfccf1a45a9b793960e556d454759f4661 100644 (file)
@@ -100,6 +100,7 @@ NativeWindow::NativeWindow(content::WebContents* web_contents,
       node_integration_(true),
       has_dialog_attached_(false),
       html_fullscreen_(false),
+      native_fullscreen_(false),
       zoom_factor_(1.0),
       weak_factory_(this),
       inspectable_web_contents_(
@@ -477,6 +478,25 @@ 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;
@@ -525,6 +545,16 @@ void NativeWindow::NotifyWindowLeaveFullScreen() {
                     OnWindowLeaveFullScreen());
 }
 
+void NativeWindow::NotifyWindowEnterHtmlFullScreen() {
+  FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
+                    OnWindowEnterHtmlFullScreen());
+}
+
+void NativeWindow::NotifyWindowLeaveHtmlFullScreen() {
+  FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
+                    OnWindowLeaveHtmlFullScreen());
+}
+
 bool NativeWindow::ShouldCreateWebContents(
     content::WebContents* web_contents,
     int route_id,
@@ -700,19 +730,15 @@ void NativeWindow::RendererResponsive(content::WebContents* source) {
 void NativeWindow::EnterFullscreenModeForTab(content::WebContents* source,
                                              const GURL& origin) {
   SetHtmlApiFullscreen(true);
-  FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
-                    OnWindowEnterHtmlFullScreen());
 }
 
 void NativeWindow::ExitFullscreenModeForTab(content::WebContents* source) {
   SetHtmlApiFullscreen(false);
-  FOR_EACH_OBSERVER(NativeWindowObserver, observers_,
-                    OnWindowLeaveHtmlFullScreen());
 }
 
 bool NativeWindow::IsFullscreenForTabOrPending(
     const content::WebContents* source) const {
-  return IsHtmlApiFullscreen();
+  return is_html_api_fullscreen();
 }
 
 void NativeWindow::BeforeUnloadFired(const base::TimeTicks& proceed_time) {
@@ -805,25 +831,6 @@ void NativeWindow::ScheduleUnresponsiveEvent(int ms) {
       base::TimeDelta::FromMilliseconds(ms));
 }
 
-void NativeWindow::SetHtmlApiFullscreen(bool enter_fullscreen) {
-  // Window is already in fullscreen mode, save the state.
-  if (enter_fullscreen && IsFullscreen()) {
-    forced_fullscreen_ = true;
-    html_fullscreen_ = true;
-    return;
-  }
-
-  // Exit html fullscreen state but not window's fullscreen mode.
-  if (!enter_fullscreen && forced_fullscreen_) {
-    html_fullscreen_ = false;
-    return;
-  }
-
-  SetFullScreen(enter_fullscreen);
-  html_fullscreen_ = enter_fullscreen;
-  forced_fullscreen_ = false;
-}
-
 void NativeWindow::NotifyWindowUnresponsive() {
   window_unresposive_closure_.Cancel();
 
index f23c27ebf7701d053e3e7104b64574eb910805f2..b114ecf510b496158f7a9fe985effbc9375fc773 100644 (file)
@@ -209,6 +209,8 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   void NotifyWindowRestore();
   void NotifyWindowEnterFullScreen();
   void NotifyWindowLeaveFullScreen();
+  void NotifyWindowEnterHtmlFullScreen();
+  void NotifyWindowLeaveHtmlFullScreen();
 
   void AddObserver(NativeWindowObserver* obs) {
     observers_.AddObserver(obs);
@@ -220,7 +222,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
 
   bool has_frame() const { return has_frame_; }
 
-  bool IsHtmlApiFullscreen() const { return html_fullscreen_; }
+  bool is_html_api_fullscreen() const { return html_fullscreen_; }
 
   void set_has_dialog_attached(bool has_dialog_attached) {
     has_dialog_attached_ = has_dialog_attached;
@@ -352,7 +354,7 @@ class NativeWindow : public brightray::DefaultWebContentsDelegate,
   bool html_fullscreen_;
 
   // Whether window is fullscreened by window api.
-  bool forced_fullscreen_;
+  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.