#ifndef ASH_WM_WINDOW_RESIZER_H_
#define ASH_WM_WINDOW_RESIZER_H_
#include <memory>
#include "ash/ash_export.h"
#include "ash/wm/drag_details.h"
#include "ash/wm/window_state.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/weak_ptr.h"
#include "ui/wm/public/window_move_client.h"
namespace aura {
class Window;
}
namespace gfx {
class Rect;
}
namespace ui {
class GestureEvent;
}
namespace ash {
class PresentationTimeRecorder;
class ASH_EXPORT WindowResizer {
public:
static const int kBoundsChange_None;
static const int kBoundsChange_Repositions;
static const int kBoundsChange_Resizes;
static const int kBoundsChangeDirection_None;
static const int kBoundsChangeDirection_Horizontal;
static const int kBoundsChangeDirection_Vertical;
explicit WindowResizer(WindowState* window_state);
WindowResizer(const WindowResizer&) = delete;
WindowResizer& operator=(const WindowResizer&) = delete;
virtual ~WindowResizer();
static int GetBoundsChangeForWindowComponent(int component);
static int GetPositionChangeDirectionForWindowComponent(int window_component);
virtual void Drag(const gfx::PointF& location, int event_flags) = 0;
virtual void CompleteDrag() = 0;
virtual void RevertDrag() = 0;
virtual void FlingOrSwipe(ui::GestureEvent* event) = 0;
aura::Window* GetTarget() const;
const gfx::PointF& GetInitialLocation() const {
return window_state_->drag_details()->initial_location_in_parent;
}
const DragDetails& details() const { return *window_state_->drag_details(); }
protected:
gfx::Rect CalculateBoundsForDrag(const gfx::PointF& location);
void SetBoundsDuringResize(const gfx::Rect& bounds);
void SetPresentationTimeRecorder(
std::unique_ptr<PresentationTimeRecorder> recorder);
raw_ptr<WindowState, ExperimentalAsh> window_state_;
private:
void AdjustDeltaForTouchResize(int* delta_x, int* delta_y);
gfx::Point GetOriginForDrag(int delta_x,
int delta_y,
const gfx::PointF& event_location);
gfx::Size GetSizeForDrag(int* delta_x, int* delta_y);
int GetWidthForDrag(int min_width, int* delta_x);
int GetHeightForDrag(int min_height, int* delta_y);
void CalculateBoundsWithAspectRatio(float aspect_ratio,
gfx::Rect* new_bounds);
std::unique_ptr<PresentationTimeRecorder> recorder_;
base::WeakPtrFactory<WindowResizer> weak_ptr_factory_{this};
};
ASH_EXPORT std::unique_ptr<WindowResizer> CreateWindowResizer(
aura::Window* window,
const gfx::PointF& point_in_parent,
int window_component,
::wm::WindowMoveSource source);
}
#endif