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

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

Issue 300863003: Wire input events through the ViewManagerClient interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 6 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 | Annotate | Revision Log
OLDNEW
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 "base/strings/stringprintf.h"
9 #include "mojo/public/cpp/application/application.h" 10 #include "mojo/public/cpp/application/application.h"
10 #include "mojo/public/cpp/environment/environment.h" 11 #include "mojo/public/cpp/environment/environment.h"
11 #include "mojo/public/cpp/system/core.h" 12 #include "mojo/public/cpp/system/core.h"
12 #include "mojo/public/cpp/system/macros.h" 13 #include "mojo/public/cpp/system/macros.h"
13 #include "mojo/public/cpp/utility/run_loop.h" 14 #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.h"
15 #include "mojo/services/public/cpp/view_manager/view_manager.h" 16 #include "mojo/services/public/cpp/view_manager/view_manager.h"
17 #include "mojo/services/public/cpp/view_manager/view_observer.h"
16 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" 18 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
19 #include "ui/events/event_constants.h"
17 #include "ui/gfx/canvas.h" 20 #include "ui/gfx/canvas.h"
18 21
19 #if defined(WIN32) 22 #if defined(WIN32)
20 #if !defined(CDECL) 23 #if !defined(CDECL)
21 #define CDECL __cdecl 24 #define CDECL __cdecl
22 #endif 25 #endif
23 #define SAMPLE_APP_EXPORT __declspec(dllexport) 26 #define SAMPLE_APP_EXPORT __declspec(dllexport)
24 #else 27 #else
25 #define CDECL 28 #define CDECL
26 #define SAMPLE_APP_EXPORT __attribute__((visibility("default"))) 29 #define SAMPLE_APP_EXPORT __attribute__((visibility("default")))
27 #endif 30 #endif
28 31
29 namespace mojo { 32 namespace mojo {
30 namespace examples { 33 namespace examples {
31 34
32 class SampleApp : public Application { 35 namespace {
36
37 std::string EventNameForAction(int32_t action) {
38 switch (action) {
39 case ui::ET_MOUSE_MOVED:
40 return "MouseMoved";
41 case ui::ET_MOUSE_PRESSED:
42 return "MousePressed";
43 case ui::ET_MOUSE_RELEASED:
44 return "MouseReleased";
45 case ui::ET_MOUSE_DRAGGED:
46 return "MouseDragged";
47 case ui::ET_KEY_PRESSED:
48 return "KeyPressed";
49 case ui::ET_KEY_RELEASED:
50 return "KeyReleased";
51 case ui::ET_TOUCH_PRESSED:
52 return "TouchPressed";
53 case ui::ET_TOUCH_RELEASED:
54 return "TouchReleased";
55 case ui::ET_TOUCH_MOVED:
56 return "TouchMoved";
57 }
58 return "Other";
59 }
60
61 }
sky 2014/05/28 19:32:57 nit: // namespace
62
63 class SampleApp : public Application, public mojo::view_manager::ViewObserver {
33 public: 64 public:
34 explicit SampleApp(MojoHandle service_provider_handle) 65 explicit SampleApp(MojoHandle service_provider_handle)
35 : Application(service_provider_handle) { 66 : Application(service_provider_handle) {
36 view_manager_.reset(new view_manager::ViewManager(service_provider())); 67 view_manager_.reset(new view_manager::ViewManager(service_provider()));
37 view_manager_->Init(); 68 view_manager_->Init();
38 view_manager::ViewTreeNode* node1 = 69 view_manager::ViewTreeNode* node1 =
39 view_manager::ViewTreeNode::Create(view_manager_.get()); 70 view_manager::ViewTreeNode::Create(view_manager_.get());
71 node1->SetBounds(gfx::Rect(800, 600));
40 view_manager::ViewTreeNode* node11 = 72 view_manager::ViewTreeNode* node11 =
41 view_manager::ViewTreeNode::Create(view_manager_.get()); 73 view_manager::ViewTreeNode::Create(view_manager_.get());
42 node11->SetBounds(gfx::Rect(800, 600)); 74 node11->SetBounds(gfx::Rect(800, 600));
43 75
44 view_manager::View* view11 = 76 view_manager::View* view11 =
45 view_manager::View::Create(view_manager_.get()); 77 view_manager::View::Create(view_manager_.get());
46 node11->SetActiveView(view11); 78 node11->SetActiveView(view11);
47 view_manager_->tree()->AddChild(node1); 79 view_manager_->tree()->AddChild(node1);
48 node1->AddChild(node11); 80 node1->AddChild(node11);
49 81
50 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); 82 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
51 canvas.DrawColor(SK_ColorRED); 83 canvas.DrawColor(SK_ColorRED);
52 view11->SetContents( 84 view11->SetContents(
53 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true)); 85 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
86
87 view11->AddObserver(this);
54 } 88 }
55 89
56 virtual ~SampleApp() { 90 virtual ~SampleApp() {
57 } 91 }
58 92
59 private: 93 private:
94 virtual void OnViewInputEvent(mojo::view_manager::View* view,
95 const Event& event) OVERRIDE {
96 std::string event_name = EventNameForAction(event.action());
97 if (!event.location().is_null()) {
98 LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d",
99 event_name.c_str(),
100 event.location().x(),
101 event.location().y());
102 } else {
103 LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str());
104 }
105 }
106
60 // SampleApp creates a ViewManager and a trivial node hierarchy. 107 // SampleApp creates a ViewManager and a trivial node hierarchy.
61 scoped_ptr<view_manager::ViewManager> view_manager_; 108 scoped_ptr<view_manager::ViewManager> view_manager_;
62 109
63 DISALLOW_COPY_AND_ASSIGN(SampleApp); 110 DISALLOW_COPY_AND_ASSIGN(SampleApp);
64 }; 111 };
65 112
66 } // namespace examples 113 } // namespace examples
67 } // namespace mojo 114 } // namespace mojo
68 115
69 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain( 116 extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
70 MojoHandle service_provider_handle) { 117 MojoHandle service_provider_handle) {
71 base::MessageLoop loop; 118 base::MessageLoop loop;
72 119
73 mojo::examples::SampleApp app(service_provider_handle); 120 mojo::examples::SampleApp app(service_provider_handle);
74 loop.Run(); 121 loop.Run();
75 return MOJO_RESULT_OK; 122 return MOJO_RESULT_OK;
76 } 123 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698