| 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 SERVICES_UI_PUBLIC_CPP_IN_FLIGHT_CHANGE_H_ | 5 #ifndef UI_AURA_MUS_IN_FLIGHT_CHANGE_H_ |
| 6 #define SERVICES_UI_PUBLIC_CPP_IN_FLIGHT_CHANGE_H_ | 6 #define UI_AURA_MUS_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 "mojo/public/cpp/bindings/array.h" | 16 #include "mojo/public/cpp/bindings/array.h" |
| 17 #include "services/ui/public/cpp/window_observer.h" | 17 #include "ui/aura/window_observer.h" |
| 18 #include "ui/gfx/geometry/rect.h" | 18 #include "ui/gfx/geometry/rect.h" |
| 19 | 19 |
| 20 namespace ui { | 20 namespace ui { |
| 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 } // namespace ui |
| 27 |
| 28 namespace aura { |
| 29 |
| 30 class WindowMus; |
| 27 class WindowTreeClient; | 31 class WindowTreeClient; |
| 28 | 32 |
| 29 enum class ChangeType { | 33 enum class ChangeType { |
| 30 ADD_CHILD, | 34 ADD_CHILD, |
| 31 ADD_TRANSIENT_WINDOW, | 35 ADD_TRANSIENT_WINDOW, |
| 32 BOUNDS, | 36 BOUNDS, |
| 33 CAPTURE, | 37 CAPTURE, |
| 34 DELETE_WINDOW, | 38 DELETE_WINDOW, |
| 35 DRAG_LOOP, | 39 DRAG_LOOP, |
| 36 FOCUS, | 40 FOCUS, |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 // // change takes the value to revert from |new_change|. | 97 // // change takes the value to revert from |new_change|. |
| 94 // return; | 98 // return; |
| 95 // } | 99 // } |
| 96 // | 100 // |
| 97 // // else case is no flight in change and the new value can be applied | 101 // // else case is no flight in change and the new value can be applied |
| 98 // // immediately. | 102 // // immediately. |
| 99 // WindowPrivate(window).LocalSetValue(new_value_from_server); | 103 // WindowPrivate(window).LocalSetValue(new_value_from_server); |
| 100 // | 104 // |
| 101 class InFlightChange { | 105 class InFlightChange { |
| 102 public: | 106 public: |
| 103 InFlightChange(Window* window, ChangeType type); | 107 InFlightChange(WindowMus* window, ChangeType type); |
| 104 virtual ~InFlightChange(); | 108 virtual ~InFlightChange(); |
| 105 | 109 |
| 106 // NOTE: for properties not associated with any window window is null. | 110 // NOTE: for properties not associated with any window window is null. |
| 107 Window* window() { return window_; } | 111 WindowMus* window() { return window_; } |
| 108 const Window* window() const { return window_; } | 112 const WindowMus* window() const { return window_; } |
| 109 ChangeType change_type() const { return change_type_; } | 113 ChangeType change_type() const { return change_type_; } |
| 110 | 114 |
| 111 // Returns true if the two changes are considered the same. This is only | 115 // Returns true if the two changes are considered the same. This is only |
| 112 // invoked if the window id and ChangeType match. | 116 // invoked if the window id and ChangeType match. |
| 113 virtual bool Matches(const InFlightChange& change) const; | 117 virtual bool Matches(const InFlightChange& change) const; |
| 114 | 118 |
| 115 // Called in two cases: | 119 // Called in two cases: |
| 116 // . When the corresponding property on the server changes. In this case | 120 // . When the corresponding property on the server changes. In this case |
| 117 // |change| corresponds to the value from the server. | 121 // |change| corresponds to the value from the server. |
| 118 // . When |change| unsuccesfully completes. | 122 // . When |change| unsuccesfully completes. |
| 119 virtual void SetRevertValueFrom(const InFlightChange& change) = 0; | 123 virtual void SetRevertValueFrom(const InFlightChange& change) = 0; |
| 120 | 124 |
| 121 // The change failed. Normally you need not take any action here as Revert() | 125 // The change failed. Normally you need not take any action here as Revert() |
| 122 // is called as appropriate. | 126 // is called as appropriate. |
| 123 virtual void ChangeFailed(); | 127 virtual void ChangeFailed(); |
| 124 | 128 |
| 125 // The change failed and there is no pending change of the same type | 129 // The change failed and there is no pending change of the same type |
| 126 // outstanding, revert the value. | 130 // outstanding, revert the value. |
| 127 virtual void Revert() = 0; | 131 virtual void Revert() = 0; |
| 128 | 132 |
| 129 private: | 133 private: |
| 130 Window* window_; | 134 WindowMus* window_; |
| 131 const ChangeType change_type_; | 135 const ChangeType change_type_; |
| 132 }; | 136 }; |
| 133 | 137 |
| 134 class InFlightBoundsChange : public InFlightChange { | 138 class InFlightBoundsChange : public InFlightChange { |
| 135 public: | 139 public: |
| 136 InFlightBoundsChange(Window* window, const gfx::Rect& revert_bounds); | 140 InFlightBoundsChange(WindowMus* window, const gfx::Rect& revert_bounds); |
| 137 | 141 |
| 138 // InFlightChange: | 142 // InFlightChange: |
| 139 void SetRevertValueFrom(const InFlightChange& change) override; | 143 void SetRevertValueFrom(const InFlightChange& change) override; |
| 140 void Revert() override; | 144 void Revert() override; |
| 141 | 145 |
| 142 private: | 146 private: |
| 143 gfx::Rect revert_bounds_; | 147 gfx::Rect revert_bounds_; |
| 144 | 148 |
| 145 DISALLOW_COPY_AND_ASSIGN(InFlightBoundsChange); | 149 DISALLOW_COPY_AND_ASSIGN(InFlightBoundsChange); |
| 146 }; | 150 }; |
| 147 | 151 |
| 148 class InFlightDragChange : public InFlightChange { | 152 class InFlightDragChange : public InFlightChange { |
| 149 public: | 153 public: |
| 150 InFlightDragChange(Window* window, ChangeType type); | 154 InFlightDragChange(WindowMus* window, ChangeType type); |
| 151 | 155 |
| 152 // InFlightChange: | 156 // InFlightChange: |
| 153 void SetRevertValueFrom(const InFlightChange& change) override; | 157 void SetRevertValueFrom(const InFlightChange& change) override; |
| 154 void Revert() override; | 158 void Revert() override; |
| 155 | 159 |
| 156 private: | 160 private: |
| 157 DISALLOW_COPY_AND_ASSIGN(InFlightDragChange); | 161 DISALLOW_COPY_AND_ASSIGN(InFlightDragChange); |
| 158 }; | 162 }; |
| 159 | 163 |
| 160 // Inflight change that crashes on failure. This is useful for changes that are | 164 // Inflight change that crashes on failure. This is useful for changes that are |
| 161 // expected to always complete. | 165 // expected to always complete. |
| 162 class CrashInFlightChange : public InFlightChange { | 166 class CrashInFlightChange : public InFlightChange { |
| 163 public: | 167 public: |
| 164 CrashInFlightChange(Window* window, ChangeType type); | 168 CrashInFlightChange(WindowMus* window, ChangeType type); |
| 165 ~CrashInFlightChange() override; | 169 ~CrashInFlightChange() override; |
| 166 | 170 |
| 167 // InFlightChange: | 171 // InFlightChange: |
| 168 void SetRevertValueFrom(const InFlightChange& change) override; | 172 void SetRevertValueFrom(const InFlightChange& change) override; |
| 169 void ChangeFailed() override; | 173 void ChangeFailed() override; |
| 170 void Revert() override; | 174 void Revert() override; |
| 171 | 175 |
| 172 private: | 176 private: |
| 173 DISALLOW_COPY_AND_ASSIGN(CrashInFlightChange); | 177 DISALLOW_COPY_AND_ASSIGN(CrashInFlightChange); |
| 174 }; | 178 }; |
| 175 | 179 |
| 176 // Use this class for properties that are specific to the client, and not a | 180 // Use this class for properties that are specific to the client, and not a |
| 177 // particular window. For example, only a single window can have focus, so focus | 181 // particular window. For example, only a single window can have focus, so focus |
| 178 // is specific to the client. | 182 // is specific to the client. |
| 179 // | 183 // |
| 180 // This does not implement InFlightChange::Revert, subclasses must implement | 184 // This does not implement InFlightChange::Revert, subclasses must implement |
| 181 // that to update the WindowTreeClient. | 185 // that to update the WindowTreeClient. |
| 182 class InFlightWindowTreeClientChange : public InFlightChange, | 186 class InFlightWindowTreeClientChange : public InFlightChange, |
| 183 public WindowObserver { | 187 public WindowObserver { |
| 184 public: | 188 public: |
| 185 InFlightWindowTreeClientChange(WindowTreeClient* client, | 189 InFlightWindowTreeClientChange(WindowTreeClient* client, |
| 186 Window* revert_value, | 190 WindowMus* revert_value, |
| 187 ChangeType type); | 191 ChangeType type); |
| 188 ~InFlightWindowTreeClientChange() override; | 192 ~InFlightWindowTreeClientChange() override; |
| 189 | 193 |
| 190 // InFlightChange: | 194 // InFlightChange: |
| 191 void SetRevertValueFrom(const InFlightChange& change) override; | 195 void SetRevertValueFrom(const InFlightChange& change) override; |
| 192 | 196 |
| 193 protected: | 197 protected: |
| 194 WindowTreeClient* client() { return client_; } | 198 WindowTreeClient* client() { return client_; } |
| 195 Window* revert_window() { return revert_window_; } | 199 WindowMus* revert_window() { return revert_window_; } |
| 196 | 200 |
| 197 private: | 201 private: |
| 198 void SetRevertWindow(Window* window); | 202 void SetRevertWindow(WindowMus* window); |
| 199 | 203 |
| 200 // WindowObserver: | 204 // WindowObserver: |
| 201 void OnWindowDestroying(Window* window) override; | 205 void OnWindowDestroyed(Window* window) override; |
| 202 | 206 |
| 203 WindowTreeClient* client_; | 207 WindowTreeClient* client_; |
| 204 Window* revert_window_; | 208 WindowMus* revert_window_; |
| 205 | 209 |
| 206 DISALLOW_COPY_AND_ASSIGN(InFlightWindowTreeClientChange); | 210 DISALLOW_COPY_AND_ASSIGN(InFlightWindowTreeClientChange); |
| 207 }; | 211 }; |
| 208 | 212 |
| 209 class InFlightCaptureChange : public InFlightWindowTreeClientChange { | 213 class InFlightCaptureChange : public InFlightWindowTreeClientChange { |
| 210 public: | 214 public: |
| 211 InFlightCaptureChange(WindowTreeClient* client, Window* revert_value); | 215 InFlightCaptureChange(WindowTreeClient* client, WindowMus* revert_value); |
| 212 ~InFlightCaptureChange() override; | 216 ~InFlightCaptureChange() override; |
| 213 | 217 |
| 214 // InFlightChange: | 218 // InFlightChange: |
| 215 void Revert() override; | 219 void Revert() override; |
| 216 | 220 |
| 217 private: | 221 private: |
| 218 DISALLOW_COPY_AND_ASSIGN(InFlightCaptureChange); | 222 DISALLOW_COPY_AND_ASSIGN(InFlightCaptureChange); |
| 219 }; | 223 }; |
| 220 | 224 |
| 221 class InFlightFocusChange : public InFlightWindowTreeClientChange { | 225 class InFlightFocusChange : public InFlightWindowTreeClientChange { |
| 222 public: | 226 public: |
| 223 InFlightFocusChange(WindowTreeClient* client, Window* revert_value); | 227 InFlightFocusChange(WindowTreeClient* client, WindowMus* revert_value); |
| 224 ~InFlightFocusChange() override; | 228 ~InFlightFocusChange() override; |
| 225 | 229 |
| 226 // InFlightChange: | 230 // InFlightChange: |
| 227 void Revert() override; | 231 void Revert() override; |
| 228 | 232 |
| 229 private: | 233 private: |
| 230 DISALLOW_COPY_AND_ASSIGN(InFlightFocusChange); | 234 DISALLOW_COPY_AND_ASSIGN(InFlightFocusChange); |
| 231 }; | 235 }; |
| 232 | 236 |
| 233 class InFlightPropertyChange : public InFlightChange { | 237 class InFlightPropertyChange : public InFlightChange { |
| 234 public: | 238 public: |
| 235 InFlightPropertyChange(Window* window, | 239 InFlightPropertyChange(WindowMus* window, |
| 236 const std::string& property_name, | 240 const std::string& property_name, |
| 237 const mojo::Array<uint8_t>& revert_value); | 241 std::unique_ptr<std::vector<uint8_t>> revert_value); |
| 238 ~InFlightPropertyChange() override; | 242 ~InFlightPropertyChange() override; |
| 239 | 243 |
| 240 // InFlightChange: | 244 // InFlightChange: |
| 241 bool Matches(const InFlightChange& change) const override; | 245 bool Matches(const InFlightChange& change) const override; |
| 242 void SetRevertValueFrom(const InFlightChange& change) override; | 246 void SetRevertValueFrom(const InFlightChange& change) override; |
| 243 void Revert() override; | 247 void Revert() override; |
| 244 | 248 |
| 245 private: | 249 private: |
| 246 const std::string property_name_; | 250 const std::string property_name_; |
| 247 mojo::Array<uint8_t> revert_value_; | 251 std::unique_ptr<std::vector<uint8_t>> revert_value_; |
| 248 | 252 |
| 249 DISALLOW_COPY_AND_ASSIGN(InFlightPropertyChange); | 253 DISALLOW_COPY_AND_ASSIGN(InFlightPropertyChange); |
| 250 }; | 254 }; |
| 251 | 255 |
| 252 class InFlightPredefinedCursorChange : public InFlightChange { | 256 class InFlightPredefinedCursorChange : public InFlightChange { |
| 253 public: | 257 public: |
| 254 InFlightPredefinedCursorChange(Window* window, mojom::Cursor revert_value); | 258 InFlightPredefinedCursorChange(WindowMus* window, |
| 259 ui::mojom::Cursor revert_value); |
| 255 ~InFlightPredefinedCursorChange() override; | 260 ~InFlightPredefinedCursorChange() override; |
| 256 | 261 |
| 257 // InFlightChange: | 262 // InFlightChange: |
| 258 void SetRevertValueFrom(const InFlightChange& change) override; | 263 void SetRevertValueFrom(const InFlightChange& change) override; |
| 259 void Revert() override; | 264 void Revert() override; |
| 260 | 265 |
| 261 private: | 266 private: |
| 262 mojom::Cursor revert_cursor_; | 267 ui::mojom::Cursor revert_cursor_; |
| 263 | 268 |
| 264 DISALLOW_COPY_AND_ASSIGN(InFlightPredefinedCursorChange); | 269 DISALLOW_COPY_AND_ASSIGN(InFlightPredefinedCursorChange); |
| 265 }; | 270 }; |
| 266 | 271 |
| 267 class InFlightVisibleChange : public InFlightChange { | 272 class InFlightVisibleChange : public InFlightChange { |
| 268 public: | 273 public: |
| 269 InFlightVisibleChange(Window* window, const bool revert_value); | 274 InFlightVisibleChange(WindowMus* window, const bool revert_value); |
| 270 ~InFlightVisibleChange() override; | 275 ~InFlightVisibleChange() override; |
| 271 | 276 |
| 272 // InFlightChange: | 277 // InFlightChange: |
| 273 void SetRevertValueFrom(const InFlightChange& change) override; | 278 void SetRevertValueFrom(const InFlightChange& change) override; |
| 274 void Revert() override; | 279 void Revert() override; |
| 275 | 280 |
| 276 private: | 281 private: |
| 277 bool revert_visible_; | 282 bool revert_visible_; |
| 278 | 283 |
| 279 DISALLOW_COPY_AND_ASSIGN(InFlightVisibleChange); | 284 DISALLOW_COPY_AND_ASSIGN(InFlightVisibleChange); |
| 280 }; | 285 }; |
| 281 | 286 |
| 282 class InFlightOpacityChange : public InFlightChange { | 287 class InFlightOpacityChange : public InFlightChange { |
| 283 public: | 288 public: |
| 284 InFlightOpacityChange(Window* window, float revert_value); | 289 InFlightOpacityChange(WindowMus* window, float revert_value); |
| 285 ~InFlightOpacityChange() override; | 290 ~InFlightOpacityChange() override; |
| 286 | 291 |
| 287 // InFlightChange: | 292 // InFlightChange: |
| 288 void SetRevertValueFrom(const InFlightChange& change) override; | 293 void SetRevertValueFrom(const InFlightChange& change) override; |
| 289 void Revert() override; | 294 void Revert() override; |
| 290 | 295 |
| 291 private: | 296 private: |
| 292 float revert_opacity_; | 297 float revert_opacity_; |
| 293 | 298 |
| 294 DISALLOW_COPY_AND_ASSIGN(InFlightOpacityChange); | 299 DISALLOW_COPY_AND_ASSIGN(InFlightOpacityChange); |
| 295 }; | 300 }; |
| 296 | 301 |
| 297 class InFlightSetModalChange : public InFlightChange { | 302 class InFlightSetModalChange : public InFlightChange { |
| 298 public: | 303 public: |
| 299 explicit InFlightSetModalChange(Window* window); | 304 explicit InFlightSetModalChange(WindowMus* window); |
| 300 ~InFlightSetModalChange() override; | 305 ~InFlightSetModalChange() override; |
| 301 | 306 |
| 302 // InFlightChange: | 307 // InFlightChange: |
| 303 void SetRevertValueFrom(const InFlightChange& change) override; | 308 void SetRevertValueFrom(const InFlightChange& change) override; |
| 304 void Revert() override; | 309 void Revert() override; |
| 305 | 310 |
| 306 private: | 311 private: |
| 307 DISALLOW_COPY_AND_ASSIGN(InFlightSetModalChange); | 312 DISALLOW_COPY_AND_ASSIGN(InFlightSetModalChange); |
| 308 }; | 313 }; |
| 309 | 314 |
| 310 } // namespace ui | 315 } // namespace aura |
| 311 | 316 |
| 312 #endif // SERVICES_UI_PUBLIC_CPP_IN_FLIGHT_CHANGE_H_ | 317 #endif // UI_AURA_MUS_IN_FLIGHT_CHANGE_H_ |
| OLD | NEW |