Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(90)

Side by Side Diff: ui/aura/mus/window_port_mus.h

Issue 2445163002: Make aura work with mus (Closed)
Patch Set: NON_EXPORTED_BASE_CLASS Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/aura/mus/window_mus.h ('k') | ui/aura/mus/window_port_mus.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef UI_AURA_MUS_WINDOW_PORT_MUS_H_
6 #define UI_AURA_MUS_WINDOW_PORT_MUS_H_
7
8 #include <stdint.h>
9
10 #include <string>
11 #include <vector>
12
13 #include "base/logging.h"
14 #include "base/macros.h"
15 #include "services/ui/public/interfaces/cursor.mojom.h"
16 #include "ui/aura/aura_export.h"
17 #include "ui/aura/mus/mus_types.h"
18 #include "ui/aura/mus/window_mus.h"
19 #include "ui/aura/window_port.h"
20 #include "ui/gfx/geometry/rect.h"
21 #include "ui/platform_window/mojo/text_input_state.mojom.h"
22
23 namespace aura {
24
25 class PropertyConverter;
26 class SurfaceIdHandler;
27 class Window;
28 class WindowPortMusTestApi;
29 class WindowTreeClient;
30 class WindowTreeClientPrivate;
31
32 // WindowPortMus is a WindowPort that forwards calls to WindowTreeClient
33 // so that changes are propagated to the server. All changes from
34 // WindowTreeClient to the underlying Window route through this class (by
35 // way of WindowMus) and are done in such a way that they don't result in
36 // calling back to WindowTreeClient.
37 class AURA_EXPORT WindowPortMus : public WindowPort, public WindowMus {
38 public:
39 WindowPortMus(WindowTreeClient* client);
40 ~WindowPortMus() override;
41
42 static WindowPortMus* Get(Window* window);
43
44 Window* window() { return window_; }
45 const Window* window() const { return window_; }
46
47 void SetTextInputState(mojo::TextInputStatePtr state);
48 void SetImeVisibility(bool visible, mojo::TextInputStatePtr state);
49
50 ui::mojom::Cursor predefined_cursor() const { return predefined_cursor_; }
51 void SetPredefinedCursor(ui::mojom::Cursor cursor_id);
52
53 void set_surface_id_handler(SurfaceIdHandler* surface_id_handler) {
54 surface_id_handler_ = surface_id_handler;
55 }
56
57 private:
58 friend class WindowPortMusTestApi;
59 friend class WindowTreeClient;
60 friend class WindowTreeClientPrivate;
61
62 using ServerChangeIdType = uint8_t;
63
64 // Changes to the underlying Window originating from the server must be done
65 // in such a way that the same change is not applied back to the server. To
66 // accomplish this every changes from the server is associated with at least
67 // one ServerChange. If the underlying Window ends up calling back to this
68 // class and the change is expected then the change is ignored and not sent to
69 // the server. For example, here's the flow when the server changes the
70 // bounds:
71 // . WindowTreeClient calls SetBoundsFromServer().
72 // . A ServerChange is added of type BOUNDS and the matching bounds.
73 // . Window::SetBounds() is called.
74 // . Window::SetBounds() calls WindowPortMus::OnDidChangeBounds().
75 // . A ServerChange of type BOUNDS is found, and the request is ignored.
76 // Additionally the ServerChange is removed at this point so that if another
77 // bounds change is made it will be propagated. This is important as changes
78 // to underyling window may generate more changes.
79 //
80 // The typical pattern in implementing a call from the server looks like:
81 // // Create and configure the data as appropriate to the change:
82 // ServerChangeData data;
83 // data.foo = window->bar();
84 // ScopedServerChange change(this, ServerChangeType::FOO, data);
85 // window_->SetFoo(...);
86 //
87 // And the call from the Window (by way of WindowPort interface) looks like:
88 // ServerChangeData change_data;
89 // change_data.foo = ...;
90 // if (!RemoveChangeByTypeAndData(ServerChangeType::FOO, change_data))
91 // window_tree_client_->OnFooChanged(this, ...);
92 enum ServerChangeType {
93 ADD,
94 BOUNDS,
95 PROPERTY,
96 REMOVE,
97 REORDER,
98 VISIBLE,
99 };
100
101 // Contains data needed to identify a change from the server.
102 struct ServerChangeData {
103 // Applies to ADD, REMOVE and REORDER.
104 Id child_id;
105 // Applies to BOUNDS.
106 gfx::Rect bounds;
107 // Applies to VISIBLE.
108 bool visible;
109 // Applies to PROPERTY.
110 std::string property_name;
111 };
112
113 // Used to identify a change the server.
114 struct ServerChange {
115 ServerChangeType type;
116 // A unique id assigned to the change and used later on to identify it for
117 // removal.
118 ServerChangeIdType server_change_id;
119 ServerChangeData data;
120 };
121
122 // Convenience for adding/removing a ScopedChange.
123 class ScopedServerChange {
124 public:
125 ScopedServerChange(WindowPortMus* window_impl,
126 const ServerChangeType type,
127 const ServerChangeData& data)
128 : window_impl_(window_impl),
129 server_change_id_(window_impl->ScheduleChange(type, data)) {}
130
131 ~ScopedServerChange() { window_impl_->RemoveChangeById(server_change_id_); }
132
133 private:
134 WindowPortMus* window_impl_;
135 const ServerChangeIdType server_change_id_;
136
137 DISALLOW_COPY_AND_ASSIGN(ScopedServerChange);
138 };
139
140 // Creates and adds a ServerChange to |server_changes_|. Returns the id
141 // assigned to the ServerChange.
142 ServerChangeIdType ScheduleChange(const ServerChangeType type,
143 const ServerChangeData& data);
144
145 // Removes a ServerChange by id.
146 void RemoveChangeById(ServerChangeIdType change_id);
147
148 // If there is a schedule change matching |type| and |data| it is removed and
149 // true is returned. If no matching change is scheduled returns false.
150 bool RemoveChangeByTypeAndData(const ServerChangeType type,
151 const ServerChangeData& data);
152
153 PropertyConverter* GetPropertyConverter();
154
155 // WindowMus:
156 Window* GetWindow() override;
157 void AddChildFromServer(WindowMus* window) override;
158 void RemoveChildFromServer(WindowMus* child) override;
159 void ReorderFromServer(WindowMus* child,
160 WindowMus* relative,
161 ui::mojom::OrderDirection) override;
162 void SetBoundsFromServer(const gfx::Rect& bounds) override;
163 void SetVisibleFromServer(bool visible) override;
164 void SetOpacityFromServer(float opacity) override;
165 void SetPredefinedCursorFromServer(ui::mojom::Cursor cursor) override;
166 void SetPropertyFromServer(
167 const std::string& property_name,
168 const std::vector<uint8_t>* property_data) override;
169 void SetSurfaceIdFromServer(
170 std::unique_ptr<SurfaceInfo> surface_info) override;
171 void NotifyEmbeddedAppDisconnected() override;
172
173 // WindowPort:
174 std::unique_ptr<WindowPortInitData> OnPreInit(Window* window) override;
175 void OnPostInit(std::unique_ptr<WindowPortInitData> init_data) override;
176 void OnDeviceScaleFactorChanged(float device_scale_factor) override;
177 void OnWillAddChild(Window* child) override;
178 void OnWillRemoveChild(Window* child) override;
179 void OnWillMoveChild(size_t current_index, size_t dest_index) override;
180 void OnVisibilityChanged(bool visible) override;
181 void OnDidChangeBounds(const gfx::Rect& old_bounds,
182 const gfx::Rect& new_bounds) override;
183 std::unique_ptr<WindowPortPropertyData> OnWillChangeProperty(
184 const void* key) override;
185 void OnPropertyChanged(const void* key,
186 std::unique_ptr<WindowPortPropertyData> data) override;
187
188 WindowTreeClient* window_tree_client_;
189 Window* window_ = nullptr;
190
191 ServerChangeIdType next_server_change_id_ = 0;
192 std::vector<ServerChange> server_changes_;
193
194 SurfaceIdHandler* surface_id_handler_;
195 std::unique_ptr<SurfaceInfo> surface_info_;
196
197 ui::mojom::Cursor predefined_cursor_ = ui::mojom::Cursor::CURSOR_NULL;
198
199 DISALLOW_COPY_AND_ASSIGN(WindowPortMus);
200 };
201
202 } // namespace aura
203
204 #endif // UI_AURA_MUS_WINDOW_PORT_MUS_H_
OLDNEW
« no previous file with comments | « ui/aura/mus/window_mus.h ('k') | ui/aura/mus/window_port_mus.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698