Skip to content

Commit

Permalink
[Merge to M-102] capture_selfie_cam: camera preview size specs
Browse files Browse the repository at this point in the history
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}
  • Loading branch information
Ahmed Fakhry authored and Chromium LUCI CQ committed Apr 20, 2022
1 parent fd35f0f commit 66eea4d
Show file tree
Hide file tree
Showing 12 changed files with 637 additions and 249 deletions.
320 changes: 195 additions & 125 deletions ash/capture_mode/capture_mode_camera_controller.cc

Large diffs are not rendered by default.

53 changes: 36 additions & 17 deletions ash/capture_mode/capture_mode_camera_controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,10 +186,11 @@ class ASH_EXPORT CaptureModeCameraController
// bounds accordingly.
void SetCameraPreviewSnapPosition(CameraPreviewSnapPosition value);

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

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

// Fades in or out the `camera_preview_widget_` and updates its visibility
// accordingly.
void FadeInCameraPreview();
void FadeOutCameraPreview();

void OnRecordingStarted(bool is_in_projector_mode);
void OnRecordingEnded();

Expand Down Expand Up @@ -264,15 +260,23 @@ class ASH_EXPORT CaptureModeCameraController
void OnSelectedCameraDisconnected();

// Returns the bounds of the preview widget which doesn't intersect with
// system tray. Always try `camera_preview_snap_position_` first. If camera
// preview at all snap positions intersects with system tray, returns the
// bounds of `camera_preview_snap_position_`.
gfx::Rect CalculatePreviewWidgetTargetBounds();

// Call by `CalculatePreviewWidgetTargetBounds` above. Returns the bounds of
// the preview widget that matches the coordinate system of the confine
// bounds.
// system tray, which should be confined within the given `confine_bounds`,
// and have the given `preview_size`. Always tries the current
// `camera_preview_snap_position_` first. Once a snap position with which the
// preview has no collisions is found, it will be set in
// `camera_preview_snap_position_`. If the camera preview at all possible snap
// positions intersects with system tray, returns the bounds for the current
// `camera_preview_snap_position_`.
gfx::Rect CalculatePreviewWidgetTargetBounds(const gfx::Rect& confine_bounds,
const gfx::Size& preview_size);

// Called by `CalculatePreviewWidgetTargetBounds` above. Returns the bounds of
// the preview widget that matches the coordinate system of the given
// `confine_bounds` with the given `preview_size` at the given
// `snap_position`.
gfx::Rect GetPreviewWidgetBoundsForSnapPosition(
const gfx::Rect& confine_bounds,
const gfx::Size& preview_size,
CameraPreviewSnapPosition snap_position) const;

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

// Sets the visibility of the camera preview to the given `target_visibility`
// and returns true only if the `target_visibility` is different than the
// current.
bool SetCameraPreviewVisibility(bool target_visibility, bool animate);

// Fades in or out the `camera_preview_widget_` and updates its visibility
// accordingly.
void FadeInCameraPreview();
void FadeOutCameraPreview();

// Sets the given `target_bounds` on the camera preview widget, potentially
// animating to it if `animate` is true. Returns true if the bounds actually
// changed from the current.
bool SetCameraPreviewBounds(const gfx::Rect& target_bounds, bool animate);

