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

Unified 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, 7 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 side-by-side diff with in-line comments
Download patch
Index: mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
diff --git a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
index 0188fb299fab23a3f444407e5c0d062a7ebf71b3..a88df71731b107d6949ea01a2e7da1c50489735a 100644
--- a/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
+++ b/mojo/examples/sample_view_manager_app/sample_view_manager_app.cc
@@ -6,6 +6,7 @@
#include "base/bind.h"
#include "base/command_line.h"
#include "base/message_loop/message_loop.h"
+#include "base/strings/stringprintf.h"
#include "mojo/public/cpp/application/application.h"
#include "mojo/public/cpp/environment/environment.h"
#include "mojo/public/cpp/system/core.h"
@@ -13,7 +14,9 @@
#include "mojo/public/cpp/utility/run_loop.h"
#include "mojo/services/public/cpp/view_manager/view.h"
#include "mojo/services/public/cpp/view_manager/view_manager.h"
+#include "mojo/services/public/cpp/view_manager/view_observer.h"
#include "mojo/services/public/cpp/view_manager/view_tree_node.h"
+#include "ui/events/event_constants.h"
#include "ui/gfx/canvas.h"
#if defined(WIN32)
@@ -29,7 +32,35 @@
namespace mojo {
namespace examples {
-class SampleApp : public Application {
+namespace {
+
+std::string EventNameForAction(int32_t action) {
+ switch (action) {
+ case ui::ET_MOUSE_MOVED:
+ return "MouseMoved";
+ case ui::ET_MOUSE_PRESSED:
+ return "MousePressed";
+ case ui::ET_MOUSE_RELEASED:
+ return "MouseReleased";
+ case ui::ET_MOUSE_DRAGGED:
+ return "MouseDragged";
+ case ui::ET_KEY_PRESSED:
+ return "KeyPressed";
+ case ui::ET_KEY_RELEASED:
+ return "KeyReleased";
+ case ui::ET_TOUCH_PRESSED:
+ return "TouchPressed";
+ case ui::ET_TOUCH_RELEASED:
+ return "TouchReleased";
+ case ui::ET_TOUCH_MOVED:
+ return "TouchMoved";
+ }
+ return "Other";
+}
+
+}
sky 2014/05/28 19:32:57 nit: // namespace
+
+class SampleApp : public Application, public mojo::view_manager::ViewObserver {
public:
explicit SampleApp(MojoHandle service_provider_handle)
: Application(service_provider_handle) {
@@ -37,6 +68,7 @@ class SampleApp : public Application {
view_manager_->Init();
view_manager::ViewTreeNode* node1 =
view_manager::ViewTreeNode::Create(view_manager_.get());
+ node1->SetBounds(gfx::Rect(800, 600));
view_manager::ViewTreeNode* node11 =
view_manager::ViewTreeNode::Create(view_manager_.get());
node11->SetBounds(gfx::Rect(800, 600));
@@ -51,12 +83,27 @@ class SampleApp : public Application {
canvas.DrawColor(SK_ColorRED);
view11->SetContents(
skia::GetTopDevice(*canvas.sk_canvas())->accessBitmap(true));
+
+ view11->AddObserver(this);
}
virtual ~SampleApp() {
}
private:
+ virtual void OnViewInputEvent(mojo::view_manager::View* view,
+ const Event& event) OVERRIDE {
+ std::string event_name = EventNameForAction(event.action());
+ if (!event.location().is_null()) {
+ LOG(WARNING) << base::StringPrintf("Got %s @ %d,%d",
+ event_name.c_str(),
+ event.location().x(),
+ event.location().y());
+ } else {
+ LOG(WARNING) << base::StringPrintf("Got %s", event_name.c_str());
+ }
+ }
+
// SampleApp creates a ViewManager and a trivial node hierarchy.
scoped_ptr<view_manager::ViewManager> view_manager_;

Powered by Google App Engine
This is Rietveld 408576698