fix: vibrant view is inserted into Views API hierarchy (#42263)
This commit is contained in:
parent
484cf26787
commit
e645ea88e0
2 changed files with 21 additions and 7 deletions
|
@ -12,6 +12,7 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "base/memory/raw_ptr.h"
|
||||||
#include "electron/shell/common/api/api.mojom.h"
|
#include "electron/shell/common/api/api.mojom.h"
|
||||||
#include "shell/browser/native_window.h"
|
#include "shell/browser/native_window.h"
|
||||||
#include "ui/display/display_observer.h"
|
#include "ui/display/display_observer.h"
|
||||||
|
@ -299,6 +300,9 @@ class NativeWindowMac : public NativeWindow,
|
||||||
|
|
||||||
std::string vibrancy_type_;
|
std::string vibrancy_type_;
|
||||||
|
|
||||||
|
// A views::NativeViewHost wrapping the vibrant view. Owned by the root view.
|
||||||
|
raw_ptr<views::NativeViewHost> vibrant_native_view_host_ = nullptr;
|
||||||
|
|
||||||
// The presentation options before entering simple fullscreen mode.
|
// The presentation options before entering simple fullscreen mode.
|
||||||
NSApplicationPresentationOptions simple_fullscreen_options_;
|
NSApplicationPresentationOptions simple_fullscreen_options_;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1393,13 +1393,19 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
NativeWindow::SetVibrancy(type);
|
NativeWindow::SetVibrancy(type);
|
||||||
|
|
||||||
NSVisualEffectView* vibrantView = [window_ vibrantView];
|
NSVisualEffectView* vibrantView = [window_ vibrantView];
|
||||||
|
views::View* rootView = GetContentsView();
|
||||||
|
|
||||||
if (type.empty()) {
|
if (type.empty()) {
|
||||||
if (vibrantView == nil)
|
if (vibrant_native_view_host_ != nullptr) {
|
||||||
return;
|
// Transfers ownership back to caller in the form of a unique_ptr which is
|
||||||
|
// subsequently deleted.
|
||||||
|
rootView->RemoveChildViewT(vibrant_native_view_host_);
|
||||||
|
vibrant_native_view_host_ = nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
[vibrantView removeFromSuperview];
|
if (vibrantView != nil) {
|
||||||
[window_ setVibrantView:nil];
|
[window_ setVibrantView:nil];
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -1455,9 +1461,13 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||||
[vibrantView setState:NSVisualEffectStateFollowsWindowActiveState];
|
[vibrantView setState:NSVisualEffectStateFollowsWindowActiveState];
|
||||||
}
|
}
|
||||||
|
|
||||||
[[window_ contentView] addSubview:vibrantView
|
// Vibrant view is inserted into the root view hierarchy underneath all
|
||||||
positioned:NSWindowBelow
|
// other views.
|
||||||
relativeTo:nil];
|
vibrant_native_view_host_ = new views::NativeViewHost();
|
||||||
|
rootView->AddChildViewAt(vibrant_native_view_host_, 0);
|
||||||
|
vibrant_native_view_host_->Attach(vibrantView);
|
||||||
|
|
||||||
|
rootView->DeprecatedLayoutImmediately();
|
||||||
|
|
||||||
UpdateVibrancyRadii(IsFullscreen());
|
UpdateVibrancyRadii(IsFullscreen());
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue