summaryrefslogtreecommitdiff
path: root/chromium/ui/aura/mus/capture_synchronizer.h
blob: 4b300160f296e9d4718a8a587ef042eefaea1eb4 (plain)
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
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef UI_AURA_MUS_CAPTURE_SYNCHRONIZER_H_
#define UI_AURA_MUS_CAPTURE_SYNCHRONIZER_H_

#include <stdint.h>

#include "base/macros.h"
#include "ui/aura/aura_export.h"
#include "ui/aura/client/capture_client_observer.h"
#include "ui/aura/window_observer.h"

namespace ui {
namespace mojom {
class WindowTree;
}
}

namespace aura {
class CaptureSynchronizerDelegate;
class WindowMus;

namespace client {
class CaptureClient;
}

// CaptureSynchronizer is resonsible for keeping capture in sync between aura
// and the mus server.
class AURA_EXPORT CaptureSynchronizer : public WindowObserver,
                                        public client::CaptureClientObserver {
 public:
  CaptureSynchronizer(CaptureSynchronizerDelegate* delegate,
                      ui::mojom::WindowTree* window_tree);
  ~CaptureSynchronizer() override;

  WindowMus* capture_window() { return capture_window_; }

  // Called when the server side wants to change capture to |window|.
  void SetCaptureFromServer(WindowMus* window);

  // Called when the |capture_client| has been set or will be unset.
  void AttachToCaptureClient(client::CaptureClient* capture_client);
  void DetachFromCaptureClient(client::CaptureClient* capture_client);

 private:
  // Internal implementation for capture changes. Adds/removes observer as
  // necessary and sets |capture_window_| to |window|.
  void SetCaptureWindow(WindowMus* window);

  // WindowObserver:
  void OnWindowDestroying(Window* window) override;

  // client::CaptureClientObserver:
  void OnCaptureChanged(Window* lost_capture, Window* gained_capture) override;

  CaptureSynchronizerDelegate* delegate_;
  ui::mojom::WindowTree* window_tree_;

  // Window that currently has capture.
  WindowMus* capture_window_ = nullptr;

  // Used when setting capture from the server to avoid setting capture back
  // on the server. If |setting_capture_| is true SetCaptureFromServer() was
  // called and |window_setting_capture_to_| is the window capture is being
  // set on.
  bool setting_capture_ = false;
  WindowMus* window_setting_capture_to_ = nullptr;

  DISALLOW_COPY_AND_ASSIGN(CaptureSynchronizer);
};

}  // namespace aura

#endif  // UI_AURA_MUS_CAPTURE_SYNCHRONIZER_H_