File: capture_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 (127 lines) | stat: -rw-r--r-- 3,994 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
// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_WM_CORE_CAPTURE_CONTROLLER_H_
#define UI_WM_CORE_CAPTURE_CONTROLLER_H_

#include <map>

#include "base/component_export.h"
#include "base/memory/raw_ptr.h"
#include "base/observer_list.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/window_observer.h"

namespace aura {
namespace client {
class CaptureDelegate;
}
}

namespace wm {

// Internal CaptureClient implementation. See ScopedCaptureClient for details.
class COMPONENT_EXPORT(UI_WM) CaptureController
    : public aura::client::CaptureClient {
 public:
  CaptureController();

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

  ~CaptureController() override;

  static CaptureController* Get() { return instance_; }

  // Adds |root| to the list of root windows notified when capture changes.
  void Attach(aura::Window* root);

  // Removes |root| from the list of root windows notified when capture changes.
  void Detach(aura::Window* root);

  // Resets the current capture window and prevents it from being set again.
  void PrepareForShutdown();

  // Returns true if this CaptureController is installed on at least one
  // root window.
  bool is_active() const { return !delegates_.empty(); }

  // Overridden from aura::client::CaptureClient:
  void SetCapture(aura::Window* window) override;
  void ReleaseCapture(aura::Window* window) override;
  aura::Window* GetCaptureWindow() override;
  aura::Window* GetGlobalCaptureWindow() override;
  void AddObserver(aura::client::CaptureClientObserver* observer) override;
  void RemoveObserver(aura::client::CaptureClientObserver* observer) override;

 private:
  friend class ScopedCaptureClient;

  static CaptureController* instance_;

  // Set to true by `PrepareForShutdown()`. If this is true, `SetCapture()` will
  // have no effect.
  bool destroying_ = false;

  // The current capture window. NULL if there is no capture window.
  raw_ptr<aura::Window> capture_window_;

  // The capture delegate for the root window with native capture. The root
  // window with native capture may not contain |capture_window_|. This occurs
  // if |capture_window_| is reparented to a different root window while it has
  // capture.
  raw_ptr<aura::client::CaptureDelegate> capture_delegate_;

  // The delegates notified when capture changes.
  std::map<aura::Window*,
           raw_ptr<aura::client::CaptureDelegate, CtnExperimental>>
      delegates_;

  base::ObserverList<aura::client::CaptureClientObserver>::Unchecked observers_;
};

// ScopedCaptureClient is responsible for creating a CaptureClient for a
// RootWindow. Specifically it creates a single CaptureController that is shared
// among all ScopedCaptureClients and adds the RootWindow to it.
class COMPONENT_EXPORT(UI_WM) ScopedCaptureClient
    : public aura::WindowObserver {
 public:
  class COMPONENT_EXPORT(UI_WM) TestApi {
   public:
    explicit TestApi(ScopedCaptureClient* client) : client_(client) {}

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

    ~TestApi() {}

    // Sets the delegate.
    void SetDelegate(aura::client::CaptureDelegate* delegate);

   private:
    // Not owned.
    raw_ptr<ScopedCaptureClient> client_;
  };

  explicit ScopedCaptureClient(aura::Window* root);

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

  ~ScopedCaptureClient() override;

  // Overridden from aura::WindowObserver:
  void OnWindowDestroyed(aura::Window* window) override;

 private:
  // Invoked from destructor and OnWindowDestroyed() to cleanup.
  void Shutdown();

  // RootWindow this ScopedCaptureClient was create for.
  raw_ptr<aura::Window> root_window_;
};

}  // namespace wm

#endif  // UI_WM_CORE_CAPTURE_CONTROLLER_H_