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

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

Issue 1397563003: Remove wm_flow, browser, nesting_app examples (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 unified diff | Download patch
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 "examples/bitmap_uploader/bitmap_uploader.h"
10 #include "examples/window_manager/window_manager.mojom.h"
11 #include "mojo/application/application_runner_chromium.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/view_manager/cpp/view.h"
18 #include "mojo/services/view_manager/cpp/view_manager.h"
19 #include "mojo/services/view_manager/cpp/view_manager_client_factory.h"
20 #include "mojo/services/view_manager/cpp/view_manager_delegate.h"
21 #include "mojo/services/view_manager/cpp/view_observer.h"
22 #include "third_party/skia/include/core/SkColor.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 ~NestingApp() override {}
43
44 private:
45 // Overridden from ApplicationDelegate:
46 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 bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
54 connection->ConnectToService(&window_manager_);
55 connection->AddService(view_manager_client_factory_.get());
56 return true;
57 }
58
59 // Overridden from ViewManagerDelegate:
60 void OnEmbed(View* root,
61 InterfaceRequest<ServiceProvider> services,
62 ServiceProviderPtr exposed_services) override {
63 root->AddObserver(this);
64 bitmap_uploader_.reset(new BitmapUploader(root));
65 bitmap_uploader_->Init(shell_);
66 bitmap_uploader_->SetColor(SK_ColorCYAN);
67
68 nested_ = root->view_manager()->CreateView();
69 root->AddChild(nested_);
70 Rect rect;
71 rect.x = rect.y = 20;
72 rect.width = rect.height = 50;
73 nested_->SetBounds(rect);
74 nested_->SetVisible(true);
75 nested_->Embed(kEmbeddedAppURL);
76 }
77 void OnViewManagerDisconnected(ViewManager* view_manager) override {
78 base::MessageLoop::current()->Quit();
79 }
80
81 // Overridden from ViewObserver:
82 void OnViewDestroyed(View* view) override {
83 // TODO(beng): reap views & child Views.
84 nested_ = NULL;
85 }
86 void OnViewInputEvent(View* view, const EventPtr& event) override {
87 if (event->action == EventType::POINTER_UP)
88 window_manager_->CloseWindow(view->id());
89 }
90
91 scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
92
93 View* nested_;
94 Shell* shell_;
95 ::examples::IWindowManagerPtr window_manager_;
96 scoped_ptr<BitmapUploader> bitmap_uploader_;
97
98 DISALLOW_COPY_AND_ASSIGN(NestingApp);
99 };
100
101 } // namespace examples
102 } // namespace mojo
103
104 MojoResult MojoMain(MojoHandle application_request) {
105 mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp);
106 return runner.Run(application_request);
107 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698