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

Side by Side Diff: mojo/examples/nesting_app/nesting_app.cc

Issue 684543003: Move //mojo/examples to //examples (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: Created 6 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « mojo/examples/nesting_app/DEPS ('k') | mojo/examples/png_viewer/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2014 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/bind.h"
6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h"
9 #include "mojo/application/application_runner_chromium.h"
10 #include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
11 #include "mojo/examples/window_manager/window_manager.mojom.h"
12 #include "mojo/public/c/system/main.h"
13 #include "mojo/public/cpp/application/application_connection.h"
14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/application/interface_factory_impl.h"
17 #include "mojo/services/public/cpp/view_manager/view.h"
18 #include "mojo/services/public/cpp/view_manager/view_manager.h"
19 #include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
20 #include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
21 #include "mojo/services/public/cpp/view_manager/view_observer.h"
22 #include "ui/events/event_constants.h"
23 #include "url/gurl.h"
24
25 namespace mojo {
26 namespace examples {
27
28 namespace {
29 const char kEmbeddedAppURL[] = "mojo:embedded_app";
30 }
31
32 class NestingApp;
33
34 // An app that embeds another app.
35 // TODO(davemoore): Is this the right name?
36 class NestingApp
37 : public ApplicationDelegate,
38 public ViewManagerDelegate,
39 public ViewObserver {
40 public:
41 NestingApp() : nested_(nullptr), shell_(nullptr) {}
42 virtual ~NestingApp() {}
43
44 private:
45 // Overridden from ApplicationDelegate:
46 virtual void Initialize(ApplicationImpl* app) override {
47 shell_ = app->shell();
48 view_manager_client_factory_.reset(
49 new ViewManagerClientFactory(app->shell(), this));
50 }
51
52 // Overridden from ApplicationImpl:
53 virtual bool ConfigureIncomingConnection(
54 ApplicationConnection* connection) override {
55 connection->ConnectToService(&window_manager_);
56 connection->AddService(view_manager_client_factory_.get());
57 return true;
58 }
59
60 // Overridden from ViewManagerDelegate:
61 virtual void OnEmbed(ViewManager* view_manager,
62 View* root,
63 ServiceProviderImpl* exported_services,
64 scoped_ptr<ServiceProvider> imported_services) override {
65 root->AddObserver(this);
66 bitmap_uploader_.reset(new BitmapUploader(root));
67 bitmap_uploader_->Init(shell_);
68 bitmap_uploader_->SetColor(SK_ColorCYAN);
69
70 nested_ = View::Create(view_manager);
71 root->AddChild(nested_);
72 Rect rect;
73 rect.x = rect.y = 20;
74 rect.width = rect.height = 50;
75 nested_->SetBounds(rect);
76 nested_->Embed(kEmbeddedAppURL);
77 }
78 virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
79 base::MessageLoop::current()->Quit();
80 }
81
82 // Overridden from ViewObserver:
83 virtual void OnViewDestroyed(View* view) override {
84 // TODO(beng): reap views & child Views.
85 nested_ = NULL;
86 }
87 virtual void OnViewInputEvent(View* view, const EventPtr& event) override {
88 if (event->action == EVENT_TYPE_MOUSE_RELEASED)
89 window_manager_->CloseWindow(view->id());
90 }
91
92 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
93
94 View* nested_;
95 Shell* shell_;
96 IWindowManagerPtr window_manager_;
97 scoped_ptr<BitmapUploader> bitmap_uploader_;
98
99 DISALLOW_COPY_AND_ASSIGN(NestingApp);
100 };
101
102 } // namespace examples
103 } // namespace mojo
104
105 MojoResult MojoMain(MojoHandle shell_handle) {
106 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp);
107 return runner.Run(shell_handle);
108 }
OLDNEW
« no previous file with comments | « mojo/examples/nesting_app/DEPS ('k') | mojo/examples/png_viewer/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698