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/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" | |
| 13 #include "ui/aura/env.h" | 15 #include "ui/aura/env.h" |
| 14 #include "ui/aura/mus/mus_context_factory.h" | 16 #include "ui/aura/mus/mus_context_factory.h" |
| 15 #include "ui/aura/mus/os_exchange_data_provider_mus.h" | 17 #include "ui/aura/mus/os_exchange_data_provider_mus.h" |
| 16 #include "ui/aura/mus/property_converter.h" | 18 #include "ui/aura/mus/property_converter.h" |
| 17 #include "ui/aura/mus/window_tree_client.h" | 19 #include "ui/aura/mus/window_tree_client.h" |
| 18 #include "ui/aura/mus/window_tree_host_mus.h" | 20 #include "ui/aura/mus/window_tree_host_mus.h" |
| 19 #include "ui/aura/window.h" | 21 #include "ui/aura/window.h" |
| 20 #include "ui/aura/window_tree_host.h" | 22 #include "ui/aura/window_tree_host.h" |
| 21 #include "ui/views/mus/aura_init.h" | 23 #include "ui/views/mus/aura_init.h" |
| 22 #include "ui/views/mus/clipboard_mus.h" | 24 #include "ui/views/mus/clipboard_mus.h" |
| 23 #include "ui/views/mus/desktop_window_tree_host_mus.h" | 25 #include "ui/views/mus/desktop_window_tree_host_mus.h" |
| 24 #include "ui/views/mus/screen_mus.h" | 26 #include "ui/views/mus/screen_mus.h" |
| 25 #include "ui/views/views_delegate.h" | 27 #include "ui/views/views_delegate.h" |
| 26 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" | 28 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h" |
| 27 #include "ui/wm/core/capture_controller.h" | 29 #include "ui/wm/core/capture_controller.h" |
| 28 #include "ui/wm/core/wm_state.h" | 30 #include "ui/wm/core/wm_state.h" |
| 29 | 31 |
| 32 // Widget::InitParams::Type must match that of ui::mojom::WindowType. | |
| 33 #define WINDOW_TYPES_MATCH(NAME) \ | |
| 34 static_assert( \ | |
| 35 static_cast<int32_t>(views::Widget::InitParams::TYPE_##NAME) == \ | |
| 36 static_cast<int32_t>(ui::mojom::WindowType::NAME), \ | |
| 37 "Window type constants must match") | |
| 38 | |
| 39 WINDOW_TYPES_MATCH(WINDOW); | |
| 40 WINDOW_TYPES_MATCH(PANEL); | |
| 41 WINDOW_TYPES_MATCH(WINDOW_FRAMELESS); | |
| 42 WINDOW_TYPES_MATCH(CONTROL); | |
| 43 WINDOW_TYPES_MATCH(POPUP); | |
| 44 WINDOW_TYPES_MATCH(MENU); | |
| 45 WINDOW_TYPES_MATCH(TOOLTIP); | |
| 46 WINDOW_TYPES_MATCH(BUBBLE); | |
| 47 WINDOW_TYPES_MATCH(DRAG); | |
|
msw
2016/11/21 22:40:45
nit: add UNKNOWN too
sky
2016/11/21 22:42:09
I can't. Widget::InitParams::Type doesn't have UNK
| |
| 48 | |
| 30 namespace views { | 49 namespace views { |
| 31 | 50 |
| 32 // static | 51 // static |
| 33 MusClient* MusClient::instance_ = nullptr; | 52 MusClient* MusClient::instance_ = nullptr; |
| 34 | 53 |
| 35 MusClient::~MusClient() { | 54 MusClient::~MusClient() { |
| 36 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while | 55 // ~WindowTreeClient calls back to us (we're its delegate), destroy it while |
| 37 // we are still valid. | 56 // we are still valid. |
| 38 window_tree_client_.reset(); | 57 window_tree_client_.reset(); |
| 39 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); | 58 ui::OSExchangeDataProviderFactory::SetFactory(nullptr); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 50 } | 69 } |
| 51 | 70 |
| 52 // static | 71 // static |
| 53 bool MusClient::ShouldCreateDesktopNativeWidgetAura( | 72 bool MusClient::ShouldCreateDesktopNativeWidgetAura( |
| 54 const Widget::InitParams& init_params) { | 73 const Widget::InitParams& init_params) { |
| 55 // TYPE_CONTROL and child widgets require a NativeWidgetAura. | 74 // TYPE_CONTROL and child widgets require a NativeWidgetAura. |
| 56 return init_params.type != Widget::InitParams::TYPE_CONTROL && | 75 return init_params.type != Widget::InitParams::TYPE_CONTROL && |
| 57 !init_params.child; | 76 !init_params.child; |
| 58 } | 77 } |
| 59 | 78 |
| 79 // static | |
| 80 std::map<std::string, std::vector<uint8_t>> | |
| 81 MusClient::ConfigurePropertiesFromParams( | |
| 82 const Widget::InitParams& init_params) { | |
| 83 std::map<std::string, std::vector<uint8_t>> mus_properties = | |
| 84 init_params.mus_properties; | |
| 85 // Widget::InitParams::Type matches ui::mojom::WindowType. | |
| 86 mus_properties[ui::mojom::WindowManager::kWindowType_Property] = | |
| 87 mojo::ConvertTo<std::vector<uint8_t>>( | |
| 88 static_cast<int32_t>(init_params.type)); | |
| 89 return mus_properties; | |
| 90 } | |
| 91 | |
| 60 NativeWidget* MusClient::CreateNativeWidget( | 92 NativeWidget* MusClient::CreateNativeWidget( |
| 61 const Widget::InitParams& init_params, | 93 const Widget::InitParams& init_params, |
| 62 internal::NativeWidgetDelegate* delegate) { | 94 internal::NativeWidgetDelegate* delegate) { |
| 63 if (!ShouldCreateDesktopNativeWidgetAura(init_params)) { | 95 if (!ShouldCreateDesktopNativeWidgetAura(init_params)) { |
| 64 // A null return value results in creating NativeWidgetAura. | 96 // A null return value results in creating NativeWidgetAura. |
| 65 return nullptr; | 97 return nullptr; |
| 66 } | 98 } |
| 67 | 99 |
| 68 DesktopNativeWidgetAura* native_widget = | 100 DesktopNativeWidgetAura* native_widget = |
| 69 new DesktopNativeWidgetAura(delegate); | 101 new DesktopNativeWidgetAura(delegate); |
| 70 if (init_params.desktop_window_tree_host) { | 102 if (init_params.desktop_window_tree_host) { |
| 71 native_widget->SetDesktopWindowTreeHost( | 103 native_widget->SetDesktopWindowTreeHost( |
| 72 base::WrapUnique(init_params.desktop_window_tree_host)); | 104 base::WrapUnique(init_params.desktop_window_tree_host)); |
| 73 } else { | 105 } else { |
| 106 std::map<std::string, std::vector<uint8_t>> mus_properties = | |
| 107 ConfigurePropertiesFromParams(init_params); | |
| 74 native_widget->SetDesktopWindowTreeHost( | 108 native_widget->SetDesktopWindowTreeHost( |
| 75 base::MakeUnique<DesktopWindowTreeHostMus>(delegate, native_widget, | 109 base::MakeUnique<DesktopWindowTreeHostMus>(delegate, native_widget, |
| 76 init_params)); | 110 &mus_properties)); |
| 77 } | 111 } |
| 78 return native_widget; | 112 return native_widget; |
| 79 } | 113 } |
| 80 | 114 |
| 81 MusClient::MusClient(service_manager::Connector* connector, | 115 MusClient::MusClient(service_manager::Connector* connector, |
| 82 const service_manager::Identity& identity, | 116 const service_manager::Identity& identity, |
| 83 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) | 117 scoped_refptr<base::SingleThreadTaskRunner> io_task_runner) |
| 84 : connector_(connector), identity_(identity) { | 118 : connector_(connector), identity_(identity) { |
| 85 DCHECK(!instance_); | 119 DCHECK(!instance_); |
| 86 instance_ = this; | 120 instance_ = this; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 162 return root->GetTopWindowContainingPoint(relative_point); | 196 return root->GetTopWindowContainingPoint(relative_point); |
| 163 } | 197 } |
| 164 return nullptr; | 198 return nullptr; |
| 165 } | 199 } |
| 166 | 200 |
| 167 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { | 201 std::unique_ptr<OSExchangeData::Provider> MusClient::BuildProvider() { |
| 168 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); | 202 return base::MakeUnique<aura::OSExchangeDataProviderMus>(); |
| 169 } | 203 } |
| 170 | 204 |
| 171 } // namespace views | 205 } // namespace views |
| OLD | NEW |