| Index: services/ui/view_manager/view_layout_request.h
|
| diff --git a/services/ui/view_manager/view_layout_request.h b/services/ui/view_manager/view_layout_request.h
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..9a4a139e6ed5934346e1828444b1d94719df4468
|
| --- /dev/null
|
| +++ b/services/ui/view_manager/view_layout_request.h
|
| @@ -0,0 +1,81 @@
|
| +// Copyright 2015 The Chromium Authors. All rights reserved.
|
| +// Use of this source code is governed by a BSD-style license that can be
|
| +// found in the LICENSE file.
|
| +
|
| +#ifndef SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_
|
| +#define SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_
|
| +
|
| +#include <memory>
|
| +#include <vector>
|
| +
|
| +#include "base/callback.h"
|
| +#include "base/macros.h"
|
| +#include "mojo/services/ui/views/interfaces/layouts.mojom.h"
|
| +
|
| +namespace view_manager {
|
| +
|
| +typedef base::Callback<void(mojo::ui::ViewLayoutInfoPtr)> ViewLayoutCallback;
|
| +
|
| +void RunViewLayoutCallback(mojo::ui::ViewLayoutInfo* info,
|
| + bool provide_size,
|
| + const ViewLayoutCallback& callback);
|
| +
|
| +// Describes a pending layout request for a view.
|
| +class ViewLayoutRequest {
|
| + public:
|
| + ViewLayoutRequest(mojo::ui::ViewLayoutParamsPtr layout_params);
|
| +
|
| + // Dispatches null layout info automatically if DispatchLayoutInfo was not
|
| + // called.
|
| + ~ViewLayoutRequest();
|
| +
|
| + // Gets the layout parameters for this request.
|
| + // Does not confer ownership.
|
| + mojo::ui::ViewLayoutParams* layout_params() { return layout_params_.get(); }
|
| +
|
| + // Gets the layout parameters for this request and takes ownership.
|
| + mojo::ui::ViewLayoutParamsPtr TakeLayoutParams() {
|
| + return layout_params_.Pass();
|
| + }
|
| +
|
| + // Adds a callback to this layout request and specifies the information
|
| + // to include. Must be called before dispatching.
|
| + void AddCallback(bool provide_size, const ViewLayoutCallback& callback);
|
| +
|
| + // Returns true if the request has callbacks.
|
| + bool has_callbacks() { return !clients_.empty(); }
|
| +
|
| + // Sends the layout information to each client.
|
| + // Must be invoked exactly once before destroying the request to prevent
|
| + // dangling callbacks.
|
| + void DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info);
|
| +
|
| + // True if the request has been issued to the view.
|
| + // False if it is still pending in the queue.
|
| + bool issued;
|
| +
|
| + private:
|
| + class Client {
|
| + public:
|
| + Client(bool provide_size, const ViewLayoutCallback& callback);
|
| + ~Client();
|
| +
|
| + void DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info);
|
| +
|
| + private:
|
| + bool provide_size_;
|
| + ViewLayoutCallback callback_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(Client);
|
| + };
|
| +
|
| + mojo::ui::ViewLayoutParamsPtr layout_params_;
|
| + std::vector<std::unique_ptr<Client>> clients_;
|
| + bool was_dispatched_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(ViewLayoutRequest);
|
| +};
|
| +
|
| +} // namespace view_manager
|
| +
|
| +#endif // SERVICES_UI_VIEW_MANAGER_VIEW_LAYOUT_REQUEST_H_
|
|
|