Move disable counter to NativeWindow from api::Window
authorCheng Zhao <zcbenz@gmail.com>
Mon, 20 Jun 2016 02:48:46 +0000 (11:48 +0900)
committerCheng Zhao <zcbenz@gmail.com>
Mon, 20 Jun 2016 02:48:46 +0000 (11:48 +0900)
atom/browser/api/atom_api_window.cc
atom/browser/api/atom_api_window.h
atom/browser/native_window.cc
atom/browser/native_window.h
atom/browser/native_window_mac.h
atom/browser/native_window_mac.mm
atom/browser/native_window_views.cc
atom/browser/native_window_views.h

index a3df8f9..7068360 100644 (file)
@@ -77,8 +77,7 @@ v8::Local<v8::Value> ToBuffer(v8::Isolate* isolate, void* val, int size) {
 
 
 Window::Window(v8::Isolate* isolate, const mate::Dictionary& options)
-    : disable_count_(0),
-      is_modal_(false) {
+    : is_modal_(false) {
   // Use options.webPreferences to create WebContents.
   mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
   options.Get(options::kWebPreferences, &web_preferences);
@@ -325,15 +324,11 @@ bool Window::IsVisible() {
 }
 
 void Window::Disable() {
-  ++disable_count_;
-  if (disable_count_ == 1)
-    window_->Disable();
+  window_->Disable();
 }
 
 void Window::Enable() {
-  --disable_count_;
-  if (disable_count_ == 0)
-    window_->Enable();
+  window_->Enable();
 }
 
 bool Window::IsEnabled() {
index 238e3ad..80785d7 100644 (file)
@@ -209,9 +209,6 @@ class Window : public mate::TrackableObject<Window>,
   v8::Global<v8::Value> parent_window_;
   KeyWeakMap<int> child_windows_;
 
-  // How many times the Disable has been called.
-  int disable_count_;
-
   // Is current window modal.
   bool is_modal_;
 
index 6db53df..f58e026 100644 (file)
@@ -56,6 +56,7 @@ NativeWindow::NativeWindow(
       sheet_offset_x_(0.0),
       sheet_offset_y_(0.0),
       aspect_ratio_(0.0),
+      disable_count_(0),
       inspectable_web_contents_(inspectable_web_contents),
       weak_factory_(this) {
   options.Get(options::kFrame, &has_frame_);
@@ -178,6 +179,18 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
     Show();
 }
 
+void NativeWindow::Disable() {
+  ++disable_count_;
+  if (disable_count_ == 1)
+    SetEnabled(false);
+}
+
+void NativeWindow::Enable() {
+  --disable_count_;
+  if (disable_count_ == 0)
+    SetEnabled(true);
+}
+
 void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
   SetBounds(gfx::Rect(GetPosition(), size), animate);
 }
index d201468..96c10ac 100644 (file)
@@ -98,8 +98,9 @@ class NativeWindow : public base::SupportsUserData,
   virtual void ShowInactive() = 0;
   virtual void Hide() = 0;
   virtual bool IsVisible() = 0;
-  virtual void Disable() = 0;
-  virtual void Enable() = 0;
+  virtual void Disable();
+  virtual void Enable();
+  virtual void SetEnabled(bool enable) = 0;  // should not be used
   virtual bool IsEnabled() = 0;
   virtual void Maximize() = 0;
   virtual void Unmaximize() = 0;
@@ -337,6 +338,9 @@ class NativeWindow : public base::SupportsUserData,
   double aspect_ratio_;
   gfx::Size aspect_ratio_extraSize_;
 
+  // How many times the Disable has been called.
+  int disable_count_;
+
   // The page this window is viewing.
   brightray::InspectableWebContents* inspectable_web_contents_;
 
index 3061663..2dcd298 100644 (file)
@@ -35,8 +35,7 @@ class NativeWindowMac : public NativeWindow {
   void ShowInactive() override;
   void Hide() override;
   bool IsVisible() override;
-  void Disable() override;
-  void Enable() override;
+  void SetEnabled(bool enable) override;
   bool IsEnabled() override;
   void Maximize() override;
   void Unmaximize() override;
index f68d499..b49f878 100644 (file)
@@ -673,14 +673,9 @@ bool NativeWindowMac::IsVisible() {
   return [window_ isVisible];
 }
 
-void NativeWindowMac::Disable() {
-  [window_ setDisableKeyOrMainWindow:YES];
-  [window_ setDisableMouseEvents:YES];
-}
-
-void NativeWindowMac::Enable() {
-  [window_ setDisableKeyOrMainWindow:NO];
-  [window_ setDisableMouseEvents:NO];
+void NativeWindowMac::SetEnabled(bool enable) {
+  [window_ setDisableKeyOrMainWindow:!enable];
+  [window_ setDisableMouseEvents:!enable];
 }
 
 bool NativeWindowMac::IsEnabled() {
index 0dcef46..ab317f1 100644 (file)
@@ -382,25 +382,19 @@ bool NativeWindowViews::IsVisible() {
   return window_->IsVisible();
 }
 
-void NativeWindowViews::Disable() {
+void NativeWindowViews::SetEnabled(bool enable) {
 #if defined(OS_WIN)
-  ::EnableWindow(GetAcceleratedWidget(), FALSE);
+  ::EnableWindow(GetAcceleratedWidget(), enable);
 #elif defined(USE_X11)
-  event_disabler_.reset(new EventDisabler);
   views::DesktopWindowTreeHostX11* tree_host =
       views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
-  tree_host->AddEventRewriter(event_disabler_.get());
-#endif
-}
-
-void NativeWindowViews::Enable() {
-#if defined(OS_WIN)
-  ::EnableWindow(GetAcceleratedWidget(), TRUE);
-#elif defined(USE_X11)
-  views::DesktopWindowTreeHostX11* tree_host =
-      views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
-  tree_host->RemoveEventRewriter(event_disabler_.get());
-  event_disabler_.reset();
+  if (enable) {
+    tree_host->RemoveEventRewriter(event_disabler_.get());
+    event_disabler_.reset();
+  } else {
+    event_disabler_.reset(new EventDisabler);
+    tree_host->AddEventRewriter(event_disabler_.get());
+  }
 #endif
 }
 
index bdc2d36..adc18a1 100644 (file)
@@ -57,8 +57,7 @@ class NativeWindowViews : public NativeWindow,
   void ShowInactive() override;
   void Hide() override;
   bool IsVisible() override;
-  void Disable() override;
-  void Enable() override;
+  void SetEnabled(bool enable) override;
   bool IsEnabled() override;
   void Maximize() override;
   void Unmaximize() override;