File: multitask_menu_view.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 (128 lines) | stat: -rw-r--r-- 4,899 bytes parent folder | download | duplicates (6)
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
// Copyright 2022 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_MULTITASK_MENU_MULTITASK_MENU_VIEW_H_
#define CHROMEOS_UI_FRAME_MULTITASK_MENU_MULTITASK_MENU_VIEW_H_

#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "chromeos/ui/frame/caption_buttons/snap_controller.h"
#include "ui/aura/window_observer.h"
#include "ui/base/metadata/metadata_header_macros.h"
#include "ui/views/view.h"

namespace views {
class View;
}  // namespace views

namespace chromeos {

enum class SnapDirection;
class MultitaskButton;
class SplitButtonView;

// Contains buttons which can fullscreen, snap, or float a window.
class COMPONENT_EXPORT(CHROMEOS_UI_FRAME) MultitaskMenuView
    : public views::View,
      public aura::WindowObserver {
  METADATA_HEADER(MultitaskMenuView, views::View)

 public:
  // Bitmask for the buttons to show on the multitask menu view.
  enum MultitaskButtons : uint8_t {
    kHalfSplit = 1 << 0,
    kPartialSplit = 1 << 1,
    kFullscreen = 1 << 2,
    kFloat = 1 << 3,
  };

  // `window` is the window that the buttons on this view act on. `anchor_view`
  // should be passed when we want the functionality of auto-closing the menu
  // when the mouse moves out of the menu or the anchor.
  MultitaskMenuView(aura::Window* window,
                    base::RepeatingClosure close_callback,
                    base::RepeatingClosure dismiss_callback,
                    uint8_t buttons,
                    views::View* anchor_view);

  MultitaskMenuView(const MultitaskMenuView&) = delete;
  MultitaskMenuView& operator=(const MultitaskMenuView&) = delete;

  ~MultitaskMenuView() override;

  SplitButtonView* partial_button() { return partial_button_.get(); }

  // Forwarded from the size button which is the anchor of `this`'s widget. When
  // an event starts on the size button, it will receive all subsequent events.
  // Therefore, we have to manually forward them if the pointer is visually on
  // `this`. Receives the event and updates the hover state or fires the
  // callback of the button that the pointer is visually on top of.
  // `OnSizeButtonRelease` returns true if any button was activated.
  void OnSizeButtonDrag(const gfx::Point& event_screen_location);
  bool OnSizeButtonRelease(const gfx::Point& event_screen_location);

  // views::View:
  void AddedToWidget() override;
  bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
  bool OnKeyPressed(const ui::KeyEvent& event) override;

  // aura::WindowObserver:
  void OnWindowDestroying(aura::Window* parent_window) override;
  void OnWindowBoundsChanged(aura::Window* window,
                             const gfx::Rect& old_bounds,
                             const gfx::Rect& new_bounds,
                             ui::PropertyChangeReason reason) override;
  void OnWindowVisibilityChanging(aura::Window* window, bool visible) override;

  // If the menu is opened because of mouse hover, moving the mouse outside the
  // menu for 3 seconds will result in it auto closing. This function reduces
  // that 3 second delay to zero.
  static void SetSkipMouseOutDelayForTesting(bool val);

 private:
  class MenuPreTargetHandler;
  friend class MultitaskMenuViewTestApi;

  // Callbacks for the buttons in the multitask menu view.
  void HalfButtonPressed(SnapDirection direction);
  void PartialButtonPressed(SnapDirection direction);
  void FullScreenButtonPressed();
  void FloatButtonPressed();

  // Owned by views hierarchy.
  raw_ptr<SplitButtonView> half_button_ = nullptr;
  raw_ptr<SplitButtonView> partial_button_ = nullptr;
  raw_ptr<MultitaskButton> full_button_ = nullptr;
  raw_ptr<MultitaskButton> float_button_ = nullptr;

  // True if the menu buttons should be painted in reverse, when the `Alt` key
  // is pressed. Toggled on every `Alt` press.
  bool is_reversed_ = false;

  // The window which the buttons act on.
  raw_ptr<aura::Window> window_;

  // The view the menu is anchored to if any. This is only passed if we want to
  // close the menu when the mouse moves out of the multitask menu or its anchor
  // view.
  const raw_ptr<views::View, DanglingUntriaged> anchor_view_;

  // Runs when the widget which contains `this` should be destroyed. For
  // example, after any of the buttons are pressed, or a press out of the menu
  // bounds.
  base::RepeatingClosure close_callback_;

  // Run by the `MenuPreTargetHandler` to dismiss the menu when clicking outside
  // the menu (or anchor) bounds, or after timeout.
  base::RepeatingClosure dismiss_callback_;

  std::unique_ptr<MenuPreTargetHandler> event_handler_;

  base::ScopedObservation<aura::Window, aura::WindowObserver>
      window_observation_{this};
};

}  // namespace chromeos

#endif  // CHROMEOS_UI_FRAME_MULTITASK_MENU_MULTITASK_MENU_VIEW_H_