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

Unified Diff: services/ui/demo/mus_demo_external.cc

Issue 2622103004: Mus Demo: Demonstrate external window mode (Closed)
Patch Set: Add description of internal VS external modes ; fix namespace comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « services/ui/demo/mus_demo_external.h ('k') | services/ui/demo/mus_demo_internal.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: services/ui/demo/mus_demo_external.cc
diff --git a/services/ui/demo/mus_demo_external.cc b/services/ui/demo/mus_demo_external.cc
new file mode 100644
index 0000000000000000000000000000000000000000..d4026285c0d9c7c271c81728abd16e17f0c9d270
--- /dev/null
+++ b/services/ui/demo/mus_demo_external.cc
@@ -0,0 +1,73 @@
+// Copyright 2017 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 "services/ui/demo/mus_demo_external.h"
+
+#include "services/service_manager/public/cpp/service_context.h"
+#include "services/ui/demo/window_tree_data.h"
+#include "services/ui/public/interfaces/constants.mojom.h"
+#include "services/ui/public/interfaces/window_tree_host.mojom.h"
+#include "ui/aura/mus/window_tree_client.h"
+#include "ui/aura/mus/window_tree_host_mus.h"
+#include "ui/display/display.h"
+
+namespace ui {
+namespace demo {
+
+namespace {
+
+class WindowTreeDataExternal : public WindowTreeData {
+ public:
+ // Creates a new window tree host associated to the WindowTreeData.
+ WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory,
+ mojom::WindowTreeClientPtr tree_client,
+ int square_size)
+ : WindowTreeData(square_size) {
+ factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client));
+ }
+
+ private:
+ // Holds the Mojo pointer to the window tree host.
+ mojom::WindowTreeHostPtr host_;
+};
+
+// Size of square in pixels to draw.
+const int kSquareSize = 500;
+} // namespace
+
+MusDemoExternal::MusDemoExternal() {}
+
+MusDemoExternal::~MusDemoExternal() {}
+
+void MusDemoExternal::OnStartImpl(
+ std::unique_ptr<aura::WindowTreeClient>* window_tree_client,
+ std::unique_ptr<WindowTreeData>* window_tree_data) {
+ context()->connector()->BindInterface(ui::mojom::kServiceName,
+ &window_tree_host_factory_);
+ mojom::WindowTreeClientPtr tree_client;
+ *window_tree_client = base::MakeUnique<aura::WindowTreeClient>(
+ context()->connector(), this, nullptr, MakeRequest(&tree_client));
+ // TODO(tonikitoo,fwang): Open two external windows with different square
+ // sizes.
+ *window_tree_data = base::MakeUnique<WindowTreeDataExternal>(
+ window_tree_host_factory_.get(), std::move(tree_client), kSquareSize);
+
+ // TODO(tonikitoo,fwang): Implement management of displays in external mode.
+ // For now, a fake display is created in order to work around an assertion in
+ // aura::GetDeviceScaleFactorFromDisplay().
+ AddPrimaryDisplay(display::Display(0));
+}
+
+void MusDemoExternal::OnEmbed(
+ std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
+ InitWindowTreeData(std::move(window_tree_host));
+}
+
+void MusDemoExternal::OnEmbedRootDestroyed(
+ aura::WindowTreeHostMus* window_tree_host) {
+ CleanupWindowTreeData();
+}
+
+} // namespace demo
+} // namespace ui
« no previous file with comments | « services/ui/demo/mus_demo_external.h ('k') | services/ui/demo/mus_demo_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698