Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: incorrect wco bounds in macOS fullscreen #40179

Merged
merged 1 commit into from Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 6 additions & 4 deletions shell/browser/native_window.cc
Expand Up @@ -537,7 +537,7 @@ void NativeWindow::PreviewFile(const std::string& path,

void NativeWindow::CloseFilePreview() {}

gfx::Rect NativeWindow::GetWindowControlsOverlayRect() {
absl::optional<gfx::Rect> NativeWindow::GetWindowControlsOverlayRect() {
return overlay_rect_;
}

Expand Down Expand Up @@ -665,6 +665,7 @@ void NativeWindow::NotifyWindowMoved() {
}

void NativeWindow::NotifyWindowEnterFullScreen() {
NotifyLayoutWindowControlsOverlay();
for (NativeWindowObserver& observer : observers_)
observer.OnWindowEnterFullScreen();
}
Expand All @@ -690,6 +691,7 @@ void NativeWindow::NotifyWindowSheetEnd() {
}

void NativeWindow::NotifyWindowLeaveFullScreen() {
NotifyLayoutWindowControlsOverlay();
for (NativeWindowObserver& observer : observers_)
observer.OnWindowLeaveFullScreen();
}
Expand Down Expand Up @@ -733,10 +735,10 @@ void NativeWindow::NotifyWindowSystemContextMenu(int x,
}

void NativeWindow::NotifyLayoutWindowControlsOverlay() {
gfx::Rect bounding_rect = GetWindowControlsOverlayRect();
if (!bounding_rect.IsEmpty()) {
auto bounding_rect = GetWindowControlsOverlayRect();
if (bounding_rect.has_value()) {
for (NativeWindowObserver& observer : observers_)
observer.UpdateWindowControlsOverlay(bounding_rect);
observer.UpdateWindowControlsOverlay(bounding_rect.value());
}
}

Expand Down
2 changes: 1 addition & 1 deletion shell/browser/native_window.h
Expand Up @@ -286,7 +286,7 @@ class NativeWindow : public base::SupportsUserData,
return weak_factory_.GetWeakPtr();
}

virtual gfx::Rect GetWindowControlsOverlayRect();
virtual absl::optional<gfx::Rect> GetWindowControlsOverlayRect();
virtual void SetWindowControlsOverlayRect(const gfx::Rect& overlay_rect);

// Methods called by the WebContents.
Expand Down
2 changes: 1 addition & 1 deletion shell/browser/native_window_mac.h
Expand Up @@ -153,7 +153,7 @@ class NativeWindowMac : public NativeWindow,
void CloseFilePreview() override;
gfx::Rect ContentBoundsToWindowBounds(const gfx::Rect& bounds) const override;
gfx::Rect WindowBoundsToContentBounds(const gfx::Rect& bounds) const override;
gfx::Rect GetWindowControlsOverlayRect() override;
absl::optional<gfx::Rect> GetWindowControlsOverlayRect() override;
void NotifyWindowEnterFullScreen() override;
void NotifyWindowLeaveFullScreen() override;
void SetActive(bool is_key) override;
Expand Down
28 changes: 19 additions & 9 deletions shell/browser/native_window_mac.mm
Expand Up @@ -1899,23 +1899,33 @@ int NonClientHitTest(const gfx::Point& point) override {
[window_ setAcceptsMouseMovedEvents:forward];
}

gfx::Rect NativeWindowMac::GetWindowControlsOverlayRect() {
if (titlebar_overlay_ && buttons_proxy_ &&
window_button_visibility_.value_or(true)) {
absl::optional<gfx::Rect> NativeWindowMac::GetWindowControlsOverlayRect() {
if (!titlebar_overlay_)
return absl::nullopt;

// On macOS, when in fullscreen mode, window controls (the menu bar, title
// bar, and toolbar) are attached to a separate NSView that slides down from
// the top of the screen, independent of, and overlapping the WebContents.
// Disable WCO when in fullscreen, because this space is inaccessible to
// WebContents. https://crbug.com/915110.
if (IsFullscreen())
return gfx::Rect();

if (buttons_proxy_ && window_button_visibility_.value_or(true)) {
NSRect buttons = [buttons_proxy_ getButtonsContainerBounds];
gfx::Rect overlay;
overlay.set_width(GetContentSize().width() - NSWidth(buttons));
if ([buttons_proxy_ useCustomHeight]) {
overlay.set_height(titlebar_overlay_height());
} else {
overlay.set_height(NSHeight(buttons));
}
overlay.set_height([buttons_proxy_ useCustomHeight]
? titlebar_overlay_height()
: NSHeight(buttons));

if (!base::i18n::IsRTL())
overlay.set_x(NSMaxX(buttons));

return overlay;
}
return gfx::Rect();

return absl::nullopt;
}

// static
Expand Down