summaryrefslogtreecommitdiffstats
path: root/mojo
diff options
context:
space:
mode:
authorben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 21:03:40 +0000
committerben@chromium.org <ben@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-31 21:03:40 +0000
commitab900db95eaae7d5a3eb561c9adba605250e1778 (patch)
treee5d2cfe7ea80e5834ca29ae266e3d6af1720b80d /mojo
parent705afd661e5207754b9c8822bf19fcb40e304a1f (diff)
downloadchromium_src-ab900db95eaae7d5a3eb561c9adba605250e1778.zip
chromium_src-ab900db95eaae7d5a3eb561c9adba605250e1778.tar.gz
chromium_src-ab900db95eaae7d5a3eb561c9adba605250e1778.tar.bz2
Adds the skeleton of a NativeViewport concept.
This is a platform-specific View (output surface and event sink). We listen for events and other disposition changes and forward them to app code. In this case I just do something ad-hoc (stringify some event metadata and post to our existing sample app). Once we have bindings, we can surface a better API here. I would also like for the app to request the NativeViewportService from the Service Service, and get a separate pipe for that, rather than reusing the one that is passed through MojoMain (which I think is supposed to only be for surfacing the ServiceService). Anyway WDYT? If we agree on this I can figure out how to wrap the org.chromium.mojo_shell_apk.MojoView in a NativeViewport. BUG= R=abarth@chromium.org Review URL: https://codereview.chromium.org/51373002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@232210 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo')
-rw-r--r--mojo/examples/sample_app/sample_app.cc19
-rw-r--r--mojo/mojo.gyp28
-rw-r--r--mojo/services/DEPS4
-rw-r--r--mojo/services/native_viewport/DEPS5
-rw-r--r--mojo/services/native_viewport/native_viewport.h45
-rw-r--r--mojo/services/native_viewport/native_viewport_android.cc39
-rw-r--r--mojo/services/native_viewport/native_viewport_controller.cc51
-rw-r--r--mojo/services/native_viewport/native_viewport_controller.h43
-rw-r--r--mojo/services/native_viewport/native_viewport_stub.cc38
-rw-r--r--mojo/services/native_viewport/native_viewport_win.cc80
-rw-r--r--mojo/services/native_viewport/native_viewport_x11.cc37
-rw-r--r--mojo/shell/app_container.cc12
-rw-r--r--mojo/shell/app_container.h4
13 files changed, 391 insertions, 14 deletions
diff --git a/mojo/examples/sample_app/sample_app.cc b/mojo/examples/sample_app/sample_app.cc
index 820bdd4..f4a7299 100644
--- a/mojo/examples/sample_app/sample_app.cc
+++ b/mojo/examples/sample_app/sample_app.cc
@@ -4,8 +4,8 @@
#include <stdio.h>
-#include "base/basictypes.h"
#include "mojo/public/system/core.h"
+#include "mojo/public/system/macros.h"
#include "mojo/system/core_impl.h"
#if defined(OS_WIN)
@@ -52,18 +52,21 @@ class SampleMessageWaiter {
}
void WaitAndRead() {
- MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
- if (result < MOJO_RESULT_OK) {
- // Failure...
+ for (int i = 0; i < 100;) {
+ MojoResult result = mojo::Wait(pipe_, MOJO_WAIT_FLAG_READABLE, 100);
+ if (result < MOJO_RESULT_OK) {
+ // Failure...
+ continue;
+ }
+ ++i;
+ Read();
}
-
- Read();
}
private:
-
mojo::Handle pipe_;
- DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
+
+ MOJO_DISALLOW_COPY_AND_ASSIGN(SampleMessageWaiter);
};
extern "C" SAMPLE_APP_EXPORT MojoResult CDECL MojoMain(
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index d363175..515cfe1 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -63,7 +63,6 @@
},
{
'target_name': 'mojo_system',
- # TODO(vtl): This should probably be '<(component)'; make it work.
'type': '<(component)',
'dependencies': [
'../base/base.gyp:base',
@@ -139,6 +138,7 @@
'../net/net.gyp:net',
'../url/url.gyp:url_lib',
'mojo_system',
+ 'native_viewport',
],
'sources': [
'shell/app_container.cc',
@@ -194,7 +194,6 @@
'target_name': 'sample_app',
'type': 'shared_library',
'dependencies': [
- '../base/base.gyp:base',
'mojo_system',
],
'sources': [
@@ -246,6 +245,31 @@
'public/bindings/sample/sample_test.cc',
],
},
+ {
+ 'target_name': 'native_viewport',
+ 'type': 'static_library',
+ 'dependencies': [
+ '../base/base.gyp:base',
+ '../ui/gfx/gfx.gyp:gfx',
+ '../ui/events/events.gyp:events'
+ ],
+ 'sources': [
+ 'services/native_viewport/native_viewport.h',
+ 'services/native_viewport/native_viewport_android.cc',
+ 'services/native_viewport/native_viewport_controller.cc',
+ 'services/native_viewport/native_viewport_controller.h',
+ 'services/native_viewport/native_viewport_stub.cc',
+ 'services/native_viewport/native_viewport_win.cc',
+ 'services/native_viewport/native_viewport_x11.cc',
+ ],
+ 'conditions': [
+ ['OS=="win" or OS=="android" or OS=="linux"', {
+ 'sources!': [
+ 'services/native_viewport/native_viewport_stub.cc',
+ ],
+ }]
+ ],
+ },
],
'conditions': [
['OS=="android"', {
diff --git a/mojo/services/DEPS b/mojo/services/DEPS
new file mode 100644
index 0000000..35cd2dd
--- /dev/null
+++ b/mojo/services/DEPS
@@ -0,0 +1,4 @@
+include_rules = [
+ "-mojo",
+ "+mojo/public",
+]
diff --git a/mojo/services/native_viewport/DEPS b/mojo/services/native_viewport/DEPS
new file mode 100644
index 0000000..4de3631
--- /dev/null
+++ b/mojo/services/native_viewport/DEPS
@@ -0,0 +1,5 @@
+include_rules = [
+ "+base",
+ "+ui/events",
+ "+ui/gfx",
+]
diff --git a/mojo/services/native_viewport/native_viewport.h b/mojo/services/native_viewport/native_viewport.h
new file mode 100644
index 0000000..78ae27d
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport.h
@@ -0,0 +1,45 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_H_
+#define MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_H_
+
+#include "base/memory/scoped_ptr.h"
+
+namespace gfx {
+class Size;
+}
+
+namespace ui {
+class Event;
+}
+
+namespace mojo {
+namespace services {
+
+class NativeViewportDelegate {
+ public:
+ virtual ~NativeViewportDelegate() {}
+
+ virtual bool OnEvent(ui::Event* event) = 0;
+
+ virtual void OnResized(const gfx::Size& size) = 0;
+
+ virtual void OnDestroyed() = 0;
+};
+
+// Encapsulation of platform-specific Viewport.
+class NativeViewport {
+ public:
+ virtual ~NativeViewport() {}
+
+ virtual void Close() = 0;
+
+ static scoped_ptr<NativeViewport> Create(NativeViewportDelegate* delegate);
+};
+
+} // namespace services
+} // namespace mojo
+
+#endif // MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_H_
diff --git a/mojo/services/native_viewport/native_viewport_android.cc b/mojo/services/native_viewport/native_viewport_android.cc
new file mode 100644
index 0000000..4cf5396
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_android.cc
@@ -0,0 +1,39 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/native_viewport/native_viewport.h"
+
+namespace mojo {
+namespace services {
+
+class NativeViewportAndroid : public NativeViewport {
+ public:
+ NativeViewportAndroid(NativeViewportDelegate* delegate)
+ : delegate_(delegate) {
+ }
+ virtual ~NativeViewportAndroid() {
+ }
+
+ private:
+ // Overridden from NativeViewport:
+ virtual void Close() OVERRIDE {
+ // TODO(beng): close activity containing MojoView?
+
+ // TODO(beng): perform this in response to view destruction.
+ delegate_->OnDestroyed();
+ }
+
+ NativeViewportDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportAndroid);
+};
+
+// static
+scoped_ptr<NativeViewport> NativeViewport::Create(
+ NativeViewportDelegate* delegate) {
+ return scoped_ptr<NativeViewport>(new NativeViewportAndroid(delegate)).Pass();
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/services/native_viewport/native_viewport_controller.cc b/mojo/services/native_viewport/native_viewport_controller.cc
new file mode 100644
index 0000000..2a8f6d0
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_controller.cc
@@ -0,0 +1,51 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/native_viewport/native_viewport_controller.h"
+
+#include "base/message_loop/message_loop.h"
+#include "base/strings/stringprintf.h"
+#include "mojo/services/native_viewport/native_viewport.h"
+#include "ui/events/event.h"
+
+namespace mojo {
+namespace services {
+
+NativeViewportController::NativeViewportController(Handle pipe)
+ : pipe_(pipe) {
+ native_viewport_ = NativeViewport::Create(this);
+}
+NativeViewportController::~NativeViewportController() {
+}
+
+void NativeViewportController::Close() {
+ DCHECK(native_viewport_);
+ native_viewport_->Close();
+}
+
+bool NativeViewportController::OnEvent(ui::Event* event) {
+ ui::LocatedEvent* located = static_cast<ui::LocatedEvent*>(event);
+ SendString(base::StringPrintf("Event @ %d,%d",
+ located->location().x(),
+ located->location().y()));
+ return false;
+}
+
+void NativeViewportController::OnResized(const gfx::Size& size) {
+ SendString(base::StringPrintf("Sized to: %d x %d",
+ size.width(),
+ size.height()));
+}
+
+void NativeViewportController::OnDestroyed() {
+ base::MessageLoop::current()->Quit();
+}
+
+void NativeViewportController::SendString(const std::string& string) {
+ WriteMessage(pipe_, string.c_str(), string.size()+1, NULL, 0,
+ MOJO_WRITE_MESSAGE_FLAG_NONE);
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/services/native_viewport/native_viewport_controller.h b/mojo/services/native_viewport/native_viewport_controller.h
new file mode 100644
index 0000000..7349019
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_controller.h
@@ -0,0 +1,43 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_CONTROLLER_H_
+#define MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_CONTROLLER_H_
+
+#include <string>
+
+#include "mojo/public/system/core.h"
+#include "mojo/services/native_viewport/native_viewport.h"
+
+namespace mojo {
+namespace services {
+
+class NativeViewportController : public services::NativeViewportDelegate {
+ public:
+ // TODO(beng): Currently, pipe is just the single pipe that exists between
+ // mojo_shell and the loaded app. This should really be hidden
+ // behind the bindings layer, when that comes up.
+ explicit NativeViewportController(Handle pipe);
+ virtual ~NativeViewportController();
+
+ void Close();
+
+ private:
+ // Overridden from services::NativeViewportDelegate:
+ virtual bool OnEvent(ui::Event* event) OVERRIDE;
+ virtual void OnResized(const gfx::Size& size) OVERRIDE;
+ virtual void OnDestroyed() OVERRIDE;
+
+ void SendString(const std::string& string);
+
+ Handle pipe_;
+ scoped_ptr<NativeViewport> native_viewport_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportController);
+};
+
+} // namespace services
+} // namespace mojo
+
+#endif // MOJO_SERVICES_NATIVE_VIEWPORT_NATIVE_VIEWPORT_CONTROLLER_H_
diff --git a/mojo/services/native_viewport/native_viewport_stub.cc b/mojo/services/native_viewport/native_viewport_stub.cc
new file mode 100644
index 0000000..b4f3bd2
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_stub.cc
@@ -0,0 +1,38 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/native_viewport/native_viewport.h"
+
+// Stub to build on platforms we don't fully support yet.
+
+namespace mojo {
+namespace services {
+
+class NativeViewportStub : public NativeViewport {
+ public:
+ NativeViewportStub(NativeViewportDelegate* delegate)
+ : delegate_(delegate) {
+ }
+ virtual ~NativeViewportStub() {
+ }
+
+ private:
+ // Overridden from NativeViewport:
+ virtual void Close() OVERRIDE {
+ delegate_->OnDestroyed();
+ }
+
+ NativeViewportDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportStub);
+};
+
+// static
+scoped_ptr<NativeViewport> NativeViewport::Create(
+ NativeViewportDelegate* delegate) {
+ return scoped_ptr<NativeViewport>(new NativeViewportStub(delegate)).Pass();
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/services/native_viewport/native_viewport_win.cc b/mojo/services/native_viewport/native_viewport_win.cc
new file mode 100644
index 0000000..8951e53
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_win.cc
@@ -0,0 +1,80 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/native_viewport/native_viewport.h"
+#include "ui/events/event.h"
+#include "ui/gfx/win/window_impl.h"
+
+namespace mojo {
+namespace services {
+
+class NativeViewportWin : public gfx::WindowImpl,
+ public NativeViewport {
+ public:
+ explicit NativeViewportWin(NativeViewportDelegate* delegate)
+ : delegate_(delegate) {
+ Init(NULL, gfx::Rect(10, 10, 500, 500));
+ ShowWindow(hwnd(), SW_SHOWNORMAL);
+ SetWindowText(hwnd(), L"native_viewport::NativeViewportWin!");
+ }
+ virtual ~NativeViewportWin() {
+ if (IsWindow(hwnd()))
+ DestroyWindow(hwnd());
+ }
+
+ private:
+ // Overridden from NativeViewport:
+ virtual void Close() OVERRIDE {
+ DestroyWindow(hwnd());
+ }
+
+ BEGIN_MSG_MAP_EX(NativeViewportWin)
+ MESSAGE_RANGE_HANDLER_EX(WM_MOUSEFIRST, WM_MOUSELAST, OnMouseRange)
+
+ MSG_WM_PAINT(OnPaint)
+ MSG_WM_SIZE(OnSize)
+ MSG_WM_DESTROY(OnDestroy)
+ END_MSG_MAP()
+
+ LRESULT OnMouseRange(UINT message, WPARAM w_param, LPARAM l_param) {
+ MSG msg = { hwnd(), message, w_param, l_param, 0,
+ { GET_X_LPARAM(l_param), GET_Y_LPARAM(l_param) } };
+ ui::MouseEvent event(msg);
+ bool handled = delegate_->OnEvent(&event);
+ SetMsgHandled(handled);
+ return 0;
+ }
+ void OnPaint(HDC) {
+ RECT cr;
+ GetClientRect(hwnd(), &cr);
+
+ PAINTSTRUCT ps;
+ HDC dc = BeginPaint(hwnd(), &ps);
+ HBRUSH red_brush = CreateSolidBrush(RGB(255, 0, 0));
+ HGDIOBJ old_object = SelectObject(dc, red_brush);
+ Rectangle(dc, cr.left, cr.top, cr.right, cr.bottom);
+ SelectObject(dc, old_object);
+ DeleteObject(red_brush);
+ EndPaint(hwnd(), &ps);
+ }
+ void OnSize(UINT param, const CSize& size) {
+ delegate_->OnResized(gfx::Size(size.cx, size.cy));
+ }
+ void OnDestroy() {
+ delegate_->OnDestroyed();
+ }
+
+ NativeViewportDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportWin);
+};
+
+// static
+scoped_ptr<NativeViewport> NativeViewport::Create(
+ NativeViewportDelegate* delegate) {
+ return scoped_ptr<NativeViewport>(new NativeViewportWin(delegate)).Pass();
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/services/native_viewport/native_viewport_x11.cc b/mojo/services/native_viewport/native_viewport_x11.cc
new file mode 100644
index 0000000..8ffa51b
--- /dev/null
+++ b/mojo/services/native_viewport/native_viewport_x11.cc
@@ -0,0 +1,37 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/services/native_viewport/native_viewport.h"
+
+namespace mojo {
+namespace services {
+
+class NativeViewportX11 : public NativeViewport {
+ public:
+ NativeViewportX11(NativeViewportDelegate* delegate)
+ : delegate_(delegate) {
+ }
+ virtual ~NativeViewportX11() {
+ }
+
+ private:
+ // Overridden from NativeViewport:
+ virtual void Close() OVERRIDE {
+ // TODO(beng): perform this in response to XWindow destruction.
+ delegate_->OnDestroyed();
+ }
+
+ NativeViewportDelegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(NativeViewportX11);
+};
+
+// static
+scoped_ptr<NativeViewport> NativeViewport::Create(
+ NativeViewportDelegate* delegate) {
+ return scoped_ptr<NativeViewport>(new NativeViewportX11(delegate)).Pass();
+}
+
+} // namespace services
+} // namespace mojo
diff --git a/mojo/shell/app_container.cc b/mojo/shell/app_container.cc
index 0227e78..a0bfe03 100644
--- a/mojo/shell/app_container.cc
+++ b/mojo/shell/app_container.cc
@@ -12,6 +12,7 @@
#include "base/thread_task_runner_handle.h"
#include "base/threading/thread.h"
#include "mojo/public/system/core.h"
+#include "mojo/services/native_viewport/native_viewport_controller.h"
#include "mojo/shell/context.h"
typedef MojoResult (*MojoMainFunction)(mojo::Handle pipe);
@@ -89,15 +90,18 @@ void AppContainer::DidCompleteLoad(const GURL& app_url,
if (result < MOJO_RESULT_OK) {
// Failure..
}
+
+ // TODO(beng): This should be created on demand by the NativeViewportService
+ // when it is retrieved by the app.
+ native_viewport_controller_.reset(
+ new services::NativeViewportController(shell_handle_));
}
void AppContainer::AppCompleted() {
+ native_viewport_controller_->Close();
+
thread_.reset();
Close(shell_handle_);
-
- // Probably want to do something more sophisticated here, like notify someone
- // else to do this.
- base::MessageLoop::current()->Quit();
}
} // namespace shell
diff --git a/mojo/shell/app_container.h b/mojo/shell/app_container.h
index a2691e81..ae6e277 100644
--- a/mojo/shell/app_container.h
+++ b/mojo/shell/app_container.h
@@ -17,6 +17,9 @@ class Thread;
}
namespace mojo {
+namespace services {
+class NativeViewportController;
+}
namespace shell {
class Context;
@@ -39,6 +42,7 @@ class AppContainer : public Loader::Delegate {
Context* context_;
scoped_ptr<Loader::Job> request_;
scoped_ptr<base::Thread> thread_;
+ scoped_ptr<services::NativeViewportController> native_viewport_controller_;
// Following members are valid only on app thread.
Handle shell_handle_;