Add NativeWindow::SetContentView
This commit is contained in:
parent
13473ee138
commit
56735d4ff5
6 changed files with 81 additions and 68 deletions
|
@ -150,9 +150,9 @@ void BrowserWindow::Init(v8::Isolate* isolate,
|
||||||
|
|
||||||
// Creates BrowserWindow.
|
// Creates BrowserWindow.
|
||||||
window_.reset(NativeWindow::Create(
|
window_.reset(NativeWindow::Create(
|
||||||
web_contents->managed_web_contents(),
|
|
||||||
options,
|
options,
|
||||||
parent.IsEmpty() ? nullptr : parent->window_.get()));
|
parent.IsEmpty() ? nullptr : parent->window_.get()));
|
||||||
|
window_->SetContentView(web_contents->managed_web_contents());
|
||||||
web_contents->SetOwnerWindow(window_.get());
|
web_contents->SetOwnerWindow(window_.get());
|
||||||
|
|
||||||
// Tell the content module to initialize renderer widget with transparent
|
// Tell the content module to initialize renderer widget with transparent
|
||||||
|
|
|
@ -53,13 +53,14 @@ class NativeWindow : public base::SupportsUserData {
|
||||||
|
|
||||||
// Create window with existing WebContents, the caller is responsible for
|
// Create window with existing WebContents, the caller is responsible for
|
||||||
// managing the window's live.
|
// managing the window's live.
|
||||||
static NativeWindow* Create(
|
static NativeWindow* Create(const mate::Dictionary& options,
|
||||||
brightray::InspectableWebContents* inspectable_web_contents,
|
NativeWindow* parent = nullptr);
|
||||||
const mate::Dictionary& options,
|
|
||||||
NativeWindow* parent = nullptr);
|
|
||||||
|
|
||||||
void InitFromOptions(const mate::Dictionary& options);
|
void InitFromOptions(const mate::Dictionary& options);
|
||||||
|
|
||||||
|
virtual void SetContentView(
|
||||||
|
brightray::InspectableWebContents* web_contents) = 0;
|
||||||
|
|
||||||
virtual void Close() = 0;
|
virtual void Close() = 0;
|
||||||
virtual void CloseImmediately() = 0;
|
virtual void CloseImmediately() = 0;
|
||||||
virtual bool IsClosed() const { return is_closed_; }
|
virtual bool IsClosed() const { return is_closed_; }
|
||||||
|
|
|
@ -21,12 +21,12 @@ namespace atom {
|
||||||
|
|
||||||
class NativeWindowMac : public NativeWindow {
|
class NativeWindowMac : public NativeWindow {
|
||||||
public:
|
public:
|
||||||
NativeWindowMac(brightray::InspectableWebContents* inspectable_web_contents,
|
NativeWindowMac(const mate::Dictionary& options,
|
||||||
const mate::Dictionary& options,
|
|
||||||
NativeWindow* parent);
|
NativeWindow* parent);
|
||||||
~NativeWindowMac() override;
|
~NativeWindowMac() override;
|
||||||
|
|
||||||
// NativeWindow:
|
// NativeWindow:
|
||||||
|
void SetContentView(brightray::InspectableWebContents* web_contents) override;
|
||||||
void Close() override;
|
void Close() override;
|
||||||
void CloseImmediately() override;
|
void CloseImmediately() override;
|
||||||
void Focus(bool focus) override;
|
void Focus(bool focus) override;
|
||||||
|
|
|
@ -776,10 +776,8 @@ struct Converter<atom::NativeWindowMac::TitleBarStyle> {
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
NativeWindowMac::NativeWindowMac(
|
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||||
brightray::InspectableWebContents* web_contents,
|
NativeWindow* parent)
|
||||||
const mate::Dictionary& options,
|
|
||||||
NativeWindow* parent)
|
|
||||||
: NativeWindow(options, parent),
|
: NativeWindow(options, parent),
|
||||||
is_kiosk_(false),
|
is_kiosk_(false),
|
||||||
was_fullscreen_(false),
|
was_fullscreen_(false),
|
||||||
|
@ -952,9 +950,6 @@ NativeWindowMac::NativeWindowMac(
|
||||||
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
options.Get(options::kDisableAutoHideCursor, &disableAutoHideCursor);
|
||||||
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
[window_ setDisableAutoHideCursor:disableAutoHideCursor];
|
||||||
|
|
||||||
NSView* view = web_contents->GetView()->GetNativeView();
|
|
||||||
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
|
||||||
|
|
||||||
// Use an NSEvent monitor to listen for the wheel event.
|
// Use an NSEvent monitor to listen for the wheel event.
|
||||||
BOOL __block began = NO;
|
BOOL __block began = NO;
|
||||||
wheel_event_monitor_ = [NSEvent
|
wheel_event_monitor_ = [NSEvent
|
||||||
|
@ -975,8 +970,6 @@ NativeWindowMac::NativeWindowMac(
|
||||||
return event;
|
return event;
|
||||||
}];
|
}];
|
||||||
|
|
||||||
InstallView(web_contents->GetView()->GetNativeView());
|
|
||||||
|
|
||||||
std::string type;
|
std::string type;
|
||||||
if (options.Get(options::kVibrancyType, &type)) {
|
if (options.Get(options::kVibrancyType, &type)) {
|
||||||
SetVibrancy(type);
|
SetVibrancy(type);
|
||||||
|
@ -991,6 +984,16 @@ NativeWindowMac::~NativeWindowMac() {
|
||||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowMac::SetContentView(
|
||||||
|
brightray::InspectableWebContents* web_contents) {
|
||||||
|
// TODO(zcbenz): Uninstall view first.
|
||||||
|
// TODO(zcbenz): Handle vibrancy.
|
||||||
|
// TODO(zcbenz): Handle draggable regions.
|
||||||
|
NSView* view = web_contents->GetView()->GetNativeView();
|
||||||
|
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||||
|
InstallView(web_contents->GetView()->GetNativeView());
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::Close() {
|
void NativeWindowMac::Close() {
|
||||||
// When this is a sheet showing, performClose won't work.
|
// When this is a sheet showing, performClose won't work.
|
||||||
if (is_modal() && parent() && IsVisible()) {
|
if (is_modal() && parent() && IsVisible()) {
|
||||||
|
@ -1860,11 +1863,9 @@ void NativeWindowMac::SetCollectionBehavior(bool on, NSUInteger flag) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
NativeWindow* NativeWindow::Create(
|
NativeWindow* NativeWindow::Create(const mate::Dictionary& options,
|
||||||
brightray::InspectableWebContents* inspectable_web_contents,
|
NativeWindow* parent) {
|
||||||
const mate::Dictionary& options,
|
return new NativeWindowMac(options, parent);
|
||||||
NativeWindow* parent) {
|
|
||||||
return new NativeWindowMac(inspectable_web_contents, options, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -118,14 +118,12 @@ class NativeWindowClientView : public views::ClientView {
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
NativeWindowViews::NativeWindowViews(
|
NativeWindowViews::NativeWindowViews(const mate::Dictionary& options,
|
||||||
brightray::InspectableWebContents* web_contents,
|
NativeWindow* parent)
|
||||||
const mate::Dictionary& options,
|
|
||||||
NativeWindow* parent)
|
|
||||||
: NativeWindow(options, parent),
|
: NativeWindow(options, parent),
|
||||||
window_(new views::Widget),
|
window_(new views::Widget),
|
||||||
content_view_(web_contents->GetView()->GetView()),
|
content_view_(nullptr),
|
||||||
focused_view_(web_contents->GetView()->GetWebView()),
|
focused_view_(nullptr),
|
||||||
menu_bar_autohide_(false),
|
menu_bar_autohide_(false),
|
||||||
menu_bar_visible_(false),
|
menu_bar_visible_(false),
|
||||||
menu_bar_alt_pressed_(false),
|
menu_bar_alt_pressed_(false),
|
||||||
|
@ -266,8 +264,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
SetWindowType(GetAcceleratedWidget(), window_type);
|
SetWindowType(GetAcceleratedWidget(), window_type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
AddChildView(content_view_);
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
if (!has_frame()) {
|
if (!has_frame()) {
|
||||||
// Set Window style so that we get a minimize and maximize animation when
|
// Set Window style so that we get a minimize and maximize animation when
|
||||||
|
@ -310,7 +306,6 @@ NativeWindowViews::NativeWindowViews(
|
||||||
size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();
|
size = ContentBoundsToWindowBounds(gfx::Rect(size)).size();
|
||||||
|
|
||||||
window_->CenterWindow(size);
|
window_->CenterWindow(size);
|
||||||
Layout();
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// Save initial window state.
|
// Save initial window state.
|
||||||
|
@ -331,6 +326,22 @@ NativeWindowViews::~NativeWindowViews() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowViews::SetContentView(
|
||||||
|
brightray::InspectableWebContents* web_contents) {
|
||||||
|
if (content_view_) {
|
||||||
|
RemoveChildView(content_view_);
|
||||||
|
if (browser_view()) {
|
||||||
|
content_view_->RemoveChildView(
|
||||||
|
browser_view()->GetInspectableWebContentsView()->GetView());
|
||||||
|
set_browser_view(nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
content_view_ = web_contents->GetView()->GetView();
|
||||||
|
focused_view_ = web_contents->GetView()->GetWebView();
|
||||||
|
AddChildView(content_view_);
|
||||||
|
Layout();
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::Close() {
|
void NativeWindowViews::Close() {
|
||||||
if (!IsClosable()) {
|
if (!IsClosable()) {
|
||||||
WindowList::WindowCloseCancelled(this);
|
WindowList::WindowCloseCancelled(this);
|
||||||
|
@ -412,6 +423,33 @@ bool NativeWindowViews::IsEnabled() {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void NativeWindowViews::SetEnabled(bool enable) {
|
||||||
|
// Handle multiple calls of SetEnabled correctly.
|
||||||
|
if (enable) {
|
||||||
|
--disable_count_;
|
||||||
|
if (disable_count_ != 0)
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
++disable_count_;
|
||||||
|
if (disable_count_ != 1)
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#if defined(OS_WIN)
|
||||||
|
::EnableWindow(GetAcceleratedWidget(), enable);
|
||||||
|
#elif defined(USE_X11)
|
||||||
|
views::DesktopWindowTreeHostX11* tree_host =
|
||||||
|
views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
|
||||||
|
if (enable) {
|
||||||
|
tree_host->RemoveEventRewriter(event_disabler_.get());
|
||||||
|
event_disabler_.reset();
|
||||||
|
} else {
|
||||||
|
event_disabler_.reset(new EventDisabler);
|
||||||
|
tree_host->AddEventRewriter(event_disabler_.get());
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowViews::Maximize() {
|
void NativeWindowViews::Maximize() {
|
||||||
#if defined(OS_WIN)
|
#if defined(OS_WIN)
|
||||||
// For window without WS_THICKFRAME style, we can not call Maximize().
|
// For window without WS_THICKFRAME style, we can not call Maximize().
|
||||||
|
@ -544,7 +582,7 @@ gfx::Rect NativeWindowViews::GetBounds() {
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Rect NativeWindowViews::GetContentBounds() {
|
gfx::Rect NativeWindowViews::GetContentBounds() {
|
||||||
return content_view_->GetBoundsInScreen();
|
return content_view_ ? content_view_->GetBoundsInScreen() : gfx::Rect();
|
||||||
}
|
}
|
||||||
|
|
||||||
gfx::Size NativeWindowViews::GetContentSize() {
|
gfx::Size NativeWindowViews::GetContentSize() {
|
||||||
|
@ -553,7 +591,7 @@ gfx::Size NativeWindowViews::GetContentSize() {
|
||||||
return NativeWindow::GetContentSize();
|
return NativeWindow::GetContentSize();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return content_view_->size();
|
return content_view_ ? content_view_->size() : gfx::Size();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetContentSizeConstraints(
|
void NativeWindowViews::SetContentSizeConstraints(
|
||||||
|
@ -933,6 +971,9 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowViews::SetBrowserView(NativeBrowserView* view) {
|
void NativeWindowViews::SetBrowserView(NativeBrowserView* view) {
|
||||||
|
if (!content_view_)
|
||||||
|
return;
|
||||||
|
|
||||||
if (browser_view()) {
|
if (browser_view()) {
|
||||||
content_view_->RemoveChildView(
|
content_view_->RemoveChildView(
|
||||||
browser_view()->GetInspectableWebContentsView()->GetView());
|
browser_view()->GetInspectableWebContentsView()->GetView());
|
||||||
|
@ -1129,33 +1170,6 @@ void NativeWindowViews::SetIcon(const gfx::ImageSkia& icon) {
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void NativeWindowViews::SetEnabled(bool enable) {
|
|
||||||
// Handle multiple calls of SetEnabled correctly.
|
|
||||||
if (enable) {
|
|
||||||
--disable_count_;
|
|
||||||
if (disable_count_ != 0)
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
++disable_count_;
|
|
||||||
if (disable_count_ != 1)
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(OS_WIN)
|
|
||||||
::EnableWindow(GetAcceleratedWidget(), enable);
|
|
||||||
#elif defined(USE_X11)
|
|
||||||
views::DesktopWindowTreeHostX11* tree_host =
|
|
||||||
views::DesktopWindowTreeHostX11::GetHostForXID(GetAcceleratedWidget());
|
|
||||||
if (enable) {
|
|
||||||
tree_host->RemoveEventRewriter(event_disabler_.get());
|
|
||||||
event_disabler_.reset();
|
|
||||||
} else {
|
|
||||||
event_disabler_.reset(new EventDisabler);
|
|
||||||
tree_host->AddEventRewriter(event_disabler_.get());
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void NativeWindowViews::OnWidgetActivationChanged(
|
void NativeWindowViews::OnWidgetActivationChanged(
|
||||||
views::Widget* widget, bool active) {
|
views::Widget* widget, bool active) {
|
||||||
if (widget != window_.get())
|
if (widget != window_.get())
|
||||||
|
@ -1399,11 +1413,9 @@ ui::WindowShowState NativeWindowViews::GetRestoredState() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// static
|
// static
|
||||||
NativeWindow* NativeWindow::Create(
|
NativeWindow* NativeWindow::Create(const mate::Dictionary& options,
|
||||||
brightray::InspectableWebContents* inspectable_web_contents,
|
NativeWindow* parent) {
|
||||||
const mate::Dictionary& options,
|
return new NativeWindowViews(options, parent);
|
||||||
NativeWindow* parent) {
|
|
||||||
return new NativeWindowViews(inspectable_web_contents, options, parent);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace atom
|
} // namespace atom
|
||||||
|
|
|
@ -46,12 +46,12 @@ class NativeWindowViews : public NativeWindow,
|
||||||
public views::WidgetDelegateView,
|
public views::WidgetDelegateView,
|
||||||
public views::WidgetObserver {
|
public views::WidgetObserver {
|
||||||
public:
|
public:
|
||||||
NativeWindowViews(brightray::InspectableWebContents* inspectable_web_contents,
|
NativeWindowViews(const mate::Dictionary& options,
|
||||||
const mate::Dictionary& options,
|
|
||||||
NativeWindow* parent);
|
NativeWindow* parent);
|
||||||
~NativeWindowViews() override;
|
~NativeWindowViews() override;
|
||||||
|
|
||||||
// NativeWindow:
|
// NativeWindow:
|
||||||
|
void SetContentView(brightray::InspectableWebContents* web_contents) override;
|
||||||
void Close() override;
|
void Close() override;
|
||||||
void CloseImmediately() override;
|
void CloseImmediately() override;
|
||||||
void Focus(bool focus) override;
|
void Focus(bool focus) override;
|
||||||
|
@ -61,6 +61,7 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void Hide() override;
|
void Hide() override;
|
||||||
bool IsVisible() override;
|
bool IsVisible() override;
|
||||||
bool IsEnabled() override;
|
bool IsEnabled() override;
|
||||||
|
void SetEnabled(bool enable) override;
|
||||||
void Maximize() override;
|
void Maximize() override;
|
||||||
void Unmaximize() override;
|
void Unmaximize() override;
|
||||||
bool IsMaximized() override;
|
bool IsMaximized() override;
|
||||||
|
@ -139,8 +140,6 @@ class NativeWindowViews : public NativeWindow,
|
||||||
void SetIcon(const gfx::ImageSkia& icon);
|
void SetIcon(const gfx::ImageSkia& icon);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void SetEnabled(bool enable) override;
|
|
||||||
|
|
||||||
views::Widget* widget() const { return window_.get(); }
|
views::Widget* widget() const { return window_.get(); }
|
||||||
views::View* content_view() const { return content_view_; }
|
views::View* content_view() const { return content_view_; }
|
||||||
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
SkRegion* draggable_region() const { return draggable_region_.get(); }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue