| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #ifndef SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_ |
| 6 #define SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_ |
| 7 |
| 8 #include <memory> |
| 9 #include <vector> |
| 10 |
| 11 #include "base/callback.h" |
| 12 #include "base/macros.h" |
| 13 #include "mojo/services/ui/views/interfaces/layouts.mojom.h" |
| 14 |
| 15 namespace view_manager { |
| 16 |
| 17 using ViewLayoutCallback = base::Callback<void(mojo::ui::ViewLayoutInfoPtr)>; |
| 18 |
| 19 // Describes a pending layout request for a view. |
| 20 class ViewLayoutRequest { |
| 21 public: |
| 22 explicit ViewLayoutRequest(mojo::ui::ViewLayoutParamsPtr layout_params); |
| 23 |
| 24 // Dispatches null layout info automatically if DispatchLayoutInfo was not |
| 25 // called. |
| 26 ~ViewLayoutRequest(); |
| 27 |
| 28 // Gets the layout parameters for this request. |
| 29 // Does not confer ownership. |
| 30 mojo::ui::ViewLayoutParams* layout_params() { return layout_params_.get(); } |
| 31 |
| 32 // Gets the layout parameters for this request and takes ownership. |
| 33 mojo::ui::ViewLayoutParamsPtr TakeLayoutParams() { |
| 34 return layout_params_.Pass(); |
| 35 } |
| 36 |
| 37 // Adds a callback to this layout request. |
| 38 // Must be called before dispatching. |
| 39 void AddCallback(const ViewLayoutCallback& callback); |
| 40 |
| 41 // Returns true if the request has callbacks. |
| 42 bool has_callbacks() { return !callbacks_.empty(); } |
| 43 |
| 44 // Sends the layout information to each client. |
| 45 // Must be invoked exactly once before destroying the request to prevent |
| 46 // dangling callbacks. |
| 47 void DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info); |
| 48 |
| 49 // True if the request has been issued to the view. |
| 50 // False if it is still pending in the queue. |
| 51 bool issued() const { return issued_; } |
| 52 void set_issued(bool value) { issued_ = value; } |
| 53 |
| 54 private: |
| 55 mojo::ui::ViewLayoutParamsPtr layout_params_; |
| 56 std::vector<ViewLayoutCallback> callbacks_; |
| 57 bool was_dispatched_; |
| 58 bool issued_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(ViewLayoutRequest); |
| 61 }; |
| 62 |
| 63 } // namespace view_manager |
| 64 |
| 65 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_ |
| OLD | NEW |