Save browser_view_ in the NativeWindow

No need to store it separately in subclasses.
This commit is contained in:
Cheng Zhao 2018-03-06 15:04:40 +09:00
parent 503b0ba1b1
commit 3b3e69f8b2
8 changed files with 34 additions and 33 deletions

View file

@ -6,8 +6,7 @@
#import <Cocoa/Cocoa.h> #import <Cocoa/Cocoa.h>
#include "atom/browser/native_browser_view_mac.h" #include "atom/browser/native_browser_view.h"
#include "atom/browser/native_window_mac.h"
#include "atom/common/draggable_region.h" #include "atom/common/draggable_region.h"
#include "base/mac/scoped_nsobject.h" #include "base/mac/scoped_nsobject.h"
@ -90,9 +89,8 @@ void BrowserWindow::UpdateDraggableRegions(
DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight); DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight);
} }
NativeWindowMac* window = static_cast<NativeWindowMac*>(window_.get()); if (window_->browser_view())
if (window->browser_view()) window_->browser_view()->UpdateDraggableRegions(system_drag_exclude_areas);
window->browser_view()->UpdateDraggableRegions(system_drag_exclude_areas);
// Create and add a ControlRegionView for each region that needs to be // Create and add a ControlRegionView for each region that needs to be
// excluded from the dragging. // excluded from the dragging.

View file

