1
    2
    3
    4
    5
    6
    7
    8
    9
   10
   11
   12
   13
   14
   15
   16
   17
   18
   19
   20
   21
   22
   23
   24
   25
   26
   27
   28
   29
   30
   31
   32
   33
   34
   35
   36
   37
   38
   39
   40
   41
   42
   43
   44
   45
   46
   47
   48
   49
   50
   51
   52
   53
   54
   55
   56
   57
   58
   59
   60
   61
   62
   63
   64
   65
   66
   67
   68
   69
   70
   71
   72
   73
   74
   75
   76
   77
   78

ash / wm / splitview / layout_divider_controller.h [blame]

// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef ASH_WM_SPLITVIEW_LAYOUT_DIVIDER_CONTROLLER_H_
#define ASH_WM_SPLITVIEW_LAYOUT_DIVIDER_CONTROLLER_H_

#include "ash/wm/splitview/split_view_types.h"

namespace gfx {
class Point;
class Rect;
}  // namespace gfx

namespace aura {
class Window;
}  // namespace aura

namespace ash {

// Defines an interface for the delegate to handle events forwarded from
// `SplitViewDivider`. Implementations of this interface may do special handling
// during resizing, such as adjusting or translating the window bounds for
// performant resizing.
class LayoutDividerController {
 public:
  // Returns the root window for the layout.
  virtual aura::Window* GetRootWindow() const = 0;

  // Resizing functions used when resizing via the divider, where
  // `location_in_screen` is the location of the event that started this resize
  // and will be used to calculate the divider position.
  virtual void StartResizeWithDivider(const gfx::Point& location_in_screen) = 0;
  virtual void UpdateResizeWithDivider(
      const gfx::Point& location_in_screen) = 0;

  // Returns true if the delegate is finished with resizing and can hand back
  // resizing work to `SplitViewDivider`, otherwise returns false, e.g. if the
  // divider is performing a snap animation.
  virtual bool EndResizeWithDivider(const gfx::Point& location_in_screen) = 0;

  // Called when the divider is about to end resizing by finishing window
  // resizing and cleaning up drag details.
  virtual void OnResizeEnding() = 0;

  // Called when the divider has finished cleaning up window resizing.
  virtual void OnResizeEnded() = 0;

  // Swaps the window(s). If in tablet mode, it is triggered by `kDoubleTap`
  // with only one window snapped, the window will be snapped to the other
  // position. For all other cases with the windows in `GetLayoutWindows()`
  // available, the two windows will be swapped together with their bounds.
  virtual void SwapWindows() = 0;

  // Gets snapped bounds in screen coordinates based on `snap_position` and
  // `snap_ratio`. The snapped bounds are updated to accommodate for the
  // `SplitViewDivider` so that the windows and `SplitViewDivider` are not
  // overlapped.
  virtual gfx::Rect GetSnappedWindowBoundsInScreen(
      SnapPosition snap_position,
      aura::Window* window_for_minimum_size,
      float snap_ratio,
      bool account_for_divider_width) const = 0;

  // Returns the snap position of the given snapped `window`.
  // `SnapPosition::kPrimary` is returned if the window is the primary snapped
  // window. `SnapPosition::kSecondary` is returned if the window is the
  // secondary snapped window.
  virtual SnapPosition GetPositionOfSnappedWindow(
      const aura::Window* window) const = 0;

 protected:
  virtual ~LayoutDividerController() = default;
};

}  // namespace ash

#endif  // ASH_WM_SPLITVIEW_LAYOUT_DIVIDER_CONTROLLER_H_