File: snap_controller.h

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (79 lines) | stat: -rw-r--r-- 3,163 bytes parent folder | download | duplicates (5)
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
79
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROMEOS_UI_FRAME_CAPTION_BUTTONS_SNAP_CONTROLLER_H_
#define CHROMEOS_UI_FRAME_CAPTION_BUTTONS_SNAP_CONTROLLER_H_

#include "base/component_export.h"

namespace aura {
class Window;
}

namespace chromeos {

// Snap ratios that correspond to the size of a window when it is snapped. A
// window with `kOneThirdSnapRatio` will snap to one third of the display,
// `kTwoThirdSnapRatio` will snap to two thirds of the display, and
// `kDefaultSnapRatio` will snap to the default half of the display.
constexpr float kOneThirdSnapRatio = 1.f / 3.f;
constexpr float kDefaultSnapRatio = 0.5f;
constexpr float kTwoThirdSnapRatio = 2.f / 3.f;

// The previewed snap state for a window, corresponding to the use of a
// PhantomWindowController.
enum class SnapDirection {
  kNone,       // No snap preview.
  kPrimary,    // The phantom window controller is previewing a snap to the
               // primary position, translated into left for landscape display
               // (or right for secondary display layout) and top (or bottom)
               // for portrait display. For more details, see
               // description for `IsLayoutHorizontal()`.
  kSecondary,  // The phantom window controller is previewing a snap to the
               // secondary position, the opposite position of the primary. For
               // example, in primary portrait display, primary position is the
               // top and secondary position is the bottom.
};

// This interface handles snap actions to be performed on a top level window.
// The singleton that implements the interface is provided by Ash.
class COMPONENT_EXPORT(CHROMEOS_UI_FRAME) SnapController {
 public:
  // The sources of the snap request that are from the window size button.
  // Currently there can be two sources: either by long pressing on the size
  // button and then pressing on one of the snap buttons, or by hovering the
  // size button to show the window layout menu and then pressing on one of the
  // snap options.
  enum class SnapRequestSource {
    kSnapButton,
    kWindowLayoutMenu,
  };

  virtual ~SnapController();

  static SnapController* Get();

  // Returns whether the snapping action on the size button should be enabled.
  virtual bool CanSnap(aura::Window* window) = 0;

  // Shows a preview (phantom window) for the given snap direction.
  // `allow_haptic_feedback` indicates if it should send haptic feedback.
  virtual void ShowSnapPreview(aura::Window* window,
                               SnapDirection snap,
                               bool allow_haptic_feedback) = 0;

  // Snaps the window in the given direction, if not kNone. Destroys the preview
  // window, if any.
  virtual void CommitSnap(aura::Window* window,
                          SnapDirection snap,
                          float snap_ratio,
                          SnapRequestSource snap_request_source) = 0;

 protected:
  SnapController();
};

}  // namespace chromeos

#endif  // CHROMEOS_UI_FRAME_CAPTION_BUTTONS_SNAP_CONTROLLER_H_