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

Side by Side Diff: services/ui/demo/mus_demo_external.cc

Issue 2700493005: Mus Demo: Refactor code to prepare multiple windows in external mode (Closed)
Patch Set: Rename MusExternal::tree_client_ & describes the helper functions for WindowTreeData. 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "services/ui/demo/mus_demo_external.h" 5 #include "services/ui/demo/mus_demo_external.h"
6 6
7 #include "services/service_manager/public/cpp/service_context.h" 7 #include "services/service_manager/public/cpp/service_context.h"
8 #include "services/ui/demo/window_tree_data.h" 8 #include "services/ui/demo/window_tree_data.h"
9 #include "services/ui/public/interfaces/constants.mojom.h" 9 #include "services/ui/public/interfaces/constants.mojom.h"
10 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 10 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
11 #include "ui/aura/mus/window_tree_client.h" 11 #include "ui/aura/mus/window_tree_client.h"
12 #include "ui/aura/mus/window_tree_host_mus.h" 12 #include "ui/aura/mus/window_tree_host_mus.h"
13 #include "ui/display/display.h" 13 #include "ui/display/display.h"
14 14
15 namespace ui { 15 namespace ui {
16 namespace demo { 16 namespace demo {
17 17
18 namespace { 18 namespace {
19 19
20 class WindowTreeDataExternal : public WindowTreeData { 20 class WindowTreeDataExternal : public WindowTreeData {
21 public: 21 public:
22 // Creates a new window tree host associated to the WindowTreeData. 22 // Creates a new window tree host associated to the WindowTreeData.
23 WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory, 23 WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory,
24 mojom::WindowTreeClientPtr tree_client, 24 mojom::WindowTreeClientPtr tree_client,
25 int square_size) 25 int square_size)
26 : WindowTreeData(square_size) { 26 : WindowTreeData(square_size) {
27 // TODO(tonikitoo,fwang): Extend the API to allow creating WindowTreeHost
28 // using the WindowTreeClient.
27 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); 29 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client));
28 } 30 }
29 31
30 private: 32 private:
31 // Holds the Mojo pointer to the window tree host. 33 // Holds the Mojo pointer to the window tree host.
32 mojom::WindowTreeHostPtr host_; 34 mojom::WindowTreeHostPtr host_;
35
36 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal);
33 }; 37 };
34 38
35 // Size of square in pixels to draw. 39 // Number of windows to open.
36 const int kSquareSize = 500; 40 // TODO(tonikitoo,fwang): Open multiple windows.
41 const size_t kNumberOfWindows = 1;
42
43 int GetSquareSizeForWindow(int window_index) {
44 return 50 * window_index + 400;
45 };
46
37 } // namespace 47 } // namespace
38 48
39 MusDemoExternal::MusDemoExternal() {} 49 MusDemoExternal::MusDemoExternal() {}
40 50
41 MusDemoExternal::~MusDemoExternal() {} 51 MusDemoExternal::~MusDemoExternal() {}
42 52
43 void MusDemoExternal::OnStartImpl( 53 std::unique_ptr<aura::WindowTreeClient>
44 std::unique_ptr<aura::WindowTreeClient>* window_tree_client, 54 MusDemoExternal::CreateWindowTreeClient() {
45 std::unique_ptr<WindowTreeData>* window_tree_data) { 55 return base::MakeUnique<aura::WindowTreeClient>(
56 context()->connector(), this, nullptr,
57 MakeRequest(&window_tree_client_mojo_));
58 }
59
60 void MusDemoExternal::OnStartImpl() {
61 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow connection
62 // to the window tree host factory using window_tree_client().
46 context()->connector()->BindInterface(ui::mojom::kServiceName, 63 context()->connector()->BindInterface(ui::mojom::kServiceName,
47 &window_tree_host_factory_); 64 &window_tree_host_factory_);
48 mojom::WindowTreeClientPtr tree_client;
49 *window_tree_client = base::MakeUnique<aura::WindowTreeClient>(
50 context()->connector(), this, nullptr, MakeRequest(&tree_client));
51 // TODO(tonikitoo,fwang): Open two external windows with different square
52 // sizes.
53 *window_tree_data = base::MakeUnique<WindowTreeDataExternal>(
54 window_tree_host_factory_.get(), std::move(tree_client), kSquareSize);
55 65
56 // TODO(tonikitoo,fwang): Implement management of displays in external mode. 66 // TODO(tonikitoo,fwang): Implement management of displays in external mode.
57 // For now, a fake display is created in order to work around an assertion in 67 // For now, a fake display is created in order to work around an assertion in
58 // aura::GetDeviceScaleFactorFromDisplay(). 68 // aura::GetDeviceScaleFactorFromDisplay().
59 AddPrimaryDisplay(display::Display(0)); 69 AddPrimaryDisplay(display::Display(0));
70
71 // The number of windows to open is specified by kNumberOfWindows. The windows
72 // are opened sequentially (the first one here and the others after each call
73 // to OnEmbed) to ensure that the WindowTreeHostMus passed to OnEmbed
74 // corresponds to the WindowTreeDataExternal::host_ created in OpenNewWindow.
75 OpenNewWindow();
76 }
77
78 void MusDemoExternal::OpenNewWindow() {
79 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow creation
80 // of window tree host. Then pass window_tree_client() here and remove
81 // window_tree_host_factory_ and window_tree_client_mojo_. Currently
82 // window_tree_client_mojo_ is only initialized once so this is incorrect when
83 // kNumberOfWindows > 1.
84 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>(
85 window_tree_host_factory_.get(), std::move(window_tree_client_mojo_),
86 GetSquareSizeForWindow(initialized_windows_count_)));
60 } 87 }
61 88
62 void MusDemoExternal::OnEmbed( 89 void MusDemoExternal::OnEmbed(
63 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 90 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
64 InitWindowTreeData(std::move(window_tree_host)); 91 InitWindowTreeData(std::move(window_tree_host));
92 initialized_windows_count_++;
93
94 // Open the next window until the requested number of windows is reached.
95 if (initialized_windows_count_ < kNumberOfWindows)
96 OpenNewWindow();
65 } 97 }
66 98
67 void MusDemoExternal::OnEmbedRootDestroyed( 99 void MusDemoExternal::OnEmbedRootDestroyed(
68 aura::WindowTreeHostMus* window_tree_host) { 100 aura::WindowTreeHostMus* window_tree_host) {
69 CleanupWindowTreeData(); 101 RemoveWindowTreeData(window_tree_host);
70 } 102 }
71 103
72 } // namespace demo 104 } // namespace demo
73 } // namespace ui 105 } // namespace ui
OLDNEW
« 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