Skip to content

Commit 66eea4d

Browse files
Ahmed FakhryChromium LUCI CQ
authored andcommitted
[Merge to M-102] capture_selfie_cam: camera preview size specs
This CL implements the new camera preview size specs as defined in http://go/slefie-cam-size-specs. The size of the preview now controls whether the preview is capable of collapsing, and whether it will be visible at all. Bug: 1311325 Test: Modified existing tests, added a new test. (cherry picked from commit 16d0659) Change-Id: I93d2d126bceae4859c0d1ca37c7261ebc1b3c641 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3565340 Reviewed-by: James Cook <jamescook@chromium.org> Commit-Queue: Ahmed Fakhry <afakhry@chromium.org> Cr-Original-Commit-Position: refs/heads/main@{#993781} Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3597952 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Cr-Commit-Position: refs/branch-heads/5005@{#57} Cr-Branched-From: 5b4d945-refs/heads/main@{#992738}
1 parent fd35f0f commit 66eea4d

12 files changed

+637
-249
lines changed

ash/capture_mode/capture_mode_camera_controller.cc

Lines changed: 195 additions & 125 deletions
Large diffs are not rendered by default.

ash/capture_mode/capture_mode_camera_controller.h

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -186,10 +186,11 @@ class ASH_EXPORT CaptureModeCameraController
186186
// bounds accordingly.
187187
void SetCameraPreviewSnapPosition(CameraPreviewSnapPosition value);
188188

189-
// Updates the bounds of `camera_preview_widget_` to current
190-
// GetPreviewWidgetBounds() when necessary. If `animate` is set to true, the
191-
// widget will animate to the new target bounds.
192-
void MaybeUpdatePreviewWidgetBounds(bool animate = false);
189+
// Updates the bounds and visibility of `camera_preview_widget_` according to
190+
// the current state of the capture surface within which the camera preview
191+
// is confined and snapped to one of its corners. If `animate` is set to true,
192+
// the widget will animate to the new target bounds.
193+
void MaybeUpdatePreviewWidget(bool animate = false);
193194

194195
// Handles drag events forwarded from `camera_preview_view_`.
195196
void StartDraggingPreview(const gfx::PointF& screen_location);
@@ -200,11 +201,6 @@ class ASH_EXPORT CaptureModeCameraController
200201
// `is_camera_preview_collapsed_` when the resize button is pressed.
201202
void ToggleCameraPreviewSize();
202203

203-
// Fades in or out the `camera_preview_widget_` and updates its visibility
204-
// accordingly.
205-
void FadeInCameraPreview();
206-
void FadeOutCameraPreview();
207-
208204
void OnRecordingStarted(bool is_in_projector_mode);
209205
void OnRecordingEnded();
210206

@@ -264,15 +260,23 @@ class ASH_EXPORT CaptureModeCameraController
264260
void OnSelectedCameraDisconnected();
265261

266262
// Returns the bounds of the preview widget which doesn't intersect with
267-
// system tray. Always try `camera_preview_snap_position_` first. If camera
268-
// preview at all snap positions intersects with system tray, returns the
269-
// bounds of `camera_preview_snap_position_`.
270-
gfx::Rect CalculatePreviewWidgetTargetBounds();
271-
272-
// Call by `CalculatePreviewWidgetTargetBounds` above. Returns the bounds of
273-
// the preview widget that matches the coordinate system of the confine
274-
// bounds.
263+
// system tray, which should be confined within the given `confine_bounds`,
264+
// and have the given `preview_size`. Always tries the current
265+
// `camera_preview_snap_position_` first. Once a snap position with which the
266+
// preview has no collisions is found, it will be set in
267+
// `camera_preview_snap_position_`. If the camera preview at all possible snap
268+
// positions intersects with system tray, returns the bounds for the current
269+
// `camera_preview_snap_position_`.
270+
gfx::Rect CalculatePreviewWidgetTargetBounds(const gfx::Rect& confine_bounds,
271+
const gfx::Size& preview_size);
272+
273+
// Called by `CalculatePreviewWidgetTargetBounds` above. Returns the bounds of
274+
// the preview widget that matches the coordinate system of the given
275+
// `confine_bounds` with the given `preview_size` at the given
276+
// `snap_position`.
275277
gfx::Rect GetPreviewWidgetBoundsForSnapPosition(
278+
const gfx::Rect& confine_bounds,
279+
const gfx::Size& preview_size,
276280
CameraPreviewSnapPosition snap_position) const;
277281

278282
// Called by `EndDraggingPreview`, updating `camera_preview_snap_position_`
@@ -292,6 +296,21 @@ class ASH_EXPORT CaptureModeCameraController
292296
// panels.
293297
void RunPostRefreshCameraPreview(bool was_preview_visible_before);
294298

299+
// Sets the visibility of the camera preview to the given `target_visibility`
300+
// and returns true only if the `target_visibility` is different than the
301+
// current.
302+
bool SetCameraPreviewVisibility(bool target_visibility, bool animate);
303+
304+
// Fades in or out the `camera_preview_widget_` and updates its visibility
305+
// accordingly.
306+
void FadeInCameraPreview();
307+
void FadeOutCameraPreview();
308+
309+
// Sets the given `target_bounds` on the camera preview widget, potentially
310+
// animating to it if `animate` is true. Returns true if the bounds actually
311+
// changed from the current.
312+
bool SetCameraPreviewBounds(const gfx::Rect& target_bounds, bool animate);
313+
295314
// Owned by CaptureModeController and guaranteed to be not null and to outlive
296315
// `this`.
297316
CaptureModeDelegate* const delegate_;

