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 MOJO_UI_BASE_VIEW_H_ |
| 6 #define MOJO_UI_BASE_VIEW_H_ |
| 7 |
| 8 #include <string> |
| 9 |
| 10 #include "mojo/public/cpp/application/application_impl.h" |
| 11 #include "mojo/public/cpp/bindings/strong_binding.h" |
| 12 #include "mojo/public/cpp/system/macros.h" |
| 13 #include "mojo/public/interfaces/application/service_provider.mojom.h" |
| 14 #include "mojo/services/gfx/composition/interfaces/scenes.mojom.h" |
| 15 #include "mojo/services/ui/views/interfaces/view_manager.mojom.h" |
| 16 #include "mojo/services/ui/views/interfaces/view_provider.mojom.h" |
| 17 #include "mojo/services/ui/views/interfaces/views.mojom.h" |
| 18 |
| 19 namespace mojo { |
| 20 namespace ui { |
| 21 |
| 22 // Abstract base implementation of the View interface for simple applications. |
| 23 // Subclasses must handle layout and provide content for the scene by |
| 24 // implementing the methods of the |View| mojom interface. |
| 25 // |
| 26 // It is not necessary to use this class to implement all Views. |
| 27 // This class is merely intended to make the simple apps easier to write. |
| 28 class BaseView : public mojo::ui::View { |
| 29 public: |
| 30 // TODO(jeffbrown): Consider switching this over to an ApplicationConnector |
| 31 // but having ApplicationImpl is handy for simple examples. |
| 32 BaseView( |
| 33 mojo::ApplicationImpl* app_impl, |
| 34 const std::string& label, |
| 35 const mojo::ui::ViewProvider::CreateViewCallback& create_view_callback); |
| 36 |
| 37 ~BaseView() override; |
| 38 |
| 39 // Gets the application implementation object provided at creation time. |
| 40 mojo::ApplicationImpl* app_impl() { return app_impl_; } |
| 41 |
| 42 // Gets the view manager. |
| 43 mojo::ui::ViewManager* view_manager() { return view_manager_.get(); } |
| 44 |
| 45 // Gets the view host for the view. |
| 46 mojo::ui::ViewHost* view_host() { return view_host_.get(); } |
| 47 |
| 48 // Gets the service provider for the view. |
| 49 mojo::ServiceProvider* view_service_provider() { |
| 50 return view_service_provider_.get(); |
| 51 } |
| 52 |
| 53 // Gets the scene for the view. |
| 54 // Returns nullptr if the |TakeScene| was called. |
| 55 mojo::gfx::composition::Scene* scene() { return scene_.get(); } |
| 56 |
| 57 // Takes the scene from the view. |
| 58 // This is useful if the scene will be rendered by a separate component. |
| 59 mojo::gfx::composition::ScenePtr TakeScene() { return scene_.Pass(); } |
| 60 |
| 61 // |View|: |
| 62 void OnChildUnavailable(uint32_t child_key, |
| 63 const OnChildUnavailableCallback& callback) override; |
| 64 |
| 65 private: |
| 66 mojo::ApplicationImpl* app_impl_; |
| 67 |
| 68 mojo::StrongBinding<mojo::ui::View> view_binding_; |
| 69 mojo::ui::ViewManagerPtr view_manager_; |
| 70 mojo::ui::ViewHostPtr view_host_; |
| 71 mojo::ServiceProviderPtr view_service_provider_; |
| 72 mojo::gfx::composition::ScenePtr scene_; |
| 73 |
| 74 MOJO_DISALLOW_COPY_AND_ASSIGN(BaseView); |
| 75 }; |
| 76 |
| 77 } // namespace ui |
| 78 } // namespace mojo |
| 79 |
| 80 #endif // MOJO_UI_BASE_VIEW_H_ |
OLD | NEW |