Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(678)

Unified Diff: services/ui/view_manager/view_layout_request.cc

Issue 1415493003: mozart: Initial commit of the view manager. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: services/ui/view_manager/view_layout_request.cc
diff --git a/services/ui/view_manager/view_layout_request.cc b/services/ui/view_manager/view_layout_request.cc
new file mode 100644
index 0000000000000000000000000000000000000000..db62e6128468c0d1d329a89559836592e8c00ace
--- /dev/null
+++ b/services/ui/view_manager/view_layout_request.cc
@@ -0,0 +1,60 @@
+// 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.
+
+#include "base/logging.h"
+#include "services/ui/view_manager/view_layout_request.h"
+
+namespace view_manager {
+
+void RunViewLayoutCallback(mojo::ui::ViewLayoutInfo* info,
+ bool provide_size,
+ const ViewLayoutCallback& callback) {
+ if (info) {
+ mojo::ui::ViewLayoutInfoPtr filtered_info = info->Clone();
+ if (!provide_size)
+ filtered_info->size.reset();
+ callback.Run(filtered_info.Pass());
+ } else {
+ callback.Run(nullptr);
+ }
+}
+
+ViewLayoutRequest::ViewLayoutRequest(
+ mojo::ui::ViewLayoutParamsPtr layout_params)
+ : issued(false),
+ layout_params_(layout_params.Pass()),
+ was_dispatched_(false) {}
+
+ViewLayoutRequest::~ViewLayoutRequest() {
+ if (!was_dispatched_)
+ DispatchLayoutInfo(nullptr);
+}
+
+void ViewLayoutRequest::AddCallback(bool provide_size,
+ const ViewLayoutCallback& callback) {
+ DCHECK(!was_dispatched_);
+ clients_.emplace_back(
+ std::unique_ptr<Client>(new Client(provide_size, callback)));
+}
+
+void ViewLayoutRequest::DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info) {
+ DCHECK(!was_dispatched_);
+ was_dispatched_ = true;
+ for (auto it = clients_.begin(); it != clients_.end(); ++it) {
+ (*it)->DispatchLayoutInfo(info);
+ }
+}
+
+ViewLayoutRequest::Client::Client(bool provide_size,
+ const ViewLayoutCallback& callback)
+ : provide_size_(provide_size), callback_(callback) {}
+
+ViewLayoutRequest::Client::~Client() {}
+
+void ViewLayoutRequest::Client::DispatchLayoutInfo(
+ mojo::ui::ViewLayoutInfo* info) {
+ RunViewLayoutCallback(info, provide_size_, callback_);
+}
+
+} // namespace view_manager

Powered by Google App Engine
This is Rietveld 408576698