| 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 #include "base/logging.h" |
| 6 #include "services/ui/view_manager/view_layout_request.h" |
| 7 |
| 8 namespace view_manager { |
| 9 |
| 10 void RunViewLayoutCallback(mojo::ui::ViewLayoutInfo* info, |
| 11 bool provide_size, |
| 12 const ViewLayoutCallback& callback) { |
| 13 if (info) { |
| 14 mojo::ui::ViewLayoutInfoPtr filtered_info = info->Clone(); |
| 15 if (!provide_size) |
| 16 filtered_info->size.reset(); |
| 17 callback.Run(filtered_info.Pass()); |
| 18 } else { |
| 19 callback.Run(nullptr); |
| 20 } |
| 21 } |
| 22 |
| 23 ViewLayoutRequest::ViewLayoutRequest( |
| 24 mojo::ui::ViewLayoutParamsPtr layout_params) |
| 25 : issued(false), |
| 26 layout_params_(layout_params.Pass()), |
| 27 was_dispatched_(false) {} |
| 28 |
| 29 ViewLayoutRequest::~ViewLayoutRequest() { |
| 30 if (!was_dispatched_) |
| 31 DispatchLayoutInfo(nullptr); |
| 32 } |
| 33 |
| 34 void ViewLayoutRequest::AddCallback(bool provide_size, |
| 35 const ViewLayoutCallback& callback) { |
| 36 DCHECK(!was_dispatched_); |
| 37 clients_.emplace_back( |
| 38 std::unique_ptr<Client>(new Client(provide_size, callback))); |
| 39 } |
| 40 |
| 41 void ViewLayoutRequest::DispatchLayoutInfo(mojo::ui::ViewLayoutInfo* info) { |
| 42 DCHECK(!was_dispatched_); |
| 43 was_dispatched_ = true; |
| 44 for (auto it = clients_.begin(); it != clients_.end(); ++it) { |
| 45 (*it)->DispatchLayoutInfo(info); |
| 46 } |
| 47 } |
| 48 |
| 49 ViewLayoutRequest::Client::Client(bool provide_size, |
| 50 const ViewLayoutCallback& callback) |
| 51 : provide_size_(provide_size), callback_(callback) {} |
| 52 |
| 53 ViewLayoutRequest::Client::~Client() {} |
| 54 |
| 55 void ViewLayoutRequest::Client::DispatchLayoutInfo( |
| 56 mojo::ui::ViewLayoutInfo* info) { |
| 57 RunViewLayoutCallback(info, provide_size_, callback_); |
| 58 } |
| 59 |
| 60 } // namespace view_manager |
| OLD | NEW |