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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
|
// Copyright 2015 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 COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_
#define COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_
#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "components/mus/common/types.h"
#include "components/mus/public/interfaces/window_tree_host.mojom.h"
#include "components/mus/ws/display_manager.h"
#include "components/mus/ws/event_dispatcher.h"
#include "components/mus/ws/event_dispatcher_delegate.h"
#include "components/mus/ws/focus_controller_delegate.h"
#include "components/mus/ws/server_window.h"
#include "components/mus/ws/server_window_observer.h"
namespace mus {
namespace ws {
class ConnectionManager;
class FocusController;
class WindowTreeHostDelegate;
class WindowTreeImpl;
// WindowTreeHostImpl is an implementation of the WindowTreeHost interface.
// It serves as a top level root window for a window. Its lifetime is managed by
// ConnectionManager. If the connection to the client breaks or if the user
// closes the associated window, then this object and related state will be
// deleted.
class WindowTreeHostImpl : public DisplayManagerDelegate,
public mojom::WindowTreeHost,
public FocusControllerDelegate,
public EventDispatcherDelegate,
public ServerWindowObserver {
public:
// TODO(fsamuel): All these parameters are just plumbing for creating
// DisplayManagers. We should probably just store these common parameters
// in the DisplayManagerFactory and pass them along on DisplayManager::Create.
WindowTreeHostImpl(mojom::WindowTreeHostClientPtr client,
ConnectionManager* connection_manager,
mojo::ApplicationImpl* app_impl,
const scoped_refptr<GpuState>& gpu_state,
const scoped_refptr<SurfacesState>& surfaces_state,
mojom::WindowManagerPtr window_manater);
~WindowTreeHostImpl() override;
// Initializes state that depends on the existence of a WindowTreeHostImpl.
void Init(WindowTreeHostDelegate* delegate);
WindowTreeImpl* GetWindowTree();
mojom::WindowTreeHostClient* client() const { return client_.get(); }
// Returns whether |window| is a descendant of this root but not itself a
// root window.
bool IsWindowAttachedToRoot(const ServerWindow* window) const;
// Schedules a paint for the specified region in the coordinates of |window|
// if
// the |window| is in this viewport. Returns whether |window| is in the
// viewport.
bool SchedulePaintIfInViewport(const ServerWindow* window,
const gfx::Rect& bounds);
// Schedules destruction of surfaces in |window|. If a frame has been
// scheduled but not drawn surface destruction is delayed until the frame is
// drawn, otherwise destruction is immediate.
void ScheduleSurfaceDestruction(ServerWindow* window);
// Returns the metrics for this viewport.
const mojom::ViewportMetrics& GetViewportMetrics() const;
ConnectionManager* connection_manager() { return connection_manager_; }
mojom::WindowManager* window_manager() { return window_manager_.get(); }
// Returns the root ServerWindow of this viewport.
ServerWindow* root_window() { return root_.get(); }
const ServerWindow* root_window() const { return root_.get(); }
void SetFocusedWindow(ServerWindow* window);
ServerWindow* GetFocusedWindow();
void DestroyFocusController();
void UpdateTextInputState(ServerWindow* window,
const ui::TextInputState& state);
void SetImeVisibility(ServerWindow* window, bool visible);
// WindowTreeHost:
void SetSize(mojo::SizePtr size) override;
void SetTitle(const mojo::String& title) override;
void AddAccelerator(uint32_t id,
mojom::EventMatcherPtr event_matcher) override;
void RemoveAccelerator(uint32_t id) override;
private:
void OnClientClosed();
// DisplayManagerDelegate:
ServerWindow* GetRootWindow() override;
void OnEvent(mojom::EventPtr event) override;
void OnDisplayClosed() override;
void OnViewportMetricsChanged(
const mojom::ViewportMetrics& old_metrics,
const mojom::ViewportMetrics& new_metrics) override;
void OnTopLevelSurfaceChanged(cc::SurfaceId surface_id) override;
void OnCompositorFrameDrawn() override;
// FocusControllerDelegate:
void OnFocusChanged(ServerWindow* old_focused_window,
ServerWindow* new_focused_window) override;
// EventDispatcherDelegate:
void OnAccelerator(uint32_t accelerator_id, mojom::EventPtr event) override;
void SetFocusedWindowFromEventDispatcher(ServerWindow* window) override;
ServerWindow* GetFocusedWindowForEventDispatcher() override;
void DispatchInputEventToWindow(ServerWindow* target,
bool in_nonclient_area,
mojom::EventPtr event) override;
// ServerWindowObserver:
void OnWindowDestroyed(ServerWindow* window) override;
WindowTreeHostDelegate* delegate_;
ConnectionManager* const connection_manager_;
mojom::WindowTreeHostClientPtr client_;
EventDispatcher event_dispatcher_;
scoped_ptr<ServerWindow> root_;
scoped_ptr<DisplayManager> display_manager_;
scoped_ptr<FocusController> focus_controller_;
mojom::WindowManagerPtr window_manager_;
// Set of windows with surfaces that need to be destroyed once the frame
// draws.
std::set<ServerWindow*> windows_needing_frame_destruction_;
DISALLOW_COPY_AND_ASSIGN(WindowTreeHostImpl);
};
} // namespace ws
} // namespace mus
#endif // COMPONENTS_MUS_WS_WINDOW_TREE_HOST_IMPL_H_
|