From: Cheng Zhao Date: Fri, 17 Jun 2016 08:38:44 +0000 (+0900) Subject: mac: Add win.disable/enable/isEnabled() API X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=1a4b4a65c96ece6225edddee28560d372b87c9ed;p=platform%2Fframework%2Fweb%2Fcrosswalk-tizen.git mac: Add win.disable/enable/isEnabled() API --- diff --git a/atom/browser/api/atom_api_window.cc b/atom/browser/api/atom_api_window.cc index 3e1bb6a..30427d5 100644 --- a/atom/browser/api/atom_api_window.cc +++ b/atom/browser/api/atom_api_window.cc @@ -293,6 +293,18 @@ bool Window::IsVisible() { return window_->IsVisible(); } +void Window::Disable() { + window_->Disable(); +} + +void Window::Enable() { + window_->Enable(); +} + +bool Window::IsEnabled() { + return window_->IsEnabled(); +} + void Window::Maximize() { window_->Maximize(); } @@ -726,6 +738,9 @@ void Window::BuildPrototype(v8::Isolate* isolate, .SetMethod("showInactive", &Window::ShowInactive) .SetMethod("hide", &Window::Hide) .SetMethod("isVisible", &Window::IsVisible) + .SetMethod("enable", &Window::Enable) + .SetMethod("disable", &Window::Disable) + .SetMethod("isEnabled", &Window::IsEnabled) .SetMethod("maximize", &Window::Maximize) .SetMethod("unmaximize", &Window::Unmaximize) .SetMethod("isMaximized", &Window::IsMaximized) diff --git a/atom/browser/api/atom_api_window.h b/atom/browser/api/atom_api_window.h index 0cc238a..3e53cbf 100644 --- a/atom/browser/api/atom_api_window.h +++ b/atom/browser/api/atom_api_window.h @@ -95,6 +95,9 @@ class Window : public mate::TrackableObject, void ShowInactive(); void Hide(); bool IsVisible(); + void Disable(); + void Enable(); + bool IsEnabled(); void Maximize(); void Unmaximize(); bool IsMaximized(); diff --git a/atom/browser/native_window.h b/atom/browser/native_window.h index 8dd3dc5..a2adb55 100644 --- a/atom/browser/native_window.h +++ b/atom/browser/native_window.h @@ -97,6 +97,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 bool IsEnabled() = 0; virtual void Maximize() = 0; virtual void Unmaximize() = 0; virtual bool IsMaximized() = 0; diff --git a/atom/browser/native_window_mac.h b/atom/browser/native_window_mac.h index 2e0b769..0a783c3 100644 --- a/atom/browser/native_window_mac.h +++ b/atom/browser/native_window_mac.h @@ -34,6 +34,9 @@ class NativeWindowMac : public NativeWindow { void ShowInactive() override; void Hide() override; bool IsVisible() override; + void Disable() override; + void Enable() override; + bool IsEnabled() override; void Maximize() override; void Unmaximize() override; bool IsMaximized() override; diff --git a/atom/browser/native_window_mac.mm b/atom/browser/native_window_mac.mm index 8dd6457..bad2fc7 100644 --- a/atom/browser/native_window_mac.mm +++ b/atom/browser/native_window_mac.mm @@ -279,6 +279,7 @@ bool ScopedDisableResize::disable_resize_ = false; @property BOOL acceptsFirstMouse; @property BOOL disableAutoHideCursor; @property BOOL disableKeyOrMainWindow; +@property BOOL disableMouseEvents; - (void)setShell:(atom::NativeWindowMac*)shell; - (void)setEnableLargerThanScreen:(bool)enable; @@ -348,6 +349,29 @@ bool ScopedDisableResize::disable_resize_ = false; return !self.disableKeyOrMainWindow; } +- (void)sendEvent:(NSEvent*)event { + // Drop all mouse events. + if (self.disableMouseEvents) { + switch([event type]) { + case NSLeftMouseUp: + case NSLeftMouseDown: + case NSRightMouseDown: + case NSRightMouseUp: + case NSOtherMouseUp: + case NSLeftMouseDragged: + case NSRightMouseDragged: + case NSOtherMouseDragged: + case NSMouseMoved: + case NSScrollWheel: + return; + default: + break; + } + } + + [super sendEvent:event]; +} + @end @interface ControlRegionView : NSView @@ -496,6 +520,7 @@ NativeWindowMac::NativeWindowMac( backing:NSBackingStoreBuffered defer:YES]); [window_ setShell:this]; + [window_ setDisableMouseEvents:NO]; [window_ setEnableLargerThanScreen:enable_larger_than_screen()]; window_delegate_.reset([[AtomNSWindowDelegate alloc] initWithShell:this]); @@ -647,6 +672,20 @@ bool NativeWindowMac::IsVisible() { return [window_ isVisible]; } +void NativeWindowMac::Disable() { + [window_ setDisableKeyOrMainWindow:YES]; + [window_ setDisableMouseEvents:YES]; +} + +void NativeWindowMac::Enable() { + [window_ setDisableKeyOrMainWindow:NO]; + [window_ setDisableMouseEvents:NO]; +} + +bool NativeWindowMac::IsEnabled() { + return ![window_ disableMouseEvents]; +} + void NativeWindowMac::Maximize() { if (IsMaximized()) return; diff --git a/atom/browser/native_window_views.cc b/atom/browser/native_window_views.cc index ca93bb0..b27f08a 100644 --- a/atom/browser/native_window_views.cc +++ b/atom/browser/native_window_views.cc @@ -373,6 +373,16 @@ bool NativeWindowViews::IsVisible() { return window_->IsVisible(); } +void NativeWindowViews::Disable() { +} + +void NativeWindowViews::Enable() { +} + +bool NativeWindowViews::IsEnabled() { + return true; +} + void NativeWindowViews::Maximize() { if (IsVisible()) window_->Maximize(); diff --git a/atom/browser/native_window_views.h b/atom/browser/native_window_views.h index 2c63270..f876a8b 100644 --- a/atom/browser/native_window_views.h +++ b/atom/browser/native_window_views.h @@ -54,6 +54,9 @@ class NativeWindowViews : public NativeWindow, void ShowInactive() override; void Hide() override; bool IsVisible() override; + void Disable() override; + void Enable() override; + bool IsEnabled() override; void Maximize() override; void Unmaximize() override; bool IsMaximized() override;