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

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: Do not hide shadow underlay for max/fullscreen state even if the client disables the shadow. Created 3 years, 7 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
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 if (shadow_underlay_in_surface_)
631 ResetShadowWindows();
reveman 2017/04/25 18:04:40 Should these calls be deferred until commit? What
oshima 2017/04/26 16:36:11 Good point. Done.
632
630 shadow_underlay_in_surface_ = false; 633 shadow_underlay_in_surface_ = false;
631 shadow_enabled_ = enabled; 634 shadow_enabled_ = enabled;
632 } 635 }
633 636
634 void ShellSurface::SetRectangularShadow_DEPRECATED( 637 void ShellSurface::SetRectangularShadow_DEPRECATED(
635 const gfx::Rect& content_bounds) { 638 const gfx::Rect& content_bounds) {
636 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED", 639 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadow_DEPRECATED",
637 "content_bounds", content_bounds.ToString()); 640 "content_bounds", content_bounds.ToString());
641 if (shadow_underlay_in_surface_)
642 ResetShadowWindows();
reveman 2017/04/25 18:04:40 ditto
638 shadow_underlay_in_surface_ = false; 643 shadow_underlay_in_surface_ = false;
639 shadow_content_bounds_ = content_bounds; 644 shadow_content_bounds_ = content_bounds;
640 shadow_enabled_ = !content_bounds.IsEmpty(); 645 shadow_enabled_ = !content_bounds.IsEmpty();
641 } 646 }
642 647
643 void ShellSurface::SetRectangularSurfaceShadow( 648 void ShellSurface::SetRectangularSurfaceShadow(
644 const gfx::Rect& content_bounds) { 649 const gfx::Rect& content_bounds) {
645 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow", 650 TRACE_EVENT1("exo", "ShellSurface::SetRectangularSurfaceShadow",
646 "content_bounds", content_bounds.ToString()); 651 "content_bounds", content_bounds.ToString());
652 if (!shadow_underlay_in_surface_)
653 ResetShadowWindows();
reveman 2017/04/25 18:04:40 ditto
647 shadow_underlay_in_surface_ = true; 654 shadow_underlay_in_surface_ = true;
648 shadow_content_bounds_ = content_bounds; 655 shadow_content_bounds_ = content_bounds;
649 shadow_enabled_ = !content_bounds.IsEmpty(); 656 shadow_enabled_ = !content_bounds.IsEmpty();
650 } 657 }
651 658
652 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) { 659 void ShellSurface::SetRectangularShadowBackgroundOpacity(float opacity) {
653 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity", 660 TRACE_EVENT1("exo", "ShellSurface::SetRectangularShadowBackgroundOpacity",
654 "opacity", opacity); 661 "opacity", opacity);
655 shadow_background_opacity_ = opacity; 662 shadow_background_opacity_ = opacity;
656 } 663 }
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
869 if (bounds_mode_ != BoundsMode::CLIENT) 876 if (bounds_mode_ != BoundsMode::CLIENT)
870 return WidgetDelegate::GetSavedWindowPlacement(widget, bounds, show_state); 877 return WidgetDelegate::GetSavedWindowPlacement(widget, bounds, show_state);
871 return false; 878 return false;
872 } 879 }
873 880
874 void ShellSurface::WindowClosing() { 881 void ShellSurface::WindowClosing() {
875 if (resizer_) 882 if (resizer_)
876 EndDrag(true /* revert */); 883 EndDrag(true /* revert */);
877 SetEnabled(false); 884 SetEnabled(false);
878 widget_ = nullptr; 885 widget_ = nullptr;
879 shadow_overlay_ = nullptr; 886 ResetShadowWindows();
reveman 2017/04/25 18:04:40 is this needed? prior we did this to avoid leaving
oshima 2017/04/26 16:36:11 This is just for the safety because they'll never
reveman 2017/04/26 18:00:56 Let's remove it if not needed as then there's also
oshima 2017/04/26 21:45:01 Done.
880 shadow_underlay_ = nullptr;
881 } 887 }
882 888
883 views::Widget* ShellSurface::GetWidget() { 889 views::Widget* ShellSurface::GetWidget() {
884 return widget_; 890 return widget_;
885 } 891 }
886 892
887 const views::Widget* ShellSurface::GetWidget() const { 893 const views::Widget* ShellSurface::GetWidget() const {
888 return widget_; 894 return widget_;
889 } 895 }
890 896
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
1562 1568
1563 surface_->window()->SetBounds( 1569 surface_->window()->SetBounds(
1564 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(), 1570 gfx::Rect(GetSurfaceOrigin() + client_view_bounds.OffsetFromOrigin(),
1565 surface_->window()->layer()->size())); 1571 surface_->window()->layer()->size()));
1566 } 1572 }
1567 1573
1568 void ShellSurface::UpdateShadow() { 1574 void ShellSurface::UpdateShadow() {
1569 if (!widget_ || !surface_) 1575 if (!widget_ || !surface_)
1570 return; 1576 return;
1571 aura::Window* window = widget_->GetNativeWindow(); 1577 aura::Window* window = widget_->GetNativeWindow();
1572 if (!shadow_enabled_) { 1578
1579 bool underlay_capture_events =
1580 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() && widget_->IsActive();
1581 bool black_background_enabled =
1582 ((widget_->IsFullscreen() || widget_->IsMaximized()) ||
1583 underlay_capture_events) &&
1584 ash::wm::GetWindowState(window)->allow_set_bounds_direct() &&
1585 window->layer()->GetTargetTransform().IsIdentity();
1586
1587 if (!shadow_enabled_ && !black_background_enabled) {
1573 wm::SetShadowElevation(window, wm::ShadowElevation::NONE); 1588 wm::SetShadowElevation(window, wm::ShadowElevation::NONE);
1574 if (shadow_underlay_) 1589 if (shadow_underlay_)
1575 shadow_underlay_->Hide(); 1590 shadow_underlay_->Hide();
1576 } else { 1591 } else {
1577 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM); 1592 wm::SetShadowElevation(window, wm::ShadowElevation::MEDIUM);
1578 gfx::Rect shadow_content_bounds = 1593 gfx::Rect shadow_content_bounds =
1579 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_); 1594 gfx::ScaleToEnclosedRect(shadow_content_bounds_, 1.f / scale_);
1580 1595
1581 // Convert from screen to display coordinates. 1596 // Convert from screen to display coordinates.
1582 if (!shadow_content_bounds.IsEmpty()) { 1597 if (!shadow_content_bounds.IsEmpty()) {
(...skipping 26 matching lines...) Expand all
1609 shadow_content_bounds.set_origin(origin); 1624 shadow_content_bounds.set_origin(origin);
1610 } 1625 }
1611 } 1626 }
1612 1627
1613 gfx::Point shadow_origin = shadow_content_bounds.origin(); 1628 gfx::Point shadow_origin = shadow_content_bounds.origin();
1614 shadow_origin -= window->bounds().OffsetFromOrigin(); 1629 shadow_origin -= window->bounds().OffsetFromOrigin();
1615 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size()); 1630 gfx::Rect shadow_bounds(shadow_origin, shadow_content_bounds.size());
1616 1631
1617 // Always create and show the underlay, even in maximized/fullscreen. 1632 // Always create and show the underlay, even in maximized/fullscreen.
1618 if (!shadow_underlay_) { 1633 if (!shadow_underlay_) {
1619 shadow_underlay_ = new aura::Window(nullptr); 1634 shadow_underlay_ = base::MakeUnique<aura::Window>(nullptr);
1635 shadow_underlay_->set_owned_by_parent(false);
1620 shadow_underlay_event_handler_ = 1636 shadow_underlay_event_handler_ =
1621 base::MakeUnique<ShadowUnderlayEventHandler>(); 1637 base::MakeUnique<ShadowUnderlayEventHandler>();
1622 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get()); 1638 shadow_underlay_->SetTargetHandler(shadow_underlay_event_handler_.get());
1623 DCHECK(shadow_underlay_->owned_by_parent()); 1639 DCHECK(!shadow_underlay_->owned_by_parent());
1624 // Ensure the background area inside the shadow is solid black. 1640 // Ensure the background area inside the shadow is solid black.
1625 // Clients that provide translucent contents should not be using 1641 // Clients that provide translucent contents should not be using
1626 // rectangular shadows as this method requires opaque contents to 1642 // rectangular shadows as this method requires opaque contents to
1627 // cast a shadow that represent it correctly. 1643 // cast a shadow that represent it correctly.
1628 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR); 1644 shadow_underlay_->Init(ui::LAYER_SOLID_COLOR);
1629 shadow_underlay_->layer()->SetColor(SK_ColorBLACK); 1645 shadow_underlay_->layer()->SetColor(SK_ColorBLACK);
1630 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely()); 1646 DCHECK(shadow_underlay_->layer()->fills_bounds_opaquely());
1631 if (shadow_underlay_in_surface_) { 1647 if (shadow_underlay_in_surface_) {
1632 surface_->window()->AddChild(shadow_underlay_); 1648 surface_->window()->AddChild(shadow_underlay());
1633 surface_->window()->StackChildAtBottom(shadow_underlay_); 1649 surface_->window()->StackChildAtBottom(shadow_underlay());
1634 } else { 1650 } else {
1635 window->AddChild(shadow_underlay_); 1651 window->AddChild(shadow_underlay());
1636 window->StackChildAtBottom(shadow_underlay_); 1652 window->StackChildAtBottom(shadow_underlay());
1637 } 1653 }
1638 } 1654 }
1639 1655
1640 bool underlay_capture_events =
1641 WMHelper::GetInstance()->IsSpokenFeedbackEnabled() &&
1642 widget_->IsActive();
1643
1644 float shadow_underlay_opacity = shadow_background_opacity_; 1656 float shadow_underlay_opacity = shadow_background_opacity_;
1645 1657
1646 // Put the black background layer behind the window if 1658 // Put the black background layer behind the window if
1647 // 1) the window is in immersive fullscreen, maximized or is active with 1659 // 1) the window is in immersive fullscreen, maximized or is active with
1648 // spoken feedback enabled. 1660 // spoken feedback enabled.
1649 // 2) the window can control the bounds of the window in fullscreen ( 1661 // 2) the window can control the bounds of the window in fullscreen (
1650 // thus the background can be visible). 1662 // thus the background can be visible).
1651 // 3) the window has no transform (the transformed background may 1663 // 3) the window has no transform (the transformed background may
1652 // not cover the entire background, e.g. overview mode). 1664 // not cover the entire background, e.g. overview mode).
1653 if ((widget_->IsFullscreen() || widget_->IsMaximized() || 1665 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_) { 1666 if (shadow_underlay_in_surface_) {
1658 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size()); 1667 shadow_underlay_bounds = gfx::Rect(surface_->window()->bounds().size());
1659 } else { 1668 } else {
1660 gfx::Point origin; 1669 gfx::Point origin;
1661 origin -= window->bounds().origin().OffsetFromOrigin(); 1670 origin -= window->bounds().origin().OffsetFromOrigin();
1662 shadow_bounds.set_origin(origin); 1671 shadow_bounds.set_origin(origin);
1663 shadow_bounds.set_size(window->parent()->bounds().size()); 1672 shadow_bounds.set_size(window->parent()->bounds().size());
1664 } 1673 }
1665 shadow_underlay_opacity = 1.0f; 1674 shadow_underlay_opacity = 1.0f;
1666 } 1675 }
1667 1676
1668 if (!shadow_underlay_in_surface_) 1677 if (!shadow_underlay_in_surface_)
1669 shadow_underlay_bounds = shadow_bounds; 1678 shadow_underlay_bounds = shadow_bounds;
1670 1679
1671 // Constrain the underlay bounds to the client area in case shell surface 1680 // Constrain the underlay bounds to the client area in case shell surface
1672 // frame is enabled. 1681 // frame is enabled.
1673 if (frame_enabled_) { 1682 if (frame_enabled_) {
1674 shadow_underlay_bounds.Intersect( 1683 shadow_underlay_bounds.Intersect(
1675 widget_->non_client_view()->frame_view()->GetBoundsForClientView()); 1684 widget_->non_client_view()->frame_view()->GetBoundsForClientView());
1676 } 1685 }
1677 1686
1678 shadow_underlay_->SetBounds(shadow_underlay_bounds); 1687 shadow_underlay_->SetBounds(shadow_underlay_bounds);
1679 1688
1680 shadow_underlay_->Show(); 1689 if (!shadow_underlay_->IsVisible())
oshima 2017/04/25 17:04:40 Not sure why I missed the original CL, but this is
1690 shadow_underlay_->Show();
1681 1691
1682 // TODO(oshima): Setting to the same value should be no-op. 1692 // TODO(oshima): Setting to the same value should be no-op.
1683 // crbug.com/642223. 1693 // crbug.com/642223.
1684 if (shadow_underlay_opacity != 1694 if (shadow_underlay_opacity !=
1685 shadow_underlay_->layer()->GetTargetOpacity()) { 1695 shadow_underlay_->layer()->GetTargetOpacity()) {
1686 shadow_underlay_->layer()->SetOpacity(shadow_underlay_opacity); 1696 shadow_underlay_->layer()->SetOpacity(shadow_underlay_opacity);
1687 } 1697 }
1688 1698
1689 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window); 1699 wm::Shadow* shadow = wm::ShadowController::GetShadowForWindow(window);
1690 // Maximized/Fullscreen window does not create a shadow. 1700 // Maximized/Fullscreen window does not create a shadow.
1691 if (!shadow) 1701 if (!shadow)
1692 return; 1702 return;
1693 1703
1694 if (!shadow_overlay_) { 1704 if (!shadow_overlay_) {
1695 shadow_overlay_ = new aura::Window(nullptr); 1705 shadow_overlay_ = base::MakeUnique<aura::Window>(nullptr);
1696 DCHECK(shadow_overlay_->owned_by_parent()); 1706 shadow_overlay_->set_owned_by_parent(false);
1707 DCHECK(!shadow_overlay_->owned_by_parent());
1697 shadow_overlay_->set_ignore_events(true); 1708 shadow_overlay_->set_ignore_events(true);
1698 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN); 1709 shadow_overlay_->Init(ui::LAYER_NOT_DRAWN);
1699 shadow_overlay_->layer()->Add(shadow->layer()); 1710 shadow_overlay_->layer()->Add(shadow->layer());
1700 window->AddChild(shadow_overlay_); 1711 window->AddChild(shadow_overlay());
1701 1712
1702 if (shadow_underlay_in_surface_) { 1713 if (shadow_underlay_in_surface_) {
1703 window->StackChildBelow(shadow_overlay_, surface_->window()); 1714 window->StackChildBelow(shadow_overlay(), surface_->window());
1704 } else { 1715 } else {
1705 window->StackChildAbove(shadow_overlay_, shadow_underlay_); 1716 window->StackChildAbove(shadow_overlay(), shadow_underlay());
1706 } 1717 }
1707 shadow_overlay_->Show(); 1718 shadow_overlay_->Show();
1708 } 1719 }
1709 shadow_overlay_->SetBounds(shadow_bounds); 1720 shadow_overlay_->SetBounds(shadow_bounds);
1710 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size())); 1721 shadow->SetContentBounds(gfx::Rect(shadow_bounds.size()));
1711 // Surfaces that can't be activated are usually menus and tooltips. Use a 1722 // Surfaces that can't be activated are usually menus and tooltips. Use a
1712 // small style shadow for them. 1723 // small style shadow for them.
1713 if (!activatable_) 1724 if (!activatable_)
1714 shadow->SetElevation(wm::ShadowElevation::SMALL); 1725 shadow->SetElevation(wm::ShadowElevation::SMALL);
1715 // We don't have rounded corners unless frame is enabled. 1726 // We don't have rounded corners unless frame is enabled.
1716 if (!frame_enabled_) 1727 if (!frame_enabled_)
1717 shadow->SetRoundedCornerRadius(0); 1728 shadow->SetRoundedCornerRadius(0);
1718 } 1729 }
1719 } 1730 }
1720 1731
1721 gfx::Point ShellSurface::GetMouseLocation() const { 1732 gfx::Point ShellSurface::GetMouseLocation() const {
1722 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow(); 1733 aura::Window* const root_window = widget_->GetNativeWindow()->GetRootWindow();
1723 gfx::Point location = 1734 gfx::Point location =
1724 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot(); 1735 root_window->GetHost()->dispatcher()->GetLastMouseLocationInRoot();
1725 aura::Window::ConvertPointToTarget( 1736 aura::Window::ConvertPointToTarget(
1726 root_window, widget_->GetNativeWindow()->parent(), &location); 1737 root_window, widget_->GetNativeWindow()->parent(), &location);
1727 return location; 1738 return location;
1728 } 1739 }
1729 1740
1741 void ShellSurface::ResetShadowWindows() {
1742 shadow_overlay_.reset();
1743 shadow_underlay_.reset();
1744 }
1745
1730 } // namespace exo 1746 } // namespace exo
OLDNEW
« no previous file with comments | « components/exo/shell_surface.h ('k') | components/exo/shell_surface_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698