Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ui/aura/mus/window_port_mus.h" | 5 #include "ui/aura/mus/window_port_mus.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_reference_factory.h" | |
| 7 #include "ui/aura/client/aura_constants.h" | 8 #include "ui/aura/client/aura_constants.h" |
| 8 #include "ui/aura/client/transient_window_client.h" | 9 #include "ui/aura/client/transient_window_client.h" |
| 9 #include "ui/aura/mus/property_converter.h" | 10 #include "ui/aura/mus/property_converter.h" |
| 10 #include "ui/aura/mus/surface_id_handler.h" | 11 #include "ui/aura/mus/surface_id_handler.h" |
| 11 #include "ui/aura/mus/window_tree_client.h" | 12 #include "ui/aura/mus/window_tree_client.h" |
| 12 #include "ui/aura/mus/window_tree_client_delegate.h" | 13 #include "ui/aura/mus/window_tree_client_delegate.h" |
| 13 #include "ui/aura/window.h" | 14 #include "ui/aura/window.h" |
| 14 #include "ui/aura/window_delegate.h" | 15 #include "ui/aura/window_delegate.h" |
| 15 #include "ui/aura/window_observer.h" | 16 #include "ui/aura/window_observer.h" |
| 16 #include "ui/aura/window_property.h" | 17 #include "ui/aura/window_property.h" |
| 17 | 18 |
| 18 namespace aura { | 19 namespace aura { |
| 20 namespace { | |
| 21 | |
| 22 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference | |
| 23 // work is complete. | |
| 24 class StubSurfaceReference : public cc::SurfaceReferenceBase { | |
| 25 public: | |
| 26 StubSurfaceReference(scoped_refptr<const cc::SurfaceReferenceFactory> factory) | |
| 27 : cc::SurfaceReferenceBase(factory) {} | |
| 28 | |
| 29 ~StubSurfaceReference() override { Destroy(); } | |
| 30 | |
| 31 private: | |
| 32 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReference); | |
| 33 }; | |
| 34 | |
| 35 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { | |
| 36 public: | |
| 37 StubSurfaceReferenceFactory() = default; | |
| 38 | |
| 39 // cc::SurfaceReferenceFactory: | |
| 40 std::unique_ptr<cc::SurfaceReferenceBase> CreateReference( | |
| 41 cc::SurfaceReferenceOwner* owner, | |
| 42 const cc::SurfaceId& surface_id) const override { | |
| 43 return base::MakeUnique<StubSurfaceReference>(make_scoped_refptr(this)); | |
| 44 } | |
| 45 | |
| 46 protected: | |
| 47 ~StubSurfaceReferenceFactory() override = default; | |
| 48 | |
| 49 private: | |
| 50 // cc::SurfaceReferenceFactory: | |
| 51 void DestroyReference(cc::SurfaceReferenceBase* surface_ref) const override {} | |
| 52 | |
| 53 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); | |
| 54 }; | |
| 55 } // namespace | |
| 56 | |
| 57 // Used by WindowPortMus when it is embedding a client. Responsible for setting | |
|
sky
2017/01/03 21:53:07
Can you move this into it's own .h/.cc?
mfomitchev
2017/01/03 22:28:50
Done.
| |
| 58 // up layers containing content from the client, parenting them to the window's | |
| 59 // layer, and updating them when the client submits new surfaces. | |
| 60 class EmbeddedContent { | |
| 61 public: | |
| 62 EmbeddedContent(Window* window); | |
|
sky
2017/01/03 21:53:07
explicit
mfomitchev
2017/01/03 22:28:50
Done.
| |
| 63 virtual ~EmbeddedContent(); | |
|
sky
2017/01/03 21:53:07
Do you really need virtual?
mfomitchev
2017/01/03 22:28:50
Nope. Removed, thanks.
| |
| 64 | |
| 65 // Updates the surface layer and the clip layer based on the surface info. | |
| 66 void UpdateSurface(const SurfaceInfo& surface_info); | |
| 67 | |
| 68 private: | |
| 69 // The window which embeds the client. | |
| 70 Window* window_; | |
| 71 | |
| 72 // Contains the client's content. | |
| 73 std::unique_ptr<ui::Layer> surface_layer_; | |
| 74 | |
| 75 // Used for clipping the surface layer to the window bounds. | |
| 76 std::unique_ptr<ui::Layer> clip_layer_; | |
| 77 | |
| 78 DISALLOW_COPY_AND_ASSIGN(EmbeddedContent); | |
| 79 }; | |
| 80 | |
| 81 EmbeddedContent::EmbeddedContent(Window* window) : window_(window) { | |
| 82 surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); | |
| 83 surface_layer_->SetVisible(true); | |
| 84 // The frame provided by the parent window->layer() needs to show through | |
| 85 // the surface layer. | |
| 86 surface_layer_->SetFillsBoundsOpaquely(false); | |
| 87 | |
| 88 clip_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_NOT_DRAWN); | |
| 89 clip_layer_->SetFillsBoundsOpaquely(false); | |
| 90 | |
| 91 clip_layer_->Add(surface_layer_.get()); | |
| 92 window_->layer()->Add(clip_layer_.get()); | |
| 93 | |
| 94 // Window's layer may contain content from this client (the embedder), e.g. | |
| 95 // this is the case with window decorations provided by Window Manager. | |
| 96 // This content should appear underneath the content of the embedded client. | |
| 97 window_->layer()->StackAtTop(clip_layer_.get()); | |
| 98 | |
| 99 // We can't set this on window's layer, because that would clip the window | |
| 100 // shadow. | |
| 101 clip_layer_->SetMasksToBounds(true); | |
| 102 } | |
| 103 | |
| 104 EmbeddedContent::~EmbeddedContent() { | |
| 105 window_->layer()->Remove(clip_layer_.get()); | |
| 106 } | |
| 107 | |
| 108 void EmbeddedContent::UpdateSurface(const SurfaceInfo& surface_info) { | |
| 109 // TODO(mfomitchev): Currently the frame size may not match the window size. | |
| 110 // In the future the surface id will be created by Ash (and used with the | |
| 111 // surface layer) when the window resize happens, which will ensure that the | |
| 112 // surface size matches the window size (unless a timeout occurs). | |
| 113 gfx::Size frame_size = surface_info.frame_size; | |
| 114 surface_layer_->SetBounds( | |
| 115 gfx::Rect(0, 0, frame_size.width(), frame_size.height())); | |
| 116 // Clip to window bounds. | |
| 117 clip_layer_->SetBounds( | |
| 118 gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); | |
| 119 | |
| 120 // TODO(mfomitchev, samans): Get rid of Aura's SurfaceInfo. | |
| 121 cc::SurfaceInfo cc_surface_info(surface_info.surface_id, | |
| 122 surface_info.device_scale_factor, frame_size); | |
| 123 | |
| 124 surface_layer_->SetShowSurface( | |
| 125 cc_surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); | |
| 126 } | |
| 19 | 127 |
| 20 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; | 128 WindowPortMus::WindowMusChangeDataImpl::WindowMusChangeDataImpl() = default; |
| 21 | 129 |
| 22 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; | 130 WindowPortMus::WindowMusChangeDataImpl::~WindowMusChangeDataImpl() = default; |
| 23 | 131 |
| 24 // static | 132 // static |
| 25 WindowMus* WindowMus::Get(Window* window) { | 133 WindowMus* WindowMus::Get(Window* window) { |
| 26 return WindowPortMus::Get(window); | 134 return WindowPortMus::Get(window); |
| 27 } | 135 } |
| 28 | 136 |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 248 if (surface_info_) { | 356 if (surface_info_) { |
| 249 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id; | 357 const cc::SurfaceId& existing_surface_id = surface_info_->surface_id; |
| 250 cc::SurfaceId new_surface_id = | 358 cc::SurfaceId new_surface_id = |
| 251 surface_info ? surface_info->surface_id : cc::SurfaceId(); | 359 surface_info ? surface_info->surface_id : cc::SurfaceId(); |
| 252 if (existing_surface_id.is_valid() && | 360 if (existing_surface_id.is_valid() && |
| 253 existing_surface_id != new_surface_id) { | 361 existing_surface_id != new_surface_id) { |
| 254 // TODO(kylechar): Start return reference here? | 362 // TODO(kylechar): Start return reference here? |
| 255 } | 363 } |
| 256 } | 364 } |
| 257 WindowPortMus* parent = Get(window_->parent()); | 365 WindowPortMus* parent = Get(window_->parent()); |
| 366 // TODO(mfomitchev): This is unused. We probably don't need this. | |
| 258 if (parent && parent->surface_id_handler_) { | 367 if (parent && parent->surface_id_handler_) { |
| 259 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, | 368 parent->surface_id_handler_->OnChildWindowSurfaceChanged(window_, |
| 260 &surface_info); | 369 &surface_info); |
| 261 } | 370 } |
| 371 | |
| 372 // The fact that SetSurfaceIdFromServer was called means that this window | |
| 373 // corresponds to an embedded client. | |
| 374 if (!embedded_content_ && surface_info) | |
| 375 embedded_content_ = base::MakeUnique<EmbeddedContent>(window_); | |
| 376 | |
| 377 if (surface_info) | |
| 378 embedded_content_->UpdateSurface(*surface_info.get()); | |
| 379 else | |
| 380 embedded_content_.reset(); | |
| 381 | |
| 262 surface_info_ = std::move(surface_info); | 382 surface_info_ = std::move(surface_info); |
| 263 } | 383 } |
| 264 | 384 |
| 265 void WindowPortMus::DestroyFromServer() { | 385 void WindowPortMus::DestroyFromServer() { |
| 266 std::unique_ptr<ScopedServerChange> remove_from_parent_change; | 386 std::unique_ptr<ScopedServerChange> remove_from_parent_change; |
| 267 if (window_->parent()) { | 387 if (window_->parent()) { |
| 268 ServerChangeData data; | 388 ServerChangeData data; |
| 269 data.child_id = server_id(); | 389 data.child_id = server_id(); |
| 270 WindowPortMus* parent = Get(window_->parent()); | 390 WindowPortMus* parent = Get(window_->parent()); |
| 271 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( | 391 remove_from_parent_change = base::MakeUnique<ScopedServerChange>( |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 425 change_data.property_name = | 545 change_data.property_name = |
| 426 GetPropertyConverter()->GetTransportNameForPropertyKey(key); | 546 GetPropertyConverter()->GetTransportNameForPropertyKey(key); |
| 427 // TODO(sky): investigate to see if we need to compare data. In particular do | 547 // TODO(sky): investigate to see if we need to compare data. In particular do |
| 428 // we ever have a case where changing a property cascades into changing the | 548 // we ever have a case where changing a property cascades into changing the |
| 429 // same property? | 549 // same property? |
| 430 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) | 550 if (!RemoveChangeByTypeAndData(ServerChangeType::PROPERTY, change_data)) |
| 431 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); | 551 window_tree_client_->OnWindowMusPropertyChanged(this, key, std::move(data)); |
| 432 } | 552 } |
| 433 | 553 |
| 434 } // namespace aura | 554 } // namespace aura |
| OLD | NEW |