diff --git a/shell/browser/native_window.cc b/shell/browser/native_window.cc index 90540c2689..07d374226c 100644 --- a/shell/browser/native_window.cc +++ b/shell/browser/native_window.cc @@ -537,7 +537,7 @@ void NativeWindow::PreviewFile(const std::string& path, void NativeWindow::CloseFilePreview() {} -gfx::Rect NativeWindow::GetWindowControlsOverlayRect() { +absl::optional NativeWindow::GetWindowControlsOverlayRect() { return overlay_rect_; } @@ -665,6 +665,7 @@ void NativeWindow::NotifyWindowMoved() { } void NativeWindow::NotifyWindowEnterFullScreen() { + NotifyLayoutWindowControlsOverlay(); for (NativeWindowObserver& observer : observers_) observer.OnWindowEnterFullScreen(); } @@ -690,6 +691,7 @@ void NativeWindow::NotifyWindowSheetEnd() { } void NativeWindow::NotifyWindowLeaveFullScreen() { + NotifyLayoutWindowControlsOverlay(); for (NativeWindowObserver& observer : observers_) observer.OnWindowLeaveFullScreen(); } @@ -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()); } } diff --git a/shell/browser/native_window.h b/shell/browser/native_window.h index 79bc09f9c8..6abcb44fa7 100644 --- a/shell/browser/native_window.h +++ b/shell/browser/native_window.h @@ -286,7 +286,7 @@ class NativeWindow : public base::SupportsUserData, return weak_factory_.GetWeakPtr(); } - virtual gfx::Rect GetWindowControlsOverlayRect(); + virtual absl::optional GetWindowControlsOverlayRect(); virtual void SetWindowControlsOverlayRect(const gfx::Rect& overlay_rect); // Methods called by the WebContents. diff --git a/shell/browser/native_window_mac.h b/shell/browser/native_window_mac.h index 95a164bafa..6ce521b5e9 100644 --- a/shell/browser/native_window_mac.h +++ b/shell/browser/native_window_mac.h @@ -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 GetWindowControlsOverlayRect() override; void NotifyWindowEnterFullScreen() override; void NotifyWindowLeaveFullScreen() override; void SetActive(bool is_key) override; diff --git a/shell/browser/native_window_mac.mm b/shell/browser/native_window_mac.mm index e0ff57736c..5bc222a127 100644 --- a/shell/browser/native_window_mac.mm +++ b/shell/browser/native_window_mac.mm @@ -1899,23 +1899,33 @@ void NativeWindowMac::SetForwardMouseMessages(bool forward) { [window_ setAcceptsMouseMovedEvents:forward]; } -gfx::Rect NativeWindowMac::GetWindowControlsOverlayRect() { - if (titlebar_overlay_ && buttons_proxy_ && - window_button_visibility_.value_or(true)) { +absl::optional 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