| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "components/mus/public/cpp/window.h" | 5 #include "components/mus/public/cpp/window.h" |
| 6 #include "components/mus/public/cpp/window_manager_delegate.h" | 6 #include "components/mus/public/cpp/window_manager_delegate.h" |
| 7 #include "components/mus/public/cpp/window_tree_client.h" | 7 #include "components/mus/public/cpp/window_tree_client.h" |
| 8 #include "components/mus/public/cpp/window_tree_client_delegate.h" | 8 #include "components/mus/public/cpp/window_tree_client_delegate.h" |
| 9 #include "components/mus/public/interfaces/window_manager_factory.mojom.h" | |
| 10 #include "mojo/public/c/system/main.h" | 9 #include "mojo/public/c/system/main.h" |
| 11 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
| 12 #include "services/shell/public/cpp/application_runner.h" | 11 #include "services/shell/public/cpp/application_runner.h" |
| 13 #include "services/shell/public/cpp/connector.h" | 12 #include "services/shell/public/cpp/connector.h" |
| 14 #include "services/shell/public/cpp/shell_client.h" | 13 #include "services/shell/public/cpp/shell_client.h" |
| 15 #include "ui/display/display.h" | 14 #include "ui/display/display.h" |
| 16 #include "ui/display/mojo/display_type_converters.h" | 15 #include "ui/display/mojo/display_type_converters.h" |
| 17 | 16 |
| 18 namespace mus { | 17 namespace mus { |
| 19 namespace test { | 18 namespace test { |
| 20 | 19 |
| 21 class TestWM : public shell::ShellClient, | 20 class TestWM : public shell::ShellClient, |
| 22 public mus::mojom::WindowManagerFactory, | |
| 23 public mus::WindowTreeClientDelegate, | 21 public mus::WindowTreeClientDelegate, |
| 24 public mus::WindowManagerDelegate { | 22 public mus::WindowManagerDelegate { |
| 25 public: | 23 public: |
| 26 TestWM() : window_manager_factory_binding_(this) {} | 24 TestWM() {} |
| 27 ~TestWM() override {} | 25 ~TestWM() override { delete window_tree_client_; } |
| 28 | 26 |
| 29 private: | 27 private: |
| 30 // shell::ShellClient: | 28 // shell::ShellClient: |
| 31 void Initialize(shell::Connector* connector, | 29 void Initialize(shell::Connector* connector, |
| 32 const shell::Identity& identity, | 30 const shell::Identity& identity, |
| 33 uint32_t id) override { | 31 uint32_t id) override { |
| 34 mus::mojom::WindowManagerFactoryServicePtr wm_factory_service; | 32 window_tree_client_ = new mus::WindowTreeClient(this, this, nullptr); |
| 35 connector->ConnectToInterface("mojo:mus", &wm_factory_service); | 33 window_tree_client_->ConnectAsWindowManager(connector); |
| 36 wm_factory_service->SetWindowManagerFactory( | |
| 37 window_manager_factory_binding_.CreateInterfacePtrAndBind()); | |
| 38 } | 34 } |
| 39 bool AcceptConnection(shell::Connection* connection) override { | 35 bool AcceptConnection(shell::Connection* connection) override { |
| 40 return true; | 36 return true; |
| 41 } | 37 } |
| 42 | 38 |
| 43 // mus::mojom::WindowManagerFactory: | |
| 44 void CreateWindowManager( | |
| 45 mus::mojom::DisplayPtr display, | |
| 46 mus::mojom::WindowTreeClientRequest request) override { | |
| 47 new mus::WindowTreeClient(this, this, std::move(request)); | |
| 48 } | |
| 49 | |
| 50 // mus::WindowTreeClientDelegate: | 39 // mus::WindowTreeClientDelegate: |
| 51 void OnEmbed(mus::Window* root) override { | 40 void OnEmbed(mus::Window* root) override { |
| 52 root_ = root; | 41 // WindowTreeClients configured as the window manager should never get |
| 53 window_manager_client_->AddActivationParent(root_); | 42 // OnEmbed(). |
| 54 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = | 43 NOTREACHED(); |
| 55 mus::mojom::FrameDecorationValues::New(); | |
| 56 frame_decoration_values->max_title_bar_button_width = 0; | |
| 57 window_manager_client_->SetFrameDecorationValues( | |
| 58 std::move(frame_decoration_values)); | |
| 59 } | 44 } |
| 60 void OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) override {} | 45 void OnWindowTreeClientDestroyed(mus::WindowTreeClient* client) override { |
| 46 window_tree_client_ = nullptr; |
| 47 } |
| 61 void OnEventObserved(const ui::Event& event, mus::Window* target) override { | 48 void OnEventObserved(const ui::Event& event, mus::Window* target) override { |
| 62 // Don't care. | 49 // Don't care. |
| 63 } | 50 } |
| 64 | 51 |
| 65 // mus::WindowManagerDelegate: | 52 // mus::WindowManagerDelegate: |
| 66 void SetWindowManagerClient(mus::WindowManagerClient* client) override { | 53 void SetWindowManagerClient(mus::WindowManagerClient* client) override { |
| 67 window_manager_client_ = client; | 54 window_manager_client_ = client; |
| 68 } | 55 } |
| 69 bool OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) override { | 56 bool OnWmSetBounds(mus::Window* window, gfx::Rect* bounds) override { |
| 70 return true; | 57 return true; |
| 71 } | 58 } |
| 72 bool OnWmSetProperty( | 59 bool OnWmSetProperty( |
| 73 mus::Window* window, | 60 mus::Window* window, |
| 74 const std::string& name, | 61 const std::string& name, |
| 75 std::unique_ptr<std::vector<uint8_t>>* new_data) override { | 62 std::unique_ptr<std::vector<uint8_t>>* new_data) override { |
| 76 return true; | 63 return true; |
| 77 } | 64 } |
| 78 mus::Window* OnWmCreateTopLevelWindow( | 65 mus::Window* OnWmCreateTopLevelWindow( |
| 79 std::map<std::string, std::vector<uint8_t>>* properties) override { | 66 std::map<std::string, std::vector<uint8_t>>* properties) override { |
| 80 mus::Window* window = root_->window_tree()->NewWindow(properties); | 67 mus::Window* window = root_->window_tree()->NewWindow(properties); |
| 81 window->SetBounds(gfx::Rect(10, 10, 500, 500)); | 68 window->SetBounds(gfx::Rect(10, 10, 500, 500)); |
| 82 root_->AddChild(window); | 69 root_->AddChild(window); |
| 83 return window; | 70 return window; |
| 84 } | 71 } |
| 85 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, | 72 void OnWmClientJankinessChanged(const std::set<Window*>& client_windows, |
| 86 bool janky) override { | 73 bool janky) override { |
| 87 // Don't care. | 74 // Don't care. |
| 88 } | 75 } |
| 76 void OnWmNewDisplay(Window* window, |
| 77 const display::Display& display) override { |
| 78 // Only handles a single root. |
| 79 DCHECK(!root_); |
| 80 root_ = window; |
| 81 DCHECK(window_manager_client_); |
| 82 window_manager_client_->AddActivationParent(root_); |
| 83 mus::mojom::FrameDecorationValuesPtr frame_decoration_values = |
| 84 mus::mojom::FrameDecorationValues::New(); |
| 85 frame_decoration_values->max_title_bar_button_width = 0; |
| 86 window_manager_client_->SetFrameDecorationValues( |
| 87 std::move(frame_decoration_values)); |
| 88 } |
| 89 void OnAccelerator(uint32_t id, const ui::Event& event) override { | 89 void OnAccelerator(uint32_t id, const ui::Event& event) override { |
| 90 // Don't care. | 90 // Don't care. |
| 91 } | 91 } |
| 92 | 92 |
| 93 mojo::Binding<mus::mojom::WindowManagerFactory> | |
| 94 window_manager_factory_binding_; | |
| 95 mus::Window* root_ = nullptr; | 93 mus::Window* root_ = nullptr; |
| 96 mus::WindowManagerClient* window_manager_client_ = nullptr; | 94 mus::WindowManagerClient* window_manager_client_ = nullptr; |
| 95 // See WindowTreeClient for details on ownership. |
| 96 mus::WindowTreeClient* window_tree_client_ = nullptr; |
| 97 | 97 |
| 98 DISALLOW_COPY_AND_ASSIGN(TestWM); | 98 DISALLOW_COPY_AND_ASSIGN(TestWM); |
| 99 }; | 99 }; |
| 100 | 100 |
| 101 } // namespace test | 101 } // namespace test |
| 102 } // namespace mus | 102 } // namespace mus |
| 103 | 103 |
| 104 MojoResult MojoMain(MojoHandle shell_handle) { | 104 MojoResult MojoMain(MojoHandle shell_handle) { |
| 105 shell::ApplicationRunner runner(new mus::test::TestWM); | 105 shell::ApplicationRunner runner(new mus::test::TestWM); |
| 106 return runner.Run(shell_handle); | 106 return runner.Run(shell_handle); |
| 107 } | 107 } |
| OLD | NEW |