Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(25)

Unified Diff: ui/aura/mus/window_tree_client.cc

Issue 2470963002: Makes it possible for clients to directly create WindowTreeHostMus (Closed)
Patch Set: nuke comment Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_delegate.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/aura/mus/window_tree_client.cc
diff --git a/ui/aura/mus/window_tree_client.cc b/ui/aura/mus/window_tree_client.cc
index c7dc8e3078cc3c3f21d0cd84e1f63b5586ffec32..363c5397f12e0c45be763fdd4384a3c9b3b187c4 100644
--- a/ui/aura/mus/window_tree_client.cc
+++ b/ui/aura/mus/window_tree_client.cc
@@ -55,22 +55,6 @@ Id MakeTransportId(ClientSpecificId client_id, ClientSpecificId local_id) {
return (client_id << 16) | local_id;
}
-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);
}
@@ -217,13 +201,6 @@ void WindowTreeClient::ConnectAsWindowManager(
SetWindowTree(std::move(window_tree));
}
-void WindowTreeClient::WaitForEmbed() {
- DCHECK(roots_.empty());
- // OnEmbed() is the first function called.
- binding_.WaitForIncomingMethodCall();
- // TODO(sky): deal with pipe being closed before we get OnEmbed().
-}
-
void WindowTreeClient::SetClientArea(
Window* window,
const gfx::Insets& client_area,
@@ -399,9 +376,10 @@ void WindowTreeClient::BuildWindowTree(
}
std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortMus(
- const ui::mojom::WindowDataPtr& window_data) {
+ const ui::mojom::WindowDataPtr& window_data,
+ WindowMusType window_mus_type) {
std::unique_ptr<WindowPortMus> window_port_mus(
- base::MakeUnique<WindowPortMus>(this));
+ base::MakeUnique<WindowPortMus>(this, window_mus_type));
window_port_mus->set_server_id(window_data->window_id);
RegisterWindowMus(window_port_mus.get());
return window_port_mus;
@@ -420,55 +398,29 @@ void WindowTreeClient::SetLocalPropertiesFromServerProperties(
}
}
-Window* WindowTreeClient::CreateWindowTreeHost(
- RootWindowType type,
+std::unique_ptr<WindowTreeHostMus> WindowTreeClient::CreateWindowTreeHost(
+ WindowMusType window_mus_type,
const ui::mojom::WindowDataPtr& window_data,
- int64_t display_id,
- Window* content_window) {
- Window* user_window = nullptr;
- switch (type) {
- case RootWindowType::DISPLAY: {
- DCHECK(!content_window);
- // See WindowTreeHostMus for details on ownership.
- WindowTreeHost* window_tree_host = new WindowTreeHostMus(
- CreateWindowPortMus(window_data), this, type, display_id);
- user_window = window_tree_host->window();
- break;
- }
- case RootWindowType::EMBED: {
- DCHECK(!content_window);
- user_window = new Window(nullptr, CreateWindowPortMus(window_data));
- user_window->Init(ui::LAYER_TEXTURED);
- // See WindowTreeHostMus for details on ownership.
- new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this,
- type, display_id, user_window);
- break;
- }
- case RootWindowType::TOP_LEVEL: {
- DCHECK(content_window);
- user_window = content_window;
- // See WindowTreeHostMus for details on ownership.
- new WindowTreeHostMus(base::MakeUnique<WindowPortMus>(this, false), this,
- type, display_id, user_window);
- break;
- }
+ int64_t display_id) {
+ std::unique_ptr<WindowPortMus> window_port =
+ CreateWindowPortMus(window_data, window_mus_type);
+ roots_.insert(window_port.get());
+ std::unique_ptr<WindowTreeHostMus> window_tree_host =
+ base::MakeUnique<WindowTreeHostMus>(std::move(window_port), this,
+ display_id);
+ if (!window_data.is_null()) {
+ SetLocalPropertiesFromServerProperties(
+ WindowMus::Get(window_tree_host->window()), window_data);
}
- WindowMus* user_window_mus = WindowMus::Get(user_window);
- roots_.insert(user_window_mus);
- if (!window_data.is_null())
- SetLocalPropertiesFromServerProperties(user_window_mus, window_data);
- // All WindowTreeHosts are destroyed before this, so we don't need to unset
- // the DragDropClient.
- client::SetDragDropClient(user_window->GetRootWindow(),
- drag_drop_controller_.get());
- return user_window;
+ return window_tree_host;
}
WindowMus* WindowTreeClient::NewWindowFromWindowData(
WindowMus* parent,
const ui::mojom::WindowDataPtr& window_data) {
+ // This function is only called for windows coming from other clients.
std::unique_ptr<WindowPortMus> window_port_mus(
- CreateWindowPortMus(window_data));
+ CreateWindowPortMus(window_data, WindowMusType::OTHER));
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;
@@ -543,13 +495,12 @@ void WindowTreeClient::OnEmbedImpl(ui::mojom::WindowTree* window_tree,
WindowTreeConnectionEstablished(window_tree);
DCHECK(roots_.empty());
- Window* root = CreateWindowTreeHost(RootWindowType::EMBED, root_data,
- display_id, nullptr);
- // TODO: needs to deal with drawn and display_id.
+ std::unique_ptr<WindowTreeHostMus> window_tree_host =
+ CreateWindowTreeHost(WindowMusType::EMBED, root_data, display_id);
SetFocusFromServer(GetWindowByServerId(focused_window_id));
- delegate_->OnEmbed(root);
+ delegate_->OnEmbed(std::move(window_tree_host));
}
WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl(
@@ -558,14 +509,13 @@ WindowTreeHost* WindowTreeClient::WmNewDisplayAddedImpl(
bool parent_drawn) {
DCHECK(window_manager_delegate_);
- // TODO: need to deal with display_id and drawn.
- Window* root = CreateWindowTreeHost(RootWindowType::DISPLAY, root_data,
- display.id(), nullptr);
- // WindowPrivate(root).LocalSetDisplay(display.id());
- // WindowPrivate(root).LocalSetParentDrawn(parent_drawn);
+ std::unique_ptr<WindowTreeHostMus> window_tree_host =
+ CreateWindowTreeHost(WindowMusType::DISPLAY, root_data, display.id());
- window_manager_delegate_->OnWmNewDisplay(root, display);
- return root->GetHost();
+ WindowTreeHost* window_tree_host_ptr = window_tree_host.get();
+ window_manager_delegate_->OnWmNewDisplay(std::move(window_tree_host),
+ display);
+ return window_tree_host_ptr;
}
std::unique_ptr<EventResultCallback>
@@ -584,18 +534,12 @@ void WindowTreeClient::OnReceivedCursorLocationMemory(
void WindowTreeClient::SetWindowBoundsFromServer(
WindowMus* window,
const gfx::Rect& revert_bounds) {
- if (!IsRoot(window)) {
- window->SetBoundsFromServer(revert_bounds);
+ if (IsRoot(window)) {
+ GetWindowTreeHostMus(window)->SetBoundsFromServer(revert_bounds);
return;
}
- const gfx::Rect window_tree_host_bounds(gfx::Rect(revert_bounds.size()));
- std::unique_ptr<WindowMusChangeData> data =
- window->PrepareForServerBoundsChange(window_tree_host_bounds);
- // We need the root window to always have an origin of 0x0 locally.
- WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
- window_tree_host->set_origin_offset(revert_bounds.OffsetFromOrigin());
- window_tree_host->SetBoundsFromServer(window_tree_host_bounds);
+ window->SetBoundsFromServer(revert_bounds);
}
void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
@@ -605,7 +549,7 @@ void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
return;
}
- std::unique_ptr<WindowMusChangeData> data1 =
+ std::unique_ptr<WindowMusChangeData> data =
window->PrepareForServerVisibilityChange(visible);
WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
if (visible)
@@ -614,20 +558,23 @@ void WindowTreeClient::SetWindowVisibleFromServer(WindowMus* window,
window_tree_host->Hide();
}
-std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated(
- WindowMus* window) {
- if (window->server_id() != 0 || !window->create_remote_window()) {
- // This window was created by us, or should not have a window created on
- // the server.
- return nullptr;
- }
+void WindowTreeClient::ScheduleInFlightBoundsChange(
+ WindowMus* window,
+ const gfx::Rect& old_bounds,
+ const gfx::Rect& new_bounds) {
+ const uint32_t change_id = ScheduleInFlightChange(
+ base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds));
+ tree_->SetWindowBounds(change_id, window->server_id(), new_bounds);
+}
+
+void WindowTreeClient::OnWindowMusCreated(WindowMus* window) {
+ if (window->server_id() != kInvalidServerId)
+ return;
window->set_server_id(MakeTransportId(client_id_, next_window_id_++));
RegisterWindowMus(window);
- const bool create_top_level =
- !window_manager_delegate_ &&
- ShouldCreateTopLevel(window->GetWindow()->type());
+ const bool create_top_level = !window_manager_delegate_ && IsRoot(window);
mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties;
std::set<const void*> property_keys =
@@ -653,31 +600,12 @@ std::unique_ptr<WindowPortInitData> WindowTreeClient::OnWindowMusCreated(
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;
+ } else {
+ tree_->NewWindow(change_id, window->server_id(),
+ std::move(transport_properties));
}
- 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.
- //
- // Use the primary display. We'll get the real display when created.
- CreateWindowTreeHost(RootWindowType::TOP_LEVEL, nullptr,
- display::Screen::GetScreen()->GetPrimaryDisplay().id(),
- window->GetWindow());
}
void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) {
@@ -719,16 +647,13 @@ void WindowTreeClient::OnWindowMusDestroyed(WindowMus* window) {
void WindowTreeClient::OnWindowMusBoundsChanged(WindowMus* window,
const gfx::Rect& old_bounds,
const gfx::Rect& new_bounds) {
- const uint32_t change_id = ScheduleInFlightChange(
- base::MakeUnique<InFlightBoundsChange>(this, window, old_bounds));
- gfx::Point origin(new_bounds.origin());
- if (IsRoot(window)) {
- // WindowTreeHostMus stores the true origin of root windows.
- WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
- origin += window_tree_host->origin_offset();
- }
- tree_->SetWindowBounds(change_id, window->server_id(),
- gfx::Rect(origin, new_bounds.size()));
+ // Changes to bounds of root windows are routed through
+ // OnWindowTreeHostBoundsWillChange(). Any bounds that happen here are a side
+ // effect of those and can be ignored.
+ if (IsRoot(window))
+ return;
+
+ ScheduleInFlightBoundsChange(window, old_bounds, new_bounds);
}
void WindowTreeClient::OnWindowMusAddChild(WindowMus* parent,
@@ -994,10 +919,11 @@ void WindowTreeClient::OnTopLevelCreated(uint32_t change_id,
in_flight_map_.erase(change_id);
WindowMus* window = change->window();
+ WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
// Drawn state and display-id always come from the server (they can't be
// modified locally).
- GetWindowTreeHostMus(window)->set_display_id(display_id);
+ window_tree_host->set_display_id(display_id);
// The default visibilty is false, we only need update visibility if it
// differs from that.
@@ -1132,6 +1058,8 @@ void WindowTreeClient::OnWindowReordered(Id window_id,
}
void WindowTreeClient::OnWindowDeleted(Id window_id) {
+ // TODO(sky): decide how best to deal with this. It seems we should let the
+ // delegate do the actualy deletion.
delete GetWindowByServerId(window_id)->GetWindow();
}
@@ -1607,26 +1535,26 @@ void WindowTreeClient::OnWindowFocused(Window* gained_focus,
: kInvalidServerId);
}
-void WindowTreeClient::SetRootWindowBounds(Window* window, gfx::Rect* bounds) {
- WindowTreeHostMus* window_tree_host = GetWindowTreeHostMus(window);
- switch (window_tree_host->root_window_type()) {
- case RootWindowType::EMBED:
- NOTREACHED();
- return;
- case RootWindowType::TOP_LEVEL:
- // Top level requests are always in display coordinates.
- break;
- case RootWindowType::DISPLAY: {
- gfx::Point display_relative_origin(bounds->origin());
- display_relative_origin -=
- window_tree_host->GetDisplay().bounds().OffsetFromOrigin();
- bounds->set_origin(display_relative_origin);
- break;
- }
- }
- // We need the root window to always have an origin of 0x0 locally.
- window_tree_host->set_origin_offset(bounds->OffsetFromOrigin());
- bounds->set_origin(gfx::Point());
+void WindowTreeClient::OnWindowTreeHostBoundsWillChange(
+ WindowTreeHostMus* window_tree_host,
+ const gfx::Rect& bounds) {
+ ScheduleInFlightBoundsChange(WindowMus::Get(window_tree_host->window()),
+ window_tree_host->GetBounds(), bounds);
+}
+
+std::unique_ptr<WindowPortMus> WindowTreeClient::CreateWindowPortForTopLevel() {
+ std::unique_ptr<WindowPortMus> window_port =
+ base::MakeUnique<WindowPortMus>(this, WindowMusType::TOP_LEVEL);
+ roots_.insert(window_port.get());
+ return window_port;
+}
+
+void WindowTreeClient::OnWindowTreeHostCreated(
+ WindowTreeHostMus* window_tree_host) {
+ // All WindowTreeHosts are destroyed before this, so we don't need to unset
+ // the DragDropClient.
+ client::SetDragDropClient(window_tree_host->window(),
+ drag_drop_controller_.get());
}
void WindowTreeClient::OnTransientChildWindowAdded(Window* parent,
« no previous file with comments | « ui/aura/mus/window_tree_client.h ('k') | ui/aura/mus/window_tree_client_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698