Chromium Code Reviews| 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 "ui/views/mus/mus_client.h" | 5 #include "ui/views/mus/mus_client.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "services/service_manager/public/cpp/connection.h" | 9 #include "services/service_manager/public/cpp/connection.h" |
| 10 #include "services/service_manager/public/cpp/connector.h" | 10 #include "services/service_manager/public/cpp/connector.h" |
| 11 #include "services/ui/public/cpp/gpu/gpu_service.h" | 11 #include "services/ui/public/cpp/gpu/gpu_service.h" |
| 12 #include "services/ui/public/cpp/property_type_converters.h" | 12 #include "services/ui/public/cpp/property_type_converters.h" |
| 13 #include "services/ui/public/interfaces/event_matcher.mojom.h" | 13 #include "services/ui/public/interfaces/event_matcher.mojom.h" |
| 14 #include "services/ui/public/interfaces/window_manager.mojom.h" | 14 #include "services/ui/public/interfaces/window_manager.mojom.h" |
| 15 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 16 #include "ui/aura/mus/mus_context_factory.h" | 16 #include "ui/aura/mus/mus_context_factory.h" |
| 17 #include "ui/aura/mus/os_exchange_data_provider_mus.h" | 17 #include "ui/aura/mus/os_exchange_data_provider_mus.h" |
| 18 #include "ui/aura/mus/property_converter.h" | 18 #include "ui/aura/mus/property_converter.h" |
| 19 #include "ui/aura/mus/window_tree_client.h" | 19 #include "ui/aura/mus/window_tree_client.h" |
| 20 #include "ui/aura/mus/window_tree_host_mus.h" | 20 #include "ui/aura/mus/window_tree_host_mus.h" |
| 21 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 22 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 23 #include "ui/views/mus/aura_init.h" | 23 #include "ui/views/mus/aura_init.h" |
| 24 #include "ui/views/mus/clipboard_mus.h" | 24 #include "ui/views/mus/clipboard_mus.h" |
| 25 #include "ui/views/mus/desktop_window_tree_host_mus.h" | 25 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 26 #include "ui/views/mus/pointer_watcher_event_router2.h" | 26 #include "ui/views/mus/pointer_watcher_event_router2.h" |
| 27 #include "ui/views/mus/screen_mus.h" | 27 #include "ui/views/mus/screen_mus.h" |
| 28 #include "ui/views/views_delegate.h" | 28 #include "ui/views/views_delegate.h" |
| 29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 29 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 30 #include "ui/views/widget/widget_delegate.h" | |
| 30 #include "ui/wm/core/capture_controller.h" | 31 #include "ui/wm/core/capture_controller.h" |
| 31 #include "ui/wm/core/wm_state.h" | 32 #include "ui/wm/core/wm_state.h" |
| 32 | 33 |
| 33 // Widget::InitParams::Type must match that of ui::mojom::WindowType. | 34 // Widget::InitParams::Type must match that of ui::mojom::WindowType. |
| 34 #define WINDOW_TYPES_MATCH(NAME) \ | 35 #define WINDOW_TYPES_MATCH(NAME) \ |
| 35 static_assert( \ | 36 static_assert( \ |
| 36 static_cast<int32_t>(views::Widget::InitParams::TYPE_##NAME) == \ | 37 static_cast<int32_t>(views::Widget::InitParams::TYPE_##NAME) == \ |
| 37 static_cast<int32_t>(ui::mojom::WindowType::NAME), \ | 38 static_cast<int32_t>(ui::mojom::WindowType::NAME), \ |
| 38 "Window type constants must match") | 39 "Window type constants must match") |
| 39 | 40 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 72 } | 73 } |
| 73 | 74 |
| 74 // static | 75 // static |
| 75 bool MusClient::ShouldCreateDesktopNativeWidgetAura( | 76 bool MusClient::ShouldCreateDesktopNativeWidgetAura( |
| 76 const Widget::InitParams& init_params) { | 77 const Widget::InitParams& init_params) { |
| 77 // TYPE_CONTROL and child widgets require a NativeWidgetAura. | 78 // TYPE_CONTROL and child widgets require a NativeWidgetAura. |
| 78 return init_params.type != Widget::InitParams::TYPE_CONTROL && | 79 return init_params.type != Widget::InitParams::TYPE_CONTROL && |
| 79 !init_params.child; | 80 !init_params.child; |
| 80 } | 81 } |
| 81 | 82 |
| 82 // static | |
|
msw
2016/11/29 01:15:45
Why can't/shouldn't this be static anymore?
sky
2016/11/29 04:19:36
Good point. Done.
| |
| 83 std::map<std::string, std::vector<uint8_t>> | 83 std::map<std::string, std::vector<uint8_t>> |
| 84 MusClient::ConfigurePropertiesFromParams( | 84 MusClient::ConfigurePropertiesFromParams( |
| 85 const Widget::InitParams& init_params) { | 85 const Widget::InitParams& init_params) { |
| 86 std::map<std::string, std::vector<uint8_t>> mus_properties = | 86 using PrimitiveType = aura::PropertyConverter::PrimitiveType; |
| 87 std::map<std::string, std::vector<uint8_t>> properties = | |
| 87 init_params.mus_properties; | 88 init_params.mus_properties; |
| 89 | |
| 88 // Widget::InitParams::Type matches ui::mojom::WindowType. | 90 // Widget::InitParams::Type matches ui::mojom::WindowType. |
| 89 mus_properties[ui::mojom::WindowManager::kWindowType_Property] = | 91 properties[ui::mojom::WindowManager::kWindowType_Property] = |
| 90 mojo::ConvertTo<std::vector<uint8_t>>( | 92 mojo::ConvertTo<std::vector<uint8_t>>( |
| 91 static_cast<int32_t>(init_params.type)); | 93 static_cast<int32_t>(init_params.type)); |
| 92 return mus_properties; | 94 |
| 95 if (!init_params.bounds.IsEmpty()) { | |
| 96 properties[ui::mojom::WindowManager::kInitialBounds_Property] = | |
| 97 mojo::ConvertTo<std::vector<uint8_t>>(init_params.bounds); | |
| 98 } | |
| 99 | |
| 100 if (!init_params.name.empty()) { | |
| 101 properties[ui::mojom::WindowManager::kName_Property] = | |
| 102 mojo::ConvertTo<std::vector<uint8_t>>(init_params.name); | |
| 103 } | |
| 104 | |
| 105 properties[ui::mojom::WindowManager::kAlwaysOnTop_Property] = | |
| 106 mojo::ConvertTo<std::vector<uint8_t>>( | |
| 107 static_cast<PrimitiveType>(init_params.keep_on_top)); | |
| 108 | |
| 109 if (!Widget::RequiresNonClientView(init_params.type)) | |
| 110 return properties; | |
| 111 | |
| 112 if (init_params.delegate) { | |
| 113 if (properties.count(ui::mojom::WindowManager::kResizeBehavior_Property) == | |
| 114 0) { | |
| 115 properties[ui::mojom::WindowManager::kResizeBehavior_Property] = | |
| 116 mojo::ConvertTo<std::vector<uint8_t>>(static_cast<PrimitiveType>( | |
| 117 DesktopWindowTreeHostMus::GetResizeBehaviorFromDelegate( | |
| 118 init_params.delegate))); | |
| 119 } | |
| 120 | |
| 121 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. | |
| 122 gfx::ImageSkia app_icon = init_params.delegate->GetWindowAppIcon(); | |
| 123 SkBitmap app_bitmap = app_icon.GetRepresentation(1.f).sk_bitmap(); | |
| 124 if (!app_bitmap.isNull()) { | |
| 125 properties[ui::mojom::WindowManager::kAppIcon_Property] = | |
| 126 mojo::ConvertTo<std::vector<uint8_t>>(app_bitmap); | |
| 127 } | |
| 128 // TODO(crbug.com/667566): Support additional scales or gfx::Image[Skia]. | |
| 129 gfx::ImageSkia window_icon = init_params.delegate->GetWindowIcon(); | |
| 130 SkBitmap window_bitmap = window_icon.GetRepresentation(1.f).sk_bitmap(); | |
| 131 if (!window_bitmap.isNull()) { | |
| 132 properties[ui::mojom::WindowManager::kWindowIcon_Property] = | |
| 133 mojo::ConvertTo<std::vector<uint8_t>>(window_bitmap); | |
| 134 } | |
| 135 } | |
| 136 | |
| 137 return properties; | |
| 93 } | 138 } |
| 94 | 139 |
| 95 NativeWidget* MusClient::CreateNativeWidget( | 140 NativeWidget* MusClient::CreateNativeWidget( |
| 96 const Widget::InitParams& init_params, | 141 const Widget::InitParams& init_params, |
| 97 internal::NativeWidgetDelegate* delegate) { | 142 internal::NativeWidgetDelegate* delegate) { |
| 98 if (!ShouldCreateDesktopNativeWidgetAura(init_params)) { | 143 if (!ShouldCreateDesktopNativeWidgetAura(init_params)) { |
| 99 // A null return value results in creating NativeWidgetAura. | 144 // A null return value results in creating NativeWidgetAura. |
| 100 return nullptr; | 145 return nullptr; |
| 101 } | 146 } |
| 102 | 147 |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 207 return root->GetTopWindowContainingPoint(relative_point); | 252 return root->GetTopWindowContainingPoint(relative_point); |
| 208 } | 253 } |
| 209 return nullptr; | 254 return nullptr; |
| 210 } | 255 } |
| 211 | 256 |
| 212 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { | 257 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { |
| 213 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); | 258 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); |
| 214 } | 259 } |
| 215 | 260 |
| 216 } // namespace views | 261 } // namespace views |
| OLD | NEW |