OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ | 5 #ifndef COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ |
6 #define COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ | 6 #define COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ |
7 | 7 |
8 #include <stdint.h> | 8 #include <stdint.h> |
9 | 9 |
10 #include <memory> | 10 #include <memory> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/macros.h" | 14 #include "base/macros.h" |
15 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
16 #include "components/mus/public/cpp/window_observer.h" | 16 #include "components/mus/public/cpp/window_observer.h" |
17 #include "mojo/public/cpp/bindings/array.h" | 17 #include "mojo/public/cpp/bindings/array.h" |
18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
19 | 19 |
20 namespace mus { | 20 namespace mus { |
21 | 21 |
22 namespace mojom { | 22 namespace mojom { |
23 enum class Cursor : int32_t; | 23 enum class Cursor : int32_t; |
24 } | 24 } |
25 | 25 |
26 class Window; | 26 class Window; |
27 class WindowTreeClientImpl; | 27 class WindowTreeClient; |
28 | 28 |
29 enum class ChangeType { | 29 enum class ChangeType { |
30 ADD_CHILD, | 30 ADD_CHILD, |
31 ADD_TRANSIENT_WINDOW, | 31 ADD_TRANSIENT_WINDOW, |
32 BOUNDS, | 32 BOUNDS, |
33 CAPTURE, | 33 CAPTURE, |
34 DELETE_WINDOW, | 34 DELETE_WINDOW, |
35 FOCUS, | 35 FOCUS, |
36 NEW_WINDOW, | 36 NEW_WINDOW, |
37 NEW_TOP_LEVEL_WINDOW, | 37 NEW_TOP_LEVEL_WINDOW, |
(...skipping 30 matching lines...) Expand all Loading... |
68 // invoked followed by Revert(). The expectation is Revert() sets the | 68 // invoked followed by Revert(). The expectation is Revert() sets the |
69 // appropriate value back on the Window. | 69 // appropriate value back on the Window. |
70 // | 70 // |
71 // In general there are two classes of changes: | 71 // In general there are two classes of changes: |
72 // 1. We are the only side allowed to make the change. | 72 // 1. We are the only side allowed to make the change. |
73 // 2. The change can also be applied by another client. For example, the | 73 // 2. The change can also be applied by another client. For example, the |
74 // window manager may change the bounds as well as the local client. | 74 // window manager may change the bounds as well as the local client. |
75 // | 75 // |
76 // For (1) use CrashInFlightChange. As the name implies this change CHECKs that | 76 // For (1) use CrashInFlightChange. As the name implies this change CHECKs that |
77 // the change succeeded. Use the following pattern for this. This code goes | 77 // the change succeeded. Use the following pattern for this. This code goes |
78 // where the change is sent to the server (in WindowTreeClientImpl): | 78 // where the change is sent to the server (in WindowTreeClient): |
79 // const uint32_t change_id = | 79 // const uint32_t change_id = |
80 // ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( | 80 // ScheduleInFlightChange(base::WrapUnique(new CrashInFlightChange( |
81 // window, ChangeType::REORDER))); | 81 // window, ChangeType::REORDER))); |
82 // | 82 // |
83 // For (2) use the same pattern as (1), but in the on change callback from the | 83 // For (2) use the same pattern as (1), but in the on change callback from the |
84 // server (e.g. OnWindowBoundsChanged()) add the following: | 84 // server (e.g. OnWindowBoundsChanged()) add the following: |
85 // // value_from_server is the value supplied from the server. It corresponds | 85 // // value_from_server is the value supplied from the server. It corresponds |
86 // // to the value of the property at the time the server processed the | 86 // // to the value of the property at the time the server processed the |
87 // // change. If the local change fails, this is the value reverted to. | 87 // // change. If the local change fails, this is the value reverted to. |
88 // InFlightBoundsChange new_change(window, value_from_server); | 88 // InFlightBoundsChange new_change(window, value_from_server); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 | 152 |
153 // InFlightChange: | 153 // InFlightChange: |
154 void SetRevertValueFrom(const InFlightChange& change) override; | 154 void SetRevertValueFrom(const InFlightChange& change) override; |
155 void ChangeFailed() override; | 155 void ChangeFailed() override; |
156 void Revert() override; | 156 void Revert() override; |
157 | 157 |
158 private: | 158 private: |
159 DISALLOW_COPY_AND_ASSIGN(CrashInFlightChange); | 159 DISALLOW_COPY_AND_ASSIGN(CrashInFlightChange); |
160 }; | 160 }; |
161 | 161 |
162 // Use this class for properties that are specific to the connection, and not a | 162 // Use this class for properties that are specific to the client, and not a |
163 // particular window. For example, only a single window can have focus, so focus | 163 // particular window. For example, only a single window can have focus, so focus |
164 // is specific to the connection. | 164 // is specific to the client. |
165 // | 165 // |
166 // This does not implement InFlightChange::Revert, subclasses must implement | 166 // This does not implement InFlightChange::Revert, subclasses must implement |
167 // that to update the WindowTreeConnection. | 167 // that to update the WindowTreeClient. |
168 class InFlightWindowTreeClientChange : public InFlightChange, | 168 class InFlightWindowTreeClientChange : public InFlightChange, |
169 public WindowObserver { | 169 public WindowObserver { |
170 public: | 170 public: |
171 InFlightWindowTreeClientChange(WindowTreeClientImpl* client_connection, | 171 InFlightWindowTreeClientChange(WindowTreeClient* client, |
172 Window* revert_value, | 172 Window* revert_value, |
173 ChangeType type); | 173 ChangeType type); |
174 ~InFlightWindowTreeClientChange() override; | 174 ~InFlightWindowTreeClientChange() override; |
175 | 175 |
176 // InFlightChange: | 176 // InFlightChange: |
177 void SetRevertValueFrom(const InFlightChange& change) override; | 177 void SetRevertValueFrom(const InFlightChange& change) override; |
178 | 178 |
179 protected: | 179 protected: |
180 WindowTreeClientImpl* connection() { return connection_; } | 180 WindowTreeClient* client() { return client_; } |
181 Window* revert_window() { return revert_window_; } | 181 Window* revert_window() { return revert_window_; } |
182 | 182 |
183 private: | 183 private: |
184 void SetRevertWindow(Window* window); | 184 void SetRevertWindow(Window* window); |
185 | 185 |
186 // WindowObserver: | 186 // WindowObserver: |
187 void OnWindowDestroying(Window* window) override; | 187 void OnWindowDestroying(Window* window) override; |
188 | 188 |
189 WindowTreeClientImpl* connection_; | 189 WindowTreeClient* client_; |
190 Window* revert_window_; | 190 Window* revert_window_; |
191 | 191 |
192 DISALLOW_COPY_AND_ASSIGN(InFlightWindowTreeClientChange); | 192 DISALLOW_COPY_AND_ASSIGN(InFlightWindowTreeClientChange); |
193 }; | 193 }; |
194 | 194 |
195 class InFlightCaptureChange : public InFlightWindowTreeClientChange { | 195 class InFlightCaptureChange : public InFlightWindowTreeClientChange { |
196 public: | 196 public: |
197 InFlightCaptureChange(WindowTreeClientImpl* client_connection, | 197 InFlightCaptureChange(WindowTreeClient* client, Window* revert_value); |
198 Window* revert_value); | |
199 ~InFlightCaptureChange() override; | 198 ~InFlightCaptureChange() override; |
200 | 199 |
201 // InFlightChange: | 200 // InFlightChange: |
202 void Revert() override; | 201 void Revert() override; |
203 | 202 |
204 private: | 203 private: |
205 DISALLOW_COPY_AND_ASSIGN(InFlightCaptureChange); | 204 DISALLOW_COPY_AND_ASSIGN(InFlightCaptureChange); |
206 }; | 205 }; |
207 | 206 |
208 class InFlightFocusChange : public InFlightWindowTreeClientChange { | 207 class InFlightFocusChange : public InFlightWindowTreeClientChange { |
209 public: | 208 public: |
210 InFlightFocusChange(WindowTreeClientImpl* client_connection, | 209 InFlightFocusChange(WindowTreeClient* client, Window* revert_value); |
211 Window* revert_value); | |
212 ~InFlightFocusChange() override; | 210 ~InFlightFocusChange() override; |
213 | 211 |
214 // InFlightChange: | 212 // InFlightChange: |
215 void Revert() override; | 213 void Revert() override; |
216 | 214 |
217 private: | 215 private: |
218 DISALLOW_COPY_AND_ASSIGN(InFlightFocusChange); | 216 DISALLOW_COPY_AND_ASSIGN(InFlightFocusChange); |
219 }; | 217 }; |
220 | 218 |
221 class InFlightPropertyChange : public InFlightChange { | 219 class InFlightPropertyChange : public InFlightChange { |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
291 void SetRevertValueFrom(const InFlightChange& change) override; | 289 void SetRevertValueFrom(const InFlightChange& change) override; |
292 void Revert() override; | 290 void Revert() override; |
293 | 291 |
294 private: | 292 private: |
295 DISALLOW_COPY_AND_ASSIGN(InFlightSetModalChange); | 293 DISALLOW_COPY_AND_ASSIGN(InFlightSetModalChange); |
296 }; | 294 }; |
297 | 295 |
298 } // namespace mus | 296 } // namespace mus |
299 | 297 |
300 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ | 298 #endif // COMPONENTS_MUS_PUBLIC_CPP_LIB_IN_FLIGHT_CHANGE_H_ |
OLD | NEW |