Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(257)

Side by Side Diff: components/exo/shell_surface.cc

Issue 2837903002: Do not hide shadow underlay for max/fullscreen state even if the client disables the shadow. (Closed)
Patch Set: addressed comments Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "components/exo/shell_surface.h" 5 #include "components/exo/shell_surface.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 8
9 #include "ash/frame/custom_frame_view_ash.h" 9 #include "ash/frame/custom_frame_view_ash.h"
10 #include "ash/public/cpp/shell_window_ids.h" 10 #include "ash/public/cpp/shell_window_ids.h"
(...skipping 609 matching lines...) Expand 10 before | Expand all | Expand 10 after
620 DLOG(WARNING) << "Surface geometry must be non-empty"; 620 DLOG(WARNING) << "Surface geometry must be non-empty";
621 return; 621 return;
622 } 622 }
623 623
624 pending_geometry_ = geometry; 624 pending_geometry_ = geometry;
625 } 625 }
626 626
627 void ShellSurface::SetRectangularShadowEnabled(bool enabled) { 627 void ShellSurface::SetRectangularShadowEnabled(bool enabled) {
628 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowEnabled", "enabled", 628 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowEnabled", "enabled",
629 enabled); 629 enabled);
630 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.
631
630 shadow_underlay_in_surface_ = false; 632 shadow_underlay_in_surface_ = false;
631 shadow_enabled_ = enabled; 633 shadow_enabled_ = enabled;
632 } 634 }
633 635
634 void ShellSurface::SetRectangularShadow_DEPRECATED( 636 void ShellSurface::SetRectangularShadow_DEPRECATED(
635 const gfx::Rect& content_bounds) { 637 const gfx::Rect& content_bounds) {
636 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED", 638 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED",
637 "content_bounds", content_bounds.ToString()); 639 "content_bounds", content_bounds.ToString());
640 reset_shadow_windows_ |= shadow_underlay_in_surface_;
reveman 2017/04/26 18:00:56 nit: ditto
641
638 shadow_underlay_in_surface_ = false; 642 shadow_underlay_in_surface_ = false;
639 shadow_content_bounds_ = content_bounds; 643 shadow_content_bounds_ = content_bounds;
640 shadow_enabled_ = !content_bounds.IsEmpty(); 644 shadow_enabled_ = !content_bounds.IsEmpty();
641 } 645 }
642 646
643 void ShellSurface::SetRectangularSurfaceShadow( 647 void ShellSurface::SetRectangularSurfaceShadow(
644 const gfx::Rect& content_bounds) { 648 const gfx::Rect& content_bounds) {
645 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow", 649 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow",
646 "content_bounds", content_bounds.ToString()); 650 "content_bounds", content_bounds.ToString());
651 reset_shadow_windows_ |= !shadow_underlay_in_surface_;
reveman 2017/04/26 18:00:56 nit: ditto
652
647 shadow_underlay_in_surface_ = true; 653 shadow_underlay_in_surface_ = true;
648 shadow_content_bounds_ = content_bounds; 654 shadow_content_bounds_ = content_bounds;
649 shadow_enabled_ = !content_bounds.IsEmpty(); 655 shadow_enabled_ = !content_bounds.IsEmpty();
650 } 656 }
651 657
652 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) { 658 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) {
653 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity", 659 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity",
654 "opacity", opacity); 660 "opacity", opacity);
655 shadow_background_opacity_ = opacity; 661 shadow_background_opacity_ = opacity;
656 } 662 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (bounds_mode_ != BoundsMode::CLIENT) 875 if (bounds_mode_ != BoundsMode::CLIENT)
870 return WidgetDelegate::GetSavedWindowPlacement(widget, bounds, show_state); 876 return WidgetDelegate::GetSavedWindowPlacement(widget, bounds, show_state);
871 return false; 877 return false;
872 } 878 }
873 879
874 void ShellSurface::WindowClosing() { 880 void ShellSurface::WindowClosing() {
875 if (resizer_) 881 if (resizer_)
876 EndDrag(true /* revert */); 882 EndDrag(true /* revert */);
877 SetEnabled(false); 883 SetEnabled(false);
878 widget_ = nullptr; 884 widget_ = nullptr;
879 shadow_overlay_ = nullptr; 885 ResetShadowWindows();
reveman 2017/04/26 18:00:56 nit: remove
oshima 2017/04/26 21:45:01 Done.
880 shadow_underlay_ = nullptr;
881 } 886 }
882 887
883 views::Widget* ShellSurface::GetWidget() { 888 views::Widget* ShellSurface::GetWidget() {
884 return widget_; 889 return widget_;
885 } 890 }
886 891
887 const views::Widget* ShellSurface::GetWidget() const { 892 const views::Widget* ShellSurface::GetWidget() const {
888 return widget_; 893 return widget_;
889 } 894 }
890 895
(...skipping 670 matching lines...) Expand 10 before | Expand all | Expand 10 after
1561 widget_->non_client_view()->frame_view()->GetBoundsForClientView(); 1566 widget_->non_client_view()->frame_view()->GetBoundsForClientView();
1562 1567
1563 surface_->window()->SetBounds( 1568 surface_->window()->SetBounds(
1564 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(), 1569 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(),
1565 surface_->window()->layer()->size())); 1570 surface_->window()->layer()->size()));
1566 } 1571 }
1567 1572
1568 void ShellSurface::UpdateShadow() { 1573 void ShellSurface::UpdateShadow() {
1569 if (!widget_ || !surface_) 1574 if (!widget_ || !surface_)
1570 return; 1575 return;
1576
1577 if (reset_shadow_windows_) {
1578 reset_shadow_windows_ = false;
1579 ResetShadowWindows();
1580 }
1581
1571 aura::Window* window = widget_->GetNativeWindow(); 1582 aura::Window* window = widget_->GetNativeWindow();
1572 if (!shadow_enabled_) { 1583
1584 bool underlay_capture_events =
1585 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && widget_->IsActive();
1586 bool black_background_enabled =
1587 ((widget_->IsFullscreen() || widget_->IsMaximized()) ||
1588 underlay_capture_events) &&
1589 ash::wm::GetWindowState(window)->allow_set_bounds_direct() &&
1590 window->layer()->GetTargetTransform().IsIdentity();
1591
1592 if (!shadow_enabled_ && !black_background_enabled) {
1573 wm::SetShadowElevation(window, wm::ShadowElevation::NONE); 1593 wm::SetShadowElevation(window, wm::ShadowElevation::NONE);
1574 if (shadow_underlay_) 1594 if (shadow_underlay_)
1575 shadow_underlay_->Hide(); 1595 shadow_underlay_->Hide();
1576 } else { 1596 } else {
1577 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM); 1597 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM);
1578 gfx::Rect shadow_content_bounds = 1598 gfx::Rect shadow_content_bounds =
1579 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_); 1599 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_);
1580 1600
1581 // Convert from screen to display coordinates. 1601 // Convert from screen to display coordinates.
1582 if (!shadow_content_bounds.IsEmpty()) { 1602 if (!shadow_content_bounds.IsEmpty()) {
(...skipping 26 matching lines...) Expand all
1609 shadow_content_bounds.set_origin(origin); 1629 shadow_content_bounds.set_origin(origin);
1610 } 1630 }
1611 } 1631 }
1612 1632
1613 gfx::Point shadow_origin = shadow_content_bounds.origin(); 1633 gfx::Point shadow_origin = shadow_content_bounds.origin();
1614 shadow_origin -= window->bounds().OffsetFromOrigin(); 1634 shadow_origin -= window->bounds().OffsetFromOrigin();
1615 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size()); 1635 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size());
1616 1636
1617 // Always create and show the underlay, even in maximized/fullscreen. 1637 // Always create and show the underlay, even in maximized/fullscreen.
1618 if (!shadow_underlay_) { 1638 if (!shadow_underlay_) {
1619 shadow_underlay_ = new aura::Window(nullptr); 1639 shadow_underlay_ = base::MakeUnique<aura::Window>(nullptr);
1640 shadow_underlay_->set_owned_by_parent(false);
1620 shadow_underlay_event_handler_ = 1641 shadow_underlay_event_handler_ =
1621 base::MakeUnique<ShadowUnderlayEventHandler>(); 1642 base::MakeUnique<ShadowUnderlayEventHandler>();
1622 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get()); 1643 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get());
1623 DCHECK(shadow_underlay_->owned_by_parent()); 1644 DCHECK(!shadow_underlay_->owned_by_parent());
1624 // Ensure the background area inside the shadow is solid black. 1645 // Ensure the background area inside the shadow is solid black.
1625 // Clients that provide translucent contents should not be using 1646 // Clients that provide translucent contents should not be using
1626 // rectangular shadows as this method requires opaque contents to 1647 // rectangular shadows as this method requires opaque contents to
1627 // cast a shadow that represent it correctly. 1648 // cast a shadow that represent it correctly.
1628 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR); 1649 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR);
1629 shadow_underlay_->layer()->SetColor(SK_ColorBLACK); 1650 shadow_underlay_->layer()->SetColor(SK_ColorBLACK);
1630 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely()); 1651 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely());
1631 if (shadow_underlay_in_surface_) { 1652 if (shadow_underlay_in_surface_) {
1632 surface_->window()->AddChild(shadow_underlay_); 1653 surface_->window()->AddChild(shadow_underlay());
1633 surface_->window()->StackChildAtBottom(shadow_underlay_); 1654 surface_->window()->StackChildAtBottom(shadow_underlay());
1634 } else { 1655 } else {
1635 window->AddChild(shadow_underlay_); 1656 window->AddChild(shadow_underlay());
1636 window->StackChildAtBottom(shadow_underlay_); 1657 window->StackChildAtBottom(shadow_underlay());
1637 } 1658 }
1638 } 1659 }
1639 1660
1640 bool underlay_capture_events =
1641 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() &&
1642 widget_->IsActive();
1643
1644 float shadow_underlay_opacity = shadow_background_opacity_; 1661 float shadow_underlay_opacity = shadow_background_opacity_;
1645 1662
1646 // Put the black background layer behind the window if 1663 // Put the black background layer behind the window if
1647 // 1) the window is in immersive fullscreen, maximized or is active with 1664 // 1) the window is in immersive fullscreen, maximized or is active with
1648 // spoken feedback enabled. 1665 // spoken feedback enabled.
1649 // 2) the window can control the bounds of the window in fullscreen ( 1666 // 2) the window can control the bounds of the window in fullscreen (
1650 // thus the background can be visible). 1667 // thus the background can be visible).
1651 // 3) the window has no transform (the transformed background may 1668 // 3) the window has no transform (the transformed background may
1652 // not cover the entire background, e.g. overview mode). 1669 // not cover the entire background, e.g. overview mode).
1653 if ((widget_->IsFullscreen() || widget_->IsMaximized() || 1670 if (black_background_enabled) {
1654 underlay_capture_events) &&
1655 ash::wm::GetWindowState(window)->allow_set_bounds_direct() &&
1656 window->layer()->GetTargetTransform().IsIdentity()) {
1657 if (shadow_underlay_in_surface_) { 1671 if (shadow_underlay_in_surface_) {
1658 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size()); 1672 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1659 } else { 1673 } else {
1660 gfx::Point origin; 1674 gfx::Point origin;
1661 origin -= window->bounds().origin().OffsetFromOrigin(); 1675 origin -= window->bounds().origin().OffsetFromOrigin();
1662 shadow_bounds.set_origin(origin); 1676 shadow_bounds.set_origin(origin);
1663 shadow_bounds.set_size(window->parent()->bounds().size()); 1677 shadow_bounds.set_size(window->parent()->bounds().size());
1664 } 1678 }
1665 shadow_underlay_opacity = 1.0f; 1679 shadow_underlay_opacity = 1.0f;
1666 } 1680 }
1667 1681
1668 if (!shadow_underlay_in_surface_) 1682 if (!shadow_underlay_in_surface_)
1669 shadow_underlay_bounds = shadow_bounds; 1683 shadow_underlay_bounds = shadow_bounds;
1670 1684
1671 // Constrain the underlay bounds to the client area in case shell surface 1685 // Constrain the underlay bounds to the client area in case shell surface
1672 // frame is enabled. 1686 // frame is enabled.
1673 if (frame_enabled_) { 1687 if (frame_enabled_) {
1674 shadow_underlay_bounds.Intersect( 1688 shadow_underlay_bounds.Intersect(
1675 widget_->non_client_view()->frame_view()->GetBoundsForClientView()); 1689 widget_->non_client_view()->frame_view()->GetBoundsForClientView());
1676 } 1690 }
1677 1691
1678 shadow_underlay_->SetBounds(shadow_underlay_bounds); 1692 shadow_underlay_->SetBounds(shadow_underlay_bounds);
1679 1693
1680 shadow_underlay_->Show(); 1694 if (!shadow_underlay_->IsVisible())
1695 shadow_underlay_->Show();
1681 1696
1682 // TODO(oshima): Setting to the same value should be no-op. 1697 // TODO(oshima): Setting to the same value should be no-op.
1683 // crbug.com/642223. 1698 // crbug.com/642223.
1684 if (shadow_underlay_opacity != 1699 if (shadow_underlay_opacity !=
1685 shadow_underlay_->layer()->GetTargetOpacity()) { 1700 shadow_underlay_->layer()->GetTargetOpacity()) {
1686 shadow_underlay_->layer()->SetOpacity(shadow_underlay_opacity); 1701 shadow_underlay_->layer()->SetOpacity(shadow_underlay_opacity);
1687 } 1702 }
1688 1703
1689 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 1704 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
1690 // Maximized/Fullscreen window does not create a shadow. 1705 // Maximized/Fullscreen window does not create a shadow.
1691 if (!shadow) 1706 if (!shadow)
1692 return; 1707 return;
1693 1708
1694 if (!shadow_overlay_) { 1709 if (!shadow_overlay_) {
1695 shadow_overlay_ = new aura::Window(nullptr); 1710 shadow_overlay_ = base::MakeUnique<aura::Window>(nullptr);
1696 DCHECK(shadow_overlay_->owned_by_parent()); 1711 shadow_overlay_->set_owned_by_parent(false);
1712 DCHECK(!shadow_overlay_->owned_by_parent());
1697 shadow_overlay_->set_ignore_events(true); 1713 shadow_overlay_->set_ignore_events(true);
1698 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); 1714 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
1699 shadow_overlay_->layer()->Add(shadow->layer()); 1715 shadow_overlay_->layer()->Add(shadow->layer());
1700 window->AddChild(shadow_overlay_); 1716 window->AddChild(shadow_overlay());
1701 1717
1702 if (shadow_underlay_in_surface_) { 1718 if (shadow_underlay_in_surface_) {
1703 window->StackChildBelow(shadow_overlay_, surface_->window()); 1719 window->StackChildBelow(shadow_overlay(), surface_->window());
1704 } else { 1720 } else {
1705 window->StackChildAbove(shadow_overlay_, shadow_underlay_); 1721 window->StackChildAbove(shadow_overlay(), shadow_underlay());
1706 } 1722 }
1707 shadow_overlay_->Show(); 1723 shadow_overlay_->Show();
1708 } 1724 }
1709 shadow_overlay_->SetBounds(shadow_bounds); 1725 shadow_overlay_->SetBounds(shadow_bounds);
1710 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1726 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1711 // Surfaces that can't be activated are usually menus and tooltips. Use a 1727 // Surfaces that can't be activated are usually menus and tooltips. Use a
1712 // small style shadow for them. 1728 // small style shadow for them.
1713 if (!activatable_) 1729 if (!activatable_)
1714 shadow->SetElevation(wm::ShadowElevation::SMALL); 1730 shadow->SetElevation(wm::ShadowElevation::SMALL);
1715 // We don't have rounded corners unless frame is enabled. 1731 // We don't have rounded corners unless frame is enabled.
1716 if (!frame_enabled_) 1732 if (!frame_enabled_)
1717 shadow->SetRoundedCornerRadius(0); 1733 shadow->SetRoundedCornerRadius(0);
1718 } 1734 }
1719 } 1735 }
1720 1736
1721 gfx::Point ShellSurface::GetMouseLocation() const { 1737 gfx::Point ShellSurface::GetMouseLocation() const {
1722 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); 1738 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow();
1723 gfx::Point location = 1739 gfx::Point location =
1724 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); 1740 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
1725 aura::Window::ConvertPointToTarget( 1741 aura::Window::ConvertPointToTarget(
1726 root_window, widget_->GetNativeWindow()->parent(), &location); 1742 root_window, widget_->GetNativeWindow()->parent(), &location);
1727 return location; 1743 return location;
1728 } 1744 }
1729 1745
1746 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.
1747 shadow_overlay_.reset();
1748 shadow_underlay_.reset();
1749 }
1750
1730 } // namespace exo 1751 } // namespace exo
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698