| 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/aura/mus/window_tree_host_mus.h" | 5 #include "ui/aura/mus/window_tree_host_mus.h" |
| 6 | 6 |
| 7 #include "base/memory/ptr_util.h" | 7 #include "base/memory/ptr_util.h" |
| 8 #include "ui/aura/env.h" | 8 #include "ui/aura/env.h" |
| 9 #include "ui/aura/mus/input_method_mus.h" | 9 #include "ui/aura/mus/input_method_mus.h" |
| 10 #include "ui/aura/mus/window_port_mus.h" | 10 #include "ui/aura/mus/window_port_mus.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_delegate.h" | 12 #include "ui/aura/mus/window_tree_host_mus_delegate.h" |
| 13 #include "ui/aura/mus/window_tree_host_mus_init_params.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/base/class_property.h" | 16 #include "ui/base/class_property.h" |
| 16 #include "ui/display/display.h" | 17 #include "ui/display/display.h" |
| 17 #include "ui/display/screen.h" | 18 #include "ui/display/screen.h" |
| 18 #include "ui/events/event.h" | 19 #include "ui/events/event.h" |
| 19 #include "ui/platform_window/stub/stub_window.h" | 20 #include "ui/platform_window/stub/stub_window.h" |
| 20 | 21 |
| 21 DECLARE_UI_CLASS_PROPERTY_TYPE(aura::WindowTreeHostMus*); | 22 DECLARE_UI_CLASS_PROPERTY_TYPE(aura::WindowTreeHostMus*); |
| 22 | 23 |
| 23 namespace aura { | 24 namespace aura { |
| 24 | 25 |
| 25 namespace { | 26 namespace { |
| 26 | 27 |
| 27 DEFINE_UI_CLASS_PROPERTY_KEY( | 28 DEFINE_UI_CLASS_PROPERTY_KEY( |
| 28 WindowTreeHostMus*, kWindowTreeHostMusKey, nullptr); | 29 WindowTreeHostMus*, kWindowTreeHostMusKey, nullptr); |
| 29 | 30 |
| 30 static uint32_t accelerated_widget_count = 1; | 31 static uint32_t accelerated_widget_count = 1; |
| 31 | 32 |
| 32 bool IsUsingTestContext() { | 33 bool IsUsingTestContext() { |
| 33 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); | 34 return aura::Env::GetInstance()->context_factory()->DoesCreateTestContexts(); |
| 34 } | 35 } |
| 35 | 36 |
| 36 } // namespace | 37 } // namespace |
| 37 | 38 |
| 38 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
| 39 // WindowTreeHostMus, public: | 40 // WindowTreeHostMus, public: |
| 40 | 41 |
| 41 WindowTreeHostMus::WindowTreeHostMus( | 42 WindowTreeHostMus::WindowTreeHostMus( |
| 42 std::unique_ptr<WindowPortMus> window_port, | 43 std::unique_ptr<WindowTreeHostMusInitParams> init_params) |
| 43 WindowTreeClient* window_tree_client, | 44 : WindowTreeHostPlatform(std::move(init_params->window_port)), |
| 44 int64_t display_id, | 45 display_id_(init_params->display_id), |
| 45 const cc::FrameSinkId& frame_sink_id, | 46 delegate_(init_params->window_tree_client) { |
| 46 const std::map<std::string, std::vector<uint8_t>>* properties) | |
| 47 : WindowTreeHostPlatform(std::move(window_port)), | |
| 48 display_id_(display_id), | |
| 49 delegate_(window_tree_client) { | |
| 50 window()->SetProperty(kWindowTreeHostMusKey, this); | 47 window()->SetProperty(kWindowTreeHostMusKey, this); |
| 51 // TODO(sky): find a cleaner way to set this! Better solution is to likely | 48 // TODO(sky): find a cleaner way to set this! Better solution is to likely |
| 52 // have constructor take aura::Window. | 49 // have constructor take aura::Window. |
| 53 WindowPortMus* window_mus = WindowPortMus::Get(window()); | 50 WindowPortMus* window_mus = WindowPortMus::Get(window()); |
| 54 window_mus->window_ = window(); | 51 window_mus->window_ = window(); |
| 55 if (properties) { | 52 // Apply the properties before initializing the window, that way the server |
| 56 // Apply the properties before initializing the window, that way the | 53 // seems them at the time the window is created. |
| 57 // server seems them at the time the window is created. | 54 for (auto& pair : init_params->properties) |
| 58 for (auto& pair : *properties) | 55 window_mus->SetPropertyFromServer(pair.first, &pair.second); |
| 59 window_mus->SetPropertyFromServer(pair.first, &pair.second); | |
| 60 } | |
| 61 // TODO(fsamuel): Once the display compositor is decoupled from the browser | 56 // TODO(fsamuel): Once the display compositor is decoupled from the browser |
| 62 // process then ui::Compositor will not a cc::FrameSinkId. | 57 // process then ui::Compositor will not a cc::FrameSinkId. |
| 63 CreateCompositor(frame_sink_id); | 58 CreateCompositor(init_params->frame_sink_id); |
| 64 gfx::AcceleratedWidget accelerated_widget; | 59 gfx::AcceleratedWidget accelerated_widget; |
| 65 if (IsUsingTestContext()) { | 60 if (IsUsingTestContext()) { |
| 66 accelerated_widget = gfx::kNullAcceleratedWidget; | 61 accelerated_widget = gfx::kNullAcceleratedWidget; |
| 67 } else { | 62 } else { |
| 68 // We need accelerated widget numbers to be different for each | 63 // We need accelerated widget numbers to be different for each |
| 69 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t | 64 // window and fit in the smallest sizeof(AcceleratedWidget) uint32_t |
| 70 // has this property. | 65 // has this property. |
| 71 #if defined(OS_WIN) || defined(OS_ANDROID) | 66 #if defined(OS_WIN) || defined(OS_ANDROID) |
| 72 accelerated_widget = | 67 accelerated_widget = |
| 73 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 68 reinterpret_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 74 #else | 69 #else |
| 75 accelerated_widget = | 70 accelerated_widget = |
| 76 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); | 71 static_cast<gfx::AcceleratedWidget>(accelerated_widget_count++); |
| 77 #endif | 72 #endif |
| 78 } | 73 } |
| 79 OnAcceleratedWidgetAvailable(accelerated_widget, | 74 OnAcceleratedWidgetAvailable(accelerated_widget, |
| 80 GetDisplay().device_scale_factor()); | 75 GetDisplay().device_scale_factor()); |
| 81 | 76 |
| 82 delegate_->OnWindowTreeHostCreated(this); | 77 delegate_->OnWindowTreeHostCreated(this); |
| 83 | 78 |
| 84 SetPlatformWindow(base::MakeUnique<ui::StubWindow>( | 79 // Do not advertise accelerated widget; already set manually. |
| 85 this, | 80 const bool use_default_accelerated_widget = false; |
| 86 false)); // Do not advertise accelerated widget; already set manually. | 81 SetPlatformWindow( |
| 82 base::MakeUnique<ui::StubWindow>(this, use_default_accelerated_widget)); |
| 87 | 83 |
| 88 input_method_ = base::MakeUnique<InputMethodMus>(this, window()); | 84 input_method_ = base::MakeUnique<InputMethodMus>(this, window()); |
| 89 input_method_->Init(window_tree_client->connector()); | 85 input_method_->Init(init_params->window_tree_client->connector()); |
| 90 SetSharedInputMethod(input_method_.get()); | 86 SetSharedInputMethod(input_method_.get()); |
| 91 | 87 |
| 92 compositor()->SetHostHasTransparentBackground(true); | 88 compositor()->SetHostHasTransparentBackground(true); |
| 93 | 89 |
| 94 // Mus windows are assumed hidden. | 90 // Mus windows are assumed hidden. |
| 95 compositor()->SetVisible(false); | 91 compositor()->SetVisible(false); |
| 96 | 92 |
| 97 if (frame_sink_id.is_valid()) | 93 if (init_params->frame_sink_id.is_valid()) |
| 98 window_mus->SetFrameSinkIdFromServer(frame_sink_id); | 94 window_mus->SetFrameSinkIdFromServer(init_params->frame_sink_id); |
| 99 } | 95 } |
| 100 | 96 |
| 101 // Pass |properties| to CreateWindowPortForTopLevel() so that |properties| | |
| 102 // are passed to the server *and* pass |properties| to the WindowTreeHostMus | |
| 103 // constructor (above) which applies the properties to the Window. Some of the | |
| 104 // properties may be server specific and not applied to the Window. | |
| 105 WindowTreeHostMus::WindowTreeHostMus( | |
| 106 WindowTreeClient* window_tree_client, | |
| 107 const cc::FrameSinkId& frame_sink_id, | |
| 108 const std::map<std::string, std::vector<uint8_t>>* properties) | |
| 109 : WindowTreeHostMus( | |
| 110 static_cast<WindowTreeHostMusDelegate*>(window_tree_client) | |
| 111 ->CreateWindowPortForTopLevel(properties), | |
| 112 window_tree_client, | |
| 113 display::Screen::GetScreen()->GetPrimaryDisplay().id(), | |
| 114 frame_sink_id, | |
| 115 properties) {} | |
| 116 | |
| 117 WindowTreeHostMus::~WindowTreeHostMus() { | 97 WindowTreeHostMus::~WindowTreeHostMus() { |
| 118 DestroyCompositor(); | 98 DestroyCompositor(); |
| 119 DestroyDispatcher(); | 99 DestroyDispatcher(); |
| 120 } | 100 } |
| 121 | 101 |
| 122 // static | 102 // static |
| 123 WindowTreeHostMus* WindowTreeHostMus::ForWindow(aura::Window* window) { | 103 WindowTreeHostMus* WindowTreeHostMus::ForWindow(aura::Window* window) { |
| 124 if (!window) | 104 if (!window) |
| 125 return nullptr; | 105 return nullptr; |
| 126 | 106 |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 224 void WindowTreeHostMus::MoveCursorToScreenLocationInPixels( | 204 void WindowTreeHostMus::MoveCursorToScreenLocationInPixels( |
| 225 const gfx::Point& location_in_pixels) { | 205 const gfx::Point& location_in_pixels) { |
| 226 // TODO: this needs to message the server http://crbug.com/693340. Setting | 206 // TODO: this needs to message the server http://crbug.com/693340. Setting |
| 227 // the location is really only appropriate in tests, outside of tests this | 207 // the location is really only appropriate in tests, outside of tests this |
| 228 // value is ignored. | 208 // value is ignored. |
| 229 NOTIMPLEMENTED(); | 209 NOTIMPLEMENTED(); |
| 230 Env::GetInstance()->set_last_mouse_location(location_in_pixels); | 210 Env::GetInstance()->set_last_mouse_location(location_in_pixels); |
| 231 } | 211 } |
| 232 | 212 |
| 233 } // namespace aura | 213 } // namespace aura |
| OLD | NEW |