// Owned by CaptureModeController and guaranteed to be not null and to outlive
// `this`.
CaptureModeDelegate* const delegate_;
Expand Down
28 changes: 17 additions & 11 deletions ash/capture_mode/capture_mode_camera_preview_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ bool IsArrowKeyEvent(const ui::KeyEvent* event) {
CameraPreviewView::CameraPreviewView(
CaptureModeCameraController* camera_controller,
const CameraId& camera_id,
const gfx::Size& preferred_size,
mojo::Remote<video_capture::mojom::VideoSource> camera_video_source,
const media::VideoCaptureFormat& capture_format)
: camera_controller_(camera_controller),
Expand All @@ -70,8 +69,6 @@ CameraPreviewView::CameraPreviewView(
base::Unretained(this)),
GetIconOfResizeButton(
camera_controller_->is_camera_preview_collapsed())))) {
SetPreferredSize(preferred_size);

resize_button_->SetPaintToLayer();
resize_button_->layer()->SetFillsBoundsOpaquely(false);
resize_button_->SetBackground(views::CreateRoundedRectBackground(
Expand All @@ -91,6 +88,13 @@ CameraPreviewView::CameraPreviewView(

CameraPreviewView::~CameraPreviewView() = default;

void CameraPreviewView::SetIsCollapsible(bool value) {
if (value != is_collapsible_) {
is_collapsible_ = value;
RefreshResizeButtonVisibility();
}
}

bool CameraPreviewView::MaybeHandleKeyEvent(const ui::KeyEvent* event) {
if (!has_focus())
return false;
Expand Down Expand Up @@ -123,10 +127,13 @@ void CameraPreviewView::RefreshResizeButtonVisibility() {
if (target_opacity == resize_button_->layer()->GetTargetOpacity())
return;

if (target_opacity == 1.f)
resize_button_hide_timer_.Stop();
if (target_opacity == 1.f) {
FadeInResizeButton();
else
ScheduleRefreshResizeButtonVisibility();
} else {
FadeOutResizeButton();
}
}

void CameraPreviewView::AddedToWidget() {
Expand Down Expand Up @@ -181,9 +188,9 @@ void CameraPreviewView::OnGestureEvent(ui::GestureEvent* event) {
}
break;
case ui::ET_GESTURE_TAP:
resize_button_hide_timer_.Stop();
FadeInResizeButton();
ScheduleRefreshResizeButtonVisibility();
has_been_tapped_ = true;
RefreshResizeButtonVisibility();
has_been_tapped_ = false;
break;
default:
break;
Expand All @@ -194,7 +201,6 @@ void CameraPreviewView::OnGestureEvent(ui::GestureEvent* event) {
}

void CameraPreviewView::OnMouseEntered(const ui::MouseEvent& event) {
resize_button_hide_timer_.Stop();
RefreshResizeButtonVisibility();
}

Expand Down Expand Up @@ -308,10 +314,10 @@ void CameraPreviewView::ScheduleRefreshResizeButtonVisibility() {
}

float CameraPreviewView::CalculateResizeButtonTargetOpacity() {
if (camera_controller_->is_drag_in_progress())
if (!is_collapsible_ || camera_controller_->is_drag_in_progress())
return 0.f;

if (IsMouseHovered() || resize_button_->IsMouseHovered())
if (IsMouseHovered() || resize_button_->IsMouseHovered() || has_been_tapped_)
return 1.f;

return 0.f;
Expand Down
13 changes: 12 additions & 1 deletion ash/capture_mode/capture_mode_camera_preview_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ class CameraPreviewView
CameraPreviewView(
CaptureModeCameraController* camera_controller,
const CameraId& camera_id,
const gfx::Size& preferred_size,
mojo::Remote<video_capture::mojom::VideoSource> camera_video_source,
const media::VideoCaptureFormat& capture_format);
CameraPreviewView(const CameraPreviewView&) = delete;
Expand All @@ -51,6 +50,11 @@ class CameraPreviewView

const CameraId& camera_id() const { return camera_id_; }
CaptureModeButton* resize_button() const { return resize_button_; }
bool is_collapsible() const { return is_collapsible_; }

// Sets this camera preview collapsability to the given `value`, which will
// update the resize button visibility.
void SetIsCollapsible(bool value);

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

// True if the size of the preview in the expanded state is big enough to
// allow it to be collapsible.
bool is_collapsible_ = true;

// True only while handling a gesture tap event on this view.
bool has_been_tapped_ = false;

base::WeakPtrFactory<CameraPreviewView> weak_ptr_factory_{this};
};

Expand Down

0 comments on commit 66eea4d

Please sign in to comment.