Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "services/ui/demo/mus_demo_external.h" | |
| 6 | |
| 7 #include "services/service_manager/public/cpp/service_context.h" | |
| 8 #include "services/ui/demo/window_tree_data.h" | |
| 9 #include "services/ui/public/interfaces/constants.mojom.h" | |
| 10 #include "services/ui/public/interfaces/window_tree_host.mojom.h" | |
| 11 #include "ui/aura/mus/window_tree_client.h" | |
| 12 #include "ui/aura/mus/window_tree_host_mus.h" | |
| 13 #include "ui/display/display.h" | |
| 14 | |
| 15 namespace ui { | |
| 16 namespace demo { | |
| 17 | |
| 18 namespace { | |
| 19 | |
| 20 class WindowTreeDataExternal : public WindowTreeData { | |
| 21 public: | |
| 22 // Creates a new window tree host associated to the WindowTreeData. | |
| 23 WindowTreeDataExternal(mojom::WindowTreeHostFactory* factory, | |
| 24 mojom::WindowTreeClientPtr tree_client, | |
| 25 int square_size) | |
| 26 : WindowTreeData(square_size) { | |
| 27 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); | |
| 28 } | |
| 29 | |
| 30 private: | |
| 31 // Holds the Mojo pointer to the window tree host. | |
| 32 mojom::WindowTreeHostPtr host_; | |
| 33 }; | |
| 34 | |
| 35 // Size of square in pixels to draw. | |
| 36 const int kSquareSize = 500; | |
| 37 } | |
|
kylechar
2017/02/21 19:15:59
} // namespace
fwang
2017/02/21 19:30:04
Done.
| |
| 38 | |
| 39 MusDemoExternal::MusDemoExternal() {} | |
| 40 | |
| 41 MusDemoExternal::~MusDemoExternal() {} | |
| 42 | |
| 43 void MusDemoExternal::OnStartImpl( | |
| 44 std::unique_ptr<aura::WindowTreeClient>* window_tree_client, | |
| 45 std::unique_ptr<WindowTreeData>* window_tree_data) { | |
| 46 context()->connector()->BindInterface(ui::mojom::kServiceName, | |
| 47 &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 | |
| 56 // 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 | |
| 58 // aura::GetDeviceScaleFactorFromDisplay(). | |
| 59 AddPrimaryDisplay(display::Display(0)); | |
| 60 } | |
| 61 | |
| 62 void MusDemoExternal::OnEmbed( | |
| 63 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { | |
| 64 InitWindowTreeData(std::move(window_tree_host)); | |
| 65 } | |
| 66 | |
| 67 void MusDemoExternal::OnEmbedRootDestroyed( | |
| 68 aura::WindowTreeHostMus* window_tree_host) { | |
| 69 CleanupWindowTreeData(); | |
| 70 } | |
| 71 | |
| 72 } // namespace demo | |
| 73 } // namespace ui | |
| OLD | NEW |