Chromium Code Reviews| 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 "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/strings/string_number_conversions.h" | 8 #include "base/strings/string_number_conversions.h" |
| 9 #include "services/service_manager/public/cpp/service_context.h" | 9 #include "services/service_manager/public/cpp/service_context.h" |
| 10 #include "services/ui/demo/window_tree_data.h" | 10 #include "services/ui/demo/window_tree_data.h" |
| 11 #include "services/ui/public/interfaces/constants.mojom.h" | 11 #include "services/ui/public/interfaces/constants.mojom.h" |
| 12 #include "services/ui/public/interfaces/window_tree_host.mojom.h" | 12 #include "services/ui/public/interfaces/window_tree_host.mojom.h" |
| 13 #include "ui/aura/mus/window_tree_client.h" | 13 #include "ui/aura/mus/window_tree_client.h" |
| 14 #include "ui/aura/mus/window_tree_host_mus.h" | 14 #include "ui/aura/mus/window_tree_host_mus.h" |
| 15 #include "ui/display/display.h" | 15 #include "ui/display/display.h" |
| 16 | 16 |
| 17 namespace ui { | 17 namespace ui { |
| 18 namespace demo { | 18 namespace demo { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 class WindowTreeDataExternal : public WindowTreeData { | 22 class WindowTreeDataExternal : public WindowTreeData { |
| 23 public: | 23 public: |
| 24 // Creates a new window tree host associated to the WindowTreeData. | 24 // Creates a new window tree host associated to the WindowTreeData. |
| 25 WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory, | 25 WindowTreeDataExternal(aura::WindowTreeClient* window_tree_client, |
| 26 mojom::WindowTreeClientPtr tree_client, | |
| 27 int square_size) | 26 int square_size) |
| 28 : WindowTreeData(square_size) { | 27 : WindowTreeData(square_size) { |
| 29 // TODO(tonikitoo,fwang): Extend the API to allow creating WindowTreeHost | 28 window_tree_host_ = |
| 30 // using the WindowTreeClient. | 29 base::MakeUnique<aura::WindowTreeHostMus>(window_tree_client); |
|
fwang
2017/03/07 09:21:24
IIUC, the Chromium style is to use setter for priv
tonikitoo
2017/03/07 14:00:49
Done.
| |
| 31 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); | |
| 32 } | 30 } |
| 33 | 31 |
| 34 private: | 32 private: |
| 35 // Holds the Mojo pointer to the window tree host. | 33 void Init( |
| 36 mojom::WindowTreeHostPtr host_; | 34 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) override { |
| 35 InitImpl(window_tree_host_.get()); | |
| 36 } | |
|
fwang
2017/03/07 09:21:25
Let's postpone too much changes in MusDemo and jus
| |
| 37 | 37 |
| 38 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); | 38 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal); |
| 39 }; | 39 }; |
| 40 | 40 |
| 41 int GetSquareSizeForWindow(int window_index) { | 41 int GetSquareSizeForWindow(int window_index) { |
| 42 return 50 * window_index + 400; | 42 return 50 * window_index + 400; |
| 43 }; | 43 }; |
| 44 | 44 |
| 45 } // namespace | 45 } // namespace |
| 46 | 46 |
| 47 MusDemoExternal::MusDemoExternal() {} | 47 MusDemoExternal::MusDemoExternal() {} |
| 48 | 48 |
| 49 MusDemoExternal::~MusDemoExternal() {} | 49 MusDemoExternal::~MusDemoExternal() {} |
| 50 | 50 |
| 51 std::unique_ptr<aura::WindowTreeClient> | 51 std::unique_ptr<aura::WindowTreeClient> |
| 52 MusDemoExternal::CreateWindowTreeClient() { | 52 MusDemoExternal::CreateWindowTreeClient() { |
| 53 return base::MakeUnique<aura::WindowTreeClient>( | 53 return base::MakeUnique<aura::WindowTreeClient>(context()->connector(), this); |
| 54 context()->connector(), this, nullptr, | 54 } |
| 55 MakeRequest(&window_tree_client_mojo_)); | 55 |
| 56 bool MusDemoExternal::HasPendingWindowTreeData() const { | |
| 57 return initialized_windows_count_ != window_tree_data_list().size(); | |
|
fwang
2017/03/07 09:21:24
Again overriding HasPendingWindowTreeData is not n
tonikitoo
2017/03/07 14:00:49
Done.
| |
| 56 } | 58 } |
| 57 | 59 |
| 58 void MusDemoExternal::OnStartImpl() { | 60 void MusDemoExternal::OnStartImpl() { |
| 59 const base::CommandLine* command_line = | 61 const base::CommandLine* command_line = |
| 60 base::CommandLine::ForCurrentProcess(); | 62 base::CommandLine::ForCurrentProcess(); |
| 61 if (command_line->HasSwitch("external-window-count")) { | 63 if (command_line->HasSwitch("external-window-count")) { |
| 62 if (!base::StringToSizeT( | 64 if (!base::StringToSizeT( |
| 63 command_line->GetSwitchValueASCII("external-window-count"), | 65 command_line->GetSwitchValueASCII("external-window-count"), |
| 64 &number_of_windows_)) { | 66 &number_of_windows_)) { |
| 65 LOG(FATAL) << "Invalid value for \'external-window-count\'"; | 67 LOG(FATAL) << "Invalid value for \'external-window-count\'"; |
| 66 return; | 68 return; |
| 67 } | 69 } |
| 68 } | 70 } |
| 69 | 71 |
| 70 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow connection | 72 window_tree_client()->ConnectViaWindowTreeHostFactory(); |
| 71 // to the window tree host factory using window_tree_client(). | |
| 72 context()->connector()->BindInterface(ui::mojom::kServiceName, | |
| 73 &window_tree_host_factory_); | |
| 74 | 73 |
| 75 // TODO(tonikitoo,fwang): Implement management of displays in external mode. | 74 // TODO(tonikitoo,fwang): Implement management of displays in external mode. |
| 76 // For now, a fake display is created in order to work around an assertion in | 75 // For now, a fake display is created in order to work around an assertion in |
| 77 // aura::GetDeviceScaleFactorFromDisplay(). | 76 // aura::GetDeviceScaleFactorFromDisplay(). |
| 78 AddPrimaryDisplay(display::Display(0)); | 77 AddPrimaryDisplay(display::Display(0)); |
| 79 | 78 |
| 80 // The number of windows to open is specified by number_of_windows_. The | 79 // The number of windows to open is specified by number_of_windows_. The |
| 81 // windows are opened sequentially (the first one here and the others after | 80 // windows are opened sequentially (the first one here and the others after |
| 82 // each call to OnEmbed) to ensure that the WindowTreeHostMus passed to | 81 // each call to OnEmbed) to ensure that the WindowTreeHostMus passed to |
| 83 // OnEmbed corresponds to the WindowTreeDataExternal::host_ created in | 82 // OnEmbed corresponds to the WindowTreeDataExternal::host_ created in |
| 84 // OpenNewWindow. | 83 // OpenNewWindow. |
| 85 OpenNewWindow(); | 84 OpenNewWindow(); |
| 86 } | 85 } |
| 87 | 86 |
| 88 void MusDemoExternal::OpenNewWindow() { | 87 void MusDemoExternal::OpenNewWindow() { |
| 89 // TODO(tonikitoo,fwang): Extend the WindowTreeClient API to allow creation | |
| 90 // of window tree host. Then pass window_tree_client() here and remove | |
| 91 // window_tree_host_factory_ and window_tree_client_mojo_. Currently | |
| 92 // window_tree_client_mojo_ is only initialized once so this is incorrect when | |
| 93 // kNumberOfWindows > 1. | |
| 94 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( | 88 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>( |
| 95 window_tree_host_factory_.get(), std::move(window_tree_client_mojo_), | 89 window_tree_client(), |
| 96 GetSquareSizeForWindow(initialized_windows_count_))); | 90 GetSquareSizeForWindow(initialized_windows_count_))); |
| 97 } | 91 } |
| 98 | 92 |
| 99 void MusDemoExternal::OnEmbed( | 93 void MusDemoExternal::OnEmbed( |
| 100 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | 94 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { |
| 101 InitWindowTreeData(std::move(window_tree_host)); | 95 DCHECK(!window_tree_host); |
| 96 InitWindowTreeData(nullptr); | |
|
fwang
2017/03/07 09:21:24
This is a bit weird, but I guess it's ok if we don
tonikitoo
2017/03/07 14:00:49
This is right. As written in the commit message, t
| |
| 102 initialized_windows_count_++; | 97 initialized_windows_count_++; |
| 103 | 98 |
| 104 // Open the next window until the requested number of windows is reached. | 99 // Open the next window until the requested number of windows is reached. |
| 105 if (initialized_windows_count_ < number_of_windows_) | 100 if (initialized_windows_count_ < number_of_windows_) |
| 106 OpenNewWindow(); | 101 OpenNewWindow(); |
| 107 } | 102 } |
| 108 | 103 |
| 109 void MusDemoExternal::OnEmbedRootDestroyed( | 104 void MusDemoExternal::OnEmbedRootDestroyed( |
| 110 aura::WindowTreeHostMus* window_tree_host) { | 105 aura::WindowTreeHostMus* window_tree_host) { |
| 111 RemoveWindowTreeData(window_tree_host); | 106 RemoveWindowTreeData(window_tree_host); |
| 112 } | 107 } |
| 113 | 108 |
| 114 } // namespace demo | 109 } // namespace demo |
| 115 } // namespace ui | 110 } // namespace ui |
| OLD | NEW |