OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef EXAMPLES_UI_TILE_TILE_VIEW_H_ | 5 #ifndef EXAMPLES_UI_TILE_TILE_VIEW_H_ |
6 #define EXAMPLES_UI_TILE_TILE_VIEW_H_ | 6 #define EXAMPLES_UI_TILE_TILE_VIEW_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
11 #include "base/bind.h" | 11 #include "mojo/ui/base_view.h" |
12 #include "base/memory/weak_ptr.h" | |
13 #include "mojo/public/cpp/application/application_impl.h" | |
14 #include "mojo/public/cpp/bindings/strong_binding.h" | |
15 #include "mojo/public/cpp/environment/environment.h" | |
16 #include "mojo/public/cpp/system/core.h" | |
17 #include "mojo/public/cpp/system/macros.h" | |
18 #include "mojo/services/geometry/interfaces/geometry.mojom.h" | |
19 #include "mojo/services/surfaces/interfaces/surfaces.mojom.h" | |
20 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" | |
21 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" | |
22 #include "mojo/services/ui/views/interfaces/views.mojom.h" | |
23 | 12 |
24 namespace examples { | 13 namespace examples { |
25 | 14 |
26 class TileView : public mojo::ui::View { | 15 class TileView : public mojo::ui::BaseView { |
27 public: | 16 public: |
28 TileView(mojo::ApplicationImpl* app_impl_, | 17 TileView(mojo::ApplicationImpl* app_impl_, |
29 const std::vector<std::string>& view_urls, | 18 const std::vector<std::string>& view_urls, |
30 const mojo::ui::ViewProvider::CreateViewCallback& callback); | 19 const mojo::ui::ViewProvider::CreateViewCallback& callback); |
31 | 20 |
32 ~TileView() override; | 21 ~TileView() override; |
33 | 22 |
34 private: | 23 private: |
35 struct ViewData { | 24 struct ViewData { |
36 explicit ViewData(const std::string& url); | 25 explicit ViewData(const std::string& url, uint32_t key); |
37 ~ViewData(); | 26 ~ViewData(); |
38 | 27 |
39 const std::string url; | 28 const std::string url; |
| 29 const uint32_t key; |
40 | 30 |
41 bool layout_pending; | 31 bool layout_pending; |
42 mojo::ui::ViewLayoutParamsPtr layout_params; | 32 mojo::ui::ViewLayoutParamsPtr layout_params; |
43 mojo::ui::ViewLayoutInfoPtr layout_info; | 33 mojo::ui::ViewLayoutInfoPtr layout_info; |
44 mojo::Rect layout_bounds; | 34 mojo::Rect layout_bounds; |
45 }; | 35 }; |
46 | 36 |
47 // |View|: | 37 // |BaseView|: |
48 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, | 38 void OnLayout(mojo::ui::ViewLayoutParamsPtr layout_params, |
49 mojo::Array<uint32_t> children_needing_layout, | 39 mojo::Array<uint32_t> children_needing_layout, |
50 const OnLayoutCallback& callback) override; | 40 const OnLayoutCallback& callback) override; |
51 void OnChildUnavailable(uint32_t child_key, | 41 void OnChildUnavailable(uint32_t child_key, |
52 const OnChildUnavailableCallback& callback) override; | 42 const OnChildUnavailableCallback& callback) override; |
53 | 43 |
54 void OnSurfaceIdNamespaceAvailable(uint32_t id_namespace); | 44 void ConnectViews(); |
55 | |
56 void InitView(); | |
57 void OnChildConnectionError(uint32_t child_key, const std::string& url); | 45 void OnChildConnectionError(uint32_t child_key, const std::string& url); |
58 void OnChildCreated(uint32_t child_key, | 46 void OnChildCreated(uint32_t child_key, |
59 const std::string& url, | 47 const std::string& url, |
60 mojo::ui::ViewProviderPtr provider, | 48 mojo::ui::ViewProviderPtr provider, |
61 mojo::ui::ViewTokenPtr token); | 49 mojo::ui::ViewTokenPtr token); |
62 void OnChildLayoutFinished(uint32_t child_key, | 50 void OnChildLayoutFinished(uint32_t child_key, |
63 mojo::ui::ViewLayoutInfoPtr child_layout_info); | 51 mojo::ui::ViewLayoutInfoPtr child_layout_info); |
64 void FinishLayout(); | 52 void FinishLayout(); |
65 | 53 |
66 void OnFrameSubmitted(); | 54 void OnFrameSubmitted(); |
67 | 55 |
68 mojo::ApplicationImpl* app_impl_; | |
69 std::vector<std::string> view_urls_; | 56 std::vector<std::string> view_urls_; |
70 mojo::ui::ViewProvider::CreateViewCallback callback_; | |
71 mojo::StrongBinding<mojo::ui::View> binding_; | |
72 | |
73 mojo::SurfacePtr surfaces_; | |
74 mojo::SurfaceIdPtr surface_id_; | |
75 uint32_t surface_id_namespace_; | |
76 | |
77 mojo::ui::ViewManagerPtr view_manager_; | |
78 mojo::ui::ViewHostPtr view_host_; | |
79 | |
80 std::map<uint32_t, std::unique_ptr<ViewData>> views_; | 57 std::map<uint32_t, std::unique_ptr<ViewData>> views_; |
81 | 58 |
82 mojo::Size size_; | 59 mojo::Size size_; |
83 OnLayoutCallback pending_layout_callback_; | 60 OnLayoutCallback pending_layout_callback_; |
84 uint32_t pending_child_layout_count_; | 61 uint32_t pending_child_layout_count_ = 0u; |
85 bool frame_pending_; | |
86 | |
87 base::WeakPtrFactory<TileView> weak_ptr_factory_; | |
88 | 62 |
89 DISALLOW_COPY_AND_ASSIGN(TileView); | 63 DISALLOW_COPY_AND_ASSIGN(TileView); |
90 }; | 64 }; |
91 | 65 |
92 } // namespace examples | 66 } // namespace examples |
93 | 67 |
94 #endif // EXAMPLES_UI_TILE_TILE_VIEW_H_ | 68 #endif // EXAMPLES_UI_TILE_TILE_VIEW_H_ |
OLD | NEW |