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

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

Issue 2723853004: Mus Demo: Add a comment line switch for launching multiple windows in external mode (Closed)
Patch Set: addressed kylechar feedback Created 3 years, 9 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') | no next file » | 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 "base/command_line.h"
8 #include "base/strings/string_number_conversions.h"
7 #include "services/service_manager/public/cpp/service_context.h" 9 #include "services/service_manager/public/cpp/service_context.h"
8 #include "services/ui/demo/window_tree_data.h" 10 #include "services/ui/demo/window_tree_data.h"
9 #include "services/ui/public/interfaces/constants.mojom.h" 11 #include "services/ui/public/interfaces/constants.mojom.h"
10 #include "services/ui/public/interfaces/window_tree_host.mojom.h" 12 #include "services/ui/public/interfaces/window_tree_host.mojom.h"
11 #include "ui/aura/mus/window_tree_client.h" 13 #include "ui/aura/mus/window_tree_client.h"
12 #include "ui/aura/mus/window_tree_host_mus.h" 14 #include "ui/aura/mus/window_tree_host_mus.h"
13 #include "ui/display/display.h" 15 #include "ui/display/display.h"
14 16
15 namespace ui { 17 namespace ui {
16 namespace demo { 18 namespace demo {
(...skipping 12 matching lines...) Expand all
29 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); 31 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client));
30 } 32 }
31 33
32 private: 34 private:
33 // Holds the Mojo pointer to the window tree host. 35 // Holds the Mojo pointer to the window tree host.
34 mojom::WindowTreeHostPtr host_; 36 mojom::WindowTreeHostPtr host_;
35 37
36 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); 38 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal);
37 }; 39 };
38 40
39 // Number of windows to open.
40 // TODO(tonikitoo,fwang): Open multiple windows.
41 const size_t kNumberOfWindows = 1;
42
43 int GetSquareSizeForWindow(int window_index) { 41 int GetSquareSizeForWindow(int window_index) {
44 return 50 * window_index + 400; 42 return 50 * window_index + 400;
45 }; 43 };
46 44
47 } // namespace 45 } // namespace
48 46
49 MusDemoExternal::MusDemoExternal() {} 47 MusDemoExternal::MusDemoExternal() {}
50 48
51 MusDemoExternal::~MusDemoExternal() {} 49 MusDemoExternal::~MusDemoExternal() {}
52 50
53 std::unique_ptr<aura::WindowTreeClient> 51 std::unique_ptr<aura::WindowTreeClient>
54 MusDemoExternal::CreateWindowTreeClient() { 52 MusDemoExternal::CreateWindowTreeClient() {
55 return base::MakeUnique<aura::WindowTreeClient>( 53 return base::MakeUnique<aura::WindowTreeClient>(
56 context()->connector(), this, nullptr, 54 context()->connector(), this, nullptr,
57 MakeRequest(&window_tree_client_mojo_)); 55 MakeRequest(&window_tree_client_mojo_));
58 } 56 }
59 57
60 void MusDemoExternal::OnStartImpl() { 58 void MusDemoExternal::OnStartImpl() {
59 const base::CommandLine* command_line =
60 base::CommandLine::ForCurrentProcess();
61 if (command_line->HasSwitch("external-window-count")) {
62 if (!base::StringToSizeT(
63 command_line->GetSwitchValueASCII("external-window-count"),
64 &number_of_windows_)) {
65 LOG(FATAL) << "Invalid value for \'external-window-count\'";
66 return;
67 }
68 }
69
61 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow connection 70 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow connection
62 // to the window tree host factory using window_tree_client(). 71 // to the window tree host factory using window_tree_client().
63 context()->connector()->BindInterface(ui::mojom::kServiceName, 72 context()->connector()->BindInterface(ui::mojom::kServiceName,
64 &window_tree_host_factory_); 73 &window_tree_host_factory_);
65 74
66 // TODO(tonikitoo,fwang): Implement management of displays in external mode. 75 // 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 76 // For now, a fake display is created in order to work around an assertion in
68 // aura::GetDeviceScaleFactorFromDisplay(). 77 // aura::GetDeviceScaleFactorFromDisplay().
69 AddPrimaryDisplay(display::Display(0)); 78 AddPrimaryDisplay(display::Display(0));
70 79
71 // The number of windows to open is specified by kNumberOfWindows. The windows 80 // The number of windows to open is specified by number_of_windows_. The
72 // are opened sequentially (the first one here and the others after each call 81 // windows are opened sequentially (the first one here and the others after
73 // to OnEmbed) to ensure that the WindowTreeHostMus passed to OnEmbed 82 // each call to OnEmbed) to ensure that the WindowTreeHostMus passed to
74 // corresponds to the WindowTreeDataExternal::host_ created in OpenNewWindow. 83 // OnEmbed corresponds to the WindowTreeDataExternal::host_ created in
84 // OpenNewWindow.
75 OpenNewWindow(); 85 OpenNewWindow();
76 } 86 }
77 87
78 void MusDemoExternal::OpenNewWindow() { 88 void MusDemoExternal::OpenNewWindow() {
79 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow creation 89 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow creation
80 // of window tree host. Then pass window_tree_client() here and remove 90 // of window tree host. Then pass window_tree_client() here and remove
81 // window_tree_host_factory_ and window_tree_client_mojo_. Currently 91 // window_tree_host_factory_ and window_tree_client_mojo_. Currently
82 // window_tree_client_mojo_ is only initialized once so this is incorrect when 92 // window_tree_client_mojo_ is only initialized once so this is incorrect when
83 // kNumberOfWindows > 1. 93 // kNumberOfWindows > 1.
84 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( 94 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>(
85 window_tree_host_factory_.get(), std::move(window_tree_client_mojo_), 95 window_tree_host_factory_.get(), std::move(window_tree_client_mojo_),
86 GetSquareSizeForWindow(initialized_windows_count_))); 96 GetSquareSizeForWindow(initialized_windows_count_)));
87 } 97 }
88 98
89 void MusDemoExternal::OnEmbed( 99 void MusDemoExternal::OnEmbed(
90 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 100 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
91 InitWindowTreeData(std::move(window_tree_host)); 101 InitWindowTreeData(std::move(window_tree_host));
92 initialized_windows_count_++; 102 initialized_windows_count_++;
93 103
94 // Open the next window until the requested number of windows is reached. 104 // Open the next window until the requested number of windows is reached.
95 if (initialized_windows_count_ < kNumberOfWindows) 105 if (initialized_windows_count_ < number_of_windows_)
96 OpenNewWindow(); 106 OpenNewWindow();
97 } 107 }
98 108
99 void MusDemoExternal::OnEmbedRootDestroyed( 109 void MusDemoExternal::OnEmbedRootDestroyed(
100 aura::WindowTreeHostMus* window_tree_host) { 110 aura::WindowTreeHostMus* window_tree_host) {
101 RemoveWindowTreeData(window_tree_host); 111 RemoveWindowTreeData(window_tree_host);
102 } 112 }
103 113
104 } // namespace demo 114 } // namespace demo
105 } // namespace ui 115 } // namespace ui
OLDNEW
« no previous file with comments | « services/ui/demo/mus_demo_external.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698