Save browser_view_ in the NativeWindow
No need to store it separately in subclasses.
This commit is contained in:
parent
503b0ba1b1
commit
3b3e69f8b2
8 changed files with 34 additions and 33 deletions
|
@ -6,8 +6,7 @@
|
|||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
#include "atom/browser/native_browser_view_mac.h"
|
||||
#include "atom/browser/native_window_mac.h"
|
||||
#include "atom/browser/native_browser_view.h"
|
||||
#include "atom/common/draggable_region.h"
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
|
||||
|
@ -90,9 +89,8 @@ void BrowserWindow::UpdateDraggableRegions(
|
|||
DraggableRegionsToSkRegion(regions), webViewWidth, webViewHeight);
|
||||
}
|
||||
|
||||
NativeWindowMac* window = static_cast<NativeWindowMac*>(window_.get());
|
||||
if (window->browser_view())
|
||||
window->browser_view()->UpdateDraggableRegions(system_drag_exclude_areas);
|
||||
if (window_->browser_view())
|
||||
window_->browser_view()->UpdateDraggableRegions(system_drag_exclude_areas);
|
||||
|
||||
// Create and add a ControlRegionView for each region that needs to be
|
||||
// excluded from the dragging.
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
|
||||
#include "atom/browser/api/atom_api_browser_window.h"
|
||||
|
||||
#include "atom/browser/native_window_views.h"
|
||||
|
||||
namespace atom {
|
||||
|
||||
namespace api {
|
||||
|
@ -13,7 +15,8 @@ void BrowserWindow::UpdateDraggableRegions(
|
|||
const std::vector<DraggableRegion>& regions) {
|
||||
if (window_->has_frame())
|
||||
return;
|
||||
window_->UpdateDraggableRegions(DraggableRegionsToSkRegion(regions));
|
||||
static_cast<NativeWindowViews*>(window_.get())->UpdateDraggableRegions(
|
||||
DraggableRegionsToSkRegion(regions));
|
||||
}
|
||||
|
||||
} // namespace api
|
||||
|
|
|
@ -58,6 +58,7 @@ NativeWindow::NativeWindow(
|
|||
is_modal_(false),
|
||||
is_osr_dummy_(false),
|
||||
inspectable_web_contents_(inspectable_web_contents),
|
||||
browser_view_(nullptr),
|
||||
weak_factory_(this) {
|
||||
options.Get(options::kFrame, &has_frame_);
|
||||
options.Get(options::kTransparent, &transparent_);
|
||||
|
|
|
@ -292,6 +292,7 @@ class NativeWindow : public base::SupportsUserData,
|
|||
void set_is_offscreen_dummy(bool is_dummy) { is_osr_dummy_ = is_dummy; }
|
||||
bool is_offscreen_dummy() const { return is_osr_dummy_; }
|
||||
|
||||
NativeBrowserView* browser_view() const { return browser_view_; }
|
||||
NativeWindow* parent() const { return parent_; }
|
||||
bool is_modal() const { return is_modal_; }
|
||||
|
||||
|
@ -300,6 +301,10 @@ class NativeWindow : public base::SupportsUserData,
|
|||
const mate::Dictionary& options,
|
||||
NativeWindow* parent);
|
||||
|
||||
void set_browser_view(NativeBrowserView* browser_view) {
|
||||
browser_view_ = browser_view;
|
||||
}
|
||||
|
||||
private:
|
||||
// Whether window has standard frame.
|
||||
bool has_frame_;
|
||||
|
@ -335,6 +340,9 @@ class NativeWindow : public base::SupportsUserData,
|
|||
// Is this a dummy window for an offscreen WebContents.
|
||||
bool is_osr_dummy_;
|
||||
|
||||
// The browser view layer.
|
||||
NativeBrowserView* browser_view_;
|
||||
|
||||
// The page this window is viewing.
|
||||
brightray::InspectableWebContents* inspectable_web_contents_;
|
||||
|
||||
|
|
|
@ -135,7 +135,6 @@ class NativeWindowMac : public NativeWindow {
|
|||
bool zoom_to_page_width() const { return zoom_to_page_width_; }
|
||||
bool fullscreen_window_title() const { return fullscreen_window_title_; }
|
||||
bool simple_fullscreen() const { return always_simple_fullscreen_; }
|
||||
NativeBrowserView* browser_view() const { return browser_view_; }
|
||||
|
||||
private:
|
||||
void InternalSetParentWindow(NativeWindow* parent, bool attach);
|
||||
|
@ -153,8 +152,6 @@ class NativeWindowMac : public NativeWindow {
|
|||
// The view that will fill the whole frameless window.
|
||||
base::scoped_nsobject<FullSizeContentView> content_view_;
|
||||
|
||||
NativeBrowserView* browser_view_;
|
||||
|
||||
bool is_kiosk_;
|
||||
|
||||
bool was_fullscreen_;
|
||||
|
|
|
@ -782,7 +782,6 @@ NativeWindowMac::NativeWindowMac(
|
|||
const mate::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: NativeWindow(web_contents, options, parent),
|
||||
browser_view_(nullptr),
|
||||
is_kiosk_(false),
|
||||
was_fullscreen_(false),
|
||||
zoom_to_page_width_(false),
|
||||
|
@ -1494,20 +1493,19 @@ void NativeWindowMac::SetContentProtection(bool enable) {
|
|||
: NSWindowSharingReadOnly];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetBrowserView(NativeBrowserView* browser_view) {
|
||||
if (browser_view_) {
|
||||
[browser_view_->GetInspectableWebContentsView()->GetNativeView()
|
||||
void NativeWindowMac::SetBrowserView(NativeBrowserView* view) {
|
||||
if (browser_view()) {
|
||||
[browser_view()->GetInspectableWebContentsView()->GetNativeView()
|
||||
removeFromSuperview];
|
||||
browser_view_ = nullptr;
|
||||
set_browser_view(nullptr);
|
||||
}
|
||||
|
||||
if (!browser_view) {
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
browser_view_ = browser_view;
|
||||
auto* native_view =
|
||||
browser_view->GetInspectableWebContentsView()->GetNativeView();
|
||||
set_browser_view(view);
|
||||
auto* native_view = view->GetInspectableWebContentsView()->GetNativeView();
|
||||
[[window_ contentView] addSubview:native_view
|
||||
positioned:NSWindowAbove
|
||||
relativeTo:nil];
|
||||
|
|
|
@ -141,7 +141,6 @@ NativeWindowViews::NativeWindowViews(
|
|||
: NativeWindow(web_contents, options, parent),
|
||||
window_(new views::Widget),
|
||||
web_view_(inspectable_web_contents()->GetView()->GetView()),
|
||||
browser_view_(nullptr),
|
||||
menu_bar_autohide_(false),
|
||||
menu_bar_visible_(false),
|
||||
menu_bar_alt_pressed_(false),
|
||||
|
@ -948,22 +947,21 @@ void NativeWindowViews::SetMenu(AtomMenuModel* menu_model) {
|
|||
Layout();
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetBrowserView(NativeBrowserView* browser_view) {
|
||||
if (browser_view_) {
|
||||
void NativeWindowViews::SetBrowserView(NativeBrowserView* view) {
|
||||
if (browser_view()) {
|
||||
web_view_->RemoveChildView(
|
||||
browser_view_->GetInspectableWebContentsView()->GetView());
|
||||
browser_view_ = nullptr;
|
||||
browser_view()->GetInspectableWebContentsView()->GetView());
|
||||
set_browser_view(nullptr);
|
||||
}
|
||||
|
||||
if (!browser_view) {
|
||||
if (!view) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Add as child of the main web view to avoid (0, 0) origin from overlapping
|
||||
// with menu bar.
|
||||
browser_view_ = browser_view;
|
||||
web_view_->AddChildView(
|
||||
browser_view->GetInspectableWebContentsView()->GetView());
|
||||
set_browser_view(view);
|
||||
web_view_->AddChildView(view->GetInspectableWebContentsView()->GetView());
|
||||
}
|
||||
|
||||
void NativeWindowViews::SetParentWindow(NativeWindow* parent) {
|
||||
|
@ -1203,9 +1201,9 @@ void NativeWindowViews::OnWidgetBoundsChanged(
|
|||
// handle minimized windows on Windows.
|
||||
const auto new_bounds = GetBounds();
|
||||
if (widget_size_ != new_bounds.size()) {
|
||||
if (browser_view_) {
|
||||
const auto flags = static_cast<NativeBrowserViewViews*>(browser_view_)
|
||||
->GetAutoResizeFlags();
|
||||
if (browser_view()) {
|
||||
const auto flags = static_cast<NativeBrowserViewViews*>(browser_view())->
|
||||
GetAutoResizeFlags();
|
||||
int width_delta = 0;
|
||||
int height_delta = 0;
|
||||
if (flags & kAutoResizeWidth) {
|
||||
|
@ -1215,7 +1213,7 @@ void NativeWindowViews::OnWidgetBoundsChanged(
|
|||
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();
|
||||
new_view_size.set_width(new_view_size.width() + width_delta);
|
||||
new_view_size.set_height(new_view_size.height() + height_delta);
|
||||
|
|
|
@ -215,8 +215,6 @@ class NativeWindowViews : public NativeWindow,
|
|||
std::unique_ptr<views::Widget> window_;
|
||||
views::View* web_view_; // Managed by inspectable_web_contents_.
|
||||
|
||||
NativeBrowserView* browser_view_;
|
||||
|
||||
std::unique_ptr<AutofillPopup> autofill_popup_;
|
||||
|
||||
std::unique_ptr<MenuBar> menu_bar_;
|
||||
|
|
Loading…
Reference in a new issue