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

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

Issue 316713002: Wire input events through the ViewManagerClient interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: cleanup 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) {
Ben Goodger (Google) 2014/06/03 19:58:06 it might be better to add this to one of the new a
sky 2014/06/03 20:00:03 I'm going to leave it here for now. Will try and f
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 view11->SetColor(SK_ColorRED); 71 view11->SetColor(SK_ColorRED);
72
73 view11->AddObserver(this);
40 } 74 }
41 75
42 private: 76 private:
77 virtual void OnViewInputEvent(mojo::view_manager::View* view,
78 EventPtr event) OVERRIDE {
79 std::string event_name = EventNameForAction(event->action);
80 if (!event->location.is_null()) {
81 LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d",
82 event_name.c_str(),
83 event->location->x,
84 event->location->y);
85 } else {
86 LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str());
87 }
88 }
89
43 // SampleApp creates a ViewManager and a trivial node hierarchy. 90 // SampleApp creates a ViewManager and a trivial node hierarchy.
44 scoped_ptr<view_manager::ViewManager> view_manager_; 91 scoped_ptr<view_manager::ViewManager> view_manager_;
45 92
46 DISALLOW_COPY_AND_ASSIGN(SampleApp); 93 DISALLOW_COPY_AND_ASSIGN(SampleApp);
47 }; 94 };
48 95
49 } // namespace examples 96 } // namespace examples
50 97
51 // static 98 // static
52 Application* Application::Create() { 99 Application* Application::Create() {
53 return new examples::SampleApp(); 100 return new examples::SampleApp();
54 } 101 }
55 102
56 } // namespace mojo 103 } // 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