| 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 "components/mus/ws/view_tree_impl.h" | 5 #include "components/mus/ws/view_tree_impl.h" |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/stl_util.h" | 8 #include "base/stl_util.h" |
| 9 #include "components/mus/ws/connection_manager.h" | 9 #include "components/mus/ws/connection_manager.h" |
| 10 #include "components/mus/ws/default_access_policy.h" | 10 #include "components/mus/ws/default_access_policy.h" |
| 11 #include "components/mus/ws/display_manager.h" | 11 #include "components/mus/ws/display_manager.h" |
| 12 #include "components/mus/ws/server_view.h" | 12 #include "components/mus/ws/server_view.h" |
| 13 #include "components/mus/ws/view_tree_host_impl.h" | 13 #include "components/mus/ws/view_tree_host_impl.h" |
| 14 #include "components/mus/ws/window_manager_access_policy.h" | 14 #include "components/mus/ws/window_manager_access_policy.h" |
| 15 #include "mojo/converters/geometry/geometry_type_converters.h" | 15 #include "mojo/converters/geometry/geometry_type_converters.h" |
| 16 #include "mojo/converters/ime/ime_type_converters.h" | 16 #include "mojo/converters/ime/ime_type_converters.h" |
| 17 #include "mojo/converters/input_events/input_events_type_converters.h" | 17 #include "mojo/converters/input_events/input_events_type_converters.h" |
| 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" | 18 #include "mojo/converters/surfaces/surfaces_type_converters.h" |
| 19 #include "ui/platform_window/text_input_state.h" | 19 #include "ui/platform_window/text_input_state.h" |
| 20 | 20 |
| 21 using mojo::Array; | 21 using mojo::Array; |
| 22 using mojo::Callback; | 22 using mojo::Callback; |
| 23 using mojo::InterfaceRequest; | 23 using mojo::InterfaceRequest; |
| 24 using mojo::OrderDirection; | |
| 25 using mojo::Rect; | 24 using mojo::Rect; |
| 26 using mojo::ServiceProvider; | 25 using mojo::ServiceProvider; |
| 27 using mojo::ServiceProviderPtr; | 26 using mojo::ServiceProviderPtr; |
| 28 using mojo::String; | 27 using mojo::String; |
| 29 using mojo::ViewDataPtr; | |
| 30 | 28 |
| 31 namespace mus { | 29 namespace mus { |
| 32 | 30 |
| 33 ViewTreeImpl::ViewTreeImpl(ConnectionManager* connection_manager, | 31 ViewTreeImpl::ViewTreeImpl(ConnectionManager* connection_manager, |
| 34 ConnectionSpecificId creator_id, | 32 ConnectionSpecificId creator_id, |
| 35 const ViewId& root_id, | 33 const ViewId& root_id, |
| 36 uint32_t policy_bitmask) | 34 uint32_t policy_bitmask) |
| 37 : connection_manager_(connection_manager), | 35 : connection_manager_(connection_manager), |
| 38 id_(connection_manager_->GetAndAdvanceNextConnectionId()), | 36 id_(connection_manager_->GetAndAdvanceNextConnectionId()), |
| 39 creator_id_(creator_id), | 37 creator_id_(creator_id), |
| 40 client_(nullptr), | 38 client_(nullptr), |
| 41 is_embed_root_(false) { | 39 is_embed_root_(false) { |
| 42 ServerView* view = GetView(root_id); | 40 ServerView* view = GetView(root_id); |
| 43 CHECK(view); | 41 CHECK(view); |
| 44 root_.reset(new ViewId(root_id)); | 42 root_.reset(new ViewId(root_id)); |
| 45 if (view->GetRoot() == view) { | 43 if (view->GetRoot() == view) { |
| 46 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); | 44 access_policy_.reset(new WindowManagerAccessPolicy(id_, this)); |
| 47 is_embed_root_ = true; | 45 is_embed_root_ = true; |
| 48 } else { | 46 } else { |
| 49 access_policy_.reset(new DefaultAccessPolicy(id_, this)); | 47 access_policy_.reset(new DefaultAccessPolicy(id_, this)); |
| 50 is_embed_root_ = (policy_bitmask & ViewTree::ACCESS_POLICY_EMBED_ROOT) != 0; | 48 is_embed_root_ = |
| 49 (policy_bitmask & WindowTree::ACCESS_POLICY_EMBED_ROOT) != 0; |
| 51 } | 50 } |
| 52 } | 51 } |
| 53 | 52 |
| 54 ViewTreeImpl::~ViewTreeImpl() { | 53 ViewTreeImpl::~ViewTreeImpl() { |
| 55 DestroyViews(); | 54 DestroyViews(); |
| 56 } | 55 } |
| 57 | 56 |
| 58 void ViewTreeImpl::Init(mojo::ViewTreeClient* client, mojo::ViewTreePtr tree) { | 57 void ViewTreeImpl::Init(mojom::WindowTreeClient* client, |
| 58 mojom::WindowTreePtr tree) { |
| 59 DCHECK(!client_); | 59 DCHECK(!client_); |
| 60 client_ = client; | 60 client_ = client; |
| 61 std::vector<const ServerView*> to_send; | 61 std::vector<const ServerView*> to_send; |
| 62 if (root_.get()) | 62 if (root_.get()) |
| 63 GetUnknownViewsFrom(GetView(*root_), &to_send); | 63 GetUnknownViewsFrom(GetView(*root_), &to_send); |
| 64 | 64 |
| 65 // TODO(beng): verify that host can actually be nullptr here. | 65 // TODO(beng): verify that host can actually be nullptr here. |
| 66 ViewTreeHostImpl* host = GetHost(); | 66 ViewTreeHostImpl* host = GetHost(); |
| 67 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; | 67 const ServerView* focused_view = host ? host->GetFocusedView() : nullptr; |
| 68 if (focused_view) | 68 if (focused_view) |
| 69 focused_view = access_policy_->GetViewForFocusChange(focused_view); | 69 focused_view = access_policy_->GetViewForFocusChange(focused_view); |
| 70 const Id focused_view_transport_id( | 70 const Id focused_view_transport_id( |
| 71 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); | 71 ViewIdToTransportId(focused_view ? focused_view->id() : ViewId())); |
| 72 | 72 |
| 73 client->OnEmbed(id_, ViewToViewData(to_send.front()), tree.Pass(), | 73 client->OnEmbed(id_, ViewToWindowData(to_send.front()), tree.Pass(), |
| 74 focused_view_transport_id, | 74 focused_view_transport_id, |
| 75 is_embed_root_ ? ViewTree::ACCESS_POLICY_EMBED_ROOT | 75 is_embed_root_ ? WindowTree::ACCESS_POLICY_EMBED_ROOT |
| 76 : ViewTree::ACCESS_POLICY_DEFAULT); | 76 : WindowTree::ACCESS_POLICY_DEFAULT); |
| 77 } | 77 } |
| 78 | 78 |
| 79 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { | 79 const ServerView* ViewTreeImpl::GetView(const ViewId& id) const { |
| 80 if (id_ == id.connection_id) { | 80 if (id_ == id.connection_id) { |
| 81 ViewMap::const_iterator i = view_map_.find(id.view_id); | 81 ViewMap::const_iterator i = view_map_.find(id.window_id); |
| 82 return i == view_map_.end() ? NULL : i->second; | 82 return i == view_map_.end() ? NULL : i->second; |
| 83 } | 83 } |
| 84 return connection_manager_->GetView(id); | 84 return connection_manager_->GetView(id); |
| 85 } | 85 } |
| 86 | 86 |
| 87 bool ViewTreeImpl::IsRoot(const ViewId& id) const { | 87 bool ViewTreeImpl::IsRoot(const ViewId& id) const { |
| 88 return root_.get() && *root_ == id; | 88 return root_.get() && *root_ == id; |
| 89 } | 89 } |
| 90 | 90 |
| 91 ViewTreeHostImpl* ViewTreeImpl::GetHost() { | 91 ViewTreeHostImpl* ViewTreeImpl::GetHost() { |
| 92 return root_.get() | 92 return root_.get() |
| 93 ? connection_manager_->GetViewTreeHostByView(GetView(*root_)) | 93 ? connection_manager_->GetWindowTreeHostByView(GetView(*root_)) |
| 94 : nullptr; | 94 : nullptr; |
| 95 } | 95 } |
| 96 | 96 |
| 97 void ViewTreeImpl::OnWillDestroyViewTreeImpl(ViewTreeImpl* connection) { | 97 void ViewTreeImpl::OnWillDestroyViewTreeImpl(ViewTreeImpl* connection) { |
| 98 if (creator_id_ == connection->id()) | 98 if (creator_id_ == connection->id()) |
| 99 creator_id_ = kInvalidConnectionId; | 99 creator_id_ = kInvalidConnectionId; |
| 100 const ServerView* connection_root = | 100 const ServerView* connection_root = |
| 101 connection->root_ ? connection->GetView(*connection->root_) : nullptr; | 101 connection->root_ ? connection->GetView(*connection->root_) : nullptr; |
| 102 if (connection_root && | 102 if (connection_root && |
| 103 ((connection_root->id().connection_id == id_ && | 103 ((connection_root->id().connection_id == id_ && |
| 104 view_map_.count(connection_root->id().view_id) > 0) || | 104 view_map_.count(connection_root->id().window_id) > 0) || |
| 105 (is_embed_root_ && IsViewKnown(connection_root)))) { | 105 (is_embed_root_ && IsViewKnown(connection_root)))) { |
| 106 client()->OnEmbeddedAppDisconnected( | 106 client()->OnEmbeddedAppDisconnected( |
| 107 ViewIdToTransportId(*connection->root_)); | 107 ViewIdToTransportId(*connection->root_)); |
| 108 } | 108 } |
| 109 if (root_.get() && root_->connection_id == connection->id()) | 109 if (root_.get() && root_->connection_id == connection->id()) |
| 110 root_.reset(); | 110 root_.reset(); |
| 111 } | 111 } |
| 112 | 112 |
| 113 mojo::ErrorCode ViewTreeImpl::CreateView(const ViewId& view_id) { | 113 mojom::ErrorCode ViewTreeImpl::NewWindow(const ViewId& window_id) { |
| 114 if (view_id.connection_id != id_) | 114 if (window_id.connection_id != id_) |
| 115 return mojo::ERROR_CODE_ILLEGAL_ARGUMENT; | 115 return mojom::ERROR_CODE_ILLEGAL_ARGUMENT; |
| 116 if (view_map_.find(view_id.view_id) != view_map_.end()) | 116 if (view_map_.find(window_id.window_id) != view_map_.end()) |
| 117 return mojo::ERROR_CODE_VALUE_IN_USE; | 117 return mojom::ERROR_CODE_VALUE_IN_USE; |
| 118 view_map_[view_id.view_id] = connection_manager_->CreateServerView(view_id); | 118 view_map_[window_id.window_id] = |
| 119 known_views_.insert(ViewIdToTransportId(view_id)); | 119 connection_manager_->CreateServerView(window_id); |
| 120 return mojo::ERROR_CODE_NONE; | 120 known_views_.insert(ViewIdToTransportId(window_id)); |
| 121 return mojom::ERROR_CODE_NONE; |
| 121 } | 122 } |
| 122 | 123 |
| 123 bool ViewTreeImpl::AddView(const ViewId& parent_id, const ViewId& child_id) { | 124 bool ViewTreeImpl::AddWindow(const ViewId& parent_id, const ViewId& child_id) { |
| 124 ServerView* parent = GetView(parent_id); | 125 ServerView* parent = GetView(parent_id); |
| 125 ServerView* child = GetView(child_id); | 126 ServerView* child = GetView(child_id); |
| 126 if (parent && child && child->parent() != parent && | 127 if (parent && child && child->parent() != parent && |
| 127 !child->Contains(parent) && access_policy_->CanAddView(parent, child)) { | 128 !child->Contains(parent) && access_policy_->CanAddWindow(parent, child)) { |
| 128 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 129 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 129 parent->Add(child); | 130 parent->Add(child); |
| 130 return true; | 131 return true; |
| 131 } | 132 } |
| 132 return false; | 133 return false; |
| 133 } | 134 } |
| 134 | 135 |
| 135 std::vector<const ServerView*> ViewTreeImpl::GetViewTree( | 136 std::vector<const ServerView*> ViewTreeImpl::GetWindowTree( |
| 136 const ViewId& view_id) const { | 137 const ViewId& window_id) const { |
| 137 const ServerView* view = GetView(view_id); | 138 const ServerView* view = GetView(window_id); |
| 138 std::vector<const ServerView*> views; | 139 std::vector<const ServerView*> views; |
| 139 if (view) | 140 if (view) |
| 140 GetViewTreeImpl(view, &views); | 141 GetWindowTreeImpl(view, &views); |
| 141 return views; | 142 return views; |
| 142 } | 143 } |
| 143 | 144 |
| 144 bool ViewTreeImpl::SetViewVisibility(const ViewId& view_id, bool visible) { | 145 bool ViewTreeImpl::SetWindowVisibility(const ViewId& window_id, bool visible) { |
| 145 ServerView* view = GetView(view_id); | 146 ServerView* view = GetView(window_id); |
| 146 if (!view || view->visible() == visible || | 147 if (!view || view->visible() == visible || |
| 147 !access_policy_->CanChangeViewVisibility(view)) { | 148 !access_policy_->CanChangeViewVisibility(view)) { |
| 148 return false; | 149 return false; |
| 149 } | 150 } |
| 150 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 151 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 151 view->SetVisible(visible); | 152 view->SetVisible(visible); |
| 152 return true; | 153 return true; |
| 153 } | 154 } |
| 154 | 155 |
| 155 bool ViewTreeImpl::Embed(const ViewId& view_id, | 156 bool ViewTreeImpl::Embed(const ViewId& window_id, |
| 156 mojo::ViewTreeClientPtr client, | 157 mojom::WindowTreeClientPtr client, |
| 157 uint32_t policy_bitmask, | 158 uint32_t policy_bitmask, |
| 158 ConnectionSpecificId* connection_id) { | 159 ConnectionSpecificId* connection_id) { |
| 159 *connection_id = kInvalidConnectionId; | 160 *connection_id = kInvalidConnectionId; |
| 160 if (!client.get() || !CanEmbed(view_id, policy_bitmask)) | 161 if (!client.get() || !CanEmbed(window_id, policy_bitmask)) |
| 161 return false; | 162 return false; |
| 162 PrepareForEmbed(view_id); | 163 PrepareForEmbed(window_id); |
| 163 ViewTreeImpl* new_connection = connection_manager_->EmbedAtView( | 164 ViewTreeImpl* new_connection = connection_manager_->EmbedAtView( |
| 164 id_, view_id, policy_bitmask, client.Pass()); | 165 id_, window_id, policy_bitmask, client.Pass()); |
| 165 if (is_embed_root_) | 166 if (is_embed_root_) |
| 166 *connection_id = new_connection->id(); | 167 *connection_id = new_connection->id(); |
| 167 return true; | 168 return true; |
| 168 } | 169 } |
| 169 | 170 |
| 170 void ViewTreeImpl::Embed(const ViewId& view_id, mojo::URLRequestPtr request) { | 171 void ViewTreeImpl::Embed(const ViewId& window_id, mojo::URLRequestPtr request) { |
| 171 if (!CanEmbed(view_id, ViewTree::ACCESS_POLICY_DEFAULT)) | 172 if (!CanEmbed(window_id, WindowTree::ACCESS_POLICY_DEFAULT)) |
| 172 return; | 173 return; |
| 173 PrepareForEmbed(view_id); | 174 PrepareForEmbed(window_id); |
| 174 connection_manager_->EmbedAtView( | 175 connection_manager_->EmbedAtView( |
| 175 id_, view_id, mojo::ViewTree::ACCESS_POLICY_DEFAULT, request.Pass()); | 176 id_, window_id, mojom::WindowTree::ACCESS_POLICY_DEFAULT, request.Pass()); |
| 176 } | 177 } |
| 177 | 178 |
| 178 void ViewTreeImpl::ProcessViewBoundsChanged(const ServerView* view, | 179 void ViewTreeImpl::ProcessViewBoundsChanged(const ServerView* view, |
| 179 const gfx::Rect& old_bounds, | 180 const gfx::Rect& old_bounds, |
| 180 const gfx::Rect& new_bounds, | 181 const gfx::Rect& new_bounds, |
| 181 bool originated_change) { | 182 bool originated_change) { |
| 182 if (originated_change || !IsViewKnown(view)) | 183 if (originated_change || !IsViewKnown(view)) |
| 183 return; | 184 return; |
| 184 client()->OnWindowBoundsChanged(ViewIdToTransportId(view->id()), | 185 client()->OnWindowBoundsChanged(ViewIdToTransportId(view->id()), |
| 185 Rect::From(old_bounds), | 186 Rect::From(old_bounds), |
| 186 Rect::From(new_bounds)); | 187 Rect::From(new_bounds)); |
| 187 } | 188 } |
| 188 | 189 |
| 189 void ViewTreeImpl::ProcessClientAreaChanged(const ServerView* window, | 190 void ViewTreeImpl::ProcessClientAreaChanged(const ServerView* window, |
| 190 const gfx::Rect& old_client_area, | 191 const gfx::Rect& old_client_area, |
| 191 const gfx::Rect& new_client_area, | 192 const gfx::Rect& new_client_area, |
| 192 bool originated_change) { | 193 bool originated_change) { |
| 193 if (originated_change || !IsViewKnown(window)) | 194 if (originated_change || !IsViewKnown(window)) |
| 194 return; | 195 return; |
| 195 client()->OnClientAreaChanged(ViewIdToTransportId(window->id()), | 196 client()->OnClientAreaChanged(ViewIdToTransportId(window->id()), |
| 196 Rect::From(old_client_area), | 197 Rect::From(old_client_area), |
| 197 Rect::From(new_client_area)); | 198 Rect::From(new_client_area)); |
| 198 } | 199 } |
| 199 | 200 |
| 200 void ViewTreeImpl::ProcessViewportMetricsChanged( | 201 void ViewTreeImpl::ProcessViewportMetricsChanged( |
| 201 const mojo::ViewportMetrics& old_metrics, | 202 const mojom::ViewportMetrics& old_metrics, |
| 202 const mojo::ViewportMetrics& new_metrics, | 203 const mojom::ViewportMetrics& new_metrics, |
| 203 bool originated_change) { | 204 bool originated_change) { |
| 204 client()->OnWindowViewportMetricsChanged(old_metrics.Clone(), | 205 client()->OnWindowViewportMetricsChanged(old_metrics.Clone(), |
| 205 new_metrics.Clone()); | 206 new_metrics.Clone()); |
| 206 } | 207 } |
| 207 | 208 |
| 208 void ViewTreeImpl::ProcessWillChangeViewHierarchy(const ServerView* view, | 209 void ViewTreeImpl::ProcessWillChangeViewHierarchy(const ServerView* view, |
| 209 const ServerView* new_parent, | 210 const ServerView* new_parent, |
| 210 const ServerView* old_parent, | 211 const ServerView* old_parent, |
| 211 bool originated_change) { | 212 bool originated_change) { |
| 212 if (originated_change) | 213 if (originated_change) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 256 } | 257 } |
| 257 // Inform the client of any new views and update the set of views we know | 258 // Inform the client of any new views and update the set of views we know |
| 258 // about. | 259 // about. |
| 259 std::vector<const ServerView*> to_send; | 260 std::vector<const ServerView*> to_send; |
| 260 if (!IsViewKnown(view)) | 261 if (!IsViewKnown(view)) |
| 261 GetUnknownViewsFrom(view, &to_send); | 262 GetUnknownViewsFrom(view, &to_send); |
| 262 const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId()); | 263 const ViewId new_parent_id(new_parent ? new_parent->id() : ViewId()); |
| 263 const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId()); | 264 const ViewId old_parent_id(old_parent ? old_parent->id() : ViewId()); |
| 264 client()->OnWindowHierarchyChanged( | 265 client()->OnWindowHierarchyChanged( |
| 265 ViewIdToTransportId(view->id()), ViewIdToTransportId(new_parent_id), | 266 ViewIdToTransportId(view->id()), ViewIdToTransportId(new_parent_id), |
| 266 ViewIdToTransportId(old_parent_id), ViewsToViewDatas(to_send)); | 267 ViewIdToTransportId(old_parent_id), ViewsToWindowDatas(to_send)); |
| 267 connection_manager_->OnConnectionMessagedClient(id_); | 268 connection_manager_->OnConnectionMessagedClient(id_); |
| 268 } | 269 } |
| 269 | 270 |
| 270 void ViewTreeImpl::ProcessViewReorder(const ServerView* view, | 271 void ViewTreeImpl::ProcessViewReorder(const ServerView* view, |
| 271 const ServerView* relative_view, | 272 const ServerView* relative_view, |
| 272 OrderDirection direction, | 273 mojom::OrderDirection direction, |
| 273 bool originated_change) { | 274 bool originated_change) { |
| 274 if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view)) | 275 if (originated_change || !IsViewKnown(view) || !IsViewKnown(relative_view)) |
| 275 return; | 276 return; |
| 276 | 277 |
| 277 client()->OnWindowReordered(ViewIdToTransportId(view->id()), | 278 client()->OnWindowReordered(ViewIdToTransportId(view->id()), |
| 278 ViewIdToTransportId(relative_view->id()), | 279 ViewIdToTransportId(relative_view->id()), |
| 279 direction); | 280 direction); |
| 280 } | 281 } |
| 281 | 282 |
| 282 void ViewTreeImpl::ProcessViewDeleted(const ViewId& view, | 283 void ViewTreeImpl::ProcessViewDeleted(const ViewId& view, |
| 283 bool originated_change) { | 284 bool originated_change) { |
| 284 if (view.connection_id == id_) | 285 if (view.connection_id == id_) |
| 285 view_map_.erase(view.view_id); | 286 view_map_.erase(view.window_id); |
| 286 | 287 |
| 287 const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0; | 288 const bool in_known = known_views_.erase(ViewIdToTransportId(view)) > 0; |
| 288 | 289 |
| 289 if (IsRoot(view)) | 290 if (IsRoot(view)) |
| 290 root_.reset(); | 291 root_.reset(); |
| 291 | 292 |
| 292 if (originated_change) | 293 if (originated_change) |
| 293 return; | 294 return; |
| 294 | 295 |
| 295 if (in_known) { | 296 if (in_known) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 327 new_focused_view ? access_policy_->GetViewForFocusChange(new_focused_view) | 328 new_focused_view ? access_policy_->GetViewForFocusChange(new_focused_view) |
| 328 : nullptr; | 329 : nullptr; |
| 329 client()->OnWindowFocused(view ? ViewIdToTransportId(view->id()) | 330 client()->OnWindowFocused(view ? ViewIdToTransportId(view->id()) |
| 330 : ViewIdToTransportId(ViewId())); | 331 : ViewIdToTransportId(ViewId())); |
| 331 } | 332 } |
| 332 | 333 |
| 333 bool ViewTreeImpl::IsViewKnown(const ServerView* view) const { | 334 bool ViewTreeImpl::IsViewKnown(const ServerView* view) const { |
| 334 return known_views_.count(ViewIdToTransportId(view->id())) > 0; | 335 return known_views_.count(ViewIdToTransportId(view->id())) > 0; |
| 335 } | 336 } |
| 336 | 337 |
| 337 bool ViewTreeImpl::CanReorderView(const ServerView* view, | 338 bool ViewTreeImpl::CanReorderWindow(const ServerView* view, |
| 338 const ServerView* relative_view, | 339 const ServerView* relative_view, |
| 339 OrderDirection direction) const { | 340 mojom::OrderDirection direction) const { |
| 340 if (!view || !relative_view) | 341 if (!view || !relative_view) |
| 341 return false; | 342 return false; |
| 342 | 343 |
| 343 if (!view->parent() || view->parent() != relative_view->parent()) | 344 if (!view->parent() || view->parent() != relative_view->parent()) |
| 344 return false; | 345 return false; |
| 345 | 346 |
| 346 if (!access_policy_->CanReorderView(view, relative_view, direction)) | 347 if (!access_policy_->CanReorderWindow(view, relative_view, direction)) |
| 347 return false; | 348 return false; |
| 348 | 349 |
| 349 std::vector<const ServerView*> children = view->parent()->GetChildren(); | 350 std::vector<const ServerView*> children = view->parent()->GetChildren(); |
| 350 const size_t child_i = | 351 const size_t child_i = |
| 351 std::find(children.begin(), children.end(), view) - children.begin(); | 352 std::find(children.begin(), children.end(), view) - children.begin(); |
| 352 const size_t target_i = | 353 const size_t target_i = |
| 353 std::find(children.begin(), children.end(), relative_view) - | 354 std::find(children.begin(), children.end(), relative_view) - |
| 354 children.begin(); | 355 children.begin(); |
| 355 if ((direction == mojo::ORDER_DIRECTION_ABOVE && child_i == target_i + 1) || | 356 if ((direction == mojom::ORDER_DIRECTION_ABOVE && child_i == target_i + 1) || |
| 356 (direction == mojo::ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) { | 357 (direction == mojom::ORDER_DIRECTION_BELOW && child_i + 1 == target_i)) { |
| 357 return false; | 358 return false; |
| 358 } | 359 } |
| 359 | 360 |
| 360 return true; | 361 return true; |
| 361 } | 362 } |
| 362 | 363 |
| 363 bool ViewTreeImpl::DeleteViewImpl(ViewTreeImpl* source, ServerView* view) { | 364 bool ViewTreeImpl::DeleteWindowImpl(ViewTreeImpl* source, ServerView* view) { |
| 364 DCHECK(view); | 365 DCHECK(view); |
| 365 DCHECK_EQ(view->id().connection_id, id_); | 366 DCHECK_EQ(view->id().connection_id, id_); |
| 366 ConnectionManager::ScopedChange change(source, connection_manager_, true); | 367 ConnectionManager::ScopedChange change(source, connection_manager_, true); |
| 367 delete view; | 368 delete view; |
| 368 return true; | 369 return true; |
| 369 } | 370 } |
| 370 | 371 |
| 371 void ViewTreeImpl::GetUnknownViewsFrom(const ServerView* view, | 372 void ViewTreeImpl::GetUnknownViewsFrom(const ServerView* view, |
| 372 std::vector<const ServerView*>* views) { | 373 std::vector<const ServerView*>* views) { |
| 373 if (IsViewKnown(view) || !access_policy_->CanGetViewTree(view)) | 374 if (IsViewKnown(view) || !access_policy_->CanGetWindowTree(view)) |
| 374 return; | 375 return; |
| 375 views->push_back(view); | 376 views->push_back(view); |
| 376 known_views_.insert(ViewIdToTransportId(view->id())); | 377 known_views_.insert(ViewIdToTransportId(view->id())); |
| 377 if (!access_policy_->CanDescendIntoViewForViewTree(view)) | 378 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 378 return; | 379 return; |
| 379 std::vector<const ServerView*> children(view->GetChildren()); | 380 std::vector<const ServerView*> children(view->GetChildren()); |
| 380 for (size_t i = 0; i < children.size(); ++i) | 381 for (size_t i = 0; i < children.size(); ++i) |
| 381 GetUnknownViewsFrom(children[i], views); | 382 GetUnknownViewsFrom(children[i], views); |
| 382 } | 383 } |
| 383 | 384 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 407 connection_manager_->OnConnectionMessagedClient(id_); | 408 connection_manager_->OnConnectionMessagedClient(id_); |
| 408 | 409 |
| 409 // This connection no longer knows about the view. Unparent any views that | 410 // This connection no longer knows about the view. Unparent any views that |
| 410 // were parented to views in the root. | 411 // were parented to views in the root. |
| 411 std::vector<ServerView*> local_views; | 412 std::vector<ServerView*> local_views; |
| 412 RemoveFromKnown(GetView(root_id), &local_views); | 413 RemoveFromKnown(GetView(root_id), &local_views); |
| 413 for (size_t i = 0; i < local_views.size(); ++i) | 414 for (size_t i = 0; i < local_views.size(); ++i) |
| 414 local_views[i]->parent()->Remove(local_views[i]); | 415 local_views[i]->parent()->Remove(local_views[i]); |
| 415 } | 416 } |
| 416 | 417 |
| 417 Array<ViewDataPtr> ViewTreeImpl::ViewsToViewDatas( | 418 Array<mojom::WindowDataPtr> ViewTreeImpl::ViewsToWindowDatas( |
| 418 const std::vector<const ServerView*>& views) { | 419 const std::vector<const ServerView*>& views) { |
| 419 Array<ViewDataPtr> array(views.size()); | 420 Array<mojom::WindowDataPtr> array(views.size()); |
| 420 for (size_t i = 0; i < views.size(); ++i) | 421 for (size_t i = 0; i < views.size(); ++i) |
| 421 array[i] = ViewToViewData(views[i]).Pass(); | 422 array[i] = ViewToWindowData(views[i]).Pass(); |
| 422 return array.Pass(); | 423 return array.Pass(); |
| 423 } | 424 } |
| 424 | 425 |
| 425 ViewDataPtr ViewTreeImpl::ViewToViewData(const ServerView* view) { | 426 mojom::WindowDataPtr ViewTreeImpl::ViewToWindowData(const ServerView* view) { |
| 426 DCHECK(IsViewKnown(view)); | 427 DCHECK(IsViewKnown(view)); |
| 427 const ServerView* parent = view->parent(); | 428 const ServerView* parent = view->parent(); |
| 428 // If the parent isn't known, it means the parent is not visible to us (not | 429 // If the parent isn't known, it means the parent is not visible to us (not |
| 429 // in roots), and should not be sent over. | 430 // in roots), and should not be sent over. |
| 430 if (parent && !IsViewKnown(parent)) | 431 if (parent && !IsViewKnown(parent)) |
| 431 parent = NULL; | 432 parent = NULL; |
| 432 ViewDataPtr view_data(mojo::ViewData::New()); | 433 mojom::WindowDataPtr view_data(mojom::WindowData::New()); |
| 433 view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId()); | 434 view_data->parent_id = ViewIdToTransportId(parent ? parent->id() : ViewId()); |
| 434 view_data->view_id = ViewIdToTransportId(view->id()); | 435 view_data->window_id = ViewIdToTransportId(view->id()); |
| 435 view_data->bounds = Rect::From(view->bounds()); | 436 view_data->bounds = Rect::From(view->bounds()); |
| 436 view_data->properties = | 437 view_data->properties = |
| 437 mojo::Map<String, Array<uint8_t>>::From(view->properties()); | 438 mojo::Map<String, Array<uint8_t>>::From(view->properties()); |
| 438 view_data->visible = view->visible(); | 439 view_data->visible = view->visible(); |
| 439 view_data->drawn = view->IsDrawn(); | 440 view_data->drawn = view->IsDrawn(); |
| 440 view_data->viewport_metrics = | 441 view_data->viewport_metrics = |
| 441 connection_manager_->GetViewportMetricsForView(view); | 442 connection_manager_->GetViewportMetricsForView(view); |
| 442 return view_data.Pass(); | 443 return view_data.Pass(); |
| 443 } | 444 } |
| 444 | 445 |
| 445 void ViewTreeImpl::GetViewTreeImpl( | 446 void ViewTreeImpl::GetWindowTreeImpl( |
| 446 const ServerView* view, | 447 const ServerView* view, |
| 447 std::vector<const ServerView*>* views) const { | 448 std::vector<const ServerView*>* views) const { |
| 448 DCHECK(view); | 449 DCHECK(view); |
| 449 | 450 |
| 450 if (!access_policy_->CanGetViewTree(view)) | 451 if (!access_policy_->CanGetWindowTree(view)) |
| 451 return; | 452 return; |
| 452 | 453 |
| 453 views->push_back(view); | 454 views->push_back(view); |
| 454 | 455 |
| 455 if (!access_policy_->CanDescendIntoViewForViewTree(view)) | 456 if (!access_policy_->CanDescendIntoViewForViewTree(view)) |
| 456 return; | 457 return; |
| 457 | 458 |
| 458 std::vector<const ServerView*> children(view->GetChildren()); | 459 std::vector<const ServerView*> children(view->GetChildren()); |
| 459 for (size_t i = 0; i < children.size(); ++i) | 460 for (size_t i = 0; i < children.size(); ++i) |
| 460 GetViewTreeImpl(children[i], views); | 461 GetWindowTreeImpl(children[i], views); |
| 461 } | 462 } |
| 462 | 463 |
| 463 void ViewTreeImpl::NotifyDrawnStateChanged(const ServerView* view, | 464 void ViewTreeImpl::NotifyDrawnStateChanged(const ServerView* view, |
| 464 bool new_drawn_value) { | 465 bool new_drawn_value) { |
| 465 // Even though we don't know about view, it may be an ancestor of our root, in | 466 // Even though we don't know about view, it may be an ancestor of our root, in |
| 466 // which case the change may effect our roots drawn state. | 467 // which case the change may effect our roots drawn state. |
| 467 if (!root_.get()) | 468 if (!root_.get()) |
| 468 return; | 469 return; |
| 469 | 470 |
| 470 const ServerView* root = GetView(*root_); | 471 const ServerView* root = GetView(*root_); |
| 471 DCHECK(root); | 472 DCHECK(root); |
| 472 if (view->Contains(root) && (new_drawn_value != root->IsDrawn())) { | 473 if (view->Contains(root) && (new_drawn_value != root->IsDrawn())) { |
| 473 client()->OnWindowDrawnStateChanged(ViewIdToTransportId(root->id()), | 474 client()->OnWindowDrawnStateChanged(ViewIdToTransportId(root->id()), |
| 474 new_drawn_value); | 475 new_drawn_value); |
| 475 } | 476 } |
| 476 } | 477 } |
| 477 | 478 |
| 478 void ViewTreeImpl::DestroyViews() { | 479 void ViewTreeImpl::DestroyViews() { |
| 479 if (!view_map_.empty()) { | 480 if (!view_map_.empty()) { |
| 480 ConnectionManager::ScopedChange change(this, connection_manager_, true); | 481 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 481 // If we get here from the destructor we're not going to get | 482 // If we get here from the destructor we're not going to get |
| 482 // ProcessViewDeleted(). Copy the map and delete from the copy so that we | 483 // ProcessViewDeleted(). Copy the map and delete from the copy so that we |
| 483 // don't have to worry about whether |view_map_| changes or not. | 484 // don't have to worry about whether |view_map_| changes or not. |
| 484 ViewMap view_map_copy; | 485 ViewMap view_map_copy; |
| 485 view_map_.swap(view_map_copy); | 486 view_map_.swap(view_map_copy); |
| 486 STLDeleteValues(&view_map_copy); | 487 STLDeleteValues(&view_map_copy); |
| 487 } | 488 } |
| 488 } | 489 } |
| 489 | 490 |
| 490 bool ViewTreeImpl::CanEmbed(const ViewId& view_id, | 491 bool ViewTreeImpl::CanEmbed(const ViewId& window_id, |
| 491 uint32_t policy_bitmask) const { | 492 uint32_t policy_bitmask) const { |
| 492 const ServerView* view = GetView(view_id); | 493 const ServerView* view = GetView(window_id); |
| 493 return view && access_policy_->CanEmbed(view, policy_bitmask); | 494 return view && access_policy_->CanEmbed(view, policy_bitmask); |
| 494 } | 495 } |
| 495 | 496 |
| 496 void ViewTreeImpl::PrepareForEmbed(const ViewId& view_id) { | 497 void ViewTreeImpl::PrepareForEmbed(const ViewId& window_id) { |
| 497 const ServerView* view = GetView(view_id); | 498 const ServerView* view = GetView(window_id); |
| 498 DCHECK(view); | 499 DCHECK(view); |
| 499 | 500 |
| 500 // Only allow a node to be the root for one connection. | 501 // Only allow a node to be the root for one connection. |
| 501 ViewTreeImpl* existing_owner = | 502 ViewTreeImpl* existing_owner = |
| 502 connection_manager_->GetConnectionWithRoot(view_id); | 503 connection_manager_->GetConnectionWithRoot(window_id); |
| 503 | 504 |
| 504 ConnectionManager::ScopedChange change(this, connection_manager_, true); | 505 ConnectionManager::ScopedChange change(this, connection_manager_, true); |
| 505 RemoveChildrenAsPartOfEmbed(view_id); | 506 RemoveChildrenAsPartOfEmbed(window_id); |
| 506 if (existing_owner) { | 507 if (existing_owner) { |
| 507 // Never message the originating connection. | 508 // Never message the originating connection. |
| 508 connection_manager_->OnConnectionMessagedClient(id_); | 509 connection_manager_->OnConnectionMessagedClient(id_); |
| 509 existing_owner->RemoveRoot(); | 510 existing_owner->RemoveRoot(); |
| 510 } | 511 } |
| 511 } | 512 } |
| 512 | 513 |
| 513 void ViewTreeImpl::RemoveChildrenAsPartOfEmbed(const ViewId& view_id) { | 514 void ViewTreeImpl::RemoveChildrenAsPartOfEmbed(const ViewId& window_id) { |
| 514 ServerView* view = GetView(view_id); | 515 ServerView* view = GetView(window_id); |
| 515 CHECK(view); | 516 CHECK(view); |
| 516 CHECK(view->id().connection_id == view_id.connection_id); | 517 CHECK(view->id().connection_id == window_id.connection_id); |
| 517 std::vector<ServerView*> children = view->GetChildren(); | 518 std::vector<ServerView*> children = view->GetChildren(); |
| 518 for (size_t i = 0; i < children.size(); ++i) | 519 for (size_t i = 0; i < children.size(); ++i) |
| 519 view->Remove(children[i]); | 520 view->Remove(children[i]); |
| 520 } | 521 } |
| 521 | 522 |
| 522 void ViewTreeImpl::CreateView(Id transport_view_id, | 523 void ViewTreeImpl::NewWindow(Id transport_window_id, |
| 523 const Callback<void(mojo::ErrorCode)>& callback) { | 524 const Callback<void(mojom::ErrorCode)>& callback) { |
| 524 callback.Run(CreateView(ViewIdFromTransportId(transport_view_id))); | 525 callback.Run(NewWindow(ViewIdFromTransportId(transport_window_id))); |
| 525 } | 526 } |
| 526 | 527 |
| 527 void ViewTreeImpl::DeleteView(Id transport_view_id, | 528 void ViewTreeImpl::DeleteWindow(Id transport_window_id, |
| 528 const Callback<void(bool)>& callback) { | 529 const Callback<void(bool)>& callback) { |
| 529 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 530 ServerView* view = GetView(ViewIdFromTransportId(transport_window_id)); |
| 530 bool success = false; | 531 bool success = false; |
| 531 if (view && access_policy_->CanDeleteView(view)) { | 532 if (view && access_policy_->CanDeleteWindow(view)) { |
| 532 ViewTreeImpl* connection = | 533 ViewTreeImpl* connection = |
| 533 connection_manager_->GetConnection(view->id().connection_id); | 534 connection_manager_->GetConnection(view->id().connection_id); |
| 534 success = connection && connection->DeleteViewImpl(this, view); | 535 success = connection && connection->DeleteWindowImpl(this, view); |
| 535 } | 536 } |
| 536 callback.Run(success); | 537 callback.Run(success); |
| 537 } | 538 } |
| 538 | 539 |
| 539 void ViewTreeImpl::AddView(Id parent_id, | 540 void ViewTreeImpl::AddWindow(Id parent_id, |
| 540 Id child_id, | 541 Id child_id, |
| 541 const Callback<void(bool)>& callback) { | 542 const Callback<void(bool)>& callback) { |
| 542 callback.Run(AddView(ViewIdFromTransportId(parent_id), | 543 callback.Run(AddWindow(ViewIdFromTransportId(parent_id), |
| 543 ViewIdFromTransportId(child_id))); | 544 ViewIdFromTransportId(child_id))); |
| 544 } | 545 } |
| 545 | 546 |
| 546 void ViewTreeImpl::RemoveViewFromParent(Id view_id, | 547 void ViewTreeImpl::RemoveWindowFromParent( |
| 547 const Callback<void(bool)>& callback) { | 548 Id window_id, |
| 549 const Callback<void(bool)>& callback) { |
| 548 bool success = false; | 550 bool success = false; |
| 549 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 551 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 550 if (view && view->parent() && access_policy_->CanRemoveViewFromParent(view)) { | 552 if (view && view->parent() && |
| 553 access_policy_->CanRemoveWindowFromParent(view)) { |
| 551 success = true; | 554 success = true; |
| 552 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 555 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 553 view->parent()->Remove(view); | 556 view->parent()->Remove(view); |
| 554 } | 557 } |
| 555 callback.Run(success); | 558 callback.Run(success); |
| 556 } | 559 } |
| 557 | 560 |
| 558 void ViewTreeImpl::ReorderView(Id view_id, | 561 void ViewTreeImpl::ReorderWindow(Id window_id, |
| 559 Id relative_view_id, | 562 Id relative_window_id, |
| 560 OrderDirection direction, | 563 mojom::OrderDirection direction, |
| 561 const Callback<void(bool)>& callback) { | 564 const Callback<void(bool)>& callback) { |
| 562 bool success = false; | 565 bool success = false; |
| 563 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 566 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 564 ServerView* relative_view = GetView(ViewIdFromTransportId(relative_view_id)); | 567 ServerView* relative_view = |
| 565 if (CanReorderView(view, relative_view, direction)) { | 568 GetView(ViewIdFromTransportId(relative_window_id)); |
| 569 if (CanReorderWindow(view, relative_view, direction)) { |
| 566 success = true; | 570 success = true; |
| 567 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 571 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 568 view->parent()->Reorder(view, relative_view, direction); | 572 view->parent()->Reorder(view, relative_view, direction); |
| 569 connection_manager_->ProcessViewReorder(view, relative_view, direction); | 573 connection_manager_->ProcessViewReorder(view, relative_view, direction); |
| 570 } | 574 } |
| 571 callback.Run(success); | 575 callback.Run(success); |
| 572 } | 576 } |
| 573 | 577 |
| 574 void ViewTreeImpl::GetViewTree( | 578 void ViewTreeImpl::GetWindowTree( |
| 575 Id view_id, | 579 Id window_id, |
| 576 const Callback<void(Array<ViewDataPtr>)>& callback) { | 580 const Callback<void(Array<mojom::WindowDataPtr>)>& callback) { |
| 577 std::vector<const ServerView*> views( | 581 std::vector<const ServerView*> views( |
| 578 GetViewTree(ViewIdFromTransportId(view_id))); | 582 GetWindowTree(ViewIdFromTransportId(window_id))); |
| 579 callback.Run(ViewsToViewDatas(views)); | 583 callback.Run(ViewsToWindowDatas(views)); |
| 580 } | 584 } |
| 581 | 585 |
| 582 void ViewTreeImpl::SetViewBounds(Id view_id, | 586 void ViewTreeImpl::SetWindowBounds(Id window_id, |
| 583 mojo::RectPtr bounds, | 587 mojo::RectPtr bounds, |
| 584 const Callback<void(bool)>& callback) { | 588 const Callback<void(bool)>& callback) { |
| 585 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 589 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 586 const bool success = view && access_policy_->CanSetViewBounds(view); | 590 const bool success = view && access_policy_->CanSetWindowBounds(view); |
| 587 if (success) { | 591 if (success) { |
| 588 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 592 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 589 view->SetBounds(bounds.To<gfx::Rect>()); | 593 view->SetBounds(bounds.To<gfx::Rect>()); |
| 590 } | 594 } |
| 591 callback.Run(success); | 595 callback.Run(success); |
| 592 } | 596 } |
| 593 | 597 |
| 594 void ViewTreeImpl::SetViewVisibility(Id transport_view_id, | 598 void ViewTreeImpl::SetWindowVisibility(Id transport_window_id, |
| 595 bool visible, | 599 bool visible, |
| 596 const Callback<void(bool)>& callback) { | 600 const Callback<void(bool)>& callback) { |
| 597 callback.Run( | 601 callback.Run( |
| 598 SetViewVisibility(ViewIdFromTransportId(transport_view_id), visible)); | 602 SetWindowVisibility(ViewIdFromTransportId(transport_window_id), visible)); |
| 599 } | 603 } |
| 600 | 604 |
| 601 void ViewTreeImpl::SetViewProperty(uint32_t view_id, | 605 void ViewTreeImpl::SetWindowProperty( |
| 602 const mojo::String& name, | 606 uint32_t window_id, |
| 603 mojo::Array<uint8_t> value, | 607 const mojo::String& name, |
| 604 const mojo::Callback<void(bool)>& callback) { | 608 mojo::Array<uint8_t> value, |
| 605 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 609 const mojo::Callback<void(bool)>& callback) { |
| 606 const bool success = view && access_policy_->CanSetViewProperties(view); | 610 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 611 const bool success = view && access_policy_->CanSetWindowProperties(view); |
| 607 if (success) { | 612 if (success) { |
| 608 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 613 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 609 | 614 |
| 610 if (value.is_null()) { | 615 if (value.is_null()) { |
| 611 view->SetProperty(name, nullptr); | 616 view->SetProperty(name, nullptr); |
| 612 } else { | 617 } else { |
| 613 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); | 618 std::vector<uint8_t> data = value.To<std::vector<uint8_t>>(); |
| 614 view->SetProperty(name, &data); | 619 view->SetProperty(name, &data); |
| 615 } | 620 } |
| 616 } | 621 } |
| 617 callback.Run(success); | 622 callback.Run(success); |
| 618 } | 623 } |
| 619 | 624 |
| 620 void ViewTreeImpl::RequestSurface(Id view_id, | 625 void ViewTreeImpl::RequestSurface( |
| 621 mojo::InterfaceRequest<mojo::Surface> surface, | 626 Id window_id, |
| 622 mojo::SurfaceClientPtr client) { | 627 mojo::InterfaceRequest<mojom::Surface> surface, |
| 623 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 628 mojom::SurfaceClientPtr client) { |
| 629 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 624 const bool success = view && access_policy_->CanSetWindowSurfaceId(view); | 630 const bool success = view && access_policy_->CanSetWindowSurfaceId(view); |
| 625 if (!success) | 631 if (!success) |
| 626 return; | 632 return; |
| 627 view->Bind(surface.Pass(), client.Pass()); | 633 view->Bind(surface.Pass(), client.Pass()); |
| 628 } | 634 } |
| 629 | 635 |
| 630 void ViewTreeImpl::SetViewTextInputState(uint32_t view_id, | 636 void ViewTreeImpl::SetWindowTextInputState(uint32_t window_id, |
| 631 mojo::TextInputStatePtr state) { | 637 mojo::TextInputStatePtr state) { |
| 632 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 638 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 633 bool success = view && access_policy_->CanSetViewTextInputState(view); | 639 bool success = view && access_policy_->CanSetWindowTextInputState(view); |
| 634 if (success) | 640 if (success) |
| 635 view->SetTextInputState(state.To<ui::TextInputState>()); | 641 view->SetTextInputState(state.To<ui::TextInputState>()); |
| 636 } | 642 } |
| 637 | 643 |
| 638 void ViewTreeImpl::SetImeVisibility(Id transport_view_id, | 644 void ViewTreeImpl::SetImeVisibility(Id transport_window_id, |
| 639 bool visible, | 645 bool visible, |
| 640 mojo::TextInputStatePtr state) { | 646 mojo::TextInputStatePtr state) { |
| 641 ServerView* view = GetView(ViewIdFromTransportId(transport_view_id)); | 647 ServerView* view = GetView(ViewIdFromTransportId(transport_window_id)); |
| 642 bool success = view && access_policy_->CanSetViewTextInputState(view); | 648 bool success = view && access_policy_->CanSetWindowTextInputState(view); |
| 643 if (success) { | 649 if (success) { |
| 644 if (!state.is_null()) | 650 if (!state.is_null()) |
| 645 view->SetTextInputState(state.To<ui::TextInputState>()); | 651 view->SetTextInputState(state.To<ui::TextInputState>()); |
| 646 | 652 |
| 647 ViewTreeHostImpl* host = GetHost(); | 653 ViewTreeHostImpl* host = GetHost(); |
| 648 if (host) | 654 if (host) |
| 649 host->SetImeVisibility(view, visible); | 655 host->SetImeVisibility(view, visible); |
| 650 } | 656 } |
| 651 } | 657 } |
| 652 | 658 |
| 653 void ViewTreeImpl::SetClientArea(Id transport_window_id, mojo::RectPtr rect) { | 659 void ViewTreeImpl::SetClientArea(Id transport_window_id, mojo::RectPtr rect) { |
| 654 ServerView* window = GetView(ViewIdFromTransportId(transport_window_id)); | 660 ServerView* window = GetView(ViewIdFromTransportId(transport_window_id)); |
| 655 if (!window || !access_policy_->CanSetClientArea(window)) | 661 if (!window || !access_policy_->CanSetClientArea(window)) |
| 656 return; | 662 return; |
| 657 | 663 |
| 658 if (rect.is_null()) | 664 if (rect.is_null()) |
| 659 window->SetClientArea(gfx::Rect(window->bounds().size())); | 665 window->SetClientArea(gfx::Rect(window->bounds().size())); |
| 660 else | 666 else |
| 661 window->SetClientArea(rect.To<gfx::Rect>()); | 667 window->SetClientArea(rect.To<gfx::Rect>()); |
| 662 } | 668 } |
| 663 | 669 |
| 664 void ViewTreeImpl::Embed(Id transport_view_id, | 670 void ViewTreeImpl::Embed(Id transport_window_id, |
| 665 mojo::ViewTreeClientPtr client, | 671 mojom::WindowTreeClientPtr client, |
| 666 uint32_t policy_bitmask, | 672 uint32_t policy_bitmask, |
| 667 const EmbedCallback& callback) { | 673 const EmbedCallback& callback) { |
| 668 ConnectionSpecificId connection_id = kInvalidConnectionId; | 674 ConnectionSpecificId connection_id = kInvalidConnectionId; |
| 669 const bool result = Embed(ViewIdFromTransportId(transport_view_id), | 675 const bool result = Embed(ViewIdFromTransportId(transport_window_id), |
| 670 client.Pass(), policy_bitmask, &connection_id); | 676 client.Pass(), policy_bitmask, &connection_id); |
| 671 callback.Run(result, connection_id); | 677 callback.Run(result, connection_id); |
| 672 } | 678 } |
| 673 | 679 |
| 674 void ViewTreeImpl::SetFocus(uint32_t view_id) { | 680 void ViewTreeImpl::SetFocus(uint32_t window_id) { |
| 675 ServerView* view = GetView(ViewIdFromTransportId(view_id)); | 681 ServerView* view = GetView(ViewIdFromTransportId(window_id)); |
| 676 // TODO(beng): consider shifting non-policy drawn check logic to VTH's | 682 // TODO(beng): consider shifting non-policy drawn check logic to VTH's |
| 677 // FocusController. | 683 // FocusController. |
| 678 if (view && view->IsDrawn() && access_policy_->CanSetFocus(view)) { | 684 if (view && view->IsDrawn() && access_policy_->CanSetFocus(view)) { |
| 679 ConnectionManager::ScopedChange change(this, connection_manager_, false); | 685 ConnectionManager::ScopedChange change(this, connection_manager_, false); |
| 680 ViewTreeHostImpl* host = GetHost(); | 686 ViewTreeHostImpl* host = GetHost(); |
| 681 if (host) | 687 if (host) |
| 682 host->SetFocusedView(view); | 688 host->SetFocusedView(view); |
| 683 } | 689 } |
| 684 } | 690 } |
| 685 | 691 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 696 ViewTreeImpl* connection = | 702 ViewTreeImpl* connection = |
| 697 connection_manager_->GetConnectionWithRoot(view->id()); | 703 connection_manager_->GetConnectionWithRoot(view->id()); |
| 698 return connection && connection != this; | 704 return connection && connection != this; |
| 699 } | 705 } |
| 700 | 706 |
| 701 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { | 707 bool ViewTreeImpl::IsDescendantOfEmbedRoot(const ServerView* view) { |
| 702 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); | 708 return is_embed_root_ && root_ && GetView(*root_)->Contains(view); |
| 703 } | 709 } |
| 704 | 710 |
| 705 } // namespace mus | 711 } // namespace mus |
| OLD | NEW |