ash/capture_mode/capture_mode_camera_preview_view.cc

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ bool IsArrowKeyEvent(const ui::KeyEvent* event) {
5757
CameraPreviewView::CameraPreviewView(
5858
CaptureModeCameraController* camera_controller,
5959
const CameraId& camera_id,
60-
const gfx::Size& preferred_size,
6160
mojo::Remote<video_capture::mojom::VideoSource> camera_video_source,
6261
const media::VideoCaptureFormat& capture_format)
6362
: camera_controller_(camera_controller),
@@ -70,8 +69,6 @@ CameraPreviewView::CameraPreviewView(
7069
base::Unretained(this)),
7170
GetIconOfResizeButton(
7271
camera_controller_->is_camera_preview_collapsed())))) {
73-
SetPreferredSize(preferred_size);
74-
7572
resize_button_->SetPaintToLayer();
7673
resize_button_->layer()->SetFillsBoundsOpaquely(false);
7774
resize_button_->SetBackground(views::CreateRoundedRectBackground(
@@ -91,6 +88,13 @@ CameraPreviewView::CameraPreviewView(
9188

9289
CameraPreviewView::~CameraPreviewView() = default;
9390

91+
void CameraPreviewView::SetIsCollapsible(bool value) {
92+
if (value != is_collapsible_) {
93+
is_collapsible_ = value;
94+
RefreshResizeButtonVisibility();
95+
}
96+
}
97+
9498
bool CameraPreviewView::MaybeHandleKeyEvent(const ui::KeyEvent* event) {
9599
if (!has_focus())
96100
return false;
@@ -123,10 +127,13 @@ void CameraPreviewView::RefreshResizeButtonVisibility() {
123127
if (target_opacity == resize_button_->layer()->GetTargetOpacity())
124128
return;
125129

126-
if (target_opacity == 1.f)
130+
resize_button_hide_timer_.Stop();
131+
if (target_opacity == 1.f) {
127132
FadeInResizeButton();
128-
else
133+
ScheduleRefreshResizeButtonVisibility();
134+
} else {
129135
FadeOutResizeButton();
136+
}
130137
}
131138

132139
void CameraPreviewView::AddedToWidget() {
@@ -181,9 +188,9 @@ void CameraPreviewView::OnGestureEvent(ui::GestureEvent* event) {
181188
}
182189
break;
183190
case ui::ET_GESTURE_TAP:
184-
resize_button_hide_timer_.Stop();
185-
FadeInResizeButton();
186-
ScheduleRefreshResizeButtonVisibility();
191+
has_been_tapped_ = true;
192+
RefreshResizeButtonVisibility();
193+
has_been_tapped_ = false;
187194
break;
188195
default:
189196
break;
@@ -194,7 +201,6 @@ void CameraPreviewView::OnGestureEvent(ui::GestureEvent* event) {
194201
}
195202

196203
void CameraPreviewView::OnMouseEntered(const ui::MouseEvent& event) {
197-
resize_button_hide_timer_.Stop();
198204
RefreshResizeButtonVisibility();
199205
}
200206

@@ -308,10 +314,10 @@ void CameraPreviewView::ScheduleRefreshResizeButtonVisibility() {
308314
}
309315

310316
float CameraPreviewView::CalculateResizeButtonTargetOpacity() {
311-
if (camera_controller_->is_drag_in_progress())
317+
if (!is_collapsible_ || camera_controller_->is_drag_in_progress())
312318
return 0.f;
313319

314-
if (IsMouseHovered() || resize_button_->IsMouseHovered())
320+
if (IsMouseHovered() || resize_button_->IsMouseHovered() || has_been_tapped_)
315321
return 1.f;
316322

317323
return 0.f;

ash/capture_mode/capture_mode_camera_preview_view.h

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ class CameraPreviewView
4242
CameraPreviewView(
4343
CaptureModeCameraController* camera_controller,
4444
const CameraId& camera_id,
45-
const gfx::Size& preferred_size,
4645
mojo::Remote<video_capture::mojom::VideoSource> camera_video_source,
4746
const media::VideoCaptureFormat& capture_format);
4847
CameraPreviewView(const CameraPreviewView&) = delete;
@@ -51,6 +50,11 @@ class CameraPreviewView
5150

5251
const CameraId& camera_id() const { return camera_id_; }
5352
CaptureModeButton* resize_button() const { return resize_button_; }
53+
bool is_collapsible() const { return is_collapsible_; }
54+
55+
// Sets this camera preview collapsability to the given `value`, which will
56+
// update the resize button visibility.
57+
void SetIsCollapsible(bool value);
5458

5559
// Returns true if the `event` has been handled by CameraPrevieView. It
5660
// happens if it is control+arrow keys, which will be used to move the camera
@@ -130,6 +134,13 @@ class CameraPreviewView
130134
// the resize button if possible.
131135
base::OneShotTimer resize_button_hide_timer_;
132136

137+
// True if the size of the preview in the expanded state is big enough to
138+
// allow it to be collapsible.
139+
bool is_collapsible_ = true;
140+
141+
// True only while handling a gesture tap event on this view.
142+
bool has_been_tapped_ = false;
143+
133144
base::WeakPtrFactory<CameraPreviewView> weak_ptr_factory_{this};
134145
};
135146

0 commit comments

Comments
 (0)