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

Side by Side Diff: mojo/services/native_viewport/native_viewport_android.cc

Issue 63493002: Wires up MotionEvents for mojo_shell_apk on Android. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 1 month 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/services/native_viewport/native_viewport_android.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "mojo/services/native_viewport/native_viewport_android.h" 5 #include "mojo/services/native_viewport/native_viewport_android.h"
6 6
7 #include <android/native_window_jni.h> 7 #include <android/native_window_jni.h>
8 #include "mojo/services/native_viewport/android/mojo_viewport.h" 8 #include "mojo/services/native_viewport/android/mojo_viewport.h"
9 #include "mojo/shell/context.h" 9 #include "mojo/shell/context.h"
10 #include "ui/events/event.h"
11 #include "ui/gfx/point.h"
10 12
11 namespace mojo { 13 namespace mojo {
12 namespace services { 14 namespace services {
13 15
14 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate) 16 NativeViewportAndroid::NativeViewportAndroid(NativeViewportDelegate* delegate)
15 : delegate_(delegate), 17 : delegate_(delegate),
16 window_(NULL), 18 window_(NULL),
19 id_generator_(0),
17 weak_factory_(this) { 20 weak_factory_(this) {
18 } 21 }
19 22
20 NativeViewportAndroid::~NativeViewportAndroid() { 23 NativeViewportAndroid::~NativeViewportAndroid() {
21 if (window_) 24 if (window_)
22 ReleaseWindow(); 25 ReleaseWindow();
23 } 26 }
24 27
25 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) { 28 void NativeViewportAndroid::OnNativeWindowCreated(ANativeWindow* window) {
26 DCHECK(!window_); 29 DCHECK(!window_);
27 window_ = window; 30 window_ = window;
28 delegate_->OnAcceleratedWidgetAvailable(window_); 31 delegate_->OnAcceleratedWidgetAvailable(window_);
29 } 32 }
30 33
31 void NativeViewportAndroid::OnNativeWindowDestroyed() { 34 void NativeViewportAndroid::OnNativeWindowDestroyed() {
32 DCHECK(window_); 35 DCHECK(window_);
33 ReleaseWindow(); 36 ReleaseWindow();
34 } 37 }
35 38
36 void NativeViewportAndroid::OnResized(const gfx::Size& size) { 39 void NativeViewportAndroid::OnResized(const gfx::Size& size) {
37 size_ = size; 40 size_ = size;
38 delegate_->OnResized(size); 41 delegate_->OnResized(size);
39 } 42 }
40 43
44 void NativeViewportAndroid::OnTouchEvent(int pointer_id,
45 ui::EventType action,
46 float x, float y,
47 int64 time_ms) {
48 gfx::Point location(static_cast<int>(x), static_cast<int>(y));
49 ui::TouchEvent event(action, location,
50 id_generator_.GetGeneratedID(pointer_id),
51 base::TimeDelta::FromMilliseconds(time_ms));
52 // TODO(beng): handle multiple touch-points.
53 delegate_->OnEvent(&event);
54 if (action == ui::ET_TOUCH_RELEASED)
55 id_generator_.ReleaseNumber(pointer_id);
56 }
57
41 void NativeViewportAndroid::ReleaseWindow() { 58 void NativeViewportAndroid::ReleaseWindow() {
42 ANativeWindow_release(window_); 59 ANativeWindow_release(window_);
43 window_ = NULL; 60 window_ = NULL;
44 } 61 }
45 62
46 gfx::Size NativeViewportAndroid::GetSize() { 63 gfx::Size NativeViewportAndroid::GetSize() {
47 return size_; 64 return size_;
48 } 65 }
49 66
50 void NativeViewportAndroid::Close() { 67 void NativeViewportAndroid::Close() {
(...skipping 17 matching lines...) Expand all
68 context->task_runners()->java_runner()->PostTask(FROM_HERE, 85 context->task_runners()->java_runner()->PostTask(FROM_HERE,
69 base::Bind(MojoViewport::CreateForActivity, 86 base::Bind(MojoViewport::CreateForActivity,
70 context->activity(), 87 context->activity(),
71 init)); 88 init));
72 89
73 return scoped_ptr<NativeViewport>(native_viewport.Pass()); 90 return scoped_ptr<NativeViewport>(native_viewport.Pass());
74 } 91 }
75 92
76 } // namespace services 93 } // namespace services
77 } // namespace mojo 94 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/services/native_viewport/native_viewport_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698