display WebContents as views::View on macOS
This commit is contained in:
Родитель
ada884a129
Коммит
a9709a635c
|
@ -12,15 +12,23 @@
|
|||
|
||||
#include "atom/browser/native_window.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "ui/views/controls/native/native_view_host.h"
|
||||
|
||||
@class AtomNSWindow;
|
||||
@class AtomNSWindowDelegate;
|
||||
@class AtomPreviewItem;
|
||||
@class AtomTouchBar;
|
||||
@class CustomWindowButtonView;
|
||||
@class FullSizeContentView;
|
||||
|
||||
namespace views {
|
||||
class NativeViewHost;
|
||||
}
|
||||
|
||||
namespace atom {
|
||||
|
||||
class RootViewMac;
|
||||
|
||||
class NativeWindowMac : public NativeWindow {
|
||||
public:
|
||||
NativeWindowMac(const mate::Dictionary& options, NativeWindow* parent);
|
||||
|
@ -136,6 +144,7 @@ class NativeWindowMac : public NativeWindow {
|
|||
};
|
||||
TitleBarStyle title_bar_style() const { return title_bar_style_; }
|
||||
|
||||
views::View* content_view() { return content_view_; }
|
||||
AtomPreviewItem* preview_item() const { return preview_item_.get(); }
|
||||
AtomTouchBar* touch_bar() const { return touch_bar_.get(); }
|
||||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||
|
@ -145,6 +154,7 @@ class NativeWindowMac : public NativeWindow {
|
|||
protected:
|
||||
// views::WidgetDelegate:
|
||||
bool CanResize() const override;
|
||||
views::View* GetContentsView() override;
|
||||
|
||||
private:
|
||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||
|
@ -157,6 +167,7 @@ class NativeWindowMac : public NativeWindow {
|
|||
base::scoped_nsobject<AtomNSWindowDelegate> window_delegate_;
|
||||
base::scoped_nsobject<AtomPreviewItem> preview_item_;
|
||||
base::scoped_nsobject<AtomTouchBar> touch_bar_;
|
||||
base::scoped_nsobject<CustomWindowButtonView> buttons_view_;
|
||||
|
||||
// Event monitor for scroll wheel event.
|
||||
id wheel_event_monitor_;
|
||||
|
@ -164,8 +175,11 @@ class NativeWindowMac : public NativeWindow {
|
|||
// The view that will fill the whole frameless window.
|
||||
base::scoped_nsobject<FullSizeContentView> container_view_;
|
||||
|
||||
// The content view passed by SetContentView, weak ref.
|
||||
NSView* content_view_;
|
||||
// The view that fills the client area.
|
||||
std::unique_ptr<RootViewMac> root_view_;
|
||||
|
||||
// The content view, managed by widget_.
|
||||
views::NativeViewHost* content_view_;
|
||||
|
||||
bool is_kiosk_;
|
||||
bool was_fullscreen_;
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
#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_touch_bar.h"
|
||||
#include "atom/browser/ui/cocoa/root_view_mac.h"
|
||||
#include "atom/browser/window_list.h"
|
||||
#include "atom/common/options_switches.h"
|
||||
#include "base/mac/mac_util.h"
|
||||
|
@ -236,7 +237,8 @@ namespace atom {
|
|||
NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: NativeWindow(options, parent),
|
||||
content_view_(nil),
|
||||
root_view_(new RootViewMac(this)),
|
||||
content_view_(nullptr),
|
||||
is_kiosk_(false),
|
||||
was_fullscreen_(false),
|
||||
zoom_to_page_width_(false),
|
||||
|
@ -458,9 +460,9 @@ NativeWindowMac::NativeWindowMac(const mate::Dictionary& options,
|
|||
[[window_ standardWindowButton:NSWindowFullScreenButton] setHidden:YES];
|
||||
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||
NSView* buttonsView = [[[CustomWindowButtonView alloc]
|
||||
initWithFrame:NSZeroRect] autorelease];
|
||||
[[window_ contentView] addSubview:buttonsView];
|
||||
buttons_view_.reset(
|
||||
[[CustomWindowButtonView alloc] initWithFrame:NSZeroRect]);
|
||||
[[window_ contentView] addSubview:buttons_view_];
|
||||
} else {
|
||||
if (title_bar_style_ != NORMAL) {
|
||||
if (base::mac::IsOS10_9()) {
|
||||
|
@ -490,21 +492,21 @@ NativeWindowMac::~NativeWindowMac() {
|
|||
|
||||
void NativeWindowMac::SetContentView(
|
||||
brightray::InspectableWebContents* web_contents) {
|
||||
views::View* root_view = GetContentsView();
|
||||
if (content_view_)
|
||||
[content_view_ removeFromSuperview];
|
||||
root_view->RemoveChildView(content_view_);
|
||||
|
||||
content_view_ = web_contents->GetView()->GetNativeView();
|
||||
[content_view_ setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
|
||||
[content_view_ setFrame:[[window_ contentView] bounds]];
|
||||
content_view_ = new views::NativeViewHost();
|
||||
root_view->AddChildView(content_view_);
|
||||
content_view_->Attach(web_contents->GetView()->GetNativeView());
|
||||
|
||||
if (title_bar_style_ == CUSTOM_BUTTONS_ON_HOVER) {
|
||||
NSView* buttonsView = [[[window_ contentView] subviews] lastObject];
|
||||
[[window_ contentView] addSubview:content_view_
|
||||
positioned:NSWindowBelow
|
||||
relativeTo:buttonsView];
|
||||
} else {
|
||||
[[window_ contentView] addSubview:content_view_];
|
||||
if (buttons_view_) {
|
||||
// Ensure the buttons view are always floated on the top.
|
||||
[buttons_view_ removeFromSuperview];
|
||||
[[window_ contentView] addSubview:buttons_view_];
|
||||
}
|
||||
|
||||
root_view->Layout();
|
||||
}
|
||||
|
||||
void NativeWindowMac::Close() {
|
||||
|
@ -1302,6 +1304,10 @@ bool NativeWindowMac::CanResize() const {
|
|||
return resizable_;
|
||||
}
|
||||
|
||||
views::View* NativeWindowMac::GetContentsView() {
|
||||
return root_view_.get();
|
||||
}
|
||||
|
||||
void NativeWindowMac::InternalSetParentWindow(NativeWindow* parent,
|
||||
bool attach) {
|
||||
if (is_modal())
|
||||
|
|
|
@ -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_
|
|
@ -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/views_delegate_mac.h',
|
||||
'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/drag_util_mac.mm',
|
||||
'atom/browser/ui/drag_util_views.cc',
|
||||
|
|
Загрузка…
Ссылка в новой задаче