| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "services/ui/public/cpp/window_tree_client.h" | 5 #include "ui/aura/mus/window_tree_client.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/auto_reset.h" |
| 13 #include "base/bind.h" | 14 #include "base/bind.h" |
| 14 #include "base/memory/ptr_util.h" | 15 #include "base/memory/ptr_util.h" |
| 15 #include "services/service_manager/public/cpp/connector.h" | 16 #include "services/service_manager/public/cpp/connector.h" |
| 16 #include "services/ui/common/util.h" | |
| 17 #include "services/ui/public/cpp/in_flight_change.h" | |
| 18 #include "services/ui/public/cpp/input_event_handler.h" | |
| 19 #include "services/ui/public/cpp/surface_id_handler.h" | |
| 20 #include "services/ui/public/cpp/window_drop_target.h" | |
| 21 #include "services/ui/public/cpp/window_manager_delegate.h" | |
| 22 #include "services/ui/public/cpp/window_observer.h" | |
| 23 #include "services/ui/public/cpp/window_private.h" | |
| 24 #include "services/ui/public/cpp/window_tracker.h" | |
| 25 #include "services/ui/public/cpp/window_tree_client_delegate.h" | |
| 26 #include "services/ui/public/cpp/window_tree_client_observer.h" | |
| 27 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" | 17 #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom
.h" |
| 18 #include "ui/aura/client/aura_constants.h" |
| 19 #include "ui/aura/client/capture_client.h" |
| 20 #include "ui/aura/client/focus_client.h" |
| 21 #include "ui/aura/mus/in_flight_change.h" |
| 22 #include "ui/aura/mus/input_method_mus.h" |
| 23 #include "ui/aura/mus/property_converter.h" |
| 24 #include "ui/aura/mus/surface_id_handler.h" |
| 25 #include "ui/aura/mus/window_manager_delegate.h" |
| 26 #include "ui/aura/mus/window_mus.h" |
| 27 #include "ui/aura/mus/window_port_mus.h" |
| 28 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 29 #include "ui/aura/mus/window_tree_client_observer.h" |
| 30 #include "ui/aura/mus/window_tree_host_mus.h" |
| 31 #include "ui/aura/window.h" |
| 32 #include "ui/aura/window_delegate.h" |
| 33 #include "ui/aura/window_tracker.h" |
| 28 #include "ui/events/event.h" | 34 #include "ui/events/event.h" |
| 29 #include "ui/gfx/geometry/insets.h" | 35 #include "ui/gfx/geometry/insets.h" |
| 30 #include "ui/gfx/geometry/size.h" | 36 #include "ui/gfx/geometry/size.h" |
| 31 | 37 |
| 32 namespace ui { | 38 #if defined(HiWord) |
| 39 #undef HiWord |
| 40 #endif |
| 41 #if defined(LoWord) |
| 42 #undef LoWord |
| 43 #endif |
| 44 |
| 45 namespace aura { |
| 46 namespace { |
| 33 | 47 |
| 34 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { | 48 Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| 35 return (client_id << 16) | local_id; | 49 return (client_id << 16) | local_id; |
| 36 } | 50 } |
| 37 | 51 |
| 38 // Helper called to construct a local window object from transport data. | 52 bool ShouldCreateTopLevel(ui::wm::WindowType type) { |
| 39 Window* AddWindowToClient(WindowTreeClient* client, | 53 switch (type) { |
| 40 Window* parent, | 54 case ui::wm::WINDOW_TYPE_CONTROL: |
| 41 const mojom::WindowDataPtr& window_data) { | 55 case ui::wm::WINDOW_TYPE_UNKNOWN: |
| 42 // We don't use the ctor that takes a WindowTreeClient here, since it will | 56 return false; |
| 43 // call back to the service and attempt to create a new window. | 57 |
| 44 Window* window = WindowPrivate::LocalCreate(); | 58 case ui::wm::WINDOW_TYPE_NORMAL: |
| 45 WindowPrivate private_window(window); | 59 case ui::wm::WINDOW_TYPE_POPUP: |
| 46 private_window.set_client(client); | 60 case ui::wm::WINDOW_TYPE_PANEL: |
| 47 private_window.set_server_id(window_data->window_id); | 61 case ui::wm::WINDOW_TYPE_MENU: |
| 48 private_window.set_visible(window_data->visible); | 62 case ui::wm::WINDOW_TYPE_TOOLTIP: |
| 49 private_window.set_properties( | 63 break; |
| 50 window_data->properties | 64 } |
| 51 .To<std::map<std::string, std::vector<uint8_t>>>()); | 65 return true; |
| 52 client->AddWindow(window); | |
| 53 private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); | |
| 54 if (parent) | |
| 55 WindowPrivate(parent).LocalAddChild(window); | |
| 56 return window; | |
| 57 } | 66 } |
| 58 | 67 |
| 68 inline uint16_t HiWord(uint32_t id) { |
| 69 return static_cast<uint16_t>((id >> 16) & 0xFFFF); |
| 70 } |
| 71 |
| 72 inline uint16_t LoWord(uint32_t id) { |
| 73 return static_cast<uint16_t>(id & 0xFFFF); |
| 74 } |
| 75 |
| 76 struct WindowPortPropertyDataMus : public WindowPortPropertyData { |
| 77 std::string transport_name; |
| 78 std::unique_ptr<std::vector<uint8_t>> transport_value; |
| 79 }; |
| 80 |
| 81 // Handles acknowledgment of an input event, either immediately when a nested |
| 82 // message loop starts, or upon destruction. |
| 83 class EventAckHandler : public base::MessageLoop::NestingObserver { |
| 84 public: |
| 85 explicit EventAckHandler(std::unique_ptr<EventResultCallback> ack_callback) |
| 86 : ack_callback_(std::move(ack_callback)) { |
| 87 DCHECK(ack_callback_); |
| 88 base::MessageLoop::current()->AddNestingObserver(this); |
| 89 } |
| 90 |
| 91 ~EventAckHandler() override { |
| 92 base::MessageLoop::current()->RemoveNestingObserver(this); |
| 93 if (ack_callback_) { |
| 94 ack_callback_->Run(handled_ ? ui::mojom::EventResult::HANDLED |
| 95 : ui::mojom::EventResult::UNHANDLED); |
| 96 } |
| 97 } |
| 98 |
| 99 void set_handled(bool handled) { handled_ = handled; } |
| 100 |
| 101 // base::MessageLoop::NestingObserver: |
| 102 void OnBeginNestedMessageLoop() override { |
| 103 // Acknowledge the event immediately if a nested message loop starts. |
| 104 // Otherwise we appear unresponsive for the life of the nested message loop. |
| 105 if (ack_callback_) { |
| 106 ack_callback_->Run(ui::mojom::EventResult::HANDLED); |
| 107 ack_callback_.reset(); |
| 108 } |
| 109 } |
| 110 |
| 111 private: |
| 112 std::unique_ptr<EventResultCallback> ack_callback_; |
| 113 bool handled_ = false; |
| 114 |
| 115 DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
| 116 }; |
| 117 |
| 118 } // namespace |
| 119 |
| 59 struct WindowTreeClient::CurrentDragState { | 120 struct WindowTreeClient::CurrentDragState { |
| 60 // The current change id of the current drag an drop ipc. | 121 // The current change id of the current drag an drop ipc. |
| 61 uint32_t change_id; | 122 uint32_t change_id; |
| 62 | 123 |
| 63 // The effect to return when we send our finish signal. | 124 // The effect to return when we send our finish signal. |
| 64 uint32_t completed_action; | 125 uint32_t completed_action; |
| 65 | 126 |
| 66 // Callback executed when a drag initiated by PerformDragDrop() is completed. | 127 // Callback executed when a drag initiated by PerformDragDrop() is completed. |
| 67 base::Callback<void(bool, uint32_t)> on_finished; | 128 base::Callback<void(bool, uint32_t)> on_finished; |
| 68 }; | 129 }; |
| 69 | 130 |
| 70 WindowTreeClient::WindowTreeClient( | 131 WindowTreeClient::WindowTreeClient( |
| 71 WindowTreeClientDelegate* delegate, | 132 WindowTreeClientDelegate* delegate, |
| 72 WindowManagerDelegate* window_manager_delegate, | 133 WindowManagerDelegate* window_manager_delegate, |
| 73 mojo::InterfaceRequest<mojom::WindowTreeClient> request) | 134 mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) |
| 74 : client_id_(0), | 135 : client_id_(0), |
| 75 next_window_id_(1), | 136 next_window_id_(1), |
| 76 next_change_id_(1), | 137 next_change_id_(1), |
| 77 delegate_(delegate), | 138 delegate_(delegate), |
| 78 window_manager_delegate_(window_manager_delegate), | 139 window_manager_delegate_(window_manager_delegate), |
| 79 capture_window_(nullptr), | |
| 80 focused_window_(nullptr), | |
| 81 binding_(this), | 140 binding_(this), |
| 82 tree_(nullptr), | 141 tree_(nullptr), |
| 83 in_destructor_(false), | 142 in_destructor_(false), |
| 84 weak_factory_(this) { | 143 weak_factory_(this) { |
| 85 // Allow for a null request in tests. | 144 // Allow for a null request in tests. |
| 86 if (request.is_pending()) | 145 if (request.is_pending()) |
| 87 binding_.Bind(std::move(request)); | 146 binding_.Bind(std::move(request)); |
| 147 delegate_->GetFocusClient()->AddObserver(this); |
| 148 delegate_->GetCaptureClient()->AddObserver(this); |
| 88 if (window_manager_delegate) | 149 if (window_manager_delegate) |
| 89 window_manager_delegate->SetWindowManagerClient(this); | 150 window_manager_delegate->SetWindowManagerClient(this); |
| 90 } | 151 } |
| 91 | 152 |
| 92 WindowTreeClient::~WindowTreeClient() { | 153 WindowTreeClient::~WindowTreeClient() { |
| 93 in_destructor_ = true; | 154 in_destructor_ = true; |
| 94 | 155 |
| 95 for (auto& observer : observers_) | 156 for (WindowTreeClientObserver& observer : observers_) |
| 96 observer.OnWillDestroyClient(this); | 157 observer.OnWillDestroyClient(this); |
| 97 | 158 |
| 98 std::vector<Window*> non_owned; | 159 std::vector<Window*> non_owned; |
| 99 WindowTracker tracker; | 160 WindowTracker tracker; |
| 100 while (!windows_.empty()) { | 161 while (!windows_.empty()) { |
| 101 IdToWindowMap::iterator it = windows_.begin(); | 162 IdToWindowMap::iterator it = windows_.begin(); |
| 102 if (it->second->WasCreatedByThisClient()) { | 163 if (WasCreatedByThisClient(it->second)) { |
| 103 it->second->Destroy(); | 164 const Id window_id = it->second->server_id(); |
| 165 delete it->second->GetWindow(); |
| 166 DCHECK_EQ(0u, windows_.count(window_id)); |
| 104 } else { | 167 } else { |
| 105 tracker.Add(it->second); | 168 tracker.Add(it->second->GetWindow()); |
| 106 windows_.erase(it); | 169 windows_.erase(it); |
| 107 } | 170 } |
| 108 } | 171 } |
| 109 | 172 |
| 110 // Delete the non-owned windows last. In the typical case these are roots. The | 173 // Delete the non-owned windows last. In the typical case these are roots. The |
| 111 // exception is the window manager and embed roots, which may know about | 174 // exception is the window manager and embed roots, which may know about |
| 112 // other random windows that it doesn't own. | 175 // other random windows that it doesn't own. |
| 113 // NOTE: we manually delete as we're a friend. | |
| 114 while (!tracker.windows().empty()) | 176 while (!tracker.windows().empty()) |
| 115 delete tracker.windows().front(); | 177 delete tracker.windows().front(); |
| 116 | 178 |
| 117 for (auto& observer : observers_) | 179 for (WindowTreeClientObserver& observer : observers_) |
| 118 observer.OnDidDestroyClient(this); | 180 observer.OnDidDestroyClient(this); |
| 181 |
| 182 delegate_->GetFocusClient()->RemoveObserver(this); |
| 183 delegate_->GetCaptureClient()->RemoveObserver(this); |
| 119 } | 184 } |
| 120 | 185 |
| 121 void WindowTreeClient::ConnectViaWindowTreeFactory( | 186 void WindowTreeClient::ConnectViaWindowTreeFactory( |
| 122 service_manager::Connector* connector) { | 187 service_manager::Connector* connector) { |
| 123 // The client id doesn't really matter, we use 101 purely for debugging. | 188 // The client id doesn't really matter, we use 101 purely for debugging. |
| 124 client_id_ = 101; | 189 client_id_ = 101; |
| 125 | 190 |
| 126 mojom::WindowTreeFactoryPtr factory; | 191 ui::mojom::WindowTreeFactoryPtr factory; |
| 127 connector->ConnectToInterface("service:ui", &factory); | 192 connector->ConnectToInterface("service:ui", &factory); |
| 128 mojom::WindowTreePtr window_tree; | 193 ui::mojom::WindowTreePtr window_tree; |
| 129 factory->CreateWindowTree(GetProxy(&window_tree), | 194 factory->CreateWindowTree(GetProxy(&window_tree), |
| 130 binding_.CreateInterfacePtrAndBind()); | 195 binding_.CreateInterfacePtrAndBind()); |
| 131 SetWindowTree(std::move(window_tree)); | 196 SetWindowTree(std::move(window_tree)); |
| 132 } | 197 } |
| 133 | 198 |
| 134 void WindowTreeClient::ConnectAsWindowManager( | 199 void WindowTreeClient::ConnectAsWindowManager( |
| 135 service_manager::Connector* connector) { | 200 service_manager::Connector* connector) { |
| 136 DCHECK(window_manager_delegate_); | 201 DCHECK(window_manager_delegate_); |
| 137 | 202 |
| 138 mojom::WindowManagerWindowTreeFactoryPtr factory; | 203 ui::mojom::WindowManagerWindowTreeFactoryPtr factory; |
| 139 connector->ConnectToInterface("service:ui", &factory); | 204 connector->ConnectToInterface("service:ui", &factory); |
| 140 mojom::WindowTreePtr window_tree; | 205 ui::mojom::WindowTreePtr window_tree; |
| 141 factory->CreateWindowTree(GetProxy(&window_tree), | 206 factory->CreateWindowTree(GetProxy(&window_tree), |
| 142 binding_.CreateInterfacePtrAndBind()); | 207 binding_.CreateInterfacePtrAndBind()); |
| 143 SetWindowTree(std::move(window_tree)); | 208 SetWindowTree(std::move(window_tree)); |
| 144 } | 209 } |
| 145 | 210 |
| 146 void WindowTreeClient::WaitForEmbed() { | 211 void WindowTreeClient::WaitForEmbed() { |
| 147 DCHECK(roots_.empty()); | 212 DCHECK(roots_.empty()); |
| 148 // OnEmbed() is the first function called. | 213 // OnEmbed() is the first function called. |
| 149 binding_.WaitForIncomingMethodCall(); | 214 binding_.WaitForIncomingMethodCall(); |
| 150 // TODO(sky): deal with pipe being closed before we get OnEmbed(). | 215 // TODO(sky): deal with pipe being closed before we get OnEmbed(). |
| 151 } | 216 } |
| 152 | 217 |
| 153 void WindowTreeClient::DestroyWindow(Window* window) { | |
| 154 DCHECK(tree_); | |
| 155 const uint32_t change_id = ScheduleInFlightChange( | |
| 156 base::MakeUnique<CrashInFlightChange>(window, ChangeType::DELETE_WINDOW)); | |
| 157 tree_->DeleteWindow(change_id, server_id(window)); | |
| 158 } | |
| 159 | |
| 160 void WindowTreeClient::AddChild(Window* parent, Id child_id) { | |
| 161 DCHECK(tree_); | |
| 162 const uint32_t change_id = ScheduleInFlightChange( | |
| 163 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); | |
| 164 tree_->AddWindow(change_id, parent->server_id(), child_id); | |
| 165 } | |
| 166 | |
| 167 void WindowTreeClient::RemoveChild(Window* parent, Id child_id) { | |
| 168 DCHECK(tree_); | |
| 169 const uint32_t change_id = ScheduleInFlightChange( | |
| 170 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD)); | |
| 171 tree_->RemoveWindowFromParent(change_id, child_id); | |
| 172 } | |
| 173 | |
| 174 void WindowTreeClient::AddTransientWindow(Window* window, | |
| 175 Id transient_window_id) { | |
| 176 DCHECK(tree_); | |
| 177 const uint32_t change_id = | |
| 178 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 179 window, ChangeType::ADD_TRANSIENT_WINDOW)); | |
| 180 tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); | |
| 181 } | |
| 182 | |
| 183 void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) { | |
| 184 DCHECK(tree_); | |
| 185 const uint32_t change_id = | |
| 186 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 187 window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)); | |
| 188 tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); | |
| 189 } | |
| 190 | |
| 191 void WindowTreeClient::SetModal(Window* window) { | |
| 192 DCHECK(tree_); | |
| 193 const uint32_t change_id = | |
| 194 ScheduleInFlightChange(base::MakeUnique<InFlightSetModalChange>(window)); | |
| 195 tree_->SetModal(change_id, server_id(window)); | |
| 196 } | |
| 197 | |
| 198 void WindowTreeClient::Reorder(Window* window, | |
| 199 Id relative_window_id, | |
| 200 mojom::OrderDirection direction) { | |
| 201 DCHECK(tree_); | |
| 202 const uint32_t change_id = ScheduleInFlightChange( | |
| 203 base::MakeUnique<CrashInFlightChange>(window, ChangeType::REORDER)); | |
| 204 tree_->ReorderWindow(change_id, server_id(window), relative_window_id, | |
| 205 direction); | |
| 206 } | |
| 207 | |
| 208 bool WindowTreeClient::WasCreatedByThisClient(const Window* window) const { | |
| 209 // Windows created via CreateTopLevelWindow() are not owned by us, but have | |
| 210 // our client id. const_cast is required by set. | |
| 211 return HiWord(server_id(window)) == client_id_ && | |
| 212 roots_.count(const_cast<Window*>(window)) == 0; | |
| 213 } | |
| 214 | |
| 215 void WindowTreeClient::SetBounds(Window* window, | |
| 216 const gfx::Rect& old_bounds, | |
| 217 const gfx::Rect& bounds) { | |
| 218 DCHECK(tree_); | |
| 219 const uint32_t change_id = ScheduleInFlightChange( | |
| 220 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); | |
| 221 tree_->SetWindowBounds(change_id, server_id(window), bounds); | |
| 222 } | |
| 223 | |
| 224 void WindowTreeClient::SetCapture(Window* window) { | |
| 225 // In order for us to get here we had to have exposed a window, which implies | |
| 226 // we got a client. | |
| 227 DCHECK(tree_); | |
| 228 if (capture_window_ == window) | |
| 229 return; | |
| 230 const uint32_t change_id = ScheduleInFlightChange( | |
| 231 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); | |
| 232 tree_->SetCapture(change_id, server_id(window)); | |
| 233 LocalSetCapture(window); | |
| 234 } | |
| 235 | |
| 236 void WindowTreeClient::ReleaseCapture(Window* window) { | |
| 237 // In order for us to get here we had to have exposed a window, which implies | |
| 238 // we got a client. | |
| 239 DCHECK(tree_); | |
| 240 if (capture_window_ != window) | |
| 241 return; | |
| 242 const uint32_t change_id = ScheduleInFlightChange( | |
| 243 base::MakeUnique<InFlightCaptureChange>(this, window)); | |
| 244 tree_->ReleaseCapture(change_id, server_id(window)); | |
| 245 LocalSetCapture(nullptr); | |
| 246 } | |
| 247 | |
| 248 void WindowTreeClient::SetClientArea( | 218 void WindowTreeClient::SetClientArea( |
| 249 Id window_id, | 219 Window* window, |
| 250 const gfx::Insets& client_area, | 220 const gfx::Insets& client_area, |
| 251 const std::vector<gfx::Rect>& additional_client_areas) { | 221 const std::vector<gfx::Rect>& additional_client_areas) { |
| 252 DCHECK(tree_); | 222 DCHECK(tree_); |
| 253 tree_->SetClientArea(window_id, client_area, additional_client_areas); | 223 tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, |
| 224 additional_client_areas); |
| 254 } | 225 } |
| 255 | 226 |
| 256 void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { | 227 void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| 257 DCHECK(tree_); | 228 DCHECK(tree_); |
| 258 tree_->SetHitTestMask(window_id, mask); | 229 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); |
| 259 } | 230 } |
| 260 | 231 |
| 261 void WindowTreeClient::ClearHitTestMask(Id window_id) { | 232 void WindowTreeClient::ClearHitTestMask(Window* window) { |
| 262 DCHECK(tree_); | 233 DCHECK(tree_); |
| 263 tree_->SetHitTestMask(window_id, base::nullopt); | 234 tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); |
| 264 } | 235 } |
| 265 | 236 |
| 266 void WindowTreeClient::SetFocus(Window* window) { | 237 void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { |
| 267 // In order for us to get here we had to have exposed a window, which implies | |
| 268 // we got a client. | |
| 269 DCHECK(tree_); | 238 DCHECK(tree_); |
| 270 const uint32_t change_id = ScheduleInFlightChange( | 239 DCHECK(window); |
| 271 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); | 240 tree_->SetCanFocus(WindowMus::Get(window)->server_id(), can_focus); |
| 272 tree_->SetFocus(change_id, window ? server_id(window) : 0); | |
| 273 LocalSetFocus(window); | |
| 274 } | 241 } |
| 275 | 242 |
| 276 void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) { | 243 void WindowTreeClient::SetPredefinedCursor(WindowMus* window, |
| 244 ui::mojom::Cursor old_cursor, |
| 245 ui::mojom::Cursor new_cursor) { |
| 277 DCHECK(tree_); | 246 DCHECK(tree_); |
| 278 tree_->SetCanFocus(window_id, can_focus); | 247 |
| 248 const uint32_t change_id = ScheduleInFlightChange( |
| 249 base::MakeUnique<InFlightPredefinedCursorChange>(window, old_cursor)); |
| 250 tree_->SetPredefinedCursor(change_id, window->server_id(), new_cursor); |
| 279 } | 251 } |
| 280 | 252 |
| 281 void WindowTreeClient::SetPredefinedCursor(Id window_id, | 253 void WindowTreeClient::SetWindowTextInputState(WindowMus* window, |
| 282 ui::mojom::Cursor cursor_id) { | 254 mojo::TextInputStatePtr state) { |
| 283 DCHECK(tree_); | 255 DCHECK(tree_); |
| 284 | 256 tree_->SetWindowTextInputState(window->server_id(), std::move(state)); |
| 285 Window* window = GetWindowByServerId(window_id); | |
| 286 if (!window) | |
| 287 return; | |
| 288 | |
| 289 // We make an inflight change thing here. | |
| 290 const uint32_t change_id = | |
| 291 ScheduleInFlightChange(base::MakeUnique<InFlightPredefinedCursorChange>( | |
| 292 window, window->predefined_cursor())); | |
| 293 tree_->SetPredefinedCursor(change_id, window_id, cursor_id); | |
| 294 } | 257 } |
| 295 | 258 |
| 296 void WindowTreeClient::SetVisible(Window* window, bool visible) { | 259 void WindowTreeClient::SetImeVisibility(WindowMus* window, |
| 260 bool visible, |
| 261 mojo::TextInputStatePtr state) { |
| 297 DCHECK(tree_); | 262 DCHECK(tree_); |
| 298 const uint32_t change_id = ScheduleInFlightChange( | 263 tree_->SetImeVisibility(window->server_id(), visible, std::move(state)); |
| 299 base::MakeUnique<InFlightVisibleChange>(window, !visible)); | |
| 300 tree_->SetWindowVisibility(change_id, server_id(window), visible); | |
| 301 } | 264 } |
| 302 | 265 |
| 303 void WindowTreeClient::SetOpacity(Window* window, float opacity) { | 266 void WindowTreeClient::Embed( |
| 304 DCHECK(tree_); | |
| 305 const uint32_t change_id = ScheduleInFlightChange( | |
| 306 base::MakeUnique<InFlightOpacityChange>(window, window->opacity())); | |
| 307 tree_->SetWindowOpacity(change_id, server_id(window), opacity); | |
| 308 } | |
| 309 | |
| 310 void WindowTreeClient::SetProperty(Window* window, | |
| 311 const std::string& name, | |
| 312 mojo::Array<uint8_t> data) { | |
| 313 DCHECK(tree_); | |
| 314 | |
| 315 mojo::Array<uint8_t> old_value(nullptr); | |
| 316 if (window->HasSharedProperty(name)) | |
| 317 old_value = mojo::Array<uint8_t>::From(window->properties_[name]); | |
| 318 | |
| 319 const uint32_t change_id = ScheduleInFlightChange( | |
| 320 base::MakeUnique<InFlightPropertyChange>(window, name, old_value)); | |
| 321 tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), | |
| 322 std::move(data)); | |
| 323 } | |
| 324 | |
| 325 void WindowTreeClient::SetWindowTextInputState( | |
| 326 Id window_id, | 267 Id window_id, |
| 327 mojo::TextInputStatePtr state) { | 268 ui::mojom::WindowTreeClientPtr client, |
| 328 DCHECK(tree_); | 269 uint32_t flags, |
| 329 tree_->SetWindowTextInputState(window_id, std::move(state)); | 270 const ui::mojom::WindowTree::EmbedCallback& callback) { |
| 330 } | |
| 331 | |
| 332 void WindowTreeClient::SetImeVisibility(Id window_id, | |
| 333 bool visible, | |
| 334 mojo::TextInputStatePtr state) { | |
| 335 DCHECK(tree_); | |
| 336 tree_->SetImeVisibility(window_id, visible, std::move(state)); | |
| 337 } | |
| 338 | |
| 339 void WindowTreeClient::Embed(Id window_id, | |
| 340 mojom::WindowTreeClientPtr client, | |
| 341 uint32_t flags, | |
| 342 const mojom::WindowTree::EmbedCallback& callback) { | |
| 343 DCHECK(tree_); | 271 DCHECK(tree_); |
| 344 tree_->Embed(window_id, std::move(client), flags, callback); | 272 tree_->Embed(window_id, std::move(client), flags, callback); |
| 345 } | 273 } |
| 346 | 274 |
| 347 void WindowTreeClient::RequestClose(Window* window) { | 275 void WindowTreeClient::RequestClose(Window* window) { |
| 276 DCHECK(window); |
| 348 if (window_manager_internal_client_) | 277 if (window_manager_internal_client_) |
| 349 window_manager_internal_client_->WmRequestClose(server_id(window)); | 278 window_manager_internal_client_->WmRequestClose( |
| 279 WindowMus::Get(window)->server_id()); |
| 350 } | 280 } |
| 351 | 281 |
| 352 void WindowTreeClient::AttachCompositorFrameSink( | 282 void WindowTreeClient::AttachCompositorFrameSink( |
| 353 Id window_id, | 283 Id window_id, |
| 354 mojom::CompositorFrameSinkType type, | 284 ui::mojom::CompositorFrameSinkType type, |
| 355 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, | 285 cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, |
| 356 cc::mojom::MojoCompositorFrameSinkClientPtr client) { | 286 cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| 357 DCHECK(tree_); | 287 DCHECK(tree_); |
| 358 tree_->AttachCompositorFrameSink( | 288 tree_->AttachCompositorFrameSink( |
| 359 window_id, type, std::move(compositor_frame_sink), std::move(client)); | 289 window_id, type, std::move(compositor_frame_sink), std::move(client)); |
| 360 } | 290 } |
| 361 | 291 |
| 362 void WindowTreeClient::OnWindowSurfaceDetached( | 292 void WindowTreeClient::RegisterWindowMus(WindowMus* window) { |
| 363 Id window_id, | 293 DCHECK(windows_.find(window->server_id()) == windows_.end()); |
| 364 const cc::SurfaceSequence& sequence) { | 294 windows_[window->server_id()] = window; |
| 365 DCHECK(tree_); | |
| 366 tree_->OnWindowSurfaceDetached(window_id, sequence); | |
| 367 } | 295 } |
| 368 | 296 |
| 369 void WindowTreeClient::LocalSetCapture(Window* window) { | 297 WindowMus* WindowTreeClient::GetWindowByServerId(Id id) { |
| 298 IdToWindowMap::const_iterator it = windows_.find(id); |
| 299 return it != windows_.end() ? it->second : nullptr; |
| 300 } |
| 301 |
| 302 bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const { |
| 303 // Windows created via CreateTopLevelWindow() are not owned by us, but have |
| 304 // our client id. const_cast is required by set. |
| 305 return HiWord(window->server_id()) == client_id_ && |
| 306 roots_.count(const_cast<WindowMus*>(window)) == 0; |
| 307 } |
| 308 |
| 309 void WindowTreeClient::SetFocusFromServer(WindowMus* window) { |
| 310 if (focused_window_ == window) |
| 311 return; |
| 312 |
| 313 if (window) { |
| 314 client::FocusClient* focus_client = |
| 315 client::GetFocusClient(window->GetWindow()); |
| 316 if (focus_client) { |
| 317 SetFocusFromServerImpl(focus_client, window); |
| 318 } else { |
| 319 SetFocusFromServerImpl( |
| 320 client::GetFocusClient(focused_window_->GetWindow()), nullptr); |
| 321 } |
| 322 } else { |
| 323 SetFocusFromServerImpl(client::GetFocusClient(focused_window_->GetWindow()), |
| 324 nullptr); |
| 325 } |
| 326 } |
| 327 |
| 328 void WindowTreeClient::SetFocusFromServerImpl(client::FocusClient* focus_client, |
| 329 WindowMus* window) { |
| 330 if (!focus_client) |
| 331 return; |
| 332 |
| 333 DCHECK(!setting_focus_); |
| 334 base::AutoReset<bool> focus_reset(&setting_focus_, true); |
| 335 base::AutoReset<WindowMus*> window_setting_focus_to_reset( |
| 336 &window_setting_focus_to_, window); |
| 337 focus_client->FocusWindow(window ? window->GetWindow() : nullptr); |
| 338 } |
| 339 |
| 340 void WindowTreeClient::SetCaptureFromServer(WindowMus* window) { |
| 341 // In order for us to get here we had to have exposed a window, which implies |
| 342 // we got a client. |
| 343 DCHECK(tree_); |
| 370 if (capture_window_ == window) | 344 if (capture_window_ == window) |
| 371 return; | 345 return; |
| 372 Window* lost_capture = capture_window_; | 346 DCHECK(!setting_capture_); |
| 373 capture_window_ = window; | 347 base::AutoReset<bool> capture_reset(&setting_capture_, true); |
| 374 if (lost_capture) { | 348 base::AutoReset<WindowMus*> window_setting_capture_to_reset( |
| 375 for (auto& observer : *WindowPrivate(lost_capture).observers()) | 349 &window_setting_capture_to_, window); |
| 376 observer.OnWindowLostCapture(lost_capture); | 350 delegate_->GetCaptureClient()->SetCapture(window ? window->GetWindow() |
| 377 } | 351 : nullptr); |
| 378 for (auto& observer : observers_) | |
| 379 observer.OnWindowTreeCaptureChanged(window, lost_capture); | |
| 380 } | |
| 381 | |
| 382 void WindowTreeClient::LocalSetFocus(Window* focused) { | |
| 383 Window* blurred = focused_window_; | |
| 384 // Update |focused_window_| before calling any of the observers, so that the | |
| 385 // observers get the correct result from calling |Window::HasFocus()|, | |
| 386 // |WindowTreeClient::GetFocusedWindow()| etc. | |
| 387 focused_window_ = focused; | |
| 388 if (blurred) { | |
| 389 for (auto& observer : *WindowPrivate(blurred).observers()) | |
| 390 observer.OnWindowFocusChanged(focused, blurred); | |
| 391 } | |
| 392 if (focused) { | |
| 393 for (auto& observer : *WindowPrivate(focused).observers()) | |
| 394 observer.OnWindowFocusChanged(focused, blurred); | |
| 395 } | |
| 396 for (auto& observer : observers_) | |
| 397 observer.OnWindowTreeFocusChanged(focused, blurred); | |
| 398 } | |
| 399 | |
| 400 void WindowTreeClient::AddWindow(Window* window) { | |
| 401 DCHECK(windows_.find(server_id(window)) == windows_.end()); | |
| 402 windows_[server_id(window)] = window; | |
| 403 } | |
| 404 | |
| 405 void WindowTreeClient::OnWindowDestroying(Window* window) { | |
| 406 if (window == capture_window_) { | |
| 407 // Normally the queue updates itself upon window destruction. However since | |
| 408 // |window| is being destroyed, it will not be possible to notify its | |
| 409 // observers of the lost capture. Update local state now. | |
| 410 LocalSetCapture(nullptr); | |
| 411 } | |
| 412 // For |focused_window_| window destruction clears the entire focus state. | |
| 413 } | |
| 414 | |
| 415 void WindowTreeClient::OnWindowDestroyed(Window* window) { | |
| 416 windows_.erase(server_id(window)); | |
| 417 | |
| 418 for (auto& entry : embedded_windows_) { | |
| 419 auto it = entry.second.find(window); | |
| 420 if (it != entry.second.end()) { | |
| 421 entry.second.erase(it); | |
| 422 break; | |
| 423 } | |
| 424 } | |
| 425 | |
| 426 // Remove any InFlightChanges associated with the window. | |
| 427 std::set<uint32_t> in_flight_change_ids_to_remove; | |
| 428 for (const auto& pair : in_flight_map_) { | |
| 429 if (pair.second->window() == window) | |
| 430 in_flight_change_ids_to_remove.insert(pair.first); | |
| 431 } | |
| 432 for (auto change_id : in_flight_change_ids_to_remove) | |
| 433 in_flight_map_.erase(change_id); | |
| 434 | |
| 435 const bool was_root = roots_.erase(window) > 0; | |
| 436 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) | |
| 437 delegate_->OnEmbedRootDestroyed(window); | |
| 438 } | |
| 439 | |
| 440 Window* WindowTreeClient::GetWindowByServerId(Id id) { | |
| 441 IdToWindowMap::const_iterator it = windows_.find(id); | |
| 442 return it != windows_.end() ? it->second : NULL; | |
| 443 } | 352 } |
| 444 | 353 |
| 445 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( | 354 InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( |
| 446 const InFlightChange& change) { | 355 const InFlightChange& change) { |
| 447 for (const auto& pair : in_flight_map_) { | 356 for (const auto& pair : in_flight_map_) { |
| 448 if (pair.second->window() == change.window() && | 357 if (pair.second->window() == change.window() && |
| 449 pair.second->change_type() == change.change_type() && | 358 pair.second->change_type() == change.change_type() && |
| 450 pair.second->Matches(change)) { | 359 pair.second->Matches(change)) { |
| 451 return pair.second.get(); | 360 return pair.second.get(); |
| 452 } | 361 } |
| (...skipping 13 matching lines...) Expand all Loading... |
| 466 bool WindowTreeClient::ApplyServerChangeToExistingInFlightChange( | 375 bool WindowTreeClient::ApplyServerChangeToExistingInFlightChange( |
| 467 const InFlightChange& change) { | 376 const InFlightChange& change) { |
| 468 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); | 377 InFlightChange* existing_change = GetOldestInFlightChangeMatching(change); |
| 469 if (!existing_change) | 378 if (!existing_change) |
| 470 return false; | 379 return false; |
| 471 | 380 |
| 472 existing_change->SetRevertValueFrom(change); | 381 existing_change->SetRevertValueFrom(change); |
| 473 return true; | 382 return true; |
| 474 } | 383 } |
| 475 | 384 |
| 476 Window* WindowTreeClient::BuildWindowTree( | 385 void WindowTreeClient::BuildWindowTree( |
| 477 const mojo::Array<mojom::WindowDataPtr>& windows, | 386 const mojo::Array<ui::mojom::WindowDataPtr>& windows, |
| 478 Window* initial_parent) { | 387 WindowMus* initial_parent) { |
| 479 std::vector<Window*> parents; | 388 std::vector<WindowMus*> parents; |
| 480 Window* root = nullptr; | 389 WindowMus* last_window = nullptr; |
| 481 Window* last_window = nullptr; | |
| 482 if (initial_parent) | 390 if (initial_parent) |
| 483 parents.push_back(initial_parent); | 391 parents.push_back(initial_parent); |
| 484 for (size_t i = 0; i < windows.size(); ++i) { | 392 for (const auto& window_data : windows) { |
| 485 if (last_window && windows[i]->parent_id == server_id(last_window)) { | 393 if (last_window && window_data->parent_id == last_window->server_id()) { |
| 486 parents.push_back(last_window); | 394 parents.push_back(last_window); |
| 487 } else if (!parents.empty()) { | 395 } else if (!parents.empty()) { |
| 488 while (server_id(parents.back()) != windows[i]->parent_id) | 396 while (parents.back()->server_id() != window_data->parent_id) |
| 489 parents.pop_back(); | 397 parents.pop_back(); |
| 490 } | 398 } |
| 491 Window* window = AddWindowToClient( | 399 // This code is only called in a context where there is a parent. |
| 492 this, !parents.empty() ? parents.back() : nullptr, windows[i]); | 400 DCHECK(!parents.empty()); |
| 493 if (!last_window) | 401 last_window = NewWindowFromWindowData( |
| 494 root = window; | 402 !parents.empty() ? parents.back() : nullptr, window_data); |
| 495 last_window = window; | |
| 496 } | 403 } |
| 497 return root; | |
| 498 } | 404 } |
| 499 | 405 |
| 500 Window* WindowTreeClient::NewWindowImpl( | 406 std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( |
| 501 NewWindowType type, | 407 const ui::mojom::WindowDataPtr& window_data) { |
| 502 const Window::SharedProperties* properties) { | 408 std::unique_ptr<WindowPortMus> window_port_mus( |
| 503 DCHECK(tree_); | 409 base::MakeUnique<WindowPortMus>(this)); |
| 504 Window* window = | 410 window_port_mus->set_server_id(window_data->window_id); |
| 505 new Window(this, MakeTransportId(client_id_, next_window_id_++)); | 411 RegisterWindowMus(window_port_mus.get()); |
| 506 if (properties) | 412 return window_port_mus; |
| 507 window->properties_ = *properties; | |
| 508 AddWindow(window); | |
| 509 | |
| 510 const uint32_t change_id = | |
| 511 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 512 window, type == NewWindowType::CHILD | |
| 513 ? ChangeType::NEW_WINDOW | |
| 514 : ChangeType::NEW_TOP_LEVEL_WINDOW)); | |
| 515 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; | |
| 516 if (properties) { | |
| 517 transport_properties = | |
| 518 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); | |
| 519 } | |
| 520 if (type == NewWindowType::CHILD) { | |
| 521 tree_->NewWindow(change_id, server_id(window), | |
| 522 std::move(transport_properties)); | |
| 523 } else { | |
| 524 roots_.insert(window); | |
| 525 tree_->NewTopLevelWindow(change_id, server_id(window), | |
| 526 std::move(transport_properties)); | |
| 527 } | |
| 528 return window; | |
| 529 } | 413 } |
| 530 | 414 |
| 531 void WindowTreeClient::SetWindowTree(mojom::WindowTreePtr window_tree_ptr) { | 415 void WindowTreeClient::SetLocalPropertiesFromServerProperties( |
| 416 WindowMus* window, |
| 417 const ui::mojom::WindowDataPtr& window_data) { |
| 418 for (auto& pair : window_data->properties) { |
| 419 if (pair.second.is_null()) { |
| 420 window->SetPropertyFromServer(pair.first, nullptr); |
| 421 } else { |
| 422 std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); |
| 423 window->SetPropertyFromServer(pair.first, &stl_value); |
| 424 } |
| 425 } |
| 426 } |
| 427 |
| 428 Window* WindowTreeClient::CreateWindowTreeHost( |
| 429 WindowTreeHostType type, |
| 430 const ui::mojom::WindowDataPtr& window_data, |
| 431 Window* content_window) { |
| 432 Window* user_window = nullptr; |
| 433 switch (type) { |
| 434 case WindowTreeHostType::DISPLAY: { |
| 435 DCHECK(!content_window); |
| 436 WindowTreeHost* window_tree_host = |
| 437 new WindowTreeHostMus(CreateWindowPortMus(window_data)); |
| 438 user_window = window_tree_host->window(); |
| 439 break; |
| 440 } |
| 441 case WindowTreeHostType::EMBED: { |
| 442 DCHECK(!content_window); |
| 443 user_window = new Window(nullptr, CreateWindowPortMus(window_data)); |
| 444 user_window->Init(ui::LAYER_TEXTURED); |
| 445 new WindowTreeHostMus(nullptr, user_window); |
| 446 break; |
| 447 } |
| 448 case WindowTreeHostType::TOP_LEVEL: { |
| 449 DCHECK(content_window); |
| 450 user_window = content_window; |
| 451 new WindowTreeHostMus(nullptr, user_window); |
| 452 break; |
| 453 } |
| 454 } |
| 455 WindowMus* user_window_mus = WindowMus::Get(user_window); |
| 456 roots_.insert(user_window_mus); |
| 457 if (!window_data.is_null()) |
| 458 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); |
| 459 return user_window; |
| 460 } |
| 461 |
| 462 WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| 463 WindowMus* parent, |
| 464 const ui::mojom::WindowDataPtr& window_data) { |
| 465 std::unique_ptr<WindowPortMus> window_port_mus( |
| 466 CreateWindowPortMus(window_data)); |
| 467 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| 468 Window* window = new Window(nullptr, std::move(window_port_mus)); |
| 469 WindowMus* window_mus = window_port_mus_ptr; |
| 470 window->Init(ui::LAYER_NOT_DRAWN); |
| 471 SetLocalPropertiesFromServerProperties(window_mus, window_data); |
| 472 window_mus->SetBoundsFromServer(window_data->bounds); |
| 473 if (parent) |
| 474 parent->AddChildFromServer(window_port_mus_ptr); |
| 475 if (window_data->visible) |
| 476 window_mus->SetVisibleFromServer(true); |
| 477 return window_port_mus_ptr; |
| 478 } |
| 479 |
| 480 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { |
| 532 tree_ptr_ = std::move(window_tree_ptr); | 481 tree_ptr_ = std::move(window_tree_ptr); |
| 533 tree_ = tree_ptr_.get(); | 482 tree_ = tree_ptr_.get(); |
| 534 | 483 |
| 535 tree_ptr_->GetCursorLocationMemory( | 484 tree_ptr_->GetCursorLocationMemory( |
| 536 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, | 485 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, |
| 537 weak_factory_.GetWeakPtr())); | 486 weak_factory_.GetWeakPtr())); |
| 538 | 487 |
| 539 tree_ptr_.set_connection_error_handler(base::Bind( | 488 tree_ptr_.set_connection_error_handler(base::Bind( |
| 540 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr())); | 489 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr())); |
| 541 | 490 |
| 542 if (window_manager_delegate_) { | 491 if (window_manager_delegate_) { |
| 543 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 492 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 544 tree_ptr_.associated_group())); | 493 tree_ptr_.associated_group())); |
| 545 } | 494 } |
| 546 } | 495 } |
| 547 | 496 |
| 548 void WindowTreeClient::OnConnectionLost() { | 497 void WindowTreeClient::OnConnectionLost() { |
| 549 delegate_->OnLostConnection(this); | 498 delegate_->OnLostConnection(this); |
| 550 } | 499 } |
| 551 | 500 |
| 552 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, | 501 void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree, |
| 553 ClientSpecificId client_id, | 502 ClientSpecificId client_id, |
| 554 mojom::WindowDataPtr root_data, | 503 ui::mojom::WindowDataPtr root_data, |
| 555 int64_t display_id, | 504 int64_t display_id, |
| 556 Id focused_window_id, | 505 Id focused_window_id, |
| 557 bool drawn) { | 506 bool drawn) { |
| 558 // WARNING: this is only called if WindowTreeClient was created as the | 507 // WARNING: this is only called if WindowTreeClient was created as the |
| 559 // result of an embedding. | 508 // result of an embedding. |
| 560 tree_ = window_tree; | 509 tree_ = window_tree; |
| 561 client_id_ = client_id; | 510 client_id_ = client_id; |
| 562 | 511 |
| 563 DCHECK(roots_.empty()); | 512 DCHECK(roots_.empty()); |
| 564 Window* root = AddWindowToClient(this, nullptr, root_data); | 513 Window* root = |
| 565 WindowPrivate(root).LocalSetDisplay(display_id); | 514 CreateWindowTreeHost(WindowTreeHostType::EMBED, root_data, nullptr); |
| 566 roots_.insert(root); | 515 // TODO: needs to deal with drawn and display_id. |
| 567 | 516 |
| 568 focused_window_ = GetWindowByServerId(focused_window_id); | 517 SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
| 569 | |
| 570 WindowPrivate(root).LocalSetParentDrawn(drawn); | |
| 571 | 518 |
| 572 delegate_->OnEmbed(root); | 519 delegate_->OnEmbed(root); |
| 573 | |
| 574 if (focused_window_) { | |
| 575 for (auto& observer : observers_) | |
| 576 observer.OnWindowTreeFocusChanged(focused_window_, nullptr); | |
| 577 } | |
| 578 } | 520 } |
| 579 | 521 |
| 580 void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display, | 522 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
| 581 mojom::WindowDataPtr root_data, | 523 const display::Display& display, |
| 582 bool parent_drawn) { | 524 ui::mojom::WindowDataPtr root_data, |
| 525 bool parent_drawn) { |
| 583 DCHECK(window_manager_delegate_); | 526 DCHECK(window_manager_delegate_); |
| 584 | 527 |
| 585 Window* root = AddWindowToClient(this, nullptr, root_data); | 528 // TODO: need to deal with display_id and drawn. |
| 586 WindowPrivate(root).LocalSetDisplay(display.id()); | 529 Window* root = |
| 587 WindowPrivate(root).LocalSetParentDrawn(parent_drawn); | 530 CreateWindowTreeHost(WindowTreeHostType::DISPLAY, root_data, nullptr); |
| 588 roots_.insert(root); | 531 // WindowPrivate(root).LocalSetDisplay(display.id()); |
| 532 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); |
| 589 | 533 |
| 590 window_manager_delegate_->OnWmNewDisplay(root, display); | 534 window_manager_delegate_->OnWmNewDisplay(root, display); |
| 535 return root->GetHost(); |
| 536 } |
| 537 |
| 538 std::unique_ptr<EventResultCallback> |
| 539 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
| 540 return base::MakeUnique<EventResultCallback>( |
| 541 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, |
| 542 base::Unretained(tree_), event_id)); |
| 591 } | 543 } |
| 592 | 544 |
| 593 void WindowTreeClient::OnReceivedCursorLocationMemory( | 545 void WindowTreeClient::OnReceivedCursorLocationMemory( |
| 594 mojo::ScopedSharedBufferHandle handle) { | 546 mojo::ScopedSharedBufferHandle handle) { |
| 595 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); | 547 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); |
| 596 DCHECK(cursor_location_mapping_); | 548 DCHECK(cursor_location_mapping_); |
| 597 } | 549 } |
| 598 | 550 |
| 551 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( |
| 552 WindowMus* window) { |
| 553 if (window->server_id() != 0) { |
| 554 // This window was created by us and has an associated server window. |
| 555 return nullptr; |
| 556 } |
| 557 |
| 558 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| 559 RegisterWindowMus(window); |
| 560 |
| 561 const bool create_top_level = |
| 562 !window_manager_delegate_ && |
| 563 ShouldCreateTopLevel(window->GetWindow()->type()); |
| 564 |
| 565 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; |
| 566 std::set<const void*> property_keys = |
| 567 window->GetWindow()->GetAllPropertKeys(); |
| 568 PropertyConverter* property_converter = delegate_->GetPropertyConverter(); |
| 569 for (const void* key : property_keys) { |
| 570 std::string transport_name; |
| 571 std::unique_ptr<std::vector<uint8_t>> transport_value; |
| 572 if (!property_converter->ConvertPropertyForTransport( |
| 573 window->GetWindow(), key, &transport_name, &transport_value)) { |
| 574 continue; |
| 575 } |
| 576 if (!transport_value) { |
| 577 transport_properties[transport_name] = mojo::Array<uint8_t>(nullptr); |
| 578 } else { |
| 579 transport_properties[transport_name] = |
| 580 mojo::Array<uint8_t>::From(*transport_value); |
| 581 } |
| 582 } |
| 583 |
| 584 const uint32_t change_id = |
| 585 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| 586 window, create_top_level ? ChangeType::NEW_TOP_LEVEL_WINDOW |
| 587 : ChangeType::NEW_WINDOW)); |
| 588 if (create_top_level) { |
| 589 std::unique_ptr<WindowPortInitData> data( |
| 590 base::MakeUnique<WindowPortInitData>()); |
| 591 tree_->NewTopLevelWindow(change_id, window->server_id(), |
| 592 std::move(transport_properties)); |
| 593 return data; |
| 594 } |
| 595 tree_->NewWindow(change_id, window->server_id(), |
| 596 std::move(transport_properties)); |
| 597 return nullptr; |
| 598 } |
| 599 |
| 600 void WindowTreeClient::OnWindowMusInitDone( |
| 601 WindowMus* window, |
| 602 std::unique_ptr<WindowPortInitData> init_data) { |
| 603 if (!init_data) |
| 604 return; |
| 605 |
| 606 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger |
| 607 // crashes in code that expects window parenting to happen after |
| 608 // Env::NotifyWindowInitialized() is called. |
| 609 CreateWindowTreeHost(WindowTreeHostType::TOP_LEVEL, nullptr, |
| 610 window->GetWindow()); |
| 611 } |
| 612 |
| 613 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { |
| 614 if (focused_window_ == window) |
| 615 focused_window_ = nullptr; |
| 616 |
| 617 // TODO: decide how to deal with windows not owned by this client. |
| 618 if (WasCreatedByThisClient(window) || IsRoot(window)) { |
| 619 const uint32_t change_id = |
| 620 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| 621 window, ChangeType::DELETE_WINDOW)); |
| 622 tree_->DeleteWindow(change_id, window->server_id()); |
| 623 } |
| 624 |
| 625 windows_.erase(window->server_id()); |
| 626 |
| 627 for (auto& entry : embedded_windows_) { |
| 628 auto it = entry.second.find(window->GetWindow()); |
| 629 if (it != entry.second.end()) { |
| 630 entry.second.erase(it); |
| 631 break; |
| 632 } |
| 633 } |
| 634 |
| 635 // Remove any InFlightChanges associated with the window. |
| 636 std::set<uint32_t> in_flight_change_ids_to_remove; |
| 637 for (const auto& pair : in_flight_map_) { |
| 638 if (pair.second->window() == window) |
| 639 in_flight_change_ids_to_remove.insert(pair.first); |
| 640 } |
| 641 for (auto change_id : in_flight_change_ids_to_remove) |
| 642 in_flight_map_.erase(change_id); |
| 643 |
| 644 const bool was_root = roots_.erase(window) > 0; |
| 645 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) |
| 646 delegate_->OnEmbedRootDestroyed(window->GetWindow()); |
| 647 } |
| 648 |
| 649 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| 650 const gfx::Rect& old_bounds, |
| 651 const gfx::Rect& new_bounds) { |
| 652 const uint32_t change_id = ScheduleInFlightChange( |
| 653 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); |
| 654 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); |
| 655 } |
| 656 |
| 657 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| 658 WindowMus* child) { |
| 659 // TODO: add checks to ensure this can work. |
| 660 const uint32_t change_id = ScheduleInFlightChange( |
| 661 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| 662 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); |
| 663 } |
| 664 |
| 665 void WindowTreeClient::OnWindowMusRemoveChild(WindowMus* parent, |
| 666 WindowMus* child) { |
| 667 // TODO: add checks to ensure this can work. |
| 668 const uint32_t change_id = ScheduleInFlightChange( |
| 669 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD)); |
| 670 tree_->RemoveWindowFromParent(change_id, child->server_id()); |
| 671 } |
| 672 |
| 673 void WindowTreeClient::OnWindowMusMoveChild(WindowMus* parent, |
| 674 size_t current_index, |
| 675 size_t dest_index) { |
| 676 // TODO: add checks to ensure this can work, e.g. we own the parent. |
| 677 const uint32_t change_id = ScheduleInFlightChange( |
| 678 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REORDER)); |
| 679 WindowMus* window = |
| 680 WindowMus::Get(parent->GetWindow()->children()[current_index]); |
| 681 WindowMus* relative_window = nullptr; |
| 682 ui::mojom::OrderDirection direction; |
| 683 if (dest_index < current_index) { |
| 684 relative_window = |
| 685 WindowMus::Get(parent->GetWindow()->children()[dest_index]); |
| 686 direction = ui::mojom::OrderDirection::BELOW; |
| 687 } else { |
| 688 relative_window = |
| 689 WindowMus::Get(parent->GetWindow()->children()[dest_index]); |
| 690 direction = ui::mojom::OrderDirection::ABOVE; |
| 691 } |
| 692 tree_->ReorderWindow(change_id, window->server_id(), |
| 693 relative_window->server_id(), direction); |
| 694 } |
| 695 |
| 696 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { |
| 697 // TODO: add checks to ensure this can work. |
| 698 DCHECK(tree_); |
| 699 const uint32_t change_id = ScheduleInFlightChange( |
| 700 base::MakeUnique<InFlightVisibleChange>(window, !visible)); |
| 701 tree_->SetWindowVisibility(change_id, window->server_id(), visible); |
| 702 } |
| 703 |
| 704 std::unique_ptr<WindowPortPropertyData> |
| 705 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, |
| 706 const void* key) { |
| 707 std::unique_ptr<WindowPortPropertyDataMus> data( |
| 708 base::MakeUnique<WindowPortPropertyDataMus>()); |
| 709 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( |
| 710 window->GetWindow(), key, &data->transport_name, |
| 711 &data->transport_value)) { |
| 712 return nullptr; |
| 713 } |
| 714 return data; |
| 715 } |
| 716 |
| 717 void WindowTreeClient::OnWindowMusPropertyChanged( |
| 718 WindowMus* window, |
| 719 const void* key, |
| 720 std::unique_ptr<WindowPortPropertyData> data) { |
| 721 if (!data) |
| 722 return; |
| 723 WindowPortPropertyDataMus* data_mus = |
| 724 static_cast<WindowPortPropertyDataMus*>(data.get()); |
| 725 |
| 726 std::string transport_name; |
| 727 std::unique_ptr<std::vector<uint8_t>> transport_value; |
| 728 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( |
| 729 window->GetWindow(), key, &transport_name, &transport_value)) { |
| 730 return; |
| 731 } |
| 732 DCHECK_EQ(transport_name, data_mus->transport_name); |
| 733 |
| 734 mojo::Array<uint8_t> transport_value_mojo(nullptr); |
| 735 if (transport_value) { |
| 736 transport_value_mojo.resize(transport_value->size()); |
| 737 if (transport_value->size()) { |
| 738 memcpy(&transport_value_mojo.front(), &(transport_value->front()), |
| 739 transport_value->size()); |
| 740 } |
| 741 } |
| 742 const uint32_t change_id = |
| 743 ScheduleInFlightChange(base::MakeUnique<InFlightPropertyChange>( |
| 744 window, transport_name, std::move(data_mus->transport_value))); |
| 745 tree_->SetWindowProperty(change_id, window->server_id(), |
| 746 mojo::String(transport_name), |
| 747 std::move(transport_value_mojo)); |
| 748 } |
| 749 |
| 750 void WindowTreeClient::OnWindowMusSurfaceDetached( |
| 751 WindowMus* window, |
| 752 const cc::SurfaceSequence& sequence) { |
| 753 tree_->OnWindowSurfaceDetached(window->server_id(), sequence); |
| 754 } |
| 755 |
| 599 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, | 756 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, |
| 600 bool completed) { | 757 bool completed) { |
| 601 if (window_manager_internal_client_) | 758 if (window_manager_internal_client_) |
| 602 window_manager_internal_client_->WmResponse(change_id, completed); | 759 window_manager_internal_client_->WmResponse(change_id, completed); |
| 603 | 760 |
| 604 if (change_id == current_wm_move_loop_change_) { | 761 if (change_id == current_wm_move_loop_change_) { |
| 605 current_wm_move_loop_change_ = 0; | 762 current_wm_move_loop_change_ = 0; |
| 606 current_wm_move_loop_window_id_ = 0; | 763 current_wm_move_loop_window_id_ = 0; |
| 607 } | 764 } |
| 608 } | 765 } |
| 609 | 766 |
| 610 //////////////////////////////////////////////////////////////////////////////// | 767 //////////////////////////////////////////////////////////////////////////////// |
| 611 // WindowTreeClient, WindowTreeClient implementation: | 768 // WindowTreeClient, WindowTreeClient implementation: |
| 612 | 769 |
| 613 const std::set<Window*>& WindowTreeClient::GetRoots() { | 770 std::set<Window*> WindowTreeClient::GetRoots() { |
| 614 return roots_; | 771 std::set<Window*> roots; |
| 772 for (WindowMus* window : roots_) |
| 773 roots.insert(window->GetWindow()); |
| 774 return roots; |
| 615 } | 775 } |
| 616 | 776 |
| 617 Window* WindowTreeClient::GetFocusedWindow() { | 777 Window* WindowTreeClient::GetFocusedWindow() { |
| 618 return focused_window_; | 778 return focused_window_ ? focused_window_->GetWindow() : nullptr; |
| 619 } | |
| 620 | |
| 621 void WindowTreeClient::ClearFocus() { | |
| 622 if (!focused_window_) | |
| 623 return; | |
| 624 | |
| 625 SetFocus(nullptr); | |
| 626 } | 779 } |
| 627 | 780 |
| 628 gfx::Point WindowTreeClient::GetCursorScreenPoint() { | 781 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| 629 // We raced initialization. Return (0, 0). | 782 // We raced initialization. Return (0, 0). |
| 630 if (!cursor_location_memory()) | 783 if (!cursor_location_memory()) |
| 631 return gfx::Point(); | 784 return gfx::Point(); |
| 632 | 785 |
| 633 base::subtle::Atomic32 location = | 786 base::subtle::Atomic32 location = |
| 634 base::subtle::NoBarrier_Load(cursor_location_memory()); | 787 base::subtle::NoBarrier_Load(cursor_location_memory()); |
| 635 return gfx::Point(static_cast<int16_t>(location >> 16), | 788 return gfx::Point(static_cast<int16_t>(location >> 16), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 649 has_pointer_watcher_ = false; | 802 has_pointer_watcher_ = false; |
| 650 } | 803 } |
| 651 | 804 |
| 652 void WindowTreeClient::PerformDragDrop( | 805 void WindowTreeClient::PerformDragDrop( |
| 653 Window* window, | 806 Window* window, |
| 654 const std::map<std::string, std::vector<uint8_t>>& drag_data, | 807 const std::map<std::string, std::vector<uint8_t>>& drag_data, |
| 655 int drag_operation, | 808 int drag_operation, |
| 656 const gfx::Point& cursor_location, | 809 const gfx::Point& cursor_location, |
| 657 const SkBitmap& bitmap, | 810 const SkBitmap& bitmap, |
| 658 const base::Callback<void(bool, uint32_t)>& callback) { | 811 const base::Callback<void(bool, uint32_t)>& callback) { |
| 812 // TODO: dnd. |
| 813 /* |
| 659 DCHECK(!current_drag_state_); | 814 DCHECK(!current_drag_state_); |
| 660 | 815 |
| 661 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when | 816 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| 662 // we start showing an image representation of the drag under he cursor. | 817 // we start showing an image representation of the drag under he cursor. |
| 663 | 818 |
| 664 if (window->drop_target()) { | 819 if (window->drop_target()) { |
| 665 // To minimize the number of round trips, copy the drag drop data to our | 820 // To minimize the number of round trips, copy the drag drop data to our |
| 666 // handler here, instead of forcing mus to send this same data back. | 821 // handler here, instead of forcing mus to send this same data back. |
| 667 OnDragDropStart( | 822 OnDragDropStart( |
| 668 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); | 823 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); |
| 669 } | 824 } |
| 670 | 825 |
| 671 uint32_t current_drag_change = ScheduleInFlightChange( | 826 uint32_t current_drag_change = ScheduleInFlightChange( |
| 672 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 827 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
| 673 current_drag_state_.reset(new CurrentDragState{ | 828 current_drag_state_.reset(new CurrentDragState{ |
| 674 current_drag_change, ui::mojom::kDropEffectNone, callback}); | 829 current_drag_change, ui::mojom::kDropEffectNone, callback}); |
| 675 | 830 |
| 676 tree_->PerformDragDrop( | 831 tree_->PerformDragDrop( |
| 677 current_drag_change, window->server_id(), | 832 current_drag_change, window->server_id(), |
| 678 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), | 833 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
| 679 drag_operation); | 834 drag_operation); |
| 835 */ |
| 680 } | 836 } |
| 681 | 837 |
| 682 void WindowTreeClient::CancelDragDrop(Window* window) { | 838 void WindowTreeClient::CancelDragDrop(Window* window) { |
| 683 // Server will clean up drag and fail the in-flight change. | 839 // Server will clean up drag and fail the in-flight change. |
| 684 tree_->CancelDragDrop(window->server_id()); | 840 tree_->CancelDragDrop(WindowMus::Get(window)->server_id()); |
| 685 } | 841 } |
| 686 | 842 |
| 687 void WindowTreeClient::PerformWindowMove( | 843 void WindowTreeClient::PerformWindowMove( |
| 688 Window* window, | 844 Window* window, |
| 689 ui::mojom::MoveLoopSource source, | 845 ui::mojom::MoveLoopSource source, |
| 690 const gfx::Point& cursor_location, | 846 const gfx::Point& cursor_location, |
| 691 const base::Callback<void(bool)>& callback) { | 847 const base::Callback<void(bool)>& callback) { |
| 692 DCHECK(on_current_move_finished_.is_null()); | 848 DCHECK(on_current_move_finished_.is_null()); |
| 693 on_current_move_finished_ = callback; | 849 on_current_move_finished_ = callback; |
| 694 | 850 |
| 851 WindowMus* window_mus = WindowMus::Get(window); |
| 695 current_move_loop_change_ = ScheduleInFlightChange( | 852 current_move_loop_change_ = ScheduleInFlightChange( |
| 696 base::MakeUnique<InFlightDragChange>(window, ChangeType::MOVE_LOOP)); | 853 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); |
| 697 // Tell the window manager to take over moving us. | 854 // Tell the window manager to take over moving us. |
| 698 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), | 855 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), |
| 699 source, cursor_location); | 856 source, cursor_location); |
| 700 } | 857 } |
| 701 | 858 |
| 702 void WindowTreeClient::CancelWindowMove(Window* window) { | 859 void WindowTreeClient::CancelWindowMove(Window* window) { |
| 703 tree_->CancelWindowMove(window->server_id()); | 860 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); |
| 704 } | 861 } |
| 705 | 862 |
| 706 Window* WindowTreeClient::NewWindow( | |
| 707 const Window::SharedProperties* properties) { | |
| 708 return NewWindowImpl(NewWindowType::CHILD, properties); | |
| 709 } | |
| 710 | |
| 711 Window* WindowTreeClient::NewTopLevelWindow( | |
| 712 const Window::SharedProperties* properties) { | |
| 713 Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); | |
| 714 // Assume newly created top level windows are drawn by default, otherwise | |
| 715 // requests to focus will fail. We will get the real value in | |
| 716 // OnTopLevelCreated(). | |
| 717 window->LocalSetParentDrawn(true); | |
| 718 return window; | |
| 719 } | |
| 720 | |
| 721 #if !defined(NDEBUG) | |
| 722 std::string WindowTreeClient::GetDebugWindowHierarchy() const { | |
| 723 std::string result; | |
| 724 for (Window* root : roots_) | |
| 725 BuildDebugInfo(std::string(), root, &result); | |
| 726 return result; | |
| 727 } | |
| 728 | |
| 729 void WindowTreeClient::BuildDebugInfo(const std::string& depth, | |
| 730 Window* window, | |
| 731 std::string* result) const { | |
| 732 std::string name = window->GetName(); | |
| 733 *result += base::StringPrintf( | |
| 734 "%sid=%d visible=%s bounds=%d,%d %dx%d %s\n", depth.c_str(), | |
| 735 window->server_id(), window->visible() ? "true" : "false", | |
| 736 window->bounds().x(), window->bounds().y(), window->bounds().width(), | |
| 737 window->bounds().height(), !name.empty() ? name.c_str() : "(no name)"); | |
| 738 for (Window* child : window->children()) | |
| 739 BuildDebugInfo(depth + " ", child, result); | |
| 740 } | |
| 741 #endif // !defined(NDEBUG) | |
| 742 | |
| 743 //////////////////////////////////////////////////////////////////////////////// | 863 //////////////////////////////////////////////////////////////////////////////// |
| 744 // WindowTreeClient, WindowTreeClient implementation: | 864 // WindowTreeClient, WindowTreeClient implementation: |
| 745 | 865 |
| 746 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { | 866 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
| 747 observers_.AddObserver(observer); | 867 observers_.AddObserver(observer); |
| 748 } | 868 } |
| 749 | 869 |
| 750 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { | 870 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
| 751 observers_.RemoveObserver(observer); | 871 observers_.RemoveObserver(observer); |
| 752 } | 872 } |
| 753 | 873 |
| 754 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { | 874 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { |
| 755 DCHECK(tree_); | 875 DCHECK(tree_); |
| 756 tree_->SetCanAcceptDrops(window_id, can_accept_drops); | 876 tree_->SetCanAcceptDrops(window_id, can_accept_drops); |
| 757 } | 877 } |
| 758 | 878 |
| 759 void WindowTreeClient::SetCanAcceptEvents(Id window_id, | 879 void WindowTreeClient::SetCanAcceptEvents(Id window_id, |
| 760 bool can_accept_events) { | 880 bool can_accept_events) { |
| 761 DCHECK(tree_); | 881 DCHECK(tree_); |
| 762 tree_->SetCanAcceptEvents(window_id, can_accept_events); | 882 tree_->SetCanAcceptEvents(window_id, can_accept_events); |
| 763 } | 883 } |
| 764 | 884 |
| 765 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 885 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| 766 mojom::WindowDataPtr root_data, | 886 ui::mojom::WindowDataPtr root_data, |
| 767 mojom::WindowTreePtr tree, | 887 ui::mojom::WindowTreePtr tree, |
| 768 int64_t display_id, | 888 int64_t display_id, |
| 769 Id focused_window_id, | 889 Id focused_window_id, |
| 770 bool drawn) { | 890 bool drawn) { |
| 771 DCHECK(!tree_ptr_); | 891 DCHECK(!tree_ptr_); |
| 772 tree_ptr_ = std::move(tree); | 892 tree_ptr_ = std::move(tree); |
| 773 | 893 |
| 774 is_from_embed_ = true; | 894 is_from_embed_ = true; |
| 775 | 895 |
| 776 if (window_manager_delegate_) { | 896 if (window_manager_delegate_) { |
| 777 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 897 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 778 tree_ptr_.associated_group())); | 898 tree_ptr_.associated_group())); |
| 779 } | 899 } |
| 780 | 900 |
| 781 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 901 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| 782 focused_window_id, drawn); | 902 focused_window_id, drawn); |
| 783 } | 903 } |
| 784 | 904 |
| 785 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { | 905 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { |
| 786 Window* window = GetWindowByServerId(window_id); | 906 WindowMus* window = GetWindowByServerId(window_id); |
| 787 if (window) { | 907 if (window) |
| 788 for (auto& observer : *WindowPrivate(window).observers()) | 908 window->NotifyEmbeddedAppDisconnected(); |
| 789 observer.OnWindowEmbeddedAppDisconnected(window); | |
| 790 } | |
| 791 } | 909 } |
| 792 | 910 |
| 793 void WindowTreeClient::OnUnembed(Id window_id) { | 911 void WindowTreeClient::OnUnembed(Id window_id) { |
| 794 Window* window = GetWindowByServerId(window_id); | 912 WindowMus* window = GetWindowByServerId(window_id); |
| 795 if (!window) | 913 if (!window) |
| 796 return; | 914 return; |
| 797 | 915 |
| 798 delegate_->OnUnembed(window); | 916 delegate_->OnUnembed(window->GetWindow()); |
| 799 WindowPrivate(window).LocalDestroy(); | 917 delete window; |
| 800 } | 918 } |
| 801 | 919 |
| 802 void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, | 920 void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, |
| 803 Id old_capture_window_id) { | 921 Id old_capture_window_id) { |
| 804 Window* new_capture_window = GetWindowByServerId(new_capture_window_id); | 922 WindowMus* new_capture_window = GetWindowByServerId(new_capture_window_id); |
| 805 Window* lost_capture_window = GetWindowByServerId(old_capture_window_id); | 923 WindowMus* lost_capture_window = GetWindowByServerId(old_capture_window_id); |
| 806 if (!new_capture_window && !lost_capture_window) | 924 if (!new_capture_window && !lost_capture_window) |
| 807 return; | 925 return; |
| 808 | 926 |
| 809 InFlightCaptureChange change(this, new_capture_window); | 927 InFlightCaptureChange change(this, new_capture_window); |
| 810 if (ApplyServerChangeToExistingInFlightChange(change)) | 928 if (ApplyServerChangeToExistingInFlightChange(change)) |
| 811 return; | 929 return; |
| 812 | 930 |
| 813 LocalSetCapture(new_capture_window); | 931 SetCaptureFromServer(new_capture_window); |
| 814 } | 932 } |
| 815 | 933 |
| 816 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, | 934 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| 817 mojom::WindowDataPtr data, | 935 ui::mojom::WindowDataPtr data, |
| 818 int64_t display_id, | 936 int64_t display_id, |
| 819 bool drawn) { | 937 bool drawn) { |
| 820 // The server ack'd the top level window we created and supplied the state | 938 // The server ack'd the top level window we created and supplied the state |
| 821 // of the window at the time the server created it. For properties we do not | 939 // of the window at the time the server created it. For properties we do not |
| 822 // have changes in flight for we can update them immediately. For properties | 940 // have changes in flight for we can update them immediately. For properties |
| 823 // with changes in flight we set the revert value from the server. | 941 // with changes in flight we set the revert value from the server. |
| 824 | 942 |
| 825 if (!in_flight_map_.count(change_id)) { | 943 if (!in_flight_map_.count(change_id)) { |
| 826 // The window may have been destroyed locally before the server could finish | 944 // The window may have been destroyed locally before the server could finish |
| 827 // creating the window, and before the server received the notification that | 945 // creating the window, and before the server received the notification that |
| 828 // the window has been destroyed. | 946 // the window has been destroyed. |
| 829 return; | 947 return; |
| 830 } | 948 } |
| 831 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 949 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 832 in_flight_map_.erase(change_id); | 950 in_flight_map_.erase(change_id); |
| 833 | 951 |
| 834 Window* window = change->window(); | 952 WindowMus* window = change->window(); |
| 835 WindowPrivate window_private(window); | |
| 836 | 953 |
| 954 // TODO: parent drawn and display_id need to route to WindowTreeHost. |
| 837 // Drawn state and display-id always come from the server (they can't be | 955 // Drawn state and display-id always come from the server (they can't be |
| 838 // modified locally). | 956 // modified locally). |
| 839 window_private.LocalSetParentDrawn(drawn); | |
| 840 window_private.LocalSetDisplay(display_id); | |
| 841 | 957 |
| 842 // The default visibilty is false, we only need update visibility if it | 958 // The default visibilty is false, we only need update visibility if it |
| 843 // differs from that. | 959 // differs from that. |
| 844 if (data->visible) { | 960 if (data->visible) { |
| 845 InFlightVisibleChange visible_change(window, data->visible); | 961 InFlightVisibleChange visible_change(window, data->visible); |
| 846 InFlightChange* current_change = | 962 InFlightChange* current_change = |
| 847 GetOldestInFlightChangeMatching(visible_change); | 963 GetOldestInFlightChangeMatching(visible_change); |
| 848 if (current_change) | 964 if (current_change) |
| 849 current_change->SetRevertValueFrom(visible_change); | 965 current_change->SetRevertValueFrom(visible_change); |
| 850 else | 966 else |
| 851 window_private.LocalSetVisible(true); | 967 window->SetVisibleFromServer(true); |
| 852 } | 968 } |
| 853 | 969 |
| 854 const gfx::Rect bounds(data->bounds); | 970 const gfx::Rect bounds(data->bounds); |
| 855 { | 971 { |
| 856 InFlightBoundsChange bounds_change(window, bounds); | 972 InFlightBoundsChange bounds_change(window, bounds); |
| 857 InFlightChange* current_change = | 973 InFlightChange* current_change = |
| 858 GetOldestInFlightChangeMatching(bounds_change); | 974 GetOldestInFlightChangeMatching(bounds_change); |
| 859 if (current_change) | 975 if (current_change) |
| 860 current_change->SetRevertValueFrom(bounds_change); | 976 current_change->SetRevertValueFrom(bounds_change); |
| 861 else if (window->bounds() != bounds) | 977 else if (window->GetWindow()->bounds() != bounds) |
| 862 window_private.LocalSetBounds(window->bounds(), bounds); | 978 window->SetBoundsFromServer(bounds); |
| 863 } | 979 } |
| 864 | 980 |
| 865 // There is currently no API to bulk set properties, so we iterate over each | 981 // There is currently no API to bulk set properties, so we iterate over each |
| 866 // property individually. | 982 // property individually. |
| 867 Window::SharedProperties properties = | 983 std::map<std::string, std::vector<uint8_t>> properties = |
| 868 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 984 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 869 for (const auto& pair : properties) { | 985 for (const auto& pair : properties) { |
| 870 InFlightPropertyChange property_change( | 986 std::unique_ptr<std::vector<uint8_t>> revert_value( |
| 871 window, pair.first, mojo::Array<uint8_t>::From(pair.second)); | 987 base::MakeUnique<std::vector<uint8_t>>(pair.second)); |
| 988 InFlightPropertyChange property_change(window, pair.first, |
| 989 std::move(revert_value)); |
| 872 InFlightChange* current_change = | 990 InFlightChange* current_change = |
| 873 GetOldestInFlightChangeMatching(property_change); | 991 GetOldestInFlightChangeMatching(property_change); |
| 874 if (current_change) | 992 if (current_change) { |
| 875 current_change->SetRevertValueFrom(property_change); | 993 current_change->SetRevertValueFrom(property_change); |
| 876 else | 994 } else { |
| 877 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); | 995 window->SetPropertyFromServer(pair.first, &pair.second); |
| 996 } |
| 878 } | 997 } |
| 879 | 998 |
| 880 // Top level windows should not have a parent. | 999 // Top level windows should not have a parent. |
| 881 DCHECK_EQ(0u, data->parent_id); | 1000 DCHECK_EQ(0u, data->parent_id); |
| 882 } | 1001 } |
| 883 | 1002 |
| 884 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, | 1003 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 885 const gfx::Rect& old_bounds, | 1004 const gfx::Rect& old_bounds, |
| 886 const gfx::Rect& new_bounds) { | 1005 const gfx::Rect& new_bounds) { |
| 887 Window* window = GetWindowByServerId(window_id); | 1006 WindowMus* window = GetWindowByServerId(window_id); |
| 888 if (!window) | 1007 if (!window) |
| 889 return; | 1008 return; |
| 890 | 1009 |
| 891 InFlightBoundsChange new_change(window, new_bounds); | 1010 InFlightBoundsChange new_change(window, new_bounds); |
| 892 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1011 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 893 return; | 1012 return; |
| 894 | 1013 |
| 895 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | 1014 window->SetBoundsFromServer(new_bounds); |
| 896 } | 1015 } |
| 897 | 1016 |
| 898 void WindowTreeClient::OnClientAreaChanged( | 1017 void WindowTreeClient::OnClientAreaChanged( |
| 899 uint32_t window_id, | 1018 uint32_t window_id, |
| 900 const gfx::Insets& new_client_area, | 1019 const gfx::Insets& new_client_area, |
| 901 mojo::Array<gfx::Rect> new_additional_client_areas) { | 1020 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 1021 // TODO: client area. |
| 1022 /* |
| 902 Window* window = GetWindowByServerId(window_id); | 1023 Window* window = GetWindowByServerId(window_id); |
| 903 if (window) { | 1024 if (window) { |
| 904 WindowPrivate(window).LocalSetClientArea( | 1025 WindowPrivate(window).LocalSetClientArea( |
| 905 new_client_area, | 1026 new_client_area, |
| 906 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 1027 new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| 907 } | 1028 } |
| 1029 */ |
| 908 } | 1030 } |
| 909 | 1031 |
| 910 void WindowTreeClient::OnTransientWindowAdded( | 1032 void WindowTreeClient::OnTransientWindowAdded(uint32_t window_id, |
| 911 uint32_t window_id, | 1033 uint32_t transient_window_id) { |
| 912 uint32_t transient_window_id) { | 1034 // TODO: needs to route to StackingClient. |
| 1035 /* |
| 913 Window* window = GetWindowByServerId(window_id); | 1036 Window* window = GetWindowByServerId(window_id); |
| 914 Window* transient_window = GetWindowByServerId(transient_window_id); | 1037 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 915 // window or transient_window or both may be null if a local delete occurs | 1038 // window or transient_window or both may be null if a local delete occurs |
| 916 // with an in flight add from the server. | 1039 // with an in flight add from the server. |
| 917 if (window && transient_window) | 1040 if (window && transient_window) |
| 918 WindowPrivate(window).LocalAddTransientWindow(transient_window); | 1041 WindowPrivate(window).LocalAddTransientWindow(transient_window); |
| 1042 */ |
| 919 } | 1043 } |
| 920 | 1044 |
| 921 void WindowTreeClient::OnTransientWindowRemoved( | 1045 void WindowTreeClient::OnTransientWindowRemoved(uint32_t window_id, |
| 922 uint32_t window_id, | 1046 uint32_t transient_window_id) { |
| 923 uint32_t transient_window_id) { | 1047 // TODO: needs to route to StackingClient. |
| 1048 /* |
| 924 Window* window = GetWindowByServerId(window_id); | 1049 Window* window = GetWindowByServerId(window_id); |
| 925 Window* transient_window = GetWindowByServerId(transient_window_id); | 1050 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 926 // window or transient_window or both may be null if a local delete occurs | 1051 // window or transient_window or both may be null if a local delete occurs |
| 927 // with an in flight delete from the server. | 1052 // with an in flight delete from the server. |
| 928 if (window && transient_window) | 1053 if (window && transient_window) |
| 929 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); | 1054 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); |
| 1055 */ |
| 930 } | 1056 } |
| 931 | 1057 |
| 932 void WindowTreeClient::OnWindowHierarchyChanged( | 1058 void WindowTreeClient::OnWindowHierarchyChanged( |
| 933 Id window_id, | 1059 Id window_id, |
| 934 Id old_parent_id, | 1060 Id old_parent_id, |
| 935 Id new_parent_id, | 1061 Id new_parent_id, |
| 936 mojo::Array<mojom::WindowDataPtr> windows) { | 1062 mojo::Array<ui::mojom::WindowDataPtr> windows) { |
| 937 Window* initial_parent = | 1063 WindowMus* initial_parent = |
| 938 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; | 1064 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : nullptr; |
| 939 | 1065 |
| 940 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; | 1066 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; |
| 941 | 1067 |
| 942 BuildWindowTree(windows, initial_parent); | 1068 BuildWindowTree(windows, initial_parent); |
| 943 | 1069 |
| 944 // If the window was not known, then BuildWindowTree() will have created it | 1070 // If the window was not known, then BuildWindowTree() will have created it |
| 945 // and parented the window. | 1071 // and parented the window. |
| 946 if (!was_window_known) | 1072 if (!was_window_known) |
| 947 return; | 1073 return; |
| 948 | 1074 |
| 949 Window* new_parent = GetWindowByServerId(new_parent_id); | 1075 WindowMus* new_parent = GetWindowByServerId(new_parent_id); |
| 950 Window* old_parent = GetWindowByServerId(old_parent_id); | 1076 WindowMus* old_parent = GetWindowByServerId(old_parent_id); |
| 951 Window* window = GetWindowByServerId(window_id); | 1077 WindowMus* window = GetWindowByServerId(window_id); |
| 952 if (new_parent) | 1078 if (new_parent) |
| 953 WindowPrivate(new_parent).LocalAddChild(window); | 1079 new_parent->AddChildFromServer(window); |
| 954 else | 1080 else |
| 955 WindowPrivate(old_parent).LocalRemoveChild(window); | 1081 old_parent->RemoveChildFromServer(window); |
| 956 } | 1082 } |
| 957 | 1083 |
| 958 void WindowTreeClient::OnWindowReordered(Id window_id, | 1084 void WindowTreeClient::OnWindowReordered(Id window_id, |
| 959 Id relative_window_id, | 1085 Id relative_window_id, |
| 960 mojom::OrderDirection direction) { | 1086 ui::mojom::OrderDirection direction) { |
| 961 Window* window = GetWindowByServerId(window_id); | 1087 WindowMus* window = GetWindowByServerId(window_id); |
| 962 Window* relative_window = GetWindowByServerId(relative_window_id); | 1088 WindowMus* relative_window = GetWindowByServerId(relative_window_id); |
| 963 if (window && relative_window) | 1089 WindowMus* parent = WindowMus::Get(window->GetWindow()->parent()); |
| 964 WindowPrivate(window).LocalReorder(relative_window, direction); | 1090 if (window && relative_window && parent && |
| 1091 parent == WindowMus::Get(relative_window->GetWindow()->parent())) { |
| 1092 parent->ReorderFromServer(window, relative_window, direction); |
| 1093 } |
| 965 } | 1094 } |
| 966 | 1095 |
| 967 void WindowTreeClient::OnWindowDeleted(Id window_id) { | 1096 void WindowTreeClient::OnWindowDeleted(Id window_id) { |
| 968 Window* window = GetWindowByServerId(window_id); | 1097 delete GetWindowByServerId(window_id)->GetWindow(); |
| 969 if (window) | |
| 970 WindowPrivate(window).LocalDestroy(); | |
| 971 } | 1098 } |
| 972 | 1099 |
| 973 Window* WindowTreeClient::GetCaptureWindow() { | 1100 Window* WindowTreeClient::GetCaptureWindow() { |
| 974 return capture_window_; | 1101 return capture_window_ ? capture_window_->GetWindow() : nullptr; |
| 975 } | 1102 } |
| 976 | 1103 |
| 977 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, | 1104 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| 978 bool visible) { | 1105 WindowMus* window = GetWindowByServerId(window_id); |
| 979 Window* window = GetWindowByServerId(window_id); | |
| 980 if (!window) | 1106 if (!window) |
| 981 return; | 1107 return; |
| 982 | 1108 |
| 983 InFlightVisibleChange new_change(window, visible); | 1109 InFlightVisibleChange new_change(window, visible); |
| 984 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1110 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 985 return; | 1111 return; |
| 986 | 1112 |
| 987 WindowPrivate(window).LocalSetVisible(visible); | 1113 window->SetVisibleFromServer(visible); |
| 988 } | 1114 } |
| 989 | 1115 |
| 990 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, | 1116 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| 991 float old_opacity, | 1117 float old_opacity, |
| 992 float new_opacity) { | 1118 float new_opacity) { |
| 993 Window* window = GetWindowByServerId(window_id); | 1119 WindowMus* window = GetWindowByServerId(window_id); |
| 994 if (!window) | 1120 if (!window) |
| 995 return; | 1121 return; |
| 996 | 1122 |
| 997 InFlightOpacityChange new_change(window, new_opacity); | 1123 InFlightOpacityChange new_change(window, new_opacity); |
| 998 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1124 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 999 return; | 1125 return; |
| 1000 | 1126 |
| 1001 WindowPrivate(window).LocalSetOpacity(new_opacity); | 1127 window->SetOpacityFromServer(new_opacity); |
| 1002 } | 1128 } |
| 1003 | 1129 |
| 1004 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, | 1130 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, |
| 1005 bool drawn) { | 1131 bool drawn) { |
| 1132 // TODO: route to WindowTreeHost. |
| 1133 /* |
| 1006 Window* window = GetWindowByServerId(window_id); | 1134 Window* window = GetWindowByServerId(window_id); |
| 1007 if (window) | 1135 if (window) |
| 1008 WindowPrivate(window).LocalSetParentDrawn(drawn); | 1136 WindowPrivate(window).LocalSetParentDrawn(drawn); |
| 1137 */ |
| 1009 } | 1138 } |
| 1010 | 1139 |
| 1011 void WindowTreeClient::OnWindowSharedPropertyChanged( | 1140 void WindowTreeClient::OnWindowSharedPropertyChanged( |
| 1012 Id window_id, | 1141 Id window_id, |
| 1013 const mojo::String& name, | 1142 const mojo::String& name, |
| 1014 mojo::Array<uint8_t> new_data) { | 1143 mojo::Array<uint8_t> transport_data) { |
| 1015 Window* window = GetWindowByServerId(window_id); | 1144 WindowMus* window = GetWindowByServerId(window_id); |
| 1016 if (!window) | 1145 if (!window) |
| 1017 return; | 1146 return; |
| 1018 | 1147 |
| 1019 InFlightPropertyChange new_change(window, name, new_data); | 1148 std::unique_ptr<std::vector<uint8_t>> data; |
| 1149 if (!transport_data.is_null()) { |
| 1150 data = base::MakeUnique<std::vector<uint8_t>>( |
| 1151 transport_data.To<std::vector<uint8_t>>()); |
| 1152 } |
| 1153 InFlightPropertyChange new_change(window, name, std::move(data)); |
| 1020 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1154 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1021 return; | 1155 return; |
| 1022 | 1156 |
| 1023 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 1157 if (!transport_data.is_null()) { |
| 1158 data = base::MakeUnique<std::vector<uint8_t>>( |
| 1159 transport_data.To<std::vector<uint8_t>>()); |
| 1160 } |
| 1161 window->SetPropertyFromServer(name, data.get()); |
| 1024 } | 1162 } |
| 1025 | 1163 |
| 1026 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1164 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| 1027 Id window_id, | 1165 Id window_id, |
| 1028 std::unique_ptr<ui::Event> event, | 1166 std::unique_ptr<ui::Event> event, |
| 1029 bool matches_pointer_watcher) { | 1167 bool matches_pointer_watcher) { |
| 1030 DCHECK(event); | 1168 DCHECK(event); |
| 1031 Window* window = GetWindowByServerId(window_id); // May be null. | 1169 |
| 1170 WindowMus* window = GetWindowByServerId(window_id); // May be null. |
| 1171 |
| 1172 if (event->IsKeyEvent()) { |
| 1173 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| 1174 if (!window || !window->GetWindow()->GetHost()) { |
| 1175 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| 1176 return; |
| 1177 } |
| 1178 InputMethodMus* input_method = |
| 1179 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()) |
| 1180 ->input_method(); |
| 1181 input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| 1182 CreateEventResultCallback(event_id)); |
| 1183 return; |
| 1184 } |
| 1032 | 1185 |
| 1033 if (matches_pointer_watcher && has_pointer_watcher_) { | 1186 if (matches_pointer_watcher && has_pointer_watcher_) { |
| 1034 DCHECK(event->IsPointerEvent()); | 1187 DCHECK(event->IsPointerEvent()); |
| 1035 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), window); | 1188 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), |
| 1189 window ? window->GetWindow() : nullptr); |
| 1036 } | 1190 } |
| 1037 | 1191 |
| 1038 if (!window || !window->input_event_handler_) { | 1192 // TODO: deal with no window or host here. This could happen if during |
| 1039 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); | 1193 // dispatch a window is deleted or moved. In either case we still need to |
| 1194 // dispatch. Most likely need the display id. |
| 1195 if (!window || !window->GetWindow()->GetHost()) { |
| 1196 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| 1040 return; | 1197 return; |
| 1041 } | 1198 } |
| 1042 | 1199 |
| 1043 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( | 1200 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| 1044 new base::Callback<void(mojom::EventResult)>( | 1201 WindowTreeHostMus* host = |
| 1045 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, | 1202 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()); |
| 1046 base::Unretained(tree_), event_id))); | |
| 1047 | |
| 1048 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or | 1203 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| 1049 // ui::TouchEvent once we have proper support for pointer events. | 1204 // ui::TouchEvent once we have proper support for pointer events. |
| 1050 if (event->IsMousePointerEvent()) { | 1205 if (event->IsMousePointerEvent()) { |
| 1051 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1206 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| 1052 window->input_event_handler_->OnWindowInputEvent( | 1207 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| 1053 window, ui::MouseWheelEvent(*event->AsPointerEvent()), &ack_callback); | 1208 host->SendEventToProcessor(&mapped_event); |
| 1054 } else { | 1209 } else { |
| 1055 window->input_event_handler_->OnWindowInputEvent( | 1210 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| 1056 window, ui::MouseEvent(*event->AsPointerEvent()), &ack_callback); | 1211 host->SendEventToProcessor(&mapped_event); |
| 1057 } | 1212 } |
| 1058 } else if (event->IsTouchPointerEvent()) { | 1213 } else if (event->IsTouchPointerEvent()) { |
| 1059 window->input_event_handler_->OnWindowInputEvent( | 1214 ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
| 1060 window, ui::TouchEvent(*event->AsPointerEvent()), &ack_callback); | 1215 host->SendEventToProcessor(&mapped_event); |
| 1061 } else { | 1216 } else { |
| 1062 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), | 1217 host->SendEventToProcessor(event.get()); |
| 1063 &ack_callback); | |
| 1064 } | 1218 } |
| 1065 | 1219 ack_handler.set_handled(event->handled()); |
| 1066 // The handler did not take ownership of the callback, so we send the ack, | |
| 1067 // marking the event as not consumed. | |
| 1068 if (ack_callback) | |
| 1069 ack_callback->Run(mojom::EventResult::UNHANDLED); | |
| 1070 } | 1220 } |
| 1071 | 1221 |
| 1072 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, | 1222 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
| 1073 uint32_t window_id) { | 1223 uint32_t window_id) { |
| 1074 DCHECK(event); | 1224 DCHECK(event); |
| 1075 DCHECK(event->IsPointerEvent()); | 1225 DCHECK(event->IsPointerEvent()); |
| 1076 if (has_pointer_watcher_) { | 1226 if (!has_pointer_watcher_) |
| 1077 Window* target_window = GetWindowByServerId(window_id); | 1227 return; |
| 1078 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), target_window); | 1228 |
| 1079 } | 1229 WindowMus* target_window = GetWindowByServerId(window_id); |
| 1230 delegate_->OnPointerEventObserved( |
| 1231 *event->AsPointerEvent(), |
| 1232 target_window ? target_window->GetWindow() : nullptr); |
| 1080 } | 1233 } |
| 1081 | 1234 |
| 1082 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { | 1235 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
| 1083 Window* focused_window = GetWindowByServerId(focused_window_id); | 1236 WindowMus* focused_window = GetWindowByServerId(focused_window_id); |
| 1084 InFlightFocusChange new_change(this, focused_window); | 1237 InFlightFocusChange new_change(this, focused_window); |
| 1085 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1238 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1086 return; | 1239 return; |
| 1087 | 1240 |
| 1088 LocalSetFocus(focused_window); | 1241 SetFocusFromServer(focused_window); |
| 1089 } | 1242 } |
| 1090 | 1243 |
| 1091 void WindowTreeClient::OnWindowPredefinedCursorChanged( | 1244 void WindowTreeClient::OnWindowPredefinedCursorChanged( |
| 1092 Id window_id, | 1245 Id window_id, |
| 1093 mojom::Cursor cursor) { | 1246 ui::mojom::Cursor cursor) { |
| 1094 Window* window = GetWindowByServerId(window_id); | 1247 WindowMus* window = GetWindowByServerId(window_id); |
| 1095 if (!window) | 1248 if (!window) |
| 1096 return; | 1249 return; |
| 1097 | 1250 |
| 1098 InFlightPredefinedCursorChange new_change(window, cursor); | 1251 InFlightPredefinedCursorChange new_change(window, cursor); |
| 1099 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1252 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1100 return; | 1253 return; |
| 1101 | 1254 |
| 1102 WindowPrivate(window).LocalSetPredefinedCursor(cursor); | 1255 window->SetPredefinedCursorFromServer(cursor); |
| 1103 } | 1256 } |
| 1104 | 1257 |
| 1105 void WindowTreeClient::OnWindowSurfaceChanged( | 1258 void WindowTreeClient::OnWindowSurfaceChanged( |
| 1106 Id window_id, | 1259 Id window_id, |
| 1107 const cc::SurfaceId& surface_id, | 1260 const cc::SurfaceId& surface_id, |
| 1108 const cc::SurfaceSequence& surface_sequence, | 1261 const cc::SurfaceSequence& surface_sequence, |
| 1109 const gfx::Size& frame_size, | 1262 const gfx::Size& frame_size, |
| 1110 float device_scale_factor) { | 1263 float device_scale_factor) { |
| 1111 Window* window = GetWindowByServerId(window_id); | 1264 WindowMus* window = GetWindowByServerId(window_id); |
| 1112 if (!window) | 1265 if (!window) |
| 1113 return; | 1266 return; |
| 1114 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); | 1267 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); |
| 1115 surface_info->surface_id = surface_id; | 1268 surface_info->surface_id = surface_id; |
| 1116 surface_info->surface_sequence = surface_sequence; | 1269 surface_info->surface_sequence = surface_sequence; |
| 1117 surface_info->frame_size = frame_size; | 1270 surface_info->frame_size = frame_size; |
| 1118 surface_info->device_scale_factor = device_scale_factor; | 1271 surface_info->device_scale_factor = device_scale_factor; |
| 1119 WindowPrivate(window).LocalSetSurfaceId(std::move(surface_info)); | 1272 window->SetSurfaceIdFromServer(std::move(surface_info)); |
| 1120 } | 1273 } |
| 1121 | 1274 |
| 1122 void WindowTreeClient::OnDragDropStart( | 1275 void WindowTreeClient::OnDragDropStart( |
| 1123 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { | 1276 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { |
| 1124 mime_drag_data_ = std::move(mime_data); | 1277 mime_drag_data_ = std::move(mime_data); |
| 1125 } | 1278 } |
| 1126 | 1279 |
| 1127 void WindowTreeClient::OnDragEnter(Id window_id, | 1280 void WindowTreeClient::OnDragEnter(Id window_id, |
| 1128 uint32_t key_state, | 1281 uint32_t key_state, |
| 1129 const gfx::Point& position, | 1282 const gfx::Point& position, |
| 1130 uint32_t effect_bitmask, | 1283 uint32_t effect_bitmask, |
| 1131 const OnDragEnterCallback& callback) { | 1284 const OnDragEnterCallback& callback) { |
| 1285 // TODO: dnd. |
| 1286 /* |
| 1132 Window* window = GetWindowByServerId(window_id); | 1287 Window* window = GetWindowByServerId(window_id); |
| 1133 if (!window || !window->drop_target()) { | 1288 if (!window || !window->drop_target()) { |
| 1134 callback.Run(mojom::kDropEffectNone); | 1289 callback.Run(ui::mojom::kDropEffectNone); |
| 1135 return; | 1290 return; |
| 1136 } | 1291 } |
| 1137 | 1292 |
| 1138 if (!base::ContainsKey(drag_entered_windows_, window_id)) { | 1293 if (!base::ContainsKey(drag_entered_windows_, window_id)) { |
| 1139 window->drop_target()->OnDragDropStart( | 1294 window->drop_target()->OnDragDropStart( |
| 1140 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>()); | 1295 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>()); |
| 1141 drag_entered_windows_.insert(window_id); | 1296 drag_entered_windows_.insert(window_id); |
| 1142 } | 1297 } |
| 1143 | 1298 |
| 1144 uint32_t ret = | 1299 uint32_t ret = |
| 1145 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); | 1300 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); |
| 1146 callback.Run(ret); | 1301 callback.Run(ret); |
| 1302 */ |
| 1147 } | 1303 } |
| 1148 | 1304 |
| 1149 void WindowTreeClient::OnDragOver(Id window_id, | 1305 void WindowTreeClient::OnDragOver(Id window_id, |
| 1150 uint32_t key_state, | 1306 uint32_t key_state, |
| 1151 const gfx::Point& position, | 1307 const gfx::Point& position, |
| 1152 uint32_t effect_bitmask, | 1308 uint32_t effect_bitmask, |
| 1153 const OnDragOverCallback& callback) { | 1309 const OnDragOverCallback& callback) { |
| 1310 // TODO: dnd. |
| 1311 /* |
| 1154 Window* window = GetWindowByServerId(window_id); | 1312 Window* window = GetWindowByServerId(window_id); |
| 1155 if (!window || !window->drop_target()) { | 1313 if (!window || !window->drop_target()) { |
| 1156 callback.Run(mojom::kDropEffectNone); | 1314 callback.Run(ui::mojom::kDropEffectNone); |
| 1157 return; | 1315 return; |
| 1158 } | 1316 } |
| 1159 | 1317 |
| 1160 uint32_t ret = | 1318 uint32_t ret = |
| 1161 window->drop_target()->OnDragOver(key_state, position, effect_bitmask); | 1319 window->drop_target()->OnDragOver(key_state, position, effect_bitmask); |
| 1162 callback.Run(ret); | 1320 callback.Run(ret); |
| 1321 */ |
| 1163 } | 1322 } |
| 1164 | 1323 |
| 1165 void WindowTreeClient::OnDragLeave(Id window_id) { | 1324 void WindowTreeClient::OnDragLeave(Id window_id) { |
| 1325 // TODO: dnd. |
| 1326 /* |
| 1166 Window* window = GetWindowByServerId(window_id); | 1327 Window* window = GetWindowByServerId(window_id); |
| 1167 if (!window || !window->drop_target()) | 1328 if (!window || !window->drop_target()) |
| 1168 return; | 1329 return; |
| 1169 | 1330 |
| 1170 window->drop_target()->OnDragLeave(); | 1331 window->drop_target()->OnDragLeave(); |
| 1332 */ |
| 1171 } | 1333 } |
| 1172 | 1334 |
| 1173 void WindowTreeClient::OnDragDropDone() { | 1335 void WindowTreeClient::OnDragDropDone() { |
| 1336 // TODO: dnd. |
| 1337 /* |
| 1174 for (Id id : drag_entered_windows_) { | 1338 for (Id id : drag_entered_windows_) { |
| 1175 Window* window = GetWindowByServerId(id); | 1339 Window* window = GetWindowByServerId(id); |
| 1176 if (!window || !window->drop_target()) | 1340 if (!window || !window->drop_target()) |
| 1177 continue; | 1341 continue; |
| 1178 window->drop_target()->OnDragDropDone(); | 1342 window->drop_target()->OnDragDropDone(); |
| 1179 } | 1343 } |
| 1180 drag_entered_windows_.clear(); | 1344 drag_entered_windows_.clear(); |
| 1345 */ |
| 1181 } | 1346 } |
| 1182 | 1347 |
| 1183 void WindowTreeClient::OnCompleteDrop(Id window_id, | 1348 void WindowTreeClient::OnCompleteDrop(Id window_id, |
| 1184 uint32_t key_state, | 1349 uint32_t key_state, |
| 1185 const gfx::Point& position, | 1350 const gfx::Point& position, |
| 1186 uint32_t effect_bitmask, | 1351 uint32_t effect_bitmask, |
| 1187 const OnCompleteDropCallback& callback) { | 1352 const OnCompleteDropCallback& callback) { |
| 1353 // TODO: dnd. |
| 1354 /* |
| 1188 Window* window = GetWindowByServerId(window_id); | 1355 Window* window = GetWindowByServerId(window_id); |
| 1189 if (!window || !window->drop_target()) { | 1356 if (!window || !window->drop_target()) { |
| 1190 callback.Run(mojom::kDropEffectNone); | 1357 callback.Run(ui::mojom::kDropEffectNone); |
| 1191 return; | 1358 return; |
| 1192 } | 1359 } |
| 1193 | 1360 |
| 1194 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, | 1361 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, |
| 1195 effect_bitmask); | 1362 effect_bitmask); |
| 1196 callback.Run(ret); | 1363 callback.Run(ret); |
| 1364 */ |
| 1197 } | 1365 } |
| 1198 | 1366 |
| 1199 void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, | 1367 void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, |
| 1200 bool success, | 1368 bool success, |
| 1201 uint32_t action_taken) { | 1369 uint32_t action_taken) { |
| 1370 // TODO: dnd. |
| 1371 /* |
| 1202 if (current_drag_state_ && change_id == current_drag_state_->change_id) { | 1372 if (current_drag_state_ && change_id == current_drag_state_->change_id) { |
| 1203 current_drag_state_->completed_action = action_taken; | 1373 current_drag_state_->completed_action = action_taken; |
| 1204 OnChangeCompleted(change_id, success); | 1374 OnChangeCompleted(change_id, success); |
| 1205 } | 1375 } |
| 1376 */ |
| 1206 } | 1377 } |
| 1207 | 1378 |
| 1208 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { | 1379 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| 1209 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1380 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 1210 in_flight_map_.erase(change_id); | 1381 in_flight_map_.erase(change_id); |
| 1211 if (!change) | 1382 if (!change) |
| 1212 return; | 1383 return; |
| 1213 | 1384 |
| 1214 if (!success) | 1385 if (!success) |
| 1215 change->ChangeFailed(); | 1386 change->ChangeFailed(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1233 | 1404 |
| 1234 current_drag_state_->on_finished.Run(success, | 1405 current_drag_state_->on_finished.Run(success, |
| 1235 current_drag_state_->completed_action); | 1406 current_drag_state_->completed_action); |
| 1236 current_drag_state_.reset(); | 1407 current_drag_state_.reset(); |
| 1237 } | 1408 } |
| 1238 } | 1409 } |
| 1239 | 1410 |
| 1240 void WindowTreeClient::GetWindowManager( | 1411 void WindowTreeClient::GetWindowManager( |
| 1241 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1412 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| 1242 window_manager_internal_.reset( | 1413 window_manager_internal_.reset( |
| 1243 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1414 new mojo::AssociatedBinding<ui::mojom::WindowManager>( |
| 1244 std::move(internal))); | 1415 this, std::move(internal))); |
| 1245 } | 1416 } |
| 1246 | 1417 |
| 1247 void WindowTreeClient::RequestClose(uint32_t window_id) { | 1418 void WindowTreeClient::RequestClose(uint32_t window_id) { |
| 1248 Window* window = GetWindowByServerId(window_id); | 1419 WindowMus* window = GetWindowByServerId(window_id); |
| 1249 if (!window || !IsRoot(window)) | 1420 if (!window || !IsRoot(window)) |
| 1250 return; | 1421 return; |
| 1251 | 1422 |
| 1252 for (auto& observer : *WindowPrivate(window).observers()) | 1423 window->GetWindow()->delegate()->OnRequestClose(); |
| 1253 observer.OnRequestClose(window); | |
| 1254 } | 1424 } |
| 1255 | 1425 |
| 1256 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { | 1426 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| 1257 client_id_ = client_id; | 1427 client_id_ = client_id; |
| 1258 } | 1428 } |
| 1259 | 1429 |
| 1260 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1430 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
| 1261 mojom::WindowDataPtr root_data, | 1431 ui::mojom::WindowDataPtr root_data, |
| 1262 bool parent_drawn) { | 1432 bool parent_drawn) { |
| 1263 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1433 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
| 1264 } | 1434 } |
| 1265 | 1435 |
| 1266 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1436 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
| 1267 DCHECK(window_manager_delegate_); | 1437 DCHECK(window_manager_delegate_); |
| 1268 | 1438 // TODO: route to WindowTreeHost. |
| 1439 /* |
| 1269 for (Window* root : roots_) { | 1440 for (Window* root : roots_) { |
| 1270 if (root->display_id() == display_id) { | 1441 if (root->display_id() == display_id) { |
| 1271 window_manager_delegate_->OnWmDisplayRemoved(root); | 1442 window_manager_delegate_->OnWmDisplayRemoved(root); |
| 1272 return; | 1443 return; |
| 1273 } | 1444 } |
| 1274 } | 1445 } |
| 1446 */ |
| 1275 } | 1447 } |
| 1276 | 1448 |
| 1277 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1449 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1278 DCHECK(window_manager_delegate_); | 1450 DCHECK(window_manager_delegate_); |
| 1451 // TODO(sky): this should likely route to WindowTreeHost. |
| 1279 window_manager_delegate_->OnWmDisplayModified(display); | 1452 window_manager_delegate_->OnWmDisplayModified(display); |
| 1280 } | 1453 } |
| 1281 | 1454 |
| 1282 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1455 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1283 Id window_id, | 1456 Id window_id, |
| 1284 const gfx::Rect& transit_bounds) { | 1457 const gfx::Rect& transit_bounds) { |
| 1285 Window* window = GetWindowByServerId(window_id); | 1458 WindowMus* window = GetWindowByServerId(window_id); |
| 1286 bool result = false; | 1459 bool result = false; |
| 1287 if (window) { | 1460 if (window) { |
| 1288 DCHECK(window_manager_delegate_); | 1461 DCHECK(window_manager_delegate_); |
| 1289 gfx::Rect bounds = transit_bounds; | 1462 gfx::Rect bounds = transit_bounds; |
| 1290 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); | 1463 // TODO: this needs to trigger scheduling a bounds change on |window|. |
| 1464 result = |
| 1465 window_manager_delegate_->OnWmSetBounds(window->GetWindow(), &bounds); |
| 1291 if (result) { | 1466 if (result) { |
| 1292 // If the resulting bounds differ return false. Returning false ensures | 1467 // If the resulting bounds differ return false. Returning false ensures |
| 1293 // the client applies the bounds we set below. | 1468 // the client applies the bounds we set below. |
| 1294 result = bounds == transit_bounds; | 1469 result = bounds == transit_bounds; |
| 1295 window->SetBounds(bounds); | 1470 window->SetBoundsFromServer(bounds); |
| 1296 } | 1471 } |
| 1297 } | 1472 } |
| 1298 if (window_manager_internal_client_) | 1473 if (window_manager_internal_client_) |
| 1299 window_manager_internal_client_->WmResponse(change_id, result); | 1474 window_manager_internal_client_->WmResponse(change_id, result); |
| 1300 } | 1475 } |
| 1301 | 1476 |
| 1302 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1477 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1303 Id window_id, | 1478 Id window_id, |
| 1304 const mojo::String& name, | 1479 const mojo::String& name, |
| 1305 mojo::Array<uint8_t> transit_data) { | 1480 mojo::Array<uint8_t> transit_data) { |
| 1306 Window* window = GetWindowByServerId(window_id); | 1481 WindowMus* window = GetWindowByServerId(window_id); |
| 1307 bool result = false; | 1482 bool result = false; |
| 1308 if (window) { | 1483 if (window) { |
| 1484 // TODO: map properties. |
| 1309 DCHECK(window_manager_delegate_); | 1485 DCHECK(window_manager_delegate_); |
| 1310 std::unique_ptr<std::vector<uint8_t>> data; | 1486 std::unique_ptr<std::vector<uint8_t>> data; |
| 1311 if (!transit_data.is_null()) { | 1487 if (!transit_data.is_null()) { |
| 1312 data.reset( | 1488 data.reset( |
| 1313 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); | 1489 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); |
| 1314 } | 1490 } |
| 1315 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); | 1491 result = window_manager_delegate_->OnWmSetProperty(window->GetWindow(), |
| 1492 name, &data); |
| 1316 if (result) { | 1493 if (result) { |
| 1317 // If the resulting bounds differ return false. Returning false ensures | 1494 delegate_->GetPropertyConverter()->SetPropertyFromTransportValue( |
| 1318 // the client applies the bounds we set below. | 1495 window->GetWindow(), name, data.get()); |
| 1319 window->SetSharedPropertyInternal(name, data.get()); | |
| 1320 } | 1496 } |
| 1321 } | 1497 } |
| 1322 if (window_manager_internal_client_) | 1498 if (window_manager_internal_client_) |
| 1323 window_manager_internal_client_->WmResponse(change_id, result); | 1499 window_manager_internal_client_->WmResponse(change_id, result); |
| 1324 } | 1500 } |
| 1325 | 1501 |
| 1326 void WindowTreeClient::WmCreateTopLevelWindow( | 1502 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1327 uint32_t change_id, | 1503 uint32_t change_id, |
| 1328 ClientSpecificId requesting_client_id, | 1504 ClientSpecificId requesting_client_id, |
| 1329 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1505 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 1330 std::map<std::string, std::vector<uint8_t>> properties = | 1506 std::map<std::string, std::vector<uint8_t>> properties = |
| 1331 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1507 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 1332 Window* window = | 1508 Window* window = |
| 1333 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1509 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); |
| 1334 embedded_windows_[requesting_client_id].insert(window); | 1510 embedded_windows_[requesting_client_id].insert(window); |
| 1335 if (window_manager_internal_client_) { | 1511 if (window_manager_internal_client_) { |
| 1336 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1512 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1337 change_id, server_id(window)); | 1513 change_id, WindowMus::Get(window)->server_id()); |
| 1338 } | 1514 } |
| 1339 } | 1515 } |
| 1340 | 1516 |
| 1341 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1517 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1342 bool janky) { | 1518 bool janky) { |
| 1343 if (window_manager_delegate_) { | 1519 if (window_manager_delegate_) { |
| 1344 auto it = embedded_windows_.find(client_id); | 1520 auto it = embedded_windows_.find(client_id); |
| 1345 CHECK(it != embedded_windows_.end()); | 1521 CHECK(it != embedded_windows_.end()); |
| 1346 window_manager_delegate_->OnWmClientJankinessChanged( | 1522 window_manager_delegate_->OnWmClientJankinessChanged( |
| 1347 embedded_windows_[client_id], janky); | 1523 embedded_windows_[client_id], janky); |
| 1348 } | 1524 } |
| 1349 } | 1525 } |
| 1350 | 1526 |
| 1351 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, | 1527 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, |
| 1352 Id window_id, | 1528 Id window_id, |
| 1353 mojom::MoveLoopSource source, | 1529 ui::mojom::MoveLoopSource source, |
| 1354 const gfx::Point& cursor_location) { | 1530 const gfx::Point& cursor_location) { |
| 1355 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) { | 1531 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) { |
| 1356 OnWmMoveLoopCompleted(change_id, false); | 1532 OnWmMoveLoopCompleted(change_id, false); |
| 1357 return; | 1533 return; |
| 1358 } | 1534 } |
| 1359 | 1535 |
| 1360 current_wm_move_loop_change_ = change_id; | 1536 current_wm_move_loop_change_ = change_id; |
| 1361 current_wm_move_loop_window_id_ = window_id; | 1537 current_wm_move_loop_window_id_ = window_id; |
| 1362 Window* window = GetWindowByServerId(window_id); | 1538 WindowMus* window = GetWindowByServerId(window_id); |
| 1363 if (window) { | 1539 if (window) { |
| 1364 window_manager_delegate_->OnWmPerformMoveLoop( | 1540 window_manager_delegate_->OnWmPerformMoveLoop( |
| 1365 window, source, cursor_location, | 1541 window->GetWindow(), source, cursor_location, |
| 1366 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted, | 1542 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted, |
| 1367 weak_factory_.GetWeakPtr(), change_id)); | 1543 weak_factory_.GetWeakPtr(), change_id)); |
| 1368 } else { | 1544 } else { |
| 1369 OnWmMoveLoopCompleted(change_id, false); | 1545 OnWmMoveLoopCompleted(change_id, false); |
| 1370 } | 1546 } |
| 1371 } | 1547 } |
| 1372 | 1548 |
| 1373 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) { | 1549 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) { |
| 1374 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_) | 1550 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_) |
| 1375 return; | 1551 return; |
| 1376 | 1552 |
| 1377 Window* window = GetWindowByServerId(current_wm_move_loop_window_id_); | 1553 WindowMus* window = GetWindowByServerId(current_wm_move_loop_window_id_); |
| 1378 if (window) | 1554 if (window) |
| 1379 window_manager_delegate_->OnWmCancelMoveLoop(window); | 1555 window_manager_delegate_->OnWmCancelMoveLoop(window->GetWindow()); |
| 1380 } | 1556 } |
| 1381 | 1557 |
| 1382 void WindowTreeClient::OnAccelerator(uint32_t ack_id, | 1558 void WindowTreeClient::OnAccelerator(uint32_t ack_id, |
| 1383 uint32_t accelerator_id, | 1559 uint32_t accelerator_id, |
| 1384 std::unique_ptr<ui::Event> event) { | 1560 std::unique_ptr<ui::Event> event) { |
| 1385 DCHECK(event); | 1561 DCHECK(event); |
| 1386 const mojom::EventResult result = | 1562 const ui::mojom::EventResult result = |
| 1387 window_manager_delegate_->OnAccelerator(accelerator_id, *event.get()); | 1563 window_manager_delegate_->OnAccelerator(accelerator_id, *event.get()); |
| 1388 if (ack_id && window_manager_internal_client_) | 1564 if (ack_id && window_manager_internal_client_) |
| 1389 window_manager_internal_client_->OnAcceleratorAck(ack_id, result); | 1565 window_manager_internal_client_->OnAcceleratorAck(ack_id, result); |
| 1390 } | 1566 } |
| 1391 | 1567 |
| 1392 void WindowTreeClient::SetFrameDecorationValues( | 1568 void WindowTreeClient::SetFrameDecorationValues( |
| 1393 mojom::FrameDecorationValuesPtr values) { | 1569 ui::mojom::FrameDecorationValuesPtr values) { |
| 1394 if (window_manager_internal_client_) { | 1570 if (window_manager_internal_client_) { |
| 1395 window_manager_internal_client_->WmSetFrameDecorationValues( | 1571 window_manager_internal_client_->WmSetFrameDecorationValues( |
| 1396 std::move(values)); | 1572 std::move(values)); |
| 1397 } | 1573 } |
| 1398 } | 1574 } |
| 1399 | 1575 |
| 1400 void WindowTreeClient::SetNonClientCursor(Window* window, | 1576 void WindowTreeClient::SetNonClientCursor(Window* window, |
| 1401 ui::mojom::Cursor cursor_id) { | 1577 ui::mojom::Cursor cursor_id) { |
| 1402 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), | 1578 window_manager_internal_client_->WmSetNonClientCursor( |
| 1403 cursor_id); | 1579 WindowMus::Get(window)->server_id(), cursor_id); |
| 1404 } | 1580 } |
| 1405 | 1581 |
| 1406 void WindowTreeClient::AddAccelerator( | 1582 void WindowTreeClient::AddAccelerator( |
| 1407 uint32_t id, | 1583 uint32_t id, |
| 1408 mojom::EventMatcherPtr event_matcher, | 1584 ui::mojom::EventMatcherPtr event_matcher, |
| 1409 const base::Callback<void(bool)>& callback) { | 1585 const base::Callback<void(bool)>& callback) { |
| 1410 if (window_manager_internal_client_) { | 1586 if (window_manager_internal_client_) { |
| 1411 window_manager_internal_client_->AddAccelerator( | 1587 window_manager_internal_client_->AddAccelerator( |
| 1412 id, std::move(event_matcher), callback); | 1588 id, std::move(event_matcher), callback); |
| 1413 } | 1589 } |
| 1414 } | 1590 } |
| 1415 | 1591 |
| 1416 void WindowTreeClient::RemoveAccelerator(uint32_t id) { | 1592 void WindowTreeClient::RemoveAccelerator(uint32_t id) { |
| 1417 if (window_manager_internal_client_) { | 1593 if (window_manager_internal_client_) { |
| 1418 window_manager_internal_client_->RemoveAccelerator(id); | 1594 window_manager_internal_client_->RemoveAccelerator(id); |
| 1419 } | 1595 } |
| 1420 } | 1596 } |
| 1421 | 1597 |
| 1422 void WindowTreeClient::AddActivationParent(Window* window) { | 1598 void WindowTreeClient::AddActivationParent(Window* window) { |
| 1423 if (window_manager_internal_client_) | 1599 if (window_manager_internal_client_) { |
| 1424 window_manager_internal_client_->AddActivationParent(server_id(window)); | 1600 window_manager_internal_client_->AddActivationParent( |
| 1601 WindowMus::Get(window)->server_id()); |
| 1602 } |
| 1425 } | 1603 } |
| 1426 | 1604 |
| 1427 void WindowTreeClient::RemoveActivationParent(Window* window) { | 1605 void WindowTreeClient::RemoveActivationParent(Window* window) { |
| 1428 if (window_manager_internal_client_) | 1606 if (window_manager_internal_client_) { |
| 1429 window_manager_internal_client_->RemoveActivationParent(server_id(window)); | 1607 window_manager_internal_client_->RemoveActivationParent( |
| 1608 WindowMus::Get(window)->server_id()); |
| 1609 } |
| 1430 } | 1610 } |
| 1431 | 1611 |
| 1432 void WindowTreeClient::ActivateNextWindow() { | 1612 void WindowTreeClient::ActivateNextWindow() { |
| 1433 if (window_manager_internal_client_) | 1613 if (window_manager_internal_client_) |
| 1434 window_manager_internal_client_->ActivateNextWindow(); | 1614 window_manager_internal_client_->ActivateNextWindow(); |
| 1435 } | 1615 } |
| 1436 | 1616 |
| 1437 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1617 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1438 Window* window, | 1618 Window* window, |
| 1439 const gfx::Vector2d& offset, | 1619 const gfx::Vector2d& offset, |
| 1440 const gfx::Insets& hit_area) { | 1620 const gfx::Insets& hit_area) { |
| 1441 if (window_manager_internal_client_) { | 1621 if (window_manager_internal_client_) { |
| 1442 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1622 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1443 server_id(window), offset.x(), offset.y(), hit_area); | 1623 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); |
| 1444 } | 1624 } |
| 1445 } | 1625 } |
| 1446 | 1626 |
| 1447 } // namespace ui | 1627 void WindowTreeClient::OnWindowFocused(Window* gained_focus, |
| 1628 Window* lost_focus) { |
| 1629 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| 1630 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| 1631 focused_window_ = gained_focus_mus; |
| 1632 return; |
| 1633 } |
| 1634 |
| 1635 const uint32_t change_id = ScheduleInFlightChange( |
| 1636 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); |
| 1637 focused_window_ = gained_focus_mus; |
| 1638 tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() |
| 1639 : kInvalidServerId); |
| 1640 } |
| 1641 |
| 1642 void WindowTreeClient::OnCaptureChanged(Window* lost_capture, |
| 1643 Window* gained_capture) { |
| 1644 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture); |
| 1645 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) { |
| 1646 capture_window_ = gained_capture_mus; |
| 1647 return; |
| 1648 } |
| 1649 |
| 1650 const uint32_t change_id = ScheduleInFlightChange( |
| 1651 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| 1652 WindowMus* old_capture_window = capture_window_; |
| 1653 capture_window_ = gained_capture_mus; |
| 1654 if (capture_window_) |
| 1655 tree_->SetCapture(change_id, capture_window_->server_id()); |
| 1656 else |
| 1657 tree_->ReleaseCapture(change_id, old_capture_window->server_id()); |
| 1658 } |
| 1659 |
| 1660 } // namespace aura |
| OLD | NEW |