Move disable counter to NativeWindow from api::Window

This commit is contained in:
Cheng Zhao 2016-06-20 11:48:46 +09:00
parent 946d246aea
commit 1866dbe608
8 changed files with 36 additions and 40 deletions

View 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) Window::Window(v8::Isolate* isolate, const mate::Dictionary& options)
: disable_count_(0), : is_modal_(false) {
is_modal_(false) {
// Use options.webPreferences to create WebContents. // Use options.webPreferences to create WebContents.
mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate); mate::Dictionary web_preferences = mate::Dictionary::CreateEmpty(isolate);
options.Get(options::kWebPreferences, &web_preferences); options.Get(options::kWebPreferences, &web_preferences);
@ -325,14 +324,10 @@ bool Window::IsVisible() {
} }
void Window::Disable() { void Window::Disable() {
++disable_count_;
if (disable_count_ == 1)
window_->Disable(); window_->Disable();
} }
void Window::Enable() { void Window::Enable() {
--disable_count_;
if (disable_count_ == 0)
window_->Enable(); window_->Enable();
} }

View file

@ -209,9 +209,6 @@ class Window : public mate::TrackableObject<Window>,
v8::Global<v8::Value> parent_window_; v8::Global<v8::Value> parent_window_;
KeyWeakMap<int> child_windows_; KeyWeakMap<int> child_windows_;
// How many times the Disable has been called.
int disable_count_;
// Is current window modal. // Is current window modal.
bool is_modal_; bool is_modal_;

View file

@ -56,6 +56,7 @@ NativeWindow::NativeWindow(
sheet_offset_x_(0.0), sheet_offset_x_(0.0),
sheet_offset_y_(0.0), sheet_offset_y_(0.0),
aspect_ratio_(0.0), aspect_ratio_(0.0),
disable_count_(0),
inspectable_web_contents_(inspectable_web_contents), inspectable_web_contents_(inspectable_web_contents),
weak_factory_(this) { weak_factory_(this) {
options.Get(options::kFrame, &has_frame_); options.Get(options::kFrame, &has_frame_);
@ -178,6 +179,18 @@ void NativeWindow::InitFromOptions(const mate::Dictionary& options) {
Show(); 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) { void NativeWindow::SetSize(const gfx::Size& size, bool animate) {
SetBounds(gfx::Rect(GetPosition(), size), animate); SetBounds(gfx::Rect(GetPosition(), size), animate);
} }

View file

@ -98,8 +98,9 @@ class NativeWindow : public base::SupportsUserData,
virtual void ShowInactive() = 0; virtual void ShowInactive() = 0;
virtual void Hide() = 0; virtual void Hide() = 0;
virtual bool IsVisible() = 0; virtual bool IsVisible() = 0;
virtual void Disable() = 0; virtual void Disable();
virtual void Enable() = 0; virtual void Enable();
virtual void SetEnabled(bool enable) = 0; // should not be used
virtual bool IsEnabled() = 0; virtual bool IsEnabled() = 0;
virtual void Maximize() = 0; virtual void Maximize() = 0;
virtual void Unmaximize() = 0; virtual void Unmaximize() = 0;
@ -337,6 +338,9 @@ class NativeWindow : public base::SupportsUserData,
double aspect_ratio_; double aspect_ratio_;
gfx::Size aspect_ratio_extraSize_; gfx::Size aspect_ratio_extraSize_;
// How many times the Disable has been called.
int disable_count_;
// The page this window is viewing. // The page this window is viewing.
brightray::InspectableWebContents* inspectable_web_contents_; brightray::InspectableWebContents* inspectable_web_contents_;

View file

@ -35,8 +35,7 @@ class NativeWindowMac : public NativeWindow {
void ShowInactive() override; void ShowInactive() override;
void Hide() override; void Hide() override;
bool IsVisible() override; bool IsVisible() override;
void Disable() override; void SetEnabled(bool enable) override;
void Enable() override;
bool IsEnabled() override; bool IsEnabled() override;
void Maximize() override; void Maximize() override;
void Unmaximize() override; void Unmaximize() override;

View file

@ -673,14 +673,9 @@ bool NativeWindowMac::IsVisible() {
return [window_ isVisible]; return [window_ isVisible];
} }
void NativeWindowMac::Disable() { void NativeWindowMac::SetEnabled(bool enable) {
[window_ setDisableKeyOrMainWindow:YES]; [window_ setDisableKeyOrMainWindow:!enable];
[window_ setDisableMouseEvents:YES]; [window_ setDisableMouseEvents:!enable];
}
void NativeWindowMac::Enable() {
[window_ setDisableKeyOrMainWindow:NO];
[window_ setDisableMouseEvents:NO];
} }
bool NativeWindowMac::IsEnabled() { bool NativeWindowMac::IsEnabled() {

View file

@ -382,25 +382,19 @@ bool NativeWindowViews::IsVisible() {
return window_->IsVisible(); return window_->IsVisible();
} }
void NativeWindowViews::Disable() { void NativeWindowViews::SetEnabled(bool enable) {
#if defined(OS_WIN) #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) #elif defined(USE_X11)
views::DesktopWindowTreeHostX11* tree_host = views::DesktopWindowTreeHostX11* tree_host =
views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget()); views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
if (enable) {
tree_host->RemoveEventRewriter(event_disabler_.get()); tree_host->RemoveEventRewriter(event_disabler_.get());
event_disabler_.reset(); event_disabler_.reset();
} else {
event_disabler_.reset(new EventDisabler);
tree_host->AddEventRewriter(event_disabler_.get());
}
#endif #endif
} }

View file

@ -57,8 +57,7 @@ class NativeWindowViews : public NativeWindow,
void ShowInactive() override; void ShowInactive() override;
void Hide() override; void Hide() override;
bool IsVisible() override; bool IsVisible() override;
void Disable() override; void SetEnabled(bool enable) override;
void Enable() override;
bool IsEnabled() override; bool IsEnabled() override;
void Maximize() override; void Maximize() override;
void Unmaximize() override; void Unmaximize() override;