display WebContents as views::View on macOS
This commit is contained in:
parent
ada884a129
commit
a9709a635c
5 changed files with 106 additions and 17 deletions
|
@ -12,15 +12,23 @@
|
||||||
|
|
||||||
#include "atom/browser/native_window.h"
|
#include "atom/browser/native_window.h"
|
||||||
#include "base/mac/scoped_nsobject.h"
|
#include "base/mac/scoped_nsobject.h"
|
||||||
|
#include "ui/views/controls/native/native_view_host.h"
|
||||||
|
|
||||||
@class AtomNSWindow;
|
@class AtomNSWindow;
|
||||||
@class AtomNSWindowDelegate;
|
@class AtomNSWindowDelegate;
|
||||||
@class AtomPreviewItem;
|
@class AtomPreviewItem;
|
||||||
@class AtomTouchBar;
|
@class AtomTouchBar;
|
||||||
|
@class CustomWindowButtonView;
|
||||||
@class FullSizeContentView;
|
@class FullSizeContentView;
|
||||||
|
|
||||||
|
namespace views {
|
||||||
|
class NativeViewHost;
|
||||||
|
}
|
||||||
|
|
||||||
namespace atom {
|
namespace atom {
|
||||||
|
|
||||||
|
class RootViewMac;
|
||||||
|
|
||||||
class NativeWindowMac : public NativeWindow {
|
class NativeWindowMac : public NativeWindow {
|
||||||
public:
|
public:
|
||||||
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
|
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
|
||||||
|
@ -136,6 +144,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
};
|
};
|
||||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||||
|
|
||||||
|
views::View* content_view() { return content_view_; }
|
||||||
AtomPreviewItem* preview_item() const { return preview_item_.get(); }
|
AtomPreviewItem* preview_item() const { return preview_item_.get(); }
|
||||||
AtomTouchBar* touch_bar() const { return touch_bar_.get(); }
|
AtomTouchBar* touch_bar() const { return touch_bar_.get(); }
|
||||||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||||
|
@ -145,6 +154,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
protected:
|
protected:
|
||||||
// views::WidgetDelegate:
|
// views::WidgetDelegate:
|
||||||
bool CanResize() const override;
|
bool CanResize() const override;
|
||||||
|
views::View* GetContentsView() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||||
|
@ -157,6 +167,7 @@ class NativeWindowMac : public NativeWindow {
|
||||||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||||
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
||||||
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
||||||
|
base::scoped_nsobject<CustomWindowButtonView> buttons_view_;
|
||||||
|
|
||||||
// Event monitor for scroll wheel event.
|
// Event monitor for scroll wheel event.
|
||||||
id wheel_event_monitor_;
|
id wheel_event_monitor_;
|
||||||
|
@ -164,8 +175,11 @@ class NativeWindowMac : public NativeWindow {
|
||||||
// The view that will fill the whole frameless window.
|
// The view that will fill the whole frameless window.
|
||||||
base::scoped_nsobject<FullSizeContentView> container_view_;
|
base::scoped_nsobject<FullSizeContentView> container_view_;
|
||||||
|
|
||||||
// The content view passed by SetContentView, weak ref.
|
// The view that fills the client area.
|
||||||
NSView* content_view_;
|
std::unique_ptr<RootViewMac> root_view_;
|
||||||
|
|
||||||
|
// The content view, managed by widget_.
|
||||||
|
views::NativeViewHost* content_view_;
|
||||||
|
|
||||||
bool is_kiosk_;
|
bool is_kiosk_;
|
||||||
bool was_fullscreen_;
|
bool was_fullscreen_;
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include "atom/browser/ui/cocoa/atom_ns_window_delegate.h"
|
#include "atom/browser/ui/cocoa/atom_ns_window_delegate.h"
|
||||||
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
#include "atom/browser/ui/cocoa/atom_preview_item.h"
|
||||||
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
#include "atom/browser/ui/cocoa/atom_touch_bar.h"
|
||||||
|
#include "atom/browser/ui/cocoa/root_view_mac.h"
|
||||||
#include "atom/browser/window_list.h"
|
#include "atom/browser/window_list.h"
|
||||||
#include "atom/common/options_switches.h"
|
#include "atom/common/options_switches.h"
|
||||||
#include "base/mac/mac_util.h"
|
#include "base/mac/mac_util.h"
|
||||||
|
@ -236,7 +237,8 @@ namespace atom {
|
||||||
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||||
NativeWindow* parent)
|
NativeWindow* parent)
|
||||||
: NativeWindow(options, parent),
|
: NativeWindow(options, parent),
|
||||||
content_view_(nil),
|
root_view_(new RootViewMac(this)),
|
||||||
|
content_view_(nullptr),
|
||||||
is_kiosk_(false),
|
is_kiosk_(false),
|
||||||
was_fullscreen_(false),
|
was_fullscreen_(false),
|
||||||
zoom_to_page_width_(false),
|
zoom_to_page_width_(false),
|
||||||
|
@ -458,9 +460,9 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||||
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
||||||
|
|
||||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||||
NSView* buttonsView = [[[CustomWindowButtonView alloc]
|
buttons_view_.reset(
|
||||||
initWithFrame:NSZeroRect] autorelease];
|
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);
|
||||||
[[window_ contentView] addSubview:buttonsView];
|
[[window_ contentView] addSubview:buttons_view_];
|
||||||
} else {
|
} else {
|
||||||
if (title_bar_style_ != NORMAL) {
|
if (title_bar_style_ != NORMAL) {
|
||||||
if (base::mac::IsOS10_9()) {
|
if (base::mac::IsOS10_9()) {
|
||||||
|
@ -490,21 +492,21 @@ NativeWindowMac::~NativeWindowMac() {
|
||||||
|
|
||||||
void NativeWindowMac::SetContentView(
|
void NativeWindowMac::SetContentView(
|
||||||
brightray::InspectableWebContents* web_contents) {
|
brightray::InspectableWebContents* web_contents) {
|
||||||
|
views::View* root_view = GetContentsView();
|
||||||
if (content_view_)
|
if (content_view_)
|
||||||
[content_view_ removeFromSuperview];
|
root_view->RemoveChildView(content_view_);
|
||||||
|
|
||||||
content_view_ = web_contents->GetView()->GetNativeView();
|
content_view_ = new views::NativeViewHost();
|
||||||
[content_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
root_view->AddChildView(content_view_);
|
||||||
[content_view_ setFrame:[[window_ contentView] bounds]];
|
content_view_->Attach(web_contents->GetView()->GetNativeView());
|
||||||
|
|
||||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
if (buttons_view_) {
|
||||||
NSView* buttonsView = [[[window_ contentView] subviews] lastObject];
|
// Ensure the buttons view are always floated on the top.
|
||||||
[[window_ contentView] addSubview:content_view_
|
[buttons_view_ removeFromSuperview];
|
||||||
positioned:NSWindowBelow
|
[[window_ contentView] addSubview:buttons_view_];
|
||||||
relativeTo:buttonsView];
|
|
||||||
} else {
|
|
||||||
[[window_ contentView] addSubview:content_view_];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
root_view->Layout();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NativeWindowMac::Close() {
|
void NativeWindowMac::Close() {
|
||||||
|
@ -1302,6 +1304,10 @@ bool NativeWindowMac::CanResize() const {
|
||||||
return resizable_;
|
return resizable_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
views::View* NativeWindowMac::GetContentsView() {
|
||||||
|
return root_view_.get();
|
||||||
|
}
|
||||||
|
|
||||||
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
|
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
|
||||||
bool attach) {
|
bool attach) {
|
||||||
if (is_modal())
|
if (is_modal())
|
||||||
|
|
33
atom/browser/ui/cocoa/root_view_mac.h
Normal file
33
atom/browser/ui/cocoa/root_view_mac.h
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
// Copyright (c) 2018 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#ifndef ATOM_BROWSER_UI_COCOA_ROOT_VIEW_MAC_H_
|
||||||
|
#define ATOM_BROWSER_UI_COCOA_ROOT_VIEW_MAC_H_
|
||||||
|
|
||||||
|
#include "ui/views/view.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
class NativeWindow;
|
||||||
|
|
||||||
|
class RootViewMac : public views::View {
|
||||||
|
public:
|
||||||
|
explicit RootViewMac(NativeWindow* window);
|
||||||
|
~RootViewMac() override;
|
||||||
|
|
||||||
|
// views::View:
|
||||||
|
void Layout() override;
|
||||||
|
gfx::Size GetMinimumSize() const override;
|
||||||
|
gfx::Size GetMaximumSize() const override;
|
||||||
|
|
||||||
|
private:
|
||||||
|
// Parent window, weak ref.
|
||||||
|
NativeWindow* window_;
|
||||||
|
|
||||||
|
DISALLOW_COPY_AND_ASSIGN(RootViewMac);
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace atom
|
||||||
|
|
||||||
|
#endif // ATOM_BROWSER_UI_COCOA_ROOT_VIEW_MAC_H_
|
34
atom/browser/ui/cocoa/root_view_mac.mm
Normal file
34
atom/browser/ui/cocoa/root_view_mac.mm
Normal file
|
@ -0,0 +1,34 @@
|
||||||
|
// Copyright (c) 2018 GitHub, Inc.
|
||||||
|
// Use of this source code is governed by the MIT license that can be
|
||||||
|
// found in the LICENSE file.
|
||||||
|
|
||||||
|
#include "atom/browser/ui/cocoa/root_view_mac.h"
|
||||||
|
|
||||||
|
#include "atom/browser/native_window_mac.h"
|
||||||
|
|
||||||
|
namespace atom {
|
||||||
|
|
||||||
|
RootViewMac::RootViewMac(NativeWindow* window) : window_(window) {
|
||||||
|
set_owned_by_client();
|
||||||
|
}
|
||||||
|
|
||||||
|
RootViewMac::~RootViewMac() {}
|
||||||
|
|
||||||
|
void RootViewMac::Layout() {
|
||||||
|
views::View* content_view =
|
||||||
|
static_cast<NativeWindowMac*>(window_)->content_view();
|
||||||
|
if (!content_view) // Not ready yet.
|
||||||
|
return;
|
||||||
|
|
||||||
|
content_view->SetBoundsRect(gfx::Rect(gfx::Point(), size()));
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Size RootViewMac::GetMinimumSize() const {
|
||||||
|
return window_->GetMinimumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
gfx::Size RootViewMac::GetMaximumSize() const {
|
||||||
|
return window_->GetMaximumSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
} // namespace atom
|
|
@ -330,6 +330,8 @@
|
||||||
'atom/browser/ui/cocoa/atom_touch_bar.mm',
|
'atom/browser/ui/cocoa/atom_touch_bar.mm',
|
||||||
'atom/browser/ui/cocoa/views_delegate_mac.h',
|
'atom/browser/ui/cocoa/views_delegate_mac.h',
|
||||||
'atom/browser/ui/cocoa/views_delegate_mac.mm',
|
'atom/browser/ui/cocoa/views_delegate_mac.mm',
|
||||||
|
'atom/browser/ui/cocoa/root_view_mac.mm',
|
||||||
|
'atom/browser/ui/cocoa/root_view_mac.h',
|
||||||
'atom/browser/ui/cocoa/touch_bar_forward_declarations.h',
|
'atom/browser/ui/cocoa/touch_bar_forward_declarations.h',
|
||||||
'atom/browser/ui/drag_util_mac.mm',
|
'atom/browser/ui/drag_util_mac.mm',
|
||||||
'atom/browser/ui/drag_util_views.cc',
|
'atom/browser/ui/drag_util_views.cc',
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue