| 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 #include "ui/gfx/geometry/dip_util.h" |
| 9 | 10 |
| 10 namespace aura { | 11 namespace aura { |
| 11 namespace { | 12 namespace { |
| 12 | 13 |
| 13 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference | 14 // TODO(mfomitchev, samans): Remove these stub classes once the SurfaceReference |
| 14 // work is complete. | 15 // work is complete. |
| 15 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { | 16 class StubSurfaceReferenceFactory : public cc::SurfaceReferenceFactory { |
| 16 public: | 17 public: |
| 17 StubSurfaceReferenceFactory() = default; | 18 StubSurfaceReferenceFactory() = default; |
| 18 | 19 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 } | 59 } |
| 59 | 60 |
| 60 void ClientSurfaceEmbedder::SetFallbackSurfaceInfo( | 61 void ClientSurfaceEmbedder::SetFallbackSurfaceInfo( |
| 61 const cc::SurfaceInfo& surface_info) { | 62 const cc::SurfaceInfo& surface_info) { |
| 62 surface_layer_->SetFallbackSurface(surface_info); | 63 surface_layer_->SetFallbackSurface(surface_info); |
| 63 UpdateSizeAndGutters(); | 64 UpdateSizeAndGutters(); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void ClientSurfaceEmbedder::UpdateSizeAndGutters() { | 67 void ClientSurfaceEmbedder::UpdateSizeAndGutters() { |
| 67 surface_layer_->SetBounds(gfx::Rect(window_->bounds().size())); | 68 surface_layer_->SetBounds(gfx::Rect(window_->bounds().size())); |
| 68 // TODO(fsamuel): Fix this for high DPI. | 69 gfx::Size fallback_surface_size_in_dip; |
| 69 gfx::Size fallback_surface_size( | 70 const cc::SurfaceInfo* fallback_surface_info = |
| 70 surface_layer_->GetFallbackSurfaceInfo() | 71 surface_layer_->GetFallbackSurfaceInfo(); |
| 71 ? surface_layer_->GetFallbackSurfaceInfo()->size_in_pixels() | 72 if (fallback_surface_info) { |
| 72 : gfx::Size()); | 73 float fallback_device_scale_factor = |
| 74 fallback_surface_info->device_scale_factor(); |
| 75 fallback_surface_size_in_dip = gfx::ConvertSizeToDIP( |
| 76 fallback_device_scale_factor, fallback_surface_info->size_in_pixels()); |
| 77 } |
| 73 gfx::Rect window_bounds(window_->bounds()); | 78 gfx::Rect window_bounds(window_->bounds()); |
| 74 if (fallback_surface_size.width() < window_bounds.width()) { | 79 if (fallback_surface_size_in_dip.width() < window_bounds.width()) { |
| 75 right_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); | 80 right_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); |
| 76 // TODO(fsamuel): Use the embedded client's background color. | 81 // TODO(fsamuel): Use the embedded client's background color. |
| 77 right_gutter_->SetColor(SK_ColorWHITE); | 82 right_gutter_->SetColor(SK_ColorWHITE); |
| 78 int width = window_bounds.width() - fallback_surface_size.width(); | 83 int width = window_bounds.width() - fallback_surface_size_in_dip.width(); |
| 79 // The right gutter also includes the bottom-right corner, if necessary. | 84 // The right gutter also includes the bottom-right corner, if necessary. |
| 80 int height = window_bounds.height() - client_area_insets_.height(); | 85 int height = window_bounds.height() - client_area_insets_.height(); |
| 81 right_gutter_->SetBounds( | 86 right_gutter_->SetBounds(gfx::Rect( |
| 82 gfx::Rect(client_area_insets_.left() + fallback_surface_size.width(), | 87 client_area_insets_.left() + fallback_surface_size_in_dip.width(), |
| 83 client_area_insets_.top(), width, height)); | 88 client_area_insets_.top(), width, height)); |
| 84 window_->layer()->Add(right_gutter_.get()); | 89 window_->layer()->Add(right_gutter_.get()); |
| 85 } else { | 90 } else { |
| 86 right_gutter_.reset(); | 91 right_gutter_.reset(); |
| 87 } | 92 } |
| 88 | 93 |
| 89 // Only create a bottom gutter if a fallback surface is available. Otherwise, | 94 // 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. | 95 // the right gutter will fill the whole window until a fallback is available. |
| 91 if (!fallback_surface_size.IsEmpty() && | 96 if (!fallback_surface_size_in_dip.IsEmpty() && |
| 92 fallback_surface_size.height() < window_bounds.height()) { | 97 fallback_surface_size_in_dip.height() < window_bounds.height()) { |
| 93 bottom_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); | 98 bottom_gutter_ = base::MakeUnique<ui::Layer>(ui::LAYER_SOLID_COLOR); |
| 94 // TODO(fsamuel): Use the embedded client's background color. | 99 // TODO(fsamuel): Use the embedded client's background color. |
| 95 bottom_gutter_->SetColor(SK_ColorWHITE); | 100 bottom_gutter_->SetColor(SK_ColorWHITE); |
| 96 int width = fallback_surface_size.width(); | 101 int width = fallback_surface_size_in_dip.width(); |
| 97 int height = window_bounds.height() - fallback_surface_size.height(); | 102 int height = window_bounds.height() - fallback_surface_size_in_dip.height(); |
| 98 bottom_gutter_->SetBounds( | 103 bottom_gutter_->SetBounds( |
| 99 gfx::Rect(0, fallback_surface_size.height(), width, height)); | 104 gfx::Rect(0, fallback_surface_size_in_dip.height(), width, height)); |
| 100 window_->layer()->Add(bottom_gutter_.get()); | 105 window_->layer()->Add(bottom_gutter_.get()); |
| 101 } else { | 106 } else { |
| 102 bottom_gutter_.reset(); | 107 bottom_gutter_.reset(); |
| 103 } | 108 } |
| 104 window_->layer()->StackAtTop(surface_layer_.get()); | 109 window_->layer()->StackAtTop(surface_layer_.get()); |
| 105 } | 110 } |
| 106 | 111 |
| 107 } // namespace aura | 112 } // namespace aura |
| OLD | NEW |