OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 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 | 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 #include "base/at_exit.h" | 5 #include "base/at_exit.h" |
6 #include "base/bind.h" | 6 #include "base/bind.h" |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "mojo/public/cpp/environment/environment.h" | 9 #include "mojo/public/cpp/environment/environment.h" |
10 #include "mojo/public/cpp/shell/application.h" | 10 #include "mojo/public/cpp/shell/application.h" |
11 #include "mojo/public/cpp/system/core.h" | 11 #include "mojo/public/cpp/system/core.h" |
12 #include "mojo/public/cpp/system/macros.h" | 12 #include "mojo/public/cpp/system/macros.h" |
13 #include "mojo/public/cpp/utility/run_loop.h" | 13 #include "mojo/public/cpp/utility/run_loop.h" |
| 14 #include "mojo/services/public/cpp/view_manager/view.h" |
14 #include "mojo/services/public/cpp/view_manager/view_manager.h" | 15 #include "mojo/services/public/cpp/view_manager/view_manager.h" |
15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" | 16 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" |
| 17 #include "ui/gfx/canvas.h" |
16 | 18 |
17 #if defined(WIN32) | 19 #if defined(WIN32) |
18 #if !defined(CDECL) | 20 #if !defined(CDECL) |
19 #define CDECL __cdecl | 21 #define CDECL __cdecl |
20 #endif | 22 #endif |
21 #define SAMPLE_APP_EXPORT __declspec(dllexport) | 23 #define SAMPLE_APP_EXPORT __declspec(dllexport) |
22 #else | 24 #else |
23 #define CDECL | 25 #define CDECL |
24 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) | 26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) |
25 #endif | 27 #endif |
26 | 28 |
27 namespace mojo { | 29 namespace mojo { |
28 namespace examples { | 30 namespace examples { |
29 | 31 |
30 class SampleApp : public Application { | 32 class SampleApp : public Application { |
31 public: | 33 public: |
32 explicit SampleApp(MojoHandle shell_handle) | 34 explicit SampleApp(MojoHandle shell_handle) |
33 : Application(shell_handle) { | 35 : Application(shell_handle) { |
34 view_manager_.reset(new view_manager::ViewManager(shell())); | 36 view_manager_.reset(new view_manager::ViewManager(shell())); |
35 view_manager_->Init(); | 37 view_manager_->Init(); |
36 view_manager::ViewTreeNode* node1 = | 38 view_manager::ViewTreeNode* node1 = |
37 view_manager::ViewTreeNode::Create(view_manager_.get()); | 39 view_manager::ViewTreeNode::Create(view_manager_.get()); |
38 view_manager::ViewTreeNode* node11 = | 40 view_manager::ViewTreeNode* node11 = |
39 view_manager::ViewTreeNode::Create(view_manager_.get()); | 41 view_manager::ViewTreeNode::Create(view_manager_.get()); |
| 42 node11->SetBounds(gfx::Rect(800, 600)); |
| 43 |
| 44 view_manager::View* view11 = |
| 45 view_manager::View::Create(view_manager_.get()); |
| 46 node11->SetActiveView(view11); |
| 47 view_manager_->tree()->AddChild(node1); |
40 node1->AddChild(node11); | 48 node1->AddChild(node11); |
| 49 |
| 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)); |
41 } | 54 } |
42 | 55 |
43 virtual ~SampleApp() { | 56 virtual ~SampleApp() { |
44 } | 57 } |
45 | 58 |
46 private: | 59 private: |
47 // SampleApp creates a ViewManager and a trivial node hierarchy. | 60 // SampleApp creates a ViewManager and a trivial node hierarchy. |
48 scoped_ptr<view_manager::ViewManager> view_manager_; | 61 scoped_ptr<view_manager::ViewManager> view_manager_; |
49 | 62 |
50 DISALLOW_COPY_AND_ASSIGN(SampleApp); | 63 DISALLOW_COPY_AND_ASSIGN(SampleApp); |
51 }; | 64 }; |
52 | 65 |
53 } // namespace examples | 66 } // namespace examples |
54 } // namespace mojo | 67 } // namespace mojo |
55 | 68 |
56 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( | 69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( |
57 MojoHandle shell_handle) { | 70 MojoHandle shell_handle) { |
58 base::MessageLoop loop; | 71 base::MessageLoop loop; |
59 | 72 |
60 mojo::examples::SampleApp app(shell_handle); | 73 mojo::examples::SampleApp app(shell_handle); |
61 loop.Run(); | 74 loop.Run(); |
62 return MOJO_RESULT_OK; | 75 return MOJO_RESULT_OK; |
63 } | 76 } |
OLD | NEW |