Chromium Code Reviews| 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() |
|
sadrul
2016/10/26 18:38:20
What are the chances that canceling the capture en
sky
2016/10/26 19:56:45
I think very slim. It would be similar to aura::En
| |
| 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 // TODO: LAYER_NOT_DRAWN may be wrong here. | |
| 445 user_window->Init(ui::LAYER_NOT_DRAWN); | |
|
sadrul
2016/10/26 18:38:20
Yeah, this will almost definitely need to be LAYER
sky
2016/10/26 19:56:45
Changed.
| |
| 446 new WindowTreeHostMus(nullptr, user_window); | |
| 447 break; | |
| 448 } | |
| 449 case WindowTreeHostType::TOP_LEVEL: { | |
| 450 DCHECK(content_window); | |
| 451 user_window = content_window; | |
| 452 new WindowTreeHostMus(nullptr, user_window); | |
| 453 break; | |
| 454 } | |
| 455 } | |
| 456 WindowMus* user_window_mus = WindowMus::Get(user_window); | |
| 457 roots_.insert(user_window_mus); | |
| 458 if (!window_data.is_null()) | |
| 459 SetLocalPropertiesFromServerProperties(user_window_mus, window_data); | |
| 460 return user_window; | |
| 461 } | |
| 462 | |
| 463 WindowMus* WindowTreeClient::NewWindowFromWindowData( | |
| 464 WindowMus* parent, | |
| 465 const ui::mojom::WindowDataPtr& window_data) { | |
| 466 std::unique_ptr<WindowPortMus> window_port_mus( | |
| 467 CreateWindowPortMus(window_data)); | |
| 468 WindowPortMus* window_port_mus_ptr = window_port_mus.get(); | |
| 469 Window* window = new Window(nullptr, std::move(window_port_mus)); | |
| 470 WindowMus* window_mus = window_port_mus_ptr; | |
| 471 window->Init(ui::LAYER_NOT_DRAWN); | |
| 472 SetLocalPropertiesFromServerProperties(window_mus, window_data); | |
| 473 window_mus->SetBoundsFromServer(window_data->bounds); | |
| 474 if (parent) | |
| 475 parent->AddChildFromServer(window_port_mus_ptr); | |
| 476 if (window_data->visible) | |
| 477 window_mus->SetVisibleFromServer(true); | |
| 478 return window_port_mus_ptr; | |
| 479 } | |
| 480 | |
| 481 void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { | |
| 532 tree_ptr_ = std::move(window_tree_ptr); | 482 tree_ptr_ = std::move(window_tree_ptr); |
| 533 tree_ = tree_ptr_.get(); | 483 tree_ = tree_ptr_.get(); |
| 534 | 484 |
| 535 tree_ptr_->GetCursorLocationMemory( | 485 tree_ptr_->GetCursorLocationMemory( |
| 536 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, | 486 base::Bind(&WindowTreeClient::OnReceivedCursorLocationMemory, |
| 537 weak_factory_.GetWeakPtr())); | 487 weak_factory_.GetWeakPtr())); |
| 538 | 488 |
| 539 tree_ptr_.set_connection_error_handler(base::Bind( | 489 tree_ptr_.set_connection_error_handler(base::Bind( |
| 540 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr())); | 490 &WindowTreeClient::OnConnectionLost, weak_factory_.GetWeakPtr())); |
| 541 | 491 |
| 542 if (window_manager_delegate_) { | 492 if (window_manager_delegate_) { |
| 543 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 493 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 544 tree_ptr_.associated_group())); | 494 tree_ptr_.associated_group())); |
| 545 } | 495 } |
| 546 } | 496 } |
| 547 | 497 |
| 548 void WindowTreeClient::OnConnectionLost() { | 498 void WindowTreeClient::OnConnectionLost() { |
| 549 delegate_->OnLostConnection(this); | 499 delegate_->OnLostConnection(this); |
| 550 } | 500 } |
| 551 | 501 |
| 552 void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, | 502 void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree, |
| 553 ClientSpecificId client_id, | 503 ClientSpecificId client_id, |
| 554 mojom::WindowDataPtr root_data, | 504 ui::mojom::WindowDataPtr root_data, |
| 555 int64_t display_id, | 505 int64_t display_id, |
| 556 Id focused_window_id, | 506 Id focused_window_id, |
| 557 bool drawn) { | 507 bool drawn) { |
| 558 // WARNING: this is only called if WindowTreeClient was created as the | 508 // WARNING: this is only called if WindowTreeClient was created as the |
| 559 // result of an embedding. | 509 // result of an embedding. |
| 560 tree_ = window_tree; | 510 tree_ = window_tree; |
| 561 client_id_ = client_id; | 511 client_id_ = client_id; |
| 562 | 512 |
| 563 DCHECK(roots_.empty()); | 513 DCHECK(roots_.empty()); |
| 564 Window* root = AddWindowToClient(this, nullptr, root_data); | 514 Window* root = |
| 565 WindowPrivate(root).LocalSetDisplay(display_id); | 515 CreateWindowTreeHost(WindowTreeHostType::EMBED, root_data, nullptr); |
| 566 roots_.insert(root); | 516 // TODO: needs to deal with drawn and display_id. |
| 567 | 517 |
| 568 focused_window_ = GetWindowByServerId(focused_window_id); | 518 SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
| 569 | |
| 570 WindowPrivate(root).LocalSetParentDrawn(drawn); | |
| 571 | 519 |
| 572 delegate_->OnEmbed(root); | 520 delegate_->OnEmbed(root); |
| 573 | |
| 574 if (focused_window_) { | |
| 575 for (auto& observer : observers_) | |
| 576 observer.OnWindowTreeFocusChanged(focused_window_, nullptr); | |
| 577 } | |
| 578 } | 521 } |
| 579 | 522 |
| 580 void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display, | 523 WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
| 581 mojom::WindowDataPtr root_data, | 524 const display::Display& display, |
| 582 bool parent_drawn) { | 525 ui::mojom::WindowDataPtr root_data, |
| 526 bool parent_drawn) { | |
| 583 DCHECK(window_manager_delegate_); | 527 DCHECK(window_manager_delegate_); |
| 584 | 528 |
| 585 Window* root = AddWindowToClient(this, nullptr, root_data); | 529 // TODO: need to deal with display_id and drawn. |
| 586 WindowPrivate(root).LocalSetDisplay(display.id()); | 530 Window* root = |
| 587 WindowPrivate(root).LocalSetParentDrawn(parent_drawn); | 531 CreateWindowTreeHost(WindowTreeHostType::DISPLAY, root_data, nullptr); |
| 588 roots_.insert(root); | 532 // WindowPrivate(root).LocalSetDisplay(display.id()); |
| 533 // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); | |
| 589 | 534 |
| 590 window_manager_delegate_->OnWmNewDisplay(root, display); | 535 window_manager_delegate_->OnWmNewDisplay(root, display); |
| 536 return root->GetHost(); | |
| 537 } | |
| 538 | |
| 539 std::unique_ptr<EventResultCallback> | |
| 540 WindowTreeClient::CreateEventResultCallback(int32_t event_id) { | |
| 541 return base::MakeUnique<EventResultCallback>( | |
| 542 base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, | |
| 543 base::Unretained(tree_), event_id)); | |
| 591 } | 544 } |
| 592 | 545 |
| 593 void WindowTreeClient::OnReceivedCursorLocationMemory( | 546 void WindowTreeClient::OnReceivedCursorLocationMemory( |
| 594 mojo::ScopedSharedBufferHandle handle) { | 547 mojo::ScopedSharedBufferHandle handle) { |
| 595 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); | 548 cursor_location_mapping_ = handle->Map(sizeof(base::subtle::Atomic32)); |
| 596 DCHECK(cursor_location_mapping_); | 549 DCHECK(cursor_location_mapping_); |
| 597 } | 550 } |
| 598 | 551 |
| 552 std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( | |
| 553 WindowMus* window) { | |
| 554 if (window->server_id() != 0) { | |
| 555 // This window was created by us and has an associated server window. | |
| 556 return nullptr; | |
| 557 } | |
| 558 | |
| 559 window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); | |
| 560 RegisterWindowMus(window); | |
| 561 | |
| 562 const bool create_top_level = | |
| 563 !window_manager_delegate_ && | |
| 564 ShouldCreateTopLevel(window->GetWindow()->type()); | |
| 565 | |
| 566 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; | |
| 567 std::set<const void*> property_keys = | |
| 568 window->GetWindow()->GetAllPropertKeys(); | |
| 569 PropertyConverter* property_converter = delegate_->GetPropertyConverter(); | |
| 570 for (const void* key : property_keys) { | |
| 571 std::string transport_name; | |
| 572 std::unique_ptr<std::vector<uint8_t>> transport_value; | |
| 573 if (!property_converter->ConvertPropertyForTransport( | |
| 574 window->GetWindow(), key, &transport_name, &transport_value)) { | |
| 575 continue; | |
| 576 } | |
| 577 if (!transport_value) { | |
| 578 transport_properties[transport_name] = mojo::Array<uint8_t>(nullptr); | |
| 579 } else { | |
| 580 transport_properties[transport_name] = | |
| 581 mojo::Array<uint8_t>::From(*transport_value); | |
| 582 } | |
| 583 } | |
| 584 | |
| 585 const uint32_t change_id = | |
| 586 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 587 window, create_top_level ? ChangeType::NEW_TOP_LEVEL_WINDOW | |
| 588 : ChangeType::NEW_WINDOW)); | |
| 589 if (create_top_level) { | |
| 590 std::unique_ptr<WindowPortInitData> data( | |
| 591 base::MakeUnique<WindowPortInitData>()); | |
| 592 tree_->NewTopLevelWindow(change_id, window->server_id(), | |
| 593 std::move(transport_properties)); | |
| 594 return data; | |
| 595 } | |
| 596 tree_->NewWindow(change_id, window->server_id(), | |
| 597 std::move(transport_properties)); | |
| 598 return nullptr; | |
| 599 } | |
| 600 | |
| 601 void WindowTreeClient::OnWindowMusInitDone( | |
| 602 WindowMus* window, | |
| 603 std::unique_ptr<WindowPortInitData> init_data) { | |
| 604 if (!init_data) | |
| 605 return; | |
| 606 | |
| 607 // Delay creating the WindowTreeHost until after Init(), otherwise we trigger | |
| 608 // crashes in code that expects window parenting to happen after | |
| 609 // Env::NotifyWindowInitialized() is called. | |
| 610 CreateWindowTreeHost(WindowTreeHostType::TOP_LEVEL, nullptr, | |
| 611 window->GetWindow()); | |
| 612 } | |
| 613 | |
| 614 void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { | |
| 615 if (focused_window_ == window) | |
| 616 focused_window_ = nullptr; | |
| 617 | |
| 618 // TODO: decide how to deal with windows not owned by this client. | |
| 619 if (WasCreatedByThisClient(window) || IsRoot(window)) { | |
| 620 const uint32_t change_id = | |
| 621 ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( | |
| 622 window, ChangeType::DELETE_WINDOW)); | |
| 623 tree_->DeleteWindow(change_id, window->server_id()); | |
| 624 } | |
| 625 | |
| 626 windows_.erase(window->server_id()); | |
| 627 | |
| 628 for (auto& entry : embedded_windows_) { | |
| 629 auto it = entry.second.find(window->GetWindow()); | |
| 630 if (it != entry.second.end()) { | |
| 631 entry.second.erase(it); | |
| 632 break; | |
| 633 } | |
| 634 } | |
| 635 | |
| 636 // Remove any InFlightChanges associated with the window. | |
| 637 std::set<uint32_t> in_flight_change_ids_to_remove; | |
| 638 for (const auto& pair : in_flight_map_) { | |
| 639 if (pair.second->window() == window) | |
| 640 in_flight_change_ids_to_remove.insert(pair.first); | |
| 641 } | |
| 642 for (auto change_id : in_flight_change_ids_to_remove) | |
| 643 in_flight_map_.erase(change_id); | |
| 644 | |
| 645 const bool was_root = roots_.erase(window) > 0; | |
| 646 if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) | |
| 647 delegate_->OnEmbedRootDestroyed(window->GetWindow()); | |
| 648 } | |
| 649 | |
| 650 void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, | |
| 651 const gfx::Rect& old_bounds, | |
| 652 const gfx::Rect& new_bounds) { | |
| 653 const uint32_t change_id = ScheduleInFlightChange( | |
| 654 base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); | |
| 655 tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); | |
| 656 } | |
| 657 | |
| 658 void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, | |
| 659 WindowMus* child) { | |
| 660 // TODO: add checks to ensure this can work. | |
| 661 const uint32_t change_id = ScheduleInFlightChange( | |
| 662 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); | |
| 663 tree_->AddWindow(change_id, parent->server_id(), child->server_id()); | |
| 664 } | |
| 665 | |
| 666 void WindowTreeClient::OnWindowMusRemoveChild(WindowMus* parent, | |
| 667 WindowMus* child) { | |
| 668 // TODO: add checks to ensure this can work. | |
| 669 const uint32_t change_id = ScheduleInFlightChange( | |
| 670 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD)); | |
| 671 tree_->RemoveWindowFromParent(change_id, child->server_id()); | |
| 672 } | |
| 673 | |
| 674 void WindowTreeClient::OnWindowMusMoveChild(WindowMus* parent, | |
| 675 size_t current_index, | |
| 676 size_t dest_index) { | |
| 677 // TODO: add checks to ensure this can work, e.g. we own the parent. | |
| 678 const uint32_t change_id = ScheduleInFlightChange( | |
| 679 base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REORDER)); | |
| 680 WindowMus* window = | |
| 681 WindowMus::Get(parent->GetWindow()->children()[current_index]); | |
| 682 WindowMus* relative_window = nullptr; | |
| 683 ui::mojom::OrderDirection direction; | |
| 684 if (dest_index < current_index) { | |
| 685 relative_window = | |
| 686 WindowMus::Get(parent->GetWindow()->children()[dest_index]); | |
| 687 direction = ui::mojom::OrderDirection::BELOW; | |
| 688 } else { | |
| 689 relative_window = | |
| 690 WindowMus::Get(parent->GetWindow()->children()[dest_index]); | |
| 691 direction = ui::mojom::OrderDirection::ABOVE; | |
| 692 } | |
| 693 tree_->ReorderWindow(change_id, window->server_id(), | |
| 694 relative_window->server_id(), direction); | |
| 695 } | |
| 696 | |
| 697 void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { | |
| 698 // TODO: add checks to ensure this can work. | |
| 699 DCHECK(tree_); | |
| 700 const uint32_t change_id = ScheduleInFlightChange( | |
| 701 base::MakeUnique<InFlightVisibleChange>(window, !visible)); | |
| 702 tree_->SetWindowVisibility(change_id, window->server_id(), visible); | |
| 703 } | |
| 704 | |
| 705 std::unique_ptr<WindowPortPropertyData> | |
| 706 WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, | |
| 707 const void* key) { | |
| 708 std::unique_ptr<WindowPortPropertyDataMus> data( | |
| 709 base::MakeUnique<WindowPortPropertyDataMus>()); | |
| 710 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( | |
| 711 window->GetWindow(), key, &data->transport_name, | |
| 712 &data->transport_value)) { | |
| 713 return nullptr; | |
| 714 } | |
| 715 return data; | |
| 716 } | |
| 717 | |
| 718 void WindowTreeClient::OnWindowMusPropertyChanged( | |
| 719 WindowMus* window, | |
| 720 const void* key, | |
| 721 std::unique_ptr<WindowPortPropertyData> data) { | |
| 722 if (!data) | |
| 723 return; | |
| 724 WindowPortPropertyDataMus* data_mus = | |
| 725 static_cast<WindowPortPropertyDataMus*>(data.get()); | |
| 726 | |
| 727 std::string transport_name; | |
| 728 std::unique_ptr<std::vector<uint8_t>> transport_value; | |
| 729 if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( | |
| 730 window->GetWindow(), key, &transport_name, &transport_value)) { | |
| 731 return; | |
| 732 } | |
| 733 DCHECK_EQ(transport_name, data_mus->transport_name); | |
| 734 | |
| 735 mojo::Array<uint8_t> transport_value_mojo(nullptr); | |
| 736 if (transport_value) { | |
| 737 transport_value_mojo.resize(transport_value->size()); | |
| 738 if (transport_value->size()) { | |
| 739 memcpy(&transport_value_mojo.front(), &(transport_value->front()), | |
| 740 transport_value->size()); | |
| 741 } | |
| 742 } | |
| 743 const uint32_t change_id = | |
| 744 ScheduleInFlightChange(base::MakeUnique<InFlightPropertyChange>( | |
| 745 window, transport_name, std::move(data_mus->transport_value))); | |
| 746 tree_->SetWindowProperty(change_id, window->server_id(), | |
| 747 mojo::String(transport_name), | |
| 748 std::move(transport_value_mojo)); | |
| 749 } | |
| 750 | |
| 751 void WindowTreeClient::OnWindowMusSurfaceDetached( | |
| 752 WindowMus* window, | |
| 753 const cc::SurfaceSequence& sequence) { | |
| 754 tree_->OnWindowSurfaceDetached(window->server_id(), sequence); | |
| 755 } | |
| 756 | |
| 599 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, | 757 void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, |
| 600 bool completed) { | 758 bool completed) { |
| 601 if (window_manager_internal_client_) | 759 if (window_manager_internal_client_) |
| 602 window_manager_internal_client_->WmResponse(change_id, completed); | 760 window_manager_internal_client_->WmResponse(change_id, completed); |
| 603 | 761 |
| 604 if (change_id == current_wm_move_loop_change_) { | 762 if (change_id == current_wm_move_loop_change_) { |
| 605 current_wm_move_loop_change_ = 0; | 763 current_wm_move_loop_change_ = 0; |
| 606 current_wm_move_loop_window_id_ = 0; | 764 current_wm_move_loop_window_id_ = 0; |
| 607 } | 765 } |
| 608 } | 766 } |
| 609 | 767 |
| 610 //////////////////////////////////////////////////////////////////////////////// | 768 //////////////////////////////////////////////////////////////////////////////// |
| 611 // WindowTreeClient, WindowTreeClient implementation: | 769 // WindowTreeClient, WindowTreeClient implementation: |
| 612 | 770 |
| 613 const std::set<Window*>& WindowTreeClient::GetRoots() { | 771 std::set<Window*> WindowTreeClient::GetRoots() { |
| 614 return roots_; | 772 std::set<Window*> roots; |
| 773 for (WindowMus* window : roots_) | |
| 774 roots.insert(window->GetWindow()); | |
| 775 return roots; | |
| 615 } | 776 } |
| 616 | 777 |
| 617 Window* WindowTreeClient::GetFocusedWindow() { | 778 Window* WindowTreeClient::GetFocusedWindow() { |
| 618 return focused_window_; | 779 return focused_window_ ? focused_window_->GetWindow() : nullptr; |
| 619 } | |
| 620 | |
| 621 void WindowTreeClient::ClearFocus() { | |
| 622 if (!focused_window_) | |
| 623 return; | |
| 624 | |
| 625 SetFocus(nullptr); | |
| 626 } | 780 } |
| 627 | 781 |
| 628 gfx::Point WindowTreeClient::GetCursorScreenPoint() { | 782 gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| 629 // We raced initialization. Return (0, 0). | 783 // We raced initialization. Return (0, 0). |
| 630 if (!cursor_location_memory()) | 784 if (!cursor_location_memory()) |
| 631 return gfx::Point(); | 785 return gfx::Point(); |
| 632 | 786 |
| 633 base::subtle::Atomic32 location = | 787 base::subtle::Atomic32 location = |
| 634 base::subtle::NoBarrier_Load(cursor_location_memory()); | 788 base::subtle::NoBarrier_Load(cursor_location_memory()); |
| 635 return gfx::Point(static_cast<int16_t>(location >> 16), | 789 return gfx::Point(static_cast<int16_t>(location >> 16), |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 649 has_pointer_watcher_ = false; | 803 has_pointer_watcher_ = false; |
| 650 } | 804 } |
| 651 | 805 |
| 652 void WindowTreeClient::PerformDragDrop( | 806 void WindowTreeClient::PerformDragDrop( |
| 653 Window* window, | 807 Window* window, |
| 654 const std::map<std::string, std::vector<uint8_t>>& drag_data, | 808 const std::map<std::string, std::vector<uint8_t>>& drag_data, |
| 655 int drag_operation, | 809 int drag_operation, |
| 656 const gfx::Point& cursor_location, | 810 const gfx::Point& cursor_location, |
| 657 const SkBitmap& bitmap, | 811 const SkBitmap& bitmap, |
| 658 const base::Callback<void(bool, uint32_t)>& callback) { | 812 const base::Callback<void(bool, uint32_t)>& callback) { |
| 813 // TODO: dnd. | |
| 814 /* | |
| 659 DCHECK(!current_drag_state_); | 815 DCHECK(!current_drag_state_); |
| 660 | 816 |
| 661 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when | 817 // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| 662 // we start showing an image representation of the drag under he cursor. | 818 // we start showing an image representation of the drag under he cursor. |
| 663 | 819 |
| 664 if (window->drop_target()) { | 820 if (window->drop_target()) { |
| 665 // To minimize the number of round trips, copy the drag drop data to our | 821 // 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. | 822 // handler here, instead of forcing mus to send this same data back. |
| 667 OnDragDropStart( | 823 OnDragDropStart( |
| 668 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); | 824 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data)); |
| 669 } | 825 } |
| 670 | 826 |
| 671 uint32_t current_drag_change = ScheduleInFlightChange( | 827 uint32_t current_drag_change = ScheduleInFlightChange( |
| 672 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); | 828 base::MakeUnique<InFlightDragChange>(window, ChangeType::DRAG_LOOP)); |
| 673 current_drag_state_.reset(new CurrentDragState{ | 829 current_drag_state_.reset(new CurrentDragState{ |
| 674 current_drag_change, ui::mojom::kDropEffectNone, callback}); | 830 current_drag_change, ui::mojom::kDropEffectNone, callback}); |
| 675 | 831 |
| 676 tree_->PerformDragDrop( | 832 tree_->PerformDragDrop( |
| 677 current_drag_change, window->server_id(), | 833 current_drag_change, window->server_id(), |
| 678 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), | 834 mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
| 679 drag_operation); | 835 drag_operation); |
| 836 */ | |
| 680 } | 837 } |
| 681 | 838 |
| 682 void WindowTreeClient::CancelDragDrop(Window* window) { | 839 void WindowTreeClient::CancelDragDrop(Window* window) { |
| 683 // Server will clean up drag and fail the in-flight change. | 840 // Server will clean up drag and fail the in-flight change. |
| 684 tree_->CancelDragDrop(window->server_id()); | 841 tree_->CancelDragDrop(WindowMus::Get(window)->server_id()); |
| 685 } | 842 } |
| 686 | 843 |
| 687 void WindowTreeClient::PerformWindowMove( | 844 void WindowTreeClient::PerformWindowMove( |
| 688 Window* window, | 845 Window* window, |
| 689 ui::mojom::MoveLoopSource source, | 846 ui::mojom::MoveLoopSource source, |
| 690 const gfx::Point& cursor_location, | 847 const gfx::Point& cursor_location, |
| 691 const base::Callback<void(bool)>& callback) { | 848 const base::Callback<void(bool)>& callback) { |
| 692 DCHECK(on_current_move_finished_.is_null()); | 849 DCHECK(on_current_move_finished_.is_null()); |
| 693 on_current_move_finished_ = callback; | 850 on_current_move_finished_ = callback; |
| 694 | 851 |
| 852 WindowMus* window_mus = WindowMus::Get(window); | |
| 695 current_move_loop_change_ = ScheduleInFlightChange( | 853 current_move_loop_change_ = ScheduleInFlightChange( |
| 696 base::MakeUnique<InFlightDragChange>(window, ChangeType::MOVE_LOOP)); | 854 base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); |
| 697 // Tell the window manager to take over moving us. | 855 // Tell the window manager to take over moving us. |
| 698 tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), | 856 tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), |
| 699 source, cursor_location); | 857 source, cursor_location); |
| 700 } | 858 } |
| 701 | 859 |
| 702 void WindowTreeClient::CancelWindowMove(Window* window) { | 860 void WindowTreeClient::CancelWindowMove(Window* window) { |
| 703 tree_->CancelWindowMove(window->server_id()); | 861 tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); |
| 704 } | 862 } |
| 705 | 863 |
| 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 //////////////////////////////////////////////////////////////////////////////// | 864 //////////////////////////////////////////////////////////////////////////////// |
| 744 // WindowTreeClient, WindowTreeClient implementation: | 865 // WindowTreeClient, WindowTreeClient implementation: |
| 745 | 866 |
| 746 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { | 867 void WindowTreeClient::AddObserver(WindowTreeClientObserver* observer) { |
| 747 observers_.AddObserver(observer); | 868 observers_.AddObserver(observer); |
| 748 } | 869 } |
| 749 | 870 |
| 750 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { | 871 void WindowTreeClient::RemoveObserver(WindowTreeClientObserver* observer) { |
| 751 observers_.RemoveObserver(observer); | 872 observers_.RemoveObserver(observer); |
| 752 } | 873 } |
| 753 | 874 |
| 754 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { | 875 void WindowTreeClient::SetCanAcceptDrops(Id window_id, bool can_accept_drops) { |
| 755 DCHECK(tree_); | 876 DCHECK(tree_); |
| 756 tree_->SetCanAcceptDrops(window_id, can_accept_drops); | 877 tree_->SetCanAcceptDrops(window_id, can_accept_drops); |
| 757 } | 878 } |
| 758 | 879 |
| 759 void WindowTreeClient::SetCanAcceptEvents(Id window_id, | 880 void WindowTreeClient::SetCanAcceptEvents(Id window_id, |
| 760 bool can_accept_events) { | 881 bool can_accept_events) { |
| 761 DCHECK(tree_); | 882 DCHECK(tree_); |
| 762 tree_->SetCanAcceptEvents(window_id, can_accept_events); | 883 tree_->SetCanAcceptEvents(window_id, can_accept_events); |
| 763 } | 884 } |
| 764 | 885 |
| 765 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, | 886 void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| 766 mojom::WindowDataPtr root_data, | 887 ui::mojom::WindowDataPtr root_data, |
| 767 mojom::WindowTreePtr tree, | 888 ui::mojom::WindowTreePtr tree, |
| 768 int64_t display_id, | 889 int64_t display_id, |
| 769 Id focused_window_id, | 890 Id focused_window_id, |
| 770 bool drawn) { | 891 bool drawn) { |
| 771 DCHECK(!tree_ptr_); | 892 DCHECK(!tree_ptr_); |
| 772 tree_ptr_ = std::move(tree); | 893 tree_ptr_ = std::move(tree); |
| 773 | 894 |
| 774 is_from_embed_ = true; | 895 is_from_embed_ = true; |
| 775 | 896 |
| 776 if (window_manager_delegate_) { | 897 if (window_manager_delegate_) { |
| 777 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, | 898 tree_ptr_->GetWindowManagerClient(GetProxy(&window_manager_internal_client_, |
| 778 tree_ptr_.associated_group())); | 899 tree_ptr_.associated_group())); |
| 779 } | 900 } |
| 780 | 901 |
| 781 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, | 902 OnEmbedImpl(tree_ptr_.get(), client_id, std::move(root_data), display_id, |
| 782 focused_window_id, drawn); | 903 focused_window_id, drawn); |
| 783 } | 904 } |
| 784 | 905 |
| 785 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { | 906 void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { |
| 786 Window* window = GetWindowByServerId(window_id); | 907 WindowMus* window = GetWindowByServerId(window_id); |
| 787 if (window) { | 908 if (window) |
| 788 for (auto& observer : *WindowPrivate(window).observers()) | 909 window->NotifyEmbeddedAppDisconnected(); |
| 789 observer.OnWindowEmbeddedAppDisconnected(window); | |
| 790 } | |
| 791 } | 910 } |
| 792 | 911 |
| 793 void WindowTreeClient::OnUnembed(Id window_id) { | 912 void WindowTreeClient::OnUnembed(Id window_id) { |
| 794 Window* window = GetWindowByServerId(window_id); | 913 WindowMus* window = GetWindowByServerId(window_id); |
| 795 if (!window) | 914 if (!window) |
| 796 return; | 915 return; |
| 797 | 916 |
| 798 delegate_->OnUnembed(window); | 917 delegate_->OnUnembed(window->GetWindow()); |
| 799 WindowPrivate(window).LocalDestroy(); | 918 delete window; |
| 800 } | 919 } |
| 801 | 920 |
| 802 void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, | 921 void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, |
| 803 Id old_capture_window_id) { | 922 Id old_capture_window_id) { |
| 804 Window* new_capture_window = GetWindowByServerId(new_capture_window_id); | 923 WindowMus* new_capture_window = GetWindowByServerId(new_capture_window_id); |
| 805 Window* lost_capture_window = GetWindowByServerId(old_capture_window_id); | 924 WindowMus* lost_capture_window = GetWindowByServerId(old_capture_window_id); |
| 806 if (!new_capture_window && !lost_capture_window) | 925 if (!new_capture_window && !lost_capture_window) |
| 807 return; | 926 return; |
| 808 | 927 |
| 809 InFlightCaptureChange change(this, new_capture_window); | 928 InFlightCaptureChange change(this, new_capture_window); |
| 810 if (ApplyServerChangeToExistingInFlightChange(change)) | 929 if (ApplyServerChangeToExistingInFlightChange(change)) |
| 811 return; | 930 return; |
| 812 | 931 |
| 813 LocalSetCapture(new_capture_window); | 932 SetCaptureFromServer(new_capture_window); |
| 814 } | 933 } |
| 815 | 934 |
| 816 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, | 935 void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| 817 mojom::WindowDataPtr data, | 936 ui::mojom::WindowDataPtr data, |
| 818 int64_t display_id, | 937 int64_t display_id, |
| 819 bool drawn) { | 938 bool drawn) { |
| 820 // The server ack'd the top level window we created and supplied the state | 939 // 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 | 940 // 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 | 941 // 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. | 942 // with changes in flight we set the revert value from the server. |
| 824 | 943 |
| 825 if (!in_flight_map_.count(change_id)) { | 944 if (!in_flight_map_.count(change_id)) { |
| 826 // The window may have been destroyed locally before the server could finish | 945 // The window may have been destroyed locally before the server could finish |
| 827 // creating the window, and before the server received the notification that | 946 // creating the window, and before the server received the notification that |
| 828 // the window has been destroyed. | 947 // the window has been destroyed. |
| 829 return; | 948 return; |
| 830 } | 949 } |
| 831 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 950 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 832 in_flight_map_.erase(change_id); | 951 in_flight_map_.erase(change_id); |
| 833 | 952 |
| 834 Window* window = change->window(); | 953 WindowMus* window = change->window(); |
| 835 WindowPrivate window_private(window); | |
| 836 | 954 |
| 955 // 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 | 956 // Drawn state and display-id always come from the server (they can't be |
| 838 // modified locally). | 957 // modified locally). |
| 839 window_private.LocalSetParentDrawn(drawn); | |
| 840 window_private.LocalSetDisplay(display_id); | |
| 841 | 958 |
| 842 // The default visibilty is false, we only need update visibility if it | 959 // The default visibilty is false, we only need update visibility if it |
| 843 // differs from that. | 960 // differs from that. |
| 844 if (data->visible) { | 961 if (data->visible) { |
| 845 InFlightVisibleChange visible_change(window, data->visible); | 962 InFlightVisibleChange visible_change(window, data->visible); |
| 846 InFlightChange* current_change = | 963 InFlightChange* current_change = |
| 847 GetOldestInFlightChangeMatching(visible_change); | 964 GetOldestInFlightChangeMatching(visible_change); |
| 848 if (current_change) | 965 if (current_change) |
| 849 current_change->SetRevertValueFrom(visible_change); | 966 current_change->SetRevertValueFrom(visible_change); |
| 850 else | 967 else |
| 851 window_private.LocalSetVisible(true); | 968 window->SetVisibleFromServer(true); |
| 852 } | 969 } |
| 853 | 970 |
| 854 const gfx::Rect bounds(data->bounds); | 971 const gfx::Rect bounds(data->bounds); |
| 855 { | 972 { |
| 856 InFlightBoundsChange bounds_change(window, bounds); | 973 InFlightBoundsChange bounds_change(window, bounds); |
| 857 InFlightChange* current_change = | 974 InFlightChange* current_change = |
| 858 GetOldestInFlightChangeMatching(bounds_change); | 975 GetOldestInFlightChangeMatching(bounds_change); |
| 859 if (current_change) | 976 if (current_change) |
| 860 current_change->SetRevertValueFrom(bounds_change); | 977 current_change->SetRevertValueFrom(bounds_change); |
| 861 else if (window->bounds() != bounds) | 978 else if (window->GetWindow()->bounds() != bounds) |
| 862 window_private.LocalSetBounds(window->bounds(), bounds); | 979 window->SetBoundsFromServer(bounds); |
| 863 } | 980 } |
| 864 | 981 |
| 865 // There is currently no API to bulk set properties, so we iterate over each | 982 // There is currently no API to bulk set properties, so we iterate over each |
| 866 // property individually. | 983 // property individually. |
| 867 Window::SharedProperties properties = | 984 std::map<std::string, std::vector<uint8_t>> properties = |
| 868 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 985 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 869 for (const auto& pair : properties) { | 986 for (const auto& pair : properties) { |
| 870 InFlightPropertyChange property_change( | 987 std::unique_ptr<std::vector<uint8_t>> revert_value( |
| 871 window, pair.first, mojo::Array<uint8_t>::From(pair.second)); | 988 base::MakeUnique<std::vector<uint8_t>>(pair.second)); |
| 989 InFlightPropertyChange property_change(window, pair.first, | |
| 990 std::move(revert_value)); | |
| 872 InFlightChange* current_change = | 991 InFlightChange* current_change = |
| 873 GetOldestInFlightChangeMatching(property_change); | 992 GetOldestInFlightChangeMatching(property_change); |
| 874 if (current_change) | 993 if (current_change) { |
| 875 current_change->SetRevertValueFrom(property_change); | 994 current_change->SetRevertValueFrom(property_change); |
| 876 else | 995 } else { |
| 877 window_private.LocalSetSharedProperty(pair.first, &(pair.second)); | 996 window->SetPropertyFromServer(pair.first, &pair.second); |
| 997 } | |
| 878 } | 998 } |
| 879 | 999 |
| 880 // Top level windows should not have a parent. | 1000 // Top level windows should not have a parent. |
| 881 DCHECK_EQ(0u, data->parent_id); | 1001 DCHECK_EQ(0u, data->parent_id); |
| 882 } | 1002 } |
| 883 | 1003 |
| 884 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, | 1004 void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| 885 const gfx::Rect& old_bounds, | 1005 const gfx::Rect& old_bounds, |
| 886 const gfx::Rect& new_bounds) { | 1006 const gfx::Rect& new_bounds) { |
| 887 Window* window = GetWindowByServerId(window_id); | 1007 WindowMus* window = GetWindowByServerId(window_id); |
| 888 if (!window) | 1008 if (!window) |
| 889 return; | 1009 return; |
| 890 | 1010 |
| 891 InFlightBoundsChange new_change(window, new_bounds); | 1011 InFlightBoundsChange new_change(window, new_bounds); |
| 892 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1012 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 893 return; | 1013 return; |
| 894 | 1014 |
| 895 WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); | 1015 window->SetBoundsFromServer(new_bounds); |
| 896 } | 1016 } |
| 897 | 1017 |
| 898 void WindowTreeClient::OnClientAreaChanged( | 1018 void WindowTreeClient::OnClientAreaChanged( |
| 899 uint32_t window_id, | 1019 uint32_t window_id, |
| 900 const gfx::Insets& new_client_area, | 1020 const gfx::Insets& new_client_area, |
| 901 mojo::Array<gfx::Rect> new_additional_client_areas) { | 1021 mojo::Array<gfx::Rect> new_additional_client_areas) { |
| 1022 // TODO: client area. | |
| 1023 /* | |
| 902 Window* window = GetWindowByServerId(window_id); | 1024 Window* window = GetWindowByServerId(window_id); |
| 903 if (window) { | 1025 if (window) { |
| 904 WindowPrivate(window).LocalSetClientArea( | 1026 WindowPrivate(window).LocalSetClientArea( |
| 905 new_client_area, | 1027 new_client_area, |
| 906 new_additional_client_areas.To<std::vector<gfx::Rect>>()); | 1028 new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| 907 } | 1029 } |
| 1030 */ | |
| 908 } | 1031 } |
| 909 | 1032 |
| 910 void WindowTreeClient::OnTransientWindowAdded( | 1033 void WindowTreeClient::OnTransientWindowAdded(uint32_t window_id, |
| 911 uint32_t window_id, | 1034 uint32_t transient_window_id) { |
| 912 uint32_t transient_window_id) { | 1035 // TODO: needs to route to StackingClient. |
| 1036 /* | |
| 913 Window* window = GetWindowByServerId(window_id); | 1037 Window* window = GetWindowByServerId(window_id); |
| 914 Window* transient_window = GetWindowByServerId(transient_window_id); | 1038 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 915 // window or transient_window or both may be null if a local delete occurs | 1039 // window or transient_window or both may be null if a local delete occurs |
| 916 // with an in flight add from the server. | 1040 // with an in flight add from the server. |
| 917 if (window && transient_window) | 1041 if (window && transient_window) |
| 918 WindowPrivate(window).LocalAddTransientWindow(transient_window); | 1042 WindowPrivate(window).LocalAddTransientWindow(transient_window); |
| 1043 */ | |
| 919 } | 1044 } |
| 920 | 1045 |
| 921 void WindowTreeClient::OnTransientWindowRemoved( | 1046 void WindowTreeClient::OnTransientWindowRemoved(uint32_t window_id, |
| 922 uint32_t window_id, | 1047 uint32_t transient_window_id) { |
| 923 uint32_t transient_window_id) { | 1048 // TODO: needs to route to StackingClient. |
| 1049 /* | |
| 924 Window* window = GetWindowByServerId(window_id); | 1050 Window* window = GetWindowByServerId(window_id); |
| 925 Window* transient_window = GetWindowByServerId(transient_window_id); | 1051 Window* transient_window = GetWindowByServerId(transient_window_id); |
| 926 // window or transient_window or both may be null if a local delete occurs | 1052 // window or transient_window or both may be null if a local delete occurs |
| 927 // with an in flight delete from the server. | 1053 // with an in flight delete from the server. |
| 928 if (window && transient_window) | 1054 if (window && transient_window) |
| 929 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); | 1055 WindowPrivate(window).LocalRemoveTransientWindow(transient_window); |
| 1056 */ | |
| 930 } | 1057 } |
| 931 | 1058 |
| 932 void WindowTreeClient::OnWindowHierarchyChanged( | 1059 void WindowTreeClient::OnWindowHierarchyChanged( |
| 933 Id window_id, | 1060 Id window_id, |
| 934 Id old_parent_id, | 1061 Id old_parent_id, |
| 935 Id new_parent_id, | 1062 Id new_parent_id, |
| 936 mojo::Array<mojom::WindowDataPtr> windows) { | 1063 mojo::Array<ui::mojom::WindowDataPtr> windows) { |
| 937 Window* initial_parent = | 1064 WindowMus* initial_parent = |
| 938 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; | 1065 windows.size() ? GetWindowByServerId(windows[0]->parent_id) : nullptr; |
| 939 | 1066 |
| 940 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; | 1067 const bool was_window_known = GetWindowByServerId(window_id) != nullptr; |
| 941 | 1068 |
| 942 BuildWindowTree(windows, initial_parent); | 1069 BuildWindowTree(windows, initial_parent); |
| 943 | 1070 |
| 944 // If the window was not known, then BuildWindowTree() will have created it | 1071 // If the window was not known, then BuildWindowTree() will have created it |
| 945 // and parented the window. | 1072 // and parented the window. |
| 946 if (!was_window_known) | 1073 if (!was_window_known) |
| 947 return; | 1074 return; |
| 948 | 1075 |
| 949 Window* new_parent = GetWindowByServerId(new_parent_id); | 1076 WindowMus* new_parent = GetWindowByServerId(new_parent_id); |
| 950 Window* old_parent = GetWindowByServerId(old_parent_id); | 1077 WindowMus* old_parent = GetWindowByServerId(old_parent_id); |
| 951 Window* window = GetWindowByServerId(window_id); | 1078 WindowMus* window = GetWindowByServerId(window_id); |
| 952 if (new_parent) | 1079 if (new_parent) |
| 953 WindowPrivate(new_parent).LocalAddChild(window); | 1080 new_parent->AddChildFromServer(window); |
| 954 else | 1081 else |
| 955 WindowPrivate(old_parent).LocalRemoveChild(window); | 1082 old_parent->RemoveChildFromServer(window); |
| 956 } | 1083 } |
| 957 | 1084 |
| 958 void WindowTreeClient::OnWindowReordered(Id window_id, | 1085 void WindowTreeClient::OnWindowReordered(Id window_id, |
| 959 Id relative_window_id, | 1086 Id relative_window_id, |
| 960 mojom::OrderDirection direction) { | 1087 ui::mojom::OrderDirection direction) { |
| 961 Window* window = GetWindowByServerId(window_id); | 1088 WindowMus* window = GetWindowByServerId(window_id); |
| 962 Window* relative_window = GetWindowByServerId(relative_window_id); | 1089 WindowMus* relative_window = GetWindowByServerId(relative_window_id); |
| 963 if (window && relative_window) | 1090 WindowMus* parent = WindowMus::Get(window->GetWindow()->parent()); |
| 964 WindowPrivate(window).LocalReorder(relative_window, direction); | 1091 if (window && relative_window && parent && |
| 1092 parent == WindowMus::Get(relative_window->GetWindow()->parent())) { | |
| 1093 parent->ReorderFromServer(window, relative_window, direction); | |
| 1094 } | |
| 965 } | 1095 } |
| 966 | 1096 |
| 967 void WindowTreeClient::OnWindowDeleted(Id window_id) { | 1097 void WindowTreeClient::OnWindowDeleted(Id window_id) { |
| 968 Window* window = GetWindowByServerId(window_id); | 1098 delete GetWindowByServerId(window_id)->GetWindow(); |
| 969 if (window) | |
| 970 WindowPrivate(window).LocalDestroy(); | |
| 971 } | 1099 } |
| 972 | 1100 |
| 973 Window* WindowTreeClient::GetCaptureWindow() { | 1101 Window* WindowTreeClient::GetCaptureWindow() { |
| 974 return capture_window_; | 1102 return capture_window_ ? capture_window_->GetWindow() : nullptr; |
| 975 } | 1103 } |
| 976 | 1104 |
| 977 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, | 1105 void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| 978 bool visible) { | 1106 WindowMus* window = GetWindowByServerId(window_id); |
| 979 Window* window = GetWindowByServerId(window_id); | |
| 980 if (!window) | 1107 if (!window) |
| 981 return; | 1108 return; |
| 982 | 1109 |
| 983 InFlightVisibleChange new_change(window, visible); | 1110 InFlightVisibleChange new_change(window, visible); |
| 984 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1111 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 985 return; | 1112 return; |
| 986 | 1113 |
| 987 WindowPrivate(window).LocalSetVisible(visible); | 1114 window->SetVisibleFromServer(visible); |
| 988 } | 1115 } |
| 989 | 1116 |
| 990 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, | 1117 void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| 991 float old_opacity, | 1118 float old_opacity, |
| 992 float new_opacity) { | 1119 float new_opacity) { |
| 993 Window* window = GetWindowByServerId(window_id); | 1120 WindowMus* window = GetWindowByServerId(window_id); |
| 994 if (!window) | 1121 if (!window) |
| 995 return; | 1122 return; |
| 996 | 1123 |
| 997 InFlightOpacityChange new_change(window, new_opacity); | 1124 InFlightOpacityChange new_change(window, new_opacity); |
| 998 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1125 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 999 return; | 1126 return; |
| 1000 | 1127 |
| 1001 WindowPrivate(window).LocalSetOpacity(new_opacity); | 1128 window->SetOpacityFromServer(new_opacity); |
| 1002 } | 1129 } |
| 1003 | 1130 |
| 1004 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, | 1131 void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, |
| 1005 bool drawn) { | 1132 bool drawn) { |
| 1133 // TODO: route to WindowTreeHost. | |
| 1134 /* | |
| 1006 Window* window = GetWindowByServerId(window_id); | 1135 Window* window = GetWindowByServerId(window_id); |
| 1007 if (window) | 1136 if (window) |
| 1008 WindowPrivate(window).LocalSetParentDrawn(drawn); | 1137 WindowPrivate(window).LocalSetParentDrawn(drawn); |
| 1138 */ | |
| 1009 } | 1139 } |
| 1010 | 1140 |
| 1011 void WindowTreeClient::OnWindowSharedPropertyChanged( | 1141 void WindowTreeClient::OnWindowSharedPropertyChanged( |
| 1012 Id window_id, | 1142 Id window_id, |
| 1013 const mojo::String& name, | 1143 const mojo::String& name, |
| 1014 mojo::Array<uint8_t> new_data) { | 1144 mojo::Array<uint8_t> transport_data) { |
| 1015 Window* window = GetWindowByServerId(window_id); | 1145 WindowMus* window = GetWindowByServerId(window_id); |
| 1016 if (!window) | 1146 if (!window) |
| 1017 return; | 1147 return; |
| 1018 | 1148 |
| 1019 InFlightPropertyChange new_change(window, name, new_data); | 1149 std::unique_ptr<std::vector<uint8_t>> data; |
| 1150 if (!transport_data.is_null()) { | |
| 1151 data = base::MakeUnique<std::vector<uint8_t>>( | |
| 1152 transport_data.To<std::vector<uint8_t>>()); | |
| 1153 } | |
| 1154 InFlightPropertyChange new_change(window, name, std::move(data)); | |
| 1020 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1155 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1021 return; | 1156 return; |
| 1022 | 1157 |
| 1023 WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); | 1158 if (!transport_data.is_null()) { |
| 1159 data = base::MakeUnique<std::vector<uint8_t>>( | |
| 1160 transport_data.To<std::vector<uint8_t>>()); | |
| 1161 } | |
| 1162 window->SetPropertyFromServer(name, data.get()); | |
| 1024 } | 1163 } |
| 1025 | 1164 |
| 1026 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, | 1165 void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| 1027 Id window_id, | 1166 Id window_id, |
| 1028 std::unique_ptr<ui::Event> event, | 1167 std::unique_ptr<ui::Event> event, |
| 1029 bool matches_pointer_watcher) { | 1168 bool matches_pointer_watcher) { |
| 1030 DCHECK(event); | 1169 DCHECK(event); |
| 1031 Window* window = GetWindowByServerId(window_id); // May be null. | 1170 |
| 1171 WindowMus* window = GetWindowByServerId(window_id); // May be null. | |
| 1172 | |
| 1173 if (event->IsKeyEvent()) { | |
| 1174 DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. | |
| 1175 if (!window || !window->GetWindow()->GetHost()) { | |
| 1176 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
| 1177 return; | |
| 1178 } | |
| 1179 InputMethodMus* input_method = | |
| 1180 static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()) | |
| 1181 ->input_method(); | |
| 1182 input_method->DispatchKeyEvent(event->AsKeyEvent(), | |
| 1183 CreateEventResultCallback(event_id)); | |
| 1184 return; | |
| 1185 } | |
| 1032 | 1186 |
| 1033 if (matches_pointer_watcher && has_pointer_watcher_) { | 1187 if (matches_pointer_watcher && has_pointer_watcher_) { |
| 1034 DCHECK(event->IsPointerEvent()); | 1188 DCHECK(event->IsPointerEvent()); |
| 1035 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), window); | 1189 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), |
| 1190 window ? window->GetWindow() : nullptr); | |
| 1036 } | 1191 } |
| 1037 | 1192 |
| 1038 if (!window || !window->input_event_handler_) { | 1193 // TODO: deal with no window or host here. This could happen if during |
| 1039 tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); | 1194 // dispatch a window is deleted or moved. In either case we still need to |
| 1195 // dispatch. Most likely need the display id. | |
| 1196 if (!window || !window->GetWindow()->GetHost()) { | |
| 1197 tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); | |
| 1040 return; | 1198 return; |
| 1041 } | 1199 } |
| 1042 | 1200 |
| 1043 std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( | 1201 EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| 1044 new base::Callback<void(mojom::EventResult)>( | 1202 WindowTreeHostMus* host = |
| 1045 base::Bind(&mojom::WindowTree::OnWindowInputEventAck, | 1203 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 | 1204 // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| 1049 // ui::TouchEvent once we have proper support for pointer events. | 1205 // ui::TouchEvent once we have proper support for pointer events. |
| 1050 if (event->IsMousePointerEvent()) { | 1206 if (event->IsMousePointerEvent()) { |
| 1051 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { | 1207 if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| 1052 window->input_event_handler_->OnWindowInputEvent( | 1208 ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| 1053 window, ui::MouseWheelEvent(*event->AsPointerEvent()), &ack_callback); | 1209 host->SendEventToProcessor(&mapped_event); |
| 1054 } else { | 1210 } else { |
| 1055 window->input_event_handler_->OnWindowInputEvent( | 1211 ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| 1056 window, ui::MouseEvent(*event->AsPointerEvent()), &ack_callback); | 1212 host->SendEventToProcessor(&mapped_event); |
| 1057 } | 1213 } |
| 1058 } else if (event->IsTouchPointerEvent()) { | 1214 } else if (event->IsTouchPointerEvent()) { |
| 1059 window->input_event_handler_->OnWindowInputEvent( | 1215 ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
| 1060 window, ui::TouchEvent(*event->AsPointerEvent()), &ack_callback); | 1216 host->SendEventToProcessor(&mapped_event); |
| 1061 } else { | 1217 } else { |
| 1062 window->input_event_handler_->OnWindowInputEvent(window, *event.get(), | 1218 host->SendEventToProcessor(event.get()); |
| 1063 &ack_callback); | |
| 1064 } | 1219 } |
| 1065 | 1220 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 } | 1221 } |
| 1071 | 1222 |
| 1072 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, | 1223 void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
| 1073 uint32_t window_id) { | 1224 uint32_t window_id) { |
| 1074 DCHECK(event); | 1225 DCHECK(event); |
| 1075 DCHECK(event->IsPointerEvent()); | 1226 DCHECK(event->IsPointerEvent()); |
| 1076 if (has_pointer_watcher_) { | 1227 if (!has_pointer_watcher_) |
| 1077 Window* target_window = GetWindowByServerId(window_id); | 1228 return; |
| 1078 delegate_->OnPointerEventObserved(*event->AsPointerEvent(), target_window); | 1229 |
| 1079 } | 1230 WindowMus* target_window = GetWindowByServerId(window_id); |
| 1231 delegate_->OnPointerEventObserved( | |
| 1232 *event->AsPointerEvent(), | |
| 1233 target_window ? target_window->GetWindow() : nullptr); | |
| 1080 } | 1234 } |
| 1081 | 1235 |
| 1082 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { | 1236 void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
| 1083 Window* focused_window = GetWindowByServerId(focused_window_id); | 1237 WindowMus* focused_window = GetWindowByServerId(focused_window_id); |
| 1084 InFlightFocusChange new_change(this, focused_window); | 1238 InFlightFocusChange new_change(this, focused_window); |
| 1085 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1239 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1086 return; | 1240 return; |
| 1087 | 1241 |
| 1088 LocalSetFocus(focused_window); | 1242 SetFocusFromServer(focused_window); |
| 1089 } | 1243 } |
| 1090 | 1244 |
| 1091 void WindowTreeClient::OnWindowPredefinedCursorChanged( | 1245 void WindowTreeClient::OnWindowPredefinedCursorChanged( |
| 1092 Id window_id, | 1246 Id window_id, |
| 1093 mojom::Cursor cursor) { | 1247 ui::mojom::Cursor cursor) { |
| 1094 Window* window = GetWindowByServerId(window_id); | 1248 WindowMus* window = GetWindowByServerId(window_id); |
| 1095 if (!window) | 1249 if (!window) |
| 1096 return; | 1250 return; |
| 1097 | 1251 |
| 1098 InFlightPredefinedCursorChange new_change(window, cursor); | 1252 InFlightPredefinedCursorChange new_change(window, cursor); |
| 1099 if (ApplyServerChangeToExistingInFlightChange(new_change)) | 1253 if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| 1100 return; | 1254 return; |
| 1101 | 1255 |
| 1102 WindowPrivate(window).LocalSetPredefinedCursor(cursor); | 1256 window->SetPredefinedCursorFromServer(cursor); |
| 1103 } | 1257 } |
| 1104 | 1258 |
| 1105 void WindowTreeClient::OnWindowSurfaceChanged( | 1259 void WindowTreeClient::OnWindowSurfaceChanged( |
| 1106 Id window_id, | 1260 Id window_id, |
| 1107 const cc::SurfaceId& surface_id, | 1261 const cc::SurfaceId& surface_id, |
| 1108 const cc::SurfaceSequence& surface_sequence, | 1262 const cc::SurfaceSequence& surface_sequence, |
| 1109 const gfx::Size& frame_size, | 1263 const gfx::Size& frame_size, |
| 1110 float device_scale_factor) { | 1264 float device_scale_factor) { |
| 1111 Window* window = GetWindowByServerId(window_id); | 1265 WindowMus* window = GetWindowByServerId(window_id); |
| 1112 if (!window) | 1266 if (!window) |
| 1113 return; | 1267 return; |
| 1114 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); | 1268 std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); |
| 1115 surface_info->surface_id = surface_id; | 1269 surface_info->surface_id = surface_id; |
| 1116 surface_info->surface_sequence = surface_sequence; | 1270 surface_info->surface_sequence = surface_sequence; |
| 1117 surface_info->frame_size = frame_size; | 1271 surface_info->frame_size = frame_size; |
| 1118 surface_info->device_scale_factor = device_scale_factor; | 1272 surface_info->device_scale_factor = device_scale_factor; |
| 1119 WindowPrivate(window).LocalSetSurfaceId(std::move(surface_info)); | 1273 window->SetSurfaceIdFromServer(std::move(surface_info)); |
| 1120 } | 1274 } |
| 1121 | 1275 |
| 1122 void WindowTreeClient::OnDragDropStart( | 1276 void WindowTreeClient::OnDragDropStart( |
| 1123 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { | 1277 mojo::Map<mojo::String, mojo::Array<uint8_t>> mime_data) { |
| 1124 mime_drag_data_ = std::move(mime_data); | 1278 mime_drag_data_ = std::move(mime_data); |
| 1125 } | 1279 } |
| 1126 | 1280 |
| 1127 void WindowTreeClient::OnDragEnter(Id window_id, | 1281 void WindowTreeClient::OnDragEnter(Id window_id, |
| 1128 uint32_t key_state, | 1282 uint32_t key_state, |
| 1129 const gfx::Point& position, | 1283 const gfx::Point& position, |
| 1130 uint32_t effect_bitmask, | 1284 uint32_t effect_bitmask, |
| 1131 const OnDragEnterCallback& callback) { | 1285 const OnDragEnterCallback& callback) { |
| 1286 // TODO: dnd. | |
| 1287 /* | |
| 1132 Window* window = GetWindowByServerId(window_id); | 1288 Window* window = GetWindowByServerId(window_id); |
| 1133 if (!window || !window->drop_target()) { | 1289 if (!window || !window->drop_target()) { |
| 1134 callback.Run(mojom::kDropEffectNone); | 1290 callback.Run(ui::mojom::kDropEffectNone); |
| 1135 return; | 1291 return; |
| 1136 } | 1292 } |
| 1137 | 1293 |
| 1138 if (!base::ContainsKey(drag_entered_windows_, window_id)) { | 1294 if (!base::ContainsKey(drag_entered_windows_, window_id)) { |
| 1139 window->drop_target()->OnDragDropStart( | 1295 window->drop_target()->OnDragDropStart( |
| 1140 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>()); | 1296 mime_drag_data_.To<std::map<std::string, std::vector<uint8_t>>>()); |
| 1141 drag_entered_windows_.insert(window_id); | 1297 drag_entered_windows_.insert(window_id); |
| 1142 } | 1298 } |
| 1143 | 1299 |
| 1144 uint32_t ret = | 1300 uint32_t ret = |
| 1145 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); | 1301 window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); |
| 1146 callback.Run(ret); | 1302 callback.Run(ret); |
| 1303 */ | |
| 1147 } | 1304 } |
| 1148 | 1305 |
| 1149 void WindowTreeClient::OnDragOver(Id window_id, | 1306 void WindowTreeClient::OnDragOver(Id window_id, |
| 1150 uint32_t key_state, | 1307 uint32_t key_state, |
| 1151 const gfx::Point& position, | 1308 const gfx::Point& position, |
| 1152 uint32_t effect_bitmask, | 1309 uint32_t effect_bitmask, |
| 1153 const OnDragOverCallback& callback) { | 1310 const OnDragOverCallback& callback) { |
| 1311 // TODO: dnd. | |
| 1312 /* | |
| 1154 Window* window = GetWindowByServerId(window_id); | 1313 Window* window = GetWindowByServerId(window_id); |
| 1155 if (!window || !window->drop_target()) { | 1314 if (!window || !window->drop_target()) { |
| 1156 callback.Run(mojom::kDropEffectNone); | 1315 callback.Run(ui::mojom::kDropEffectNone); |
| 1157 return; | 1316 return; |
| 1158 } | 1317 } |
| 1159 | 1318 |
| 1160 uint32_t ret = | 1319 uint32_t ret = |
| 1161 window->drop_target()->OnDragOver(key_state, position, effect_bitmask); | 1320 window->drop_target()->OnDragOver(key_state, position, effect_bitmask); |
| 1162 callback.Run(ret); | 1321 callback.Run(ret); |
| 1322 */ | |
| 1163 } | 1323 } |
| 1164 | 1324 |
| 1165 void WindowTreeClient::OnDragLeave(Id window_id) { | 1325 void WindowTreeClient::OnDragLeave(Id window_id) { |
| 1326 // TODO: dnd. | |
| 1327 /* | |
| 1166 Window* window = GetWindowByServerId(window_id); | 1328 Window* window = GetWindowByServerId(window_id); |
| 1167 if (!window || !window->drop_target()) | 1329 if (!window || !window->drop_target()) |
| 1168 return; | 1330 return; |
| 1169 | 1331 |
| 1170 window->drop_target()->OnDragLeave(); | 1332 window->drop_target()->OnDragLeave(); |
| 1333 */ | |
| 1171 } | 1334 } |
| 1172 | 1335 |
| 1173 void WindowTreeClient::OnDragDropDone() { | 1336 void WindowTreeClient::OnDragDropDone() { |
| 1337 // TODO: dnd. | |
| 1338 /* | |
| 1174 for (Id id : drag_entered_windows_) { | 1339 for (Id id : drag_entered_windows_) { |
| 1175 Window* window = GetWindowByServerId(id); | 1340 Window* window = GetWindowByServerId(id); |
| 1176 if (!window || !window->drop_target()) | 1341 if (!window || !window->drop_target()) |
| 1177 continue; | 1342 continue; |
| 1178 window->drop_target()->OnDragDropDone(); | 1343 window->drop_target()->OnDragDropDone(); |
| 1179 } | 1344 } |
| 1180 drag_entered_windows_.clear(); | 1345 drag_entered_windows_.clear(); |
| 1346 */ | |
| 1181 } | 1347 } |
| 1182 | 1348 |
| 1183 void WindowTreeClient::OnCompleteDrop(Id window_id, | 1349 void WindowTreeClient::OnCompleteDrop(Id window_id, |
| 1184 uint32_t key_state, | 1350 uint32_t key_state, |
| 1185 const gfx::Point& position, | 1351 const gfx::Point& position, |
| 1186 uint32_t effect_bitmask, | 1352 uint32_t effect_bitmask, |
| 1187 const OnCompleteDropCallback& callback) { | 1353 const OnCompleteDropCallback& callback) { |
| 1354 // TODO: dnd. | |
| 1355 /* | |
| 1188 Window* window = GetWindowByServerId(window_id); | 1356 Window* window = GetWindowByServerId(window_id); |
| 1189 if (!window || !window->drop_target()) { | 1357 if (!window || !window->drop_target()) { |
| 1190 callback.Run(mojom::kDropEffectNone); | 1358 callback.Run(ui::mojom::kDropEffectNone); |
| 1191 return; | 1359 return; |
| 1192 } | 1360 } |
| 1193 | 1361 |
| 1194 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, | 1362 uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, |
| 1195 effect_bitmask); | 1363 effect_bitmask); |
| 1196 callback.Run(ret); | 1364 callback.Run(ret); |
| 1365 */ | |
| 1197 } | 1366 } |
| 1198 | 1367 |
| 1199 void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, | 1368 void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, |
| 1200 bool success, | 1369 bool success, |
| 1201 uint32_t action_taken) { | 1370 uint32_t action_taken) { |
| 1371 // TODO: dnd. | |
| 1372 /* | |
| 1202 if (current_drag_state_ && change_id == current_drag_state_->change_id) { | 1373 if (current_drag_state_ && change_id == current_drag_state_->change_id) { |
| 1203 current_drag_state_->completed_action = action_taken; | 1374 current_drag_state_->completed_action = action_taken; |
| 1204 OnChangeCompleted(change_id, success); | 1375 OnChangeCompleted(change_id, success); |
| 1205 } | 1376 } |
| 1377 */ | |
| 1206 } | 1378 } |
| 1207 | 1379 |
| 1208 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { | 1380 void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| 1209 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); | 1381 std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| 1210 in_flight_map_.erase(change_id); | 1382 in_flight_map_.erase(change_id); |
| 1211 if (!change) | 1383 if (!change) |
| 1212 return; | 1384 return; |
| 1213 | 1385 |
| 1214 if (!success) | 1386 if (!success) |
| 1215 change->ChangeFailed(); | 1387 change->ChangeFailed(); |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 1233 | 1405 |
| 1234 current_drag_state_->on_finished.Run(success, | 1406 current_drag_state_->on_finished.Run(success, |
| 1235 current_drag_state_->completed_action); | 1407 current_drag_state_->completed_action); |
| 1236 current_drag_state_.reset(); | 1408 current_drag_state_.reset(); |
| 1237 } | 1409 } |
| 1238 } | 1410 } |
| 1239 | 1411 |
| 1240 void WindowTreeClient::GetWindowManager( | 1412 void WindowTreeClient::GetWindowManager( |
| 1241 mojo::AssociatedInterfaceRequest<WindowManager> internal) { | 1413 mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| 1242 window_manager_internal_.reset( | 1414 window_manager_internal_.reset( |
| 1243 new mojo::AssociatedBinding<mojom::WindowManager>(this, | 1415 new mojo::AssociatedBinding<ui::mojom::WindowManager>( |
| 1244 std::move(internal))); | 1416 this, std::move(internal))); |
| 1245 } | 1417 } |
| 1246 | 1418 |
| 1247 void WindowTreeClient::RequestClose(uint32_t window_id) { | 1419 void WindowTreeClient::RequestClose(uint32_t window_id) { |
| 1248 Window* window = GetWindowByServerId(window_id); | 1420 WindowMus* window = GetWindowByServerId(window_id); |
| 1249 if (!window || !IsRoot(window)) | 1421 if (!window || !IsRoot(window)) |
| 1250 return; | 1422 return; |
| 1251 | 1423 |
| 1252 for (auto& observer : *WindowPrivate(window).observers()) | 1424 window->GetWindow()->delegate()->OnRequestClose(); |
| 1253 observer.OnRequestClose(window); | |
| 1254 } | 1425 } |
| 1255 | 1426 |
| 1256 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { | 1427 void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| 1257 client_id_ = client_id; | 1428 client_id_ = client_id; |
| 1258 } | 1429 } |
| 1259 | 1430 |
| 1260 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, | 1431 void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
| 1261 mojom::WindowDataPtr root_data, | 1432 ui::mojom::WindowDataPtr root_data, |
| 1262 bool parent_drawn) { | 1433 bool parent_drawn) { |
| 1263 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); | 1434 WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
| 1264 } | 1435 } |
| 1265 | 1436 |
| 1266 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { | 1437 void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
| 1267 DCHECK(window_manager_delegate_); | 1438 DCHECK(window_manager_delegate_); |
| 1268 | 1439 // TODO: route to WindowTreeHost. |
| 1440 /* | |
| 1269 for (Window* root : roots_) { | 1441 for (Window* root : roots_) { |
| 1270 if (root->display_id() == display_id) { | 1442 if (root->display_id() == display_id) { |
| 1271 window_manager_delegate_->OnWmDisplayRemoved(root); | 1443 window_manager_delegate_->OnWmDisplayRemoved(root); |
| 1272 return; | 1444 return; |
| 1273 } | 1445 } |
| 1274 } | 1446 } |
| 1447 */ | |
| 1275 } | 1448 } |
| 1276 | 1449 |
| 1277 void WindowTreeClient::WmDisplayModified(const display::Display& display) { | 1450 void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| 1278 DCHECK(window_manager_delegate_); | 1451 DCHECK(window_manager_delegate_); |
| 1452 // TODO(sky): this should likely route to WindowTreeHost. | |
| 1279 window_manager_delegate_->OnWmDisplayModified(display); | 1453 window_manager_delegate_->OnWmDisplayModified(display); |
| 1280 } | 1454 } |
| 1281 | 1455 |
| 1282 void WindowTreeClient::WmSetBounds(uint32_t change_id, | 1456 void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| 1283 Id window_id, | 1457 Id window_id, |
| 1284 const gfx::Rect& transit_bounds) { | 1458 const gfx::Rect& transit_bounds) { |
| 1285 Window* window = GetWindowByServerId(window_id); | 1459 WindowMus* window = GetWindowByServerId(window_id); |
| 1286 bool result = false; | 1460 bool result = false; |
| 1287 if (window) { | 1461 if (window) { |
| 1288 DCHECK(window_manager_delegate_); | 1462 DCHECK(window_manager_delegate_); |
| 1289 gfx::Rect bounds = transit_bounds; | 1463 gfx::Rect bounds = transit_bounds; |
| 1290 result = window_manager_delegate_->OnWmSetBounds(window, &bounds); | 1464 // TODO: this needs to trigger scheduling a bounds change on |window|. |
| 1465 result = | |
| 1466 window_manager_delegate_->OnWmSetBounds(window->GetWindow(), &bounds); | |
| 1291 if (result) { | 1467 if (result) { |
| 1292 // If the resulting bounds differ return false. Returning false ensures | 1468 // If the resulting bounds differ return false. Returning false ensures |
| 1293 // the client applies the bounds we set below. | 1469 // the client applies the bounds we set below. |
| 1294 result = bounds == transit_bounds; | 1470 result = bounds == transit_bounds; |
| 1295 window->SetBounds(bounds); | 1471 window->SetBoundsFromServer(bounds); |
| 1296 } | 1472 } |
| 1297 } | 1473 } |
| 1298 if (window_manager_internal_client_) | 1474 if (window_manager_internal_client_) |
| 1299 window_manager_internal_client_->WmResponse(change_id, result); | 1475 window_manager_internal_client_->WmResponse(change_id, result); |
| 1300 } | 1476 } |
| 1301 | 1477 |
| 1302 void WindowTreeClient::WmSetProperty(uint32_t change_id, | 1478 void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| 1303 Id window_id, | 1479 Id window_id, |
| 1304 const mojo::String& name, | 1480 const mojo::String& name, |
| 1305 mojo::Array<uint8_t> transit_data) { | 1481 mojo::Array<uint8_t> transit_data) { |
| 1306 Window* window = GetWindowByServerId(window_id); | 1482 WindowMus* window = GetWindowByServerId(window_id); |
| 1307 bool result = false; | 1483 bool result = false; |
| 1308 if (window) { | 1484 if (window) { |
| 1485 // TODO: map properties. | |
| 1309 DCHECK(window_manager_delegate_); | 1486 DCHECK(window_manager_delegate_); |
| 1310 std::unique_ptr<std::vector<uint8_t>> data; | 1487 std::unique_ptr<std::vector<uint8_t>> data; |
| 1311 if (!transit_data.is_null()) { | 1488 if (!transit_data.is_null()) { |
| 1312 data.reset( | 1489 data.reset( |
| 1313 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); | 1490 new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); |
| 1314 } | 1491 } |
| 1315 result = window_manager_delegate_->OnWmSetProperty(window, name, &data); | 1492 result = window_manager_delegate_->OnWmSetProperty(window->GetWindow(), |
| 1493 name, &data); | |
| 1316 if (result) { | 1494 if (result) { |
| 1317 // If the resulting bounds differ return false. Returning false ensures | 1495 delegate_->GetPropertyConverter()->SetPropertyFromTransportValue( |
| 1318 // the client applies the bounds we set below. | 1496 window->GetWindow(), name, data.get()); |
| 1319 window->SetSharedPropertyInternal(name, data.get()); | |
| 1320 } | 1497 } |
| 1321 } | 1498 } |
| 1322 if (window_manager_internal_client_) | 1499 if (window_manager_internal_client_) |
| 1323 window_manager_internal_client_->WmResponse(change_id, result); | 1500 window_manager_internal_client_->WmResponse(change_id, result); |
| 1324 } | 1501 } |
| 1325 | 1502 |
| 1326 void WindowTreeClient::WmCreateTopLevelWindow( | 1503 void WindowTreeClient::WmCreateTopLevelWindow( |
| 1327 uint32_t change_id, | 1504 uint32_t change_id, |
| 1328 ClientSpecificId requesting_client_id, | 1505 ClientSpecificId requesting_client_id, |
| 1329 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { | 1506 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties) { |
| 1330 std::map<std::string, std::vector<uint8_t>> properties = | 1507 std::map<std::string, std::vector<uint8_t>> properties = |
| 1331 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 1508 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 1332 Window* window = | 1509 Window* window = |
| 1333 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); | 1510 window_manager_delegate_->OnWmCreateTopLevelWindow(&properties); |
| 1334 embedded_windows_[requesting_client_id].insert(window); | 1511 embedded_windows_[requesting_client_id].insert(window); |
| 1335 if (window_manager_internal_client_) { | 1512 if (window_manager_internal_client_) { |
| 1336 window_manager_internal_client_->OnWmCreatedTopLevelWindow( | 1513 window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| 1337 change_id, server_id(window)); | 1514 change_id, WindowMus::Get(window)->server_id()); |
| 1338 } | 1515 } |
| 1339 } | 1516 } |
| 1340 | 1517 |
| 1341 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, | 1518 void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| 1342 bool janky) { | 1519 bool janky) { |
| 1343 if (window_manager_delegate_) { | 1520 if (window_manager_delegate_) { |
| 1344 auto it = embedded_windows_.find(client_id); | 1521 auto it = embedded_windows_.find(client_id); |
| 1345 CHECK(it != embedded_windows_.end()); | 1522 CHECK(it != embedded_windows_.end()); |
| 1346 window_manager_delegate_->OnWmClientJankinessChanged( | 1523 window_manager_delegate_->OnWmClientJankinessChanged( |
| 1347 embedded_windows_[client_id], janky); | 1524 embedded_windows_[client_id], janky); |
| 1348 } | 1525 } |
| 1349 } | 1526 } |
| 1350 | 1527 |
| 1351 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, | 1528 void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, |
| 1352 Id window_id, | 1529 Id window_id, |
| 1353 mojom::MoveLoopSource source, | 1530 ui::mojom::MoveLoopSource source, |
| 1354 const gfx::Point& cursor_location) { | 1531 const gfx::Point& cursor_location) { |
| 1355 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) { | 1532 if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) { |
| 1356 OnWmMoveLoopCompleted(change_id, false); | 1533 OnWmMoveLoopCompleted(change_id, false); |
| 1357 return; | 1534 return; |
| 1358 } | 1535 } |
| 1359 | 1536 |
| 1360 current_wm_move_loop_change_ = change_id; | 1537 current_wm_move_loop_change_ = change_id; |
| 1361 current_wm_move_loop_window_id_ = window_id; | 1538 current_wm_move_loop_window_id_ = window_id; |
| 1362 Window* window = GetWindowByServerId(window_id); | 1539 WindowMus* window = GetWindowByServerId(window_id); |
| 1363 if (window) { | 1540 if (window) { |
| 1364 window_manager_delegate_->OnWmPerformMoveLoop( | 1541 window_manager_delegate_->OnWmPerformMoveLoop( |
| 1365 window, source, cursor_location, | 1542 window->GetWindow(), source, cursor_location, |
| 1366 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted, | 1543 base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted, |
| 1367 weak_factory_.GetWeakPtr(), change_id)); | 1544 weak_factory_.GetWeakPtr(), change_id)); |
| 1368 } else { | 1545 } else { |
| 1369 OnWmMoveLoopCompleted(change_id, false); | 1546 OnWmMoveLoopCompleted(change_id, false); |
| 1370 } | 1547 } |
| 1371 } | 1548 } |
| 1372 | 1549 |
| 1373 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) { | 1550 void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) { |
| 1374 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_) | 1551 if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_) |
| 1375 return; | 1552 return; |
| 1376 | 1553 |
| 1377 Window* window = GetWindowByServerId(current_wm_move_loop_window_id_); | 1554 WindowMus* window = GetWindowByServerId(current_wm_move_loop_window_id_); |
| 1378 if (window) | 1555 if (window) |
| 1379 window_manager_delegate_->OnWmCancelMoveLoop(window); | 1556 window_manager_delegate_->OnWmCancelMoveLoop(window->GetWindow()); |
| 1380 } | 1557 } |
| 1381 | 1558 |
| 1382 void WindowTreeClient::OnAccelerator(uint32_t ack_id, | 1559 void WindowTreeClient::OnAccelerator(uint32_t ack_id, |
| 1383 uint32_t accelerator_id, | 1560 uint32_t accelerator_id, |
| 1384 std::unique_ptr<ui::Event> event) { | 1561 std::unique_ptr<ui::Event> event) { |
| 1385 DCHECK(event); | 1562 DCHECK(event); |
| 1386 const mojom::EventResult result = | 1563 const ui::mojom::EventResult result = |
| 1387 window_manager_delegate_->OnAccelerator(accelerator_id, *event.get()); | 1564 window_manager_delegate_->OnAccelerator(accelerator_id, *event.get()); |
| 1388 if (ack_id && window_manager_internal_client_) | 1565 if (ack_id && window_manager_internal_client_) |
| 1389 window_manager_internal_client_->OnAcceleratorAck(ack_id, result); | 1566 window_manager_internal_client_->OnAcceleratorAck(ack_id, result); |
| 1390 } | 1567 } |
| 1391 | 1568 |
| 1392 void WindowTreeClient::SetFrameDecorationValues( | 1569 void WindowTreeClient::SetFrameDecorationValues( |
| 1393 mojom::FrameDecorationValuesPtr values) { | 1570 ui::mojom::FrameDecorationValuesPtr values) { |
| 1394 if (window_manager_internal_client_) { | 1571 if (window_manager_internal_client_) { |
| 1395 window_manager_internal_client_->WmSetFrameDecorationValues( | 1572 window_manager_internal_client_->WmSetFrameDecorationValues( |
| 1396 std::move(values)); | 1573 std::move(values)); |
| 1397 } | 1574 } |
| 1398 } | 1575 } |
| 1399 | 1576 |
| 1400 void WindowTreeClient::SetNonClientCursor(Window* window, | 1577 void WindowTreeClient::SetNonClientCursor(Window* window, |
| 1401 ui::mojom::Cursor cursor_id) { | 1578 ui::mojom::Cursor cursor_id) { |
| 1402 window_manager_internal_client_->WmSetNonClientCursor(server_id(window), | 1579 window_manager_internal_client_->WmSetNonClientCursor( |
| 1403 cursor_id); | 1580 WindowMus::Get(window)->server_id(), cursor_id); |
| 1404 } | 1581 } |
| 1405 | 1582 |
| 1406 void WindowTreeClient::AddAccelerator( | 1583 void WindowTreeClient::AddAccelerator( |
| 1407 uint32_t id, | 1584 uint32_t id, |
| 1408 mojom::EventMatcherPtr event_matcher, | 1585 ui::mojom::EventMatcherPtr event_matcher, |
| 1409 const base::Callback<void(bool)>& callback) { | 1586 const base::Callback<void(bool)>& callback) { |
| 1410 if (window_manager_internal_client_) { | 1587 if (window_manager_internal_client_) { |
| 1411 window_manager_internal_client_->AddAccelerator( | 1588 window_manager_internal_client_->AddAccelerator( |
| 1412 id, std::move(event_matcher), callback); | 1589 id, std::move(event_matcher), callback); |
| 1413 } | 1590 } |
| 1414 } | 1591 } |
| 1415 | 1592 |
| 1416 void WindowTreeClient::RemoveAccelerator(uint32_t id) { | 1593 void WindowTreeClient::RemoveAccelerator(uint32_t id) { |
| 1417 if (window_manager_internal_client_) { | 1594 if (window_manager_internal_client_) { |
| 1418 window_manager_internal_client_->RemoveAccelerator(id); | 1595 window_manager_internal_client_->RemoveAccelerator(id); |
| 1419 } | 1596 } |
| 1420 } | 1597 } |
| 1421 | 1598 |
| 1422 void WindowTreeClient::AddActivationParent(Window* window) { | 1599 void WindowTreeClient::AddActivationParent(Window* window) { |
| 1423 if (window_manager_internal_client_) | 1600 if (window_manager_internal_client_) { |
| 1424 window_manager_internal_client_->AddActivationParent(server_id(window)); | 1601 window_manager_internal_client_->AddActivationParent( |
| 1602 WindowMus::Get(window)->server_id()); | |
| 1603 } | |
| 1425 } | 1604 } |
| 1426 | 1605 |
| 1427 void WindowTreeClient::RemoveActivationParent(Window* window) { | 1606 void WindowTreeClient::RemoveActivationParent(Window* window) { |
| 1428 if (window_manager_internal_client_) | 1607 if (window_manager_internal_client_) { |
| 1429 window_manager_internal_client_->RemoveActivationParent(server_id(window)); | 1608 window_manager_internal_client_->RemoveActivationParent( |
| 1609 WindowMus::Get(window)->server_id()); | |
| 1610 } | |
| 1430 } | 1611 } |
| 1431 | 1612 |
| 1432 void WindowTreeClient::ActivateNextWindow() { | 1613 void WindowTreeClient::ActivateNextWindow() { |
| 1433 if (window_manager_internal_client_) | 1614 if (window_manager_internal_client_) |
| 1434 window_manager_internal_client_->ActivateNextWindow(); | 1615 window_manager_internal_client_->ActivateNextWindow(); |
| 1435 } | 1616 } |
| 1436 | 1617 |
| 1437 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1618 void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1438 Window* window, | 1619 Window* window, |
| 1439 const gfx::Vector2d& offset, | 1620 const gfx::Vector2d& offset, |
| 1440 const gfx::Insets& hit_area) { | 1621 const gfx::Insets& hit_area) { |
| 1441 if (window_manager_internal_client_) { | 1622 if (window_manager_internal_client_) { |
| 1442 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( | 1623 window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| 1443 server_id(window), offset.x(), offset.y(), hit_area); | 1624 WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); |
| 1444 } | 1625 } |
| 1445 } | 1626 } |
| 1446 | 1627 |
| 1447 } // namespace ui | 1628 void WindowTreeClient::OnWindowFocused(Window* gained_focus, |
| 1629 Window* lost_focus) { | |
| 1630 WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); | |
| 1631 if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { | |
| 1632 focused_window_ = gained_focus_mus; | |
| 1633 return; | |
| 1634 } | |
| 1635 | |
| 1636 const uint32_t change_id = ScheduleInFlightChange( | |
| 1637 base::MakeUnique<InFlightFocusChange>(this, focused_window_)); | |
| 1638 focused_window_ = gained_focus_mus; | |
| 1639 tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() | |
| 1640 : kInvalidServerId); | |
| 1641 } | |
| 1642 | |
| 1643 void WindowTreeClient::OnCaptureChanged(Window* lost_capture, | |
| 1644 Window* gained_capture) { | |
| 1645 WindowMus* gained_capture_mus = WindowMus::Get(gained_capture); | |
| 1646 if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) { | |
| 1647 capture_window_ = gained_capture_mus; | |
| 1648 return; | |
| 1649 } | |
| 1650 | |
| 1651 const uint32_t change_id = ScheduleInFlightChange( | |
| 1652 base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); | |
| 1653 WindowMus* old_capture_window = capture_window_; | |
| 1654 capture_window_ = gained_capture_mus; | |
| 1655 if (capture_window_) | |
| 1656 tree_->SetCapture(change_id, capture_window_->server_id()); | |
| 1657 else | |
| 1658 tree_->ReleaseCapture(change_id, old_capture_window->server_id()); | |
| 1659 } | |
| 1660 | |
| 1661 } // namespace aura | |
| OLD | NEW |