Skip to content

Commit

Permalink
fix: incorrect wco bounds in macOS fullscreen (#40179)
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Oct 16, 2023
1 parent c9f6f15 commit f362e08
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
10 changes: 6 additions & 4 deletions shell/browser/native_window.cc
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit f362e08

Please sign in to comment.