OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "ui/views/mus/window_manager_connection.h" | 5 #include "ui/views/mus/window_manager_connection.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/threading/thread_local.h" | 10 #include "base/threading/thread_local.h" |
11 #include "base/threading/thread_restrictions.h" | 11 #include "base/threading/thread_restrictions.h" |
12 #include "components/mus/public/cpp/window_tree_connection.h" | 12 #include "components/mus/public/cpp/window_tree_connection.h" |
13 #include "components/mus/public/interfaces/window_tree.mojom.h" | 13 #include "components/mus/public/interfaces/window_tree.mojom.h" |
14 #include "mojo/converters/geometry/geometry_type_converters.h" | 14 #include "mojo/converters/geometry/geometry_type_converters.h" |
15 #include "mojo/converters/network/network_type_converters.h" | 15 #include "mojo/converters/network/network_type_converters.h" |
16 #include "mojo/shell/public/cpp/application_connection.h" | 16 #include "mojo/shell/public/cpp/application_connection.h" |
17 #include "mojo/shell/public/cpp/application_impl.h" | 17 #include "mojo/shell/public/cpp/application_impl.h" |
18 #include "ui/views/mus/native_widget_mus.h" | 18 #include "ui/views/mus/native_widget_mus.h" |
19 #include "ui/views/mus/screen_mus.h" | 19 #include "ui/views/mus/screen_mus.h" |
20 #include "ui/views/mus/window_manager_frame_values.h" | |
21 #include "ui/views/views_delegate.h" | 20 #include "ui/views/views_delegate.h" |
22 | 21 |
23 namespace views { | 22 namespace views { |
24 namespace { | 23 namespace { |
25 | 24 |
26 using WindowManagerConnectionPtr = | 25 using WindowManagerConnectionPtr = |
27 base::ThreadLocalPointer<views::WindowManagerConnection>; | 26 base::ThreadLocalPointer<views::WindowManagerConnection>; |
28 | 27 |
29 // Env is thread local so that aura may be used on multiple threads. | 28 // Env is thread local so that aura may be used on multiple threads. |
30 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = | 29 base::LazyInstance<WindowManagerConnectionPtr>::Leaky lazy_tls_ptr = |
31 LAZY_INSTANCE_INITIALIZER; | 30 LAZY_INSTANCE_INITIALIZER; |
32 | 31 |
33 void GetWindowManagerFrameValues(mus::mojom::WindowManagerPtr* window_manager) { | |
34 // TODO(sky): maybe this should be associated with Display? | |
35 WindowManagerFrameValues frame_values; | |
36 (*window_manager) | |
37 ->GetConfig([&frame_values](mus::mojom::WindowManagerConfigPtr results) { | |
38 frame_values.normal_insets = | |
39 results->normal_client_area_insets.To<gfx::Insets>(); | |
40 frame_values.maximized_insets = | |
41 results->maximized_client_area_insets.To<gfx::Insets>(); | |
42 frame_values.max_title_bar_button_width = | |
43 results->max_title_bar_button_width; | |
44 }); | |
45 CHECK(window_manager->WaitForIncomingResponse()); | |
46 WindowManagerFrameValues::SetInstance(frame_values); | |
47 } | |
48 | |
49 } // namespace | 32 } // namespace |
50 | 33 |
51 // static | 34 // static |
52 void WindowManagerConnection::Create(mojo::ApplicationImpl* app) { | 35 void WindowManagerConnection::Create(mojo::ApplicationImpl* app) { |
53 DCHECK(!lazy_tls_ptr.Pointer()->Get()); | 36 DCHECK(!lazy_tls_ptr.Pointer()->Get()); |
54 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(app)); | 37 lazy_tls_ptr.Pointer()->Set(new WindowManagerConnection(app)); |
55 } | 38 } |
56 | 39 |
57 // static | 40 // static |
58 WindowManagerConnection* WindowManagerConnection::Get() { | 41 WindowManagerConnection* WindowManagerConnection::Get() { |
(...skipping 20 matching lines...) Expand all Loading... |
79 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); | 62 mus::WindowTreeConnection::CreateType::WAIT_FOR_EMBED)); |
80 window_tree_connection_->SetDeleteOnNoRoots(false); | 63 window_tree_connection_->SetDeleteOnNoRoots(false); |
81 DCHECK_EQ(1u, window_tree_connection_->GetRoots().size()); | 64 DCHECK_EQ(1u, window_tree_connection_->GetRoots().size()); |
82 return *window_tree_connection_->GetRoots().begin(); | 65 return *window_tree_connection_->GetRoots().begin(); |
83 } | 66 } |
84 | 67 |
85 WindowManagerConnection::WindowManagerConnection(mojo::ApplicationImpl* app) | 68 WindowManagerConnection::WindowManagerConnection(mojo::ApplicationImpl* app) |
86 : app_(app), window_tree_connection_(nullptr) { | 69 : app_(app), window_tree_connection_(nullptr) { |
87 app->ConnectToService("mojo:mus", &window_manager_); | 70 app->ConnectToService("mojo:mus", &window_manager_); |
88 | 71 |
89 GetWindowManagerFrameValues(&window_manager_); | 72 screen_.reset(new ScreenMus(this)); |
90 | |
91 screen_.reset(new ScreenMus); | |
92 screen_->Init(app); | 73 screen_->Init(app); |
93 ViewsDelegate::GetInstance()->set_native_widget_factory( | 74 ViewsDelegate::GetInstance()->set_native_widget_factory( |
94 base::Bind(&WindowManagerConnection::CreateNativeWidget, | 75 base::Bind(&WindowManagerConnection::CreateNativeWidget, |
95 base::Unretained(this))); | 76 base::Unretained(this))); |
96 } | 77 } |
97 | 78 |
98 WindowManagerConnection::~WindowManagerConnection() { | 79 WindowManagerConnection::~WindowManagerConnection() { |
99 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), | 80 // ~WindowTreeConnection calls back to us (we're the WindowTreeDelegate), |
100 // destroy it while we are still valid. | 81 // destroy it while we are still valid. |
101 window_tree_connection_.reset(); | 82 window_tree_connection_.reset(); |
102 } | 83 } |
103 | 84 |
104 void WindowManagerConnection::OnEmbed(mus::Window* root) {} | 85 void WindowManagerConnection::OnEmbed(mus::Window* root) {} |
105 | 86 |
106 void WindowManagerConnection::OnConnectionLost( | 87 void WindowManagerConnection::OnConnectionLost( |
107 mus::WindowTreeConnection* connection) {} | 88 mus::WindowTreeConnection* connection) {} |
108 | 89 |
| 90 void WindowManagerConnection::OnWindowManagerFrameValuesChanged() { |
| 91 if (window_tree_connection_) |
| 92 NativeWidgetMus::NotifyFrameChanged(window_tree_connection_.get()); |
| 93 } |
| 94 |
109 NativeWidget* WindowManagerConnection::CreateNativeWidget( | 95 NativeWidget* WindowManagerConnection::CreateNativeWidget( |
110 const Widget::InitParams& init_params, | 96 const Widget::InitParams& init_params, |
111 internal::NativeWidgetDelegate* delegate) { | 97 internal::NativeWidgetDelegate* delegate) { |
112 std::map<std::string, std::vector<uint8_t>> properties; | 98 std::map<std::string, std::vector<uint8_t>> properties; |
113 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); | 99 NativeWidgetMus::ConfigurePropertiesForNewWindow(init_params, &properties); |
114 return new NativeWidgetMus(delegate, app_->shell(), NewWindow(properties), | 100 return new NativeWidgetMus(delegate, app_->shell(), NewWindow(properties), |
115 mus::mojom::SurfaceType::DEFAULT); | 101 mus::mojom::SurfaceType::DEFAULT); |
116 } | 102 } |
117 | 103 |
118 } // namespace views | 104 } // namespace views |
OLD | NEW |