summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjamesr <jamesr@chromium.org>2014-10-22 22:09:24 -0700
committerCommit bot <commit-bot@chromium.org>2014-10-23 05:09:41 +0000
commitee47d094a085d2d4611da46bd12d592c63c7d712 (patch)
tree5dc31f17cb26edb8d296ee2b251199b4b8db33df
parent13b1371303258fe761e907d5874cdfdf8e3ed082 (diff)
downloadchromium_src-ee47d094a085d2d4611da46bd12d592c63c7d712.zip
chromium_src-ee47d094a085d2d4611da46bd12d592c63c7d712.tar.gz
chromium_src-ee47d094a085d2d4611da46bd12d592c63c7d712.tar.bz2
Remove mojo/services{view,window}_manager
These are being developed in the the mojo repo. R=sky@chromium.org Review URL: https://codereview.chromium.org/659113003 Cr-Commit-Position: refs/heads/master@{#300841}
-rw-r--r--mojo/BUILD.gn2
-rw-r--r--mojo/examples/BUILD.gn5
-rw-r--r--mojo/examples/browser/BUILD.gn42
-rw-r--r--mojo/examples/browser/DEPS11
-rw-r--r--mojo/examples/browser/browser.cc274
-rw-r--r--mojo/examples/embedded_app/BUILD.gn28
-rw-r--r--mojo/examples/embedded_app/DEPS3
-rw-r--r--mojo/examples/embedded_app/embedded_app.cc122
-rw-r--r--mojo/examples/nesting_app/BUILD.gn27
-rw-r--r--mojo/examples/nesting_app/DEPS3
-rw-r--r--mojo/examples/nesting_app/nesting_app.cc105
-rw-r--r--mojo/examples/window_manager/BUILD.gn56
-rw-r--r--mojo/examples/window_manager/DEPS7
-rw-r--r--mojo/examples/window_manager/debug_panel.cc138
-rw-r--r--mojo/examples/window_manager/debug_panel.h76
-rw-r--r--mojo/examples/window_manager/window_manager.cc603
-rw-r--r--mojo/examples/window_manager/window_manager.mojom22
-rw-r--r--mojo/examples/wm_flow/BUILD.gn111
-rw-r--r--mojo/examples/wm_flow/app/DEPS0
-rw-r--r--mojo/examples/wm_flow/app/app.cc154
-rw-r--r--mojo/examples/wm_flow/app/embedder.mojom11
-rw-r--r--mojo/examples/wm_flow/embedded/embedded.cc98
-rw-r--r--mojo/examples/wm_flow/embedded/embeddee.mojom11
-rw-r--r--mojo/examples/wm_flow/init/init.cc40
-rw-r--r--mojo/examples/wm_flow/wm/DEPS7
-rw-r--r--mojo/examples/wm_flow/wm/frame_controller.cc157
-rw-r--r--mojo/examples/wm_flow/wm/frame_controller.h68
-rw-r--r--mojo/examples/wm_flow/wm/wm.cc208
-rw-r--r--mojo/mojo.gyp8
-rw-r--r--mojo/mojo_services.gypi190
-rw-r--r--mojo/services/BUILD.gn10
-rw-r--r--mojo/services/view_manager/BUILD.gn102
-rw-r--r--mojo/services/view_manager/DEPS26
-rw-r--r--mojo/services/view_manager/access_policy.h53
-rw-r--r--mojo/services/view_manager/access_policy_delegate.h39
-rw-r--r--mojo/services/view_manager/connection_manager.cc301
-rw-r--r--mojo/services/view_manager/connection_manager.h211
-rw-r--r--mojo/services/view_manager/default_access_policy.cc106
-rw-r--r--mojo/services/view_manager/default_access_policy.h59
-rw-r--r--mojo/services/view_manager/display_manager.cc171
-rw-r--r--mojo/services/view_manager/display_manager.h87
-rw-r--r--mojo/services/view_manager/ids.h63
-rw-r--r--mojo/services/view_manager/main.cc47
-rw-r--r--mojo/services/view_manager/server_view.cc144
-rw-r--r--mojo/services/view_manager/server_view.h91
-rw-r--r--mojo/services/view_manager/server_view_delegate.h52
-rw-r--r--mojo/services/view_manager/test_change_tracker.cc244
-rw-r--r--mojo/services/view_manager/test_change_tracker.h133
-rw-r--r--mojo/services/view_manager/view_manager_export.h31
-rw-r--r--mojo/services/view_manager/view_manager_init_service_context.cc78
-rw-r--r--mojo/services/view_manager/view_manager_init_service_context.h64
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.cc34
-rw-r--r--mojo/services/view_manager/view_manager_init_service_impl.h57
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.cc541
-rw-r--r--mojo/services/view_manager/view_manager_service_impl.h235
-rw-r--r--mojo/services/view_manager/view_manager_unittest.cc1481
-rw-r--r--mojo/services/view_manager/window_manager_access_policy.cc92
-rw-r--r--mojo/services/view_manager/window_manager_access_policy.h53
-rw-r--r--mojo/services/view_manager/window_manager_client_impl.cc41
-rw-r--r--mojo/services/view_manager/window_manager_client_impl.h54
-rw-r--r--mojo/services/window_manager/BUILD.gn83
-rw-r--r--mojo/services/window_manager/DEPS14
-rw-r--r--mojo/services/window_manager/main.cc73
-rw-r--r--mojo/services/window_manager/window_manager_api_unittest.cc276
-rw-r--r--mojo/services/window_manager/window_manager_app.cc344
-rw-r--r--mojo/services/window_manager/window_manager_app.h175
-rw-r--r--mojo/services/window_manager/window_manager_delegate.h25
-rw-r--r--mojo/services/window_manager/window_manager_service2_impl.cc80
-rw-r--r--mojo/services/window_manager/window_manager_service2_impl.h41
-rw-r--r--mojo/services/window_manager/window_manager_service_impl.cc37
-rw-r--r--mojo/services/window_manager/window_manager_service_impl.h36
-rw-r--r--mojo/services/window_manager/window_manager_unittests.cc43
-rw-r--r--mojo/shell/view_manager_loader.cc56
-rw-r--r--mojo/shell/view_manager_loader.h57
74 files changed, 2 insertions, 8625 deletions
diff --git a/mojo/BUILD.gn b/mojo/BUILD.gn
index 02f8157..1f36443 100644
--- a/mojo/BUILD.gn
+++ b/mojo/BUILD.gn
@@ -51,8 +51,6 @@ group("tests") {
if (use_aura) {
deps += [
"//mojo/services/public/cpp/view_manager/tests:mojo_view_manager_lib_unittests",
- "//mojo/services/view_manager:mojo_view_manager_unittests",
- "//mojo/services/window_manager:mojo_core_window_manager_unittests",
]
}
}
diff --git a/mojo/examples/BUILD.gn b/mojo/examples/BUILD.gn
index bdd09f7..4d0623e 100644
--- a/mojo/examples/BUILD.gn
+++ b/mojo/examples/BUILD.gn
@@ -22,14 +22,9 @@ group("examples") {
if (use_aura) {
deps += [
"//mojo/examples/aura_demo:mojo_aura_demo",
- "//mojo/examples/browser",
"//mojo/examples/demo_launcher",
- "//mojo/examples/embedded_app",
"//mojo/examples/media_viewer",
- "//mojo/examples/nesting_app",
"//mojo/examples/keyboard",
- "//mojo/examples/window_manager",
- "//mojo/examples/wm_flow",
]
}
}
diff --git a/mojo/examples/browser/BUILD.gn b/mojo/examples/browser/BUILD.gn
deleted file mode 100644
index d28a971..0000000
--- a/mojo/examples/browser/BUILD.gn
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-
-assert(use_aura)
-
-shared_library("browser") {
- output_name = "mojo_browser"
-
- sources = [
- "browser.cc",
- ]
-
- deps = [
- "//base",
- "//cc",
- "//mojo/application",
- "//mojo/aura",
- "//mojo/common",
- "//mojo/converters/geometry",
- "//mojo/converters/input_events",
- "//mojo/examples/window_manager:bindings",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/geometry",
- "//mojo/services/public/interfaces/input_events",
- "//mojo/services/public/interfaces/navigation",
- "//mojo/services/public/interfaces/view_manager",
- "//mojo/views:views",
- "//third_party/icu",
- "//ui/aura",
- "//ui/base",
- "//ui/compositor",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//ui/resources",
- "//ui/views",
- "//url",
- ]
-}
diff --git a/mojo/examples/browser/DEPS b/mojo/examples/browser/DEPS
deleted file mode 100644
index 02dd6ea..0000000
--- a/mojo/examples/browser/DEPS
+++ /dev/null
@@ -1,11 +0,0 @@
-include_rules = [
- "+cc",
- "-cc/blink",
- "+skia/ext",
- "+ui/aura",
- "+ui/base/hit_test.h",
- "+ui/compositor",
- "+ui/events",
- "+ui/gfx",
- "+ui/views",
-]
diff --git a/mojo/examples/browser/browser.cc b/mojo/examples/browser/browser.cc
deleted file mode 100644
index e5f724e..0000000
--- a/mojo/examples/browser/browser.cc
+++ /dev/null
@@ -1,274 +0,0 @@
-// Copyright 2014 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 "base/macros.h"
-#include "base/strings/string_util.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/connect.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
-#include "mojo/views/native_widget_view_manager.h"
-#include "mojo/views/views_init.h"
-#include "ui/aura/client/focus_client.h"
-#include "ui/aura/window.h"
-#include "ui/events/event.h"
-#include "ui/views/background.h"
-#include "ui/views/controls/textfield/textfield.h"
-#include "ui/views/controls/textfield/textfield_controller.h"
-#include "ui/views/focus/focus_manager.h"
-#include "ui/views/layout/layout_manager.h"
-#include "ui/views/widget/widget.h"
-#include "ui/views/widget/widget_delegate.h"
-#include "ui/views/widget/widget_observer.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace examples {
-
-class BrowserLayoutManager : public views::LayoutManager {
- public:
- BrowserLayoutManager() {}
- virtual ~BrowserLayoutManager() {}
-
- private:
- // Overridden from views::LayoutManager:
- virtual void Layout(views::View* host) override {
- // Browser view has one child, a text input field.
- DCHECK_EQ(1, host->child_count());
- views::View* text_field = host->child_at(0);
- gfx::Size ps = text_field->GetPreferredSize();
- text_field->SetBoundsRect(gfx::Rect(host->width(), ps.height()));
- }
- virtual gfx::Size GetPreferredSize(const views::View* host) const override {
- return gfx::Size();
- }
-
- DISALLOW_COPY_AND_ASSIGN(BrowserLayoutManager);
-};
-
-// KeyboardManager handles notifying the windowmanager when views are focused.
-// To use create one and KeyboardManager will take care of all other details.
-//
-// TODO(sky): it would be nice if this were put in NativeWidgetViewManager, but
-// that requires NativeWidgetViewManager to take an IWindowManager. That may be
-// desirable anyway...
-class KeyboardManager
- : public views::FocusChangeListener,
- public ui::EventHandler,
- public views::WidgetObserver {
- public:
- KeyboardManager(views::Widget* widget,
- IWindowManager* window_manager,
- View* view)
- : widget_(widget),
- window_manager_(window_manager),
- view_(view),
- last_view_id_(0),
- focused_view_(NULL) {
- widget_->GetFocusManager()->AddFocusChangeListener(this);
- widget_->AddObserver(this);
- widget_->GetNativeView()->AddPostTargetHandler(this);
- }
-
- private:
- virtual ~KeyboardManager() {
- widget_->GetFocusManager()->RemoveFocusChangeListener(this);
- widget_->GetNativeView()->RemovePostTargetHandler(this);
- widget_->RemoveObserver(this);
-
- HideKeyboard();
- }
-
- void ShowKeyboard(views::View* view) {
- if (focused_view_ == view)
- return;
-
- const gfx::Rect bounds_in_widget =
- view->ConvertRectToWidget(gfx::Rect(view->bounds().size()));
- last_view_id_ = view_->id();
- window_manager_->ShowKeyboard(last_view_id_,
- Rect::From(bounds_in_widget));
- // TODO(sky): listen for view to be removed.
- focused_view_ = view;
- }
-
- void HideKeyboard() {
- if (!focused_view_)
- return;
-
- window_manager_->HideKeyboard(last_view_id_);
- last_view_id_ = 0;
- focused_view_ = NULL;
- }
-
- // views::FocusChangeListener:
- virtual void OnWillChangeFocus(views::View* focused_before,
- views::View* focused_now) override {
- }
- virtual void OnDidChangeFocus(views::View* focused_before,
- views::View* focused_now) override {
- if (focused_view_ && focused_now != focused_view_)
- HideKeyboard();
- }
-
- // ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* event) override {
- views::View* focused_now = widget_->GetFocusManager()->GetFocusedView();
- if (focused_now &&
- focused_now->GetClassName() == views::Textfield::kViewClassName &&
- (event->flags() & ui::EF_FROM_TOUCH) != 0) {
- ShowKeyboard(focused_now);
- }
- }
-
- // views::WidgetObserver:
- virtual void OnWidgetDestroying(views::Widget* widget) override {
- delete this;
- }
-
- views::Widget* widget_;
- IWindowManager* window_manager_;
- View* view_;
- Id last_view_id_;
- views::View* focused_view_;
-
- DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
-};
-
-// This is the basics of creating a views widget with a textfield.
-// TODO: cleanup!
-class Browser : public ApplicationDelegate,
- public ViewManagerDelegate,
- public views::TextfieldController,
- public ViewObserver {
- public:
- Browser()
- : shell_(nullptr), view_manager_(NULL), root_(NULL), widget_(NULL) {}
-
- virtual ~Browser() {
- if (root_)
- root_->RemoveObserver(this);
- }
-
- private:
- // Overridden from ApplicationDelegate:
- virtual void Initialize(ApplicationImpl* app) override {
- shell_ = app->shell();
- view_manager_client_factory_.reset(
- new ViewManagerClientFactory(shell_, this));
- views_init_.reset(new ViewsInit);
- app->ConnectToService("mojo:window_manager", &window_manager_);
- }
-
- virtual bool ConfigureIncomingConnection(
- ApplicationConnection* connection) override {
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- void CreateWidget(View* view) {
- views::Textfield* textfield = new views::Textfield;
- textfield->set_controller(this);
-
- views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView;
- widget_delegate->GetContentsView()->set_background(
- views::Background::CreateSolidBackground(SK_ColorBLUE));
- widget_delegate->GetContentsView()->AddChildView(textfield);
- widget_delegate->GetContentsView()->SetLayoutManager(
- new BrowserLayoutManager);
-
- widget_ = new views::Widget;
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.native_widget = new NativeWidgetViewManager(widget_, shell_, view);
- params.delegate = widget_delegate;
- params.bounds = gfx::Rect(view->bounds().width(), view->bounds().height());
- widget_->Init(params);
- // KeyboardManager handles deleting itself when the widget is destroyed.
- new KeyboardManager(widget_, window_manager_.get(), view);
- widget_->Show();
- textfield->RequestFocus();
- }
-
- // ViewManagerDelegate:
- virtual void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- // TODO: deal with OnEmbed() being invoked multiple times.
- ConnectToService(imported_services.get(), &navigator_host_);
- view_manager_ = view_manager;
- root_ = root;
- root_->AddObserver(this);
- root_->SetFocus();
- CreateWidget(root_);
- }
- virtual void OnViewManagerDisconnected(
- ViewManager* view_manager) override {
- DCHECK_EQ(view_manager_, view_manager);
- view_manager_ = NULL;
- base::MessageLoop::current()->Quit();
- }
-
- // views::TextfieldController:
- virtual bool HandleKeyEvent(views::Textfield* sender,
- const ui::KeyEvent& key_event) override {
- if (key_event.key_code() == ui::VKEY_RETURN) {
- GURL url(sender->text());
- printf("User entered this URL: %s\n", url.spec().c_str());
- URLRequestPtr request(URLRequest::New());
- request->url = String::From(url);
- navigator_host_->RequestNavigate(TARGET_NEW_NODE, request.Pass());
- }
- return false;
- }
-
- // ViewObserver:
- virtual void OnViewFocusChanged(View* gained_focus,
- View* lost_focus) override {
- aura::client::FocusClient* focus_client =
- aura::client::GetFocusClient(widget_->GetNativeView());
- if (lost_focus == root_)
- focus_client->FocusWindow(NULL);
- else if (gained_focus == root_)
- focus_client->FocusWindow(widget_->GetNativeView());
- }
- virtual void OnViewDestroyed(View* view) override {
- DCHECK_EQ(root_, view);
- view->RemoveObserver(this);
- root_ = NULL;
- }
-
- Shell* shell_;
-
- scoped_ptr<ViewsInit> views_init_;
-
- ViewManager* view_manager_;
- scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
- View* root_;
- views::Widget* widget_;
- NavigatorHostPtr navigator_host_;
- IWindowManagerPtr window_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(Browser);
-};
-
-} // namespace examples
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::examples::Browser);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/embedded_app/BUILD.gn b/mojo/examples/embedded_app/BUILD.gn
deleted file mode 100644
index 12cf1b9..0000000
--- a/mojo/examples/embedded_app/BUILD.gn
+++ /dev/null
@@ -1,28 +0,0 @@
-# Copyright 2014 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.
-
-shared_library("embedded_app") {
- output_name = "mojo_embedded_app"
-
- sources = [
- "embedded_app.cc",
- ]
-
- deps = [
- "//base",
- "//mojo/application",
- "//mojo/examples/bitmap_uploader",
- "//mojo/examples/window_manager:bindings",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/cpp/bindings",
- "//mojo/public/cpp/utility",
- "//mojo/public/gles2:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/geometry",
- "//mojo/services/public/interfaces/navigation",
- "//ui/gfx/geometry",
- "//ui/gl",
- "//url",
- ]
-}
diff --git a/mojo/examples/embedded_app/DEPS b/mojo/examples/embedded_app/DEPS
deleted file mode 100644
index fe1d98e..0000000
--- a/mojo/examples/embedded_app/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+ui/events",
-]
diff --git a/mojo/examples/embedded_app/embedded_app.cc b/mojo/examples/embedded_app/embedded_app.cc
deleted file mode 100644
index 98c418e..0000000
--- a/mojo/examples/embedded_app/embedded_app.cc
+++ /dev/null
@@ -1,122 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/logging.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/string_number_conversions.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/cpp/application/interface_factory_impl.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
-#include "ui/events/event_constants.h"
-#include "url/gurl.h"
-#include "url/url_util.h"
-
-namespace mojo {
-namespace examples {
-
-const SkColor kColors[] = {SK_ColorYELLOW, SK_ColorRED, SK_ColorGREEN,
- SK_ColorMAGENTA};
-
-struct Window {
- Window(View* root,
- scoped_ptr<ServiceProvider> embedder_service_provider,
- Shell* shell)
- : root(root),
- embedder_service_provider(embedder_service_provider.Pass()),
- bitmap_uploader(root) {
- bitmap_uploader.Init(shell);
- }
-
- View* root;
- scoped_ptr<ServiceProvider> embedder_service_provider;
- BitmapUploader bitmap_uploader;
-};
-
-class EmbeddedApp
- : public ApplicationDelegate,
- public ViewManagerDelegate,
- public ViewObserver {
- public:
- EmbeddedApp() : shell_(nullptr) { url::AddStandardScheme("mojo"); }
- virtual ~EmbeddedApp() {}
-
- private:
-
- // Overridden from ApplicationDelegate:
- virtual void Initialize(ApplicationImpl* app) override {
- shell_ = app->shell();
- view_manager_client_factory_.reset(
- new ViewManagerClientFactory(app->shell(), this));
- }
-
- virtual bool ConfigureIncomingConnection(
- ApplicationConnection* connection) override {
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- // Overridden from ViewManagerDelegate:
- virtual void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- root->AddObserver(this);
- Window* window = new Window(root, imported_services.Pass(), shell_);
- windows_[root->id()] = window;
- window->bitmap_uploader.SetColor(
- kColors[next_color_++ % arraysize(kColors)]);
- }
- virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
- base::MessageLoop::current()->Quit();
- }
-
- // Overridden from ViewObserver:
- virtual void OnViewDestroyed(View* view) override {
- DCHECK(windows_.find(view->id()) != windows_.end());
- windows_.erase(view->id());
- }
- virtual void OnViewInputEvent(View* view, const EventPtr& event) override {
- if (event->action == EVENT_TYPE_MOUSE_RELEASED) {
- if (event->flags & EVENT_FLAGS_LEFT_MOUSE_BUTTON) {
- URLRequestPtr request(URLRequest::New());
- request->url = "http://www.aaronboodman.com/z_dropbox/test.html";
- NavigatorHostPtr navigator_host;
- ConnectToService(windows_[view->id()]->embedder_service_provider.get(),
- &navigator_host);
- navigator_host->RequestNavigate(TARGET_SOURCE_NODE, request.Pass());
- }
- }
- }
-
- Shell* shell_;
- scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
-
- typedef std::map<Id, Window*> WindowMap;
- WindowMap windows_;
-
- int next_color_;
-
- DISALLOW_COPY_AND_ASSIGN(EmbeddedApp);
-};
-
-} // namespace examples
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::examples::EmbeddedApp);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/nesting_app/BUILD.gn b/mojo/examples/nesting_app/BUILD.gn
deleted file mode 100644
index 0043517..0000000
--- a/mojo/examples/nesting_app/BUILD.gn
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright 2014 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.
-
-shared_library("nesting_app") {
- output_name = "mojo_nesting_app"
-
- sources = [
- "nesting_app.cc"
- ]
-
- deps = [
- "//base",
- "//mojo/application",
- "//mojo/examples/bitmap_uploader",
- "//mojo/examples/window_manager:bindings",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/cpp/bindings",
- "//mojo/public/cpp/utility",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/geometry",
- "//mojo/services/public/interfaces/navigation",
- "//ui/gfx/geometry",
- "//ui/gl",
- "//url",
- ]
-}
diff --git a/mojo/examples/nesting_app/DEPS b/mojo/examples/nesting_app/DEPS
deleted file mode 100644
index fe1d98e..0000000
--- a/mojo/examples/nesting_app/DEPS
+++ /dev/null
@@ -1,3 +0,0 @@
-include_rules = [
- "+ui/events",
-]
diff --git a/mojo/examples/nesting_app/nesting_app.cc b/mojo/examples/nesting_app/nesting_app.cc
deleted file mode 100644
index 4473d6f..0000000
--- a/mojo/examples/nesting_app/nesting_app.cc
+++ /dev/null
@@ -1,105 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/macros.h"
-#include "base/message_loop/message_loop.h"
-#include "base/strings/stringprintf.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
-#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/interface_factory_impl.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "ui/events/event_constants.h"
-#include "url/gurl.h"
-
-namespace mojo {
-namespace examples {
-
-namespace {
-const char kEmbeddedAppURL[] = "mojo:embedded_app";
-}
-
-class NestingApp;
-
-// An app that embeds another app.
-// TODO(davemoore): Is this the right name?
-class NestingApp
- : public ApplicationDelegate,
- public ViewManagerDelegate,
- public ViewObserver {
- public:
- NestingApp() : nested_(nullptr), shell_(nullptr) {}
- virtual ~NestingApp() {}
-
- private:
- // Overridden from ApplicationDelegate:
- virtual void Initialize(ApplicationImpl* app) override {
- shell_ = app->shell();
- view_manager_client_factory_.reset(
- new ViewManagerClientFactory(app->shell(), this));
- }
-
- // Overridden from ApplicationImpl:
- virtual bool ConfigureIncomingConnection(
- ApplicationConnection* connection) override {
- connection->ConnectToService(&window_manager_);
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- // Overridden from ViewManagerDelegate:
- virtual void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- root->AddObserver(this);
- bitmap_uploader_.reset(new BitmapUploader(root));
- bitmap_uploader_->Init(shell_);
- bitmap_uploader_->SetColor(SK_ColorCYAN);
-
- nested_ = View::Create(view_manager);
- root->AddChild(nested_);
- nested_->SetBounds(gfx::Rect(20, 20, 50, 50));
- nested_->Embed(kEmbeddedAppURL);
- }
- virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
- base::MessageLoop::current()->Quit();
- }
-
- // Overridden from ViewObserver:
- virtual void OnViewDestroyed(View* view) override {
- // TODO(beng): reap views & child Views.
- nested_ = NULL;
- }
- virtual void OnViewInputEvent(View* view, const EventPtr& event) override {
- if (event->action == EVENT_TYPE_MOUSE_RELEASED)
- window_manager_->CloseWindow(view->id());
- }
-
- scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
-
- View* nested_;
- Shell* shell_;
- IWindowManagerPtr window_manager_;
- scoped_ptr<BitmapUploader> bitmap_uploader_;
-
- DISALLOW_COPY_AND_ASSIGN(NestingApp);
-};
-
-} // namespace examples
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::examples::NestingApp);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/window_manager/BUILD.gn b/mojo/examples/window_manager/BUILD.gn
deleted file mode 100644
index 3f463e5..0000000
--- a/mojo/examples/window_manager/BUILD.gn
+++ /dev/null
@@ -1,56 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-import("//mojo/public/tools/bindings/mojom.gni")
-
-assert(use_aura)
-
-shared_library("window_manager") {
- output_name = "mojo_window_manager"
-
- sources = [
- "debug_panel.cc",
- "debug_panel.h",
- "window_manager.cc",
- ]
-
- deps = [
- ":bindings",
- "//base",
- "//mojo/application",
- "//mojo/aura",
- "//mojo/converters/geometry",
- "//mojo/converters/input_events",
- "//mojo/examples/keyboard:bindings",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/cpp/bindings",
- "//mojo/public/cpp/utility",
- "//mojo/public/gles2:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/geometry",
- "//mojo/services/public/interfaces/input_events",
- "//mojo/services/public/interfaces/navigation",
- "//mojo/services/window_manager:lib",
- "//mojo/views:views",
- "//ui/aura",
- "//ui/base",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//ui/gl",
- "//ui/resources",
- "//ui/views",
- "//ui/wm",
- ]
-}
-
-mojom("bindings") {
- sources = [
- "window_manager.mojom",
- ]
- deps = [
- "//mojo/services/public/interfaces/geometry",
- ]
-}
-
diff --git a/mojo/examples/window_manager/DEPS b/mojo/examples/window_manager/DEPS
deleted file mode 100644
index 372b6a8..0000000
--- a/mojo/examples/window_manager/DEPS
+++ /dev/null
@@ -1,7 +0,0 @@
-include_rules = [
- "+ui/aura",
- "+ui/events",
- "+ui/gfx",
- "+ui/views",
- "+ui/wm/core",
-]
diff --git a/mojo/examples/window_manager/debug_panel.cc b/mojo/examples/window_manager/debug_panel.cc
deleted file mode 100644
index 4a751344..0000000
--- a/mojo/examples/window_manager/debug_panel.cc
+++ /dev/null
@@ -1,138 +0,0 @@
-// Copyright 2014 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/examples/window_manager/debug_panel.h"
-
-#include "base/strings/stringprintf.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mojo/services/public/cpp/view_manager/view.h"
-#include "mojo/views/native_widget_view_manager.h"
-#include "ui/gfx/text_constants.h"
-#include "ui/views/background.h"
-#include "ui/views/controls/button/blue_button.h"
-#include "ui/views/controls/button/radio_button.h"
-#include "ui/views/widget/widget.h"
-
-namespace mojo {
-namespace examples {
-
-namespace {
-
-const int kControlBorderInset = 5;
-const int kNavigationTargetGroupId = 1;
-
-} // namespace
-
-DebugPanel::DebugPanel(Delegate* delegate, Shell* shell, View* view)
- : delegate_(delegate),
- view_(view),
- navigation_target_label_(
- new views::Label(base::ASCIIToUTF16("Navigation target:"))),
- navigation_target_new_(
- new views::RadioButton(base::ASCIIToUTF16("New window"),
- kNavigationTargetGroupId)),
- navigation_target_source_(
- new views::RadioButton(base::ASCIIToUTF16("Source window"),
- kNavigationTargetGroupId)),
- navigation_target_default_(
- new views::RadioButton(base::ASCIIToUTF16("Default"),
- kNavigationTargetGroupId)),
- colored_square_(
- new views::BlueButton(this, base::ASCIIToUTF16("Local nav test"))),
- close_last_(
- new views::BlueButton(this, base::ASCIIToUTF16("Close last window"))),
- cross_app_(
- new views::BlueButton(this,
- base::ASCIIToUTF16("Cross-app nav test"))) {
- navigation_target_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
- navigation_target_default_->SetChecked(true);
-
- views::WidgetDelegateView* widget_delegate = new views::WidgetDelegateView();
- widget_delegate->GetContentsView()->set_background(
- views::Background::CreateSolidBackground(0xFFDDDDDD));
- widget_delegate->GetContentsView()->AddChildView(navigation_target_label_);
- widget_delegate->GetContentsView()->AddChildView(navigation_target_default_);
- widget_delegate->GetContentsView()->AddChildView(navigation_target_new_);
- widget_delegate->GetContentsView()->AddChildView(navigation_target_source_);
- widget_delegate->GetContentsView()->AddChildView(colored_square_);
- widget_delegate->GetContentsView()->AddChildView(close_last_);
- widget_delegate->GetContentsView()->AddChildView(cross_app_);
- widget_delegate->GetContentsView()->SetLayoutManager(this);
-
- views::Widget* widget = new views::Widget();
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.native_widget = new NativeWidgetViewManager(widget, shell, view);
- params.delegate = widget_delegate;
- params.bounds = gfx::Rect(view->bounds().size());
- widget->Init(params);
- widget->Show();
-}
-
-DebugPanel::~DebugPanel() {
-}
-
-gfx::Size DebugPanel::GetPreferredSize(const views::View* view) const {
- return gfx::Size();
-}
-
-Target DebugPanel::navigation_target() const {
- if (navigation_target_new_->checked())
- return TARGET_NEW_NODE;
- if (navigation_target_source_->checked())
- return TARGET_SOURCE_NODE;
- return TARGET_DEFAULT;
-}
-
-void DebugPanel::Layout(views::View* view) {
- int y = kControlBorderInset;
- int w = view->width() - kControlBorderInset * 2;
-
- navigation_target_label_->SetBounds(
- kControlBorderInset, y, w,
- navigation_target_label_->GetPreferredSize().height());
- y += navigation_target_label_->height();
-
- views::RadioButton* radios[] = {
- navigation_target_default_,
- navigation_target_new_,
- navigation_target_source_,
- };
- for (size_t i = 0; i < arraysize(radios); ++i) {
- radios[i]->SetBounds(kControlBorderInset, y, w,
- radios[i]->GetPreferredSize().height());
- y += radios[i]->height();
- }
-
- y += kControlBorderInset;
- views::Button* buttons[] = {
- colored_square_,
- close_last_,
- cross_app_,
- };
- for (size_t i = 0; i < arraysize(buttons); ++i) {
- buttons[i]->SetBounds(kControlBorderInset, y, w,
- buttons[i]->GetPreferredSize().height());
- y += buttons[i]->height();
- }
-}
-
-void DebugPanel::ButtonPressed(views::Button* sender, const ui::Event& event) {
- if (sender == colored_square_) {
- Navigate("mojo://embedded_app/");
- } else if (sender == close_last_) {
- delegate_->CloseTopWindow();
- } else if (sender == cross_app_) {
- Navigate("http://www.aaronboodman.com/z_dropbox/test.html");
- }
-}
-
-void DebugPanel::Navigate(const std::string& url) {
- URLRequestPtr request(URLRequest::New());
- request->url = url;
- delegate_->RequestNavigate(view_->id(), TARGET_NEW_NODE, request.Pass());
-}
-
-} // namespace examples
-} // namespace mojo
diff --git a/mojo/examples/window_manager/debug_panel.h b/mojo/examples/window_manager/debug_panel.h
deleted file mode 100644
index eec3067..0000000
--- a/mojo/examples/window_manager/debug_panel.h
+++ /dev/null
@@ -1,76 +0,0 @@
-// Copyright 2014 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_EXAMPLES_WINDOW_MANAGER_DEBUG_PANEL_H_
-#define MOJO_EXAMPLES_WINDOW_MANAGER_DEBUG_PANEL_H_
-
-#include <string>
-
-#include "base/macros.h"
-#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
-#include "ui/views/controls/button/button.h"
-#include "ui/views/layout/layout_manager.h"
-#include "ui/views/widget/widget_delegate.h"
-
-namespace views {
-class Label;
-class RadioButton;
-}
-
-namespace mojo {
-
-class Shell;
-class View;
-
-namespace examples {
-
-// A panel of controls intended to demonstrate the functionality of the window
-// manager.
-class DebugPanel : public views::LayoutManager, public views::ButtonListener {
- public:
- class Delegate {
- public:
- virtual void CloseTopWindow() = 0;
- virtual void RequestNavigate(uint32 source_view_id,
- Target target,
- URLRequestPtr url_request) = 0;
-
- protected:
- virtual ~Delegate(){}
- };
-
- DebugPanel(Delegate* delegate, Shell* shell, View* view);
- virtual ~DebugPanel();
-
- Target navigation_target() const;
-
- private:
- // LayoutManager overrides:
- virtual gfx::Size GetPreferredSize(const views::View* view) const override;
- virtual void Layout(views::View* host) override;
- virtual void ButtonPressed(views::Button* sender,
- const ui::Event& event) override;
-
- void Navigate(const std::string& url);
-
- Delegate* delegate_;
- Shell* shell_;
- View* view_;
-
- views::Label* navigation_target_label_;
- views::RadioButton* navigation_target_new_;
- views::RadioButton* navigation_target_source_;
- views::RadioButton* navigation_target_default_;
-
- views::Button* colored_square_;
- views::Button* close_last_;
- views::Button* cross_app_;
-
- DISALLOW_COPY_AND_ASSIGN(DebugPanel);
-};
-
-} // examples
-} // mojo
-
-#endif // MOJO_EXAMPLES_WINDOW_MANAGER_DEBUG_PANEL_H_
diff --git a/mojo/examples/window_manager/window_manager.cc b/mojo/examples/window_manager/window_manager.cc
deleted file mode 100644
index e2bb237..0000000
--- a/mojo/examples/window_manager/window_manager.cc
+++ /dev/null
@@ -1,603 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/macros.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/examples/keyboard/keyboard.mojom.h"
-#include "mojo/examples/window_manager/debug_panel.h"
-#include "mojo/examples/window_manager/window_manager.mojom.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/interface_factory_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.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"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
-#include "mojo/services/public/interfaces/navigation/navigation.mojom.h"
-#include "mojo/services/window_manager/window_manager_app.h"
-#include "mojo/services/window_manager/window_manager_delegate.h"
-#include "mojo/views/views_init.h"
-#include "ui/aura/window.h"
-#include "ui/events/event.h"
-#include "ui/events/event_constants.h"
-#include "ui/gfx/geometry/size_conversions.h"
-#include "ui/wm/core/focus_rules.h"
-
-#if defined CreateWindow
-#undef CreateWindow
-#endif
-
-namespace mojo {
-namespace examples {
-
-class WindowManager;
-
-namespace {
-
-const int kBorderInset = 25;
-const int kControlPanelWidth = 200;
-const int kTextfieldHeight = 25;
-
-class WMFocusRules : public wm::FocusRules {
- public:
- WMFocusRules(mojo::WindowManagerApp* window_manager_app,
- mojo::View* window_container)
- : window_container_(window_container),
- window_manager_app_(window_manager_app) {}
- virtual ~WMFocusRules() {}
-
- private:
- // Overridden from wm::FocusRules:
- virtual bool IsToplevelWindow(aura::Window* window) const override {
- return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
- window_container_;
- }
- virtual bool CanActivateWindow(aura::Window* window) const override {
- return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
- window_container_;
- }
- virtual bool CanFocusWindow(aura::Window* window) const override {
- return true;
- }
- virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
- mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
- while (view->parent() != window_container_) {
- view = view->parent();
- // Unparented hierarchy, there is no "top level" window.
- if (!view)
- return NULL;
- }
-
- return window_manager_app_->GetWindowForViewId(view->id());
- }
- virtual aura::Window* GetActivatableWindow(
- aura::Window* window) const override {
- return GetToplevelWindow(window);
- }
- virtual aura::Window* GetFocusableWindow(
- aura::Window* window) const override {
- return window;
- }
- virtual aura::Window* GetNextActivatableWindow(
- aura::Window* ignore) const override {
- aura::Window* activatable = GetActivatableWindow(ignore);
- const aura::Window::Windows& children = activatable->parent()->children();
- for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
- it != children.rend(); ++it) {
- if (*it != ignore)
- return *it;
- }
- return NULL;
- }
-
- mojo::View* window_container_;
- mojo::WindowManagerApp* window_manager_app_;
-
- DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
-};
-
-} // namespace
-
-class WindowManagerConnection : public InterfaceImpl<IWindowManager> {
- public:
- explicit WindowManagerConnection(WindowManager* window_manager)
- : window_manager_(window_manager) {}
- virtual ~WindowManagerConnection() {}
-
- private:
- // Overridden from IWindowManager:
- virtual void CloseWindow(Id view_id) override;
- virtual void ShowKeyboard(Id view_id, RectPtr bounds) override;
- virtual void HideKeyboard(Id view_id) override;
-
- WindowManager* window_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerConnection);
-};
-
-class NavigatorHostImpl : public InterfaceImpl<NavigatorHost> {
- public:
- explicit NavigatorHostImpl(WindowManager* window_manager, Id view_id)
- : window_manager_(window_manager), view_id_(view_id) {}
- virtual ~NavigatorHostImpl() {
- }
-
- private:
- virtual void DidNavigateLocally(const mojo::String& url) override;
- virtual void RequestNavigate(Target target, URLRequestPtr request) override;
-
- WindowManager* window_manager_;
- Id view_id_;
-
- DISALLOW_COPY_AND_ASSIGN(NavigatorHostImpl);
-};
-
-class KeyboardManager : public KeyboardClient,
- public ViewObserver {
- public:
- KeyboardManager() : view_manager_(NULL), view_(NULL) {
- }
- virtual ~KeyboardManager() {
- if (view_)
- view_->parent()->RemoveObserver(this);
- }
-
- View* view() { return view_; }
-
- void Init(ApplicationImpl* application,
- ViewManager* view_manager,
- View* parent,
- const gfx::Rect& bounds) {
- view_manager_ = view_manager;
- view_ = View::Create(view_manager);
- view_->SetBounds(bounds);
- parent->AddChild(view_);
- view_->Embed("mojo:keyboard");
- application->ConnectToService("mojo:keyboard", &keyboard_service_);
- keyboard_service_.set_client(this);
- parent->AddObserver(this);
- }
-
- void Show(Id view_id, const gfx::Rect& bounds) {
- keyboard_service_->SetTarget(view_id);
- view_->SetVisible(true);
- }
-
- void Hide(Id view_id) {
- keyboard_service_->SetTarget(0);
- view_->SetVisible(false);
- }
-
- private:
- // KeyboardClient:
- virtual void OnKeyboardEvent(Id view_id,
- int32_t code,
- int32_t flags) override {
- // TODO(sky): figure this out. Code use to dispatch events, but that's a
- // hack. Instead strings should be passed through, or maybe a richer text
- // input interface.
- }
-
- // Overridden from ViewObserver:
- virtual void OnViewBoundsChanged(View* parent,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {
- gfx::Rect keyboard_bounds(view_->bounds());
- keyboard_bounds.set_y(new_bounds.bottom() - keyboard_bounds.height());
- keyboard_bounds.set_width(keyboard_bounds.width() +
- new_bounds.width() - old_bounds.width());
- view_->SetBounds(keyboard_bounds);
- }
- virtual void OnViewDestroyed(View* parent) override {
- DCHECK_EQ(parent, view_->parent());
- parent->RemoveObserver(this);
- view_ = NULL;
- }
-
- KeyboardServicePtr keyboard_service_;
- ViewManager* view_manager_;
-
- // View the keyboard is attached to.
- View* view_;
-
- DISALLOW_COPY_AND_ASSIGN(KeyboardManager);
-};
-
-class RootLayoutManager : public ViewObserver {
- public:
- RootLayoutManager(ViewManager* view_manager,
- View* root,
- Id content_view_id,
- Id launcher_ui_view_id,
- Id control_panel_view_id)
- : root_(root),
- view_manager_(view_manager),
- content_view_id_(content_view_id),
- launcher_ui_view_id_(launcher_ui_view_id),
- control_panel_view_id_(control_panel_view_id) {}
- virtual ~RootLayoutManager() {
- if (root_)
- root_->RemoveObserver(this);
- }
-
- private:
- // Overridden from ViewObserver:
- virtual void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {
- DCHECK_EQ(view, root_);
-
- View* content_view = view_manager_->GetViewById(content_view_id_);
- content_view->SetBounds(new_bounds);
-
- int delta_width = new_bounds.width() - old_bounds.width();
- int delta_height = new_bounds.height() - old_bounds.height();
-
- View* launcher_ui_view =
- view_manager_->GetViewById(launcher_ui_view_id_);
- gfx::Rect launcher_ui_bounds(launcher_ui_view->bounds());
- launcher_ui_bounds.set_width(launcher_ui_bounds.width() + delta_width);
- launcher_ui_view->SetBounds(launcher_ui_bounds);
-
- View* control_panel_view =
- view_manager_->GetViewById(control_panel_view_id_);
- gfx::Rect control_panel_bounds(control_panel_view->bounds());
- control_panel_bounds.set_x(control_panel_bounds.x() + delta_width);
- control_panel_view->SetBounds(control_panel_bounds);
-
- const View::Children& content_views = content_view->children();
- View::Children::const_iterator iter = content_views.begin();
- for(; iter != content_views.end(); ++iter) {
- View* view = *iter;
- if (view->id() == control_panel_view->id() ||
- view->id() == launcher_ui_view->id())
- continue;
- gfx::Rect view_bounds(view->bounds());
- view_bounds.set_width(view_bounds.width() + delta_width);
- view_bounds.set_height(view_bounds.height() + delta_height);
- view->SetBounds(view_bounds);
- }
- }
- virtual void OnViewDestroyed(View* view) override {
- DCHECK_EQ(view, root_);
- root_->RemoveObserver(this);
- root_ = NULL;
- }
-
- View* root_;
- ViewManager* view_manager_;
- const Id content_view_id_;
- const Id launcher_ui_view_id_;
- const Id control_panel_view_id_;
-
- DISALLOW_COPY_AND_ASSIGN(RootLayoutManager);
-};
-
-class Window : public InterfaceFactory<NavigatorHost> {
- public:
- Window(WindowManager* window_manager, View* view)
- : window_manager_(window_manager), view_(view) {}
-
- virtual ~Window() {}
-
- View* view() const { return view_; }
-
- void Embed(const std::string& url) {
- scoped_ptr<ServiceProviderImpl> service_provider_impl(
- new ServiceProviderImpl());
- service_provider_impl->AddService<NavigatorHost>(this);
- view_->Embed(url, service_provider_impl.Pass());
- }
-
- private:
- // InterfaceFactory<NavigatorHost>
- virtual void Create(ApplicationConnection* connection,
- InterfaceRequest<NavigatorHost> request) override {
- BindToRequest(new NavigatorHostImpl(window_manager_, view_->id()),
- &request);
- }
-
- WindowManager* window_manager_;
- View* view_;
-};
-
-class WindowManager
- : public ApplicationDelegate,
- public DebugPanel::Delegate,
- public ViewManagerDelegate,
- public WindowManagerDelegate,
- public ui::EventHandler {
- public:
- WindowManager()
- : shell_(nullptr),
- window_manager_factory_(this),
- launcher_ui_(NULL),
- view_manager_(NULL),
- window_manager_app_(new WindowManagerApp(this, this)),
- app_(NULL) {}
-
- virtual ~WindowManager() {
- // host() may be destroyed by the time we get here.
- // TODO: figure out a way to always cleanly remove handler.
- if (window_manager_app_->host())
- window_manager_app_->host()->window()->RemovePreTargetHandler(this);
- }
-
- void CloseWindow(Id view_id) {
- WindowVector::iterator iter = GetWindowByViewId(view_id);
- DCHECK(iter != windows_.end());
- Window* window = *iter;
- windows_.erase(iter);
- window->view()->Destroy();
- }
-
- void ShowKeyboard(Id view_id, const gfx::Rect& bounds) {
- // TODO: this needs to validate |view_id|. That is, it shouldn't assume
- // |view_id| is valid and it also needs to make sure the client that sent
- // this really owns |view_id|.
- // TODO: honor |bounds|.
- if (!keyboard_manager_) {
- keyboard_manager_.reset(new KeyboardManager);
- View* parent = view_manager_->GetRoots().back();
- int ideal_height = 200;
- // TODO(sky): 10 is a bit of a hack here. There is a bug that causes
- // white strips to appear when 0 is used. Figure this out!
- const gfx::Rect keyboard_bounds(
- 10, parent->bounds().height() - ideal_height,
- parent->bounds().width() - 20, ideal_height);
- keyboard_manager_->Init(app_, view_manager_, parent, keyboard_bounds);
- }
- keyboard_manager_->Show(view_id, bounds);
- }
-
- void HideKeyboard(Id view_id) {
- // See comment in ShowKeyboard() about validating args.
- if (keyboard_manager_)
- keyboard_manager_->Hide(view_id);
- }
-
- void DidNavigateLocally(uint32 source_view_id, const mojo::String& url) {
- LOG(ERROR) << "DidNavigateLocally: source_view_id: " << source_view_id
- << " url: " << url.To<std::string>();
- }
-
- // Overridden from DebugPanel::Delegate:
- virtual void CloseTopWindow() override {
- if (!windows_.empty())
- CloseWindow(windows_.back()->view()->id());
- }
-
- virtual void RequestNavigate(uint32 source_view_id,
- Target target,
- URLRequestPtr request) override {
- OnLaunch(source_view_id, target, request->url);
- }
-
- private:
- typedef std::vector<Window*> WindowVector;
-
- // Overridden from ApplicationDelegate:
- virtual void Initialize(ApplicationImpl* app) override {
- shell_ = app->shell();
- app_ = app;
- views_init_.reset(new ViewsInit);
- window_manager_app_->Initialize(app);
- }
-
- virtual bool ConfigureIncomingConnection(
- ApplicationConnection* connection) override {
- connection->AddService(&window_manager_factory_);
- window_manager_app_->ConfigureIncomingConnection(connection);
- return true;
- }
-
- // Overridden from ViewManagerDelegate:
- virtual void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- DCHECK(!view_manager_);
- view_manager_ = view_manager;
-
- View* view = View::Create(view_manager_);
- root->AddChild(view);
- view->SetBounds(gfx::Rect(root->bounds().size()));
- content_view_id_ = view->id();
-
- Id launcher_ui_id = CreateLauncherUI();
- Id control_panel_id = CreateControlPanel(view);
-
- root_layout_manager_.reset(
- new RootLayoutManager(view_manager, root,
- content_view_id_,
- launcher_ui_id,
- control_panel_id));
- root->AddObserver(root_layout_manager_.get());
-
- window_manager_app_->host()->window()->AddPreTargetHandler(this);
-
- window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
- view));
- }
- virtual void OnViewManagerDisconnected(ViewManager* view_manager) override {
- DCHECK_EQ(view_manager_, view_manager);
- view_manager_ = NULL;
- base::MessageLoop::current()->Quit();
- }
-
- // Overridden from WindowManagerDelegate:
- virtual void Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override {
- const Id kInvalidSourceViewId = 0;
- OnLaunch(kInvalidSourceViewId, TARGET_DEFAULT, url);
- }
-
- // Overridden from ui::EventHandler:
- virtual void OnEvent(ui::Event* event) override {
- View* view = WindowManagerApp::GetViewForWindow(
- static_cast<aura::Window*>(event->target()));
- if (event->type() == ui::ET_MOUSE_PRESSED &&
- !IsDescendantOfKeyboard(view)) {
- view->SetFocus();
- }
- }
-
- void OnLaunch(uint32 source_view_id,
- Target requested_target,
- const mojo::String& url) {
- Target target = debug_panel_->navigation_target();
- if (target == TARGET_DEFAULT) {
- if (requested_target != TARGET_DEFAULT) {
- target = requested_target;
- } else {
- // TODO(aa): Should be TARGET_NEW_NODE if source origin and dest origin
- // are different?
- target = TARGET_SOURCE_NODE;
- }
- }
-
- Window* dest_view = NULL;
- if (target == TARGET_SOURCE_NODE) {
- WindowVector::iterator source_view = GetWindowByViewId(source_view_id);
- bool app_initiated = source_view != windows_.end();
- if (app_initiated)
- dest_view = *source_view;
- else if (!windows_.empty())
- dest_view = windows_.back();
- }
-
- if (!dest_view) {
- dest_view = CreateWindow();
- windows_.push_back(dest_view);
- }
-
- dest_view->Embed(url);
- }
-
- // TODO(beng): proper layout manager!!
- Id CreateLauncherUI() {
- View* view = view_manager_->GetViewById(content_view_id_);
- gfx::Rect bounds = view->bounds();
- bounds.Inset(kBorderInset, kBorderInset);
- bounds.set_height(kTextfieldHeight);
- launcher_ui_ = CreateWindow(bounds);
- launcher_ui_->Embed("mojo:browser");
- return launcher_ui_->view()->id();
- }
-
- Window* CreateWindow() {
- View* view = view_manager_->GetViewById(content_view_id_);
- gfx::Rect bounds(kBorderInset,
- 2 * kBorderInset + kTextfieldHeight,
- view->bounds().width() - 3 * kBorderInset -
- kControlPanelWidth,
- view->bounds().height() -
- (3 * kBorderInset + kTextfieldHeight));
- if (!windows_.empty()) {
- gfx::Point position = windows_.back()->view()->bounds().origin();
- position.Offset(35, 35);
- bounds.set_origin(position);
- }
- return CreateWindow(bounds);
- }
-
- Window* CreateWindow(const gfx::Rect& bounds) {
- View* content = view_manager_->GetViewById(content_view_id_);
- View* view = View::Create(view_manager_);
- content->AddChild(view);
- view->SetBounds(bounds);
- view->SetFocus();
- return new Window(this, view);
- }
-
- bool IsDescendantOfKeyboard(View* target) {
- return keyboard_manager_.get() &&
- keyboard_manager_->view()->Contains(target);
- }
-
- Id CreateControlPanel(View* root) {
- View* view = View::Create(view_manager_);
- root->AddChild(view);
-
- gfx::Rect bounds(root->bounds().width() - kControlPanelWidth -
- kBorderInset,
- kBorderInset * 2 + kTextfieldHeight,
- kControlPanelWidth,
- root->bounds().height() - kBorderInset * 3 -
- kTextfieldHeight);
- view->SetBounds(bounds);
-
- debug_panel_ = new DebugPanel(this, shell_, view);
- return view->id();
- }
-
- WindowVector::iterator GetWindowByViewId(Id view_id) {
- for (std::vector<Window*>::iterator iter = windows_.begin();
- iter != windows_.end();
- ++iter) {
- if ((*iter)->view()->id() == view_id) {
- return iter;
- }
- }
- return windows_.end();
- }
-
- Shell* shell_;
-
- InterfaceFactoryImplWithContext<WindowManagerConnection, WindowManager>
- window_manager_factory_;
-
- scoped_ptr<ViewsInit> views_init_;
- DebugPanel* debug_panel_;
- Window* launcher_ui_;
- WindowVector windows_;
- ViewManager* view_manager_;
- scoped_ptr<RootLayoutManager> root_layout_manager_;
-
- scoped_ptr<WindowManagerApp> window_manager_app_;
-
- // Id of the view most content is added to. The keyboard is NOT added here.
- Id content_view_id_;
-
- scoped_ptr<KeyboardManager> keyboard_manager_;
- ApplicationImpl* app_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManager);
-};
-
-void WindowManagerConnection::CloseWindow(Id view_id) {
- window_manager_->CloseWindow(view_id);
-}
-
-void WindowManagerConnection::ShowKeyboard(Id view_id, RectPtr bounds) {
- window_manager_->ShowKeyboard(view_id, bounds.To<gfx::Rect>());
-}
-
-void WindowManagerConnection::HideKeyboard(Id view_id) {
- window_manager_->HideKeyboard(view_id);
-}
-
-void NavigatorHostImpl::DidNavigateLocally(const mojo::String& url) {
- window_manager_->DidNavigateLocally(view_id_, url);
-}
-
-void NavigatorHostImpl::RequestNavigate(Target target, URLRequestPtr request) {
- window_manager_->RequestNavigate(view_id_, target, request.Pass());
-}
-
-} // namespace examples
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::examples::WindowManager);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/window_manager/window_manager.mojom b/mojo/examples/window_manager/window_manager.mojom
deleted file mode 100644
index c6b4187..0000000
--- a/mojo/examples/window_manager/window_manager.mojom
+++ /dev/null
@@ -1,22 +0,0 @@
-// Copyright 2014 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.
-
-import "mojo/services/public/interfaces/geometry/geometry.mojom"
-
-module mojo {
-
-interface IWindowManager {
- CloseWindow(uint32 node_id);
-
- // Shows the keyboard for the specified view. |bounds| is the bounds of the
- // view that is showing focus. |bounds| is relative to the bounds of the node.
- // Events from the keyboard are routed to the view with id |view_id|.
- ShowKeyboard(uint32 view_id, mojo.Rect? bounds);
-
- // Hides the keyboard. This is ignored if |view_id| is not the view that was
- // last passed to ShowKeyboard().
- HideKeyboard(uint32 view_id);
-};
-
-}
diff --git a/mojo/examples/wm_flow/BUILD.gn b/mojo/examples/wm_flow/BUILD.gn
deleted file mode 100644
index 5f70abf..0000000
--- a/mojo/examples/wm_flow/BUILD.gn
+++ /dev/null
@@ -1,111 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-import("//mojo/public/tools/bindings/mojom.gni")
-
-assert(use_aura)
-
-group("wm_flow") {
- deps = [
- ":app",
- ":embedded",
- ":init",
- ":wm",
- ]
-}
-
-shared_library("wm") {
- output_name = "mojo_wm_flow_wm"
-
- sources = [
- "wm/wm.cc",
- "wm/frame_controller.cc",
- "wm/frame_controller.h",
- ]
-
- deps = [
- "//base",
- "//skia",
- "//ui/aura",
- "//ui/views",
- "//ui/wm:wm",
- "//mojo/application",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/input_events",
- "//mojo/services/window_manager:lib",
- "//mojo/views:views",
- ]
-}
-
-shared_library("init") {
- output_name = "mojo_wm_flow_init"
-
- sources = [
- "init/init.cc",
- ]
-
- deps = [
- "//base",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//mojo/application",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/interfaces/application:application",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/view_manager",
- ]
-}
-
-shared_library("app") {
- output_name = "mojo_wm_flow_app"
-
- sources = [
- "app/app.cc",
- ]
-
- deps = [
- ":embedder_bindings",
- ":embeddee_bindings",
- "//base",
- "//mojo/application",
- "//mojo/examples/bitmap_uploader",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/interfaces/application:application",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/window_manager:lib",
- ]
-}
-
-shared_library("embedded") {
- output_name = "mojo_wm_flow_embedded"
-
- sources = [
- "embedded/embedded.cc",
- ]
-
- deps = [
- ":embedder_bindings",
- ":embeddee_bindings",
- "//base",
- "//mojo/application",
- "//mojo/examples/bitmap_uploader",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/window_manager:lib",
- ]
-}
-
-mojom("embedder_bindings") {
- sources = [
- "app/embedder.mojom",
- ]
-}
-
-mojom("embeddee_bindings") {
- sources = [
- "embedded/embeddee.mojom",
- ]
-}
diff --git a/mojo/examples/wm_flow/app/DEPS b/mojo/examples/wm_flow/app/DEPS
deleted file mode 100644
index e69de29..0000000
--- a/mojo/examples/wm_flow/app/DEPS
+++ /dev/null
diff --git a/mojo/examples/wm_flow/app/app.cc b/mojo/examples/wm_flow/app/app.cc
deleted file mode 100644
index d9a8da2..0000000
--- a/mojo/examples/wm_flow/app/app.cc
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2014 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 <map>
-
-#include "base/bind.h"
-#include "base/macros.h"
-#include "base/stl_util.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
-#include "mojo/examples/wm_flow/app/embedder.mojom.h"
-#include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/cpp/application/interface_factory_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/public/interfaces/application/service_provider.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_context.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-
-namespace examples {
-namespace {
-
-const SkColor kColors[] = { SK_ColorRED, SK_ColorGREEN, SK_ColorYELLOW };
-
-class EmbedderImpl : public mojo::InterfaceImpl<Embedder> {
- public:
- EmbedderImpl() {}
- virtual ~EmbedderImpl() {}
-
- private:
- // Overridden from Embedder:
- virtual void HelloWorld(const mojo::Callback<void()>& callback) override {
- callback.Run();
- }
-
- DISALLOW_COPY_AND_ASSIGN(EmbedderImpl);
-};
-
-} // namespace
-
-// This app starts its life via Connect() rather than by being embed, so it does
-// not start with a connection to the ViewManager service. It has to obtain a
-// connection by connecting to the ViewManagerInit service and asking to be
-// embed without a view context.
-class WMFlowApp : public mojo::ApplicationDelegate,
- public mojo::ViewManagerDelegate,
- public mojo::ViewObserver {
- public:
- WMFlowApp() : shell_(nullptr), embed_count_(0) {}
- virtual ~WMFlowApp() { STLDeleteValues(&uploaders_); }
-
- private:
- typedef std::map<mojo::View*, mojo::BitmapUploader*> ViewToUploader;
-
- // Overridden from Application:
- virtual void Initialize(mojo::ApplicationImpl* app) override {
- shell_ = app->shell();
- view_manager_client_factory_.reset(
- new mojo::ViewManagerClientFactory(app->shell(), this));
- view_manager_context_.reset(new mojo::ViewManagerContext(app));
- OpenNewWindow();
- OpenNewWindow();
- OpenNewWindow();
- }
- virtual bool ConfigureIncomingConnection(
- mojo::ApplicationConnection* connection) override {
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- void OnConnect(bool success) {}
-
- // Overridden from mojo::ViewManagerDelegate:
- virtual void OnEmbed(
- mojo::ViewManager* view_manager,
- mojo::View* root,
- mojo::ServiceProviderImpl* exported_services,
- scoped_ptr<mojo::ServiceProvider> imported_services) override {
- root->AddObserver(this);
- mojo::BitmapUploader* uploader = new mojo::BitmapUploader(root);
- uploaders_[root] = uploader;
- uploader->Init(shell_);
- uploader->SetColor(kColors[embed_count_++ % arraysize(kColors)]);
-
- mojo::View* embed = mojo::View::Create(view_manager);
- root->AddChild(embed);
- gfx::Rect bounds = gfx::Rect(root->bounds().size());
- bounds.Inset(25, 25);
- embed->SetBounds(bounds);
-
- scoped_ptr<mojo::ServiceProviderImpl> registry(
- new mojo::ServiceProviderImpl);
- // Expose some services to the embeddee...
- registry->AddService(&embedder_factory_);
- scoped_ptr<mojo::ServiceProvider> imported =
- embed->Embed("mojo:wm_flow_embedded", registry.Pass());
- mojo::ConnectToService(imported.get(), &embeddee_);
- embeddee_->HelloBack(base::Bind(&WMFlowApp::HelloBackAck,
- base::Unretained(this)));
- }
- virtual void OnViewManagerDisconnected(
- mojo::ViewManager* view_manager) override {
- STLDeleteValues(&uploaders_);
- }
-
- // Overridden from mojo::ViewObserver:
- virtual void OnViewInputEvent(mojo::View* view,
- const mojo::EventPtr& event) override {
- if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
- event->flags & mojo::EVENT_FLAGS_LEFT_MOUSE_BUTTON) {
- OpenNewWindow();
- }
- }
- virtual void OnViewDestroyed(mojo::View* view) override {
- if (uploaders_.find(view) != uploaders_.end()) {
- delete uploaders_[view];
- uploaders_.erase(view);
- }
- --embed_count_;
- view->RemoveObserver(this);
- }
-
- void HelloBackAck() {
- printf("HelloBack() ack'ed\n");
- }
-
- void OpenNewWindow() { view_manager_context_->Embed("mojo:wm_flow_app"); }
-
- mojo::Shell* shell_;
- int embed_count_;
- scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
- mojo::InterfaceFactoryImpl<EmbedderImpl> embedder_factory_;
- scoped_ptr<mojo::ViewManagerContext> view_manager_context_;
- EmbeddeePtr embeddee_;
- ViewToUploader uploaders_;
-
- DISALLOW_COPY_AND_ASSIGN(WMFlowApp);
-};
-
-} // namespace examples
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new examples::WMFlowApp);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/wm_flow/app/embedder.mojom b/mojo/examples/wm_flow/app/embedder.mojom
deleted file mode 100644
index aae7870..0000000
--- a/mojo/examples/wm_flow/app/embedder.mojom
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2014 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.
-
-module examples {
-
-interface Embedder {
- HelloWorld() => ();
-};
-
-}
diff --git a/mojo/examples/wm_flow/embedded/embedded.cc b/mojo/examples/wm_flow/embedded/embedded.cc
deleted file mode 100644
index d328501..0000000
--- a/mojo/examples/wm_flow/embedded/embedded.cc
+++ /dev/null
@@ -1,98 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/macros.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/examples/bitmap_uploader/bitmap_uploader.h"
-#include "mojo/examples/wm_flow/app/embedder.mojom.h"
-#include "mojo/examples/wm_flow/embedded/embeddee.mojom.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/cpp/application/interface_factory_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-
-namespace examples {
-
-namespace {
-
-class EmbeddeeImpl : public mojo::InterfaceImpl<Embeddee> {
- public:
- EmbeddeeImpl() {}
- virtual ~EmbeddeeImpl() {}
-
- private:
- // Overridden from Embeddee:
- virtual void HelloBack(const mojo::Callback<void()>& callback) override {
- callback.Run();
- }
-
- DISALLOW_COPY_AND_ASSIGN(EmbeddeeImpl);
-};
-
-} // namespace
-
-class WMFlowEmbedded : public mojo::ApplicationDelegate,
- public mojo::ViewManagerDelegate {
- public:
- WMFlowEmbedded() : shell_(nullptr) {}
- virtual ~WMFlowEmbedded() {}
-
- private:
- // Overridden from Application:
- virtual void Initialize(mojo::ApplicationImpl* app) override {
- shell_ = app->shell();
- view_manager_client_factory_.reset(
- new mojo::ViewManagerClientFactory(app->shell(), this));
- }
- virtual bool ConfigureIncomingConnection(
- mojo::ApplicationConnection* connection) override {
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- // Overridden from mojo::ViewManagerDelegate:
- virtual void OnEmbed(
- mojo::ViewManager* view_manager,
- mojo::View* root,
- mojo::ServiceProviderImpl* exported_services,
- scoped_ptr<mojo::ServiceProvider> imported_services) override {
- bitmap_uploader_.reset(new mojo::BitmapUploader(root));
- bitmap_uploader_->Init(shell_);
- bitmap_uploader_->SetColor(SK_ColorMAGENTA);
-
- exported_services->AddService(&embeddee_factory_);
- mojo::ConnectToService(imported_services.get(), &embedder_);
- embedder_->HelloWorld(base::Bind(&WMFlowEmbedded::HelloWorldAck,
- base::Unretained(this)));
- }
- virtual void OnViewManagerDisconnected(
- mojo::ViewManager* view_manager) override {}
-
- void HelloWorldAck() {
- printf("HelloWorld() ack'ed\n");
- }
-
- mojo::Shell* shell_;
- scoped_ptr<mojo::ViewManagerClientFactory> view_manager_client_factory_;
- EmbedderPtr embedder_;
- mojo::InterfaceFactoryImpl<EmbeddeeImpl> embeddee_factory_;
- scoped_ptr<mojo::BitmapUploader> bitmap_uploader_;
-
- DISALLOW_COPY_AND_ASSIGN(WMFlowEmbedded);
-};
-
-} // namespace examples
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new examples::WMFlowEmbedded);
- return runner.Run(shell_handle);
-}
-
diff --git a/mojo/examples/wm_flow/embedded/embeddee.mojom b/mojo/examples/wm_flow/embedded/embeddee.mojom
deleted file mode 100644
index b989da2..0000000
--- a/mojo/examples/wm_flow/embedded/embeddee.mojom
+++ /dev/null
@@ -1,11 +0,0 @@
-// Copyright 2014 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.
-
-module examples {
-
-interface Embeddee {
- HelloBack() => ();
-};
-
-}
diff --git a/mojo/examples/wm_flow/init/init.cc b/mojo/examples/wm_flow/init/init.cc
deleted file mode 100644
index 5738edd..0000000
--- a/mojo/examples/wm_flow/init/init.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// Copyright 2014 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/application/application_runner_chromium.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/services/public/cpp/view_manager/view_manager.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_context.h"
-
-namespace examples {
-
-// This application starts the view manager, embeds the window manager and then
-// starts another app (wm_flow_app) which also connects to the view manager and
-// asks to be embedded without context.
-class WMFlowInit : public mojo::ApplicationDelegate {
- public:
- WMFlowInit() {}
- virtual ~WMFlowInit() {}
-
- private:
- // Overridden from Application:
- virtual void Initialize(mojo::ApplicationImpl* app) override {
- context_.reset(new mojo::ViewManagerContext(app));
- context_->Embed("mojo:wm_flow_wm");
- app->ConnectToApplication("mojo:wm_flow_app");
- }
-
- scoped_ptr<mojo::ViewManagerContext> context_;
-
- DISALLOW_COPY_AND_ASSIGN(WMFlowInit);
-};
-
-} // namespace examples
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new examples::WMFlowInit);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/examples/wm_flow/wm/DEPS b/mojo/examples/wm_flow/wm/DEPS
deleted file mode 100644
index 1486b9f..0000000
--- a/mojo/examples/wm_flow/wm/DEPS
+++ /dev/null
@@ -1,7 +0,0 @@
-include_rules = [
- "+ui/aura",
- "+ui/gfx/geometry",
- "+ui/views",
- "+ui/wm/core",
- "+ui/wm/public",
-]
diff --git a/mojo/examples/wm_flow/wm/frame_controller.cc b/mojo/examples/wm_flow/wm/frame_controller.cc
deleted file mode 100644
index 40ff041..0000000
--- a/mojo/examples/wm_flow/wm/frame_controller.cc
+++ /dev/null
@@ -1,157 +0,0 @@
-// Copyright 2014 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/examples/wm_flow/wm/frame_controller.h"
-
-#include "base/macros.h"
-#include "base/strings/utf_string_conversions.h"
-#include "mojo/services/public/cpp/view_manager/view.h"
-#include "mojo/services/window_manager/window_manager_app.h"
-#include "mojo/views/native_widget_view_manager.h"
-#include "ui/views/background.h"
-#include "ui/views/controls/button/label_button.h"
-#include "ui/views/layout/layout_manager.h"
-#include "ui/views/widget/widget.h"
-#include "ui/wm/public/activation_client.h"
-
-class FrameController::LayoutManager : public views::LayoutManager,
- public views::ButtonListener {
- public:
- explicit LayoutManager(FrameController* controller)
- : controller_(controller),
- close_button_(
- new views::LabelButton(this, base::ASCIIToUTF16("Begone"))),
- maximize_button_(
- new views::LabelButton(this, base::ASCIIToUTF16("Embiggen"))) {}
- virtual ~LayoutManager() {}
-
- private:
- static const int kButtonFrameMargin = 5;
- static const int kButtonFrameSpacing = 2;
- static const int kFrameSize = 10;
-
- // Overridden from views::LayoutManager:
- virtual void Installed(views::View* host) override {
- host->AddChildView(close_button_);
- host->AddChildView(maximize_button_);
- }
- virtual void Layout(views::View* host) override {
- gfx::Size ps = close_button_->GetPreferredSize();
- gfx::Rect bounds = host->GetLocalBounds();
- close_button_->SetBounds(bounds.right() - kButtonFrameMargin - ps.width(),
- kButtonFrameMargin, ps.width(), ps.height());
-
- ps = maximize_button_->GetPreferredSize();
- maximize_button_->SetBounds(
- close_button_->x() - kButtonFrameSpacing - ps.width(),
- kButtonFrameMargin, ps.width(), ps.height());
-
- bounds.Inset(kFrameSize,
- close_button_->bounds().bottom() + kButtonFrameMargin,
- kFrameSize, kFrameSize);
- controller_->app_view_->SetBounds(bounds);
- }
- virtual gfx::Size GetPreferredSize(const views::View* host) const override {
- return gfx::Size();
- }
-
- // Overridden from views::ButtonListener:
- virtual void ButtonPressed(views::Button* sender,
- const ui::Event& event) override {
- if (sender == close_button_)
- controller_->CloseWindow();
- else if (sender == maximize_button_)
- controller_->ToggleMaximize();
- }
-
- FrameController* controller_;
- views::Button* close_button_;
- views::Button* maximize_button_;
-
- DISALLOW_COPY_AND_ASSIGN(LayoutManager);
-};
-
-class FrameController::FrameEventHandler : public ui::EventHandler {
- public:
- explicit FrameEventHandler(FrameController* frame_controller)
- : frame_controller_(frame_controller) {}
- virtual ~FrameEventHandler() {}
-
- private:
-
- // Overriden from ui::EventHandler:
- virtual void OnMouseEvent(ui::MouseEvent* event) override {
- if (event->type() == ui::ET_MOUSE_PRESSED)
- frame_controller_->ActivateWindow();
- }
-
- FrameController* frame_controller_;
-
- DISALLOW_COPY_AND_ASSIGN(FrameEventHandler);
-};
-
-////////////////////////////////////////////////////////////////////////////////
-// FrameController, public:
-
-FrameController::FrameController(
- mojo::Shell* shell,
- mojo::View* view,
- mojo::View** app_view,
- aura::client::ActivationClient* activation_client,
- mojo::WindowManagerApp* window_manager_app)
- : view_(view),
- app_view_(mojo::View::Create(view->view_manager())),
- frame_view_(new views::View),
- frame_view_layout_manager_(new LayoutManager(this)),
- widget_(new views::Widget),
- maximized_(false),
- activation_client_(activation_client),
- window_manager_app_(window_manager_app) {
- view_->AddChild(app_view_);
- view_->AddObserver(this);
- *app_view = app_view_;
- frame_view_->set_background(
- views::Background::CreateSolidBackground(SK_ColorBLUE));
- frame_view_->SetLayoutManager(frame_view_layout_manager_);
- frame_event_handler_.reset(new FrameEventHandler(this));
- frame_view_->AddPreTargetHandler(frame_event_handler_.get());
- views::Widget::InitParams params(
- views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
- params.native_widget =
- new mojo::NativeWidgetViewManager(widget_, shell, view_);
- params.bounds = gfx::Rect(view_->bounds().size());
- widget_->Init(params);
- widget_->SetContentsView(frame_view_);
- widget_->Show();
-}
-
-FrameController::~FrameController() {}
-
-void FrameController::CloseWindow() {
- app_view_->Destroy();
- view_->Destroy();
-}
-
-void FrameController::ToggleMaximize() {
- if (!maximized_)
- restored_bounds_ = view_->bounds();
- maximized_ = !maximized_;
- if (maximized_)
- view_->SetBounds(view_->parent()->bounds());
- else
- view_->SetBounds(restored_bounds_);
-}
-
-void FrameController::ActivateWindow() {
- aura::Window* window = window_manager_app_->GetWindowForViewId(view_->id());
- activation_client_->ActivateWindow(window);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// FrameController, mojo::ViewObserver implementation:
-
-void FrameController::OnViewDestroyed(mojo::View* view) {
- view_->RemoveObserver(this);
- delete this;
-}
diff --git a/mojo/examples/wm_flow/wm/frame_controller.h b/mojo/examples/wm_flow/wm/frame_controller.h
deleted file mode 100644
index 0add0a1..0000000
--- a/mojo/examples/wm_flow/wm/frame_controller.h
+++ /dev/null
@@ -1,68 +0,0 @@
-// Copyright 2014 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_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_
-#define MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace aura {
-namespace client {
-class ActivationClient;
-}
-}
-
-namespace mojo {
-class NativeWidgetViewManager;
-class Shell;
-class View;
-class WindowManagerApp;
-}
-
-namespace views {
-class View;
-class Widget;
-}
-
-// FrameController encapsulates the window manager's frame additions to a window
-// created by an application. It renders the content of the frame and responds
-// to any events targeted at it.
-class FrameController : mojo::ViewObserver {
- public:
- FrameController(mojo::Shell* shell,
- mojo::View* view,
- mojo::View** app_view,
- aura::client::ActivationClient* activation_client,
- mojo::WindowManagerApp* window_manager_app);
- virtual ~FrameController();
-
- void CloseWindow();
- void ToggleMaximize();
-
- void ActivateWindow();
-
- private:
- class LayoutManager;
- friend class LayoutManager;
- class FrameEventHandler;
-
- virtual void OnViewDestroyed(mojo::View* view) override;
-
- mojo::View* view_;
- mojo::View* app_view_;
- views::View* frame_view_;
- LayoutManager* frame_view_layout_manager_;
- views::Widget* widget_;
- bool maximized_;
- gfx::Rect restored_bounds_;
- aura::client::ActivationClient* activation_client_;
- mojo::WindowManagerApp* window_manager_app_;
- scoped_ptr<FrameEventHandler> frame_event_handler_;
-
- DISALLOW_COPY_AND_ASSIGN(FrameController);
-};
-
-#endif // MOJO_EXAMPLES_WM_FLOW_WM_FRAME_CONTROLLER_H_
diff --git a/mojo/examples/wm_flow/wm/wm.cc b/mojo/examples/wm_flow/wm/wm.cc
deleted file mode 100644
index 228f04f..0000000
--- a/mojo/examples/wm_flow/wm/wm.cc
+++ /dev/null
@@ -1,208 +0,0 @@
-// Copyright 2014 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 <vector>
-
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/examples/wm_flow/wm/frame_controller.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/services/public/cpp/view_manager/view_manager.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/public/interfaces/input_events/input_events.mojom.h"
-#include "mojo/services/window_manager/window_manager_app.h"
-#include "mojo/services/window_manager/window_manager_delegate.h"
-#include "mojo/views/views_init.h"
-#include "ui/aura/window.h"
-#include "ui/wm/core/focus_rules.h"
-#include "ui/wm/public/activation_client.h"
-
-namespace examples {
-
-namespace {
-
-class WMFocusRules : public wm::FocusRules {
- public:
- WMFocusRules(mojo::WindowManagerApp* window_manager_app,
- mojo::View* window_container)
- : window_container_(window_container),
- window_manager_app_(window_manager_app) {}
- virtual ~WMFocusRules() {}
-
- private:
- // Overridden from wm::FocusRules:
- virtual bool IsToplevelWindow(aura::Window* window) const override {
- return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
- window_container_;
- }
- virtual bool CanActivateWindow(aura::Window* window) const override {
- return mojo::WindowManagerApp::GetViewForWindow(window)->parent() ==
- window_container_;
- }
- virtual bool CanFocusWindow(aura::Window* window) const override {
- return true;
- }
- virtual aura::Window* GetToplevelWindow(aura::Window* window) const override {
- mojo::View* view = mojo::WindowManagerApp::GetViewForWindow(window);
- while (view->parent() != window_container_) {
- view = view->parent();
- // Unparented hierarchy, there is no "top level" window.
- if (!view)
- return NULL;
- }
-
- return window_manager_app_->GetWindowForViewId(view->id());
- }
- virtual aura::Window* GetActivatableWindow(
- aura::Window* window) const override {
- return GetToplevelWindow(window);
- }
- virtual aura::Window* GetFocusableWindow(
- aura::Window* window) const override {
- return window;
- }
- virtual aura::Window* GetNextActivatableWindow(
- aura::Window* ignore) const override {
- aura::Window* activatable = GetActivatableWindow(ignore);
- const aura::Window::Windows& children = activatable->parent()->children();
- for (aura::Window::Windows::const_reverse_iterator it = children.rbegin();
- it != children.rend(); ++it) {
- if (*it != ignore)
- return *it;
- }
- return NULL;
- }
-
- mojo::View* window_container_;
- mojo::WindowManagerApp* window_manager_app_;
-
- DISALLOW_COPY_AND_ASSIGN(WMFocusRules);
-};
-
-} // namespace
-
-class SimpleWM : public mojo::ApplicationDelegate,
- public mojo::ViewManagerDelegate,
- public mojo::WindowManagerDelegate,
- public mojo::ViewObserver {
- public:
- SimpleWM()
- : shell_(nullptr),
- window_manager_app_(new mojo::WindowManagerApp(this, this)),
- view_manager_(NULL),
- root_(NULL),
- window_container_(NULL),
- next_window_origin_(10, 10) {}
- virtual ~SimpleWM() {}
-
- private:
- // Overridden from mojo::ApplicationDelegate:
- virtual void Initialize(mojo::ApplicationImpl* impl) override {
- // Create views_init here as we need ApplicationRunnerChromium to install
- // an AtExitManager and CommandLine.
- if (!views_init_.get())
- views_init_.reset(new mojo::ViewsInit);
- shell_ = impl->shell();
- window_manager_app_->Initialize(impl);
- }
- virtual bool ConfigureIncomingConnection(
- mojo::ApplicationConnection* connection) override {
- window_manager_app_->ConfigureIncomingConnection(connection);
- return true;
- }
-
- // Overridden from mojo::ViewManagerDelegate:
- virtual void OnEmbed(
- mojo::ViewManager* view_manager,
- mojo::View* root,
- mojo::ServiceProviderImpl* exported_services,
- scoped_ptr<mojo::ServiceProvider> remote_service_provider) override {
- view_manager_ = view_manager;
- root_ = root;
-
- window_container_ = mojo::View::Create(view_manager_);
- window_container_->SetBounds(root_->bounds());
- root_->AddChild(window_container_);
-
- window_manager_app_->InitFocus(new WMFocusRules(window_manager_app_.get(),
- window_container_));
- }
- virtual void OnViewManagerDisconnected(
- mojo::ViewManager* view_manager) override {
- view_manager_ = NULL;
- root_ = NULL;
- }
-
- // Overridden from mojo::WindowManagerDelegate:
- virtual void Embed(
- const mojo::String& url,
- mojo::InterfaceRequest<mojo::ServiceProvider> service_provider) override {
- mojo::View* app_view = NULL;
- mojo::View* frame_view = CreateTopLevelWindow(&app_view);
- window_container_->AddChild(frame_view);
-
- // TODO(beng): We're dropping the |service_provider| passed from the client
- // on the floor here and passing our own. Seems like we should
- // be sending both. I'm not yet sure how this sould work for
- // N levels of proxying.
- app_view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
- new mojo::ServiceProviderImpl).Pass());
- }
-
- // Overridden from mojo::ViewObserver:
- virtual void OnViewInputEvent(mojo::View* view,
- const mojo::EventPtr& event) override {
- if (event->action == mojo::EVENT_TYPE_MOUSE_RELEASED &&
- event->flags & mojo::EVENT_FLAGS_RIGHT_MOUSE_BUTTON &&
- view->parent() == window_container_) {
- CloseWindow(view);
- }
- }
- virtual void OnViewDestroyed(mojo::View* view) override {
- view->RemoveObserver(this);
- }
-
- void CloseWindow(mojo::View* view) {
- mojo::View* first_child = view->children().front();
- first_child->Destroy();
- view->Destroy();
- next_window_origin_.Offset(-50, -50);
- }
-
- mojo::View* CreateTopLevelWindow(mojo::View** app_view) {
- mojo::View* frame_view = mojo::View::Create(view_manager_);
- frame_view->SetBounds(gfx::Rect(next_window_origin_, gfx::Size(400, 400)));
- next_window_origin_.Offset(50, 50);
-
- aura::client::ActivationClient* client = aura::client::GetActivationClient(
- window_manager_app_->host()->window());
- new FrameController(
- shell_, frame_view, app_view, client, window_manager_app_.get());
- return frame_view;
- }
-
- mojo::Shell* shell_;
-
- scoped_ptr<mojo::ViewsInit> views_init_;
-
- scoped_ptr<mojo::WindowManagerApp> window_manager_app_;
-
- mojo::ViewManager* view_manager_;
- mojo::View* root_;
- mojo::View* window_container_;
-
- gfx::Point next_window_origin_;
-
- DISALLOW_COPY_AND_ASSIGN(SimpleWM);
-};
-
-} // namespace examples
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new examples::SimpleWM);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/mojo.gyp b/mojo/mojo.gyp
index fddb016..447afec 100644
--- a/mojo/mojo.gyp
+++ b/mojo/mojo.gyp
@@ -53,14 +53,6 @@
'public/mojo_public.gyp:mojo_public',
],
'conditions': [
- ['use_aura==1', {
- 'dependencies': [
- 'mojo_core_window_manager',
- 'mojo_core_window_manager_unittests',
- 'mojo_view_manager',
- 'mojo_view_manager_unittests',
- ],
- }],
['OS == "linux"', {
'dependencies': [
'mojo_external_application_tests',
diff --git a/mojo/mojo_services.gypi b/mojo/mojo_services.gypi
index 0a9b7e0..51e2eea55 100644
--- a/mojo/mojo_services.gypi
+++ b/mojo/mojo_services.gypi
@@ -507,194 +507,4 @@
],
},
],
- 'conditions': [
- ['use_aura==1', {
- 'targets': [
- {
- # GN version: //mojo/services/view_manager
- 'target_name': 'mojo_view_manager',
- 'type': 'loadable_module',
- 'dependencies': [
- '../base/base.gyp:base',
- '../cc/cc.gyp:cc_surfaces',
- '../skia/skia.gyp:skia',
- '../ui/base/ui_base.gyp:ui_base',
- '../ui/events/events.gyp:events',
- '../ui/events/events.gyp:events_base',
- '../ui/gfx/gfx.gyp:gfx',
- '../ui/gfx/gfx.gyp:gfx_geometry',
- 'mojo_base.gyp:mojo_application_chromium',
- 'mojo_base.gyp:mojo_common_lib',
- 'mojo_geometry_lib',
- 'mojo_input_events_lib',
- 'mojo_surfaces_lib',
- 'services/public/mojo_services_public.gyp:mojo_geometry_bindings',
- 'services/public/mojo_services_public.gyp:mojo_gpu_bindings',
- 'services/public/mojo_services_public.gyp:mojo_input_events_bindings',
- 'services/public/mojo_services_public.gyp:mojo_native_viewport_bindings',
- 'services/public/mojo_services_public.gyp:mojo_surfaces_bindings',
- 'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
- 'services/public/mojo_services_public.gyp:mojo_view_manager_common',
- 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
- '<(mojo_system_for_loadable_module)',
- ],
- 'sources': [
- 'services/view_manager/access_policy.h',
- 'services/view_manager/access_policy_delegate.h',
- 'services/view_manager/connection_manager.cc',
- 'services/view_manager/connection_manager.h',
- 'services/view_manager/default_access_policy.cc',
- 'services/view_manager/default_access_policy.h',
- 'services/view_manager/display_manager.cc',
- 'services/view_manager/display_manager.h',
- 'services/view_manager/ids.h',
- 'services/view_manager/main.cc',
- 'services/view_manager/server_view.cc',
- 'services/view_manager/server_view.h',
- 'services/view_manager/server_view_delegate.h',
- 'services/view_manager/view_manager_export.h',
- 'services/view_manager/view_manager_init_service_context.cc',
- 'services/view_manager/view_manager_init_service_context.h',
- 'services/view_manager/view_manager_init_service_impl.cc',
- 'services/view_manager/view_manager_init_service_impl.h',
- 'services/view_manager/view_manager_service_impl.cc',
- 'services/view_manager/view_manager_service_impl.h',
- 'services/view_manager/window_manager_access_policy.cc',
- 'services/view_manager/window_manager_access_policy.h',
- 'services/view_manager/window_manager_client_impl.cc',
- 'services/view_manager/window_manager_client_impl.h',
- ],
- 'includes': [
- 'mojo_public_gles2_for_loadable_module.gypi',
- ],
- 'defines': [
- 'MOJO_VIEW_MANAGER_IMPLEMENTATION',
- ],
- },
- {
- # GN version: //mojo/services/view_manager:mojo_view_manager_unittests
- 'target_name': 'mojo_view_manager_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../base/base.gyp:base',
- '../base/base.gyp:test_support_base',
- '../skia/skia.gyp:skia',
- '../testing/gtest.gyp:gtest',
- '../ui/aura/aura.gyp:aura',
- '../ui/gfx/gfx.gyp:gfx_geometry',
- 'edk/mojo_edk.gyp:mojo_system_impl',
- 'mojo_application_manager',
- 'mojo_base.gyp:mojo_application_chromium',
- 'mojo_geometry_lib',
- 'mojo_input_events_lib',
- 'mojo_native_viewport_service_args',
- 'mojo_shell_test_support',
- 'mojo_view_manager_run_unittests',
- 'services/public/mojo_services_public.gyp:mojo_geometry_bindings',
- 'services/public/mojo_services_public.gyp:mojo_input_events_bindings',
- 'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
- 'services/public/mojo_services_public.gyp:mojo_view_manager_common',
- 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
- # Included only to force deps for bots.
- 'mojo_native_viewport_service',
- 'mojo_surfaces_service',
- 'mojo_view_manager',
- ],
- 'sources': [
- 'services/view_manager/test_change_tracker.cc',
- 'services/view_manager/test_change_tracker.h',
- 'services/view_manager/view_manager_unittest.cc',
- ],
- 'conditions': [
- ['OS=="win"', {
- 'dependencies': [
- '../ui/gfx/gfx.gyp:gfx',
- ],
- }],
- ],
- },
- {
- 'target_name': 'package_mojo_view_manager',
- 'variables': {
- 'app_name': 'mojo_view_manager',
- },
- 'includes': [ 'build/package_app.gypi' ],
- },
- {
- # GN version: //mojo/services/window_manager:lib
- 'target_name': 'mojo_core_window_manager_lib',
- 'type': 'static_library',
- 'dependencies': [
- '../base/base.gyp:base',
- '../ui/base/ui_base.gyp:ui_base',
- '../ui/gfx/gfx.gyp:gfx',
- '../ui/gfx/gfx.gyp:gfx_geometry',
- '../ui/wm/wm.gyp:wm',
- 'mojo_aura_support',
- 'mojo_base.gyp:mojo_application_chromium',
- 'mojo_base.gyp:mojo_common_lib',
- 'mojo_input_events_lib',
- 'mojo_view_manager_lib',
- 'public/mojo_public.gyp:mojo_application_bindings',
- 'services/public/mojo_services_public.gyp:mojo_core_window_manager_bindings',
- 'services/public/mojo_services_public.gyp:mojo_window_manager_bindings',
- ],
- 'sources': [
- 'services/window_manager/window_manager_app.cc',
- 'services/window_manager/window_manager_app.h',
- 'services/window_manager/window_manager_delegate.h',
- 'services/window_manager/window_manager_service_impl.cc',
- 'services/window_manager/window_manager_service_impl.h',
- 'services/window_manager/window_manager_service2_impl.cc',
- 'services/window_manager/window_manager_service2_impl.h',
- ],
- },
- {
- # GN version: //mojo/services/window_manager
- 'target_name': 'mojo_core_window_manager',
- 'type': 'loadable_module',
- 'dependencies': [
- 'mojo_core_window_manager_lib',
- '<(mojo_system_for_loadable_module)',
- ],
- 'sources': [
- 'services/window_manager/main.cc',
- ],
- },
- {
- # GN version: //mojo/services/window_manager:mojo_core_window_manager_unittests
- 'target_name': 'mojo_core_window_manager_unittests',
- 'type': 'executable',
- 'dependencies': [
- '../base/base.gyp:test_support_base',
- '../testing/gtest.gyp:gtest',
- 'edk/mojo_edk.gyp:mojo_system_impl',
- 'mojo_application_manager',
- 'mojo_base.gyp:mojo_environment_chromium',
- 'services/public/mojo_services_public.gyp:mojo_core_window_manager_bindings',
- 'mojo_shell_test_support',
- 'services/public/mojo_services_public.gyp:mojo_view_manager_bindings',
- 'mojo_view_manager_lib',
- ],
- 'sources': [
- 'services/window_manager/window_manager_api_unittest.cc',
- 'services/window_manager/window_manager_unittests.cc',
- ],
- 'conditions': [
- ['OS=="linux"', {
- 'dependencies': [
- '../third_party/mesa/mesa.gyp:osmesa',
- 'mojo_native_viewport_service_lib',
- ],
- }],
- ['use_x11==1', {
- 'dependencies': [
- '../ui/gfx/x/gfx_x11.gyp:gfx_x11',
- ],
- }],
- ],
- },
- ],
- }],
- ],
}
diff --git a/mojo/services/BUILD.gn b/mojo/services/BUILD.gn
index fdddd3d..f4809fd 100644
--- a/mojo/services/BUILD.gn
+++ b/mojo/services/BUILD.gn
@@ -20,16 +20,10 @@ group("services") {
"//mojo/services/public/interfaces/surfaces",
"//mojo/services/surfaces",
"//mojo/services/test_service:bindings",
+ "//mojo/services/public/interfaces/view_manager",
+ "//mojo/services/public/interfaces/window_manager2",
]
if (!is_android) {
deps += ["//mojo/services/native_viewport"]
}
- if (use_aura) {
- deps += [
- "//mojo/services/public/interfaces/view_manager",
- "//mojo/services/public/interfaces/window_manager2",
- "//mojo/services/view_manager",
- "//mojo/services/window_manager",
- ]
- }
}
diff --git a/mojo/services/view_manager/BUILD.gn b/mojo/services/view_manager/BUILD.gn
deleted file mode 100644
index a870c3f..0000000
--- a/mojo/services/view_manager/BUILD.gn
+++ /dev/null
@@ -1,102 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-
-# GYP version: mojo/mojo_services.gypi:mojo_view_manager
-shared_library("view_manager") {
- output_name = "mojo_view_manager"
-
- deps = [
- "//base",
- "//cc/surfaces",
- "//mojo/application",
- "//mojo/common",
- "//mojo/converters/geometry",
- "//mojo/converters/input_events",
- "//mojo/converters/surfaces",
- "//mojo/environment:chromium",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/public/cpp/bindings",
- "//mojo/public/interfaces/application",
- "//mojo/services/public/interfaces/geometry",
- "//mojo/services/public/interfaces/input_events",
- "//mojo/services/public/interfaces/native_viewport",
- "//mojo/services/public/interfaces/surfaces",
- "//mojo/services/public/interfaces/view_manager",
- "//mojo/services/public/interfaces/window_manager",
- "//ui/base",
- "//ui/events",
- "//ui/events:events_base",
- "//ui/gfx",
- "//ui/gfx/geometry",
- ]
-
- defines = [
- "MOJO_VIEW_MANAGER_IMPLEMENTATION",
- ]
-
- sources = [
- "access_policy.h",
- "access_policy_delegate.h",
- "connection_manager.cc",
- "connection_manager.h",
- "default_access_policy.cc",
- "default_access_policy.h",
- "display_manager.cc",
- "display_manager.h",
- "main.cc",
- "server_view.cc",
- "server_view.h",
- "server_view_delegate.h",
- "view_manager_export.h",
- "view_manager_init_service_context.cc",
- "view_manager_init_service_context.h",
- "view_manager_init_service_impl.cc",
- "view_manager_init_service_impl.h",
- "view_manager_service_impl.cc",
- "view_manager_service_impl.h",
- "window_manager_access_policy.cc",
- "window_manager_access_policy.h",
- "window_manager_client_impl.cc",
- "window_manager_client_impl.h",
- ]
-}
-
-# GYP version: mojo/mojo_services.gypi:mojo_view_manager_unittests
-test("mojo_view_manager_unittests") {
- deps = [
- "//base",
- "//base/test:test_support",
- "//mojo/application",
- "//mojo/application_manager",
- "//mojo/converters/geometry",
- "//mojo/converters/input_events",
- "//mojo/edk/system",
- "//mojo/environment:chromium",
- "//mojo/public/cpp/bindings",
- "//mojo/services/public/cpp/native_viewport:args",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/cpp/view_manager/lib:run_unittests",
- "//mojo/services/public/interfaces/view_manager",
- "//mojo/services/public/interfaces/window_manager",
- "//mojo/shell:test_support",
- "//testing/gtest",
- "//ui/gfx/geometry",
- ]
-
- if (use_x11) {
- deps += ["//ui/gfx/x"]
- }
-
- if (is_component_build) {
- deps += ["//ui/gl"]
- }
-
- sources = [
- "test_change_tracker.cc",
- "test_change_tracker.h",
- "view_manager_unittest.cc",
- ]
-}
diff --git a/mojo/services/view_manager/DEPS b/mojo/services/view_manager/DEPS
deleted file mode 100644
index b9172b5..0000000
--- a/mojo/services/view_manager/DEPS
+++ /dev/null
@@ -1,26 +0,0 @@
-include_rules = [
- "+cc",
- "-cc/blink",
- "+gpu/command_buffer/service/mailbox_manager.h",
- "+mojo/application",
- "+mojo/cc",
- "+mojo/converters/geometry",
- "+mojo/converters/input_events",
- "+mojo/converters/surfaces",
- "+mojo/geometry",
- "+mojo/services",
- "+third_party/skia",
- "+ui/base/cursor/cursor.h",
- "+ui/base/hit_test.h",
- "+ui/compositor",
- "+ui/events",
- "+ui/gfx",
- "+ui/gl",
- "+webkit/common/gpu",
-]
-
-specific_include_rules = {
- "view_manager_unittest.cc": [
- "+mojo/application_manager/application_manager.h",
- ],
-}
diff --git a/mojo/services/view_manager/access_policy.h b/mojo/services/view_manager/access_policy.h
deleted file mode 100644
index cac5579..0000000
--- a/mojo/services/view_manager/access_policy.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_ACCESS_POLICY_H_
-#define MOJO_SERVICES_VIEW_MANAGER_ACCESS_POLICY_H_
-
-#include "mojo/services/public/interfaces/view_manager/view_manager_constants.mojom.h"
-#include "mojo/services/view_manager/ids.h"
-
-namespace mojo {
-namespace service {
-
-class ServerView;
-
-// AccessPolicy is used by ViewManagerServiceImpl to determine what a connection
-// is allowed to do.
-class AccessPolicy {
- public:
- virtual ~AccessPolicy() {}
-
- // Unless otherwise mentioned all arguments have been validated. That is the
- // |view| arguments are non-null unless otherwise stated (eg CanSetView() is
- // allowed to take a NULL view).
- virtual bool CanRemoveViewFromParent(const ServerView* view) const = 0;
- virtual bool CanAddView(const ServerView* parent,
- const ServerView* child) const = 0;
- virtual bool CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const = 0;
- virtual bool CanDeleteView(const ServerView* view) const = 0;
- virtual bool CanGetViewTree(const ServerView* view) const = 0;
- // Used when building a view tree (GetViewTree()) to decide if we should
- // descend into |view|.
- virtual bool CanDescendIntoViewForViewTree(const ServerView* view) const = 0;
- virtual bool CanEmbed(const ServerView* view) const = 0;
- virtual bool CanChangeViewVisibility(const ServerView* view) const = 0;
- virtual bool CanSetViewSurfaceId(const ServerView* view) const = 0;
- virtual bool CanSetViewBounds(const ServerView* view) const = 0;
-
- // Returns whether the connection should notify on a hierarchy change.
- // |new_parent| and |old_parent| are initially set to the new and old parents
- // but may be altered so that the client only sees a certain set of views.
- virtual bool ShouldNotifyOnHierarchyChange(
- const ServerView* view,
- const ServerView** new_parent,
- const ServerView** old_parent) const = 0;
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_ACCESS_POLICY_H_
diff --git a/mojo/services/view_manager/access_policy_delegate.h b/mojo/services/view_manager/access_policy_delegate.h
deleted file mode 100644
index 12c7479..0000000
--- a/mojo/services/view_manager/access_policy_delegate.h
+++ /dev/null
@@ -1,39 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_ACCESS_POLICY_DELEGATE_H_
-#define MOJO_SERVICES_VIEW_MANAGER_ACCESS_POLICY_DELEGATE_H_
-
-#include <vector>
-
-#include "base/containers/hash_tables.h"
-#include "mojo/services/view_manager/ids.h"
-
-namespace mojo {
-namespace service {
-
-class ServerView;
-
-// Delegate used by the AccessPolicy implementations to get state.
-class AccessPolicyDelegate {
- public:
- // Returns the ids of the roots views for this connection. That is, this is
- // the set of views the connection was embedded at.
- virtual const base::hash_set<Id>& GetRootsForAccessPolicy() const = 0;
-
- // Returns true if |view| has been exposed to the client.
- virtual bool IsViewKnownForAccessPolicy(const ServerView* view) const = 0;
-
- // Returns true if Embed(view) has been invoked on |view|.
- virtual bool IsViewRootOfAnotherConnectionForAccessPolicy(
- const ServerView* view) const = 0;
-
- protected:
- virtual ~AccessPolicyDelegate() {}
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_ACCESS_POLICY_DELEGATE_H_
diff --git a/mojo/services/view_manager/connection_manager.cc b/mojo/services/view_manager/connection_manager.cc
deleted file mode 100644
index d610392..0000000
--- a/mojo/services/view_manager/connection_manager.cc
+++ /dev/null
@@ -1,301 +0,0 @@
-// Copyright 2014 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/view_manager/connection_manager.h"
-
-#include "base/logging.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-#include "mojo/services/view_manager/view_manager_service_impl.h"
-
-namespace mojo {
-namespace service {
-
-ConnectionManager::ScopedChange::ScopedChange(
- ViewManagerServiceImpl* connection,
- ConnectionManager* connection_manager,
- bool is_delete_view)
- : connection_manager_(connection_manager),
- connection_id_(connection->id()),
- is_delete_view_(is_delete_view) {
- connection_manager_->PrepareForChange(this);
-}
-
-ConnectionManager::ScopedChange::~ScopedChange() {
- connection_manager_->FinishChange();
-}
-
-ConnectionManager::ConnectionManager(
- ApplicationConnection* app_connection,
- const Callback<void()>& native_viewport_closed_callback)
- : app_connection_(app_connection),
- wm_client_impl_(this),
- next_connection_id_(1),
- display_manager_(app_connection, this, native_viewport_closed_callback),
- root_(new ServerView(this, RootViewId())),
- current_change_(NULL) {
- root_->SetBounds(gfx::Rect(800, 600));
-}
-
-ConnectionManager::~ConnectionManager() {
- while (!connections_created_by_connect_.empty())
- delete *(connections_created_by_connect_.begin());
- // All the connections should have been destroyed.
- DCHECK(connection_map_.empty());
- root_.reset();
-}
-
-ConnectionSpecificId ConnectionManager::GetAndAdvanceNextConnectionId() {
- const ConnectionSpecificId id = next_connection_id_++;
- DCHECK_LT(id, next_connection_id_);
- return id;
-}
-
-void ConnectionManager::AddConnection(ViewManagerServiceImpl* connection) {
- DCHECK_EQ(0u, connection_map_.count(connection->id()));
- connection_map_[connection->id()] = connection;
-}
-
-void ConnectionManager::RemoveConnection(ViewManagerServiceImpl* connection) {
- connection_map_.erase(connection->id());
- connections_created_by_connect_.erase(connection);
-
- // Notify remaining connections so that they can cleanup.
- for (ConnectionMap::const_iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->OnViewManagerServiceImplDestroyed(connection->id());
- }
-}
-
-void ConnectionManager::Embed(
- const std::string& url,
- InterfaceRequest<ServiceProvider> service_provider) {
- if (connection_map_.empty()) {
- // TODO(sky): this is unsafe and racy. Need a better way to determine the
- // window manager.
- EmbedImpl(kInvalidConnectionId,
- String::From(url),
- RootViewId(),
- service_provider.Pass());
- return;
- }
- wm_client_impl_.client()->Embed(url, service_provider.Pass());
-}
-
-void ConnectionManager::EmbedAtView(
- ConnectionSpecificId creator_id,
- const String& url,
- Id transport_view_id,
- InterfaceRequest<ServiceProvider> service_provider) {
- EmbedImpl(creator_id,
- url,
- ViewIdFromTransportId(transport_view_id),
- service_provider.Pass())->set_delete_on_connection_error();
-}
-
-ViewManagerServiceImpl* ConnectionManager::GetConnection(
- ConnectionSpecificId connection_id) {
- ConnectionMap::iterator i = connection_map_.find(connection_id);
- return i == connection_map_.end() ? NULL : i->second;
-}
-
-ServerView* ConnectionManager::GetView(const ViewId& id) {
- if (id == root_->id())
- return root_.get();
- ConnectionMap::iterator i = connection_map_.find(id.connection_id);
- return i == connection_map_.end() ? NULL : i->second->GetView(id);
-}
-
-void ConnectionManager::OnConnectionMessagedClient(ConnectionSpecificId id) {
- if (current_change_)
- current_change_->MarkConnectionAsMessaged(id);
-}
-
-bool ConnectionManager::DidConnectionMessageClient(
- ConnectionSpecificId id) const {
- return current_change_ && current_change_->DidMessageConnection(id);
-}
-
-const ViewManagerServiceImpl* ConnectionManager::GetConnectionWithRoot(
- const ViewId& id) const {
- for (ConnectionMap::const_iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- if (i->second->HasRoot(id))
- return i->second;
- }
- return NULL;
-}
-
-void ConnectionManager::DispatchViewInputEventToDelegate(EventPtr event) {
- if (wm_client_impl_.client())
- wm_client_impl_.client()->OnViewInputEvent(event.Pass());
-}
-
-void ConnectionManager::ProcessViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessViewBoundsChanged(
- view, old_bounds, new_bounds, IsChangeSource(i->first));
- }
-}
-
-void ConnectionManager::ProcessWillChangeViewHierarchy(
- const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessWillChangeViewHierarchy(
- view, new_parent, old_parent, IsChangeSource(i->first));
- }
-}
-
-void ConnectionManager::ProcessViewHierarchyChanged(
- const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessViewHierarchyChanged(
- view, new_parent, old_parent, IsChangeSource(i->first));
- }
-}
-
-void ConnectionManager::ProcessViewReorder(const ServerView* view,
- const ServerView* relative_view,
- const OrderDirection direction) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessViewReorder(
- view, relative_view, direction, IsChangeSource(i->first));
- }
-}
-
-void ConnectionManager::ProcessViewDeleted(const ViewId& view) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessViewDeleted(view, IsChangeSource(i->first));
- }
-}
-
-void ConnectionManager::PrepareForChange(ScopedChange* change) {
- // Should only ever have one change in flight.
- CHECK(!current_change_);
- current_change_ = change;
-}
-
-void ConnectionManager::FinishChange() {
- // PrepareForChange/FinishChange should be balanced.
- CHECK(current_change_);
- current_change_ = NULL;
-}
-
-ViewManagerServiceImpl* ConnectionManager::EmbedImpl(
- const ConnectionSpecificId creator_id,
- const String& url,
- const ViewId& root_id,
- InterfaceRequest<ServiceProvider> service_provider) {
- MessagePipe pipe;
-
- ServiceProvider* view_manager_service_provider =
- app_connection_->ConnectToApplication(url)->GetServiceProvider();
-
- view_manager_service_provider->ConnectToService(
- ViewManagerServiceImpl::Client::Name_, pipe.handle1.Pass());
-
- if (root_id == RootViewId()) {
- MessagePipe wm_pipe;
- view_manager_service_provider->ConnectToService(
- WindowManagerClientImpl::Client::Name_, wm_pipe.handle1.Pass());
- WeakBindToPipe(&wm_client_impl_, wm_pipe.handle0.Pass());
- }
-
- std::string creator_url;
- ConnectionMap::const_iterator it = connection_map_.find(creator_id);
- if (it != connection_map_.end())
- creator_url = it->second->url();
-
- ViewManagerServiceImpl* connection =
- new ViewManagerServiceImpl(this,
- creator_id,
- creator_url,
- url.To<std::string>(),
- root_id,
- service_provider.Pass());
- WeakBindToPipe(connection, pipe.handle0.Pass());
- connections_created_by_connect_.insert(connection);
- OnConnectionMessagedClient(connection->id());
- return connection;
-}
-
-void ConnectionManager::OnViewDestroyed(const ServerView* view) {
- ProcessViewDeleted(view->id());
-}
-
-void ConnectionManager::OnWillChangeViewHierarchy(
- const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) {
- if (!display_manager_.in_setup())
- ProcessWillChangeViewHierarchy(view, new_parent, old_parent);
-}
-
-void ConnectionManager::OnViewHierarchyChanged(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) {
- if (!display_manager_.in_setup())
- ProcessViewHierarchyChanged(view, new_parent, old_parent);
- // TODO(beng): optimize.
- if (old_parent) {
- display_manager_.SchedulePaint(old_parent,
- gfx::Rect(old_parent->bounds().size()));
- }
- if (new_parent) {
- display_manager_.SchedulePaint(new_parent,
- gfx::Rect(new_parent->bounds().size()));
- }
-}
-
-void ConnectionManager::OnViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- ProcessViewBoundsChanged(view, old_bounds, new_bounds);
- if (!view->parent())
- return;
-
- // TODO(sky): optimize this.
- display_manager_.SchedulePaint(view->parent(), old_bounds);
- display_manager_.SchedulePaint(view->parent(), new_bounds);
-}
-
-void ConnectionManager::OnViewSurfaceIdChanged(const ServerView* view) {
- display_manager_.SchedulePaint(view, gfx::Rect(view->bounds().size()));
-}
-
-void ConnectionManager::OnViewReordered(const ServerView* view,
- const ServerView* relative,
- OrderDirection direction) {
- display_manager_.SchedulePaint(view, gfx::Rect(view->bounds().size()));
-}
-
-void ConnectionManager::OnWillChangeViewVisibility(const ServerView* view) {
- for (ConnectionMap::iterator i = connection_map_.begin();
- i != connection_map_.end();
- ++i) {
- i->second->ProcessWillChangeViewVisibility(view, IsChangeSource(i->first));
- }
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/connection_manager.h b/mojo/services/view_manager/connection_manager.h
deleted file mode 100644
index 618460f..0000000
--- a/mojo/services/view_manager/connection_manager.h
+++ /dev/null
@@ -1,211 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_CONNECTION_MANAGER_H_
-#define MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
-
-#include <map>
-#include <set>
-
-#include "base/basictypes.h"
-#include "mojo/public/cpp/bindings/array.h"
-#include "mojo/services/view_manager/display_manager.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/server_view.h"
-#include "mojo/services/view_manager/server_view_delegate.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-#include "mojo/services/view_manager/window_manager_client_impl.h"
-
-namespace ui {
-class Event;
-}
-
-namespace mojo {
-
-class ApplicationConnection;
-
-namespace service {
-
-class ViewManagerServiceImpl;
-
-// ConnectionManager manages the set of connections to the ViewManager (all the
-// ViewManagerServiceImpls) as well as providing the root of the hierarchy.
-class MOJO_VIEW_MANAGER_EXPORT ConnectionManager : public ServerViewDelegate {
- public:
- // Create when a ViewManagerServiceImpl is about to make a change. Ensures
- // clients are notified correctly.
- class ScopedChange {
- public:
- ScopedChange(ViewManagerServiceImpl* connection,
- ConnectionManager* connection_manager,
- bool is_delete_view);
- ~ScopedChange();
-
- ConnectionSpecificId connection_id() const { return connection_id_; }
- bool is_delete_view() const { return is_delete_view_; }
-
- // Marks the connection with the specified id as having seen a message.
- void MarkConnectionAsMessaged(ConnectionSpecificId connection_id) {
- message_ids_.insert(connection_id);
- }
-
- // Returns true if MarkConnectionAsMessaged(connection_id) was invoked.
- bool DidMessageConnection(ConnectionSpecificId connection_id) const {
- return message_ids_.count(connection_id) > 0;
- }
-
- private:
- ConnectionManager* connection_manager_;
- const ConnectionSpecificId connection_id_;
- const bool is_delete_view_;
-
- // See description of MarkConnectionAsMessaged/DidMessageConnection.
- std::set<ConnectionSpecificId> message_ids_;
-
- DISALLOW_COPY_AND_ASSIGN(ScopedChange);
- };
-
- ConnectionManager(ApplicationConnection* app_connection,
- const Callback<void()>& native_viewport_closed_callback);
- ~ConnectionManager() override;
-
- // Returns the id for the next ViewManagerServiceImpl.
- ConnectionSpecificId GetAndAdvanceNextConnectionId();
-
- void AddConnection(ViewManagerServiceImpl* connection);
- void RemoveConnection(ViewManagerServiceImpl* connection);
-
- // Used in two cases:
- // . Establishes the client for the root.
- // . Requests to Embed() at an unspecified view. For this case the request
- // is passed on to the WindowManagerService.
- void Embed(const std::string& url,
- InterfaceRequest<ServiceProvider> service_provider);
-
- // See description of ViewManagerService::Embed() for details. This assumes
- // |transport_view_id| is valid.
- void EmbedAtView(ConnectionSpecificId creator_id,
- const String& url,
- Id transport_view_id,
- InterfaceRequest<ServiceProvider> service_provider);
-
- // Returns the connection by id.
- ViewManagerServiceImpl* GetConnection(ConnectionSpecificId connection_id);
-
- // Returns the View identified by |id|.
- ServerView* GetView(const ViewId& id);
-
- ServerView* root() { return root_.get(); }
-
- bool IsProcessingChange() const { return current_change_ != NULL; }
-
- bool is_processing_delete_view() const {
- return current_change_ && current_change_->is_delete_view();
- }
-
- // Invoked when a connection messages a client about the change. This is used
- // to avoid sending ServerChangeIdAdvanced() unnecessarily.
- void OnConnectionMessagedClient(ConnectionSpecificId id);
-
- // Returns true if OnConnectionMessagedClient() was invoked for id.
- bool DidConnectionMessageClient(ConnectionSpecificId id) const;
-
- // Returns the ViewManagerServiceImpl that has |id| as a root.
- ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) {
- return const_cast<ViewManagerServiceImpl*>(
- const_cast<const ConnectionManager*>(this)->GetConnectionWithRoot(id));
- }
- const ViewManagerServiceImpl* GetConnectionWithRoot(const ViewId& id) const;
-
- void DispatchViewInputEventToDelegate(EventPtr event);
-
- // These functions trivially delegate to all ViewManagerServiceImpls, which in
- // term notify their clients.
- void ProcessViewDestroyed(ServerView* view);
- void ProcessViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds);
- void ProcessWillChangeViewHierarchy(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent);
- void ProcessViewHierarchyChanged(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent);
- void ProcessViewReorder(const ServerView* view,
- const ServerView* relative_view,
- const OrderDirection direction);
- void ProcessViewDeleted(const ViewId& view);
-
- private:
- typedef std::map<ConnectionSpecificId, ViewManagerServiceImpl*> ConnectionMap;
-
- // Invoked when a connection is about to make a change. Subsequently followed
- // by FinishChange() once the change is done.
- //
- // Changes should never nest, meaning each PrepareForChange() must be
- // balanced with a call to FinishChange() with no PrepareForChange()
- // in between.
- void PrepareForChange(ScopedChange* change);
-
- // Balances a call to PrepareForChange().
- void FinishChange();
-
- // Returns true if the specified connection originated the current change.
- bool IsChangeSource(ConnectionSpecificId connection_id) const {
- return current_change_ && current_change_->connection_id() == connection_id;
- }
-
- // Implementation of the two embed variants.
- ViewManagerServiceImpl* EmbedImpl(
- ConnectionSpecificId creator_id,
- const String& url,
- const ViewId& root_id,
- InterfaceRequest<ServiceProvider> service_provider);
-
- // Overridden from ServerViewDelegate:
- void OnViewDestroyed(const ServerView* view) override;
- void OnWillChangeViewHierarchy(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) override;
- void OnViewHierarchyChanged(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) override;
- void OnViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
- void OnViewSurfaceIdChanged(const ServerView* view) override;
- void OnViewReordered(const ServerView* view,
- const ServerView* relative,
- OrderDirection direction) override;
- void OnWillChangeViewVisibility(const ServerView* view) override;
-
- ApplicationConnection* app_connection_;
-
- WindowManagerClientImpl wm_client_impl_;
-
- // ID to use for next ViewManagerServiceImpl.
- ConnectionSpecificId next_connection_id_;
-
- // Set of ViewManagerServiceImpls.
- ConnectionMap connection_map_;
-
- DisplayManager display_manager_;
-
- scoped_ptr<ServerView> root_;
-
- // Set of ViewManagerServiceImpls created by way of Connect(). These have to
- // be explicitly destroyed.
- std::set<ViewManagerServiceImpl*> connections_created_by_connect_;
-
- // If non-null we're processing a change. The ScopedChange is not owned by us
- // (it's created on the stack by ViewManagerServiceImpl).
- ScopedChange* current_change_;
-
- DISALLOW_COPY_AND_ASSIGN(ConnectionManager);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_CONNECTION_MANAGER_H_
diff --git a/mojo/services/view_manager/default_access_policy.cc b/mojo/services/view_manager/default_access_policy.cc
deleted file mode 100644
index a2443c3..0000000
--- a/mojo/services/view_manager/default_access_policy.cc
+++ /dev/null
@@ -1,106 +0,0 @@
-// Copyright 2014 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/view_manager/default_access_policy.h"
-
-#include "mojo/services/view_manager/access_policy_delegate.h"
-#include "mojo/services/view_manager/server_view.h"
-
-namespace mojo {
-namespace service {
-
-DefaultAccessPolicy::DefaultAccessPolicy(ConnectionSpecificId connection_id,
- AccessPolicyDelegate* delegate)
- : connection_id_(connection_id),
- delegate_(delegate) {
-}
-
-DefaultAccessPolicy::~DefaultAccessPolicy() {
-}
-
-bool DefaultAccessPolicy::CanRemoveViewFromParent(
- const ServerView* view) const {
- if (!WasCreatedByThisConnection(view))
- return false; // Can only unparent views we created.
-
- return IsViewInRoots(view->parent()) ||
- WasCreatedByThisConnection(view->parent());
-}
-
-bool DefaultAccessPolicy::CanAddView(const ServerView* parent,
- const ServerView* child) const {
- return WasCreatedByThisConnection(child) &&
- (IsViewInRoots(parent) ||
- (WasCreatedByThisConnection(parent) &&
- !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(parent)));
-}
-
-bool DefaultAccessPolicy::CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const {
- return WasCreatedByThisConnection(view) &&
- WasCreatedByThisConnection(relative_view);
-}
-
-bool DefaultAccessPolicy::CanDeleteView(const ServerView* view) const {
- return WasCreatedByThisConnection(view);
-}
-
-bool DefaultAccessPolicy::CanGetViewTree(const ServerView* view) const {
- return WasCreatedByThisConnection(view) || IsViewInRoots(view);
-}
-
-bool DefaultAccessPolicy::CanDescendIntoViewForViewTree(
- const ServerView* view) const {
- return WasCreatedByThisConnection(view) &&
- !delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view);
-}
-
-bool DefaultAccessPolicy::CanEmbed(const ServerView* view) const {
- return WasCreatedByThisConnection(view);
-}
-
-bool DefaultAccessPolicy::CanChangeViewVisibility(
- const ServerView* view) const {
- return WasCreatedByThisConnection(view) || IsViewInRoots(view);
-}
-
-bool DefaultAccessPolicy::CanSetViewSurfaceId(const ServerView* view) const {
- // Once a view embeds another app, the embedder app is no longer able to
- // call SetViewSurfaceId() - this ability is transferred to the embedded app.
- if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
- return false;
- return WasCreatedByThisConnection(view) || IsViewInRoots(view);
-}
-
-bool DefaultAccessPolicy::CanSetViewBounds(const ServerView* view) const {
- return WasCreatedByThisConnection(view);
-}
-
-bool DefaultAccessPolicy::ShouldNotifyOnHierarchyChange(
- const ServerView* view,
- const ServerView** new_parent,
- const ServerView** old_parent) const {
- if (!WasCreatedByThisConnection(view))
- return false;
-
- if (*new_parent && !WasCreatedByThisConnection(*new_parent) &&
- !IsViewInRoots(*new_parent)) {
- *new_parent = NULL;
- }
-
- if (*old_parent && !WasCreatedByThisConnection(*old_parent) &&
- !IsViewInRoots(*old_parent)) {
- *old_parent = NULL;
- }
- return true;
-}
-
-bool DefaultAccessPolicy::IsViewInRoots(const ServerView* view) const {
- return delegate_->GetRootsForAccessPolicy().count(
- ViewIdToTransportId(view->id())) > 0;
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/default_access_policy.h b/mojo/services/view_manager/default_access_policy.h
deleted file mode 100644
index a57ecc2..0000000
--- a/mojo/services/view_manager/default_access_policy.h
+++ /dev/null
@@ -1,59 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_DEFAULT_ACCESS_POLICY_H_
-#define MOJO_SERVICES_VIEW_MANAGER_DEFAULT_ACCESS_POLICY_H_
-
-#include "base/basictypes.h"
-#include "mojo/services/view_manager/access_policy.h"
-
-namespace mojo {
-namespace service {
-
-class AccessPolicyDelegate;
-
-// AccessPolicy for all connections, except the window manager.
-class DefaultAccessPolicy : public AccessPolicy {
- public:
- DefaultAccessPolicy(ConnectionSpecificId connection_id,
- AccessPolicyDelegate* delegate);
- ~DefaultAccessPolicy() override;
-
- // AccessPolicy:
- bool CanRemoveViewFromParent(const ServerView* view) const override;
- bool CanAddView(const ServerView* parent,
- const ServerView* child) const override;
- bool CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const override;
- bool CanDeleteView(const ServerView* view) const override;
- bool CanGetViewTree(const ServerView* view) const override;
- bool CanDescendIntoViewForViewTree(const ServerView* view) const override;
- bool CanEmbed(const ServerView* view) const override;
- bool CanChangeViewVisibility(const ServerView* view) const override;
- bool CanSetViewSurfaceId(const ServerView* view) const override;
- bool CanSetViewBounds(const ServerView* view) const override;
- bool ShouldNotifyOnHierarchyChange(
- const ServerView* view,
- const ServerView** new_parent,
- const ServerView** old_parent) const override;
-
- private:
- bool IsViewInRoots(const ServerView* view) const;
-
- template <typename T>
- bool WasCreatedByThisConnection(const T* t) const {
- return t->id().connection_id == connection_id_;
- }
-
- const ConnectionSpecificId connection_id_;
- AccessPolicyDelegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(DefaultAccessPolicy);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_DEFAULT_ACCESS_POLICY_H_
diff --git a/mojo/services/view_manager/display_manager.cc b/mojo/services/view_manager/display_manager.cc
deleted file mode 100644
index 5488177..0000000
--- a/mojo/services/view_manager/display_manager.cc
+++ /dev/null
@@ -1,171 +0,0 @@
-// Copyright 2014 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/view_manager/display_manager.h"
-
-#include "base/numerics/safe_conversions.h"
-#include "cc/surfaces/surface_id_allocator.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/surfaces/surfaces_type_converters.h"
-#include "mojo/converters/surfaces/surfaces_utils.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/services/public/interfaces/gpu/gpu.mojom.h"
-#include "mojo/services/public/interfaces/surfaces/quads.mojom.h"
-#include "mojo/services/view_manager/connection_manager.h"
-
-namespace mojo {
-namespace service {
-namespace {
-
-gfx::Rect ConvertRectToRoot(const ServerView* view, const gfx::Rect& bounds) {
- gfx::Point origin(bounds.origin());
- while (view->parent()) {
- origin += view->bounds().OffsetFromOrigin();
- view = view->parent();
- if (!view->visible())
- return gfx::Rect();
- }
- return gfx::Rect(origin, bounds.size());
-}
-
-void DrawViewTree(Pass* pass, const ServerView* view, gfx::Vector2d offset) {
- if (!view->visible())
- return;
-
- gfx::Rect node_bounds = view->bounds() + offset;
- std::vector<const ServerView*> children(view->GetChildren());
- for (std::vector<const ServerView*>::reverse_iterator it = children.rbegin();
- it != children.rend();
- ++it) {
- DrawViewTree(pass, *it, offset + view->bounds().OffsetFromOrigin());
- }
-
- cc::SurfaceId node_id = view->surface_id();
-
- SurfaceQuadStatePtr surface_quad_state = SurfaceQuadState::New();
- surface_quad_state->surface = SurfaceId::From(node_id);
-
- gfx::Transform node_transform;
- node_transform.Translate(node_bounds.x(), node_bounds.y());
-
- QuadPtr surface_quad = Quad::New();
- surface_quad->material = Material::MATERIAL_SURFACE_CONTENT;
- surface_quad->rect = Rect::From(node_bounds);
- surface_quad->opaque_rect = Rect::From(node_bounds);
- surface_quad->visible_rect = Rect::From(node_bounds);
- surface_quad->needs_blending = true;
- surface_quad->shared_quad_state_index =
- base::saturated_cast<int32_t>(pass->shared_quad_states.size());
- surface_quad->surface_quad_state = surface_quad_state.Pass();
-
- SharedQuadStatePtr sqs = CreateDefaultSQS(node_bounds.size());
- sqs->content_to_target_transform = Transform::From(node_transform);
-
- pass->quads.push_back(surface_quad.Pass());
- pass->shared_quad_states.push_back(sqs.Pass());
-}
-
-} // namespace
-
-DisplayManager::DisplayManager(
- ApplicationConnection* app_connection,
- ConnectionManager* connection_manager,
- const Callback<void()>& native_viewport_closed_callback)
- : connection_manager_(connection_manager),
- in_setup_(false),
- size_(800, 600),
- draw_timer_(false, false),
- weak_factory_(this) {
- app_connection->ConnectToService("mojo:native_viewport_service",
- &native_viewport_);
- native_viewport_.set_client(this);
- native_viewport_->Create(
- Size::From(size_),
- base::Bind(&DisplayManager::OnCreatedNativeViewport,
- weak_factory_.GetWeakPtr()));
- native_viewport_->Show();
- app_connection->ConnectToService("mojo:surfaces_service", &surfaces_service_);
- surfaces_service_->CreateSurfaceConnection(base::Bind(
- &DisplayManager::OnSurfaceConnectionCreated, weak_factory_.GetWeakPtr()));
-}
-
-DisplayManager::~DisplayManager() {
-}
-
-void DisplayManager::SchedulePaint(const ServerView* view,
- const gfx::Rect& bounds) {
- if (!view->visible())
- return;
- gfx::Rect root_relative_rect = ConvertRectToRoot(view, bounds);
- if (root_relative_rect.IsEmpty())
- return;
- dirty_rect_.Union(root_relative_rect);
- if (!draw_timer_.IsRunning()) {
- draw_timer_.Start(
- FROM_HERE,
- base::TimeDelta(),
- base::Bind(&DisplayManager::Draw, base::Unretained(this)));
- }
-}
-
-void DisplayManager::OnCreatedNativeViewport(uint64_t native_viewport_id) {
-}
-
-void DisplayManager::OnSurfaceConnectionCreated(SurfacePtr surface,
- uint32_t id_namespace) {
- surface_ = surface.Pass();
- surface_.set_client(this);
- surface_id_allocator_.reset(new cc::SurfaceIdAllocator(id_namespace));
- Draw();
-}
-
-void DisplayManager::Draw() {
- if (!surface_)
- return;
- if (surface_id_.is_null()) {
- surface_id_ = surface_id_allocator_->GenerateId();
- surface_->CreateSurface(SurfaceId::From(surface_id_), Size::From(size_));
- }
-
- PassPtr pass = CreateDefaultPass(1, gfx::Rect(size_));
- pass->damage_rect = Rect::From(dirty_rect_);
-
- DrawViewTree(pass.get(), connection_manager_->root(), gfx::Vector2d());
-
- FramePtr frame = Frame::New();
- frame->passes.push_back(pass.Pass());
- frame->resources.resize(0u);
- surface_->SubmitFrame(SurfaceId::From(surface_id_), frame.Pass());
-
- native_viewport_->SubmittedFrame(SurfaceId::From(surface_id_));
-
- dirty_rect_ = gfx::Rect();
-}
-
-void DisplayManager::OnDestroyed() {
- native_viewport_closed_callback_.Run();
-}
-
-void DisplayManager::OnSizeChanged(SizePtr size) {
- size_ = size.To<gfx::Size>();
- connection_manager_->root()->SetBounds(gfx::Rect(size_));
- if (surface_id_.is_null())
- return;
- surface_->DestroySurface(SurfaceId::From(surface_id_));
- surface_id_ = cc::SurfaceId();
- SchedulePaint(connection_manager_->root(), gfx::Rect(size_));
-}
-
-void DisplayManager::OnEvent(EventPtr event,
- const mojo::Callback<void()>& callback) {
- connection_manager_->DispatchViewInputEventToDelegate(event.Pass());
- callback.Run();
-}
-
-void DisplayManager::ReturnResources(Array<ReturnedResourcePtr> resources) {
- DCHECK_EQ(0u, resources.size());
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/display_manager.h b/mojo/services/view_manager/display_manager.h
deleted file mode 100644
index 1f5f930..0000000
--- a/mojo/services/view_manager/display_manager.h
+++ /dev/null
@@ -1,87 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_DISPLAY_MANAGER_H_
-#define MOJO_SERVICES_VIEW_MANAGER_DISPLAY_MANAGER_H_
-
-#include <map>
-
-#include "base/basictypes.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/weak_ptr.h"
-#include "base/timer/timer.h"
-#include "cc/surfaces/surface_id.h"
-#include "mojo/public/cpp/bindings/callback.h"
-#include "mojo/services/public/interfaces/native_viewport/native_viewport.mojom.h"
-#include "mojo/services/public/interfaces/surfaces/surfaces.mojom.h"
-#include "mojo/services/public/interfaces/surfaces/surfaces_service.mojom.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-#include "ui/gfx/rect.h"
-
-namespace cc {
-class SurfaceIdAllocator;
-}
-
-namespace mojo {
-
-class ApplicationConnection;
-
-namespace service {
-
-class ConnectionManager;
-class ServerView;
-
-// DisplayManager binds the root node to an actual display.
-class MOJO_VIEW_MANAGER_EXPORT DisplayManager
- : NON_EXPORTED_BASE(public NativeViewportClient),
- NON_EXPORTED_BASE(public SurfaceClient) {
- public:
- DisplayManager(ApplicationConnection* app_connection,
- ConnectionManager* connection_manager,
- const Callback<void()>& native_viewport_closed_callback);
- ~DisplayManager() override;
-
- // Schedules a paint for the specified region of the specified view.
- void SchedulePaint(const ServerView* view, const gfx::Rect& bounds);
-
- // See description above field for details.
- bool in_setup() const { return in_setup_; }
-
- private:
- void OnCreatedNativeViewport(uint64_t native_viewport_id);
- void OnSurfaceConnectionCreated(SurfacePtr surface, uint32_t id_namespace);
- void Draw();
-
- // NativeViewportClient implementation.
- void OnDestroyed() override;
- void OnSizeChanged(SizePtr size) override;
- void OnEvent(EventPtr event, const mojo::Callback<void()>& callback) override;
-
- // SurfaceClient implementation.
- void ReturnResources(Array<ReturnedResourcePtr> resources) override;
-
- ConnectionManager* connection_manager_;
-
- // Returns true if adding the root view's window to |window_tree_host_|.
- bool in_setup_;
-
- gfx::Size size_;
- gfx::Rect dirty_rect_;
- base::Timer draw_timer_;
-
- SurfacesServicePtr surfaces_service_;
- SurfacePtr surface_;
- scoped_ptr<cc::SurfaceIdAllocator> surface_id_allocator_;
- cc::SurfaceId surface_id_;
- NativeViewportPtr native_viewport_;
- Callback<void()> native_viewport_closed_callback_;
- base::WeakPtrFactory<DisplayManager> weak_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(DisplayManager);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_DISPLAY_MANAGER_H_
diff --git a/mojo/services/view_manager/ids.h b/mojo/services/view_manager/ids.h
deleted file mode 100644
index 0d1c486..0000000
--- a/mojo/services/view_manager/ids.h
+++ /dev/null
@@ -1,63 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_IDS_H_
-#define MOJO_SERVICES_VIEW_MANAGER_IDS_H_
-
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/cpp/view_manager/util.h"
-
-namespace mojo {
-namespace service {
-
-// Connection id is used to indicate no connection. That is, no
-// ViewManagerServiceImpl ever gets this id.
-const ConnectionSpecificId kInvalidConnectionId = 0;
-
-// TODO(sky): remove this, temporary while window manager API is in existing
-// api.
-const ConnectionSpecificId kWindowManagerConnection = 1;
-
-// Adds a bit of type safety to view ids.
-struct ViewId {
- ViewId(ConnectionSpecificId connection_id, ConnectionSpecificId view_id)
- : connection_id(connection_id),
- view_id(view_id) {}
- ViewId() : connection_id(0), view_id(0) {}
-
- bool operator==(const ViewId& other) const {
- return other.connection_id == connection_id &&
- other.view_id == view_id;
- }
-
- bool operator!=(const ViewId& other) const {
- return !(*this == other);
- }
-
- ConnectionSpecificId connection_id;
- ConnectionSpecificId view_id;
-};
-
-inline ViewId ViewIdFromTransportId(Id id) {
- return ViewId(HiWord(id), LoWord(id));
-}
-
-inline Id ViewIdToTransportId(const ViewId& id) {
- return (id.connection_id << 16) | id.view_id;
-}
-
-inline ViewId RootViewId() {
- return ViewId(kInvalidConnectionId, 1);
-}
-
-// Returns a ViewId that is reserved to indicate no view. That is, no view will
-// ever be created with this id.
-inline ViewId InvalidViewId() {
- return ViewId(kInvalidConnectionId, 0);
-}
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_IDS_H_
diff --git a/mojo/services/view_manager/main.cc b/mojo/services/view_manager/main.cc
deleted file mode 100644
index 39c48d6b..0000000
--- a/mojo/services/view_manager/main.cc
+++ /dev/null
@@ -1,47 +0,0 @@
-// Copyright 2014 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/application/application_runner_chromium.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/services/view_manager/view_manager_init_service_context.h"
-#include "mojo/services/view_manager/view_manager_init_service_impl.h"
-
-namespace mojo {
-namespace service {
-
-class ViewManagerApp : public ApplicationDelegate,
- public InterfaceFactory<ViewManagerInitService> {
- public:
- ViewManagerApp() {}
- ~ViewManagerApp() override {}
-
- bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
- context_.ConfigureIncomingConnection(connection);
- // TODO(sky): this needs some sort of authentication as well as making sure
- // we only ever have one active at a time.
- connection->AddService(this);
- return true;
- }
-
- void Create(ApplicationConnection* connection,
- InterfaceRequest<ViewManagerInitService> request) override {
- BindToRequest(new ViewManagerInitServiceImpl(connection, &context_),
- &request);
- }
-
- private:
- ViewManagerInitServiceContext context_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerApp);
-};
-
-} // namespace service
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::service::ViewManagerApp);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/services/view_manager/server_view.cc b/mojo/services/view_manager/server_view.cc
deleted file mode 100644
index 8f5a559..0000000
--- a/mojo/services/view_manager/server_view.cc
+++ /dev/null
@@ -1,144 +0,0 @@
-// Copyright 2014 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/view_manager/server_view.h"
-
-#include "mojo/services/view_manager/server_view_delegate.h"
-
-namespace mojo {
-namespace service {
-
-ServerView::ServerView(ServerViewDelegate* delegate, const ViewId& id)
- : delegate_(delegate), id_(id), parent_(NULL), visible_(true) {
- DCHECK(delegate); // Must provide a delegate.
-}
-
-ServerView::~ServerView() {
- while (!children_.empty())
- children_.front()->parent()->Remove(children_.front());
-
- if (parent_)
- parent_->Remove(this);
-
- delegate_->OnViewDestroyed(this);
-}
-
-void ServerView::Add(ServerView* child) {
- // We assume validation checks happened already.
- DCHECK(child);
- DCHECK(child != this);
- DCHECK(!child->Contains(this));
- if (child->parent() == this) {
- if (children_.size() == 1)
- return; // Already in the right position.
- Reorder(child, children_.back(), ORDER_DIRECTION_ABOVE);
- return;
- }
-
- const ServerView* old_parent = child->parent();
- child->delegate_->OnWillChangeViewHierarchy(child, this, old_parent);
- if (child->parent())
- child->parent()->RemoveImpl(child);
-
- child->parent_ = this;
- children_.push_back(child);
- child->delegate_->OnViewHierarchyChanged(child, this, old_parent);
-}
-
-void ServerView::Remove(ServerView* child) {
- // We assume validation checks happened else where.
- DCHECK(child);
- DCHECK(child != this);
- DCHECK(child->parent() == this);
-
- child->delegate_->OnWillChangeViewHierarchy(child, NULL, this);
- RemoveImpl(child);
- child->delegate_->OnViewHierarchyChanged(child, NULL, this);
-}
-
-void ServerView::Reorder(ServerView* child,
- ServerView* relative,
- OrderDirection direction) {
- // We assume validation checks happened else where.
- DCHECK(child);
- DCHECK(child->parent() == this);
- DCHECK_GT(children_.size(), 1u);
- children_.erase(std::find(children_.begin(), children_.end(), child));
- Views::iterator i = std::find(children_.begin(), children_.end(), relative);
- if (direction == ORDER_DIRECTION_ABOVE) {
- DCHECK(i != children_.end());
- children_.insert(++i, child);
- } else if (direction == ORDER_DIRECTION_BELOW) {
- DCHECK(i != children_.end());
- children_.insert(i, child);
- }
- delegate_->OnViewReordered(this, relative, direction);
-}
-
-void ServerView::SetBounds(const gfx::Rect& bounds) {
- if (bounds_ == bounds)
- return;
-
- const gfx::Rect old_bounds = bounds_;
- bounds_ = bounds;
- delegate_->OnViewBoundsChanged(this, old_bounds, bounds);
-}
-
-const ServerView* ServerView::GetRoot() const {
- const ServerView* view = this;
- while (view && view->parent())
- view = view->parent();
- return view;
-}
-
-std::vector<const ServerView*> ServerView::GetChildren() const {
- std::vector<const ServerView*> children;
- children.reserve(children_.size());
- for (size_t i = 0; i < children_.size(); ++i)
- children.push_back(children_[i]);
- return children;
-}
-
-std::vector<ServerView*> ServerView::GetChildren() {
- // TODO(sky): rename to children() and fix return type.
- return children_;
-}
-
-bool ServerView::Contains(const ServerView* view) const {
- for (const ServerView* parent = view; parent; parent = parent->parent_) {
- if (parent == this)
- return true;
- }
- return false;
-}
-
-void ServerView::SetVisible(bool value) {
- if (visible_ == value)
- return;
-
- delegate_->OnWillChangeViewVisibility(this);
- visible_ = value;
-}
-
-bool ServerView::IsDrawn(const ServerView* root) const {
- if (!root->visible_)
- return false;
- const ServerView* view = this;
- while (view && view != root && view->visible_)
- view = view->parent_;
- return view == root;
-}
-
-void ServerView::SetSurfaceId(cc::SurfaceId surface_id) {
- surface_id_ = surface_id;
- delegate_->OnViewSurfaceIdChanged(this);
-}
-
-void ServerView::RemoveImpl(ServerView* view) {
- view->parent_ = NULL;
- children_.erase(std::find(children_.begin(), children_.end(), view));
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/server_view.h b/mojo/services/view_manager/server_view.h
deleted file mode 100644
index af7b37d..0000000
--- a/mojo/services/view_manager/server_view.h
+++ /dev/null
@@ -1,91 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_SERVER_VIEW_H_
-#define MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_H_
-
-#include <vector>
-
-#include "base/logging.h"
-#include "cc/surfaces/surface_id.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-#include "ui/gfx/geometry/rect.h"
-
-namespace mojo {
-namespace service {
-
-class ServerViewDelegate;
-
-// Server side representation of a view. Delegate is informed of interesting
-// events.
-//
-// It is assumed that all functions that mutate the tree have validated the
-// mutation is possible before hand. For example, Reorder() assumes the supplied
-// view is a child and not already in position.
-class MOJO_VIEW_MANAGER_EXPORT ServerView {
- public:
- ServerView(ServerViewDelegate* delegate, const ViewId& id);
- virtual ~ServerView();
-
- const ViewId& id() const { return id_; }
-
- void Add(ServerView* child);
- void Remove(ServerView* child);
- void Reorder(ServerView* child,
- ServerView* relative,
- OrderDirection direction);
-
- const gfx::Rect& bounds() const { return bounds_; }
- void SetBounds(const gfx::Rect& bounds);
-
- const ServerView* parent() const { return parent_; }
- ServerView* parent() { return parent_; }
-
- const ServerView* GetRoot() const;
- ServerView* GetRoot() {
- return const_cast<ServerView*>(
- const_cast<const ServerView*>(this)->GetRoot());
- }
-
- std::vector<const ServerView*> GetChildren() const;
- std::vector<ServerView*> GetChildren();
-
- // Returns true if this contains |view| or is |view|.
- bool Contains(const ServerView* view) const;
-
- // Returns true if the window is visible. This does not consider visibility
- // of any ancestors.
- bool visible() const { return visible_; }
- void SetVisible(bool value);
-
- // Returns true if this view is attached to |root| and all ancestors are
- // visible.
- bool IsDrawn(const ServerView* root) const;
-
- void SetSurfaceId(cc::SurfaceId surface_id);
- const cc::SurfaceId surface_id() const { return surface_id_; }
-
- private:
- typedef std::vector<ServerView*> Views;
-
- // Implementation of removing a view. Doesn't send any notification.
- void RemoveImpl(ServerView* view);
-
- ServerViewDelegate* delegate_;
- const ViewId id_;
- ServerView* parent_;
- Views children_;
- bool visible_;
- gfx::Rect bounds_;
- cc::SurfaceId surface_id_;
-
- DISALLOW_COPY_AND_ASSIGN(ServerView);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_H_
diff --git a/mojo/services/view_manager/server_view_delegate.h b/mojo/services/view_manager/server_view_delegate.h
deleted file mode 100644
index 24e5f8f..0000000
--- a/mojo/services/view_manager/server_view_delegate.h
+++ /dev/null
@@ -1,52 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_SERVER_VIEW_DELEGATE_H_
-#define MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_DELEGATE_H_
-
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace gfx {
-class Rect;
-}
-
-namespace mojo {
-namespace service {
-
-class ServerView;
-
-class MOJO_VIEW_MANAGER_EXPORT ServerViewDelegate {
- public:
- // Invoked at the end of the View's destructor (after it has been removed from
- // the hierarchy).
- virtual void OnViewDestroyed(const ServerView* view) = 0;
-
- virtual void OnWillChangeViewHierarchy(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) = 0;
-
- virtual void OnViewHierarchyChanged(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent) = 0;
-
- virtual void OnViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) = 0;
-
- virtual void OnViewSurfaceIdChanged(const ServerView* view) = 0;
-
- virtual void OnViewReordered(const ServerView* view,
- const ServerView* relative,
- OrderDirection direction) = 0;
-
- virtual void OnWillChangeViewVisibility(const ServerView* view) = 0;
-
- protected:
- virtual ~ServerViewDelegate() {}
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_SERVER_VIEW_DELEGATE_H_
diff --git a/mojo/services/view_manager/test_change_tracker.cc b/mojo/services/view_manager/test_change_tracker.cc
deleted file mode 100644
index 2b127cd..0000000
--- a/mojo/services/view_manager/test_change_tracker.cc
+++ /dev/null
@@ -1,244 +0,0 @@
-// Copyright 2014 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/view_manager/test_change_tracker.h"
-
-#include "base/strings/string_util.h"
-#include "base/strings/stringprintf.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/services/public/cpp/view_manager/util.h"
-
-namespace mojo {
-namespace service {
-
-std::string ViewIdToString(Id id) {
- return (id == 0) ? "null" :
- base::StringPrintf("%d,%d", HiWord(id), LoWord(id));
-}
-
-namespace {
-
-std::string RectToString(const gfx::Rect& rect) {
- return base::StringPrintf("%d,%d %dx%d", rect.x(), rect.y(), rect.width(),
- rect.height());
-}
-
-std::string DirectionToString(OrderDirection direction) {
- return direction == ORDER_DIRECTION_ABOVE ? "above" : "below";
-}
-
-std::string ChangeToDescription1(const Change& change) {
- switch (change.type) {
- case CHANGE_TYPE_EMBED:
- return base::StringPrintf("OnEmbed creator=%s",
- change.creator_url.data());
-
- case CHANGE_TYPE_NODE_BOUNDS_CHANGED:
- return base::StringPrintf(
- "BoundsChanged view=%s old_bounds=%s new_bounds=%s",
- ViewIdToString(change.view_id).c_str(),
- RectToString(change.bounds).c_str(),
- RectToString(change.bounds2).c_str());
-
- case CHANGE_TYPE_NODE_HIERARCHY_CHANGED:
- return base::StringPrintf(
- "HierarchyChanged view=%s new_parent=%s old_parent=%s",
- ViewIdToString(change.view_id).c_str(),
- ViewIdToString(change.view_id2).c_str(),
- ViewIdToString(change.view_id3).c_str());
-
- case CHANGE_TYPE_NODE_REORDERED:
- return base::StringPrintf("Reordered view=%s relative=%s direction=%s",
- ViewIdToString(change.view_id).c_str(),
- ViewIdToString(change.view_id2).c_str(),
- DirectionToString(change.direction).c_str());
-
- case CHANGE_TYPE_NODE_DELETED:
- return base::StringPrintf("ViewDeleted view=%s",
- ViewIdToString(change.view_id).c_str());
-
- case CHANGE_TYPE_NODE_VISIBILITY_CHANGED:
- return base::StringPrintf("VisibilityChanged view=%s visible=%s",
- ViewIdToString(change.view_id).c_str(),
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED:
- return base::StringPrintf("DrawnStateChanged view=%s drawn=%s",
- ViewIdToString(change.view_id).c_str(),
- change.bool_value ? "true" : "false");
-
- case CHANGE_TYPE_INPUT_EVENT:
- return base::StringPrintf("InputEvent view=%s event_action=%d",
- ViewIdToString(change.view_id).c_str(),
- change.event_action);
-
- case CHANGE_TYPE_DELEGATE_EMBED:
- return base::StringPrintf("DelegateEmbed url=%s",
- change.embed_url.data());
- }
- return std::string();
-}
-
-} // namespace
-
-std::vector<std::string> ChangesToDescription1(
- const std::vector<Change>& changes) {
- std::vector<std::string> strings(changes.size());
- for (size_t i = 0; i < changes.size(); ++i)
- strings[i] = ChangeToDescription1(changes[i]);
- return strings;
-}
-
-std::string ChangeViewDescription(const std::vector<Change>& changes) {
- if (changes.size() != 1)
- return std::string();
- std::vector<std::string> view_strings(changes[0].views.size());
- for (size_t i = 0; i < changes[0].views.size(); ++i)
- view_strings[i] = "[" + changes[0].views[i].ToString() + "]";
- return JoinString(view_strings, ',');
-}
-
-TestView ViewDataToTestView(const ViewDataPtr& data) {
- TestView view;
- view.parent_id = data->parent_id;
- view.view_id = data->view_id;
- view.visible = data->visible;
- view.drawn = data->drawn;
- return view;
-}
-
-void ViewDatasToTestViews(const Array<ViewDataPtr>& data,
- std::vector<TestView>* test_views) {
- for (size_t i = 0; i < data.size(); ++i)
- test_views->push_back(ViewDataToTestView(data[i]));
-}
-
-Change::Change()
- : type(CHANGE_TYPE_EMBED),
- connection_id(0),
- view_id(0),
- view_id2(0),
- view_id3(0),
- event_action(0),
- direction(ORDER_DIRECTION_ABOVE),
- bool_value(false) {
-}
-
-Change::~Change() {
-}
-
-TestChangeTracker::TestChangeTracker()
- : delegate_(NULL) {
-}
-
-TestChangeTracker::~TestChangeTracker() {
-}
-
-void TestChangeTracker::OnEmbed(ConnectionSpecificId connection_id,
- const String& creator_url,
- ViewDataPtr root) {
- Change change;
- change.type = CHANGE_TYPE_EMBED;
- change.connection_id = connection_id;
- change.creator_url = creator_url;
- change.views.push_back(ViewDataToTestView(root));
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewBoundsChanged(Id view_id,
- RectPtr old_bounds,
- RectPtr new_bounds) {
- Change change;
- change.type = CHANGE_TYPE_NODE_BOUNDS_CHANGED;
- change.view_id = view_id;
- change.bounds = old_bounds.To<gfx::Rect>();
- change.bounds2 = new_bounds.To<gfx::Rect>();
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewHierarchyChanged(Id view_id,
- Id new_parent_id,
- Id old_parent_id,
- Array<ViewDataPtr> views) {
- Change change;
- change.type = CHANGE_TYPE_NODE_HIERARCHY_CHANGED;
- change.view_id = view_id;
- change.view_id2 = new_parent_id;
- change.view_id3 = old_parent_id;
- ViewDatasToTestViews(views, &change.views);
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewReordered(Id view_id,
- Id relative_view_id,
- OrderDirection direction) {
- Change change;
- change.type = CHANGE_TYPE_NODE_REORDERED;
- change.view_id = view_id;
- change.view_id2 = relative_view_id;
- change.direction = direction;
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewDeleted(Id view_id) {
- Change change;
- change.type = CHANGE_TYPE_NODE_DELETED;
- change.view_id = view_id;
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewVisibilityChanged(Id view_id, bool visible) {
- Change change;
- change.type = CHANGE_TYPE_NODE_VISIBILITY_CHANGED;
- change.view_id = view_id;
- change.bool_value = visible;
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewDrawnStateChanged(Id view_id, bool drawn) {
- Change change;
- change.type = CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED;
- change.view_id = view_id;
- change.bool_value = drawn;
- AddChange(change);
-}
-
-void TestChangeTracker::OnViewInputEvent(Id view_id, EventPtr event) {
- Change change;
- change.type = CHANGE_TYPE_INPUT_EVENT;
- change.view_id = view_id;
- change.event_action = event->action;
- AddChange(change);
-}
-
-void TestChangeTracker::DelegateEmbed(const String& url) {
- Change change;
- change.type = CHANGE_TYPE_DELEGATE_EMBED;
- change.embed_url = url;
- AddChange(change);
-}
-
-void TestChangeTracker::AddChange(const Change& change) {
- changes_.push_back(change);
- if (delegate_)
- delegate_->OnChangeAdded();
-}
-
-std::string TestView::ToString() const {
- return base::StringPrintf("view=%s parent=%s",
- ViewIdToString(view_id).c_str(),
- ViewIdToString(parent_id).c_str());
-}
-
-std::string TestView::ToString2() const {
- return base::StringPrintf("view=%s parent=%s visible=%s drawn=%s",
- ViewIdToString(view_id).c_str(),
- ViewIdToString(parent_id).c_str(),
- visible ? "true" : "false",
- drawn ? "true" : "false");
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/test_change_tracker.h b/mojo/services/view_manager/test_change_tracker.h
deleted file mode 100644
index 791c8ad..0000000
--- a/mojo/services/view_manager/test_change_tracker.h
+++ /dev/null
@@ -1,133 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
-#define MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
-
-#include <string>
-#include <vector>
-
-#include "mojo/public/cpp/bindings/array.h"
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "ui/gfx/rect.h"
-
-namespace mojo {
-namespace service {
-
-enum ChangeType {
- CHANGE_TYPE_EMBED,
- // TODO(sky): NODE->VIEW.
- CHANGE_TYPE_NODE_BOUNDS_CHANGED,
- CHANGE_TYPE_NODE_HIERARCHY_CHANGED,
- CHANGE_TYPE_NODE_REORDERED,
- CHANGE_TYPE_NODE_VISIBILITY_CHANGED,
- CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED,
- CHANGE_TYPE_NODE_DELETED,
- CHANGE_TYPE_INPUT_EVENT,
- CHANGE_TYPE_DELEGATE_EMBED,
-};
-
-// TODO(sky): consider nuking and converting directly to ViewData.
-struct TestView {
- // Returns a string description of this.
- std::string ToString() const;
-
- // Returns a string description that includes visible and drawn.
- std::string ToString2() const;
-
- Id parent_id;
- Id view_id;
- bool visible;
- bool drawn;
-};
-
-// Tracks a call to ViewManagerClient. See the individual functions for the
-// fields that are used.
-struct Change {
- Change();
- ~Change();
-
- ChangeType type;
- ConnectionSpecificId connection_id;
- std::vector<TestView> views;
- Id view_id;
- Id view_id2;
- Id view_id3;
- gfx::Rect bounds;
- gfx::Rect bounds2;
- int32 event_action;
- String creator_url;
- String embed_url;
- OrderDirection direction;
- bool bool_value;
-};
-
-// Converts Changes to string descriptions.
-std::vector<std::string> ChangesToDescription1(
- const std::vector<Change>& changes);
-
-// Returns a string description of |changes[0].views|. Returns an empty string
-// if change.size() != 1.
-std::string ChangeViewDescription(const std::vector<Change>& changes);
-
-// Converts ViewDatas to TestViews.
-void ViewDatasToTestViews(const Array<ViewDataPtr>& data,
- std::vector<TestView>* test_views);
-
-// TestChangeTracker is used to record ViewManagerClient functions. It notifies
-// a delegate any time a change is added.
-class TestChangeTracker {
- public:
- // Used to notify the delegate when a change is added. A change corresponds to
- // a single ViewManagerClient function.
- class Delegate {
- public:
- virtual void OnChangeAdded() = 0;
-
- protected:
- virtual ~Delegate() {}
- };
-
- TestChangeTracker();
- ~TestChangeTracker();
-
- void set_delegate(Delegate* delegate) {
- delegate_ = delegate;
- }
-
- std::vector<Change>* changes() { return &changes_; }
-
- // Each of these functions generate a Change. There is one per
- // ViewManagerClient function.
- void OnEmbed(ConnectionSpecificId connection_id,
- const String& creator_url,
- ViewDataPtr root);
- void OnViewBoundsChanged(Id view_id, RectPtr old_bounds, RectPtr new_bounds);
- void OnViewHierarchyChanged(Id view_id,
- Id new_parent_id,
- Id old_parent_id,
- Array<ViewDataPtr> views);
- void OnViewReordered(Id view_id,
- Id relative_view_id,
- OrderDirection direction);
- void OnViewDeleted(Id view_id);
- void OnViewVisibilityChanged(Id view_id, bool visible);
- void OnViewDrawnStateChanged(Id view_id, bool drawn);
- void OnViewInputEvent(Id view_id, EventPtr event);
- void DelegateEmbed(const String& url);
-
- private:
- void AddChange(const Change& change);
-
- Delegate* delegate_;
- std::vector<Change> changes_;
-
- DISALLOW_COPY_AND_ASSIGN(TestChangeTracker);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_TEST_CHANGE_TRACKER_H_
diff --git a/mojo/services/view_manager/view_manager_export.h b/mojo/services/view_manager/view_manager_export.h
deleted file mode 100644
index 29b0e62..0000000
--- a/mojo/services/view_manager/view_manager_export.h
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_VIEW_MANAGER_EXPORT_H_
-#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_EXPORT_H_
-
-#if defined(COMPONENT_BUILD)
-#if defined(WIN32)
-
-#if defined(MOJO_VIEW_MANAGER_IMPLEMENTATION)
-#define MOJO_VIEW_MANAGER_EXPORT __declspec(dllexport)
-#else
-#define MOJO_VIEW_MANAGER_EXPORT __declspec(dllimport)
-#endif
-
-#else // !defined(WIN32)
-
-#if defined(MOJO_VIEW_MANAGER_IMPLEMENTATION)
-#define MOJO_VIEW_MANAGER_EXPORT __attribute__((visibility("default")))
-#else
-#define MOJO_VIEW_MANAGER_EXPORT
-#endif
-
-#endif // defined(WIN32)
-
-#else // defined(COMPONENT_BUILD)
-#define MOJO_VIEW_MANAGER_EXPORT
-#endif
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_EXPORT_H_
diff --git a/mojo/services/view_manager/view_manager_init_service_context.cc b/mojo/services/view_manager/view_manager_init_service_context.cc
deleted file mode 100644
index d23bec7..0000000
--- a/mojo/services/view_manager/view_manager_init_service_context.cc
+++ /dev/null
@@ -1,78 +0,0 @@
-// Copyright 2014 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/view_manager/view_manager_init_service_context.h"
-
-#include "base/auto_reset.h"
-#include "base/bind.h"
-#include "mojo/services/view_manager/connection_manager.h"
-#include "mojo/services/view_manager/view_manager_init_service_impl.h"
-
-namespace mojo {
-namespace service {
-
-ViewManagerInitServiceContext::ConnectParams::ConnectParams() {}
-
-ViewManagerInitServiceContext::ConnectParams::~ConnectParams() {}
-
-ViewManagerInitServiceContext::ViewManagerInitServiceContext()
- : deleting_connection_(false) {
-}
-ViewManagerInitServiceContext::~ViewManagerInitServiceContext() {}
-
-void ViewManagerInitServiceContext::AddConnection(
- ViewManagerInitServiceImpl* connection) {
- DCHECK(std::find(connections_.begin(), connections_.end(), connection) ==
- connections_.end());
- connections_.push_back(connection);
-}
-
-void ViewManagerInitServiceContext::RemoveConnection(
- ViewManagerInitServiceImpl* connection) {
- if (!deleting_connection_) {
- Connections::iterator it =
- std::find(connections_.begin(), connections_.end(), connection);
- DCHECK(it != connections_.end());
- connections_.erase(it);
- }
-
- // This object is owned by an object that outlives the current thread's
- // message loop, so we need to destroy the ConnectionManager earlier, as it
- // may attempt to post tasks during its destruction.
- if (connections_.empty())
- connection_manager_.reset();
-}
-
-void ViewManagerInitServiceContext::ConfigureIncomingConnection(
- ApplicationConnection* connection) {
- if (!connection_manager_.get()) {
- connection_manager_.reset(new ConnectionManager(
- connection,
- base::Bind(&ViewManagerInitServiceContext::OnNativeViewportDeleted,
- base::Unretained(this))));
- }
-}
-
-void ViewManagerInitServiceContext::Embed(
- const String& url,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback) {
- connection_manager_->Embed(url, GetProxy(&service_provider));
- callback.Run(true);
-}
-
-void ViewManagerInitServiceContext::OnNativeViewportDeleted() {
- // Prevent the connection from modifying the connection list during manual
- // teardown.
- base::AutoReset<bool> deleting_connection(&deleting_connection_, true);
- for (Connections::const_iterator it = connections_.begin();
- it != connections_.end(); ++it) {
- delete *it;
- }
- connections_.clear();
- connection_manager_.reset();
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_init_service_context.h b/mojo/services/view_manager/view_manager_init_service_context.h
deleted file mode 100644
index 5019c68..0000000
--- a/mojo/services/view_manager/view_manager_init_service_context.h
+++ /dev/null
@@ -1,64 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
-#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
-
-#include "base/memory/scoped_ptr.h"
-#include "mojo/public/cpp/bindings/callback.h"
-#include "mojo/public/cpp/bindings/interface_request.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace mojo {
-class ApplicationConnection;
-
-namespace service {
-
-class ConnectionManager;
-class ViewManagerInitServiceImpl;
-
-// State shared between all ViewManagerInitService impls.
-class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceContext {
- public:
- ViewManagerInitServiceContext();
- virtual ~ViewManagerInitServiceContext();
-
- void AddConnection(ViewManagerInitServiceImpl* connection);
- void RemoveConnection(ViewManagerInitServiceImpl* connection);
-
- void ConfigureIncomingConnection(ApplicationConnection* connection);
-
- void Embed(const String& url,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback);
-
- ConnectionManager* connection_manager() { return connection_manager_.get(); }
-
- private:
- typedef std::vector<ViewManagerInitServiceImpl*> Connections;
-
- struct ConnectParams {
- ConnectParams();
- ~ConnectParams();
-
- std::string url;
- InterfaceRequest<ServiceProvider> service_provider;
- Callback<void(bool)> callback;
- };
-
- void OnNativeViewportDeleted();
-
- scoped_ptr<ConnectionManager> connection_manager_;
- Connections connections_;
-
- bool deleting_connection_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerInitServiceContext);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_CONTEXT_H_
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.cc b/mojo/services/view_manager/view_manager_init_service_impl.cc
deleted file mode 100644
index ab30718..0000000
--- a/mojo/services/view_manager/view_manager_init_service_impl.cc
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright 2014 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/view_manager/view_manager_init_service_impl.h"
-
-#include "base/bind.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/view_manager_init_service_context.h"
-#include "mojo/services/view_manager/view_manager_service_impl.h"
-
-namespace mojo {
-namespace service {
-
-ViewManagerInitServiceImpl::ViewManagerInitServiceImpl(
- ApplicationConnection* connection,
- ViewManagerInitServiceContext* context)
- : context_(context) {
- context_->AddConnection(this);
-}
-
-ViewManagerInitServiceImpl::~ViewManagerInitServiceImpl() {
- context_->RemoveConnection(this);
-}
-
-void ViewManagerInitServiceImpl::Embed(
- const String& url,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback) {
- context_->Embed(url, service_provider.Pass(), callback);
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_init_service_impl.h b/mojo/services/view_manager/view_manager_init_service_impl.h
deleted file mode 100644
index b36efbe..0000000
--- a/mojo/services/view_manager/view_manager_init_service_impl.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_IMPL_H_
-#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_IMPL_H_
-
-#include <string>
-
-#include "base/basictypes.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/view_manager/connection_manager.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace mojo {
-
-class ApplicationConnection;
-
-namespace service {
-
-class ViewManagerInitServiceContext;
-
-#if defined(OS_WIN)
-// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
-// below.
-#pragma warning(push)
-#pragma warning(disable : 4275)
-#endif
-
-// Used to create the initial ViewManagerClient. Doesn't initiate the Connect()
-// until the WindowTreeHost has been created.
-class MOJO_VIEW_MANAGER_EXPORT ViewManagerInitServiceImpl
- : public InterfaceImpl<ViewManagerInitService> {
- public:
- ViewManagerInitServiceImpl(ApplicationConnection* connection,
- ViewManagerInitServiceContext* context);
- ~ViewManagerInitServiceImpl() override;
-
- private:
- // ViewManagerInitService overrides:
- void Embed(const String& url,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback) override;
-
- ViewManagerInitServiceContext* context_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerInitServiceImpl);
-};
-
-#if defined(OS_WIN)
-#pragma warning(pop)
-#endif
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_INIT_SERVICE_IMPL_H_
diff --git a/mojo/services/view_manager/view_manager_service_impl.cc b/mojo/services/view_manager/view_manager_service_impl.cc
deleted file mode 100644
index f066b82..0000000
--- a/mojo/services/view_manager/view_manager_service_impl.cc
+++ /dev/null
@@ -1,541 +0,0 @@
-// Copyright 2014 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/view_manager/view_manager_service_impl.h"
-
-#include "base/bind.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/converters/surfaces/surfaces_type_converters.h"
-#include "mojo/services/view_manager/connection_manager.h"
-#include "mojo/services/view_manager/default_access_policy.h"
-#include "mojo/services/view_manager/server_view.h"
-#include "mojo/services/view_manager/window_manager_access_policy.h"
-
-namespace mojo {
-namespace service {
-
-ViewManagerServiceImpl::ViewManagerServiceImpl(
- ConnectionManager* connection_manager,
- ConnectionSpecificId creator_id,
- const std::string& creator_url,
- const std::string& url,
- const ViewId& root_id,
- InterfaceRequest<ServiceProvider> service_provider)
- : connection_manager_(connection_manager),
- id_(connection_manager_->GetAndAdvanceNextConnectionId()),
- url_(url),
- creator_id_(creator_id),
- creator_url_(creator_url),
- delete_on_connection_error_(false),
- service_provider_(service_provider.Pass()) {
- CHECK(GetView(root_id));
- roots_.insert(ViewIdToTransportId(root_id));
- if (root_id == RootViewId())
- access_policy_.reset(new WindowManagerAccessPolicy(id_, this));
- else
- access_policy_.reset(new DefaultAccessPolicy(id_, this));
-}
-
-ViewManagerServiceImpl::~ViewManagerServiceImpl() {
- // Delete any views we created.
- if (!view_map_.empty()) {
- ConnectionManager::ScopedChange change(this, connection_manager_, true);
- while (!view_map_.empty())
- delete view_map_.begin()->second;
- }
-
- connection_manager_->RemoveConnection(this);
-}
-
-const ServerView* ViewManagerServiceImpl::GetView(const ViewId& id) const {
- if (id_ == id.connection_id) {
- ViewMap::const_iterator i = view_map_.find(id.view_id);
- return i == view_map_.end() ? NULL : i->second;
- }
- return connection_manager_->GetView(id);
-}
-
-bool ViewManagerServiceImpl::HasRoot(const ViewId& id) const {
- return roots_.find(ViewIdToTransportId(id)) != roots_.end();
-}
-
-void ViewManagerServiceImpl::OnViewManagerServiceImplDestroyed(
- ConnectionSpecificId id) {
- if (creator_id_ == id)
- creator_id_ = kInvalidConnectionId;
-}
-
-void ViewManagerServiceImpl::ProcessViewBoundsChanged(
- const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- bool originated_change) {
- if (originated_change || !IsViewKnown(view))
- return;
- client()->OnViewBoundsChanged(ViewIdToTransportId(view->id()),
- Rect::From(old_bounds),
- Rect::From(new_bounds));
-}
-
-void ViewManagerServiceImpl::ProcessWillChangeViewHierarchy(
- const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent,
- bool originated_change) {
- if (originated_change)
- return;
-
- const bool old_drawn = view->IsDrawn(connection_manager_->root());
- const bool new_drawn = view->visible() && new_parent &&
- new_parent->IsDrawn(connection_manager_->root());
- if (old_drawn == new_drawn)
- return;
-
- NotifyDrawnStateChanged(view, new_drawn);
-}
-
-void ViewManagerServiceImpl::ProcessViewHierarchyChanged(
- const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent,
- bool originated_change) {
- if (originated_change && !IsViewKnown(view) && new_parent &&
- IsViewKnown(new_parent)) {
- std::vector<const ServerView*> unused;
- GetUnknownViewsFrom(view, &unused);
- }
- if (originated_change || connection_manager_->is_processing_delete_view() ||
- connection_manager_->DidConnectionMessageClient(id_)) {
- return;
- }
-
- if (!access_policy_->ShouldNotifyOnHierarchyChange(
- view, &new_parent, &old_parent)) {
- return;
- }
- // Inform the client of any new views and update the set of views we know
- // about.
- std::vector<const ServerView*> to_send;
- if (!IsViewKnown(view))
- GetUnknownViewsFrom(view, &to_send);
- const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId());
- const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId());
- client()->OnViewHierarchyChanged(ViewIdToTransportId(view->id()),
- ViewIdToTransportId(new_parent_id),
- ViewIdToTransportId(old_parent_id),
- ViewsToViewDatas(to_send));
- connection_manager_->OnConnectionMessagedClient(id_);
-}
-
-void ViewManagerServiceImpl::ProcessViewReorder(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction,
- bool originated_change) {
- if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view))
- return;
-
- client()->OnViewReordered(ViewIdToTransportId(view->id()),
- ViewIdToTransportId(relative_view->id()),
- direction);
-}
-
-void ViewManagerServiceImpl::ProcessViewDeleted(const ViewId& view,
- bool originated_change) {
- view_map_.erase(view.view_id);
-
- const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0;
- roots_.erase(ViewIdToTransportId(view));
-
- if (originated_change)
- return;
-
- if (in_known) {
- client()->OnViewDeleted(ViewIdToTransportId(view));
- connection_manager_->OnConnectionMessagedClient(id_);
- }
-}
-
-void ViewManagerServiceImpl::ProcessWillChangeViewVisibility(
- const ServerView* view,
- bool originated_change) {
- if (originated_change)
- return;
-
- if (IsViewKnown(view)) {
- client()->OnViewVisibilityChanged(ViewIdToTransportId(view->id()),
- !view->visible());
- return;
- }
-
- bool view_target_drawn_state;
- if (view->visible()) {
- // View is being hidden, won't be drawn.
- view_target_drawn_state = false;
- } else {
- // View is being shown. View will be drawn if its parent is drawn.
- view_target_drawn_state =
- view->parent() && view->parent()->IsDrawn(connection_manager_->root());
- }
-
- NotifyDrawnStateChanged(view, view_target_drawn_state);
-}
-
-void ViewManagerServiceImpl::OnConnectionError() {
- if (delete_on_connection_error_)
- delete this;
-}
-
-bool ViewManagerServiceImpl::IsViewKnown(const ServerView* view) const {
- return known_views_.count(ViewIdToTransportId(view->id())) > 0;
-}
-
-bool ViewManagerServiceImpl::CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const {
- if (!view || !relative_view)
- return false;
-
- if (!view->parent() || view->parent() != relative_view->parent())
- return false;
-
- if (!access_policy_->CanReorderView(view, relative_view, direction))
- return false;
-
- std::vector<const ServerView*> children = view->parent()->GetChildren();
- const size_t child_i =
- std::find(children.begin(), children.end(), view) - children.begin();
- const size_t target_i =
- std::find(children.begin(), children.end(), relative_view) -
- children.begin();
- if ((direction == ORDER_DIRECTION_ABOVE && child_i == target_i + 1) ||
- (direction == ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) {
- return false;
- }
-
- return true;
-}
-
-bool ViewManagerServiceImpl::DeleteViewImpl(ViewManagerServiceImpl* source,
- ServerView* view) {
- DCHECK(view);
- DCHECK_EQ(view->id().connection_id, id_);
- ConnectionManager::ScopedChange change(source, connection_manager_, true);
- delete view;
- return true;
-}
-
-void ViewManagerServiceImpl::GetUnknownViewsFrom(
- const ServerView* view,
- std::vector<const ServerView*>* views) {
- if (IsViewKnown(view) || !access_policy_->CanGetViewTree(view))
- return;
- views->push_back(view);
- known_views_.insert(ViewIdToTransportId(view->id()));
- if (!access_policy_->CanDescendIntoViewForViewTree(view))
- return;
- std::vector<const ServerView*> children(view->GetChildren());
- for (size_t i = 0 ; i < children.size(); ++i)
- GetUnknownViewsFrom(children[i], views);
-}
-
-void ViewManagerServiceImpl::RemoveFromKnown(
- const ServerView* view,
- std::vector<ServerView*>* local_views) {
- if (view->id().connection_id == id_) {
- if (local_views)
- local_views->push_back(GetView(view->id()));
- return;
- }
- known_views_.erase(ViewIdToTransportId(view->id()));
- std::vector<const ServerView*> children = view->GetChildren();
- for (size_t i = 0; i < children.size(); ++i)
- RemoveFromKnown(children[i], local_views);
-}
-
-void ViewManagerServiceImpl::RemoveRoot(const ViewId& view_id) {
- const Id transport_view_id(ViewIdToTransportId(view_id));
- CHECK(roots_.count(transport_view_id) > 0);
-
- roots_.erase(transport_view_id);
-
- // No need to do anything if we created the view.
- if (view_id.connection_id == id_)
- return;
-
- client()->OnViewDeleted(transport_view_id);
- connection_manager_->OnConnectionMessagedClient(id_);
-
- // This connection no longer knows about the view. Unparent any views that
- // were parented to views in the root.
- std::vector<ServerView*> local_views;
- RemoveFromKnown(GetView(view_id), &local_views);
- for (size_t i = 0; i < local_views.size(); ++i)
- local_views[i]->parent()->Remove(local_views[i]);
-}
-
-void ViewManagerServiceImpl::RemoveChildrenAsPartOfEmbed(
- const ViewId& view_id) {
- ServerView* view = GetView(view_id);
- CHECK(view);
- CHECK(view->id().connection_id == view_id.connection_id);
- std::vector<ServerView*> children = view->GetChildren();
- for (size_t i = 0; i < children.size(); ++i)
- view->Remove(children[i]);
-}
-
-Array<ViewDataPtr> ViewManagerServiceImpl::ViewsToViewDatas(
- const std::vector<const ServerView*>& views) {
- Array<ViewDataPtr> array(views.size());
- for (size_t i = 0; i < views.size(); ++i)
- array[i] = ViewToViewData(views[i]).Pass();
- return array.Pass();
-}
-
-ViewDataPtr ViewManagerServiceImpl::ViewToViewData(const ServerView* view) {
- DCHECK(IsViewKnown(view));
- const ServerView* parent = view->parent();
- // If the parent isn't known, it means the parent is not visible to us (not
- // in roots), and should not be sent over.
- if (parent && !IsViewKnown(parent))
- parent = NULL;
- ViewDataPtr view_data(ViewData::New());
- view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId());
- view_data->view_id = ViewIdToTransportId(view->id());
- view_data->bounds = Rect::From(view->bounds());
- view_data->visible = view->visible();
- view_data->drawn = view->IsDrawn(connection_manager_->root());
- return view_data.Pass();
-}
-
-void ViewManagerServiceImpl::GetViewTreeImpl(
- const ServerView* view,
- std::vector<const ServerView*>* views) const {
- DCHECK(view);
-
- if (!access_policy_->CanGetViewTree(view))
- return;
-
- views->push_back(view);
-
- if (!access_policy_->CanDescendIntoViewForViewTree(view))
- return;
-
- std::vector<const ServerView*> children(view->GetChildren());
- for (size_t i = 0 ; i < children.size(); ++i)
- GetViewTreeImpl(children[i], views);
-}
-
-void ViewManagerServiceImpl::NotifyDrawnStateChanged(const ServerView* view,
- bool new_drawn_value) {
- // Even though we don't know about view, it may be an ancestor of one of our
- // roots, in which case the change may effect our roots drawn state.
- for (ViewIdSet::iterator i = roots_.begin(); i != roots_.end(); ++i) {
- const ServerView* root = GetView(ViewIdFromTransportId(*i));
- DCHECK(root);
- if (view->Contains(root) &&
- (new_drawn_value != root->IsDrawn(connection_manager_->root()))) {
- client()->OnViewDrawnStateChanged(ViewIdToTransportId(root->id()),
- new_drawn_value);
- }
- }
-}
-
-void ViewManagerServiceImpl::CreateView(
- Id transport_view_id,
- const Callback<void(ErrorCode)>& callback) {
- const ViewId view_id(ViewIdFromTransportId(transport_view_id));
- ErrorCode error_code = ERROR_CODE_NONE;
- if (view_id.connection_id != id_) {
- error_code = ERROR_CODE_ILLEGAL_ARGUMENT;
- } else if (view_map_.find(view_id.view_id) != view_map_.end()) {
- error_code = ERROR_CODE_VALUE_IN_USE;
- } else {
- view_map_[view_id.view_id] = new ServerView(connection_manager_, view_id);
- known_views_.insert(transport_view_id);
- }
- callback.Run(error_code);
-}
-
-void ViewManagerServiceImpl::DeleteView(
- Id transport_view_id,
- const Callback<void(bool)>& callback) {
- ServerView* view = GetView(ViewIdFromTransportId(transport_view_id));
- bool success = false;
- if (view && access_policy_->CanDeleteView(view)) {
- ViewManagerServiceImpl* connection =
- connection_manager_->GetConnection(view->id().connection_id);
- success = connection && connection->DeleteViewImpl(this, view);
- }
- callback.Run(success);
-}
-
-void ViewManagerServiceImpl::AddView(
- Id parent_id,
- Id child_id,
- const Callback<void(bool)>& callback) {
- bool success = false;
- ServerView* parent = GetView(ViewIdFromTransportId(parent_id));
- ServerView* child = GetView(ViewIdFromTransportId(child_id));
- if (parent && child && child->parent() != parent &&
- !child->Contains(parent) && access_policy_->CanAddView(parent, child)) {
- success = true;
- ConnectionManager::ScopedChange change(this, connection_manager_, false);
- parent->Add(child);
- }
- callback.Run(success);
-}
-
-void ViewManagerServiceImpl::RemoveViewFromParent(
- Id view_id,
- const Callback<void(bool)>& callback) {
- bool success = false;
- ServerView* view = GetView(ViewIdFromTransportId(view_id));
- if (view && view->parent() && access_policy_->CanRemoveViewFromParent(view)) {
- success = true;
- ConnectionManager::ScopedChange change(this, connection_manager_, false);
- view->parent()->Remove(view);
- }
- callback.Run(success);
-}
-
-void ViewManagerServiceImpl::ReorderView(Id view_id,
- Id relative_view_id,
- OrderDirection direction,
- const Callback<void(bool)>& callback) {
- bool success = false;
- ServerView* view = GetView(ViewIdFromTransportId(view_id));
- ServerView* relative_view = GetView(ViewIdFromTransportId(relative_view_id));
- if (CanReorderView(view, relative_view, direction)) {
- success = true;
- ConnectionManager::ScopedChange change(this, connection_manager_, false);
- view->parent()->Reorder(view, relative_view, direction);
- connection_manager_->ProcessViewReorder(view, relative_view, direction);
- }
- callback.Run(success);
-}
-
-void ViewManagerServiceImpl::GetViewTree(
- Id view_id,
- const Callback<void(Array<ViewDataPtr>)>& callback) {
- ServerView* view = GetView(ViewIdFromTransportId(view_id));
- std::vector<const ServerView*> views;
- if (view) {
- GetViewTreeImpl(view, &views);
- // TODO(sky): this should map in views that weren't none.
- }
- callback.Run(ViewsToViewDatas(views));
-}
-
-void ViewManagerServiceImpl::SetViewSurfaceId(
- Id view_id,
- SurfaceIdPtr surface_id,
- const Callback<void(bool)>& callback) {
- // TODO(sky): add coverage of not being able to set for random node.
- ServerView* view = GetView(ViewIdFromTransportId(view_id));
- if (!view || !access_policy_->CanSetViewSurfaceId(view)) {
- callback.Run(false);
- return;
- }
- view->SetSurfaceId(surface_id.To<cc::SurfaceId>());
- callback.Run(true);
-}
-
-void ViewManagerServiceImpl::SetViewBounds(
- Id view_id,
- RectPtr bounds,
- const Callback<void(bool)>& callback) {
- ServerView* view = GetView(ViewIdFromTransportId(view_id));
- const bool success = view && access_policy_->CanSetViewBounds(view);
- if (success) {
- ConnectionManager::ScopedChange change(this, connection_manager_, false);
- view->SetBounds(bounds.To<gfx::Rect>());
- }
- callback.Run(success);
-}
-
-void ViewManagerServiceImpl::SetViewVisibility(
- Id transport_view_id,
- bool visible,
- const Callback<void(bool)>& callback) {
- ServerView* view = GetView(ViewIdFromTransportId(transport_view_id));
- if (!view || view->visible() == visible ||
- !access_policy_->CanChangeViewVisibility(view)) {
- callback.Run(false);
- return;
- }
- {
- ConnectionManager::ScopedChange change(this, connection_manager_, false);
- view->SetVisible(visible);
- }
- callback.Run(true);
-}
-
-void ViewManagerServiceImpl::Embed(
- const String& url,
- Id transport_view_id,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback) {
- InterfaceRequest<ServiceProvider> spir;
- spir.Bind(service_provider.PassMessagePipe());
-
- if (ViewIdFromTransportId(transport_view_id) == InvalidViewId()) {
- connection_manager_->Embed(url, spir.Pass());
- callback.Run(true);
- return;
- }
- const ServerView* view = GetView(ViewIdFromTransportId(transport_view_id));
- if (!view || !access_policy_->CanEmbed(view)) {
- callback.Run(false);
- return;
- }
-
- // Only allow a node to be the root for one connection.
- const ViewId view_id(ViewIdFromTransportId(transport_view_id));
- ViewManagerServiceImpl* existing_owner =
- connection_manager_->GetConnectionWithRoot(view_id);
-
- ConnectionManager::ScopedChange change(this, connection_manager_, true);
- RemoveChildrenAsPartOfEmbed(view_id);
- if (existing_owner) {
- // Never message the originating connection.
- connection_manager_->OnConnectionMessagedClient(id_);
- existing_owner->RemoveRoot(view_id);
- }
- connection_manager_->EmbedAtView(id_, url, transport_view_id, spir.Pass());
- callback.Run(true);
-}
-
-void ViewManagerServiceImpl::OnConnectionEstablished() {
- connection_manager_->AddConnection(this);
-
- std::vector<const ServerView*> to_send;
- for (ViewIdSet::const_iterator i = roots_.begin(); i != roots_.end(); ++i)
- GetUnknownViewsFrom(GetView(ViewIdFromTransportId(*i)), &to_send);
-
- client()->OnEmbed(id_,
- creator_url_,
- ViewToViewData(to_send.front()),
- service_provider_.Pass());
-}
-
-const base::hash_set<Id>&
-ViewManagerServiceImpl::GetRootsForAccessPolicy() const {
- return roots_;
-}
-
-bool ViewManagerServiceImpl::IsViewKnownForAccessPolicy(
- const ServerView* view) const {
- return IsViewKnown(view);
-}
-
-bool ViewManagerServiceImpl::IsViewRootOfAnotherConnectionForAccessPolicy(
- const ServerView* view) const {
- ViewManagerServiceImpl* connection =
- connection_manager_->GetConnectionWithRoot(view->id());
- return connection && connection != this;
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/view_manager_service_impl.h b/mojo/services/view_manager/view_manager_service_impl.h
deleted file mode 100644
index bb15fcd..0000000
--- a/mojo/services/view_manager/view_manager_service_impl.h
+++ /dev/null
@@ -1,235 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
-#define MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
-
-#include <set>
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "base/containers/hash_tables.h"
-#include "base/memory/scoped_ptr.h"
-#include "mojo/services/public/interfaces/surfaces/surface_id.mojom.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/view_manager/access_policy_delegate.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace gfx {
-class Rect;
-}
-
-namespace mojo {
-namespace service {
-
-class AccessPolicy;
-class ConnectionManager;
-class ServerView;
-
-#if defined(OS_WIN)
-// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
-// below.
-#pragma warning(push)
-#pragma warning(disable : 4275)
-#endif
-
-// Manages a connection from the client.
-class MOJO_VIEW_MANAGER_EXPORT ViewManagerServiceImpl
- : public InterfaceImpl<ViewManagerService>,
- public AccessPolicyDelegate {
- public:
- ViewManagerServiceImpl(ConnectionManager* connection_manager,
- ConnectionSpecificId creator_id,
- const std::string& creator_url,
- const std::string& url,
- const ViewId& root_id,
- InterfaceRequest<ServiceProvider> service_provider);
- ~ViewManagerServiceImpl() override;
-
- // Used to mark this connection as originating from a call to
- // ViewManagerService::Connect(). When set OnConnectionError() deletes |this|.
- void set_delete_on_connection_error() { delete_on_connection_error_ = true; }
-
- ConnectionSpecificId id() const { return id_; }
- ConnectionSpecificId creator_id() const { return creator_id_; }
- const std::string& url() const { return url_; }
-
- // Returns the View with the specified id.
- ServerView* GetView(const ViewId& id) {
- return const_cast<ServerView*>(
- const_cast<const ViewManagerServiceImpl*>(this)->GetView(id));
- }
- const ServerView* GetView(const ViewId& id) const;
-
- // Returns true if this has |id| as a root.
- bool HasRoot(const ViewId& id) const;
-
- // Invoked when a connection is destroyed.
- void OnViewManagerServiceImplDestroyed(ConnectionSpecificId id);
-
- // The following methods are invoked after the corresponding change has been
- // processed. They do the appropriate bookkeeping and update the client as
- // necessary.
- void ProcessViewBoundsChanged(const ServerView* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds,
- bool originated_change);
- void ProcessWillChangeViewHierarchy(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent,
- bool originated_change);
- void ProcessViewHierarchyChanged(const ServerView* view,
- const ServerView* new_parent,
- const ServerView* old_parent,
- bool originated_change);
- void ProcessViewReorder(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction,
- bool originated_change);
- void ProcessViewDeleted(const ViewId& view, bool originated_change);
- void ProcessWillChangeViewVisibility(const ServerView* view,
- bool originated_change);
-
- // TODO(sky): move this to private section (currently can't because of
- // bindings).
- // InterfaceImp overrides:
- void OnConnectionError() override;
-
- private:
- typedef std::map<ConnectionSpecificId, ServerView*> ViewMap;
- typedef base::hash_set<Id> ViewIdSet;
-
- bool IsViewKnown(const ServerView* view) const;
-
- // These functions return true if the corresponding mojom function is allowed
- // for this connection.
- bool CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const;
-
- // Deletes a view owned by this connection. Returns true on success. |source|
- // is the connection that originated the change.
- bool DeleteViewImpl(ViewManagerServiceImpl* source, ServerView* view);
-
- // If |view| is known (in |known_views_|) does nothing. Otherwise adds |view|
- // to |views|, marks |view| as known and recurses.
- void GetUnknownViewsFrom(const ServerView* view,
- std::vector<const ServerView*>* views);
-
- // Removes |view| and all its descendants from |known_views_|. This does not
- // recurse through views that were created by this connection. All views owned
- // by this connection are added to |local_views|.
- void RemoveFromKnown(const ServerView* view,
- std::vector<ServerView*>* local_views);
-
- // Removes |view_id| from the set of roots this connection knows about.
- void RemoveRoot(const ViewId& view_id);
-
- void RemoveChildrenAsPartOfEmbed(const ViewId& view_id);
-
- // Converts View(s) to ViewData(s) for transport. This assumes all the views
- // are valid for the client. The parent of views the client is not allowed to
- // see are set to NULL (in the returned ViewData(s)).
- Array<ViewDataPtr> ViewsToViewDatas(
- const std::vector<const ServerView*>& views);
- ViewDataPtr ViewToViewData(const ServerView* view);
-
- // Implementation of GetViewTree(). Adds |view| to |views| and recurses if
- // CanDescendIntoViewForViewTree() returns true.
- void GetViewTreeImpl(const ServerView* view,
- std::vector<const ServerView*>* views) const;
-
- // Notify the client if the drawn state of any of the roots changes.
- // |view| is the view that is changing to the drawn state |new_drawn_value|.
- void NotifyDrawnStateChanged(const ServerView* view, bool new_drawn_value);
-
- // ViewManagerService:
- void CreateView(Id transport_view_id,
- const Callback<void(ErrorCode)>& callback) override;
- void DeleteView(Id transport_view_id,
- const Callback<void(bool)>& callback) override;
- void AddView(Id parent_id,
- Id child_id,
- const Callback<void(bool)>& callback) override;
- void RemoveViewFromParent(Id view_id,
- const Callback<void(bool)>& callback) override;
- void ReorderView(Id view_id,
- Id relative_view_id,
- OrderDirection direction,
- const Callback<void(bool)>& callback) override;
- void GetViewTree(Id view_id,
- const Callback<void(Array<ViewDataPtr>)>& callback) override;
- void SetViewSurfaceId(Id view_id,
- SurfaceIdPtr surface_id,
- const Callback<void(bool)>& callback) override;
- void SetViewBounds(Id view_id,
- RectPtr bounds,
- const Callback<void(bool)>& callback) override;
- void SetViewVisibility(Id view_id,
- bool visible,
- const Callback<void(bool)>& callback) override;
- void Embed(const String& url,
- Id view_id,
- ServiceProviderPtr service_provider,
- const Callback<void(bool)>& callback) override;
-
- // InterfaceImpl:
- void OnConnectionEstablished() override;
-
- // AccessPolicyDelegate:
- const base::hash_set<Id>& GetRootsForAccessPolicy() const override;
- bool IsViewKnownForAccessPolicy(const ServerView* view) const override;
- bool IsViewRootOfAnotherConnectionForAccessPolicy(
- const ServerView* view) const override;
-
- ConnectionManager* connection_manager_;
-
- // Id of this connection as assigned by ConnectionManager.
- const ConnectionSpecificId id_;
-
- // URL this connection was created for.
- const std::string url_;
-
- // ID of the connection that created us. If 0 it indicates either we were
- // created by the root, or the connection that created us has been destroyed.
- ConnectionSpecificId creator_id_;
-
- // The URL of the app that embedded the app this connection was created for.
- const std::string creator_url_;
-
- scoped_ptr<AccessPolicy> access_policy_;
-
- // The views and views created by this connection. This connection owns these
- // objects.
- ViewMap view_map_;
-
- // The set of views that has been communicated to the client.
- ViewIdSet known_views_;
-
- // Set of root views from other connections. More specifically any time
- // Embed() is invoked the id of the view is added to this set for the child
- // connection. The connection Embed() was invoked on (the parent) doesn't
- // directly track which connections are attached to which of its views. That
- // information can be found by looking through the |roots_| of all
- // connections.
- ViewIdSet roots_;
-
- // See description above setter.
- bool delete_on_connection_error_;
-
- InterfaceRequest<ServiceProvider> service_provider_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerServiceImpl);
-};
-
-#if defined(OS_WIN)
-#pragma warning(pop)
-#endif
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_VIEW_MANAGER_SERVICE_IMPL_H_
diff --git a/mojo/services/view_manager/view_manager_unittest.cc b/mojo/services/view_manager/view_manager_unittest.cc
deleted file mode 100644
index 073ad4c..0000000
--- a/mojo/services/view_manager/view_manager_unittest.cc
+++ /dev/null
@@ -1,1481 +0,0 @@
-// Copyright 2014 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 <string>
-#include <vector>
-
-#include "base/at_exit.h"
-#include "base/auto_reset.h"
-#include "base/bind.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "base/message_loop/message_loop.h"
-#include "base/run_loop.h"
-#include "base/strings/stringprintf.h"
-#include "mojo/application_manager/application_manager.h"
-#include "mojo/common/common_type_converters.h"
-#include "mojo/converters/geometry/geometry_type_converters.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/connect.h"
-#include "mojo/public/cpp/application/interface_factory_impl.h"
-#include "mojo/public/cpp/bindings/lib/router.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-#include "mojo/services/public/cpp/native_viewport/args.h"
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/cpp/view_manager/util.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/test_change_tracker.h"
-#include "mojo/shell/shell_test_helper.h"
-#include "testing/gtest/include/gtest/gtest.h"
-#include "ui/gfx/geometry/rect.h"
-
-#if defined(OS_WIN)
-#include "ui/gfx/win/window_impl.h"
-#endif
-
-namespace mojo {
-namespace service {
-
-namespace {
-
-const char kTestServiceURL[] = "mojo:test_url";
-const char kTestServiceURL2[] = "mojo:test_url2";
-
-// ViewManagerProxy is a proxy to an ViewManagerService. It handles invoking
-// ViewManagerService functions on the right thread in a synchronous manner
-// (each ViewManagerService cover function blocks until the response from the
-// ViewManagerService is returned). In addition it tracks the set of
-// ViewManagerClient messages received by way of a vector of Changes. Use
-// DoRunLoopUntilChangesCount() to wait for a certain number of messages to be
-// received.
-class ViewManagerProxy : public TestChangeTracker::Delegate {
- public:
- explicit ViewManagerProxy(TestChangeTracker* tracker)
- : tracker_(tracker),
- main_loop_(nullptr),
- view_manager_(nullptr),
- window_manager_client_(nullptr),
- quit_count_(0),
- router_(nullptr) {
- SetInstance(this);
- }
-
- ~ViewManagerProxy() override {}
-
- // Returns true if in an initial state. If this returns false it means the
- // last test didn't clean up properly, or most likely didn't invoke
- // WaitForInstance() when it needed to.
- static bool IsInInitialState() { return instance_ == NULL; }
-
- // Runs a message loop until the single instance has been created.
- static ViewManagerProxy* WaitForInstance() {
- if (!instance_)
- RunMainLoop();
- ViewManagerProxy* instance = instance_;
- instance_ = NULL;
- return instance;
- }
-
- ViewManagerService* view_manager() { return view_manager_; }
- WindowManagerClient* window_manager_client() {
- return window_manager_client_;
- }
-
- // Runs the main loop until |count| changes have been received.
- std::vector<Change> DoRunLoopUntilChangesCount(size_t count) {
- DCHECK_EQ(0u, quit_count_);
- if (tracker_->changes()->size() >= count) {
- CopyChangesFromTracker();
- return changes_;
- }
- quit_count_ = count - tracker_->changes()->size();
- // Run the current message loop. When |count| Changes have been received,
- // we'll quit.
- RunMainLoop();
- return changes_;
- }
-
- const std::vector<Change>& changes() const { return changes_; }
-
- // Destroys the connection, blocking until done.
- void Destroy() {
- router_->CloseMessagePipe();
- }
-
- void ClearChanges() {
- changes_.clear();
- tracker_->changes()->clear();
- }
-
- void CopyChangesFromTracker() {
- std::vector<Change> changes;
- tracker_->changes()->swap(changes);
- changes_.swap(changes);
- }
-
- // The following functions are cover methods for ViewManagerService. They
- // block until the result is received.
- bool CreateView(Id view_id) {
- changes_.clear();
- ErrorCode result = ERROR_CODE_NONE;
- view_manager_->CreateView(
- view_id,
- base::Bind(&ViewManagerProxy::GotResultWithErrorCode,
- base::Unretained(this),
- &result));
- RunMainLoop();
- return result == ERROR_CODE_NONE;
- }
- ErrorCode CreateViewWithErrorCode(Id view_id) {
- changes_.clear();
- ErrorCode result = ERROR_CODE_NONE;
- view_manager_->CreateView(
- view_id,
- base::Bind(&ViewManagerProxy::GotResultWithErrorCode,
- base::Unretained(this),
- &result));
- RunMainLoop();
- return result;
- }
- bool AddView(Id parent, Id child) {
- changes_.clear();
- bool result = false;
- view_manager_->AddView(parent, child,
- base::Bind(&ViewManagerProxy::GotResult,
- base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- bool RemoveViewFromParent(Id view_id) {
- changes_.clear();
- bool result = false;
- view_manager_->RemoveViewFromParent(
- view_id,
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- bool ReorderView(Id view_id, Id relative_view_id, OrderDirection direction) {
- changes_.clear();
- bool result = false;
- view_manager_->ReorderView(
- view_id,
- relative_view_id,
- direction,
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- void GetViewTree(Id view_id, std::vector<TestView>* views) {
- changes_.clear();
- view_manager_->GetViewTree(
- view_id,
- base::Bind(
- &ViewManagerProxy::GotViewTree, base::Unretained(this), views));
- RunMainLoop();
- }
- bool Embed(const Id view_id, const char* url) {
- changes_.clear();
- base::AutoReset<bool> auto_reset(&in_embed_, true);
- bool result = false;
- ServiceProviderPtr services;
- view_manager_->Embed(
- url,
- view_id,
- services.Pass(),
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- bool DeleteView(Id view_id) {
- changes_.clear();
- bool result = false;
- view_manager_->DeleteView(
- view_id,
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- bool SetViewBounds(Id view_id, const gfx::Rect& bounds) {
- changes_.clear();
- bool result = false;
- view_manager_->SetViewBounds(
- view_id,
- Rect::From(bounds),
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
- bool SetViewVisibility(Id view_id, bool visible) {
- changes_.clear();
- bool result = false;
- view_manager_->SetViewVisibility(
- view_id,
- visible,
- base::Bind(
- &ViewManagerProxy::GotResult, base::Unretained(this), &result));
- RunMainLoop();
- return result;
- }
-
- private:
- friend class TestViewManagerClientConnection;
- friend class WindowManagerServiceImpl;
-
- void set_router(mojo::internal::Router* router) { router_ = router; }
-
- void set_view_manager(ViewManagerService* view_manager) {
- view_manager_ = view_manager;
- }
-
- void set_window_manager_client(WindowManagerClient* client) {
- window_manager_client_ = client;
- }
-
- static void RunMainLoop() {
- DCHECK(!main_run_loop_);
- main_run_loop_ = new base::RunLoop;
- main_run_loop_->Run();
- delete main_run_loop_;
- main_run_loop_ = NULL;
- }
-
- void QuitCountReached() {
- CopyChangesFromTracker();
- main_run_loop_->Quit();
- }
-
- static void SetInstance(ViewManagerProxy* instance) {
- DCHECK(!instance_);
- instance_ = instance;
- // Embed() runs its own run loop that is quit when the result is
- // received. Embed() also results in a new instance. If we quit here while
- // waiting for a Embed() we would prematurely return before we got the
- // result from Embed().
- if (!in_embed_ && main_run_loop_)
- main_run_loop_->Quit();
- }
-
- // Callbacks from the various ViewManagerService functions.
- void GotResult(bool* result_cache, bool result) {
- *result_cache = result;
- DCHECK(main_run_loop_);
- main_run_loop_->Quit();
- }
-
- void GotResultWithErrorCode(ErrorCode* error_code_cache,
- ErrorCode error_code) {
- *error_code_cache = error_code;
- DCHECK(main_run_loop_);
- main_run_loop_->Quit();
- }
-
- void GotViewTree(std::vector<TestView>* views, Array<ViewDataPtr> results) {
- ViewDatasToTestViews(results, views);
- DCHECK(main_run_loop_);
- main_run_loop_->Quit();
- }
-
- // TestChangeTracker::Delegate:
- void OnChangeAdded() override {
- if (quit_count_ > 0 && --quit_count_ == 0)
- QuitCountReached();
- }
-
- static ViewManagerProxy* instance_;
- static base::RunLoop* main_run_loop_;
- static bool in_embed_;
-
- TestChangeTracker* tracker_;
-
- // MessageLoop of the test.
- base::MessageLoop* main_loop_;
-
- ViewManagerService* view_manager_;
- WindowManagerClient* window_manager_client_;
-
- // Number of changes we're waiting on until we quit the current loop.
- size_t quit_count_;
-
- std::vector<Change> changes_;
-
- mojo::internal::Router* router_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerProxy);
-};
-
-// static
-ViewManagerProxy* ViewManagerProxy::instance_ = NULL;
-
-// static
-base::RunLoop* ViewManagerProxy::main_run_loop_ = NULL;
-
-// static
-bool ViewManagerProxy::in_embed_ = false;
-
-class TestViewManagerClientConnection
- : public InterfaceImpl<ViewManagerClient> {
- public:
- TestViewManagerClientConnection() : proxy_(&tracker_) {
- tracker_.set_delegate(&proxy_);
- }
-
- TestChangeTracker* tracker() { return &tracker_; }
-
- ViewManagerProxy* proxy() { return &proxy_; }
-
- // InterfaceImpl:
- void OnConnectionEstablished() override {
- proxy_.set_router(internal_state()->router());
- proxy_.set_view_manager(client());
- }
-
- // ViewManagerClient:
- void OnEmbed(ConnectionSpecificId connection_id,
- const String& creator_url,
- ViewDataPtr root,
- InterfaceRequest<ServiceProvider> services) override {
- tracker_.OnEmbed(connection_id, creator_url, root.Pass());
- }
- void OnViewBoundsChanged(Id view_id,
- RectPtr old_bounds,
- RectPtr new_bounds) override {
- tracker_.OnViewBoundsChanged(view_id, old_bounds.Pass(), new_bounds.Pass());
- }
- void OnViewHierarchyChanged(Id view,
- Id new_parent,
- Id old_parent,
- Array<ViewDataPtr> views) override {
- tracker_.OnViewHierarchyChanged(view, new_parent, old_parent, views.Pass());
- }
- void OnViewReordered(Id view_id,
- Id relative_view_id,
- OrderDirection direction) override {
- tracker_.OnViewReordered(view_id, relative_view_id, direction);
- }
- void OnViewDeleted(Id view) override { tracker_.OnViewDeleted(view); }
- void OnViewVisibilityChanged(uint32_t view, bool visible) override {
- tracker_.OnViewVisibilityChanged(view, visible);
- }
- void OnViewDrawnStateChanged(uint32_t view, bool drawn) override {
- tracker_.OnViewDrawnStateChanged(view, drawn);
- }
- void OnViewInputEvent(Id view_id,
- EventPtr event,
- const Callback<void()>& callback) override {
- tracker_.OnViewInputEvent(view_id, event.Pass());
- }
-
- private:
- TestChangeTracker tracker_;
- ViewManagerProxy proxy_;
-
- DISALLOW_COPY_AND_ASSIGN(TestViewManagerClientConnection);
-};
-
-class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> {
- public:
- explicit WindowManagerServiceImpl(TestViewManagerClientConnection* connection)
- : connection_(connection) {}
- ~WindowManagerServiceImpl() override {}
-
- // InterfaceImpl:
- void OnConnectionEstablished() override {
- connection_->proxy()->set_window_manager_client(client());
- }
-
- // WindowManagerService:
- void Embed(const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override {
- connection_->tracker()->DelegateEmbed(url);
- }
- void OnViewInputEvent(mojo::EventPtr event) override {}
-
- private:
- TestViewManagerClientConnection* connection_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl);
-};
-
-// Used with ViewManagerService::Embed(). Creates a
-// TestViewManagerClientConnection, which creates and owns the ViewManagerProxy.
-class EmbedApplicationLoader : public ApplicationLoader,
- ApplicationDelegate,
- public InterfaceFactory<ViewManagerClient>,
- public InterfaceFactory<WindowManagerService> {
- public:
- EmbedApplicationLoader() : last_view_manager_client_(nullptr) {}
- ~EmbedApplicationLoader() override {}
-
- // ApplicationLoader implementation:
- void Load(ApplicationManager* manager,
- const GURL& url,
- scoped_refptr<LoadCallbacks> callbacks) override {
- ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
- if (!shell_handle.is_valid())
- return;
- scoped_ptr<ApplicationImpl> app(new ApplicationImpl(this,
- shell_handle.Pass()));
- apps_.push_back(app.release());
- }
- void OnApplicationError(ApplicationManager* manager,
- const GURL& url) override {}
-
- // ApplicationDelegate implementation:
- bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
- connection->AddService<ViewManagerClient>(this);
- connection->AddService<WindowManagerService>(this);
- return true;
- }
-
- // InterfaceFactory<ViewManagerClient> implementation:
- void Create(ApplicationConnection* connection,
- InterfaceRequest<ViewManagerClient> request) override {
- last_view_manager_client_ = new TestViewManagerClientConnection;
- BindToRequest(last_view_manager_client_, &request);
- }
- void Create(ApplicationConnection* connection,
- InterfaceRequest<WindowManagerService> request) override {
- BindToRequest(new WindowManagerServiceImpl(last_view_manager_client_),
- &request);
- }
-
- private:
- // Used so that TestViewManagerClientConnection and
- // WindowManagerServiceImpl can share the same TestChangeTracker.
- TestViewManagerClientConnection* last_view_manager_client_;
- ScopedVector<ApplicationImpl> apps_;
-
- DISALLOW_COPY_AND_ASSIGN(EmbedApplicationLoader);
-};
-
-// Creates an id used for transport from the specified parameters.
-Id BuildViewId(ConnectionSpecificId connection_id,
- ConnectionSpecificId view_id) {
- return (connection_id << 16) | view_id;
-}
-
-// Callback from Embed(). |result| is the result of the
-// Embed() call and |run_loop| the nested RunLoop.
-void EmbedCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
- *result_cache = result;
- run_loop->Quit();
-}
-
-// Embed from an application that does not yet have a view manager connection.
-// Blocks until result is determined.
-bool InitEmbed(ViewManagerInitService* view_manager_init,
- const std::string& url,
- size_t number_of_calls) {
- bool result = false;
- base::RunLoop run_loop;
- for (size_t i = 0; i < number_of_calls; ++i) {
- ServiceProviderPtr sp;
- view_manager_init->Embed(url, sp.Pass(),
- base::Bind(&EmbedCallback, &result, &run_loop));
- }
- run_loop.Run();
- return result;
-}
-
-} // namespace
-
-typedef std::vector<std::string> Changes;
-
-class ViewManagerTest : public testing::Test {
- public:
- ViewManagerTest()
- : connection_(NULL),
- connection2_(NULL),
- connection3_(NULL) {}
-
- virtual void SetUp() override {
- ASSERT_TRUE(ViewManagerProxy::IsInInitialState());
- test_helper_.Init();
- std::vector<std::string> native_viewport_args;
- native_viewport_args.push_back(kUseTestConfig);
- test_helper_.application_manager()->SetArgsForURL(
- native_viewport_args, GURL("mojo:native_viewport_service"));
- printf("Setting args\n");
-
-#if defined(OS_WIN)
- // As we unload the wndproc of window classes we need to be sure to
- // unregister them.
- gfx::WindowImpl::UnregisterClassesAtExit();
-#endif
-
- test_helper_.SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()),
- GURL(kTestServiceURL));
-
- test_helper_.SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(new EmbedApplicationLoader()),
- GURL(kTestServiceURL2));
-
- test_helper_.application_manager()->ConnectToService(
- GURL("mojo:view_manager"), &view_manager_init_);
- ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
-
- connection_ = ViewManagerProxy::WaitForInstance();
- ASSERT_TRUE(connection_ != NULL);
- connection_->DoRunLoopUntilChangesCount(1);
- }
-
- virtual void TearDown() override {
- if (connection3_)
- connection3_->Destroy();
- if (connection2_)
- connection2_->Destroy();
- if (connection_)
- connection_->Destroy();
- }
-
- protected:
- void EstablishSecondConnectionWithRoot(Id root_id) {
- ASSERT_TRUE(connection_->Embed(root_id, kTestServiceURL));
- connection2_ = ViewManagerProxy::WaitForInstance();
- ASSERT_TRUE(connection2_ != NULL);
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- }
-
- // Creates a second connection to the viewmanager.
- void EstablishSecondConnection(bool create_initial_view) {
- if (create_initial_view)
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_NO_FATAL_FAILURE(
- EstablishSecondConnectionWithRoot(BuildViewId(1, 1)));
- const std::vector<Change>& changes(connection2_->changes());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("OnEmbed creator=mojo:test_url",
- ChangesToDescription1(changes)[0]);
- if (create_initial_view)
- EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes));
- }
-
- void EstablishThirdConnection(ViewManagerProxy* owner, Id root_id) {
- ASSERT_TRUE(connection3_ == NULL);
- ASSERT_TRUE(owner->Embed(root_id, kTestServiceURL2));
- connection3_ = ViewManagerProxy::WaitForInstance();
- ASSERT_TRUE(connection3_ != NULL);
- connection3_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection3_->changes().size());
- EXPECT_EQ("OnEmbed creator=mojo:test_url",
- ChangesToDescription1(connection3_->changes())[0]);
- }
-
- void DestroySecondConnection() {
- connection2_->Destroy();
- connection2_ = NULL;
- }
-
- base::ShadowingAtExitManager at_exit_;
- shell::ShellTestHelper test_helper_;
-
- ViewManagerInitServicePtr view_manager_init_;
-
- // NOTE: this connection is the root. As such, it has special permissions.
- ViewManagerProxy* connection_;
- ViewManagerProxy* connection2_;
- ViewManagerProxy* connection3_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerTest);
-};
-
-TEST_F(ViewManagerTest, SecondEmbedRoot_InitService) {
- ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 1));
- connection_->DoRunLoopUntilChangesCount(1);
- EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
-}
-
-TEST_F(ViewManagerTest, SecondEmbedRoot_Service) {
- ASSERT_TRUE(connection_->Embed(BuildViewId(0, 0), kTestServiceURL));
- connection_->DoRunLoopUntilChangesCount(1);
- EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
-}
-
-TEST_F(ViewManagerTest, MultipleEmbedRootsBeforeWTHReady) {
- ASSERT_TRUE(InitEmbed(view_manager_init_.get(), kTestServiceURL, 2));
- connection_->DoRunLoopUntilChangesCount(2);
- EXPECT_EQ(kTestServiceURL, connection_->changes()[0].embed_url);
- EXPECT_EQ(kTestServiceURL, connection_->changes()[1].embed_url);
-}
-
-// Verifies client gets a valid id.
-// http://crbug.com/396492
-TEST_F(ViewManagerTest, DISABLED_ValidId) {
- // TODO(beng): this should really have the URL of the application that
- // connected to ViewManagerInit.
- EXPECT_EQ("OnEmbed creator=",
- ChangesToDescription1(connection_->changes())[0]);
-
- // All these tests assume 1 for the client id. The only real assertion here is
- // the client id is not zero, but adding this as rest of code here assumes 1.
- EXPECT_EQ(1, connection_->changes()[0].connection_id);
-}
-
-// Verifies two clients/connections get different ids.
-TEST_F(ViewManagerTest, TwoClientsGetDifferentConnectionIds) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
- EXPECT_EQ("OnEmbed creator=mojo:test_url",
- ChangesToDescription1(connection2_->changes())[0]);
-
- // It isn't strictly necessary that the second connection gets 2, but these
- // tests are written assuming that is the case. The key thing is the
- // connection ids of |connection_| and |connection2_| differ.
- EXPECT_EQ(2, connection2_->changes()[0].connection_id);
-}
-
-// Verifies when Embed() is invoked any child views are removed.
-TEST_F(ViewManagerTest, ViewsRemovedWhenEmbedding) {
- // Two views 1 and 2. 2 is parented to 1.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
- EXPECT_EQ("[view=1,1 parent=null]",
- ChangeViewDescription(connection2_->changes()));
-
- // Embed() removed view 2.
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 2), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,2 parent=null", views[0].ToString());
- }
-
- // |connection2_| should not see view 2.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,1 parent=null", views[0].ToString());
- }
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(1, 2), &views);
- EXPECT_TRUE(views.empty());
- }
-
- // Views 3 and 4 in connection 2.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 4)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 3), BuildViewId(2, 4)));
-
- // Connection 3 rooted at 2.
- ASSERT_NO_FATAL_FAILURE(
- EstablishThirdConnection(connection2_, BuildViewId(2, 3)));
-
- // View 4 should no longer have a parent.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(2, 3), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=2,3 parent=null", views[0].ToString());
-
- views.clear();
- connection2_->GetViewTree(BuildViewId(2, 4), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=2,4 parent=null", views[0].ToString());
- }
-
- // And view 4 should not be visible to connection 3.
- {
- std::vector<TestView> views;
- connection3_->GetViewTree(BuildViewId(2, 3), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=2,3 parent=null", views[0].ToString());
- }
-}
-
-// Verifies once Embed() has been invoked the parent connection can't see any
-// children.
-TEST_F(ViewManagerTest, CantAccessChildrenOfEmbeddedView) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
-
- ASSERT_NO_FATAL_FAILURE(
- EstablishThirdConnection(connection2_, BuildViewId(2, 2)));
-
- ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 3)));
- ASSERT_TRUE(connection3_->AddView(BuildViewId(2, 2), BuildViewId(3, 3)));
-
- // Even though 3 is a child of 2 connection 2 can't see 3 as it's from a
- // different connection.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(2, 2), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=2,2 parent=1,1", views[0].ToString());
- }
-
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(3, 3), &views);
- EXPECT_TRUE(views.empty());
- }
-
- // Connection 2 shouldn't be able to get view 3 at all.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(3, 3), &views);
- EXPECT_TRUE(views.empty());
- }
-
- // Connection 1 should be able to see it all (its the root).
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(3u, views.size());
- EXPECT_EQ("view=1,1 parent=null", views[0].ToString());
- EXPECT_EQ("view=2,2 parent=1,1", views[1].ToString());
- EXPECT_EQ("view=3,3 parent=2,2", views[2].ToString());
- }
-}
-
-// Verifies once Embed() has been invoked the parent can't mutate the children.
-TEST_F(ViewManagerTest, CantModifyChildrenOfEmbeddedView) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
-
- ASSERT_NO_FATAL_FAILURE(
- EstablishThirdConnection(connection2_, BuildViewId(2, 2)));
-
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3)));
- // Connection 2 shouldn't be able to add anything to the view anymore.
- ASSERT_FALSE(connection2_->AddView(BuildViewId(2, 2), BuildViewId(2, 3)));
-
- // Create view 3 in connection 3 and add it to view 3.
- ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 3)));
- ASSERT_TRUE(connection3_->AddView(BuildViewId(2, 2), BuildViewId(3, 3)));
-
- // Connection 2 shouldn't be able to remove view 3.
- ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(3, 3)));
-}
-
-// Verifies client gets a valid id.
-TEST_F(ViewManagerTest, CreateView) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- EXPECT_TRUE(connection_->changes().empty());
-
- // Can't create a view with the same id.
- ASSERT_EQ(ERROR_CODE_VALUE_IN_USE,
- connection_->CreateViewWithErrorCode(BuildViewId(1, 1)));
- EXPECT_TRUE(connection_->changes().empty());
-
- // Can't create a view with a bogus connection id.
- EXPECT_EQ(ERROR_CODE_ILLEGAL_ARGUMENT,
- connection_->CreateViewWithErrorCode(BuildViewId(2, 1)));
- EXPECT_TRUE(connection_->changes().empty());
-}
-
-// Verifies AddView fails when view is already in position.
-TEST_F(ViewManagerTest, AddViewWithNoChange) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- // Make 3 a child of 2.
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3)));
-
- // Try again, this should fail.
- EXPECT_FALSE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3)));
-}
-
-// Verifies AddView fails when view is already in position.
-TEST_F(ViewManagerTest, AddAncestorFails) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- // Make 3 a child of 2.
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 3)));
-
- // Try to make 2 a child of 3, this should fail since 2 is an ancestor of 3.
- EXPECT_FALSE(connection_->AddView(BuildViewId(1, 3), BuildViewId(1, 2)));
-}
-
-// Verifies adding to root sends right notifications.
-TEST_F(ViewManagerTest, AddToRoot) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 21)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 3)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- // Make 3 a child of 21.
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 21), BuildViewId(1, 3)));
-
- // Make 21 a child of 1.
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 21)));
-
- // Connection 2 should not be told anything (because the view is from a
- // different connection). Create a view to ensure we got a response from
- // the server.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100)));
- connection2_->CopyChangesFromTracker();
- EXPECT_TRUE(connection2_->changes().empty());
-}
-
-// Verifies HierarchyChanged is correctly sent for various adds/removes.
-TEST_F(ViewManagerTest, ViewHierarchyChangedViews) {
- // 1,2->1,11.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 2), BuildViewId(1, 11)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- // 1,1->1,2->1,11
- {
- // Client 2 should not get anything (1,2 is from another connection).
- connection2_->ClearChanges();
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 100)));
- connection2_->CopyChangesFromTracker();
- EXPECT_TRUE(connection2_->changes().empty());
- }
-
- // 0,1->1,1->1,2->1,11.
- {
- // Client 2 is now connected to the root, so it should have gotten a drawn
- // notification.
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,1 drawn=true",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // 1,1->1,2->1,11.
- {
- // Client 2 is no longer connected to the root, should get drawn state
- // changed.
- ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1)));
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,1 drawn=false",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // 1,1->1,2->1,11->1,111.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 111)));
- {
- connection2_->ClearChanges();
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 11), BuildViewId(1, 111)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 103)));
- connection2_->CopyChangesFromTracker();
- EXPECT_TRUE(connection2_->changes().empty());
- }
-
- // 0,1->1,1->1,2->1,11->1,111
- {
- connection2_->ClearChanges();
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,1 drawn=true",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-}
-
-TEST_F(ViewManagerTest, ViewHierarchyChangedAddingKnownToUnknown) {
- // Create the following structure: root -> 1 -> 11 and 2->21 (2 has no
- // parent).
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 21)));
-
- // Set up the hierarchy.
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 11)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 2), BuildViewId(2, 21)));
-
- // Remove 11, should result in a hierarchy change for the root.
- {
- connection_->ClearChanges();
- ASSERT_TRUE(connection2_->RemoveViewFromParent(BuildViewId(2, 11)));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("HierarchyChanged view=2,11 new_parent=null old_parent=1,1",
- changes[0]);
- }
-
- // Add 2 to 1.
- {
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
- changes[0]);
- EXPECT_EQ(
- "[view=2,2 parent=1,1],"
- "[view=2,21 parent=2,2]",
- ChangeViewDescription(connection_->changes()));
- }
-}
-
-TEST_F(ViewManagerTest, ReorderView) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- Id view1_id = BuildViewId(2, 1);
- Id view2_id = BuildViewId(2, 2);
- Id view3_id = BuildViewId(2, 3);
- Id view4_id = BuildViewId(1, 4); // Peer to 1,1
- Id view5_id = BuildViewId(1, 5); // Peer to 1,1
- Id view6_id = BuildViewId(2, 6); // Child of 1,2.
- Id view7_id = BuildViewId(2, 7); // Unparented.
- Id view8_id = BuildViewId(2, 8); // Unparented.
- ASSERT_TRUE(connection2_->CreateView(view1_id));
- ASSERT_TRUE(connection2_->CreateView(view2_id));
- ASSERT_TRUE(connection2_->CreateView(view3_id));
- ASSERT_TRUE(connection_->CreateView(view4_id));
- ASSERT_TRUE(connection_->CreateView(view5_id));
- ASSERT_TRUE(connection2_->CreateView(view6_id));
- ASSERT_TRUE(connection2_->CreateView(view7_id));
- ASSERT_TRUE(connection2_->CreateView(view8_id));
- ASSERT_TRUE(connection2_->AddView(view1_id, view2_id));
- ASSERT_TRUE(connection2_->AddView(view2_id, view6_id));
- ASSERT_TRUE(connection2_->AddView(view1_id, view3_id));
- ASSERT_TRUE(
- connection_->AddView(ViewIdToTransportId(RootViewId()), view4_id));
- ASSERT_TRUE(
- connection_->AddView(ViewIdToTransportId(RootViewId()), view5_id));
-
- ASSERT_TRUE(
- connection_->AddView(ViewIdToTransportId(RootViewId()), view1_id));
-
- {
- ASSERT_TRUE(
- connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_ABOVE));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=above", changes[0]);
- }
-
- {
- ASSERT_TRUE(
- connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_BELOW));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("Reordered view=2,2 relative=2,3 direction=below", changes[0]);
- }
-
- // view2 is already below view3.
- EXPECT_FALSE(
- connection2_->ReorderView(view2_id, view3_id, ORDER_DIRECTION_BELOW));
-
- // view4 & 5 are unknown to connection2_.
- EXPECT_FALSE(
- connection2_->ReorderView(view4_id, view5_id, ORDER_DIRECTION_ABOVE));
-
- // view6 & view3 have different parents.
- EXPECT_FALSE(
- connection_->ReorderView(view3_id, view6_id, ORDER_DIRECTION_ABOVE));
-
- // Non-existent view-ids
- EXPECT_FALSE(connection_->ReorderView(
- BuildViewId(1, 27), BuildViewId(1, 28), ORDER_DIRECTION_ABOVE));
-
- // view7 & view8 are un-parented.
- EXPECT_FALSE(
- connection_->ReorderView(view7_id, view8_id, ORDER_DIRECTION_ABOVE));
-}
-
-// Verifies DeleteView works.
-TEST_F(ViewManagerTest, DeleteView) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
-
- // Make 2 a child of 1.
- {
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
- changes[0]);
- }
-
- // Delete 2.
- {
- ASSERT_TRUE(connection2_->DeleteView(BuildViewId(2, 2)));
- EXPECT_TRUE(connection2_->changes().empty());
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("ViewDeleted view=2,2", changes[0]);
- }
-}
-
-// Verifies DeleteView isn't allowed from a separate connection.
-TEST_F(ViewManagerTest, DeleteViewFromAnotherConnectionDisallowed) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
- EXPECT_FALSE(connection2_->DeleteView(BuildViewId(1, 1)));
-}
-
-// Verifies if a view was deleted and then reused that other clients are
-// properly notified.
-TEST_F(ViewManagerTest, ReuseDeletedViewId) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
-
- // Add 2 to 1.
- {
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
- changes[0]);
- EXPECT_EQ("[view=2,2 parent=1,1]",
- ChangeViewDescription(connection_->changes()));
- }
-
- // Delete 2.
- {
- ASSERT_TRUE(connection2_->DeleteView(BuildViewId(2, 2)));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("ViewDeleted view=2,2", changes[0]);
- }
-
- // Create 2 again, and add it back to 1. Should get the same notification.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
- {
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
-
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- EXPECT_EQ("HierarchyChanged view=2,2 new_parent=1,1 old_parent=null",
- changes[0]);
- EXPECT_EQ("[view=2,2 parent=1,1]",
- ChangeViewDescription(connection_->changes()));
- }
-}
-
-// Assertions for GetViewTree.
-TEST_F(ViewManagerTest, GetViewTree) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- // Create 11 in first connection and make it a child of 1.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 11)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 11)));
-
- // Create two views in second connection, 2 and 3, both children of 1.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 2)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 2)));
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(2, 3)));
-
- // Verifies GetViewTree() on the root. The root connection sees all.
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(0, 1), &views);
- ASSERT_EQ(5u, views.size());
- EXPECT_EQ("view=0,1 parent=null", views[0].ToString());
- EXPECT_EQ("view=1,1 parent=0,1", views[1].ToString());
- EXPECT_EQ("view=1,11 parent=1,1", views[2].ToString());
- EXPECT_EQ("view=2,2 parent=1,1", views[3].ToString());
- EXPECT_EQ("view=2,3 parent=1,1", views[4].ToString());
- }
-
- // Verifies GetViewTree() on the view 1,1. This does not include any children
- // as they are not from this connection.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,1 parent=null", views[0].ToString());
- }
-
- // Connection 2 shouldn't be able to get the root tree.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(0, 1), &views);
- ASSERT_EQ(0u, views.size());
- }
-}
-
-TEST_F(ViewManagerTest, SetViewBounds) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
-
- ASSERT_TRUE(
- connection_->SetViewBounds(BuildViewId(1, 1), gfx::Rect(0, 0, 100, 100)));
-
- connection2_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection2_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("BoundsChanged view=1,1 old_bounds=0,0 0x0 new_bounds=0,0 100x100",
- changes[0]);
-
- // Should not be possible to change the bounds of a view created by another
- // connection.
- ASSERT_FALSE(
- connection2_->SetViewBounds(BuildViewId(1, 1), gfx::Rect(0, 0, 0, 0)));
-}
-
-// Verify AddView fails when trying to manipulate views in other roots.
-TEST_F(ViewManagerTest, CantMoveViewsFromOtherRoot) {
- // Create 1 and 2 in the first connection.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
-
- // Try to move 2 to be a child of 1 from connection 2. This should fail as 2
- // should not be able to access 1.
- ASSERT_FALSE(connection2_->AddView(BuildViewId(1, 1), BuildViewId(1, 2)));
-
- // Try to reparent 1 to the root. A connection is not allowed to reparent its
- // roots.
- ASSERT_FALSE(connection2_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
-}
-
-// Verify RemoveViewFromParent fails for views that are descendants of the
-// roots.
-TEST_F(ViewManagerTest, CantRemoveViewsInOtherRoots) {
- // Create 1 and 2 in the first connection and parent both to the root.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
-
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 2)));
-
- // Establish the second connection and give it the root 1.
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
-
- // Connection 2 should not be able to remove view 2 or 1 from its parent.
- ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(1, 2)));
- ASSERT_FALSE(connection2_->RemoveViewFromParent(BuildViewId(1, 1)));
-
- // Create views 10 and 11 in 2.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 10)));
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 11)));
-
- // Parent 11 to 10.
- ASSERT_TRUE(connection2_->AddView(BuildViewId(2, 10), BuildViewId(2, 11)));
- // Remove 11 from 10.
- ASSERT_TRUE(connection2_->RemoveViewFromParent(BuildViewId(2, 11)));
-
- // Verify nothing was actually removed.
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(0, 1), &views);
- ASSERT_EQ(3u, views.size());
- EXPECT_EQ("view=0,1 parent=null", views[0].ToString());
- EXPECT_EQ("view=1,1 parent=0,1", views[1].ToString());
- EXPECT_EQ("view=1,2 parent=0,1", views[2].ToString());
- }
-}
-
-// Verify GetViewTree fails for views that are not descendants of the roots.
-TEST_F(ViewManagerTest, CantGetViewTreeOfOtherRoots) {
- // Create 1 and 2 in the first connection and parent both to the root.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
-
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 2)));
-
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
-
- std::vector<TestView> views;
-
- // Should get nothing for the root.
- connection2_->GetViewTree(BuildViewId(0, 1), &views);
- ASSERT_TRUE(views.empty());
-
- // Should get nothing for view 2.
- connection2_->GetViewTree(BuildViewId(1, 2), &views);
- ASSERT_TRUE(views.empty());
-
- // Should get view 1 if asked for.
- connection2_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,1 parent=null", views[0].ToString());
-}
-
-TEST_F(ViewManagerTest, OnViewInput) {
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(false));
-
- // Dispatch an event to the view and verify its received.
- {
- EventPtr event(Event::New());
- event->action = static_cast<EventType>(1);
- connection_->window_manager_client()->DispatchInputEventToView(
- BuildViewId(1, 1), event.Pass());
- connection2_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection2_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("InputEvent view=1,1 event_action=1", changes[0]);
- }
-}
-
-TEST_F(ViewManagerTest, EmbedWithSameViewId) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- ASSERT_NO_FATAL_FAILURE(
- EstablishThirdConnection(connection_, BuildViewId(1, 1)));
-
- // Connection2 should have been told the view was deleted.
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection2_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("ViewDeleted view=1,1", changes[0]);
- }
-
- // Connection2 has no root. Verify it can't see view 1,1 anymore.
- {
- std::vector<TestView> views;
- connection2_->GetViewTree(BuildViewId(1, 1), &views);
- EXPECT_TRUE(views.empty());
- }
-}
-
-TEST_F(ViewManagerTest, EmbedWithSameViewId2) {
- ASSERT_NO_FATAL_FAILURE(EstablishSecondConnection(true));
-
- ASSERT_NO_FATAL_FAILURE(
- EstablishThirdConnection(connection_, BuildViewId(1, 1)));
-
- // Connection2 should have been told the view was deleted.
- connection2_->DoRunLoopUntilChangesCount(1);
- connection2_->ClearChanges();
-
- // Create a view in the third connection and parent it to the root.
- ASSERT_TRUE(connection3_->CreateView(BuildViewId(3, 1)));
- ASSERT_TRUE(connection3_->AddView(BuildViewId(1, 1), BuildViewId(3, 1)));
-
- // Connection 1 should have been told about the add (it owns the view).
- {
- connection_->DoRunLoopUntilChangesCount(1);
- const Changes changes(ChangesToDescription1(connection_->changes()));
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("HierarchyChanged view=3,1 new_parent=1,1 old_parent=null",
- changes[0]);
- }
-
- // Embed 1,1 again.
- {
- // We should get a new connection for the new embedding.
- ASSERT_TRUE(connection_->Embed(BuildViewId(1, 1), kTestServiceURL));
- ViewManagerProxy* connection4 = ViewManagerProxy::WaitForInstance();
- connection4->DoRunLoopUntilChangesCount(1);
- const std::vector<Change>& changes(connection4->changes());
- ASSERT_EQ(1u, changes.size());
- EXPECT_EQ("OnEmbed creator=mojo:test_url",
- ChangesToDescription1(changes)[0]);
- EXPECT_EQ("[view=1,1 parent=null]", ChangeViewDescription(changes));
-
- // And 3 should get a delete.
- connection3_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection3_->changes().size());
- EXPECT_EQ("ViewDeleted view=1,1",
- ChangesToDescription1(connection3_->changes())[0]);
- }
-
- // Connection3_ has no root. Verify it can't see view 1,1 anymore.
- {
- std::vector<TestView> views;
- connection3_->GetViewTree(BuildViewId(1, 1), &views);
- EXPECT_TRUE(views.empty());
- }
-
- // Verify 3,1 is no longer parented to 1,1. We have to do this from 1,1 as
- // connection3_ can no longer see 1,1.
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,1 parent=null", views[0].ToString());
- }
-
- // Verify connection3_ can still see the view it created 3,1.
- {
- std::vector<TestView> views;
- connection3_->GetViewTree(BuildViewId(3, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=3,1 parent=null", views[0].ToString());
- }
-}
-
-// Assertions for SetViewVisibility.
-TEST_F(ViewManagerTest, SetViewVisibility) {
- // Create 1 and 2 in the first connection and parent both to the root.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
-
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(0, 1), &views);
- ASSERT_EQ(2u, views.size());
- EXPECT_EQ("view=0,1 parent=null visible=true drawn=true",
- views[0].ToString2());
- EXPECT_EQ("view=1,1 parent=0,1 visible=true drawn=true",
- views[1].ToString2());
- }
-
- // Hide 1.
- ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), false));
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(1u, views.size());
- EXPECT_EQ("view=1,1 parent=0,1 visible=false drawn=false",
- views[0].ToString2());
- }
-
- // Attach 2 to 1.
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2)));
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(2u, views.size());
- EXPECT_EQ("view=1,1 parent=0,1 visible=false drawn=false",
- views[0].ToString2());
- EXPECT_EQ("view=1,2 parent=1,1 visible=true drawn=false",
- views[1].ToString2());
- }
-
- // Show 1.
- ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), true));
- {
- std::vector<TestView> views;
- connection_->GetViewTree(BuildViewId(1, 1), &views);
- ASSERT_EQ(2u, views.size());
- EXPECT_EQ("view=1,1 parent=0,1 visible=true drawn=true",
- views[0].ToString2());
- EXPECT_EQ("view=1,2 parent=1,1 visible=true drawn=true",
- views[1].ToString2());
- }
-}
-
-// Assertions for SetViewVisibility sending notifications.
-TEST_F(ViewManagerTest, SetViewVisibilityNotifications) {
- // Create 1,1 and 1,2, 1,2 and child of 1,1 and 1,1 a child of the root.
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->CreateView(BuildViewId(1, 2)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- ASSERT_TRUE(connection_->AddView(BuildViewId(1, 1), BuildViewId(1, 2)));
-
- // Establish the second connection at 1,2.
- ASSERT_NO_FATAL_FAILURE(
- EstablishSecondConnectionWithRoot(BuildViewId(1, 2)));
-
- // Add 2,3 as a child of 1,2.
- ASSERT_TRUE(connection2_->CreateView(BuildViewId(2, 3)));
- connection_->ClearChanges();
- ASSERT_TRUE(connection2_->AddView(BuildViewId(1, 2), BuildViewId(2, 3)));
- connection_->DoRunLoopUntilChangesCount(1);
-
- // Hide 1,2 from connection 1. Connection 2 should see this.
- ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 2), false));
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("VisibilityChanged view=1,2 visible=false",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // Show 1,2 from connection 2, connection 1 should be notified.
- ASSERT_TRUE(connection2_->SetViewVisibility(BuildViewId(1, 2), true));
- {
- connection_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection_->changes().size());
- EXPECT_EQ("VisibilityChanged view=1,2 visible=true",
- ChangesToDescription1(connection_->changes())[0]);
- }
-
- // Hide 1,1, connection 2 should be told the draw state changed.
- ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), false));
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // Show 1,1 from connection 1. Connection 2 should see this.
- ASSERT_TRUE(connection_->SetViewVisibility(BuildViewId(1, 1), true));
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // Change visibility of 2,3, connection 1 should see this.
- connection_->ClearChanges();
- ASSERT_TRUE(connection2_->SetViewVisibility(BuildViewId(2, 3), false));
- {
- connection_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection_->changes().size());
- EXPECT_EQ("VisibilityChanged view=2,3 visible=false",
- ChangesToDescription1(connection_->changes())[0]);
- }
-
- // Remove 1,1 from the root, connection 2 should see drawn state changed.
- ASSERT_TRUE(connection_->RemoveViewFromParent(BuildViewId(1, 1)));
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,2 drawn=false",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-
- // Add 1,1 back to the root, connection 2 should see drawn state changed.
- ASSERT_TRUE(connection_->AddView(BuildViewId(0, 1), BuildViewId(1, 1)));
- {
- connection2_->DoRunLoopUntilChangesCount(1);
- ASSERT_EQ(1u, connection2_->changes().size());
- EXPECT_EQ("DrawnStateChanged view=1,2 drawn=true",
- ChangesToDescription1(connection2_->changes())[0]);
- }
-}
-
-// TODO(sky): add coverage of test that destroys connections and ensures other
-// connections get deletion notification.
-
-// TODO(sky): need to better track changes to initial connection. For example,
-// that SetBounsdViews/AddView and the like don't result in messages to the
-// originating connection.
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/window_manager_access_policy.cc b/mojo/services/view_manager/window_manager_access_policy.cc
deleted file mode 100644
index f781534..0000000
--- a/mojo/services/view_manager/window_manager_access_policy.cc
+++ /dev/null
@@ -1,92 +0,0 @@
-// Copyright 2014 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/view_manager/window_manager_access_policy.h"
-
-#include "mojo/services/view_manager/access_policy_delegate.h"
-#include "mojo/services/view_manager/server_view.h"
-
-namespace mojo {
-namespace service {
-
-// TODO(sky): document why this differs from default for each case. Maybe want
-// to subclass DefaultAccessPolicy.
-
-WindowManagerAccessPolicy::WindowManagerAccessPolicy(
- ConnectionSpecificId connection_id,
- AccessPolicyDelegate* delegate)
- : connection_id_(connection_id),
- delegate_(delegate) {
-}
-
-WindowManagerAccessPolicy::~WindowManagerAccessPolicy() {
-}
-
-bool WindowManagerAccessPolicy::CanRemoveViewFromParent(
- const ServerView* view) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanAddView(const ServerView* parent,
- const ServerView* child) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanDeleteView(const ServerView* view) const {
- return view->id().connection_id == connection_id_;
-}
-
-bool WindowManagerAccessPolicy::CanGetViewTree(const ServerView* view) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanDescendIntoViewForViewTree(
- const ServerView* view) const {
- return true;
-}
-
-bool WindowManagerAccessPolicy::CanEmbed(const ServerView* view) const {
- return view->id().connection_id == connection_id_;
-}
-
-bool WindowManagerAccessPolicy::CanChangeViewVisibility(
- const ServerView* view) const {
- return view->id().connection_id == connection_id_;
-}
-
-bool WindowManagerAccessPolicy::CanSetViewSurfaceId(
- const ServerView* view) const {
- if (delegate_->IsViewRootOfAnotherConnectionForAccessPolicy(view))
- return false;
- return view->id().connection_id == connection_id_ ||
- (delegate_->GetRootsForAccessPolicy().count(
- ViewIdToTransportId(view->id())) > 0);
-}
-
-bool WindowManagerAccessPolicy::CanSetViewBounds(const ServerView* view) const {
- return view->id().connection_id == connection_id_;
-}
-
-bool WindowManagerAccessPolicy::ShouldNotifyOnHierarchyChange(
- const ServerView* view,
- const ServerView** new_parent,
- const ServerView** old_parent) const {
- // Notify if we've already told the window manager about the view, or if we've
- // already told the window manager about the parent. The later handles the
- // case of a view that wasn't parented to the root getting added to the root.
- return IsViewKnown(view) || (*new_parent && IsViewKnown(*new_parent));
-}
-
-bool WindowManagerAccessPolicy::IsViewKnown(const ServerView* view) const {
- return delegate_->IsViewKnownForAccessPolicy(view);
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/window_manager_access_policy.h b/mojo/services/view_manager/window_manager_access_policy.h
deleted file mode 100644
index 7b8e7a9..0000000
--- a/mojo/services/view_manager/window_manager_access_policy.h
+++ /dev/null
@@ -1,53 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_WINDOW_MANAGER_ACCESS_POLICY_H_
-#define MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_ACCESS_POLICY_H_
-
-#include "base/basictypes.h"
-#include "mojo/services/view_manager/access_policy.h"
-
-namespace mojo {
-namespace service {
-
-class AccessPolicyDelegate;
-
-class WindowManagerAccessPolicy : public AccessPolicy {
- public:
- WindowManagerAccessPolicy(ConnectionSpecificId connection_id,
- AccessPolicyDelegate* delegate);
- ~WindowManagerAccessPolicy() override;
-
- // AccessPolicy:
- bool CanRemoveViewFromParent(const ServerView* view) const override;
- bool CanAddView(const ServerView* parent,
- const ServerView* child) const override;
- bool CanReorderView(const ServerView* view,
- const ServerView* relative_view,
- OrderDirection direction) const override;
- bool CanDeleteView(const ServerView* view) const override;
- bool CanGetViewTree(const ServerView* view) const override;
- bool CanDescendIntoViewForViewTree(const ServerView* view) const override;
- bool CanEmbed(const ServerView* view) const override;
- bool CanChangeViewVisibility(const ServerView* view) const override;
- bool CanSetViewSurfaceId(const ServerView* view) const override;
- bool CanSetViewBounds(const ServerView* view) const override;
- bool ShouldNotifyOnHierarchyChange(
- const ServerView* view,
- const ServerView** new_parent,
- const ServerView** old_parent) const override;
-
- private:
- bool IsViewKnown(const ServerView* view) const;
-
- const ConnectionSpecificId connection_id_;
- AccessPolicyDelegate* delegate_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerAccessPolicy);
-};
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_ACCESS_POLICY_H_
diff --git a/mojo/services/view_manager/window_manager_client_impl.cc b/mojo/services/view_manager/window_manager_client_impl.cc
deleted file mode 100644
index 493e8f1..0000000
--- a/mojo/services/view_manager/window_manager_client_impl.cc
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 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/view_manager/window_manager_client_impl.h"
-
-#include "base/bind.h"
-#include "mojo/services/view_manager/connection_manager.h"
-#include "mojo/services/view_manager/view_manager_service_impl.h"
-
-namespace mojo {
-namespace service {
-
-WindowManagerClientImpl::WindowManagerClientImpl(
- ConnectionManager* connection_manager)
- : connection_manager_(connection_manager) {
-}
-
-WindowManagerClientImpl::~WindowManagerClientImpl() {
-}
-
-void WindowManagerClientImpl::DispatchInputEventToView(Id transport_view_id,
- EventPtr event) {
- const ViewId view_id(ViewIdFromTransportId(transport_view_id));
-
- ViewManagerServiceImpl* connection =
- connection_manager_->GetConnectionWithRoot(view_id);
- if (!connection)
- connection = connection_manager_->GetConnection(view_id.connection_id);
- if (connection) {
- connection->client()->OnViewInputEvent(
- transport_view_id, event.Pass(), base::Bind(&base::DoNothing));
- }
-}
-
-void WindowManagerClientImpl::OnConnectionError() {
- // TODO(sky): deal with this. We may need to tear everything down here.
-}
-
-} // namespace service
-} // namespace mojo
diff --git a/mojo/services/view_manager/window_manager_client_impl.h b/mojo/services/view_manager/window_manager_client_impl.h
deleted file mode 100644
index 704489d..0000000
--- a/mojo/services/view_manager/window_manager_client_impl.h
+++ /dev/null
@@ -1,54 +0,0 @@
-// Copyright 2014 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_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
-#define MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
-
-#include <set>
-#include <string>
-#include <vector>
-
-#include "base/basictypes.h"
-#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
-#include "mojo/services/view_manager/ids.h"
-#include "mojo/services/view_manager/view_manager_export.h"
-
-namespace mojo {
-namespace service {
-
-class ConnectionManager;
-
-#if defined(OS_WIN)
-// Equivalent of NON_EXPORTED_BASE which does not work with the template snafu
-// below.
-#pragma warning(push)
-#pragma warning(disable : 4275)
-#endif
-
-class MOJO_VIEW_MANAGER_EXPORT WindowManagerClientImpl
- : public InterfaceImpl<WindowManagerClient> {
- public:
- explicit WindowManagerClientImpl(ConnectionManager* connection_manager);
- ~WindowManagerClientImpl() override;
-
- // WindowManagerClient:
- void DispatchInputEventToView(Id transport_view_id, EventPtr event) override;
-
- // InterfaceImp overrides:
- void OnConnectionError() override;
-
- private:
- ConnectionManager* connection_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerClientImpl);
-};
-
-#if defined(OS_WIN)
-#pragma warning(pop)
-#endif
-
-} // namespace service
-} // namespace mojo
-
-#endif // MOJO_SERVICES_VIEW_MANAGER_WINDOW_MANAGER_CLIENT_IMPL_H_
diff --git a/mojo/services/window_manager/BUILD.gn b/mojo/services/window_manager/BUILD.gn
deleted file mode 100644
index 98a8b36..0000000
--- a/mojo/services/window_manager/BUILD.gn
+++ /dev/null
@@ -1,83 +0,0 @@
-# Copyright 2014 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.
-
-import("//build/config/ui.gni")
-
-if (use_aura) {
-
-# GYP version: mojo/mojo_services.gypi:mojo_core_window_manager
-shared_library("window_manager") {
- output_name = "mojo_core_window_manager"
-
- sources = [ "main.cc" ]
-
- public_deps = [
- ":lib",
- ]
- deps = [
- "//base",
- "//mojo/application",
- "//mojo/public/c/system:for_shared_library",
- "//mojo/services/public/cpp/view_manager",
- ]
-}
-
-# GYP version: mojo/mojo_services.gypi:mojo_core_window_manager_lib
-source_set("lib") {
- sources = [
- "window_manager_app.cc",
- "window_manager_app.h",
- "window_manager_delegate.h",
- "window_manager_service_impl.cc",
- "window_manager_service_impl.h",
- "window_manager_service2_impl.cc",
- "window_manager_service2_impl.h",
- ]
-
- public_deps = [
- "//mojo/aura",
- ]
- deps = [
- "//base",
- "//ui/base",
- "//ui/gfx",
- "//ui/gfx/geometry",
- "//ui/wm",
- "//mojo/aura",
- "//mojo/application",
- "//mojo/common",
- "//mojo/converters/input_events",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/public/interfaces/application:application",
- "//mojo/services/public/interfaces/window_manager",
- "//mojo/services/public/interfaces/window_manager2",
- ]
-}
-
-# GYP version: mojo/mojo_services.gypi:mojo_core_window_manager_unittests
-test("mojo_core_window_manager_unittests") {
- sources = [
- "window_manager_api_unittest.cc",
- "window_manager_unittests.cc",
- ]
-
- deps = [
- "//base/test:test_support",
- "//mojo/application_manager",
- "//mojo/edk/system",
- "//mojo/environment:chromium",
- "//mojo/services/public/cpp/view_manager",
- "//mojo/services/public/interfaces/view_manager",
- "//mojo/services/public/interfaces/window_manager",
- "//mojo/services/public/interfaces/window_manager2",
- "//mojo/shell:test_support",
- "//testing/gtest",
- "//ui/gl",
- ]
- if (use_x11) {
- deps += [ "//ui/gfx/x" ]
- }
-}
-
-} # use_aura
diff --git a/mojo/services/window_manager/DEPS b/mojo/services/window_manager/DEPS
deleted file mode 100644
index bbaa409..0000000
--- a/mojo/services/window_manager/DEPS
+++ /dev/null
@@ -1,14 +0,0 @@
-include_rules = [
- "+mojo/aura",
- "+mojo/application",
- "+mojo/application_manager",
- "+mojo/converters/input_events",
- "+mojo/services/native_viewport",
- "+mojo/services/public",
- "+ui/aura",
- "+ui/base",
- "+ui/events",
- "+ui/gfx",
- "+ui/gl",
- "+ui/wm",
-]
diff --git a/mojo/services/window_manager/main.cc b/mojo/services/window_manager/main.cc
deleted file mode 100644
index 028795b..0000000
--- a/mojo/services/window_manager/main.cc
+++ /dev/null
@@ -1,73 +0,0 @@
-// Copyright 2014 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 "base/memory/scoped_ptr.h"
-#include "mojo/application/application_runner_chromium.h"
-#include "mojo/public/c/system/main.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/services/public/cpp/view_manager/view_manager.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/window_manager/window_manager_app.h"
-#include "mojo/services/window_manager/window_manager_delegate.h"
-
-// ApplicationDelegate implementation file for WindowManager users (e.g.
-// core window manager tests) that do not want to provide their own
-// ApplicationDelegate::Create().
-
-namespace mojo {
-
-class DefaultWindowManager : public ApplicationDelegate,
- public ViewManagerDelegate,
- public WindowManagerDelegate {
- public:
- DefaultWindowManager()
- : window_manager_app_(new WindowManagerApp(this, this)),
- view_manager_(NULL),
- root_(NULL) {}
- ~DefaultWindowManager() override {}
-
- private:
- // Overridden from ApplicationDelegate:
- void Initialize(ApplicationImpl* impl) override {
- window_manager_app_->Initialize(impl);
- }
- bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
- window_manager_app_->ConfigureIncomingConnection(connection);
- return true;
- }
-
- // Overridden from ViewManagerDelegate:
- void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- view_manager_ = view_manager;
- root_ = root;
- }
- void OnViewManagerDisconnected(ViewManager* view_manager) override {}
-
- // Overridden from WindowManagerDelegate:
- void Embed(const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override {
- View* view = View::Create(view_manager_);
- root_->AddChild(view);
- view->Embed(url, scoped_ptr<mojo::ServiceProviderImpl>(
- new mojo::ServiceProviderImpl).Pass());
- }
-
- scoped_ptr<WindowManagerApp> window_manager_app_;
-
- ViewManager* view_manager_;
- View* root_;
-
- MOJO_DISALLOW_COPY_AND_ASSIGN(DefaultWindowManager);
-};
-
-} // namespace mojo
-
-MojoResult MojoMain(MojoHandle shell_handle) {
- mojo::ApplicationRunnerChromium runner(new mojo::DefaultWindowManager);
- return runner.Run(shell_handle);
-}
diff --git a/mojo/services/window_manager/window_manager_api_unittest.cc b/mojo/services/window_manager/window_manager_api_unittest.cc
deleted file mode 100644
index d5cad73..0000000
--- a/mojo/services/window_manager/window_manager_api_unittest.cc
+++ /dev/null
@@ -1,276 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/memory/scoped_vector.h"
-#include "mojo/application_manager/application_manager.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/cpp/application/service_provider_impl.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-#include "mojo/services/public/cpp/view_manager/types.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_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/public/interfaces/window_manager2/window_manager2.mojom.h"
-#include "mojo/shell/shell_test_helper.h"
-#include "testing/gtest/include/gtest/gtest.h"
-
-namespace mojo {
-namespace {
-
-const char kTestServiceURL[] = "mojo:test_url";
-
-void EmptyResultCallback(bool result) {}
-
-// Callback from Embed(). |result| is the result of the Embed() call and
-// |run_loop| the nested RunLoop.
-void ResultCallback(bool* result_cache, base::RunLoop* run_loop, bool result) {
- *result_cache = result;
- run_loop->Quit();
-}
-
-// Responsible for establishing the initial ViewManagerService connection.
-// Blocks until result is determined.
-bool InitEmbed(ViewManagerInitService* view_manager_init,
- const std::string& url) {
- bool result = false;
- base::RunLoop run_loop;
- ServiceProviderPtr sp;
- BindToProxy(new ServiceProviderImpl, &sp);
- view_manager_init->Embed(url, sp.Pass(),
- base::Bind(&ResultCallback, &result, &run_loop));
- run_loop.Run();
- return result;
-}
-
-class TestWindowManagerClient : public WindowManagerClient2 {
- public:
- typedef base::Callback<void(Id, Id)>
- TwoNodeCallback;
-
- explicit TestWindowManagerClient(base::RunLoop* run_loop)
- : run_loop_(run_loop) {}
- ~TestWindowManagerClient() override {}
-
- void set_focus_changed_callback(const TwoNodeCallback& callback) {
- focus_changed_callback_ = callback;
- }
- void set_active_window_changed_callback(const TwoNodeCallback& callback) {
- active_window_changed_callback_ = callback;
- }
-
- private:
- // Overridden from WindowManagerClient:
- void OnWindowManagerReady() override { run_loop_->Quit(); }
- void OnCaptureChanged(Id old_capture_node_id,
- Id new_capture_node_id) override {}
- void OnFocusChanged(Id old_focused_node_id, Id new_focused_node_id) override {
- if (!focus_changed_callback_.is_null())
- focus_changed_callback_.Run(old_focused_node_id, new_focused_node_id);
- }
- void OnActiveWindowChanged(Id old_active_window,
- Id new_active_window) override {
- if (!active_window_changed_callback_.is_null())
- active_window_changed_callback_.Run(old_active_window, new_active_window);
- }
-
- base::RunLoop* run_loop_;
- TwoNodeCallback focus_changed_callback_;
- TwoNodeCallback active_window_changed_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(TestWindowManagerClient);
-};
-
-class TestApplicationLoader : public ApplicationLoader,
- public ApplicationDelegate,
- public ViewManagerDelegate {
- public:
- typedef base::Callback<void(View*)> RootAddedCallback;
-
- explicit TestApplicationLoader(const RootAddedCallback& root_added_callback)
- : root_added_callback_(root_added_callback) {}
- ~TestApplicationLoader() override {}
-
- private:
- // Overridden from ApplicationLoader:
- void Load(ApplicationManager* application_manager,
- const GURL& url,
- scoped_refptr<LoadCallbacks> callbacks) override {
- ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
- if (!shell_handle.is_valid())
- return;
- scoped_ptr<ApplicationImpl> app(
- new ApplicationImpl(this, shell_handle.Pass()));
- apps_.push_back(app.release());
- }
- void OnApplicationError(ApplicationManager* application_manager,
- const GURL& url) override {}
-
- // Overridden from ApplicationDelegate:
- void Initialize(ApplicationImpl* app) override {
- view_manager_client_factory_.reset(
- new ViewManagerClientFactory(app->shell(), this));
- }
-
- bool ConfigureIncomingConnection(ApplicationConnection* connection) override {
- connection->AddService(view_manager_client_factory_.get());
- return true;
- }
-
- // Overridden from ViewManagerDelegate:
- void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override {
- root_added_callback_.Run(root);
- }
- void OnViewManagerDisconnected(ViewManager* view_manager) override {}
-
- RootAddedCallback root_added_callback_;
-
- ScopedVector<ApplicationImpl> apps_;
- scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
-
- DISALLOW_COPY_AND_ASSIGN(TestApplicationLoader);
-};
-
-} // namespace
-
-class WindowManagerApiTest : public testing::Test {
- public:
- WindowManagerApiTest() {}
- virtual ~WindowManagerApiTest() {}
-
- protected:
- typedef std::pair<Id, Id> TwoIds;
-
- Id WaitForEmbed() {
- Id id;
- base::RunLoop run_loop;
- root_added_callback_ = base::Bind(&WindowManagerApiTest::OnEmbed,
- base::Unretained(this), &id, &run_loop);
- run_loop.Run();
- return id;
- }
-
- TwoIds WaitForFocusChange() {
- TwoIds old_and_new;
- base::RunLoop run_loop;
- window_manager_client()->set_focus_changed_callback(
- base::Bind(&WindowManagerApiTest::OnFocusChanged,
- base::Unretained(this), &old_and_new, &run_loop));
- run_loop.Run();
- return old_and_new;
- }
-
- TwoIds WaitForActiveWindowChange() {
- TwoIds old_and_new;
- base::RunLoop run_loop;
- window_manager_client()->set_active_window_changed_callback(
- base::Bind(&WindowManagerApiTest::OnActiveWindowChanged,
- base::Unretained(this), &old_and_new, &run_loop));
- run_loop.Run();
- return old_and_new;
- }
-
- Id OpenWindow() {
- return OpenWindowWithURL(kTestServiceURL);
- }
-
- Id OpenWindowWithURL(const std::string& url) {
- InitEmbed(view_manager_init_.get(), url);
- return WaitForEmbed();
- }
-
- TestWindowManagerClient* window_manager_client() {
- return window_manager_client_.get();
- }
-
- WindowManagerService2Ptr window_manager_;
-
- private:
- // Overridden from testing::Test:
- virtual void SetUp() override {
- test_helper_.Init();
- test_helper_.SetLoaderForURL(
- scoped_ptr<ApplicationLoader>(new TestApplicationLoader(base::Bind(
- &WindowManagerApiTest::OnRootAdded, base::Unretained(this)))),
- GURL(kTestServiceURL));
- test_helper_.application_manager()->ConnectToService(
- GURL("mojo:view_manager"), &view_manager_init_);
- ASSERT_TRUE(
- InitEmbed(view_manager_init_.get(), "mojo:core_window_manager"));
- ConnectToWindowManager();
- }
- virtual void TearDown() override {}
-
- void ConnectToWindowManager() {
- test_helper_.application_manager()->ConnectToService(
- GURL("mojo:core_window_manager"), &window_manager_);
- base::RunLoop connect_loop;
- window_manager_client_.reset(new TestWindowManagerClient(&connect_loop));
- window_manager_.set_client(window_manager_client());
- connect_loop.Run();
- }
-
- void OnRootAdded(View* root) {
- if (!root_added_callback_.is_null())
- root_added_callback_.Run(root);
- }
-
- void OnEmbed(Id* root_id,
- base::RunLoop* loop,
- View* root) {
- *root_id = root->id();
- loop->Quit();
- }
-
- void OnFocusChanged(TwoIds* old_and_new,
- base::RunLoop* run_loop,
- Id old_focused_node_id,
- Id new_focused_node_id) {
- DCHECK(old_and_new);
- old_and_new->first = old_focused_node_id;
- old_and_new->second = new_focused_node_id;
- run_loop->Quit();
- }
-
- void OnActiveWindowChanged(TwoIds* old_and_new,
- base::RunLoop* run_loop,
- Id old_focused_node_id,
- Id new_focused_node_id) {
- DCHECK(old_and_new);
- old_and_new->first = old_focused_node_id;
- old_and_new->second = new_focused_node_id;
- run_loop->Quit();
- }
-
- shell::ShellTestHelper test_helper_;
- ViewManagerInitServicePtr view_manager_init_;
- scoped_ptr<TestWindowManagerClient> window_manager_client_;
- TestApplicationLoader::RootAddedCallback root_added_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerApiTest);
-};
-
-TEST_F(WindowManagerApiTest, FocusAndActivateWindow) {
- Id first_window = OpenWindow();
- window_manager_->FocusWindow(first_window,
- base::Bind(&EmptyResultCallback));
- TwoIds ids = WaitForFocusChange();
- EXPECT_TRUE(ids.first == 0);
- EXPECT_EQ(ids.second, first_window);
-
- Id second_window = OpenWindow();
- window_manager_->ActivateWindow(second_window,
- base::Bind(&EmptyResultCallback));
- ids = WaitForActiveWindowChange();
- EXPECT_EQ(ids.first, first_window);
- EXPECT_EQ(ids.second, second_window);
-}
-
-} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_app.cc b/mojo/services/window_manager/window_manager_app.cc
deleted file mode 100644
index 2852bd2..0000000
--- a/mojo/services/window_manager/window_manager_app.cc
+++ /dev/null
@@ -1,344 +0,0 @@
-// Copyright 2014 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/window_manager/window_manager_app.h"
-
-#include "base/message_loop/message_loop.h"
-#include "base/stl_util.h"
-#include "mojo/aura/aura_init.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/public/interfaces/application/shell.mojom.h"
-#include "mojo/services/public/cpp/view_manager/view.h"
-#include "mojo/services/public/cpp/view_manager/view_manager.h"
-#include "ui/aura/window.h"
-#include "ui/aura/window_delegate.h"
-#include "ui/aura/window_property.h"
-#include "ui/base/hit_test.h"
-#include "ui/wm/core/capture_controller.h"
-#include "ui/wm/core/focus_controller.h"
-#include "ui/wm/public/activation_client.h"
-
-DECLARE_WINDOW_PROPERTY_TYPE(mojo::View*);
-
-namespace mojo {
-
-// The aura::Windows we use to track Views don't render, so we don't actually
-// need to supply a fully functional WindowDelegate. We do need to provide _a_
-// delegate however, otherwise the event dispatcher won't dispatch events to
-// these windows. (The aura WindowTargeter won't allow a delegate-less window
-// to be the target of an event, since the window delegate is considered the
-// "target handler").
-class DummyDelegate : public aura::WindowDelegate {
- public:
- DummyDelegate() {}
- ~DummyDelegate() override {}
-
- private:
- // WindowDelegate overrides:
- gfx::Size GetMinimumSize() const override { return gfx::Size(); }
- gfx::Size GetMaximumSize() const override { return gfx::Size(); }
- void OnBoundsChanged(const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override {}
- gfx::NativeCursor GetCursor(const gfx::Point& point) override {
- return gfx::kNullCursor;
- }
- int GetNonClientComponent(const gfx::Point& point) const override {
- return HTCAPTION;
- }
- bool ShouldDescendIntoChildForEventHandling(
- aura::Window* child,
- const gfx::Point& location) override {
- return true;
- }
- bool CanFocus() override { return true; }
- void OnCaptureLost() override {}
- void OnPaint(gfx::Canvas* canvas) override {}
- void OnDeviceScaleFactorChanged(float device_scale_factor) override {}
- void OnWindowDestroying(aura::Window* window) override {}
- void OnWindowDestroyed(aura::Window* window) override {}
- void OnWindowTargetVisibilityChanged(bool visible) override {}
- bool HasHitTestMask() const override { return false; }
- void GetHitTestMask(gfx::Path* mask) const override {}
-
- DISALLOW_COPY_AND_ASSIGN(DummyDelegate);
-};
-
-namespace {
-
-DEFINE_WINDOW_PROPERTY_KEY(View*, kViewKey, NULL);
-
-Id GetIdForWindow(aura::Window* window) {
- return window ? WindowManagerApp::GetViewForWindow(window)->id() : 0;
-}
-
-} // namespace
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, public:
-
-WindowManagerApp::WindowManagerApp(
- ViewManagerDelegate* view_manager_delegate,
- WindowManagerDelegate* window_manager_delegate)
- : shell_(nullptr),
- window_manager_service2_factory_(this),
- window_manager_service_factory_(this),
- wrapped_view_manager_delegate_(view_manager_delegate),
- window_manager_delegate_(window_manager_delegate),
- view_manager_(NULL),
- root_(NULL),
- dummy_delegate_(new DummyDelegate),
- window_manager_client_(nullptr) {
-}
-
-WindowManagerApp::~WindowManagerApp() {}
-
-// static
-View* WindowManagerApp::GetViewForWindow(aura::Window* window) {
- return window->GetProperty(kViewKey);
-}
-
-aura::Window* WindowManagerApp::GetWindowForViewId(Id view) {
- ViewIdToWindowMap::const_iterator it = view_id_to_window_map_.find(view);
- return it != view_id_to_window_map_.end() ? it->second : NULL;
-}
-
-void WindowManagerApp::AddConnection(WindowManagerService2Impl* connection) {
- DCHECK(connections_.find(connection) == connections_.end());
- connections_.insert(connection);
-}
-
-void WindowManagerApp::RemoveConnection(WindowManagerService2Impl* connection) {
- DCHECK(connections_.find(connection) != connections_.end());
- connections_.erase(connection);
-}
-
-void WindowManagerApp::SetCapture(Id view) {
- capture_client_->capture_client()->SetCapture(GetWindowForViewId(view));
- // TODO(beng): notify connected clients that capture has changed, probably
- // by implementing some capture-client observer.
-}
-
-void WindowManagerApp::FocusWindow(Id view) {
- aura::Window* window = GetWindowForViewId(view);
- DCHECK(window);
- focus_client_->FocusWindow(window);
-}
-
-void WindowManagerApp::ActivateWindow(Id view) {
- aura::Window* window = GetWindowForViewId(view);
- DCHECK(window);
- activation_client_->ActivateWindow(window);
-}
-
-bool WindowManagerApp::IsReady() const {
- return view_manager_ && root_;
-}
-
-void WindowManagerApp::InitFocus(wm::FocusRules* rules) {
- wm::FocusController* focus_controller = new wm::FocusController(rules);
- activation_client_ = focus_controller;
- focus_client_.reset(focus_controller);
- aura::client::SetFocusClient(window_tree_host_->window(), focus_controller);
- aura::client::SetActivationClient(window_tree_host_->window(),
- focus_controller);
-
- focus_client_->AddObserver(this);
- activation_client_->AddObserver(this);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, ApplicationDelegate implementation:
-
-void WindowManagerApp::Initialize(ApplicationImpl* impl) {
- shell_ = impl->shell();
- aura_init_.reset(new AuraInit);
- view_manager_client_factory_.reset(
- new ViewManagerClientFactory(shell_, this));
-}
-
-bool WindowManagerApp::ConfigureIncomingConnection(
- ApplicationConnection* connection) {
- connection->AddService(&window_manager_service2_factory_);
- connection->AddService(view_manager_client_factory_.get());
- connection->AddService(&window_manager_service_factory_);
- return true;
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, ViewManagerDelegate implementation:
-
-void WindowManagerApp::OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) {
- DCHECK(!view_manager_ && !root_);
- view_manager_ = view_manager;
- root_ = root;
-
- window_tree_host_.reset(new WindowTreeHostMojo(shell_, root_));
- window_tree_host_->window()->SetBounds(root->bounds());
- window_tree_host_->window()->Show();
-
- RegisterSubtree(root_, window_tree_host_->window());
-
- capture_client_.reset(
- new wm::ScopedCaptureClient(window_tree_host_->window()));
-
- if (wrapped_view_manager_delegate_) {
- wrapped_view_manager_delegate_->OnEmbed(
- view_manager, root, exported_services, imported_services.Pass());
- }
-
- for (Connections::const_iterator it = connections_.begin();
- it != connections_.end(); ++it) {
- (*it)->NotifyReady();
- }
-}
-
-void WindowManagerApp::OnViewManagerDisconnected(
- ViewManager* view_manager) {
- DCHECK_EQ(view_manager_, view_manager);
- if (wrapped_view_manager_delegate_)
- wrapped_view_manager_delegate_->OnViewManagerDisconnected(view_manager);
- view_manager_ = NULL;
- base::MessageLoop::current()->Quit();
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, ViewObserver implementation:
-
-void WindowManagerApp::OnTreeChanged(
- const ViewObserver::TreeChangeParams& params) {
- if (params.receiver != root_)
- return;
- DCHECK(params.old_parent || params.new_parent);
- if (!params.target)
- return;
-
- if (params.new_parent) {
- if (view_id_to_window_map_.find(params.target->id()) ==
- view_id_to_window_map_.end()) {
- ViewIdToWindowMap::const_iterator it =
- view_id_to_window_map_.find(params.new_parent->id());
- DCHECK(it != view_id_to_window_map_.end());
- RegisterSubtree(params.target, it->second);
- }
- } else if (params.old_parent) {
- UnregisterSubtree(params.target);
- }
-}
-
-void WindowManagerApp::OnViewDestroying(View* view) {
- if (view != root_) {
- Unregister(view);
- return;
- }
- aura::Window* window = GetWindowForViewId(view->id());
- window->RemovePreTargetHandler(this);
- root_ = NULL;
- STLDeleteValues(&view_id_to_window_map_);
- if (focus_client_.get())
- focus_client_->RemoveObserver(this);
- if (activation_client_)
- activation_client_->RemoveObserver(this);
- window_tree_host_.reset();
-}
-
-void WindowManagerApp::OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) {
- aura::Window* window = GetWindowForViewId(view->id());
- window->SetBounds(new_bounds);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, ui::EventHandler implementation:
-
-void WindowManagerApp::OnEvent(ui::Event* event) {
- if (!window_manager_client_)
- return;
-
- View* view = GetViewForWindow(static_cast<aura::Window*>(event->target()));
- if (!view)
- return;
-
- window_manager_client_->DispatchInputEventToView(view->id(),
- Event::From(*event));
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, aura::client::FocusChangeObserver implementation:
-
-void WindowManagerApp::OnWindowFocused(aura::Window* gained_focus,
- aura::Window* lost_focus) {
- for (Connections::const_iterator it = connections_.begin();
- it != connections_.end(); ++it) {
- (*it)->NotifyViewFocused(GetIdForWindow(gained_focus),
- GetIdForWindow(lost_focus));
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, aura::client::ActivationChangeObserver implementation:
-
-void WindowManagerApp::OnWindowActivated(aura::Window* gained_active,
- aura::Window* lost_active) {
- for (Connections::const_iterator it = connections_.begin();
- it != connections_.end(); ++it) {
- (*it)->NotifyWindowActivated(GetIdForWindow(gained_active),
- GetIdForWindow(lost_active));
- }
- if (gained_active) {
- View* view = GetViewForWindow(gained_active);
- view->MoveToFront();
- }
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerApp, private:
-
-void WindowManagerApp::RegisterSubtree(View* view, aura::Window* parent) {
- view->AddObserver(this);
- DCHECK(view_id_to_window_map_.find(view->id()) ==
- view_id_to_window_map_.end());
- aura::Window* window = new aura::Window(dummy_delegate_.get());
- window->set_id(view->id());
- window->SetProperty(kViewKey, view);
- // All events pass through the root during dispatch, so we only need a handler
- // installed there.
- if (view == root_)
- window->AddPreTargetHandler(this);
- parent->AddChild(window);
- window->SetBounds(view->bounds());
- window->Show();
- view_id_to_window_map_[view->id()] = window;
- View::Children::const_iterator it = view->children().begin();
- for (; it != view->children().end(); ++it)
- RegisterSubtree(*it, window);
-}
-
-void WindowManagerApp::UnregisterSubtree(View* view) {
- for (View* child : view->children())
- UnregisterSubtree(child);
- Unregister(view);
-}
-
-void WindowManagerApp::Unregister(View* view) {
- ViewIdToWindowMap::iterator it = view_id_to_window_map_.find(view->id());
- if (it == view_id_to_window_map_.end()) {
- // Because we unregister in OnViewDestroying() we can still get a subsequent
- // OnTreeChanged for the same view. Ignore this one.
- return;
- }
- view->RemoveObserver(this);
- DCHECK(it != view_id_to_window_map_.end());
- // Delete before we remove from map as destruction may want to look up view
- // for window.
- delete it->second;
- view_id_to_window_map_.erase(it);
-}
-
-} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_app.h b/mojo/services/window_manager/window_manager_app.h
deleted file mode 100644
index c7d2dc3..0000000
--- a/mojo/services/window_manager/window_manager_app.h
+++ /dev/null
@@ -1,175 +0,0 @@
-// Copyright 2014 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_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
-#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
-
-#include <set>
-
-#include "base/memory/scoped_ptr.h"
-#include "mojo/aura/window_tree_host_mojo.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/interface_factory_impl.h"
-#include "mojo/public/cpp/bindings/string.h"
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_client_factory.h"
-#include "mojo/services/public/cpp/view_manager/view_manager_delegate.h"
-#include "mojo/services/public/cpp/view_manager/view_observer.h"
-#include "mojo/services/window_manager/window_manager_service2_impl.h"
-#include "mojo/services/window_manager/window_manager_service_impl.h"
-#include "ui/aura/client/focus_change_observer.h"
-#include "ui/events/event_handler.h"
-#include "ui/wm/public/activation_change_observer.h"
-
-namespace aura {
-namespace client {
-class ActivationClient;
-class FocusClient;
-}
-class Window;
-}
-
-namespace wm {
-class FocusRules;
-class ScopedCaptureClient;
-}
-
-namespace mojo {
-
-class AuraInit;
-class DummyDelegate;
-class WindowManagerClient;
-class WindowManagerDelegate;
-class WindowManagerService2Impl;
-
-// Implements core window manager functionality that could conceivably be shared
-// across multiple window managers implementing superficially different user
-// experiences. Establishes communication with the view manager.
-// A window manager wishing to use this core should create and own an instance
-// of this object. They may implement the associated ViewManager/WindowManager
-// delegate interfaces exposed by the view manager, this object provides the
-// canonical implementation of said interfaces but will call out to the wrapped
-// instances.
-// This object maintains an aura::WindowTreeHost containing a hierarchy of
-// aura::Windows. Window manager functionality (e.g. focus, activation,
-// modality, etc.) are implemented using aura core window manager components.
-class WindowManagerApp
- : public ApplicationDelegate,
- public ViewManagerDelegate,
- public ViewObserver,
- public ui::EventHandler,
- public aura::client::FocusChangeObserver,
- public aura::client::ActivationChangeObserver {
- public:
- WindowManagerApp(ViewManagerDelegate* view_manager_delegate,
- WindowManagerDelegate* window_manager_delegate);
- ~WindowManagerApp() override;
-
- static View* GetViewForWindow(aura::Window* window);
- aura::Window* GetWindowForViewId(Id view);
-
- // Register/deregister new connections to the window manager service.
- void AddConnection(WindowManagerService2Impl* connection);
- void RemoveConnection(WindowManagerService2Impl* connection);
-
- // These are canonical implementations of the window manager API methods.
- void SetCapture(Id view);
- void FocusWindow(Id view);
- void ActivateWindow(Id view);
-
- bool IsReady() const;
-
- // A client of this object will use this accessor to gain access to the
- // aura::Window hierarchy and attach event handlers.
- WindowTreeHostMojo* host() { return window_tree_host_.get(); }
-
- WindowManagerDelegate* window_manager_delegate() {
- return window_manager_delegate_;
- }
-
- void InitFocus(wm::FocusRules* rules);
-
- void set_window_manager_client(WindowManagerClient* client) {
- window_manager_client_ = client;
- }
-
- // Overridden from ApplicationDelegate:
- void Initialize(ApplicationImpl* impl) override;
- bool ConfigureIncomingConnection(ApplicationConnection* connection) override;
-
- private:
- typedef std::set<WindowManagerService2Impl*> Connections;
- typedef std::map<Id, aura::Window*> ViewIdToWindowMap;
-
- // Overridden from ViewManagerDelegate:
- void OnEmbed(ViewManager* view_manager,
- View* root,
- ServiceProviderImpl* exported_services,
- scoped_ptr<ServiceProvider> imported_services) override;
- void OnViewManagerDisconnected(ViewManager* view_manager) override;
-
- // Overridden from ViewObserver:
- void OnTreeChanged(const ViewObserver::TreeChangeParams& params) override;
- void OnViewDestroying(View* view) override;
- void OnViewBoundsChanged(View* view,
- const gfx::Rect& old_bounds,
- const gfx::Rect& new_bounds) override;
-
- // Overridden from ui::EventHandler:
- void OnEvent(ui::Event* event) override;
-
- // Overridden from aura::client::FocusChangeObserver:
- void OnWindowFocused(aura::Window* gained_focus,
- aura::Window* lost_focus) override;
-
- // Overridden from aura::client::ActivationChangeObserver:
- void OnWindowActivated(aura::Window* gained_active,
- aura::Window* lost_active) override;
-
- // Creates an aura::Window for every view in the hierarchy beneath |view|,
- // and adds to the registry so that it can be retrieved later via
- // GetWindowForViewId().
- // TODO(beng): perhaps View should have a property bag.
- void RegisterSubtree(View* view, aura::Window* parent);
- // Recursively invokes Unregister() for |view| and all its descendants.
- void UnregisterSubtree(View* view);
- // Deletes the aura::Windows associated with the hierarchy beneath |id|,
- // and removes from the registry.
- void Unregister(View* view);
-
- Shell* shell_;
-
- InterfaceFactoryImplWithContext<WindowManagerService2Impl, WindowManagerApp>
- window_manager_service2_factory_;
-
- InterfaceFactoryImplWithContext<WindowManagerServiceImpl, WindowManagerApp>
- window_manager_service_factory_;
-
- ViewManagerDelegate* wrapped_view_manager_delegate_;
- WindowManagerDelegate* window_manager_delegate_;
-
- ViewManager* view_manager_;
- scoped_ptr<ViewManagerClientFactory> view_manager_client_factory_;
- View* root_;
-
- scoped_ptr<AuraInit> aura_init_;
- scoped_ptr<WindowTreeHostMojo> window_tree_host_;
-
- scoped_ptr<wm::ScopedCaptureClient> capture_client_;
- scoped_ptr<aura::client::FocusClient> focus_client_;
- aura::client::ActivationClient* activation_client_;
-
- Connections connections_;
- ViewIdToWindowMap view_id_to_window_map_;
-
- scoped_ptr<DummyDelegate> dummy_delegate_;
-
- WindowManagerClient* window_manager_client_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerApp);
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_APP_H_
diff --git a/mojo/services/window_manager/window_manager_delegate.h b/mojo/services/window_manager/window_manager_delegate.h
deleted file mode 100644
index 72d7d92..0000000
--- a/mojo/services/window_manager/window_manager_delegate.h
+++ /dev/null
@@ -1,25 +0,0 @@
-// Copyright 2014 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_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
-#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
-
-#include "mojo/public/cpp/bindings/string.h"
-#include "mojo/public/interfaces/application/service_provider.mojom.h"
-
-namespace mojo {
-
-class WindowManagerDelegate {
- public:
- // See WindowManager::Embed() for details.
- virtual void Embed(const String& url,
- InterfaceRequest<ServiceProvider> service_provider) = 0;
-
- protected:
- virtual ~WindowManagerDelegate() {}
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_DELEGATE_H_
diff --git a/mojo/services/window_manager/window_manager_service2_impl.cc b/mojo/services/window_manager/window_manager_service2_impl.cc
deleted file mode 100644
index e00c987..0000000
--- a/mojo/services/window_manager/window_manager_service2_impl.cc
+++ /dev/null
@@ -1,80 +0,0 @@
-
-// Copyright 2014 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/window_manager/window_manager_service2_impl.h"
-
-#include "mojo/services/window_manager/window_manager_app.h"
-
-namespace mojo {
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerService2Impl, public:
-
-WindowManagerService2Impl::WindowManagerService2Impl(
- WindowManagerApp* window_manager)
- : window_manager_(window_manager) {
- window_manager_->AddConnection(this);
-}
-
-WindowManagerService2Impl::~WindowManagerService2Impl() {
- window_manager_->RemoveConnection(this);
-}
-
-void WindowManagerService2Impl::NotifyReady() {
- client()->OnWindowManagerReady();
-}
-
-void WindowManagerService2Impl::NotifyViewFocused(Id new_focused_id,
- Id old_focused_id) {
- client()->OnFocusChanged(old_focused_id, new_focused_id);
-}
-
-void WindowManagerService2Impl::NotifyWindowActivated(Id new_active_id,
- Id old_active_id) {
- client()->OnActiveWindowChanged(old_active_id, new_active_id);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerService2Impl, WindowManager implementation:
-
-void WindowManagerService2Impl::SetCapture(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->SetCapture(view);
- callback.Run(success);
-}
-
-void WindowManagerService2Impl::FocusWindow(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->FocusWindow(view);
- callback.Run(success);
-}
-
-void WindowManagerService2Impl::ActivateWindow(
- Id view,
- const Callback<void(bool)>& callback) {
- bool success = window_manager_->IsReady();
- if (success)
- window_manager_->ActivateWindow(view);
- callback.Run(success);
-}
-
-////////////////////////////////////////////////////////////////////////////////
-// WindowManagerService2Impl, InterfaceImpl overrides:
-
-void WindowManagerService2Impl::OnConnectionEstablished() {
- // If the connection was established prior to the window manager being
- // embedded by the view manager, |window_manager_|'s ViewManagerDelegate
- // impl will call NotifyReady() when it is.
- if (window_manager_->IsReady())
- NotifyReady();
-}
-
-} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_service2_impl.h b/mojo/services/window_manager/window_manager_service2_impl.h
deleted file mode 100644
index a09db91..0000000
--- a/mojo/services/window_manager/window_manager_service2_impl.h
+++ /dev/null
@@ -1,41 +0,0 @@
-// Copyright 2014 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_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
-#define MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
-
-#include "base/basictypes.h"
-#include "mojo/services/public/cpp/view_manager/types.h"
-#include "mojo/services/public/interfaces/window_manager2/window_manager2.mojom.h"
-
-namespace mojo {
-
-class WindowManagerApp;
-
-class WindowManagerService2Impl : public InterfaceImpl<WindowManagerService2> {
- public:
- explicit WindowManagerService2Impl(WindowManagerApp* manager);
- ~WindowManagerService2Impl() override;
-
- void NotifyReady();
- void NotifyViewFocused(Id new_focused_id, Id old_focused_id);
- void NotifyWindowActivated(Id new_active_id, Id old_active_id);
-
- private:
- // Overridden from WindowManagerService:
- void SetCapture(Id view, const Callback<void(bool)>& callback) override;
- void FocusWindow(Id view, const Callback<void(bool)>& callback) override;
- void ActivateWindow(Id view, const Callback<void(bool)>& callback) override;
-
- // Overridden from InterfaceImpl:
- void OnConnectionEstablished() override;
-
- WindowManagerApp* window_manager_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerService2Impl);
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_WINDOW_MANAGER_WINDOW_MANAGER_SERVICE2_IMPL_H_
diff --git a/mojo/services/window_manager/window_manager_service_impl.cc b/mojo/services/window_manager/window_manager_service_impl.cc
deleted file mode 100644
index 2ceee5c..0000000
--- a/mojo/services/window_manager/window_manager_service_impl.cc
+++ /dev/null
@@ -1,37 +0,0 @@
-// Copyright 2014 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/window_manager/window_manager_service_impl.h"
-
-#include "mojo/aura/window_tree_host_mojo.h"
-#include "mojo/converters/input_events/input_events_type_converters.h"
-#include "mojo/services/window_manager/window_manager_app.h"
-#include "mojo/services/window_manager/window_manager_delegate.h"
-
-namespace mojo {
-
-WindowManagerServiceImpl::WindowManagerServiceImpl(WindowManagerApp* app)
- : app_(app) {
-}
-
-WindowManagerServiceImpl::~WindowManagerServiceImpl() {
-}
-
-void WindowManagerServiceImpl::Embed(
- const String& url,
- InterfaceRequest<ServiceProvider> service_provider) {
- app_->window_manager_delegate()->Embed(url, service_provider.Pass());
-}
-
-void WindowManagerServiceImpl::OnViewInputEvent(mojo::EventPtr event) {
- scoped_ptr<ui::Event> ui_event = event.To<scoped_ptr<ui::Event>>();
- if (ui_event)
- app_->host()->SendEventToProcessor(ui_event.get());
-}
-
-void WindowManagerServiceImpl::OnConnectionEstablished() {
- app_->set_window_manager_client(client());
-}
-
-} // namespace mojo
diff --git a/mojo/services/window_manager/window_manager_service_impl.h b/mojo/services/window_manager/window_manager_service_impl.h
deleted file mode 100644
index 39349c2..0000000
--- a/mojo/services/window_manager/window_manager_service_impl.h
+++ /dev/null
@@ -1,36 +0,0 @@
-// Copyright 2014 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_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_
-#define MOJO_SERVICES_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_
-
-#include "base/basictypes.h"
-#include "mojo/services/public/interfaces/window_manager/window_manager.mojom.h"
-
-namespace mojo {
-
-class WindowManagerApp;
-
-class WindowManagerServiceImpl : public InterfaceImpl<WindowManagerService> {
- public:
- explicit WindowManagerServiceImpl(WindowManagerApp* app);
- ~WindowManagerServiceImpl() override;
-
- private:
- // WindowManagerServiceImpl:
- void Embed(const String& url,
- InterfaceRequest<ServiceProvider> service_provider) override;
- void OnViewInputEvent(mojo::EventPtr event) override;
-
- // InterfaceImpl:
- void OnConnectionEstablished() override;
-
- WindowManagerApp* app_;
-
- DISALLOW_COPY_AND_ASSIGN(WindowManagerServiceImpl);
-};
-
-} // namespace mojo
-
-#endif // MOJO_SERVICES_WINDOW_MANAGER_WNDOW_MANAGER_SERVICE_IMPL_H_
diff --git a/mojo/services/window_manager/window_manager_unittests.cc b/mojo/services/window_manager/window_manager_unittests.cc
deleted file mode 100644
index dd05b455..0000000
--- a/mojo/services/window_manager/window_manager_unittests.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// Copyright 2014 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 "base/bind.h"
-#include "base/test/launcher/unit_test_launcher.h"
-#include "base/test/test_suite.h"
-#include "ui/gl/gl_surface.h"
-
-#if defined(USE_X11)
-#include "ui/gfx/x/x11_connection.h"
-#endif
-
-namespace mojo {
-
-class WindowManagerTestSuite : public base::TestSuite {
- public:
- WindowManagerTestSuite(int argc, char** argv) : TestSuite(argc, argv) {}
- ~WindowManagerTestSuite() override {}
-
- protected:
- void Initialize() override {
-#if defined(USE_X11)
- // Each test ends up creating a new thread for the native viewport service.
- // In other words we'll use X on different threads, so tell it that.
- gfx::InitializeThreadedX11();
-#endif
- base::TestSuite::Initialize();
- gfx::GLSurface::InitializeOneOffForTests();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(WindowManagerTestSuite);
-};
-
-} // namespace mojo
-
-int main(int argc, char** argv) {
- mojo::WindowManagerTestSuite test_suite(argc, argv);
-
- return base::LaunchUnitTests(
- argc, argv, base::Bind(&TestSuite::Run, base::Unretained(&test_suite)));
-}
diff --git a/mojo/shell/view_manager_loader.cc b/mojo/shell/view_manager_loader.cc
deleted file mode 100644
index 9128084..0000000
--- a/mojo/shell/view_manager_loader.cc
+++ /dev/null
@@ -1,56 +0,0 @@
-// Copyright 2014 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/shell/view_manager_loader.h"
-
-#include "mojo/public/cpp/application/application_connection.h"
-#include "mojo/public/cpp/application/application_impl.h"
-#include "mojo/services/view_manager/view_manager_init_service_impl.h"
-
-namespace mojo {
-
-using service::ViewManagerInitServiceImpl;
-
-namespace shell {
-
-ViewManagerLoader::ViewManagerLoader() {
-}
-
-ViewManagerLoader::~ViewManagerLoader() {
-}
-
-void ViewManagerLoader::Load(ApplicationManager* manager,
- const GURL& url,
- scoped_refptr<LoadCallbacks> callbacks) {
- ScopedMessagePipeHandle shell_handle = callbacks->RegisterApplication();
- if (!shell_handle.is_valid())
- return;
-
- // TODO(sky): this needs some sort of authentication as well as making sure
- // we only ever have one active at a time.
- scoped_ptr<ApplicationImpl> app(
- new ApplicationImpl(this, shell_handle.Pass()));
- apps_.push_back(app.release());
-}
-
-void ViewManagerLoader::OnApplicationError(ApplicationManager* manager,
- const GURL& url) {
-}
-
-bool ViewManagerLoader::ConfigureIncomingConnection(
- ApplicationConnection* connection) {
- context_.ConfigureIncomingConnection(connection);
- connection->AddService(this);
- return true;
-}
-
-void ViewManagerLoader::Create(
- ApplicationConnection* connection,
- InterfaceRequest<ViewManagerInitService> request) {
- BindToRequest(new ViewManagerInitServiceImpl(connection, &context_),
- &request);
-}
-
-} // namespace shell
-} // namespace mojo
diff --git a/mojo/shell/view_manager_loader.h b/mojo/shell/view_manager_loader.h
deleted file mode 100644
index 83c5f31..0000000
--- a/mojo/shell/view_manager_loader.h
+++ /dev/null
@@ -1,57 +0,0 @@
-// Copyright 2014 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_SHELL_VIEW_MANAGER_LOADER_H_
-#define MOJO_SHELL_VIEW_MANAGER_LOADER_H_
-
-#include "base/macros.h"
-#include "base/memory/scoped_ptr.h"
-#include "base/memory/scoped_vector.h"
-#include "mojo/application_manager/application_loader.h"
-#include "mojo/public/cpp/application/application_delegate.h"
-#include "mojo/public/cpp/application/interface_factory.h"
-#include "mojo/services/public/interfaces/view_manager/view_manager.mojom.h"
-#include "mojo/services/view_manager/view_manager_init_service_context.h"
-
-namespace mojo {
-
-class Application;
-
-namespace shell {
-
-// ApplicationLoader responsible for creating connections to the ViewManager.
-class ViewManagerLoader : public ApplicationLoader,
- public ApplicationDelegate,
- public InterfaceFactory<ViewManagerInitService> {
- public:
- ViewManagerLoader();
- virtual ~ViewManagerLoader();
-
- private:
- // ApplicationLoader overrides:
- virtual void Load(ApplicationManager* manager,
- const GURL& url,
- scoped_refptr<LoadCallbacks> callbacks) override;
- virtual void OnApplicationError(ApplicationManager* manager,
- const GURL& url) override;
-
- // ApplicationDelegate overrides.
- virtual bool ConfigureIncomingConnection(
- mojo::ApplicationConnection* connection) override;
-
- // InterfaceFactory<ViewManagerInitService> overrides.
- virtual void Create(
- ApplicationConnection* connection,
- InterfaceRequest<ViewManagerInitService> request) override;
-
- ScopedVector<Application> apps_;
- service::ViewManagerInitServiceContext context_;
-
- DISALLOW_COPY_AND_ASSIGN(ViewManagerLoader);
-};
-
-} // namespace shell
-} // namespace mojo
-
-#endif // MOJO_SHELL_VIEW_MANAGER_LOADER_H_