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

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
« no previous file with comments | « mojo/examples/sample_view_manager_app/DEPS ('k') | mojo/mojo_services.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/strings/stringprintf.h"
7 #include "mojo/public/cpp/application/application.h" 8 #include "mojo/public/cpp/application/application.h"
8 #include "mojo/public/cpp/environment/environment.h" 9 #include "mojo/public/cpp/environment/environment.h"
9 #include "mojo/public/cpp/system/core.h" 10 #include "mojo/public/cpp/system/core.h"
10 #include "mojo/public/cpp/system/macros.h" 11 #include "mojo/public/cpp/system/macros.h"
11 #include "mojo/services/public/cpp/view_manager/view.h" 12 #include "mojo/services/public/cpp/view_manager/view.h"
12 #include "mojo/services/public/cpp/view_manager/view_manager.h" 13 #include "mojo/services/public/cpp/view_manager/view_manager.h"
14 #include "mojo/services/public/cpp/view_manager/view_observer.h"
13 #include "mojo/services/public/cpp/view_manager/view_tree_node.h" 15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
16 #include "ui/events/event_constants.h"
14 #include "ui/gfx/canvas.h" 17 #include "ui/gfx/canvas.h"
15 18
16 namespace mojo { 19 namespace mojo {
17 namespace examples { 20 namespace examples {
18 21
19 class SampleApp : public Application { 22 namespace {
23
24 std::string EventNameForAction(int32_t action) {
25 switch (action) {
26 case ui::ET_MOUSE_MOVED:
27 return "MouseMoved";
28 case ui::ET_MOUSE_PRESSED:
29 return "MousePressed";
30 case ui::ET_MOUSE_RELEASED:
31 return "MouseReleased";
32 case ui::ET_MOUSE_DRAGGED:
33 return "MouseDragged";
34 case ui::ET_KEY_PRESSED:
35 return "KeyPressed";
36 case ui::ET_KEY_RELEASED:
37 return "KeyReleased";
38 case ui::ET_TOUCH_PRESSED:
39 return "TouchPressed";
40 case ui::ET_TOUCH_RELEASED:
41 return "TouchReleased";
42 case ui::ET_TOUCH_MOVED:
43 return "TouchMoved";
44 }
45 return "Other";
46 }
47
48 } // namespace
49
50 class SampleApp : public Application, public mojo::view_manager::ViewObserver {
20 public: 51 public:
21 SampleApp() {} 52 SampleApp() {}
22 virtual ~SampleApp() {} 53 virtual ~SampleApp() {}
23 54
24 virtual void Initialize() MOJO_OVERRIDE { 55 virtual void Initialize() MOJO_OVERRIDE {
25 view_manager_.reset(new view_manager::ViewManager(service_provider())); 56 view_manager_.reset(new view_manager::ViewManager(service_provider()));
26 view_manager_->Init(); 57 view_manager_->Init();
27 view_manager::ViewTreeNode* node1 = 58 view_manager::ViewTreeNode* node1 =
28 view_manager::ViewTreeNode::Create(view_manager_.get()); 59 view_manager::ViewTreeNode::Create(view_manager_.get());
60 node1->SetBounds(gfx::Rect(800, 600));
29 view_manager::ViewTreeNode* node11 = 61 view_manager::ViewTreeNode* node11 =
30 view_manager::ViewTreeNode::Create(view_manager_.get()); 62 view_manager::ViewTreeNode::Create(view_manager_.get());
31 node11->SetBounds(gfx::Rect(800, 600)); 63 node11->SetBounds(gfx::Rect(800, 600));
32 64
33 view_manager::View* view11 = 65 view_manager::View* view11 =
34 view_manager::View::Create(view_manager_.get()); 66 view_manager::View::Create(view_manager_.get());
35 node11->SetActiveView(view11); 67 node11->SetActiveView(view11);
36 view_manager_->tree()->AddChild(node1); 68 view_manager_->tree()->AddChild(node1);
37 node1->AddChild(node11); 69 node1->AddChild(node11);
38 70
39 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true); 71 gfx::Canvas canvas(gfx::Size(800, 600), 1.0f, true);
40 canvas.DrawColor(SK_ColorRED); 72 canvas.DrawColor(SK_ColorRED);
41 view11->SetContents( 73 view11->SetContents(
42 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true)); 74 skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
75
76 view11->AddObserver(this);
43 } 77 }
44 78
45 private: 79 private:
80 virtual void OnViewInputEvent(mojo::view_manager::View* view,
81 EventPtr event) OVERRIDE {
82 std::string event_name = EventNameForAction(event->action);
83 if (!event->location.is_null()) {
84 LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d",
85 event_name.c_str(),
86 event->location->x,
87 event->location->y);
88 } else {
89 LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str());
90 }
91 }
92
46 // SampleApp creates a ViewManager and a trivial node hierarchy. 93 // SampleApp creates a ViewManager and a trivial node hierarchy.
47 scoped_ptr<view_manager::ViewManager> view_manager_; 94 scoped_ptr<view_manager::ViewManager> view_manager_;
48 95
49 DISALLOW_COPY_AND_ASSIGN(SampleApp); 96 DISALLOW_COPY_AND_ASSIGN(SampleApp);
50 }; 97 };
51 98
52 } // namespace examples 99 } // namespace examples
53 100
54 // static 101 // static
55 Application* Application::Create() { 102 Application* Application::Create() {
56 return new examples::SampleApp(); 103 return new examples::SampleApp();
57 } 104 }
58 105
59 } // namespace mojo 106 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/sample_view_manager_app/DEPS ('k') | mojo/mojo_services.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698