OLD | NEW |
---|---|
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(aura::WindowTreeClient* window_tree_client, |
24 mojom::WindowTreeClientPtr tree_client, | |
25 int square_size) | 24 int square_size) |
26 : WindowTreeData(square_size) { | 25 : WindowTreeData(square_size) { |
27 // TODO(tonikitoo,fwang): Extend the API to allow creating WindowTreeHost | 26 window_tree_client->CreateHost(MakeRequest(&host_)); |
28 // using the WindowTreeClient. | |
29 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); | |
30 } | 27 } |
31 | 28 |
32 private: | 29 private: |
33 // Holds the Mojo pointer to the window tree host. | 30 // Holds the Mojo pointer to the window tree host. |
34 mojom::WindowTreeHostPtr host_; | 31 mojom::WindowTreeHostPtr host_; |
35 | 32 |
36 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); | 33 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); |
37 }; | 34 }; |
38 | 35 |
39 // Number of windows to open. | 36 // Number of windows to open. |
40 // TODO(tonikitoo,fwang): Open multiple windows. | 37 // TODO(tonikitoo,fwang): Open multiple windows. |
41 const size_t kNumberOfWindows = 1; | 38 const size_t kNumberOfWindows = 1; |
fwang
2017/03/01 06:38:47
Maybe you want to change this to e.g. kNumberOfWin
| |
42 | 39 |
43 int GetSquareSizeForWindow(int window_index) { | 40 int GetSquareSizeForWindow(int window_index) { |
44 return 50 * window_index + 400; | 41 return 50 * window_index + 400; |
45 }; | 42 }; |
46 | 43 |
47 } // namespace | 44 } // namespace |
48 | 45 |
49 MusDemoExternal::MusDemoExternal() {} | 46 MusDemoExternal::MusDemoExternal() {} |
50 | 47 |
51 MusDemoExternal::~MusDemoExternal() {} | 48 MusDemoExternal::~MusDemoExternal() {} |
52 | 49 |
53 std::unique_ptr<aura::WindowTreeClient> | 50 std::unique_ptr<aura::WindowTreeClient> |
54 MusDemoExternal::CreateWindowTreeClient() { | 51 MusDemoExternal::CreateWindowTreeClient() { |
55 return base::MakeUnique<aura::WindowTreeClient>( | 52 return base::MakeUnique<aura::WindowTreeClient>(context()->connector(), this); |
56 context()->connector(), this, nullptr, | |
57 MakeRequest(&window_tree_client_mojo_)); | |
58 } | 53 } |
59 | 54 |
60 void MusDemoExternal::OnStartImpl() { | 55 void MusDemoExternal::OnStartImpl() { |
61 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow connection | 56 window_tree_client()->ConnectViaWindowTreeHostFactory(); |
62 // to the window tree host factory using window_tree_client(). | |
63 context()->connector()->BindInterface(ui::mojom::kServiceName, | |
64 &window_tree_host_factory_); | |
65 | 57 |
66 // TODO(tonikitoo,fwang): Implement management of displays in external mode. | 58 // TODO(tonikitoo,fwang): Implement management of displays in external mode. |
67 // For now, a fake display is created in order to work around an assertion in | 59 // For now, a fake display is created in order to work around an assertion in |
68 // aura::GetDeviceScaleFactorFromDisplay(). | 60 // aura::GetDeviceScaleFactorFromDisplay(). |
69 AddPrimaryDisplay(display::Display(0)); | 61 AddPrimaryDisplay(display::Display(0)); |
70 | 62 |
71 // The number of windows to open is specified by kNumberOfWindows. The windows | 63 // 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 | 64 // are opened sequentially (the first one here and the others after each call |
73 // to OnEmbed) to ensure that the WindowTreeHostMus passed to OnEmbed | 65 // to OnEmbed) to ensure that the WindowTreeHostMus passed to OnEmbed |
74 // corresponds to the WindowTreeDataExternal::host_ created in OpenNewWindow. | 66 // corresponds to the WindowTreeDataExternal::host_ created in OpenNewWindow. |
75 OpenNewWindow(); | 67 OpenNewWindow(); |
76 } | 68 } |
77 | 69 |
78 void MusDemoExternal::OpenNewWindow() { | 70 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>( | 71 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( |
85 window_tree_host_factory_.get(), std::move(window_tree_client_mojo_), | 72 window_tree_client(), |
86 GetSquareSizeForWindow(initialized_windows_count_))); | 73 GetSquareSizeForWindow(initialized_windows_count_))); |
87 } | 74 } |
88 | 75 |
89 void MusDemoExternal::OnEmbed( | 76 void MusDemoExternal::OnEmbed( |
90 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 77 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
91 InitWindowTreeData(std::move(window_tree_host)); | 78 InitWindowTreeData(std::move(window_tree_host)); |
92 initialized_windows_count_++; | 79 initialized_windows_count_++; |
93 | 80 |
94 // Open the next window until the requested number of windows is reached. | 81 // Open the next window until the requested number of windows is reached. |
95 if (initialized_windows_count_ < kNumberOfWindows) | 82 if (initialized_windows_count_ < kNumberOfWindows) |
96 OpenNewWindow(); | 83 OpenNewWindow(); |
97 } | 84 } |
98 | 85 |
99 void MusDemoExternal::OnEmbedRootDestroyed( | 86 void MusDemoExternal::OnEmbedRootDestroyed( |
100 aura::WindowTreeHostMus* window_tree_host) { | 87 aura::WindowTreeHostMus* window_tree_host) { |
101 RemoveWindowTreeData(window_tree_host); | 88 RemoveWindowTreeData(window_tree_host); |
102 } | 89 } |
103 | 90 |
104 } // namespace demo | 91 } // namespace demo |
105 } // namespace ui | 92 } // namespace ui |
OLD | NEW |