refactor: manage widget_ in NativeWindow
This commit is contained in:
parent
727cd68cee
commit
2225cc9608
6 changed files with 22 additions and 29 deletions
|
@ -13,6 +13,7 @@
|
|||
#include "atom/common/color_util.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "native_mate/dictionary.h"
|
||||
#include "ui/views/widget/widget.h"
|
||||
|
||||
DEFINE_WEB_CONTENTS_USER_DATA_KEY(atom::NativeWindowRelay);
|
||||
|
||||
|
@ -20,7 +21,8 @@ namespace atom {
|
|||
|
||||
NativeWindow::NativeWindow(const mate::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: has_frame_(true),
|
||||
: widget_(new views::Widget),
|
||||
has_frame_(true),
|
||||
transparent_(false),
|
||||
enable_larger_than_screen_(false),
|
||||
is_closed_(false),
|
||||
|
@ -509,6 +511,14 @@ void NativeWindow::NotifyWindowMessage(UINT message,
|
|||
}
|
||||
#endif
|
||||
|
||||
views::Widget* NativeWindow::GetWidget() {
|
||||
return widget();
|
||||
}
|
||||
|
||||
const views::Widget* NativeWindow::GetWidget() const {
|
||||
return widget();
|
||||
}
|
||||
|
||||
NativeWindowRelay::NativeWindowRelay(base::WeakPtr<NativeWindow> window)
|
||||
: key(UserDataKey()), window(window) {}
|
||||
|
||||
|
|
|
@ -261,6 +261,8 @@ class NativeWindow : public base::SupportsUserData,
|
|||
observers_.RemoveObserver(obs);
|
||||
}
|
||||
|
||||
views::Widget* widget() const { return widget_.get(); }
|
||||
|
||||
bool has_frame() const { return has_frame_; }
|
||||
void set_has_frame(bool has_frame) { has_frame_ = has_frame; }
|
||||
|
||||
|
@ -274,11 +276,17 @@ class NativeWindow : public base::SupportsUserData,
|
|||
protected:
|
||||
NativeWindow(const mate::Dictionary& options, NativeWindow* parent);
|
||||
|
||||
// views::WidgetDelegate:
|
||||
views::Widget* GetWidget() override;
|
||||
const views::Widget* GetWidget() const override;
|
||||
|
||||
void set_browser_view(NativeBrowserView* browser_view) {
|
||||
browser_view_ = browser_view;
|
||||
}
|
||||
|
||||
private:
|
||||
std::unique_ptr<views::Widget> widget_;
|
||||
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_;
|
||||
|
||||
|
|
|
@ -144,8 +144,6 @@ class NativeWindowMac : public NativeWindow {
|
|||
|
||||
protected:
|
||||
// views::WidgetDelegate:
|
||||
views::Widget* GetWidget() override;
|
||||
const views::Widget* GetWidget() const override;
|
||||
bool CanResize() const override;
|
||||
|
||||
private:
|
||||
|
@ -154,7 +152,6 @@ class NativeWindowMac : public NativeWindow {
|
|||
|
||||
void SetForwardMouseMessages(bool forward);
|
||||
|
||||
std::unique_ptr<views::Widget> widget_;
|
||||
AtomNSWindow* window_; // Weak ref, managed by widget_.
|
||||
|
||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||
|
|
|
@ -308,15 +308,14 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
|
||||
// Create views::Widget and assign window_ with it.
|
||||
// TODO(zcbenz): Get rid of the window_ in future.
|
||||
widget_.reset(new views::Widget());
|
||||
views::Widget::InitParams params;
|
||||
params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
|
||||
params.bounds = bounds;
|
||||
params.delegate = this;
|
||||
params.type = views::Widget::InitParams::TYPE_WINDOW;
|
||||
params.native_widget = new AtomNativeWidgetMac(styleMask, widget_.get());
|
||||
widget_->Init(params);
|
||||
window_ = static_cast<AtomNSWindow*>(widget_->GetNativeWindow());
|
||||
params.native_widget = new AtomNativeWidgetMac(styleMask, widget());
|
||||
widget()->Init(params);
|
||||
window_ = static_cast<AtomNSWindow*>(widget()->GetNativeWindow());
|
||||
|
||||
[window_ setShell:this];
|
||||
[window_ setEnableLargerThanScreen:enable_larger_than_screen()];
|
||||
|
@ -1305,14 +1304,6 @@ gfx::Rect NativeWindowMac::WindowBoundsToContentBounds(
|
|||
}
|
||||
}
|
||||
|
||||
views::Widget* NativeWindowMac::GetWidget() {
|
||||
return widget_.get();
|
||||
}
|
||||
|
||||
const views::Widget* NativeWindowMac::GetWidget() const {
|
||||
return widget_.get();
|
||||
}
|
||||
|
||||
bool NativeWindowMac::CanResize() const {
|
||||
return resizable_;
|
||||
}
|
||||
|
|
|
@ -120,7 +120,6 @@ class NativeWindowClientView : public views::ClientView {
|
|||
NativeWindowViews::NativeWindowViews(const mate::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: NativeWindow(options, parent),
|
||||
widget_(new views::Widget),
|
||||
content_view_(nullptr),
|
||||
focused_view_(nullptr),
|
||||
menu_bar_autohide_(false),
|
||||
|
@ -1264,14 +1263,6 @@ bool NativeWindowViews::ShouldHandleSystemCommands() const {
|
|||
return true;
|
||||
}
|
||||
|
||||
views::Widget* NativeWindowViews::GetWidget() {
|
||||
return widget();
|
||||
}
|
||||
|
||||
const views::Widget* NativeWindowViews::GetWidget() const {
|
||||
return widget();
|
||||
}
|
||||
|
||||
views::View* NativeWindowViews::GetContentsView() {
|
||||
return this;
|
||||
}
|
||||
|
|
|
@ -138,7 +138,6 @@ class NativeWindowViews : public NativeWindow,
|
|||
void SetIcon(const gfx::ImageSkia& icon);
|
||||
#endif
|
||||
|
||||
views::Widget* widget() const { return widget_.get(); }
|
||||
views::View* content_view() const { return content_view_; }
|
||||
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
||||
|
||||
|
@ -160,8 +159,6 @@ class NativeWindowViews : public NativeWindow,
|
|||
bool CanMinimize() const override;
|
||||
base::string16 GetWindowTitle() const override;
|
||||
bool ShouldHandleSystemCommands() const override;
|
||||
views::Widget* GetWidget() override;
|
||||
const views::Widget* GetWidget() const override;
|
||||
views::View* GetContentsView() override;
|
||||
bool ShouldDescendIntoChildForEventHandling(
|
||||
gfx::NativeView child,
|
||||
|
@ -210,7 +207,6 @@ class NativeWindowViews : public NativeWindow,
|
|||
// Returns the restore state for the window.
|
||||
ui::WindowShowState GetRestoredState();
|
||||
|
||||
std::unique_ptr<views::Widget> widget_;
|
||||
views::View* content_view_; // Weak ref.
|
||||
views::View* focused_view_; // The view should be focused by default.
|
||||
|
||||
|
|
Loading…
Reference in a new issue