@ -4,6 +4,8 @@
#include "atom/browser/api/atom_api_browser_window.h" #include "atom/browser/api/atom_api_browser_window.h"
#include "atom/browser/native_window_views.h"
namespace atom { namespace atom {
namespace api { namespace api {
@ -13,7 +15,8 @@ void BrowserWindow::UpdateDraggableRegions(
const std::vector<DraggableRegion>& regions) { const std::vector<DraggableRegion>& regions) {
if (window_->has_frame()) if (window_->has_frame())
return; return;
window_->UpdateDraggableRegions(DraggableRegionsToSkRegion(regions)); static_cast<NativeWindowViews*>(window_.get())->UpdateDraggableRegions(
DraggableRegionsToSkRegion(regions));
} }
} // namespace api } // namespace api

View file

@ -58,6 +58,7 @@ NativeWindow::NativeWindow(
is_modal_(false), is_modal_(false),
is_osr_dummy_(false), is_osr_dummy_(false),
inspectable_web_contents_(inspectable_web_contents), inspectable_web_contents_(inspectable_web_contents),
browser_view_(nullptr),
weak_factory_(this) { weak_factory_(this) {
options.Get(options::kFrame, &has_frame_); options.Get(options::kFrame, &has_frame_);
options.Get(options::kTransparent, &transparent_); options.Get(options::kTransparent, &transparent_);

View file

@ -292,6 +292,7 @@ class NativeWindow : public base::SupportsUserData,
void set_is_offscreen_dummy(bool is_dummy) { is_osr_dummy_ = is_dummy; } void set_is_offscreen_dummy(bool is_dummy) { is_osr_dummy_ = is_dummy; }
bool is_offscreen_dummy() const { return is_osr_dummy_; } bool is_offscreen_dummy() const { return is_osr_dummy_; }
NativeBrowserView* browser_view() const { return browser_view_; }
NativeWindow* parent() const { return parent_; } NativeWindow* parent() const { return parent_; }
bool is_modal() const { return is_modal_; } bool is_modal() const { return is_modal_; }
@ -300,6 +301,10 @@ class NativeWindow : public base::SupportsUserData,
const mate::Dictionary& options, const mate::Dictionary& options,
NativeWindow* parent); NativeWindow* parent);
void set_browser_view(NativeBrowserView* browser_view) {
browser_view_ = browser_view;
}
private: private:
// Whether window has standard frame. // Whether window has standard frame.
bool has_frame_; bool has_frame_;
@ -335,6 +340,9 @@ class NativeWindow : public base::SupportsUserData,
// Is this a dummy window for an offscreen WebContents. // Is this a dummy window for an offscreen WebContents.
bool is_osr_dummy_; bool is_osr_dummy_;
// The browser view layer.
NativeBrowserView* browser_view_;
// The page this window is viewing. // The page this window is viewing.
brightray::InspectableWebContents* inspectable_web_contents_; brightray::InspectableWebContents* inspectable_web_contents_;

View file

@ -135,7 +135,6 @@ class NativeWindowMac : public NativeWindow {
bool zoom_to_page_width() const { return zoom_to_page_width_; } bool zoom_to_page_width() const { return zoom_to_page_width_; }
bool fullscreen_window_title() const { return fullscreen_window_title_; } bool fullscreen_window_title() const { return fullscreen_window_title_; }
bool simple_fullscreen() const { return always_simple_fullscreen_; } bool simple_fullscreen() const { return always_simple_fullscreen_; }
NativeBrowserView* browser_view() const { return browser_view_; }
private: private:
void InternalSetParentWindow(NativeWindow* parent, bool attach); void InternalSetParentWindow(NativeWindow* parent, bool attach);
@ -153,8 +152,6 @@ 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> content_view_; base::scoped_nsobject<FullSizeContentView> content_view_;
NativeBrowserView* browser_view_;
bool is_kiosk_; bool is_kiosk_;
bool was_fullscreen_; bool was_fullscreen_;

View file

@ -782,7 +782,6 @@ NativeWindowMac::NativeWindowMac(
const mate::Dictionary& options, const mate::Dictionary& options,
NativeWindow* parent) NativeWindow* parent)
: NativeWindow(web_contents, options, parent), : NativeWindow(web_contents, options, parent),
browser_view_(nullptr),
is_kiosk_(false), is_kiosk_(false),
was_fullscreen_(false), was_fullscreen_(false),
zoom_to_page_width_(false), zoom_to_page_width_(false),
@ -1494,20 +1493,19 @@ void NativeWindowMac::SetContentProtection(bool enable) {
: NSWindowSharingReadOnly]; : NSWindowSharingReadOnly];
} }
void NativeWindowMac::SetBrowserView(NativeBrowserView* browser_view) { void NativeWindowMac::SetBrowserView(NativeBrowserView* view) {
if (browser_view_) { if (browser_view()) {
[browser_view_->GetInspectableWebContentsView()->GetNativeView() [browser_view()->GetInspectableWebContentsView()->GetNativeView()
removeFromSuperview]; removeFromSuperview];
browser_view_ = nullptr; set_browser_view(nullptr);
} }
if (!browser_view) { if (!view) {
return; return;
} }
browser_view_ = browser_view; set_browser_view(view);
auto* native_view = auto* native_view = view->GetInspectableWebContentsView()->GetNativeView();
browser_view->GetInspectableWebContentsView()->GetNativeView();
[[window_ contentView] addSubview:native_view [[window_ contentView] addSubview:native_view
positioned:NSWindowAbove positioned:NSWindowAbove
relativeTo:nil]; relativeTo:nil];

View file

@ -141,7 +141,6 @@ NativeWindowViews::NativeWindowViews(
: NativeWindow(web_contents, options, parent), : NativeWindow(web_contents, options, parent),
window_(new views::Widget), window_(new views::Widget),
web_view_(inspectable_web_contents()->GetView()->GetView()), web_view_(inspectable_web_contents()->GetView()->GetView()),
browser_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),
@ -948,22 +947,21 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
Layout(); Layout();
} }
void NativeWindowViews::SetBrowserView(NativeBrowserView* browser_view) { void NativeWindowViews::SetBrowserView(NativeBrowserView* view) {
if (browser_view_) { if (browser_view()) {
web_view_->RemoveChildView( web_view_->RemoveChildView(
browser_view_->GetInspectableWebContentsView()->GetView()); browser_view()->GetInspectableWebContentsView()->GetView());
browser_view_ = nullptr; set_browser_view(nullptr);
} }
if (!browser_view) { if (!view) {
return; return;
} }
// Add as child of the main web view to avoid (0, 0) origin from overlapping // Add as child of the main web view to avoid (0, 0) origin from overlapping
// with menu bar. // with menu bar.
browser_view_ = browser_view; set_browser_view(view);
web_view_->AddChildView( web_view_->AddChildView(view->GetInspectableWebContentsView()->GetView());
browser_view->GetInspectableWebContentsView()->GetView());
} }
void NativeWindowViews::SetParentWindow(NativeWindow* parent) { void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
@ -1203,9 +1201,9 @@ void NativeWindowViews::OnWidgetBoundsChanged(
// handle minimized windows on Windows. // handle minimized windows on Windows.
const auto new_bounds = GetBounds(); const auto new_bounds = GetBounds();
if (widget_size_ != new_bounds.size()) { if (widget_size_ != new_bounds.size()) {
if (browser_view_) { if (browser_view()) {
const auto flags = static_cast<NativeBrowserViewViews*>(browser_view_) const auto flags = static_cast<NativeBrowserViewViews*>(browser_view())->
->GetAutoResizeFlags(); GetAutoResizeFlags();
int width_delta = 0; int width_delta = 0;
int height_delta = 0; int height_delta = 0;
if (flags & kAutoResizeWidth) { if (flags & kAutoResizeWidth) {
@ -1215,7 +1213,7 @@ void NativeWindowViews::OnWidgetBoundsChanged(
height_delta = new_bounds.height() - widget_size_.height(); height_delta = new_bounds.height() - widget_size_.height();
} }
auto* view = browser_view_->GetInspectableWebContentsView()->GetView(); auto* view = browser_view()->GetInspectableWebContentsView()->GetView();
auto new_view_size = view->size(); auto new_view_size = view->size();
new_view_size.set_width(new_view_size.width() + width_delta); new_view_size.set_width(new_view_size.width() + width_delta);
new_view_size.set_height(new_view_size.height() + height_delta); new_view_size.set_height(new_view_size.height() + height_delta);

View file

@ -215,8 +215,6 @@ class NativeWindowViews : public NativeWindow,
std::unique_ptr<views::Widget> window_; std::unique_ptr<views::Widget> window_;
views::View* web_view_; // Managed by inspectable_web_contents_. views::View* web_view_; // Managed by inspectable_web_contents_.
NativeBrowserView* browser_view_;
std::unique_ptr<AutofillPopup> autofill_popup_; std::unique_ptr<AutofillPopup> autofill_popup_;
std::unique_ptr<MenuBar> menu_bar_; std::unique_ptr<MenuBar> menu_bar_;