Move disable counter to NativeWindow from api::Window
This commit is contained in:
parent
946d246aea
commit
1866dbe608
8 changed files with 36 additions and 40 deletions
|
@ -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() {
|
||||
|
|
|
@ -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_;
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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_;
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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() {
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue