Commit e8381eff authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

capture_mode: Initial land of capture region feature.

See screen cast in bug comment 1 for a video of what is included and not
included in this CL.

Included:
  - Dragging to select a region
  - After first drag, fine tuning via affordance circles
  - Button to capture region (can be reused for fullscreen and window
    capture)
  - Switching to and from capture region source
Not included:
  - Nudge for tablet mode (see specs)
  - Motion/animations
  - Styling for buttons
  - Drop shadow for border and affordance circles
  - Partial magnifier for affordance circle presses
  - Cursor changes

The basics of this CL is to provide a UI to select a region. The
selection has two phases, a quick selection phase to quickly grab a
region, then a fine tuning phase where users can resize/reposition the
region with some drag affordances.

For a capture region session, we add two widgets to have supporting
text and buttons, and a struct that holds data needed to draw the rest
of the UI onto the layer. The layer is updated when the selection
region has been updated from drag events.

For phase two, we use a simple formula to determine which affordance
has been pressed down on, if any. If an affordance was pressed on, we
allow resizing, but one or two points stay the same. These are stored
in the struct as anchor points, and used to compute the new selection
region when there is a drag event.

Test: manual
Bug: 1120132
Change-Id: If9c461d82306666cbfa9be7fcd521bd6caeec331
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2404945Reviewed-by: default avatarAhmed Fakhry <afakhry@chromium.org>
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Cr-Commit-Position: refs/heads/master@{#807318}
parent bcc673ed
This diff is collapsed.
......@@ -5,11 +5,15 @@
#ifndef ASH_CAPTURE_MODE_CAPTURE_MODE_SESSION_H_
#define ASH_CAPTURE_MODE_CAPTURE_MODE_SESSION_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/capture_mode/capture_mode_types.h"
#include "ui/compositor/layer_delegate.h"
#include "ui/compositor/layer_owner.h"
#include "ui/events/event.h"
#include "ui/events/event_handler.h"
#include "ui/views/controls/button/button.h"
#include "ui/views/widget/widget.h"
namespace gfx {
......@@ -30,7 +34,8 @@ class CaptureModeController;
// the one that will be.
class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
public ui::LayerDelegate,
public ui::EventHandler {
public ui::EventHandler,
public views::ButtonListener {
public:
// Creates the bar widget on the given |root| window.
CaptureModeSession(CaptureModeController* controller, aura::Window* root);
......@@ -61,6 +66,9 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
void OnMouseEvent(ui::MouseEvent* event) override;
void OnTouchEvent(ui::TouchEvent* event) override;
// views::ButtonListener:
void ButtonPressed(views::Button* sender, const ui::Event& event) override;
private:
// Gets the bounds of current window selected for |kWindow| capture source.
gfx::Rect GetSelectedWindowBounds() const;
......@@ -73,6 +81,34 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// Paints the current capture region depending on the current capture source.
void PaintCaptureRegion(gfx::Canvas* canvas);
// Helper to unify mouse/touch events. Forwards events to the three below
// functions and they are located on |capture_button_widget_|. Blocks events
// from reaching other handlers, unless the event is located on
// |capture_mode_bar_widget_|. |is_touch| signifies this is a touch event, and
// we will use larger hit targets for the drag affordances.
void OnLocatedEvent(ui::LocatedEvent* event, bool is_touch);
// Handles updating the select region UI.
void OnLocatedEventPressed(const gfx::Point& location_in_root, bool is_touch);
void OnLocatedEventDragged(const gfx::Point& location_in_root);
void OnLocatedEventReleased(const gfx::Point& location_in_root);
// Updates the capture region and the capture region widgets.
void UpdateCaptureRegion(const gfx::Rect& new_capture_region);
// Updates the widgets that are used to display text/icons while selecting a
// capture region. They are not visible during fullscreen or window capture,
// and some are only visible during certain phases of region capture. This
// will create or destroy the widgets as needed.
void UpdateCaptureRegionWidgets();
// Retrieves the anchor points on the current selected region associated with
// |position|. The anchor points are described as the points that do not
// change when resizing the capture region while dragging one of the drag
// affordances. There is one anchor point if |position| is a vertex, and two
// anchor points if |position| is an edge.
std::vector<gfx::Point> GetAnchorPointsForPosition(FineTunePosition position);
CaptureModeController* const controller_;
// The current root window on which the capture session is active, which may
......@@ -84,6 +120,25 @@ class ASH_EXPORT CaptureModeSession : public ui::LayerOwner,
// The content view of the above widget and owned by its views hierarchy.
CaptureModeBarView* capture_mode_bar_view_;
// Widgets which display text and icons during a region capture session.
std::unique_ptr<views::Widget> dimensions_label_widget_;
std::unique_ptr<views::Widget> capture_button_widget_;
// Stores the data needed to select a region during a region capture session.
// There are two phases for a region capture session. The select phase, where
// the user can quickly select a region and the fine tune phase, where the
// user can reposition and resize the region with a lot of accuracy.
bool is_select_phase_ = true;
// The location of the last press and drag events.
gfx::Point initial_location_in_root_;
gfx::Point previous_location_in_root_;
// The position of the last press event during the fine tune phase drag.
FineTunePosition fine_tune_position_;
// The points that do not change during a fine tune resize. This is empty
// when |fine_tune_position_| is kNone or kCenter, or if there is no drag
// underway.
std::vector<gfx::Point> anchor_points_;
// Caches the old status of mouse warping before the session started to be
// restored at the end.
bool old_mouse_warp_status_;
......
......@@ -20,6 +20,28 @@ enum class CaptureModeSource {
kWindow,
};
// The position of the press event during the fine tune phase of a region
// capture session. This will determine what subsequent drag events do to the
// select region.
enum class FineTunePosition {
// The initial press was outside region. Subsequent drags will do nothing.
kNone,
// The initial press was inside the select region. Subsequent drags will
// move the entire region.
kCenter,
// The initial press was on one of the drag affordance circles. Subsequent
// drags will resize the region. These are sorted clockwise starting at the
// top left.
kTopLeft,
kTopCenter,
kTopRight,
kRightCenter,
kBottomRight,
kBottomCenter,
kBottomLeft,
kLeftCenter,
};
} // namespace ash
#endif // ASH_CAPTURE_MODE_CAPTURE_MODE_TYPES_H_
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