mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
fix: recalibrate simpleFullscreen when display metrics change (#28870)
This commit is contained in:
@@ -201,6 +201,7 @@ class NativeWindow : public base::SupportsUserData,
|
||||
virtual void SetTrafficLightPosition(const gfx::Point& position) = 0;
|
||||
virtual gfx::Point GetTrafficLightPosition() const = 0;
|
||||
virtual void RedrawTrafficLights() = 0;
|
||||
virtual void UpdateFrame() = 0;
|
||||
#endif
|
||||
|
||||
// Touchbar API
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "base/mac/scoped_nsobject.h"
|
||||
#include "shell/browser/native_window.h"
|
||||
#include "ui/display/display_observer.h"
|
||||
#include "ui/native_theme/native_theme_observer.h"
|
||||
#include "ui/views/controls/native/native_view_host.h"
|
||||
|
||||
@@ -28,7 +29,9 @@ namespace electron {
|
||||
|
||||
class RootViewMac;
|
||||
|
||||
class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||
class NativeWindowMac : public NativeWindow,
|
||||
public ui::NativeThemeObserver,
|
||||
public display::DisplayObserver {
|
||||
public:
|
||||
NativeWindowMac(const gin_helper::Dictionary& options, NativeWindow* parent);
|
||||
~NativeWindowMac() override;
|
||||
@@ -130,7 +133,6 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||
bool IsVisibleOnAllWorkspaces() override;
|
||||
|
||||
void SetAutoHideCursor(bool auto_hide) override;
|
||||
|
||||
void SelectPreviousTab() override;
|
||||
void SelectNextTab() override;
|
||||
void MergeAllWindows() override;
|
||||
@@ -141,6 +143,7 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||
bool SetWindowButtonVisibility(bool visible) override;
|
||||
|
||||
void SetVibrancy(const std::string& type) override;
|
||||
void UpdateFrame() override;
|
||||
void SetTouchBar(
|
||||
std::vector<gin_helper::PersistentDictionary> items) override;
|
||||
void RefreshTouchBarItem(const std::string& item_id) override;
|
||||
@@ -195,6 +198,10 @@ class NativeWindowMac : public NativeWindow, public ui::NativeThemeObserver {
|
||||
bool CanResize() const override;
|
||||
views::View* GetContentsView() override;
|
||||
|
||||
// display::DisplayObserver:
|
||||
void OnDisplayMetricsChanged(const display::Display& display,
|
||||
uint32_t changed_metrics) override;
|
||||
|
||||
private:
|
||||
// Add custom layers to the content view.
|
||||
void AddContentViewLayers(bool minimizable, bool closable);
|
||||
|
||||
@@ -38,6 +38,7 @@
|
||||
#include "shell/common/process_util.h"
|
||||
#include "skia/ext/skia_utils_mac.h"
|
||||
#include "third_party/webrtc/modules/desktop_capture/mac/window_list_utils.h"
|
||||
#include "ui/display/screen.h"
|
||||
#include "ui/gfx/skia_util.h"
|
||||
#include "ui/gl/gpu_switching_manager.h"
|
||||
#include "ui/views/background.h"
|
||||
@@ -350,6 +351,7 @@ NativeWindowMac::NativeWindowMac(const gin_helper::Dictionary& options,
|
||||
NativeWindow* parent)
|
||||
: NativeWindow(options, parent), root_view_(new RootViewMac(this)) {
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->AddObserver(this);
|
||||
display::Screen::GetScreen()->AddObserver(this);
|
||||
|
||||
int width = 800, height = 600;
|
||||
options.Get(options::kWidth, &width);
|
||||
@@ -541,6 +543,7 @@ NativeWindowMac::~NativeWindowMac() {}
|
||||
void NativeWindowMac::Cleanup() {
|
||||
DCHECK(!IsClosed());
|
||||
ui::NativeTheme::GetInstanceForNativeUi()->RemoveObserver(this);
|
||||
display::Screen::GetScreen()->RemoveObserver(this);
|
||||
[NSEvent removeMonitor:wheel_event_monitor_];
|
||||
}
|
||||
|
||||
@@ -1116,6 +1119,17 @@ void NativeWindowMac::SetExcludedFromShownWindowsMenu(bool excluded) {
|
||||
[window setExcludedFromWindowsMenu:excluded];
|
||||
}
|
||||
|
||||
void NativeWindowMac::OnDisplayMetricsChanged(const display::Display& display,
|
||||
uint32_t changed_metrics) {
|
||||
// We only want to force screen recalibration if we're in simpleFullscreen
|
||||
// mode.
|
||||
if (!is_simple_fullscreen_)
|
||||
return;
|
||||
|
||||
base::PostTask(FROM_HERE, {content::BrowserThread::UI},
|
||||
base::BindOnce(&NativeWindow::UpdateFrame, GetWeakPtr()));
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetSimpleFullScreen(bool simple_fullscreen) {
|
||||
NSWindow* window = GetNativeWindow().GetNativeNSWindow();
|
||||
|
||||
@@ -1667,6 +1681,13 @@ gfx::Point NativeWindowMac::GetTrafficLightPosition() const {
|
||||
return traffic_light_position_;
|
||||
}
|
||||
|
||||
// In simpleFullScreen mode, update the frame for new bounds.
|
||||
void NativeWindowMac::UpdateFrame() {
|
||||
NSWindow* window = GetNativeWindow().GetNativeNSWindow();
|
||||
NSRect fullscreenFrame = [window.screen frame];
|
||||
[window setFrame:fullscreenFrame display:YES animate:YES];
|
||||
}
|
||||
|
||||
void NativeWindowMac::SetTouchBar(
|
||||
std::vector<gin_helper::PersistentDictionary> items) {
|
||||
if (@available(macOS 10.12.2, *)) {
|
||||
|
||||
Reference in New Issue
Block a user