Commit 53830064 authored by Richard Chui's avatar Richard Chui Committed by Commit Bot

Capture Mode: Restrict capture region edge drag resizing

This CL ensures that when dragging the selected region by an edge
affordance, that the capture region is resized only in the expected
direction.

Test: manual, updated test
Change-Id: Icd2691592deb180db55b84f8e394b2e8935a3858
Fixed: 1140778
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2490866
Commit-Queue: Richard Chui <richui@chromium.org>
Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Reviewed-by: default avatarSammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#820054}
parent e431031f
......@@ -727,10 +727,25 @@ void CaptureModeSession::OnLocatedEventDragged(
}
// The new region is defined by the rectangle which encloses the anchor
// point(s) and |location_in_root|.
// point(s) and |resizing_point|, which is based off of |location_in_root| but
// prevents edge drags from resizing the region in the non-desired direction.
std::vector<gfx::Point> points = anchor_points_;
DCHECK(!points.empty());
points.push_back(location_in_root);
gfx::Point resizing_point = location_in_root;
// For edge dragging, there will be two anchor points with the same primary
// axis value. Setting |resizing_point|'s secondary axis value to match either
// one of the anchor points secondary axis value will ensure that for the
// duration of a drag, GetRectEnclosingPoints will return a rect whose
// secondary dimension does not change.
if (fine_tune_position_ == FineTunePosition::kLeftCenter ||
fine_tune_position_ == FineTunePosition::kRightCenter) {
resizing_point.set_y(points.front().y());
} else if (fine_tune_position_ == FineTunePosition::kTopCenter ||
fine_tune_position_ == FineTunePosition::kBottomCenter) {
resizing_point.set_x(points.front().x());
}
points.push_back(resizing_point);
UpdateCaptureRegion(GetRectEnclosingPoints(points), /*is_resizing=*/true);
MaybeShowMagnifierGlassAtPoint(location_in_root);
}
......
......@@ -423,7 +423,7 @@ TEST_F(CaptureModeTest, CaptureRegionEdgeResizeBehavior) {
auto* controller = StartImageRegionCapture();
// Create the initial region.
const gfx::Rect target_region(gfx::Rect(200, 200, 400, 400));
const gfx::Rect target_region(gfx::Rect(200, 200, 200, 200));
SelectRegion(target_region);
// For each edge point try dragging to several points and verify that the
......@@ -447,7 +447,8 @@ TEST_F(CaptureModeTest, CaptureRegionEdgeResizeBehavior) {
// Drag to a couple of points that change both x and y. In all these cases,
// only the width or height should change.
auto drag_test_points = {gfx::Point(350, 350), gfx::Point(450, 450)};
auto drag_test_points = {gfx::Point(150, 150), gfx::Point(350, 350),
gfx::Point(450, 450)};
auto* event_generator = GetEventGenerator();
for (auto test_case : kDragEdgeCases) {
SCOPED_TRACE(test_case.trace);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment