Skip to content

Commit

Permalink
[AWC] Make min/max/restore JS APIs work on all Aura platforms
Browse files Browse the repository at this point in the history
The previous implementation (http://crrev.com/c/4665355 (restore),
http://crrev.com/c/4665429 (max),  http://crrev.com/c/4633301 (min))
doesn't properly work on Linux. This CL will fix the way the APIs change
the widget's display state as it's not enough on all platforms to just
override the `ui::WindowShowState` value. The previous implementation
also causes the CSS to not update properly when the state is changed by
using the existing native ways to update the display state.

I2P thread
https://groups.google.com/a/chromium.org/g/blink-dev/c/oCxWg8q_OQY/m/LUTw0T5cCQAJ

Public explainer is available @
https://github.com/ivansandrk/additional-windowing-controls/blob/main/awc-explainer.md

Private doc @ go/additional-windowing-controls

Bug: 1466855, b:288265319
Change-Id: I7df5766fa50403c95e595598aaa3c6c696918f58
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4946653
Reviewed-by: Scott Violet <sky@chromium.org>
Commit-Queue: Sonja Laurila <laurila@google.com>
Reviewed-by: Kinuko Yasuda <kinuko@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1214826}
  • Loading branch information
sonkkeli authored and Chromium LUCI CQ committed Oct 25, 2023
1 parent 5424b4a commit b602660
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 22 deletions.
12 changes: 12 additions & 0 deletions chrome/browser/ui/browser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2051,6 +2051,18 @@ bool Browser::GetCanResize() {
return window_->GetCanResize();
}

void Browser::MinimizeFromWebAPI() {
window_->Minimize();
}

void Browser::MaximizeFromWebAPI() {
window_->Maximize();
}

void Browser::RestoreFromWebAPI() {
window_->Restore();
}

bool Browser::CanEnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) {
Expand Down
3 changes: 3 additions & 0 deletions chrome/browser/ui/browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,9 @@ class Browser : public TabStripModelObserver,
content::RenderFrameHost* requesting_frame) override;
void SetCanResizeFromWebAPI(absl::optional<bool> can_resize) override;
bool GetCanResize() override;
void MinimizeFromWebAPI() override;
void MaximizeFromWebAPI() override;
void RestoreFromWebAPI() override;
bool CanEnterFullscreenModeForTab(
content::RenderFrameHost* requesting_frame,
const blink::mojom::FullscreenOptions& options) override;
Expand Down
29 changes: 11 additions & 18 deletions content/browser/web_contents/web_contents_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -3850,31 +3850,24 @@ void WebContentsImpl::FullscreenStateChanged(
}

void WebContentsImpl::Maximize() {
SetWindowShowState(ui::SHOW_STATE_MAXIMIZED);
if (!GetDelegate()) {
return;
}
GetDelegate()->MaximizeFromWebAPI();
}

void WebContentsImpl::Minimize() {
SetWindowShowState(ui::SHOW_STATE_MINIMIZED);
if (!GetDelegate()) {
return;
}
GetDelegate()->MinimizeFromWebAPI();
}

void WebContentsImpl::Restore() {
SetWindowShowState(ui::SHOW_STATE_NORMAL);
}

void WebContentsImpl::SetWindowShowState(ui::WindowShowState state) {
#if defined(USE_AURA)
aura::Window* window = GetTopLevelNativeWindow();

// TODO(laurila, crbug.com/1466855): This API function currently works only on
// Aura platforms (Win/Lin/CrOS/Fuchsia), make it also work on Mac.
wm::SetWindowState(window, state);

// This is needed to update `display-state` CSS @media query value.
if (RenderWidgetHost* render_widget_host =
GetPrimaryMainFrame()->GetRenderWidgetHost()) {
render_widget_host->SynchronizeVisualProperties();
if (!GetDelegate()) {
return;
}
#endif
GetDelegate()->RestoreFromWebAPI();
}

ui::WindowShowState WebContentsImpl::GetWindowShowState() {
Expand Down
4 changes: 0 additions & 4 deletions content/browser/web_contents/web_contents_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1782,10 +1782,6 @@ class CONTENT_EXPORT WebContentsImpl : public WebContents,
// Returns the size that the main frame should be sized to.
gfx::Size GetSizeForMainFrame();

// Sets the window's state to the given `ui::WindowShowState` and synchronizes
// the visual properties of the `RenderWidgetHost`.
void SetWindowShowState(ui::WindowShowState state);

// Helper method that's called whenever |preferred_size_| or
// |preferred_size_for_capture_| changes, to propagate the new value to the
// |delegate_|.
Expand Down
3 changes: 3 additions & 0 deletions content/public/browser/web_contents_delegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,9 @@ class CONTENT_EXPORT WebContentsDelegate {
// default.
virtual void SetCanResizeFromWebAPI(absl::optional<bool> can_resize) {}
virtual bool GetCanResize();
virtual void MinimizeFromWebAPI() {}
virtual void MaximizeFromWebAPI() {}
virtual void RestoreFromWebAPI() {}

// Returns whether entering fullscreen with |EnterFullscreenModeForTab()| is
// allowed.
Expand Down

0 comments on commit b602660

Please sign in to comment.