Change Shell / ShellClient to ServiceProvider
[chromium-blink-merge.git] / mojo / examples / sample_view_manager_app / sample_view_manager_app.cc
blob0188fb299fab23a3f444407e5c0d062a7ebf71b3
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.
5 #include "base/at_exit.h"
6 #include "base/bind.h"
7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h"
9 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/public/cpp/environment/environment.h"
11 #include "mojo/public/cpp/system/core.h"
12 #include "mojo/public/cpp/system/macros.h"
13 #include "mojo/public/cpp/utility/run_loop.h"
14 #include "mojo/services/public/cpp/view_manager/view.h"
15 #include "mojo/services/public/cpp/view_manager/view_manager.h"
16 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
17 #include "ui/gfx/canvas.h"
19 #if defined(WIN32)
20 #if !defined(CDECL)
21 #define CDECL __cdecl
22 #endif
23 #define SAMPLE_APP_EXPORT __declspec(dllexport)
24 #else
25 #define CDECL
26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
27 #endif
29 namespace mojo {
30 namespace examples {
32 class SampleApp : public Application {
33 public:
34 explicit SampleApp(MojoHandle service_provider_handle)
35 : Application(service_provider_handle) {
36 view_manager_.reset(new view_manager::ViewManager(service_provider()));
37 view_manager_->Init();
38 view_manager::ViewTreeNode* node1 =
39 view_manager::ViewTreeNode::Create(view_manager_.get());
40 view_manager::ViewTreeNode* node11 =
41 view_manager::ViewTreeNode::Create(view_manager_.get());
42 node11->SetBounds(gfx::Rect(800, 600));
44 view_manager::View* view11 =
45 view_manager::View::Create(view_manager_.get());
46 node11->SetActiveView(view11);
47 view_manager_->tree()->AddChild(node1);
48 node1->AddChild(node11);
50 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
51 canvas.DrawColor(SK_ColorRED);
52 view11->SetContents(
53 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
56 virtual ~SampleApp() {
59 private:
60 // SampleApp creates a ViewManager and a trivial node hierarchy.
61 scoped_ptr<view_manager::ViewManager> view_manager_;
63 DISALLOW_COPY_AND_ASSIGN(SampleApp);
66 } // namespace examples
67 } // namespace mojo
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
70 MojoHandle service_provider_handle) {
71 base::MessageLoop loop;
73 mojo::examples::SampleApp app(service_provider_handle);
74 loop.Run();
75 return MOJO_RESULT_OK;