0

Add SetMinimumWidgetSize to Glic API

This will be used to enforce the minimum size on the glic widget for manual resizing.

Bug: 400522982
Change-Id: Ibc90a13f7cb55f479491837047d286b64632e105
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6352391
Reviewed-by: Alex Gough <ajgo@chromium.org>
Commit-Queue: Sana Akbani <sanaakbani@google.com>
Reviewed-by: Dan Harrington <harringtond@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1432455}
This commit is contained in:
Sana Akbani
2025-03-13 16:55:22 -07:00
committed by Chromium LUCI CQ
parent 1328599438
commit b2a84ed9d9
11 changed files with 72 additions and 0 deletions

@ -344,6 +344,10 @@ interface WebClientHandler {
// like <h1> should have style 'user-select: none'.
SetPanelDraggableAreas(array<gfx.mojom.Rect> draggable_areas) => ();
// Sets the minimum possible size that a user can manually resize to for the
// widget hosting the WebUI.
SetMinimumPanelSize(gfx.mojom.Size size);
// Set the state of the Microphone permission pref:
// prefs::kGlicMicrophoneEnabled. Returns when the browser has stored the new
// pref value.

@ -338,6 +338,10 @@ class GlicWebClientHandler : public glic::mojom::WebClientHandler,
std::move(callback).Run();
}
void SetMinimumPanelSize(const gfx::Size& size) override {
glic_service_->window_controller().SetMinimumWidgetSize(size);
}
void SetMicrophonePermissionState(
bool enabled,
SetMicrophonePermissionStateCallback callback) override {

@ -89,4 +89,16 @@ display::Display GlicWidget::GetDisplay() {
return display::Screen::GetScreen()->GetPrimaryDisplay();
}
void GlicWidget::SetMinimumSize(const gfx::Size& size) {
minimum_widget_size_ = size;
// TODO(sanaakbani): Set this to a more reasonable minimum fallback size.
minimum_widget_size_.SetToMax(gfx::Size(1, 1));
}
gfx::Size GlicWidget::GetMinimumSize() const {
return base::FeatureList::IsEnabled(features::kGlicUserResize)
? minimum_widget_size_
: gfx::Size();
}
} // namespace glic

@ -32,8 +32,17 @@ class GlicWidget : public views::Widget {
// Get the most-overlapping display.
display::Display GetDisplay();
// Sets the minimum size for the widget. Used for manual resize.
void SetMinimumSize(const gfx::Size& size);
// views:Widget:
// Gets the minimum size a user can resize to for the widget.
gfx::Size GetMinimumSize() const override;
private:
explicit GlicWidget(InitParams params);
gfx::Size minimum_widget_size_;
};
} // namespace glic

@ -923,6 +923,14 @@ void GlicWindowController::SetDraggableAreas(
glic_view->SetDraggableAreas(draggable_areas);
}
void GlicWindowController::SetMinimumWidgetSize(const gfx::Size& size) {
if (!GetGlicWidget()) {
return;
}
glic_widget_->SetMinimumSize(size);
}
void GlicWindowController::Close() {
GlicWindowController::CloseInternal(std::nullopt);
}

@ -113,6 +113,10 @@ class GlicWindowController : public views::WidgetObserver,
// Sets the areas of the view from which it should be draggable.
void SetDraggableAreas(const std::vector<gfx::Rect>& draggable_areas);
// Sets the minimum widget size that the widget will allow the user to resize
// to.
void SetMinimumWidgetSize(const gfx::Size& size);
// Close the panel but keep the glic WebContents alive in the background.
void Close();

@ -159,6 +159,16 @@ export declare interface GlicBrowserHost {
*/
setWindowDraggableAreas(areas: DraggableArea[]): Promise<void>;
/**
* Sets the minimum possible size a user can resize to for the glic window.
*
* All provided values will go through sanity checks (e.g. checking min
* values for height and width) and may be adjusted. The web client should
* expect that the provided values may not be applied verbatim. Note: This
* will not affect the current glic window size.
*/
setMinimumWidgetSize?(width: number, height: number): Promise<void>;
/**
* Fetches page context for the currently focused tab, optionally including
* more expensive-to-generate data.

@ -313,6 +313,11 @@ class GlicBrowserHostImpl implements GlicBrowserHost {
'glicBrowserSetWindowDraggableAreas', {areas});
}
setMinimumWidgetSize(width: number, height: number): Promise<void> {
return this.sender.requestWithResponse(
'glicBrowserSetMinimumWidgetSize', {size: {width, height}});
}
getPanelState(): ObservableValueImpl<PanelState> {
return this.panelState;
}

@ -345,6 +345,12 @@ class HostMessageHandler implements HostMessageHandlerInterface {
return this.handler.setPanelDraggableAreas(request.areas);
}
glicBrowserSetMinimumWidgetSize(request: {
size: {width: number, height: number},
}) {
return this.handler.setMinimumPanelSize(request.size);
}
glicBrowserSetMicrophonePermissionState(request: {enabled: boolean}) {
return this.handler.setMicrophonePermissionState(request.enabled);
}

@ -97,6 +97,14 @@ export declare interface HostRequestTypes {
areas: DraggableArea[],
},
};
glicBrowserSetMinimumWidgetSize: {
request: {
size: {
width: number,
height: number,
},
},
};
glicBrowserSetMicrophonePermissionState: {
request: {
enabled: boolean,
@ -238,6 +246,7 @@ type HostRequestEnumNamesType = {
CaptureScreenshot: 0,
ResizeWindow: 0,
SetWindowDraggableAreas: 0,
SetMinimumWidgetSize: 0,
SetMicrophonePermissionState: 0,
SetLocationPermissionState: 0,
SetTabContextPermissionState: 0,

@ -75,6 +75,7 @@ chromium-metrics-reviews@google.com.
<variant name="SetContextAccessIndicator"/>
<variant name="SetLocationPermissionState"/>
<variant name="SetMicrophonePermissionState"/>
<variant name="SetMinimumWidgetSize"/>
<variant name="SetSyntheticExperimentState"/>
<variant name="SetTabContextPermissionState"/>
<variant name="SetWindowDraggableAreas"/>