summaryrefslogtreecommitdiffstats
path: root/mojo/examples/window_manager
diff options
context:
space:
mode:
authoraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 03:43:42 +0000
committeraa@chromium.org <aa@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-12 03:43:42 +0000
commit98fd5b2b2bd0a4db0e0372c014d5e50c17e8409a (patch)
tree33b8dc0437d21ecb93b0c2a9fca1736eac3b57a4 /mojo/examples/window_manager
parentaee791a678ad3a51715b2c450216b083e3f93384 (diff)
downloadchromium_src-98fd5b2b2bd0a4db0e0372c014d5e50c17e8409a.zip
chromium_src-98fd5b2b2bd0a4db0e0372c014d5e50c17e8409a.tar.gz
chromium_src-98fd5b2b2bd0a4db0e0372c014d5e50c17e8409a.tar.bz2
Introduce very beginning of navigation.
Add an interface to allow embedders to navigate embedded views. This only supports local/pushState-style navigation right now. BUG= R=darin@chromium.org, davemoore@chromium.org, sky@chromium.org Review URL: https://codereview.chromium.org/327523004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@276521 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'mojo/examples/window_manager')
-rw-r--r--mojo/examples/window_manager/window_manager.cc40
1 files changed, 36 insertions, 4 deletions
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
index d998f0c..e9a561e 100644
--- a/mojo/examples/window_manager/window_manager.cc
+++ b/mojo/examples/window_manager/window_manager.cc
@@ -4,8 +4,10 @@
#include "base/basictypes.h"
#include "base/bind.h"
+#include "base/strings/stringprintf.h"
#include "mojo/examples/window_manager/window_manager.mojom.h"
#include "mojo/public/cpp/application/application.h"
+#include "mojo/services/navigation/navigation.mojom.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_manager_delegate.h"
@@ -30,6 +32,19 @@ namespace examples {
class WindowManager;
+namespace {
+
+const SkColor kColors[] = { SK_ColorYELLOW,
+ SK_ColorRED,
+ SK_ColorGREEN,
+ SK_ColorMAGENTA };
+
+const char kEmbeddedAppURL[] = "mojo:mojo_embedded_app";
+const char kNestingAppURL[] = "mojo:mojo_nesting_app";
+const char kMojoBrowserURL[] = "mojo:mojo_browser";
+
+} // namespace
+
class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
public:
explicit WindowManagerConnection(WindowManager* window_manager)
@@ -69,11 +84,11 @@ class WindowManager : public Application,
virtual void OnViewInputEvent(View* view, const EventPtr& event) OVERRIDE {
if (event->action == ui::ET_MOUSE_RELEASED) {
if (event->flags & ui::EF_LEFT_MOUSE_BUTTON)
- CreateWindow("mojo:mojo_embedded_app");
+ CreateWindow(kEmbeddedAppURL);
else if (event->flags & ui::EF_RIGHT_MOUSE_BUTTON)
- CreateWindow("mojo:mojo_nesting_app");
+ CreateWindow(kNestingAppURL);
else if (event->flags & ui::EF_MIDDLE_MOUSE_BUTTON)
- CreateWindow("mojo:mojo_browser");
+ CreateWindow(kMojoBrowserURL);
}
}
@@ -94,7 +109,7 @@ class WindowManager : public Application,
view->AddObserver(this);
}
- void CreateWindow(const String& url) {
+ void CreateWindow(const std::string& url) {
ViewTreeNode* node = view_manager_->GetNodeById(parent_node_id_);
gfx::Rect bounds(50, 50, 200, 200);
@@ -108,6 +123,23 @@ class WindowManager : public Application,
node->AddChild(embedded);
embedded->SetBounds(bounds);
embedded->Embed(url);
+
+ // TODO(aa): Is there a way to ask for an interface and test whether it
+ // succeeded? That would be nicer than hard-coding the URLs that are known
+ // to support navigation.
+ if (url == kEmbeddedAppURL || url == kNestingAppURL) {
+ // TODO(aa): This means that there can only ever be one instance of every
+ // app, which seems wrong. Instead, perhaps embedder should get back a
+ // service provider that allows it to talk to embeddee.
+ navigation::NavigatorPtr navigator;
+ ConnectTo(url, &navigator);
+ navigation::NavigationDetailsPtr details(
+ navigation::NavigationDetails::New());
+ size_t index = node->children().size() - 1;
+ details->url = base::StringPrintf(
+ "%s/%x", kEmbeddedAppURL, kColors[index % arraysize(kColors)]);
+ navigator->Navigate(embedded->id(), details.Pass());
+ }
}
ViewManager* view_manager_;