mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: vibrant view is inserted into Views API hierarchy (#43128)
* fix: vibrant view is inserted into Views API hierarchy (#42263) Co-authored-by: Hans Halverson <hans_halverson@alumni.brown.edu> * Update shell/browser/native_window_mac.mm Co-authored-by: Charles Kerr <charles@charleskerr.com> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com> --------- Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com> Co-authored-by: Hans Halverson <hans_halverson@alumni.brown.edu> Co-authored-by: Shelley Vohr <shelley.vohr@gmail.com>
This commit is contained in:
@@ -12,6 +12,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "base/memory/raw_ptr.h"
|
||||
#include "electron/shell/common/api/api.mojom.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "ui/display/display_observer.h"
|
||||
@@ -299,6 +300,9 @@ class NativeWindowMac : public NativeWindow,
|
||||
|
||||
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.
|
||||
NSApplicationPresentationOptions simple_fullscreen_options_;
|
||||
};
|
||||
|
||||
@@ -1393,13 +1393,19 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||
NativeWindow::SetVibrancy(type);
|
||||
|
||||
NSVisualEffectView* vibrantView = [window_ vibrantView];
|
||||
views::View* rootView = GetContentsView();
|
||||
|
||||
if (type.empty()) {
|
||||
if (vibrantView == nil)
|
||||
return;
|
||||
if (vibrant_native_view_host_ != nullptr) {
|
||||
// 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];
|
||||
[window_ setVibrantView:nil];
|
||||
if (vibrantView != nil) {
|
||||
[window_ setVibrantView:nil];
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -1455,9 +1461,13 @@ void NativeWindowMac::SetVibrancy(const std::string& type) {
|
||||
[vibrantView setState:NSVisualEffectStateFollowsWindowActiveState];
|
||||
}
|
||||
|
||||
[[window_ contentView] addSubview:vibrantView
|
||||
positioned:NSWindowBelow
|
||||
relativeTo:nil];
|
||||
// Vibrant view is inserted into the root view hierarchy underneath all
|
||||
// other views.
|
||||
vibrant_native_view_host_ = rootView->AddChildViewAt(
|
||||
std::make_unique<views::NativeViewHost>(), 0);
|
||||
vibrant_native_view_host_->Attach(vibrantView);
|
||||
|
||||
rootView->DeprecatedLayoutImmediately();
|
||||
|
||||
UpdateVibrancyRadii(IsFullscreen());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user