Chromium Code Reviews| Index: components/exo/shell_surface.cc |
| diff --git a/components/exo/shell_surface.cc b/components/exo/shell_surface.cc |
| index e0ba66d23d59b553c19c9ea867f84d3fdfea8c4c..35833ba232b25c3a497b2fcba3e042ef053dbce7 100644 |
| --- a/components/exo/shell_surface.cc |
| +++ b/components/exo/shell_surface.cc |
| @@ -627,6 +627,8 @@ void ShellSurface::SetGeometry(const gfx::Rect& geometry) { |
| void ShellSurface::SetRectangularShadowEnabled(bool enabled) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowEnabled", "enabled", |
| enabled); |
| + reset_shadow_windows_ |= shadow_underlay_in_surface_; |
|
reveman
2017/04/26 18:00:56
nit: group with lines below instead of with the tr
oshima
2017/04/26 21:45:01
Done.
|
| + |
| shadow_underlay_in_surface_ = false; |
| shadow_enabled_ = enabled; |
| } |
| @@ -635,6 +637,8 @@ void ShellSurface::SetRectangularShadow_DEPRECATED( |
| const gfx::Rect& content_bounds) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED", |
| "content_bounds", content_bounds.ToString()); |
| + reset_shadow_windows_ |= shadow_underlay_in_surface_; |
|
reveman
2017/04/26 18:00:56
nit: ditto
|
| + |
| shadow_underlay_in_surface_ = false; |
| shadow_content_bounds_ = content_bounds; |
| shadow_enabled_ = !content_bounds.IsEmpty(); |
| @@ -644,6 +648,8 @@ void ShellSurface::SetRectangularSurfaceShadow( |
| const gfx::Rect& content_bounds) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow", |
| "content_bounds", content_bounds.ToString()); |
| + reset_shadow_windows_ |= !shadow_underlay_in_surface_; |
|
reveman
2017/04/26 18:00:56
nit: ditto
|
| + |
| shadow_underlay_in_surface_ = true; |
| shadow_content_bounds_ = content_bounds; |
| shadow_enabled_ = !content_bounds.IsEmpty(); |
| @@ -876,8 +882,7 @@ void ShellSurface::WindowClosing() { |
| EndDrag(true /* revert */); |
| SetEnabled(false); |
| widget_ = nullptr; |
| - shadow_overlay_ = nullptr; |
| - shadow_underlay_ = nullptr; |
| + ResetShadowWindows(); |
|
reveman
2017/04/26 18:00:56
nit: remove
oshima
2017/04/26 21:45:01
Done.
|
| } |
| views::Widget* ShellSurface::GetWidget() { |
| @@ -1568,8 +1573,23 @@ void ShellSurface::UpdateSurfaceBounds() { |
| void ShellSurface::UpdateShadow() { |
| if (!widget_ || !surface_) |
| return; |
| + |
| + if (reset_shadow_windows_) { |
| + reset_shadow_windows_ = false; |
| + ResetShadowWindows(); |
| + } |
| + |
| aura::Window* window = widget_->GetNativeWindow(); |
| - if (!shadow_enabled_) { |
| + |
| + bool underlay_capture_events = |
| + WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && widget_->IsActive(); |
| + bool black_background_enabled = |
| + ((widget_->IsFullscreen() || widget_->IsMaximized()) || |
| + underlay_capture_events) && |
| + ash::wm::GetWindowState(window)->allow_set_bounds_direct() && |
| + window->layer()->GetTargetTransform().IsIdentity(); |
| + |
| + if (!shadow_enabled_ && !black_background_enabled) { |
| wm::SetShadowElevation(window, wm::ShadowElevation::NONE); |
| if (shadow_underlay_) |
| shadow_underlay_->Hide(); |
| @@ -1616,11 +1636,12 @@ void ShellSurface::UpdateShadow() { |
| // Always create and show the underlay, even in maximized/fullscreen. |
| if (!shadow_underlay_) { |
| - shadow_underlay_ = new aura::Window(nullptr); |
| + shadow_underlay_ = base::MakeUnique<aura::Window>(nullptr); |
| + shadow_underlay_->set_owned_by_parent(false); |
| shadow_underlay_event_handler_ = |
| base::MakeUnique<ShadowUnderlayEventHandler>(); |
| shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get()); |
| - DCHECK(shadow_underlay_->owned_by_parent()); |
| + DCHECK(!shadow_underlay_->owned_by_parent()); |
| // Ensure the background area inside the shadow is solid black. |
| // Clients that provide translucent contents should not be using |
| // rectangular shadows as this method requires opaque contents to |
| @@ -1629,18 +1650,14 @@ void ShellSurface::UpdateShadow() { |
| shadow_underlay_->layer()->SetColor(SK_ColorBLACK); |
| DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely()); |
| if (shadow_underlay_in_surface_) { |
| - surface_->window()->AddChild(shadow_underlay_); |
| - surface_->window()->StackChildAtBottom(shadow_underlay_); |
| + surface_->window()->AddChild(shadow_underlay()); |
| + surface_->window()->StackChildAtBottom(shadow_underlay()); |
| } else { |
| - window->AddChild(shadow_underlay_); |
| - window->StackChildAtBottom(shadow_underlay_); |
| + window->AddChild(shadow_underlay()); |
| + window->StackChildAtBottom(shadow_underlay()); |
| } |
| } |
| - bool underlay_capture_events = |
| - WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && |
| - widget_->IsActive(); |
| - |
| float shadow_underlay_opacity = shadow_background_opacity_; |
| // Put the black background layer behind the window if |
| @@ -1650,10 +1667,7 @@ void ShellSurface::UpdateShadow() { |
| // thus the background can be visible). |
| // 3) the window has no transform (the transformed background may |
| // not cover the entire background, e.g. overview mode). |
| - if ((widget_->IsFullscreen() || widget_->IsMaximized() || |
| - underlay_capture_events) && |
| - ash::wm::GetWindowState(window)->allow_set_bounds_direct() && |
| - window->layer()->GetTargetTransform().IsIdentity()) { |
| + if (black_background_enabled) { |
| if (shadow_underlay_in_surface_) { |
| shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size()); |
| } else { |
| @@ -1677,7 +1691,8 @@ void ShellSurface::UpdateShadow() { |
| shadow_underlay_->SetBounds(shadow_underlay_bounds); |
| - shadow_underlay_->Show(); |
| + if (!shadow_underlay_->IsVisible()) |
| + shadow_underlay_->Show(); |
| // TODO(oshima): Setting to the same value should be no-op. |
| // crbug.com/642223. |
| @@ -1692,17 +1707,18 @@ void ShellSurface::UpdateShadow() { |
| return; |
| if (!shadow_overlay_) { |
| - shadow_overlay_ = new aura::Window(nullptr); |
| - DCHECK(shadow_overlay_->owned_by_parent()); |
| + shadow_overlay_ = base::MakeUnique<aura::Window>(nullptr); |
| + shadow_overlay_->set_owned_by_parent(false); |
| + DCHECK(!shadow_overlay_->owned_by_parent()); |
| shadow_overlay_->set_ignore_events(true); |
| shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); |
| shadow_overlay_->layer()->Add(shadow->layer()); |
| - window->AddChild(shadow_overlay_); |
| + window->AddChild(shadow_overlay()); |
| if (shadow_underlay_in_surface_) { |
| - window->StackChildBelow(shadow_overlay_, surface_->window()); |
| + window->StackChildBelow(shadow_overlay(), surface_->window()); |
| } else { |
| - window->StackChildAbove(shadow_overlay_, shadow_underlay_); |
| + window->StackChildAbove(shadow_overlay(), shadow_underlay()); |
| } |
| shadow_overlay_->Show(); |
| } |
| @@ -1727,4 +1743,9 @@ gfx::Point ShellSurface::GetMouseLocation() const { |
| return location; |
| } |
| +void ShellSurface::ResetShadowWindows() { |
|
reveman
2017/04/26 18:00:56
nit: remove this function as the only time we need
oshima
2017/04/26 21:45:01
Done.
|
| + shadow_overlay_.reset(); |
| + shadow_underlay_.reset(); |
| +} |
| + |
| } // namespace exo |