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

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

Issue 315223004: Moves view_manager files to view_manager directory (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rm sample_view_manager.app again 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.gyp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "base/at_exit.h"
6 #include "base/bind.h"
7 #include "base/strings/stringprintf.h"
8 #include "mojo/public/cpp/application/application.h"
9 #include "mojo/public/cpp/environment/environment.h"
10 #include "mojo/public/cpp/system/core.h"
11 #include "mojo/public/cpp/system/macros.h"
12 #include "mojo/services/public/cpp/view_manager/view.h"
13 #include "mojo/services/public/cpp/view_manager/view_manager.h"
14 #include "mojo/services/public/cpp/view_manager/view_observer.h"
15 #include "mojo/services/public/cpp/view_manager/view_tree_node.h"
16 #include "ui/events/event_constants.h"
17 #include "ui/gfx/canvas.h"
18
19 namespace mojo {
20 namespace examples {
21
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 {
51 public:
52 SampleApp() {}
53 virtual ~SampleApp() {}
54
55 virtual void Initialize() MOJO_OVERRIDE {
56 view_manager_.reset(new view_manager::ViewManager(service_provider()));
57 view_manager_->Init();
58 view_manager::ViewTreeNode* node1 =
59 view_manager::ViewTreeNode::Create(view_manager_.get());
60 node1->SetBounds(gfx::Rect(800, 600));
61 view_manager::ViewTreeNode* node11 =
62 view_manager::ViewTreeNode::Create(view_manager_.get());
63 node11->SetBounds(gfx::Rect(800, 600));
64
65 view_manager::View* view11 =
66 view_manager::View::Create(view_manager_.get());
67 node11->SetActiveView(view11);
68 view_manager_->roots().front()->AddChild(node1);
69 node1->AddChild(node11);
70
71 view11->SetColor(SK_ColorRED);
72
73 view11->AddObserver(this);
74 }
75
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
90 // SampleApp creates a ViewManager and a trivial node hierarchy.
91 scoped_ptr<view_manager::ViewManager> view_manager_;
92
93 DISALLOW_COPY_AND_ASSIGN(SampleApp);
94 };
95
96 } // namespace examples
97
98 // static
99 Application* Application::Create() {
100 return new examples::SampleApp();
101 }
102
103 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/examples/sample_view_manager_app/DEPS ('k') | mojo/mojo.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698