Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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/client_surface_embedder.h" | 5 #include "ui/aura/mus/client_surface_embedder.h" |
| 6 | 6 |
| 7 #include "cc/surfaces/surface_reference_factory.h" | 7 #include "cc/surfaces/surface_reference_factory.h" |
| 8 #include "ui/aura/window.h" | 8 #include "ui/aura/window.h" |
| 9 | 9 |
| 10 namespace aura { | 10 namespace aura { |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 23 return base::Closure(); | 23 return base::Closure(); |
| 24 } | 24 } |
| 25 | 25 |
| 26 protected: | 26 protected: |
| 27 ~StubSurfaceReferenceFactory() override = default; | 27 ~StubSurfaceReferenceFactory() override = default; |
| 28 | 28 |
| 29 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); | 29 DISALLOW_COPY_AND_ASSIGN(StubSurfaceReferenceFactory); |
| 30 }; | 30 }; |
| 31 } // namespace | 31 } // namespace |
| 32 | 32 |
| 33 ClientSurfaceEmbedder::ClientSurfaceEmbedder(Window* window) : window_(window) { | 33 ClientSurfaceEmbedder::ClientSurfaceEmbedder( |
| 34 Window* window, | |
| 35 const gfx::Insets& client_area_insets) | |
| 36 : window_(window), client_area_insets_(client_area_insets) { | |
| 34 surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); | 37 surface_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_TEXTURED); |
| 35 surface_layer_->SetVisible(true); | 38 surface_layer_->SetMasksToBounds(true); |
| 36 // The frame provided by the parent window->layer() needs to show through | 39 // The frame provided by the parent window->layer() needs to show through |
| 37 // the surface layer. | 40 // the surface layer. |
| 38 surface_layer_->SetFillsBoundsOpaquely(false); | 41 surface_layer_->SetFillsBoundsOpaquely(false); |
| 39 | 42 |
| 40 clip_layer_ = base::MakeUnique<ui::Layer>(ui::LAYER_NOT_DRAWN); | 43 window_->layer()->Add(surface_layer_.get()); |
| 41 clip_layer_->SetFillsBoundsOpaquely(false); | |
| 42 | |
| 43 clip_layer_->Add(surface_layer_.get()); | |
| 44 window_->layer()->Add(clip_layer_.get()); | |
| 45 | 44 |
| 46 // Window's layer may contain content from this client (the embedder), e.g. | 45 // Window's layer may contain content from this client (the embedder), e.g. |
| 47 // this is the case with window decorations provided by Window Manager. | 46 // this is the case with window decorations provided by Window Manager. |
| 48 // This content should appear underneath the content of the embedded client. | 47 // This content should appear underneath the content of the embedded client. |
| 49 window_->layer()->StackAtTop(clip_layer_.get()); | 48 window_->layer()->StackAtTop(surface_layer_.get()); |
| 50 | |
| 51 // We can't set this on window's layer, because that would clip the window | |
| 52 // shadow. | |
| 53 clip_layer_->SetMasksToBounds(true); | |
| 54 } | 49 } |
| 55 | 50 |
| 56 ClientSurfaceEmbedder::~ClientSurfaceEmbedder() = default; | 51 ClientSurfaceEmbedder::~ClientSurfaceEmbedder() = default; |
| 57 | 52 |
| 58 void ClientSurfaceEmbedder::SetPrimarySurfaceInfo( | 53 void ClientSurfaceEmbedder::SetPrimarySurfaceInfo( |
| 59 const cc::SurfaceInfo& surface_info) { | 54 const cc::SurfaceInfo& surface_info) { |
| 60 // TODO(mfomitchev): Currently the frame size may not match the window size. | |
| 61 // In the future the surface id will be created by Ash (and used with the | |
| 62 // surface layer) when the window resize happens, which will ensure that the | |
| 63 // surface size matches the window size (unless a timeout occurs). | |
| 64 gfx::Size frame_size = surface_info.size_in_pixels(); | |
| 65 surface_layer_->SetBounds( | |
| 66 gfx::Rect(0, 0, frame_size.width(), frame_size.height())); | |
| 67 // Clip to window bounds. | |
| 68 clip_layer_->SetBounds( | |
| 69 gfx::Rect(0, 0, window_->bounds().width(), window_->bounds().height())); | |
| 70 | |
| 71 surface_layer_->SetShowPrimarySurface( | 55 surface_layer_->SetShowPrimarySurface( |
| 72 surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); | 56 surface_info, make_scoped_refptr(new StubSurfaceReferenceFactory)); |
| 57 surface_layer_->SetBounds(gfx::Rect(window_->bounds().size())); | |
| 73 } | 58 } |
| 74 | 59 |
| 75 void ClientSurfaceEmbedder::SetFallbackSurfaceInfo( | 60 void ClientSurfaceEmbedder::SetFallbackSurfaceInfo( |
| 76 const cc::SurfaceInfo& surface_info) { | 61 const cc::SurfaceInfo& surface_info) { |
| 77 surface_layer_->SetFallbackSurface(surface_info); | 62 surface_layer_->SetFallbackSurface(surface_info); |
| 63 UpdateSizeAndGutters(); | |
| 64 } | |
| 65 | |
| 66 void ClientSurfaceEmbedder::UpdateSizeAndGutters() { | |
| 67 surface_layer_->SetBounds(gfx::Rect(window_->bounds().size())); | |
| 68 // TODO(fsamuel): Fix this for high DPI. | |
| 69 gfx::Size fallback_surface_size( | |
| 70 surface_layer_->GetFallbackSurfaceInfo() | |
| 71 ? surface_layer_->GetFallbackSurfaceInfo()->size_in_pixels() | |
| 72 : gfx::Size()); | |
| 73 gfx::Rect window_bounds(window_->bounds()); | |
| 74 if (fallback_surface_size.width() < window_bounds.width()) { | |
|
sadrul
2017/04/07 21:54:41
You should check for fallback_surface_size being e
Fady Samuel
2017/04/07 21:58:48
Actually that's deliberate. I want the right gutte
| |
| 75 right_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); | |
| 76 // TODO(fsamuel): Use the embedded client's background color. | |
| 77 right_gutter_->SetColor(SK_ColorWHITE); | |
| 78 int width = window_bounds.width() - fallback_surface_size.width(); | |
| 79 // The right gutter also includes the bottom-right corner, if necessary. | |
| 80 int height = window_bounds.height() - client_area_insets_.height(); | |
| 81 right_gutter_->SetBounds( | |
| 82 gfx::Rect(client_area_insets_.left() + fallback_surface_size.width(), | |
| 83 client_area_insets_.top(), width, height)); | |
| 84 window_->layer()->Add(right_gutter_.get()); | |
| 85 } else { | |
| 86 right_gutter_.reset(); | |
| 87 } | |
| 88 | |
| 89 // Only create a bottom gutter if a fallback surface is available. Otherwise, | |
| 90 // the right gutter will fill the whole window until a fallback is available. | |
| 91 if (!fallback_surface_size.IsEmpty() && | |
| 92 fallback_surface_size.height() < window_bounds.height()) { | |
| 93 bottom_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); | |
| 94 // TODO(fsamuel): Use the embedded client's background color. | |
| 95 bottom_gutter_->SetColor(SK_ColorWHITE); | |
| 96 int width = fallback_surface_size.width(); | |
| 97 int height = window_bounds.height() - fallback_surface_size.height(); | |
| 98 bottom_gutter_->SetBounds( | |
| 99 gfx::Rect(0, fallback_surface_size.height(), width, height)); | |
| 100 window_->layer()->Add(bottom_gutter_.get()); | |
| 101 } else { | |
| 102 bottom_gutter_.reset(); | |
| 103 } | |
| 104 window_->layer()->StackAtTop(surface_layer_.get()); | |
| 78 } | 105 } |
| 79 | 106 |
| 80 } // namespace aura | 107 } // namespace aura |
| OLD | NEW |