diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index a3df8f9c08d8..7068360ef91f 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -77,8 +77,7 @@ v8::Local 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() { diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 238e3ad7e1f0..80785d7673f9 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -209,9 +209,6 @@ class Window : public mate::TrackableObject, v8::Global parent_window_; KeyWeakMap child_windows_; - // How many times the Disable has been called. - int disable_count_; - // Is current window modal. bool is_modal_; diff --git a/atom/browser/native_window.cc b/atom/browser/native_window.cc index 6db53df28aca..f58e026cf494 100644 --- a/atom/browser/native_window.cc +++ b/atom/browser/native_window.cc @@ -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); } diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index d20146819d48..96c10ac5464a 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -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_; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 3061663520ad..2dcd29806d6d 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -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; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index f68d49929ab9..b49f878eacdd 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -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() { diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index 0dcef4661d5a..ab317f16d530 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -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); -#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); + ::EnableWindow(GetAcceleratedWidget(), enable); #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 } diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index bdc2d36497b0..adc18a1dfdeb 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -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;