Chromium Code Reviews| Index: components/exo/shell_surface.cc |
| diff --git a/components/exo/shell_surface.cc b/components/exo/shell_surface.cc |
| index 602b5a43ff1bdbbe7619df46283ecbb337524dd7..44476882b951b3d01f40eeb65509f432826dbd91 100644 |
| --- a/components/exo/shell_surface.cc |
| +++ b/components/exo/shell_surface.cc |
| @@ -627,6 +627,9 @@ void ShellSurface::SetGeometry(const gfx::Rect& geometry) { |
| void ShellSurface::SetRectangularShadowEnabled(bool enabled) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowEnabled", "enabled", |
| enabled); |
| + if (shadow_underlay_in_surface_) |
| + ResetShadowWindows(); |
|
oshima
2017/04/24 17:23:58
It was crashing because we were mixing overlay cre
|
| + |
| shadow_underlay_in_surface_ = false; |
| shadow_enabled_ = enabled; |
| } |
| @@ -635,6 +638,8 @@ void ShellSurface::SetRectangularShadow_DEPRECATED( |
| const gfx::Rect& content_bounds) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED", |
| "content_bounds", content_bounds.ToString()); |
| + if (shadow_underlay_in_surface_) |
| + ResetShadowWindows(); |
| shadow_underlay_in_surface_ = false; |
| shadow_content_bounds_ = content_bounds; |
| shadow_enabled_ = !content_bounds.IsEmpty(); |
| @@ -644,6 +649,8 @@ void ShellSurface::SetRectangularSurfaceShadow( |
| const gfx::Rect& content_bounds) { |
| TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow", |
| "content_bounds", content_bounds.ToString()); |
| + if (!shadow_underlay_in_surface_) |
| + ResetShadowWindows(); |
| shadow_underlay_in_surface_ = true; |
| shadow_content_bounds_ = content_bounds; |
| shadow_enabled_ = !content_bounds.IsEmpty(); |
| @@ -876,8 +883,7 @@ void ShellSurface::WindowClosing() { |
| EndDrag(true /* revert */); |
| SetEnabled(false); |
| widget_ = nullptr; |
| - shadow_overlay_ = nullptr; |
| - shadow_underlay_ = nullptr; |
| + ResetShadowWindows(); |
| } |
| views::Widget* ShellSurface::GetWidget() { |
| @@ -1569,7 +1575,16 @@ void ShellSurface::UpdateShadow() { |
| if (!widget_ || !surface_) |
| return; |
| 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 +1631,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 +1645,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 +1662,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 { |
| @@ -1692,17 +1701,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 +1737,9 @@ gfx::Point ShellSurface::GetMouseLocation() const { |
| return location; |
| } |
| +void ShellSurface::ResetShadowWindows() { |
| + shadow_overlay_.reset(); |
| + shadow_underlay_.reset(); |
| +} |
| + |
| } // namespace exo |