Chromium Code Reviews| Index: ui/aura/mus/window_tree_client.cc |
| diff --git a/services/ui/public/cpp/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc |
| similarity index 51% |
| copy from services/ui/public/cpp/window_tree_client.cc |
| copy to ui/aura/mus/window_tree_client.cc |
| index 11e73b05533d8f45fb7c94dd285dadeb1e01723d..2b362f0cb5530a7076ebb3cb90a697eea803ce08 100644 |
| --- a/services/ui/public/cpp/window_tree_client.cc |
| +++ b/ui/aura/mus/window_tree_client.cc |
| @@ -2,7 +2,7 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| -#include "services/ui/public/cpp/window_tree_client.h" |
| +#include "ui/aura/mus/window_tree_client.h" |
| #include <stddef.h> |
| @@ -10,52 +10,113 @@ |
| #include <utility> |
| #include <vector> |
| +#include "base/auto_reset.h" |
| #include "base/bind.h" |
| #include "base/memory/ptr_util.h" |
| #include "services/service_manager/public/cpp/connector.h" |
| -#include "services/ui/common/util.h" |
| -#include "services/ui/public/cpp/in_flight_change.h" |
| -#include "services/ui/public/cpp/input_event_handler.h" |
| -#include "services/ui/public/cpp/surface_id_handler.h" |
| -#include "services/ui/public/cpp/window_drop_target.h" |
| -#include "services/ui/public/cpp/window_manager_delegate.h" |
| -#include "services/ui/public/cpp/window_observer.h" |
| -#include "services/ui/public/cpp/window_private.h" |
| -#include "services/ui/public/cpp/window_tracker.h" |
| -#include "services/ui/public/cpp/window_tree_client_delegate.h" |
| -#include "services/ui/public/cpp/window_tree_client_observer.h" |
| #include "services/ui/public/interfaces/window_manager_window_tree_factory.mojom.h" |
| +#include "ui/aura/client/aura_constants.h" |
| +#include "ui/aura/client/capture_client.h" |
| +#include "ui/aura/client/focus_client.h" |
| +#include "ui/aura/mus/in_flight_change.h" |
| +#include "ui/aura/mus/input_method_mus.h" |
| +#include "ui/aura/mus/property_converter.h" |
| +#include "ui/aura/mus/surface_id_handler.h" |
| +#include "ui/aura/mus/window_manager_delegate.h" |
| +#include "ui/aura/mus/window_mus.h" |
| +#include "ui/aura/mus/window_port_mus.h" |
| +#include "ui/aura/mus/window_tree_client_delegate.h" |
| +#include "ui/aura/mus/window_tree_client_observer.h" |
| +#include "ui/aura/mus/window_tree_host_mus.h" |
| +#include "ui/aura/window.h" |
| +#include "ui/aura/window_delegate.h" |
| +#include "ui/aura/window_tracker.h" |
| #include "ui/events/event.h" |
| #include "ui/gfx/geometry/insets.h" |
| #include "ui/gfx/geometry/size.h" |
| -namespace ui { |
| +#if defined(HiWord) |
| +#undef HiWord |
| +#endif |
| +#if defined(LoWord) |
| +#undef LoWord |
| +#endif |
| + |
| +namespace aura { |
| +namespace { |
| Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) { |
| return (client_id << 16) | local_id; |
| } |
| -// Helper called to construct a local window object from transport data. |
| -Window* AddWindowToClient(WindowTreeClient* client, |
| - Window* parent, |
| - const mojom::WindowDataPtr& window_data) { |
| - // We don't use the ctor that takes a WindowTreeClient here, since it will |
| - // call back to the service and attempt to create a new window. |
| - Window* window = WindowPrivate::LocalCreate(); |
| - WindowPrivate private_window(window); |
| - private_window.set_client(client); |
| - private_window.set_server_id(window_data->window_id); |
| - private_window.set_visible(window_data->visible); |
| - private_window.set_properties( |
| - window_data->properties |
| - .To<std::map<std::string, std::vector<uint8_t>>>()); |
| - client->AddWindow(window); |
| - private_window.LocalSetBounds(gfx::Rect(), window_data->bounds); |
| - if (parent) |
| - WindowPrivate(parent).LocalAddChild(window); |
| - return window; |
| +bool ShouldCreateTopLevel(ui::wm::WindowType type) { |
| + switch (type) { |
| + case ui::wm::WINDOW_TYPE_CONTROL: |
| + case ui::wm::WINDOW_TYPE_UNKNOWN: |
| + return false; |
| + |
| + case ui::wm::WINDOW_TYPE_NORMAL: |
| + case ui::wm::WINDOW_TYPE_POPUP: |
| + case ui::wm::WINDOW_TYPE_PANEL: |
| + case ui::wm::WINDOW_TYPE_MENU: |
| + case ui::wm::WINDOW_TYPE_TOOLTIP: |
| + break; |
| + } |
| + return true; |
| } |
| +inline uint16_t HiWord(uint32_t id) { |
| + return static_cast<uint16_t>((id >> 16) & 0xFFFF); |
| +} |
| + |
| +inline uint16_t LoWord(uint32_t id) { |
| + return static_cast<uint16_t>(id & 0xFFFF); |
| +} |
| + |
| +struct WindowPortPropertyDataMus : public WindowPortPropertyData { |
| + std::string transport_name; |
| + std::unique_ptr<std::vector<uint8_t>> transport_value; |
| +}; |
| + |
| +// Handles acknowledgment of an input event, either immediately when a nested |
| +// message loop starts, or upon destruction. |
| +class EventAckHandler : public base::MessageLoop::NestingObserver { |
| + public: |
| + explicit EventAckHandler(std::unique_ptr<EventResultCallback> ack_callback) |
| + : ack_callback_(std::move(ack_callback)) { |
| + DCHECK(ack_callback_); |
| + base::MessageLoop::current()->AddNestingObserver(this); |
| + } |
| + |
| + ~EventAckHandler() override { |
| + base::MessageLoop::current()->RemoveNestingObserver(this); |
| + if (ack_callback_) { |
| + ack_callback_->Run(handled_ ? ui::mojom::EventResult::HANDLED |
| + : ui::mojom::EventResult::UNHANDLED); |
| + } |
| + } |
| + |
| + void set_handled(bool handled) { handled_ = handled; } |
| + |
| + // base::MessageLoop::NestingObserver: |
| + void OnBeginNestedMessageLoop() override { |
| + // Acknowledge the event immediately if a nested message loop starts. |
| + // Otherwise we appear unresponsive for the life of the nested message loop. |
| + if (ack_callback_) { |
| + ack_callback_->Run(ui::mojom::EventResult::HANDLED); |
| + ack_callback_.reset(); |
| + } |
| + } |
| + |
| + private: |
| + std::unique_ptr<EventResultCallback> ack_callback_; |
| + bool handled_ = false; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(EventAckHandler); |
| +}; |
| + |
| +} // namespace |
| + |
| struct WindowTreeClient::CurrentDragState { |
| // The current change id of the current drag an drop ipc. |
| uint32_t change_id; |
| @@ -70,14 +131,12 @@ struct WindowTreeClient::CurrentDragState { |
| WindowTreeClient::WindowTreeClient( |
| WindowTreeClientDelegate* delegate, |
| WindowManagerDelegate* window_manager_delegate, |
| - mojo::InterfaceRequest<mojom::WindowTreeClient> request) |
| + mojo::InterfaceRequest<ui::mojom::WindowTreeClient> request) |
| : client_id_(0), |
| next_window_id_(1), |
| next_change_id_(1), |
| delegate_(delegate), |
| window_manager_delegate_(window_manager_delegate), |
| - capture_window_(nullptr), |
| - focused_window_(nullptr), |
| binding_(this), |
| tree_(nullptr), |
| in_destructor_(false), |
| @@ -85,6 +144,8 @@ WindowTreeClient::WindowTreeClient( |
| // Allow for a null request in tests. |
| if (request.is_pending()) |
| binding_.Bind(std::move(request)); |
| + delegate_->GetFocusClient()->AddObserver(this); |
| + delegate_->GetCaptureClient()->AddObserver(this); |
| if (window_manager_delegate) |
| window_manager_delegate->SetWindowManagerClient(this); |
| } |
| @@ -92,17 +153,19 @@ WindowTreeClient::WindowTreeClient( |
| WindowTreeClient::~WindowTreeClient() { |
| in_destructor_ = true; |
| - for (auto& observer : observers_) |
| + for (WindowTreeClientObserver& observer : observers_) |
| observer.OnWillDestroyClient(this); |
| std::vector<Window*> non_owned; |
| WindowTracker tracker; |
| while (!windows_.empty()) { |
| IdToWindowMap::iterator it = windows_.begin(); |
| - if (it->second->WasCreatedByThisClient()) { |
| - it->second->Destroy(); |
| + if (WasCreatedByThisClient(it->second)) { |
| + const Id window_id = it->second->server_id(); |
| + delete it->second->GetWindow(); |
| + DCHECK_EQ(0u, windows_.count(window_id)); |
| } else { |
| - tracker.Add(it->second); |
| + tracker.Add(it->second->GetWindow()); |
| windows_.erase(it); |
| } |
| } |
| @@ -110,12 +173,14 @@ WindowTreeClient::~WindowTreeClient() { |
| // Delete the non-owned windows last. In the typical case these are roots. The |
| // exception is the window manager and embed roots, which may know about |
| // other random windows that it doesn't own. |
| - // NOTE: we manually delete as we're a friend. |
| while (!tracker.windows().empty()) |
| delete tracker.windows().front(); |
| - for (auto& observer : observers_) |
| + for (WindowTreeClientObserver& observer : observers_) |
| observer.OnDidDestroyClient(this); |
| + |
| + delegate_->GetFocusClient()->RemoveObserver(this); |
| + delegate_->GetCaptureClient()->RemoveObserver(this); |
| } |
| void WindowTreeClient::ConnectViaWindowTreeFactory( |
| @@ -123,9 +188,9 @@ void WindowTreeClient::ConnectViaWindowTreeFactory( |
| // The client id doesn't really matter, we use 101 purely for debugging. |
| client_id_ = 101; |
| - mojom::WindowTreeFactoryPtr factory; |
| + ui::mojom::WindowTreeFactoryPtr factory; |
| connector->ConnectToInterface("service:ui", &factory); |
| - mojom::WindowTreePtr window_tree; |
| + ui::mojom::WindowTreePtr window_tree; |
| factory->CreateWindowTree(GetProxy(&window_tree), |
| binding_.CreateInterfacePtrAndBind()); |
| SetWindowTree(std::move(window_tree)); |
| @@ -135,9 +200,9 @@ void WindowTreeClient::ConnectAsWindowManager( |
| service_manager::Connector* connector) { |
| DCHECK(window_manager_delegate_); |
| - mojom::WindowManagerWindowTreeFactoryPtr factory; |
| + ui::mojom::WindowManagerWindowTreeFactoryPtr factory; |
| connector->ConnectToInterface("service:ui", &factory); |
| - mojom::WindowTreePtr window_tree; |
| + ui::mojom::WindowTreePtr window_tree; |
| factory->CreateWindowTree(GetProxy(&window_tree), |
| binding_.CreateInterfacePtrAndBind()); |
| SetWindowTree(std::move(window_tree)); |
| @@ -150,208 +215,73 @@ void WindowTreeClient::WaitForEmbed() { |
| // TODO(sky): deal with pipe being closed before we get OnEmbed(). |
| } |
| -void WindowTreeClient::DestroyWindow(Window* window) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<CrashInFlightChange>(window, ChangeType::DELETE_WINDOW)); |
| - tree_->DeleteWindow(change_id, server_id(window)); |
| -} |
| - |
| -void WindowTreeClient::AddChild(Window* parent, Id child_id) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| - tree_->AddWindow(change_id, parent->server_id(), child_id); |
| -} |
| - |
| -void WindowTreeClient::RemoveChild(Window* parent, Id child_id) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD)); |
| - tree_->RemoveWindowFromParent(change_id, child_id); |
| -} |
| - |
| -void WindowTreeClient::AddTransientWindow(Window* window, |
| - Id transient_window_id) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = |
| - ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| - window, ChangeType::ADD_TRANSIENT_WINDOW)); |
| - tree_->AddTransientWindow(change_id, server_id(window), transient_window_id); |
| -} |
| - |
| -void WindowTreeClient::RemoveTransientWindowFromParent(Window* window) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = |
| - ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| - window, ChangeType::REMOVE_TRANSIENT_WINDOW_FROM_PARENT)); |
| - tree_->RemoveTransientWindowFromParent(change_id, server_id(window)); |
| -} |
| - |
| -void WindowTreeClient::SetModal(Window* window) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = |
| - ScheduleInFlightChange(base::MakeUnique<InFlightSetModalChange>(window)); |
| - tree_->SetModal(change_id, server_id(window)); |
| -} |
| - |
| -void WindowTreeClient::Reorder(Window* window, |
| - Id relative_window_id, |
| - mojom::OrderDirection direction) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<CrashInFlightChange>(window, ChangeType::REORDER)); |
| - tree_->ReorderWindow(change_id, server_id(window), relative_window_id, |
| - direction); |
| -} |
| - |
| -bool WindowTreeClient::WasCreatedByThisClient(const Window* window) const { |
| - // Windows created via CreateTopLevelWindow() are not owned by us, but have |
| - // our client id. const_cast is required by set. |
| - return HiWord(server_id(window)) == client_id_ && |
| - roots_.count(const_cast<Window*>(window)) == 0; |
| -} |
| - |
| -void WindowTreeClient::SetBounds(Window* window, |
| - const gfx::Rect& old_bounds, |
| - const gfx::Rect& bounds) { |
| - DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); |
| - tree_->SetWindowBounds(change_id, server_id(window), bounds); |
| -} |
| - |
| -void WindowTreeClient::SetCapture(Window* window) { |
| - // In order for us to get here we had to have exposed a window, which implies |
| - // we got a client. |
| - DCHECK(tree_); |
| - if (capture_window_ == window) |
| - return; |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| - tree_->SetCapture(change_id, server_id(window)); |
| - LocalSetCapture(window); |
| -} |
| - |
| -void WindowTreeClient::ReleaseCapture(Window* window) { |
| - // In order for us to get here we had to have exposed a window, which implies |
| - // we got a client. |
| - DCHECK(tree_); |
| - if (capture_window_ != window) |
| - return; |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightCaptureChange>(this, window)); |
| - tree_->ReleaseCapture(change_id, server_id(window)); |
| - LocalSetCapture(nullptr); |
| -} |
| - |
| void WindowTreeClient::SetClientArea( |
| - Id window_id, |
| + Window* window, |
| const gfx::Insets& client_area, |
| const std::vector<gfx::Rect>& additional_client_areas) { |
| DCHECK(tree_); |
| - tree_->SetClientArea(window_id, client_area, additional_client_areas); |
| + tree_->SetClientArea(WindowMus::Get(window)->server_id(), client_area, |
| + additional_client_areas); |
| } |
| -void WindowTreeClient::SetHitTestMask(Id window_id, const gfx::Rect& mask) { |
| +void WindowTreeClient::SetHitTestMask(Window* window, const gfx::Rect& mask) { |
| DCHECK(tree_); |
| - tree_->SetHitTestMask(window_id, mask); |
| + tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), mask); |
| } |
| -void WindowTreeClient::ClearHitTestMask(Id window_id) { |
| +void WindowTreeClient::ClearHitTestMask(Window* window) { |
| DCHECK(tree_); |
| - tree_->SetHitTestMask(window_id, base::nullopt); |
| + tree_->SetHitTestMask(WindowMus::Get(window)->server_id(), base::nullopt); |
| } |
| -void WindowTreeClient::SetFocus(Window* window) { |
| - // In order for us to get here we had to have exposed a window, which implies |
| - // we got a client. |
| +void WindowTreeClient::SetCanFocus(Window* window, bool can_focus) { |
| DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightFocusChange>(this, focused_window_)); |
| - tree_->SetFocus(change_id, window ? server_id(window) : 0); |
| - LocalSetFocus(window); |
| + DCHECK(window); |
| + tree_->SetCanFocus(WindowMus::Get(window)->server_id(), can_focus); |
| } |
| -void WindowTreeClient::SetCanFocus(Id window_id, bool can_focus) { |
| - DCHECK(tree_); |
| - tree_->SetCanFocus(window_id, can_focus); |
| -} |
| - |
| -void WindowTreeClient::SetPredefinedCursor(Id window_id, |
| - ui::mojom::Cursor cursor_id) { |
| +void WindowTreeClient::SetPredefinedCursor(WindowMus* window, |
| + ui::mojom::Cursor old_cursor, |
| + ui::mojom::Cursor new_cursor) { |
| DCHECK(tree_); |
| - Window* window = GetWindowByServerId(window_id); |
| - if (!window) |
| - return; |
| - |
| - // We make an inflight change thing here. |
| - const uint32_t change_id = |
| - ScheduleInFlightChange(base::MakeUnique<InFlightPredefinedCursorChange>( |
| - window, window->predefined_cursor())); |
| - tree_->SetPredefinedCursor(change_id, window_id, cursor_id); |
| -} |
| - |
| -void WindowTreeClient::SetVisible(Window* window, bool visible) { |
| - DCHECK(tree_); |
| const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightVisibleChange>(window, !visible)); |
| - tree_->SetWindowVisibility(change_id, server_id(window), visible); |
| + base::MakeUnique<InFlightPredefinedCursorChange>(window, old_cursor)); |
| + tree_->SetPredefinedCursor(change_id, window->server_id(), new_cursor); |
| } |
| -void WindowTreeClient::SetOpacity(Window* window, float opacity) { |
| +void WindowTreeClient::SetWindowTextInputState(WindowMus* window, |
| + mojo::TextInputStatePtr state) { |
| DCHECK(tree_); |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightOpacityChange>(window, window->opacity())); |
| - tree_->SetWindowOpacity(change_id, server_id(window), opacity); |
| + tree_->SetWindowTextInputState(window->server_id(), std::move(state)); |
| } |
| -void WindowTreeClient::SetProperty(Window* window, |
| - const std::string& name, |
| - mojo::Array<uint8_t> data) { |
| +void WindowTreeClient::SetImeVisibility(WindowMus* window, |
| + bool visible, |
| + mojo::TextInputStatePtr state) { |
| DCHECK(tree_); |
| - |
| - mojo::Array<uint8_t> old_value(nullptr); |
| - if (window->HasSharedProperty(name)) |
| - old_value = mojo::Array<uint8_t>::From(window->properties_[name]); |
| - |
| - const uint32_t change_id = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightPropertyChange>(window, name, old_value)); |
| - tree_->SetWindowProperty(change_id, server_id(window), mojo::String(name), |
| - std::move(data)); |
| + tree_->SetImeVisibility(window->server_id(), visible, std::move(state)); |
| } |
| -void WindowTreeClient::SetWindowTextInputState( |
| +void WindowTreeClient::Embed( |
| Id window_id, |
| - mojo::TextInputStatePtr state) { |
| - DCHECK(tree_); |
| - tree_->SetWindowTextInputState(window_id, std::move(state)); |
| -} |
| - |
| -void WindowTreeClient::SetImeVisibility(Id window_id, |
| - bool visible, |
| - mojo::TextInputStatePtr state) { |
| - DCHECK(tree_); |
| - tree_->SetImeVisibility(window_id, visible, std::move(state)); |
| -} |
| - |
| -void WindowTreeClient::Embed(Id window_id, |
| - mojom::WindowTreeClientPtr client, |
| - uint32_t flags, |
| - const mojom::WindowTree::EmbedCallback& callback) { |
| + ui::mojom::WindowTreeClientPtr client, |
| + uint32_t flags, |
| + const ui::mojom::WindowTree::EmbedCallback& callback) { |
| DCHECK(tree_); |
| tree_->Embed(window_id, std::move(client), flags, callback); |
| } |
| void WindowTreeClient::RequestClose(Window* window) { |
| + DCHECK(window); |
| if (window_manager_internal_client_) |
| - window_manager_internal_client_->WmRequestClose(server_id(window)); |
| + window_manager_internal_client_->WmRequestClose( |
| + WindowMus::Get(window)->server_id()); |
| } |
| void WindowTreeClient::AttachCompositorFrameSink( |
| Id window_id, |
| - mojom::CompositorFrameSinkType type, |
| + ui::mojom::CompositorFrameSinkType type, |
| cc::mojom::MojoCompositorFrameSinkRequest compositor_frame_sink, |
| cc::mojom::MojoCompositorFrameSinkClientPtr client) { |
| DCHECK(tree_); |
| @@ -359,87 +289,66 @@ void WindowTreeClient::AttachCompositorFrameSink( |
| window_id, type, std::move(compositor_frame_sink), std::move(client)); |
| } |
| -void WindowTreeClient::OnWindowSurfaceDetached( |
| - Id window_id, |
| - const cc::SurfaceSequence& sequence) { |
| - DCHECK(tree_); |
| - tree_->OnWindowSurfaceDetached(window_id, sequence); |
| +void WindowTreeClient::RegisterWindowMus(WindowMus* window) { |
| + DCHECK(windows_.find(window->server_id()) == windows_.end()); |
| + windows_[window->server_id()] = window; |
| } |
| -void WindowTreeClient::LocalSetCapture(Window* window) { |
| - if (capture_window_ == window) |
| - return; |
| - Window* lost_capture = capture_window_; |
| - capture_window_ = window; |
| - if (lost_capture) { |
| - for (auto& observer : *WindowPrivate(lost_capture).observers()) |
| - observer.OnWindowLostCapture(lost_capture); |
| - } |
| - for (auto& observer : observers_) |
| - observer.OnWindowTreeCaptureChanged(window, lost_capture); |
| -} |
| - |
| -void WindowTreeClient::LocalSetFocus(Window* focused) { |
| - Window* blurred = focused_window_; |
| - // Update |focused_window_| before calling any of the observers, so that the |
| - // observers get the correct result from calling |Window::HasFocus()|, |
| - // |WindowTreeClient::GetFocusedWindow()| etc. |
| - focused_window_ = focused; |
| - if (blurred) { |
| - for (auto& observer : *WindowPrivate(blurred).observers()) |
| - observer.OnWindowFocusChanged(focused, blurred); |
| - } |
| - if (focused) { |
| - for (auto& observer : *WindowPrivate(focused).observers()) |
| - observer.OnWindowFocusChanged(focused, blurred); |
| - } |
| - for (auto& observer : observers_) |
| - observer.OnWindowTreeFocusChanged(focused, blurred); |
| -} |
| - |
| -void WindowTreeClient::AddWindow(Window* window) { |
| - DCHECK(windows_.find(server_id(window)) == windows_.end()); |
| - windows_[server_id(window)] = window; |
| +WindowMus* WindowTreeClient::GetWindowByServerId(Id id) { |
| + IdToWindowMap::const_iterator it = windows_.find(id); |
| + return it != windows_.end() ? it->second : nullptr; |
| } |
| -void WindowTreeClient::OnWindowDestroying(Window* window) { |
| - if (window == capture_window_) { |
| - // Normally the queue updates itself upon window destruction. However since |
| - // |window| is being destroyed, it will not be possible to notify its |
| - // observers of the lost capture. Update local state now. |
| - LocalSetCapture(nullptr); |
| - } |
| - // For |focused_window_| window destruction clears the entire focus state. |
| +bool WindowTreeClient::WasCreatedByThisClient(const WindowMus* window) const { |
| + // Windows created via CreateTopLevelWindow() are not owned by us, but have |
| + // our client id. const_cast is required by set. |
| + return HiWord(window->server_id()) == client_id_ && |
| + roots_.count(const_cast<WindowMus*>(window)) == 0; |
| } |
| -void WindowTreeClient::OnWindowDestroyed(Window* window) { |
| - windows_.erase(server_id(window)); |
| +void WindowTreeClient::SetFocusFromServer(WindowMus* window) { |
| + if (focused_window_ == window) |
| + return; |
| - for (auto& entry : embedded_windows_) { |
| - auto it = entry.second.find(window); |
| - if (it != entry.second.end()) { |
| - entry.second.erase(it); |
| - break; |
| + if (window) { |
| + client::FocusClient* focus_client = |
| + client::GetFocusClient(window->GetWindow()); |
| + if (focus_client) { |
| + SetFocusFromServerImpl(focus_client, window); |
| + } else { |
| + SetFocusFromServerImpl( |
| + client::GetFocusClient(focused_window_->GetWindow()), nullptr); |
| } |
| + } else { |
| + SetFocusFromServerImpl(client::GetFocusClient(focused_window_->GetWindow()), |
| + nullptr); |
| } |
| +} |
| - // Remove any InFlightChanges associated with the window. |
| - std::set<uint32_t> in_flight_change_ids_to_remove; |
| - for (const auto& pair : in_flight_map_) { |
| - if (pair.second->window() == window) |
| - in_flight_change_ids_to_remove.insert(pair.first); |
| - } |
| - for (auto change_id : in_flight_change_ids_to_remove) |
| - in_flight_map_.erase(change_id); |
| +void WindowTreeClient::SetFocusFromServerImpl(client::FocusClient* focus_client, |
| + WindowMus* window) { |
| + if (!focus_client) |
| + return; |
| - const bool was_root = roots_.erase(window) > 0; |
| - if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) |
| - delegate_->OnEmbedRootDestroyed(window); |
| + DCHECK(!setting_focus_); |
| + base::AutoReset<bool> focus_reset(&setting_focus_, true); |
| + base::AutoReset<WindowMus*> window_setting_focus_to_reset( |
| + &window_setting_focus_to_, window); |
| + focus_client->FocusWindow(window ? window->GetWindow() : nullptr); |
| } |
| -Window* WindowTreeClient::GetWindowByServerId(Id id) { |
| - IdToWindowMap::const_iterator it = windows_.find(id); |
| - return it != windows_.end() ? it->second : NULL; |
| +void WindowTreeClient::SetCaptureFromServer(WindowMus* window) { |
| + // In order for us to get here we had to have exposed a window, which implies |
| + // we got a client. |
| + DCHECK(tree_); |
| + if (capture_window_ == window) |
| + return; |
| + DCHECK(!setting_capture_); |
| + base::AutoReset<bool> capture_reset(&setting_capture_, true); |
| + base::AutoReset<WindowMus*> window_setting_capture_to_reset( |
| + &window_setting_capture_to_, window); |
| + 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
|
| + : nullptr); |
| } |
| InFlightChange* WindowTreeClient::GetOldestInFlightChangeMatching( |
| @@ -473,62 +382,103 @@ bool WindowTreeClient::ApplyServerChangeToExistingInFlightChange( |
| return true; |
| } |
| -Window* WindowTreeClient::BuildWindowTree( |
| - const mojo::Array<mojom::WindowDataPtr>& windows, |
| - Window* initial_parent) { |
| - std::vector<Window*> parents; |
| - Window* root = nullptr; |
| - Window* last_window = nullptr; |
| +void WindowTreeClient::BuildWindowTree( |
| + const mojo::Array<ui::mojom::WindowDataPtr>& windows, |
| + WindowMus* initial_parent) { |
| + std::vector<WindowMus*> parents; |
| + WindowMus* last_window = nullptr; |
| if (initial_parent) |
| parents.push_back(initial_parent); |
| - for (size_t i = 0; i < windows.size(); ++i) { |
| - if (last_window && windows[i]->parent_id == server_id(last_window)) { |
| + for (const auto& window_data : windows) { |
| + if (last_window && window_data->parent_id == last_window->server_id()) { |
| parents.push_back(last_window); |
| } else if (!parents.empty()) { |
| - while (server_id(parents.back()) != windows[i]->parent_id) |
| + while (parents.back()->server_id() != window_data->parent_id) |
| parents.pop_back(); |
| } |
| - Window* window = AddWindowToClient( |
| - this, !parents.empty() ? parents.back() : nullptr, windows[i]); |
| - if (!last_window) |
| - root = window; |
| - last_window = window; |
| + // This code is only called in a context where there is a parent. |
| + DCHECK(!parents.empty()); |
| + last_window = NewWindowFromWindowData( |
| + !parents.empty() ? parents.back() : nullptr, window_data); |
| } |
| - return root; |
| } |
| -Window* WindowTreeClient::NewWindowImpl( |
| - NewWindowType type, |
| - const Window::SharedProperties* properties) { |
| - DCHECK(tree_); |
| - Window* window = |
| - new Window(this, MakeTransportId(client_id_, next_window_id_++)); |
| - if (properties) |
| - window->properties_ = *properties; |
| - AddWindow(window); |
| +std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus( |
| + const ui::mojom::WindowDataPtr& window_data) { |
| + std::unique_ptr<WindowPortMus> window_port_mus( |
| + base::MakeUnique<WindowPortMus>(this)); |
| + window_port_mus->set_server_id(window_data->window_id); |
| + RegisterWindowMus(window_port_mus.get()); |
| + return window_port_mus; |
| +} |
| - const uint32_t change_id = |
| - ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| - window, type == NewWindowType::CHILD |
| - ? ChangeType::NEW_WINDOW |
| - : ChangeType::NEW_TOP_LEVEL_WINDOW)); |
| - mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; |
| - if (properties) { |
| - transport_properties = |
| - mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(*properties); |
| +void WindowTreeClient::SetLocalPropertiesFromServerProperties( |
| + WindowMus* window, |
| + const ui::mojom::WindowDataPtr& window_data) { |
| + for (auto& pair : window_data->properties) { |
| + if (pair.second.is_null()) { |
| + window->SetPropertyFromServer(pair.first, nullptr); |
| + } else { |
| + std::vector<uint8_t> stl_value = pair.second.To<std::vector<uint8_t>>(); |
| + window->SetPropertyFromServer(pair.first, &stl_value); |
| + } |
| } |
| - if (type == NewWindowType::CHILD) { |
| - tree_->NewWindow(change_id, server_id(window), |
| - std::move(transport_properties)); |
| - } else { |
| - roots_.insert(window); |
| - tree_->NewTopLevelWindow(change_id, server_id(window), |
| - std::move(transport_properties)); |
| +} |
| + |
| +Window* WindowTreeClient::CreateWindowTreeHost( |
| + WindowTreeHostType type, |
| + const ui::mojom::WindowDataPtr& window_data, |
| + Window* content_window) { |
| + Window* user_window = nullptr; |
| + switch (type) { |
| + case WindowTreeHostType::DISPLAY: { |
| + DCHECK(!content_window); |
| + WindowTreeHost* window_tree_host = |
| + new WindowTreeHostMus(CreateWindowPortMus(window_data)); |
| + user_window = window_tree_host->window(); |
| + break; |
| + } |
| + case WindowTreeHostType::EMBED: { |
| + DCHECK(!content_window); |
| + user_window = new Window(nullptr, CreateWindowPortMus(window_data)); |
| + // TODO: LAYER_NOT_DRAWN may be wrong here. |
| + 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.
|
| + new WindowTreeHostMus(nullptr, user_window); |
| + break; |
| + } |
| + case WindowTreeHostType::TOP_LEVEL: { |
| + DCHECK(content_window); |
| + user_window = content_window; |
| + new WindowTreeHostMus(nullptr, user_window); |
| + break; |
| + } |
| } |
| - return window; |
| + WindowMus* user_window_mus = WindowMus::Get(user_window); |
| + roots_.insert(user_window_mus); |
| + if (!window_data.is_null()) |
| + SetLocalPropertiesFromServerProperties(user_window_mus, window_data); |
| + return user_window; |
| +} |
| + |
| +WindowMus* WindowTreeClient::NewWindowFromWindowData( |
| + WindowMus* parent, |
| + const ui::mojom::WindowDataPtr& window_data) { |
| + std::unique_ptr<WindowPortMus> window_port_mus( |
| + CreateWindowPortMus(window_data)); |
| + WindowPortMus* window_port_mus_ptr = window_port_mus.get(); |
| + Window* window = new Window(nullptr, std::move(window_port_mus)); |
| + WindowMus* window_mus = window_port_mus_ptr; |
| + window->Init(ui::LAYER_NOT_DRAWN); |
| + SetLocalPropertiesFromServerProperties(window_mus, window_data); |
| + window_mus->SetBoundsFromServer(window_data->bounds); |
| + if (parent) |
| + parent->AddChildFromServer(window_port_mus_ptr); |
| + if (window_data->visible) |
| + window_mus->SetVisibleFromServer(true); |
| + return window_port_mus_ptr; |
| } |
| -void WindowTreeClient::SetWindowTree(mojom::WindowTreePtr window_tree_ptr) { |
| +void WindowTreeClient::SetWindowTree(ui::mojom::WindowTreePtr window_tree_ptr) { |
| tree_ptr_ = std::move(window_tree_ptr); |
| tree_ = tree_ptr_.get(); |
| @@ -549,45 +499,48 @@ void WindowTreeClient::OnConnectionLost() { |
| delegate_->OnLostConnection(this); |
| } |
| -void WindowTreeClient::OnEmbedImpl(mojom::WindowTree* window_tree, |
| - ClientSpecificId client_id, |
| - mojom::WindowDataPtr root_data, |
| - int64_t display_id, |
| - Id focused_window_id, |
| - bool drawn) { |
| +void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree, |
| + ClientSpecificId client_id, |
| + ui::mojom::WindowDataPtr root_data, |
| + int64_t display_id, |
| + Id focused_window_id, |
| + bool drawn) { |
| // WARNING: this is only called if WindowTreeClient was created as the |
| // result of an embedding. |
| tree_ = window_tree; |
| client_id_ = client_id; |
| DCHECK(roots_.empty()); |
| - Window* root = AddWindowToClient(this, nullptr, root_data); |
| - WindowPrivate(root).LocalSetDisplay(display_id); |
| - roots_.insert(root); |
| - |
| - focused_window_ = GetWindowByServerId(focused_window_id); |
| + Window* root = |
| + CreateWindowTreeHost(WindowTreeHostType::EMBED, root_data, nullptr); |
| + // TODO: needs to deal with drawn and display_id. |
| - WindowPrivate(root).LocalSetParentDrawn(drawn); |
| + SetFocusFromServer(GetWindowByServerId(focused_window_id)); |
| delegate_->OnEmbed(root); |
| - |
| - if (focused_window_) { |
| - for (auto& observer : observers_) |
| - observer.OnWindowTreeFocusChanged(focused_window_, nullptr); |
| - } |
| } |
| -void WindowTreeClient::WmNewDisplayAddedImpl(const display::Display& display, |
| - mojom::WindowDataPtr root_data, |
| - bool parent_drawn) { |
| +WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl( |
| + const display::Display& display, |
| + ui::mojom::WindowDataPtr root_data, |
| + bool parent_drawn) { |
| DCHECK(window_manager_delegate_); |
| - Window* root = AddWindowToClient(this, nullptr, root_data); |
| - WindowPrivate(root).LocalSetDisplay(display.id()); |
| - WindowPrivate(root).LocalSetParentDrawn(parent_drawn); |
| - roots_.insert(root); |
| + // TODO: need to deal with display_id and drawn. |
| + Window* root = |
| + CreateWindowTreeHost(WindowTreeHostType::DISPLAY, root_data, nullptr); |
| + // WindowPrivate(root).LocalSetDisplay(display.id()); |
| + // WindowPrivate(root).LocalSetParentDrawn(parent_drawn); |
| window_manager_delegate_->OnWmNewDisplay(root, display); |
| + return root->GetHost(); |
| +} |
| + |
| +std::unique_ptr<EventResultCallback> |
| +WindowTreeClient::CreateEventResultCallback(int32_t event_id) { |
| + return base::MakeUnique<EventResultCallback>( |
| + base::Bind(&ui::mojom::WindowTree::OnWindowInputEventAck, |
| + base::Unretained(tree_), event_id)); |
| } |
| void WindowTreeClient::OnReceivedCursorLocationMemory( |
| @@ -596,6 +549,211 @@ void WindowTreeClient::OnReceivedCursorLocationMemory( |
| DCHECK(cursor_location_mapping_); |
| } |
| +std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated( |
| + WindowMus* window) { |
| + if (window->server_id() != 0) { |
| + // This window was created by us and has an associated server window. |
| + return nullptr; |
| + } |
| + |
| + window->set_server_id(MakeTransportId(client_id_, next_window_id_++)); |
| + RegisterWindowMus(window); |
| + |
| + const bool create_top_level = |
| + !window_manager_delegate_ && |
| + ShouldCreateTopLevel(window->GetWindow()->type()); |
| + |
| + mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties; |
| + std::set<const void*> property_keys = |
| + window->GetWindow()->GetAllPropertKeys(); |
| + PropertyConverter* property_converter = delegate_->GetPropertyConverter(); |
| + for (const void* key : property_keys) { |
| + std::string transport_name; |
| + std::unique_ptr<std::vector<uint8_t>> transport_value; |
| + if (!property_converter->ConvertPropertyForTransport( |
| + window->GetWindow(), key, &transport_name, &transport_value)) { |
| + continue; |
| + } |
| + if (!transport_value) { |
| + transport_properties[transport_name] = mojo::Array<uint8_t>(nullptr); |
| + } else { |
| + transport_properties[transport_name] = |
| + mojo::Array<uint8_t>::From(*transport_value); |
| + } |
| + } |
| + |
| + const uint32_t change_id = |
| + ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| + window, create_top_level ? ChangeType::NEW_TOP_LEVEL_WINDOW |
| + : ChangeType::NEW_WINDOW)); |
| + if (create_top_level) { |
| + std::unique_ptr<WindowPortInitData> data( |
| + base::MakeUnique<WindowPortInitData>()); |
| + tree_->NewTopLevelWindow(change_id, window->server_id(), |
| + std::move(transport_properties)); |
| + return data; |
| + } |
| + tree_->NewWindow(change_id, window->server_id(), |
| + std::move(transport_properties)); |
| + return nullptr; |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusInitDone( |
| + WindowMus* window, |
| + std::unique_ptr<WindowPortInitData> init_data) { |
| + if (!init_data) |
| + return; |
| + |
| + // Delay creating the WindowTreeHost until after Init(), otherwise we trigger |
| + // crashes in code that expects window parenting to happen after |
| + // Env::NotifyWindowInitialized() is called. |
| + CreateWindowTreeHost(WindowTreeHostType::TOP_LEVEL, nullptr, |
| + window->GetWindow()); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) { |
| + if (focused_window_ == window) |
| + focused_window_ = nullptr; |
| + |
| + // TODO: decide how to deal with windows not owned by this client. |
| + if (WasCreatedByThisClient(window) || IsRoot(window)) { |
| + const uint32_t change_id = |
| + ScheduleInFlightChange(base::MakeUnique<CrashInFlightChange>( |
| + window, ChangeType::DELETE_WINDOW)); |
| + tree_->DeleteWindow(change_id, window->server_id()); |
| + } |
| + |
| + windows_.erase(window->server_id()); |
| + |
| + for (auto& entry : embedded_windows_) { |
| + auto it = entry.second.find(window->GetWindow()); |
| + if (it != entry.second.end()) { |
| + entry.second.erase(it); |
| + break; |
| + } |
| + } |
| + |
| + // Remove any InFlightChanges associated with the window. |
| + std::set<uint32_t> in_flight_change_ids_to_remove; |
| + for (const auto& pair : in_flight_map_) { |
| + if (pair.second->window() == window) |
| + in_flight_change_ids_to_remove.insert(pair.first); |
| + } |
| + for (auto change_id : in_flight_change_ids_to_remove) |
| + in_flight_map_.erase(change_id); |
| + |
| + const bool was_root = roots_.erase(window) > 0; |
| + if (!in_destructor_ && was_root && roots_.empty() && is_from_embed_) |
| + delegate_->OnEmbedRootDestroyed(window->GetWindow()); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window, |
| + const gfx::Rect& old_bounds, |
| + const gfx::Rect& new_bounds) { |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<InFlightBoundsChange>(window, old_bounds)); |
| + tree_->SetWindowBounds(change_id, window->server_id(), new_bounds); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent, |
| + WindowMus* child) { |
| + // TODO: add checks to ensure this can work. |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<CrashInFlightChange>(parent, ChangeType::ADD_CHILD)); |
| + tree_->AddWindow(change_id, parent->server_id(), child->server_id()); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusRemoveChild(WindowMus* parent, |
| + WindowMus* child) { |
| + // TODO: add checks to ensure this can work. |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REMOVE_CHILD)); |
| + tree_->RemoveWindowFromParent(change_id, child->server_id()); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusMoveChild(WindowMus* parent, |
| + size_t current_index, |
| + size_t dest_index) { |
| + // TODO: add checks to ensure this can work, e.g. we own the parent. |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<CrashInFlightChange>(parent, ChangeType::REORDER)); |
| + WindowMus* window = |
| + WindowMus::Get(parent->GetWindow()->children()[current_index]); |
| + WindowMus* relative_window = nullptr; |
| + ui::mojom::OrderDirection direction; |
| + if (dest_index < current_index) { |
| + relative_window = |
| + WindowMus::Get(parent->GetWindow()->children()[dest_index]); |
| + direction = ui::mojom::OrderDirection::BELOW; |
| + } else { |
| + relative_window = |
| + WindowMus::Get(parent->GetWindow()->children()[dest_index]); |
| + direction = ui::mojom::OrderDirection::ABOVE; |
| + } |
| + tree_->ReorderWindow(change_id, window->server_id(), |
| + relative_window->server_id(), direction); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusSetVisible(WindowMus* window, bool visible) { |
| + // TODO: add checks to ensure this can work. |
| + DCHECK(tree_); |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<InFlightVisibleChange>(window, !visible)); |
| + tree_->SetWindowVisibility(change_id, window->server_id(), visible); |
| +} |
| + |
| +std::unique_ptr<WindowPortPropertyData> |
| +WindowTreeClient::OnWindowMusWillChangeProperty(WindowMus* window, |
| + const void* key) { |
| + std::unique_ptr<WindowPortPropertyDataMus> data( |
| + base::MakeUnique<WindowPortPropertyDataMus>()); |
| + if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( |
| + window->GetWindow(), key, &data->transport_name, |
| + &data->transport_value)) { |
| + return nullptr; |
| + } |
| + return data; |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusPropertyChanged( |
| + WindowMus* window, |
| + const void* key, |
| + std::unique_ptr<WindowPortPropertyData> data) { |
| + if (!data) |
| + return; |
| + WindowPortPropertyDataMus* data_mus = |
| + static_cast<WindowPortPropertyDataMus*>(data.get()); |
| + |
| + std::string transport_name; |
| + std::unique_ptr<std::vector<uint8_t>> transport_value; |
| + if (!delegate_->GetPropertyConverter()->ConvertPropertyForTransport( |
| + window->GetWindow(), key, &transport_name, &transport_value)) { |
| + return; |
| + } |
| + DCHECK_EQ(transport_name, data_mus->transport_name); |
| + |
| + mojo::Array<uint8_t> transport_value_mojo(nullptr); |
| + if (transport_value) { |
| + transport_value_mojo.resize(transport_value->size()); |
| + if (transport_value->size()) { |
| + memcpy(&transport_value_mojo.front(), &(transport_value->front()), |
| + transport_value->size()); |
| + } |
| + } |
| + const uint32_t change_id = |
| + ScheduleInFlightChange(base::MakeUnique<InFlightPropertyChange>( |
| + window, transport_name, std::move(data_mus->transport_value))); |
| + tree_->SetWindowProperty(change_id, window->server_id(), |
| + mojo::String(transport_name), |
| + std::move(transport_value_mojo)); |
| +} |
| + |
| +void WindowTreeClient::OnWindowMusSurfaceDetached( |
| + WindowMus* window, |
| + const cc::SurfaceSequence& sequence) { |
| + tree_->OnWindowSurfaceDetached(window->server_id(), sequence); |
| +} |
| + |
| void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, |
| bool completed) { |
| if (window_manager_internal_client_) |
| @@ -610,19 +768,15 @@ void WindowTreeClient::OnWmMoveLoopCompleted(uint32_t change_id, |
| //////////////////////////////////////////////////////////////////////////////// |
| // WindowTreeClient, WindowTreeClient implementation: |
| -const std::set<Window*>& WindowTreeClient::GetRoots() { |
| - return roots_; |
| +std::set<Window*> WindowTreeClient::GetRoots() { |
| + std::set<Window*> roots; |
| + for (WindowMus* window : roots_) |
| + roots.insert(window->GetWindow()); |
| + return roots; |
| } |
| Window* WindowTreeClient::GetFocusedWindow() { |
| - return focused_window_; |
| -} |
| - |
| -void WindowTreeClient::ClearFocus() { |
| - if (!focused_window_) |
| - return; |
| - |
| - SetFocus(nullptr); |
| + return focused_window_ ? focused_window_->GetWindow() : nullptr; |
| } |
| gfx::Point WindowTreeClient::GetCursorScreenPoint() { |
| @@ -656,6 +810,8 @@ void WindowTreeClient::PerformDragDrop( |
| const gfx::Point& cursor_location, |
| const SkBitmap& bitmap, |
| const base::Callback<void(bool, uint32_t)>& callback) { |
| + // TODO: dnd. |
| + /* |
| DCHECK(!current_drag_state_); |
| // TODO(erg): Pass |cursor_location| and |bitmap| in PerformDragDrop() when |
| @@ -677,11 +833,12 @@ void WindowTreeClient::PerformDragDrop( |
| current_drag_change, window->server_id(), |
| mojo::Map<mojo::String, mojo::Array<uint8_t>>::From(drag_data), |
| drag_operation); |
| + */ |
| } |
| void WindowTreeClient::CancelDragDrop(Window* window) { |
| // Server will clean up drag and fail the in-flight change. |
| - tree_->CancelDragDrop(window->server_id()); |
| + tree_->CancelDragDrop(WindowMus::Get(window)->server_id()); |
| } |
| void WindowTreeClient::PerformWindowMove( |
| @@ -692,54 +849,18 @@ void WindowTreeClient::PerformWindowMove( |
| DCHECK(on_current_move_finished_.is_null()); |
| on_current_move_finished_ = callback; |
| + WindowMus* window_mus = WindowMus::Get(window); |
| current_move_loop_change_ = ScheduleInFlightChange( |
| - base::MakeUnique<InFlightDragChange>(window, ChangeType::MOVE_LOOP)); |
| + base::MakeUnique<InFlightDragChange>(window_mus, ChangeType::MOVE_LOOP)); |
| // Tell the window manager to take over moving us. |
| - tree_->PerformWindowMove(current_move_loop_change_, window->server_id(), |
| + tree_->PerformWindowMove(current_move_loop_change_, window_mus->server_id(), |
| source, cursor_location); |
| } |
| void WindowTreeClient::CancelWindowMove(Window* window) { |
| - tree_->CancelWindowMove(window->server_id()); |
| + tree_->CancelWindowMove(WindowMus::Get(window)->server_id()); |
| } |
| -Window* WindowTreeClient::NewWindow( |
| - const Window::SharedProperties* properties) { |
| - return NewWindowImpl(NewWindowType::CHILD, properties); |
| -} |
| - |
| -Window* WindowTreeClient::NewTopLevelWindow( |
| - const Window::SharedProperties* properties) { |
| - Window* window = NewWindowImpl(NewWindowType::TOP_LEVEL, properties); |
| - // Assume newly created top level windows are drawn by default, otherwise |
| - // requests to focus will fail. We will get the real value in |
| - // OnTopLevelCreated(). |
| - window->LocalSetParentDrawn(true); |
| - return window; |
| -} |
| - |
| -#if !defined(NDEBUG) |
| -std::string WindowTreeClient::GetDebugWindowHierarchy() const { |
| - std::string result; |
| - for (Window* root : roots_) |
| - BuildDebugInfo(std::string(), root, &result); |
| - return result; |
| -} |
| - |
| -void WindowTreeClient::BuildDebugInfo(const std::string& depth, |
| - Window* window, |
| - std::string* result) const { |
| - std::string name = window->GetName(); |
| - *result += base::StringPrintf( |
| - "%sid=%d visible=%s bounds=%d,%d %dx%d %s\n", depth.c_str(), |
| - window->server_id(), window->visible() ? "true" : "false", |
| - window->bounds().x(), window->bounds().y(), window->bounds().width(), |
| - window->bounds().height(), !name.empty() ? name.c_str() : "(no name)"); |
| - for (Window* child : window->children()) |
| - BuildDebugInfo(depth + " ", child, result); |
| -} |
| -#endif // !defined(NDEBUG) |
| - |
| //////////////////////////////////////////////////////////////////////////////// |
| // WindowTreeClient, WindowTreeClient implementation: |
| @@ -763,8 +884,8 @@ void WindowTreeClient::SetCanAcceptEvents(Id window_id, |
| } |
| void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| - mojom::WindowDataPtr root_data, |
| - mojom::WindowTreePtr tree, |
| + ui::mojom::WindowDataPtr root_data, |
| + ui::mojom::WindowTreePtr tree, |
| int64_t display_id, |
| Id focused_window_id, |
| bool drawn) { |
| @@ -783,26 +904,24 @@ void WindowTreeClient::OnEmbed(ClientSpecificId client_id, |
| } |
| void WindowTreeClient::OnEmbeddedAppDisconnected(Id window_id) { |
| - Window* window = GetWindowByServerId(window_id); |
| - if (window) { |
| - for (auto& observer : *WindowPrivate(window).observers()) |
| - observer.OnWindowEmbeddedAppDisconnected(window); |
| - } |
| + WindowMus* window = GetWindowByServerId(window_id); |
| + if (window) |
| + window->NotifyEmbeddedAppDisconnected(); |
| } |
| void WindowTreeClient::OnUnembed(Id window_id) { |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| - delegate_->OnUnembed(window); |
| - WindowPrivate(window).LocalDestroy(); |
| + delegate_->OnUnembed(window->GetWindow()); |
| + delete window; |
| } |
| void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, |
| Id old_capture_window_id) { |
| - Window* new_capture_window = GetWindowByServerId(new_capture_window_id); |
| - Window* lost_capture_window = GetWindowByServerId(old_capture_window_id); |
| + WindowMus* new_capture_window = GetWindowByServerId(new_capture_window_id); |
| + WindowMus* lost_capture_window = GetWindowByServerId(old_capture_window_id); |
| if (!new_capture_window && !lost_capture_window) |
| return; |
| @@ -810,13 +929,13 @@ void WindowTreeClient::OnCaptureChanged(Id new_capture_window_id, |
| if (ApplyServerChangeToExistingInFlightChange(change)) |
| return; |
| - LocalSetCapture(new_capture_window); |
| + SetCaptureFromServer(new_capture_window); |
| } |
| void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| - mojom::WindowDataPtr data, |
| - int64_t display_id, |
| - bool drawn) { |
| + ui::mojom::WindowDataPtr data, |
| + int64_t display_id, |
| + bool drawn) { |
| // The server ack'd the top level window we created and supplied the state |
| // of the window at the time the server created it. For properties we do not |
| // have changes in flight for we can update them immediately. For properties |
| @@ -831,13 +950,11 @@ void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| std::unique_ptr<InFlightChange> change(std::move(in_flight_map_[change_id])); |
| in_flight_map_.erase(change_id); |
| - Window* window = change->window(); |
| - WindowPrivate window_private(window); |
| + WindowMus* window = change->window(); |
| + // TODO: parent drawn and display_id need to route to WindowTreeHost. |
| // Drawn state and display-id always come from the server (they can't be |
| // modified locally). |
| - window_private.LocalSetParentDrawn(drawn); |
| - window_private.LocalSetDisplay(display_id); |
| // The default visibilty is false, we only need update visibility if it |
| // differs from that. |
| @@ -848,7 +965,7 @@ void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| if (current_change) |
| current_change->SetRevertValueFrom(visible_change); |
| else |
| - window_private.LocalSetVisible(true); |
| + window->SetVisibleFromServer(true); |
| } |
| const gfx::Rect bounds(data->bounds); |
| @@ -858,23 +975,26 @@ void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| GetOldestInFlightChangeMatching(bounds_change); |
| if (current_change) |
| current_change->SetRevertValueFrom(bounds_change); |
| - else if (window->bounds() != bounds) |
| - window_private.LocalSetBounds(window->bounds(), bounds); |
| + else if (window->GetWindow()->bounds() != bounds) |
| + window->SetBoundsFromServer(bounds); |
| } |
| // There is currently no API to bulk set properties, so we iterate over each |
| // property individually. |
| - Window::SharedProperties properties = |
| + std::map<std::string, std::vector<uint8_t>> properties = |
| data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| for (const auto& pair : properties) { |
| - InFlightPropertyChange property_change( |
| - window, pair.first, mojo::Array<uint8_t>::From(pair.second)); |
| + std::unique_ptr<std::vector<uint8_t>> revert_value( |
| + base::MakeUnique<std::vector<uint8_t>>(pair.second)); |
| + InFlightPropertyChange property_change(window, pair.first, |
| + std::move(revert_value)); |
| InFlightChange* current_change = |
| GetOldestInFlightChangeMatching(property_change); |
| - if (current_change) |
| + if (current_change) { |
| current_change->SetRevertValueFrom(property_change); |
| - else |
| - window_private.LocalSetSharedProperty(pair.first, &(pair.second)); |
| + } else { |
| + window->SetPropertyFromServer(pair.first, &pair.second); |
| + } |
| } |
| // Top level windows should not have a parent. |
| @@ -884,7 +1004,7 @@ void WindowTreeClient::OnTopLevelCreated(uint32_t change_id, |
| void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| const gfx::Rect& old_bounds, |
| const gfx::Rect& new_bounds) { |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| @@ -892,50 +1012,57 @@ void WindowTreeClient::OnWindowBoundsChanged(Id window_id, |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - WindowPrivate(window).LocalSetBounds(old_bounds, new_bounds); |
| + window->SetBoundsFromServer(new_bounds); |
| } |
| void WindowTreeClient::OnClientAreaChanged( |
| uint32_t window_id, |
| const gfx::Insets& new_client_area, |
| mojo::Array<gfx::Rect> new_additional_client_areas) { |
| + // TODO: client area. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (window) { |
| WindowPrivate(window).LocalSetClientArea( |
| new_client_area, |
| new_additional_client_areas.To<std::vector<gfx::Rect>>()); |
| } |
| + */ |
| } |
| -void WindowTreeClient::OnTransientWindowAdded( |
| - uint32_t window_id, |
| - uint32_t transient_window_id) { |
| +void WindowTreeClient::OnTransientWindowAdded(uint32_t window_id, |
| + uint32_t transient_window_id) { |
| + // TODO: needs to route to StackingClient. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| Window* transient_window = GetWindowByServerId(transient_window_id); |
| // window or transient_window or both may be null if a local delete occurs |
| // with an in flight add from the server. |
| if (window && transient_window) |
| WindowPrivate(window).LocalAddTransientWindow(transient_window); |
| + */ |
| } |
| -void WindowTreeClient::OnTransientWindowRemoved( |
| - uint32_t window_id, |
| - uint32_t transient_window_id) { |
| +void WindowTreeClient::OnTransientWindowRemoved(uint32_t window_id, |
| + uint32_t transient_window_id) { |
| + // TODO: needs to route to StackingClient. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| Window* transient_window = GetWindowByServerId(transient_window_id); |
| // window or transient_window or both may be null if a local delete occurs |
| // with an in flight delete from the server. |
| if (window && transient_window) |
| WindowPrivate(window).LocalRemoveTransientWindow(transient_window); |
| + */ |
| } |
| void WindowTreeClient::OnWindowHierarchyChanged( |
| Id window_id, |
| Id old_parent_id, |
| Id new_parent_id, |
| - mojo::Array<mojom::WindowDataPtr> windows) { |
| - Window* initial_parent = |
| - windows.size() ? GetWindowByServerId(windows[0]->parent_id) : NULL; |
| + mojo::Array<ui::mojom::WindowDataPtr> windows) { |
| + WindowMus* initial_parent = |
| + windows.size() ? GetWindowByServerId(windows[0]->parent_id) : nullptr; |
| const bool was_window_known = GetWindowByServerId(window_id) != nullptr; |
| @@ -946,37 +1073,37 @@ void WindowTreeClient::OnWindowHierarchyChanged( |
| if (!was_window_known) |
| return; |
| - Window* new_parent = GetWindowByServerId(new_parent_id); |
| - Window* old_parent = GetWindowByServerId(old_parent_id); |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* new_parent = GetWindowByServerId(new_parent_id); |
| + WindowMus* old_parent = GetWindowByServerId(old_parent_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (new_parent) |
| - WindowPrivate(new_parent).LocalAddChild(window); |
| + new_parent->AddChildFromServer(window); |
| else |
| - WindowPrivate(old_parent).LocalRemoveChild(window); |
| + old_parent->RemoveChildFromServer(window); |
| } |
| void WindowTreeClient::OnWindowReordered(Id window_id, |
| - Id relative_window_id, |
| - mojom::OrderDirection direction) { |
| - Window* window = GetWindowByServerId(window_id); |
| - Window* relative_window = GetWindowByServerId(relative_window_id); |
| - if (window && relative_window) |
| - WindowPrivate(window).LocalReorder(relative_window, direction); |
| + Id relative_window_id, |
| + ui::mojom::OrderDirection direction) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| + WindowMus* relative_window = GetWindowByServerId(relative_window_id); |
| + WindowMus* parent = WindowMus::Get(window->GetWindow()->parent()); |
| + if (window && relative_window && parent && |
| + parent == WindowMus::Get(relative_window->GetWindow()->parent())) { |
| + parent->ReorderFromServer(window, relative_window, direction); |
| + } |
| } |
| void WindowTreeClient::OnWindowDeleted(Id window_id) { |
| - Window* window = GetWindowByServerId(window_id); |
| - if (window) |
| - WindowPrivate(window).LocalDestroy(); |
| + delete GetWindowByServerId(window_id)->GetWindow(); |
| } |
| Window* WindowTreeClient::GetCaptureWindow() { |
| - return capture_window_; |
| + return capture_window_ ? capture_window_->GetWindow() : nullptr; |
| } |
| -void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, |
| - bool visible) { |
| - Window* window = GetWindowByServerId(window_id); |
| +void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| @@ -984,13 +1111,13 @@ void WindowTreeClient::OnWindowVisibilityChanged(Id window_id, |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - WindowPrivate(window).LocalSetVisible(visible); |
| + window->SetVisibleFromServer(visible); |
| } |
| void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| - float old_opacity, |
| - float new_opacity) { |
| - Window* window = GetWindowByServerId(window_id); |
| + float old_opacity, |
| + float new_opacity) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| @@ -998,29 +1125,41 @@ void WindowTreeClient::OnWindowOpacityChanged(Id window_id, |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - WindowPrivate(window).LocalSetOpacity(new_opacity); |
| + window->SetOpacityFromServer(new_opacity); |
| } |
| void WindowTreeClient::OnWindowParentDrawnStateChanged(Id window_id, |
| - bool drawn) { |
| + bool drawn) { |
| + // TODO: route to WindowTreeHost. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (window) |
| WindowPrivate(window).LocalSetParentDrawn(drawn); |
| + */ |
| } |
| void WindowTreeClient::OnWindowSharedPropertyChanged( |
| Id window_id, |
| const mojo::String& name, |
| - mojo::Array<uint8_t> new_data) { |
| - Window* window = GetWindowByServerId(window_id); |
| + mojo::Array<uint8_t> transport_data) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| - InFlightPropertyChange new_change(window, name, new_data); |
| + std::unique_ptr<std::vector<uint8_t>> data; |
| + if (!transport_data.is_null()) { |
| + data = base::MakeUnique<std::vector<uint8_t>>( |
| + transport_data.To<std::vector<uint8_t>>()); |
| + } |
| + InFlightPropertyChange new_change(window, name, std::move(data)); |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - WindowPrivate(window).LocalSetSharedProperty(name, std::move(new_data)); |
| + if (!transport_data.is_null()) { |
| + data = base::MakeUnique<std::vector<uint8_t>>( |
| + transport_data.To<std::vector<uint8_t>>()); |
| + } |
| + window->SetPropertyFromServer(name, data.get()); |
| } |
| void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| @@ -1028,70 +1167,85 @@ void WindowTreeClient::OnWindowInputEvent(uint32_t event_id, |
| std::unique_ptr<ui::Event> event, |
| bool matches_pointer_watcher) { |
| DCHECK(event); |
| - Window* window = GetWindowByServerId(window_id); // May be null. |
| + |
| + WindowMus* window = GetWindowByServerId(window_id); // May be null. |
| + |
| + if (event->IsKeyEvent()) { |
| + DCHECK(!matches_pointer_watcher); // PointerWatcher isn't for key events. |
| + if (!window || !window->GetWindow()->GetHost()) { |
| + tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| + return; |
| + } |
| + InputMethodMus* input_method = |
| + static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()) |
| + ->input_method(); |
| + input_method->DispatchKeyEvent(event->AsKeyEvent(), |
| + CreateEventResultCallback(event_id)); |
| + return; |
| + } |
| if (matches_pointer_watcher && has_pointer_watcher_) { |
| DCHECK(event->IsPointerEvent()); |
| - delegate_->OnPointerEventObserved(*event->AsPointerEvent(), window); |
| + delegate_->OnPointerEventObserved(*event->AsPointerEvent(), |
| + window ? window->GetWindow() : nullptr); |
| } |
| - if (!window || !window->input_event_handler_) { |
| - tree_->OnWindowInputEventAck(event_id, mojom::EventResult::UNHANDLED); |
| + // TODO: deal with no window or host here. This could happen if during |
| + // dispatch a window is deleted or moved. In either case we still need to |
| + // dispatch. Most likely need the display id. |
| + if (!window || !window->GetWindow()->GetHost()) { |
| + tree_->OnWindowInputEventAck(event_id, ui::mojom::EventResult::UNHANDLED); |
| return; |
| } |
| - std::unique_ptr<base::Callback<void(mojom::EventResult)>> ack_callback( |
| - new base::Callback<void(mojom::EventResult)>( |
| - base::Bind(&mojom::WindowTree::OnWindowInputEventAck, |
| - base::Unretained(tree_), event_id))); |
| - |
| + EventAckHandler ack_handler(CreateEventResultCallback(event_id)); |
| + WindowTreeHostMus* host = |
| + static_cast<WindowTreeHostMus*>(window->GetWindow()->GetHost()); |
| // TODO(moshayedi): crbug.com/617222. No need to convert to ui::MouseEvent or |
| // ui::TouchEvent once we have proper support for pointer events. |
| if (event->IsMousePointerEvent()) { |
| if (event->type() == ui::ET_POINTER_WHEEL_CHANGED) { |
| - window->input_event_handler_->OnWindowInputEvent( |
| - window, ui::MouseWheelEvent(*event->AsPointerEvent()), &ack_callback); |
| + ui::MouseWheelEvent mapped_event(*event->AsPointerEvent()); |
| + host->SendEventToProcessor(&mapped_event); |
| } else { |
| - window->input_event_handler_->OnWindowInputEvent( |
| - window, ui::MouseEvent(*event->AsPointerEvent()), &ack_callback); |
| + ui::MouseEvent mapped_event(*event->AsPointerEvent()); |
| + host->SendEventToProcessor(&mapped_event); |
| } |
| } else if (event->IsTouchPointerEvent()) { |
| - window->input_event_handler_->OnWindowInputEvent( |
| - window, ui::TouchEvent(*event->AsPointerEvent()), &ack_callback); |
| + ui::TouchEvent mapped_event(*event->AsPointerEvent()); |
| + host->SendEventToProcessor(&mapped_event); |
| } else { |
| - window->input_event_handler_->OnWindowInputEvent(window, *event.get(), |
| - &ack_callback); |
| + host->SendEventToProcessor(event.get()); |
| } |
| - |
| - // The handler did not take ownership of the callback, so we send the ack, |
| - // marking the event as not consumed. |
| - if (ack_callback) |
| - ack_callback->Run(mojom::EventResult::UNHANDLED); |
| + ack_handler.set_handled(event->handled()); |
| } |
| void WindowTreeClient::OnPointerEventObserved(std::unique_ptr<ui::Event> event, |
| uint32_t window_id) { |
| DCHECK(event); |
| DCHECK(event->IsPointerEvent()); |
| - if (has_pointer_watcher_) { |
| - Window* target_window = GetWindowByServerId(window_id); |
| - delegate_->OnPointerEventObserved(*event->AsPointerEvent(), target_window); |
| - } |
| + if (!has_pointer_watcher_) |
| + return; |
| + |
| + WindowMus* target_window = GetWindowByServerId(window_id); |
| + delegate_->OnPointerEventObserved( |
| + *event->AsPointerEvent(), |
| + target_window ? target_window->GetWindow() : nullptr); |
| } |
| void WindowTreeClient::OnWindowFocused(Id focused_window_id) { |
| - Window* focused_window = GetWindowByServerId(focused_window_id); |
| + WindowMus* focused_window = GetWindowByServerId(focused_window_id); |
| InFlightFocusChange new_change(this, focused_window); |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - LocalSetFocus(focused_window); |
| + SetFocusFromServer(focused_window); |
| } |
| void WindowTreeClient::OnWindowPredefinedCursorChanged( |
| Id window_id, |
| - mojom::Cursor cursor) { |
| - Window* window = GetWindowByServerId(window_id); |
| + ui::mojom::Cursor cursor) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| @@ -1099,7 +1253,7 @@ void WindowTreeClient::OnWindowPredefinedCursorChanged( |
| if (ApplyServerChangeToExistingInFlightChange(new_change)) |
| return; |
| - WindowPrivate(window).LocalSetPredefinedCursor(cursor); |
| + window->SetPredefinedCursorFromServer(cursor); |
| } |
| void WindowTreeClient::OnWindowSurfaceChanged( |
| @@ -1108,7 +1262,7 @@ void WindowTreeClient::OnWindowSurfaceChanged( |
| const cc::SurfaceSequence& surface_sequence, |
| const gfx::Size& frame_size, |
| float device_scale_factor) { |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window) |
| return; |
| std::unique_ptr<SurfaceInfo> surface_info(base::MakeUnique<SurfaceInfo>()); |
| @@ -1116,7 +1270,7 @@ void WindowTreeClient::OnWindowSurfaceChanged( |
| surface_info->surface_sequence = surface_sequence; |
| surface_info->frame_size = frame_size; |
| surface_info->device_scale_factor = device_scale_factor; |
| - WindowPrivate(window).LocalSetSurfaceId(std::move(surface_info)); |
| + window->SetSurfaceIdFromServer(std::move(surface_info)); |
| } |
| void WindowTreeClient::OnDragDropStart( |
| @@ -1129,9 +1283,11 @@ void WindowTreeClient::OnDragEnter(Id window_id, |
| const gfx::Point& position, |
| uint32_t effect_bitmask, |
| const OnDragEnterCallback& callback) { |
| + // TODO: dnd. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (!window || !window->drop_target()) { |
| - callback.Run(mojom::kDropEffectNone); |
| + callback.Run(ui::mojom::kDropEffectNone); |
| return; |
| } |
| @@ -1144,6 +1300,7 @@ void WindowTreeClient::OnDragEnter(Id window_id, |
| uint32_t ret = |
| window->drop_target()->OnDragEnter(key_state, position, effect_bitmask); |
| callback.Run(ret); |
| + */ |
| } |
| void WindowTreeClient::OnDragOver(Id window_id, |
| @@ -1151,26 +1308,34 @@ void WindowTreeClient::OnDragOver(Id window_id, |
| const gfx::Point& position, |
| uint32_t effect_bitmask, |
| const OnDragOverCallback& callback) { |
| + // TODO: dnd. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (!window || !window->drop_target()) { |
| - callback.Run(mojom::kDropEffectNone); |
| + callback.Run(ui::mojom::kDropEffectNone); |
| return; |
| } |
| uint32_t ret = |
| window->drop_target()->OnDragOver(key_state, position, effect_bitmask); |
| callback.Run(ret); |
| + */ |
| } |
| void WindowTreeClient::OnDragLeave(Id window_id) { |
| + // TODO: dnd. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (!window || !window->drop_target()) |
| return; |
| window->drop_target()->OnDragLeave(); |
| + */ |
| } |
| void WindowTreeClient::OnDragDropDone() { |
| + // TODO: dnd. |
| + /* |
| for (Id id : drag_entered_windows_) { |
| Window* window = GetWindowByServerId(id); |
| if (!window || !window->drop_target()) |
| @@ -1178,6 +1343,7 @@ void WindowTreeClient::OnDragDropDone() { |
| window->drop_target()->OnDragDropDone(); |
| } |
| drag_entered_windows_.clear(); |
| + */ |
| } |
| void WindowTreeClient::OnCompleteDrop(Id window_id, |
| @@ -1185,24 +1351,30 @@ void WindowTreeClient::OnCompleteDrop(Id window_id, |
| const gfx::Point& position, |
| uint32_t effect_bitmask, |
| const OnCompleteDropCallback& callback) { |
| + // TODO: dnd. |
| + /* |
| Window* window = GetWindowByServerId(window_id); |
| if (!window || !window->drop_target()) { |
| - callback.Run(mojom::kDropEffectNone); |
| + callback.Run(ui::mojom::kDropEffectNone); |
| return; |
| } |
| uint32_t ret = window->drop_target()->OnCompleteDrop(key_state, position, |
| effect_bitmask); |
| callback.Run(ret); |
| + */ |
| } |
| void WindowTreeClient::OnPerformDragDropCompleted(uint32_t change_id, |
| bool success, |
| uint32_t action_taken) { |
| + // TODO: dnd. |
| + /* |
| if (current_drag_state_ && change_id == current_drag_state_->change_id) { |
| current_drag_state_->completed_action = action_taken; |
| OnChangeCompleted(change_id, success); |
| } |
| + */ |
| } |
| void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| @@ -1240,17 +1412,16 @@ void WindowTreeClient::OnChangeCompleted(uint32_t change_id, bool success) { |
| void WindowTreeClient::GetWindowManager( |
| mojo::AssociatedInterfaceRequest<WindowManager> internal) { |
| window_manager_internal_.reset( |
| - new mojo::AssociatedBinding<mojom::WindowManager>(this, |
| - std::move(internal))); |
| + new mojo::AssociatedBinding<ui::mojom::WindowManager>( |
| + this, std::move(internal))); |
| } |
| void WindowTreeClient::RequestClose(uint32_t window_id) { |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (!window || !IsRoot(window)) |
| return; |
| - for (auto& observer : *WindowPrivate(window).observers()) |
| - observer.OnRequestClose(window); |
| + window->GetWindow()->delegate()->OnRequestClose(); |
| } |
| void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| @@ -1258,41 +1429,46 @@ void WindowTreeClient::OnConnect(ClientSpecificId client_id) { |
| } |
| void WindowTreeClient::WmNewDisplayAdded(const display::Display& display, |
| - mojom::WindowDataPtr root_data, |
| + ui::mojom::WindowDataPtr root_data, |
| bool parent_drawn) { |
| WmNewDisplayAddedImpl(display, std::move(root_data), parent_drawn); |
| } |
| void WindowTreeClient::WmDisplayRemoved(int64_t display_id) { |
| DCHECK(window_manager_delegate_); |
| - |
| + // TODO: route to WindowTreeHost. |
| + /* |
| for (Window* root : roots_) { |
| if (root->display_id() == display_id) { |
| window_manager_delegate_->OnWmDisplayRemoved(root); |
| return; |
| } |
| } |
| + */ |
| } |
| void WindowTreeClient::WmDisplayModified(const display::Display& display) { |
| DCHECK(window_manager_delegate_); |
| + // TODO(sky): this should likely route to WindowTreeHost. |
| window_manager_delegate_->OnWmDisplayModified(display); |
| } |
| void WindowTreeClient::WmSetBounds(uint32_t change_id, |
| - Id window_id, |
| - const gfx::Rect& transit_bounds) { |
| - Window* window = GetWindowByServerId(window_id); |
| + Id window_id, |
| + const gfx::Rect& transit_bounds) { |
| + WindowMus* window = GetWindowByServerId(window_id); |
| bool result = false; |
| if (window) { |
| DCHECK(window_manager_delegate_); |
| gfx::Rect bounds = transit_bounds; |
| - result = window_manager_delegate_->OnWmSetBounds(window, &bounds); |
| + // TODO: this needs to trigger scheduling a bounds change on |window|. |
| + result = |
| + window_manager_delegate_->OnWmSetBounds(window->GetWindow(), &bounds); |
| if (result) { |
| // If the resulting bounds differ return false. Returning false ensures |
| // the client applies the bounds we set below. |
| result = bounds == transit_bounds; |
| - window->SetBounds(bounds); |
| + window->SetBoundsFromServer(bounds); |
| } |
| } |
| if (window_manager_internal_client_) |
| @@ -1303,20 +1479,21 @@ void WindowTreeClient::WmSetProperty(uint32_t change_id, |
| Id window_id, |
| const mojo::String& name, |
| mojo::Array<uint8_t> transit_data) { |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| bool result = false; |
| if (window) { |
| + // TODO: map properties. |
| DCHECK(window_manager_delegate_); |
| std::unique_ptr<std::vector<uint8_t>> data; |
| if (!transit_data.is_null()) { |
| data.reset( |
| new std::vector<uint8_t>(transit_data.To<std::vector<uint8_t>>())); |
| } |
| - result = window_manager_delegate_->OnWmSetProperty(window, name, &data); |
| + result = window_manager_delegate_->OnWmSetProperty(window->GetWindow(), |
| + name, &data); |
| if (result) { |
| - // If the resulting bounds differ return false. Returning false ensures |
| - // the client applies the bounds we set below. |
| - window->SetSharedPropertyInternal(name, data.get()); |
| + delegate_->GetPropertyConverter()->SetPropertyFromTransportValue( |
| + window->GetWindow(), name, data.get()); |
| } |
| } |
| if (window_manager_internal_client_) |
| @@ -1334,7 +1511,7 @@ void WindowTreeClient::WmCreateTopLevelWindow( |
| embedded_windows_[requesting_client_id].insert(window); |
| if (window_manager_internal_client_) { |
| window_manager_internal_client_->OnWmCreatedTopLevelWindow( |
| - change_id, server_id(window)); |
| + change_id, WindowMus::Get(window)->server_id()); |
| } |
| } |
| @@ -1350,7 +1527,7 @@ void WindowTreeClient::WmClientJankinessChanged(ClientSpecificId client_id, |
| void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, |
| Id window_id, |
| - mojom::MoveLoopSource source, |
| + ui::mojom::MoveLoopSource source, |
| const gfx::Point& cursor_location) { |
| if (!window_manager_delegate_ || current_wm_move_loop_change_ != 0) { |
| OnWmMoveLoopCompleted(change_id, false); |
| @@ -1359,10 +1536,10 @@ void WindowTreeClient::WmPerformMoveLoop(uint32_t change_id, |
| current_wm_move_loop_change_ = change_id; |
| current_wm_move_loop_window_id_ = window_id; |
| - Window* window = GetWindowByServerId(window_id); |
| + WindowMus* window = GetWindowByServerId(window_id); |
| if (window) { |
| window_manager_delegate_->OnWmPerformMoveLoop( |
| - window, source, cursor_location, |
| + window->GetWindow(), source, cursor_location, |
| base::Bind(&WindowTreeClient::OnWmMoveLoopCompleted, |
| weak_factory_.GetWeakPtr(), change_id)); |
| } else { |
| @@ -1374,23 +1551,23 @@ void WindowTreeClient::WmCancelMoveLoop(uint32_t change_id) { |
| if (!window_manager_delegate_ || change_id != current_wm_move_loop_change_) |
| return; |
| - Window* window = GetWindowByServerId(current_wm_move_loop_window_id_); |
| + WindowMus* window = GetWindowByServerId(current_wm_move_loop_window_id_); |
| if (window) |
| - window_manager_delegate_->OnWmCancelMoveLoop(window); |
| + window_manager_delegate_->OnWmCancelMoveLoop(window->GetWindow()); |
| } |
| void WindowTreeClient::OnAccelerator(uint32_t ack_id, |
| uint32_t accelerator_id, |
| std::unique_ptr<ui::Event> event) { |
| DCHECK(event); |
| - const mojom::EventResult result = |
| + const ui::mojom::EventResult result = |
| window_manager_delegate_->OnAccelerator(accelerator_id, *event.get()); |
| if (ack_id && window_manager_internal_client_) |
| window_manager_internal_client_->OnAcceleratorAck(ack_id, result); |
| } |
| void WindowTreeClient::SetFrameDecorationValues( |
| - mojom::FrameDecorationValuesPtr values) { |
| + ui::mojom::FrameDecorationValuesPtr values) { |
| if (window_manager_internal_client_) { |
| window_manager_internal_client_->WmSetFrameDecorationValues( |
| std::move(values)); |
| @@ -1399,13 +1576,13 @@ void WindowTreeClient::SetFrameDecorationValues( |
| void WindowTreeClient::SetNonClientCursor(Window* window, |
| ui::mojom::Cursor cursor_id) { |
| - window_manager_internal_client_->WmSetNonClientCursor(server_id(window), |
| - cursor_id); |
| + window_manager_internal_client_->WmSetNonClientCursor( |
| + WindowMus::Get(window)->server_id(), cursor_id); |
| } |
| void WindowTreeClient::AddAccelerator( |
| uint32_t id, |
| - mojom::EventMatcherPtr event_matcher, |
| + ui::mojom::EventMatcherPtr event_matcher, |
| const base::Callback<void(bool)>& callback) { |
| if (window_manager_internal_client_) { |
| window_manager_internal_client_->AddAccelerator( |
| @@ -1420,13 +1597,17 @@ void WindowTreeClient::RemoveAccelerator(uint32_t id) { |
| } |
| void WindowTreeClient::AddActivationParent(Window* window) { |
| - if (window_manager_internal_client_) |
| - window_manager_internal_client_->AddActivationParent(server_id(window)); |
| + if (window_manager_internal_client_) { |
| + window_manager_internal_client_->AddActivationParent( |
| + WindowMus::Get(window)->server_id()); |
| + } |
| } |
| void WindowTreeClient::RemoveActivationParent(Window* window) { |
| - if (window_manager_internal_client_) |
| - window_manager_internal_client_->RemoveActivationParent(server_id(window)); |
| + if (window_manager_internal_client_) { |
| + window_manager_internal_client_->RemoveActivationParent( |
| + WindowMus::Get(window)->server_id()); |
| + } |
| } |
| void WindowTreeClient::ActivateNextWindow() { |
| @@ -1440,8 +1621,41 @@ void WindowTreeClient::SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| const gfx::Insets& hit_area) { |
| if (window_manager_internal_client_) { |
| window_manager_internal_client_->SetUnderlaySurfaceOffsetAndExtendedHitArea( |
| - server_id(window), offset.x(), offset.y(), hit_area); |
| + WindowMus::Get(window)->server_id(), offset.x(), offset.y(), hit_area); |
| + } |
| +} |
| + |
| +void WindowTreeClient::OnWindowFocused(Window* gained_focus, |
| + Window* lost_focus) { |
| + WindowMus* gained_focus_mus = WindowMus::Get(gained_focus); |
| + if (setting_focus_ && gained_focus_mus == window_setting_focus_to_) { |
| + focused_window_ = gained_focus_mus; |
| + return; |
| + } |
| + |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<InFlightFocusChange>(this, focused_window_)); |
| + focused_window_ = gained_focus_mus; |
| + tree_->SetFocus(change_id, focused_window_ ? focused_window_->server_id() |
| + : kInvalidServerId); |
| +} |
| + |
| +void WindowTreeClient::OnCaptureChanged(Window* lost_capture, |
| + Window* gained_capture) { |
| + WindowMus* gained_capture_mus = WindowMus::Get(gained_capture); |
| + if (setting_capture_ && gained_capture_mus == window_setting_capture_to_) { |
| + capture_window_ = gained_capture_mus; |
| + return; |
| } |
| + |
| + const uint32_t change_id = ScheduleInFlightChange( |
| + base::MakeUnique<InFlightCaptureChange>(this, capture_window_)); |
| + WindowMus* old_capture_window = capture_window_; |
| + capture_window_ = gained_capture_mus; |
| + if (capture_window_) |
| + tree_->SetCapture(change_id, capture_window_->server_id()); |
| + else |
| + tree_->ReleaseCapture(change_id, old_capture_window->server_id()); |
| } |
| -} // namespace ui |
| +} // namespace aura |