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

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: Address some feedback from Antonio. 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
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): Create the host via the window tree client.
27 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client)); 28 factory->CreateWindowTreeHost(MakeRequest(&host_), std::move(tree_client));
28 } 29 }
29 30
30 private: 31 private:
31 // Holds the Mojo pointer to the window tree host. 32 // Holds the Mojo pointer to the window tree host.
32 mojom::WindowTreeHostPtr host_; 33 mojom::WindowTreeHostPtr host_;
34
35 DISALLOW_COPY_AND_ASSIGN(WindowTreeDataExternal);
33 }; 36 };
34 37
35 // Size of square in pixels to draw. 38 // Size of square in pixels to draw
36 const int kSquareSize = 500; 39 const int kSquareSizeFunctionIntercept = 400;
40 const int kSquareSizeFunctionSlope = 50;
41
42 // Number of windows to open.
43 // TODO(tonikitoo,fwang): Open multiple windows.
44 const unsigned kNumberOfWindows = 1;
kylechar 2017/02/23 22:45:30 Same comment about type.
fwang 2017/02/24 10:08:51 Acknowledged.
fwang 2017/02/24 10:40:11 Done.
45
46 static int GetSquareSizeForWindow(int window_index) {
kylechar 2017/02/23 22:45:30 I'm not sure I actually understand what this does?
kylechar 2017/02/23 22:45:30 The static qualifier here isn't necessary due to t
fwang 2017/02/24 10:08:51 Yes, it's just to have different size squares on e
fwang 2017/02/24 10:08:51 Acknowledged.
fwang 2017/02/24 10:40:11 Done.
47 return kSquareSizeFunctionSlope * window_index + kSquareSizeFunctionIntercept;
48 };
49
37 } // namespace 50 } // namespace
38 51
39 MusDemoExternal::MusDemoExternal() {} 52 MusDemoExternal::MusDemoExternal() {}
40 53
41 MusDemoExternal::~MusDemoExternal() {} 54 MusDemoExternal::~MusDemoExternal() {}
42 55
43 void MusDemoExternal::OnStartImpl( 56 std::unique_ptr<aura::WindowTreeClient>
44 std::unique_ptr<aura::WindowTreeClient>* window_tree_client, 57 MusDemoExternal::CreateWindowTreeClient() {
45 std::unique_ptr<WindowTreeData>* window_tree_data) { 58 return base::MakeUnique<aura::WindowTreeClient>(
59 context()->connector(), this, nullptr, MakeRequest(&tree_client_));
60 }
61
62 void MusDemoExternal::OnStartImpl() {
63 // TODO(tonikitoo,fwang): Do the connection to window tree host factory:
64 // window_tree_client()->ConnectViaWindowTreeHostFactory();
kylechar 2017/02/23 22:45:30 Delete commented out code.
fwang 2017/02/24 10:08:51 OK, will do that. As I said, the goal is to replac
fwang 2017/02/24 10:40:11 Done.
46 context()->connector()->BindInterface(ui::mojom::kServiceName, 65 context()->connector()->BindInterface(ui::mojom::kServiceName,
47 &window_tree_host_factory_); 66 &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 67
56 // TODO(tonikitoo,fwang): Implement management of displays in external mode. 68 // 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 69 // For now, a fake display is created in order to work around an assertion in
58 // aura::GetDeviceScaleFactorFromDisplay(). 70 // aura::GetDeviceScaleFactorFromDisplay().
59 AddPrimaryDisplay(display::Display(0)); 71 AddPrimaryDisplay(display::Display(0));
72
73 // The number of windows to open is specified by kNumberOfWindows. The windows
74 // are opened sequentially (the first one here and the others after each call
75 // to OnEmbed) to ensure that the WindowTreeHostMus passed to OnEmbed
76 // corresponds to the WindowTreeDataExternal::host_ created in OpenNewWindow.
77 OpenNewWindow();
78 }
79
80 void MusDemoExternal::OpenNewWindow() {
81 AppendWindowTreeData(base::MakeUnique<WindowTreeDataExternal>(
82 window_tree_host_factory_.get(), std::move(tree_client_),
kylechar 2017/02/23 22:45:30 For two windows, you move this value then reuse it
fwang 2017/02/24 10:08:51 You are right. As sky said, this won't work with m
fwang 2017/02/24 10:40:11 Done (added a comment to clarify).
83 GetSquareSizeForWindow(initialized_windows_count_)));
60 } 84 }
61 85
62 void MusDemoExternal::OnEmbed( 86 void MusDemoExternal::OnEmbed(
63 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) { 87 std::unique_ptr<aura::WindowTreeHostMus> window_tree_host) {
64 InitWindowTreeData(std::move(window_tree_host)); 88 InitWindowTreeData(std::move(window_tree_host));
89 initialized_windows_count_++;
90
91 // Open the next window until the requested number of windows is reached.
92 if (initialized_windows_count_ < kNumberOfWindows)
93 OpenNewWindow();
65 } 94 }
66 95
67 void MusDemoExternal::OnEmbedRootDestroyed( 96 void MusDemoExternal::OnEmbedRootDestroyed(
68 aura::WindowTreeHostMus* window_tree_host) { 97 aura::WindowTreeHostMus* window_tree_host) {
69 CleanupWindowTreeData(); 98 RemoveWindowTreeDataFor(window_tree_host);
70 } 99 }
71 100
72 } // namespace demo 101 } // namespace demo
73 } // namespace ui 102 } // namespace ui
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698