| 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 typedef base::Callback<void(mojo::ui::ViewLayoutInfoPtr)> ViewLayoutCallback; |
| 18 |
| 19 void RunViewLayoutCallback(mojo::ui::ViewLayoutInfo* info, |
| 20 bool provide_size, |
| 21 const ViewLayoutCallback& callback); |
| 22 |
| 23 // Describes a pending layout request for a view. |
| 24 class ViewLayoutRequest { |
| 25 public: |
| 26 ViewLayoutRequest(mojo::ui::ViewLayoutParamsPtr layout_params); |
| 27 |
| 28 // Dispatches null layout info automatically if DispatchLayoutInfo was not |
| 29 // called. |
| 30 ~ViewLayoutRequest(); |
| 31 |
| 32 // Gets the layout parameters for this request. |
| 33 // Does not confer ownership. |
| 34 mojo::ui::ViewLayoutParams* layout_params() { return layout_params_.get(); } |
| 35 |
| 36 // Gets the layout parameters for this request and takes ownership. |
| 37 mojo::ui::ViewLayoutParamsPtr TakeLayoutParams() { |
| 38 return layout_params_.Pass(); |
| 39 } |
| 40 |
| 41 // Adds a callback to this layout request and specifies the information |
| 42 // to include. Must be called before dispatching. |
| 43 void AddCallback(bool provide_size, const ViewLayoutCallback& callback); |
| 44 |
| 45 // Returns true if the request has callbacks. |
| 46 bool has_callbacks() { return !clients_.empty(); } |
| 47 |
| 48 // Sends the layout information to each client. |
| 49 // Must be invoked exactly once before destroying the request to prevent |
| 50 // dangling callbacks. |
| 51 void DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info); |
| 52 |
| 53 // True if the request has been issued to the view. |
| 54 // False if it is still pending in the queue. |
| 55 bool issued; |
| 56 |
| 57 private: |
| 58 class Client { |
| 59 public: |
| 60 Client(bool provide_size, const ViewLayoutCallback& callback); |
| 61 ~Client(); |
| 62 |
| 63 void DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info); |
| 64 |
| 65 private: |
| 66 bool provide_size_; |
| 67 ViewLayoutCallback callback_; |
| 68 |
| 69 DISALLOW_COPY_AND_ASSIGN(Client); |
| 70 }; |
| 71 |
| 72 mojo::ui::ViewLayoutParamsPtr layout_params_; |
| 73 std::vector<std::unique_ptr<Client>> clients_; |
| 74 bool was_dispatched_; |
| 75 |
| 76 DISALLOW_COPY_AND_ASSIGN(ViewLayoutRequest); |
| 77 }; |
| 78 |
| 79 } // namespace view_manager |
| 80 |
| 81 #endif // SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_ |
| OLD | NEW |