Commit 01629498 authored by Tim Song's avatar Tim Song Committed by Commit Bot

Ash Tray: Refactor tray bubble insets calculations to one function.

There are many code sites which calculates the work area insets for positioning
a tray bubble or pop-up notification. Now that the calculation is more complex,
it makes sense to consolidate everything to one function.

This CL also fixes insets for the message center bubble and lock screen in
tablet mode.

TEST=manually verified
BUG=1040693

Change-Id: Ic8381a0b749e9e95b56717a239285f4bbddf7f08
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1993746Reviewed-by: default avatarAhmed Mehfooz <amehfooz@chromium.org>
Commit-Queue: Tim Song <tengs@chromium.org>
Cr-Commit-Position: refs/heads/master@{#729990}
parent e8093b62
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/work_area_insets.h" #include "ash/wm/work_area_insets.h"
#include "base/i18n/rtl.h" #include "base/i18n/rtl.h"
...@@ -91,21 +92,9 @@ int AshMessagePopupCollection::GetToastOriginX( ...@@ -91,21 +92,9 @@ int AshMessagePopupCollection::GetToastOriginX(
} }
int AshMessagePopupCollection::GetBaseline() const { int AshMessagePopupCollection::GetBaseline() const {
int baseline = gfx::Insets tray_bubble_insets = GetTrayBubbleInsets();
work_area_.bottom() - kUnifiedMenuPadding - tray_bubble_height_; return work_area_.bottom() - tray_bubble_insets.bottom() -
tray_bubble_height_;
// The work area in tablet mode always uses the in-app shelf height, which
// ignores the height of the hotseat. We need to add additional height to the
// baseline to compensate.
bool in_tablet_mode = Shell::Get()->tablet_mode_controller() &&
Shell::Get()->tablet_mode_controller()->InTabletMode();
bool is_bottom_alignment = shelf_->alignment() == ShelfAlignment::kBottom;
if (chromeos::switches::ShouldShowShelfHotseat() && in_tablet_mode &&
!ShelfConfig::Get()->is_in_app() && is_bottom_alignment) {
baseline -= kPopupCollectionHotseatHeightCompensation;
}
return baseline;
} }
gfx::Rect AshMessagePopupCollection::GetWorkArea() const { gfx::Rect AshMessagePopupCollection::GetWorkArea() const {
......
...@@ -8,13 +8,14 @@ ...@@ -8,13 +8,14 @@
#include "ash/accessibility/accessibility_controller_impl.h" #include "ash/accessibility/accessibility_controller_impl.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/style/default_color_constants.h" #include "ash/style/default_color_constants.h"
#include "ash/system/message_center/unified_message_center_view.h" #include "ash/system/message_center/unified_message_center_view.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_event_filter.h" #include "ash/system/tray/tray_event_filter.h"
#include "ash/system/tray/tray_utils.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/unified/unified_system_tray_view.h" #include "ash/system/unified/unified_system_tray_view.h"
...@@ -158,13 +159,15 @@ void UnifiedMessageCenterBubble::UpdatePosition() { ...@@ -158,13 +159,15 @@ void UnifiedMessageCenterBubble::UpdatePosition() {
// position of the layer. // position of the layer.
gfx::Rect anchor_rect = tray_->shelf()->GetSystemTrayAnchorRect(); gfx::Rect anchor_rect = tray_->shelf()->GetSystemTrayAnchorRect();
int left_offset = gfx::Insets tray_bubble_insets = GetTrayBubbleInsets();
tray_->shelf()->alignment() == ShelfAlignment::kLeft int left_offset = tray_->shelf()->alignment() == ShelfAlignment::kLeft
? kUnifiedMenuPadding ? tray_bubble_insets.left()
: -(kUnifiedMenuPadding - (base::i18n::IsRTL() ? 0 : 1)); : -tray_bubble_insets.right();
anchor_rect.set_x(anchor_rect.x() + left_offset); anchor_rect.set_x(anchor_rect.x() + left_offset);
anchor_rect.set_y(anchor_rect.y() - tray_->bubble()->GetCurrentTrayHeight() - anchor_rect.set_y(anchor_rect.y() - tray_->bubble()->GetCurrentTrayHeight() -
kUnifiedMenuPadding - kUnifiedMessageCenterBubbleSpacing); tray_bubble_insets.bottom() -
kUnifiedMessageCenterBubbleSpacing);
bubble_view_->ChangeAnchorRect(anchor_rect); bubble_view_->ChangeAnchorRect(anchor_rect);
bubble_widget_->GetLayer()->StackAtTop(border_->layer()); bubble_widget_->GetLayer()->StackAtTop(border_->layer());
......
...@@ -106,7 +106,6 @@ constexpr int kUnifiedSliderViewSpacing = 12; ...@@ -106,7 +106,6 @@ constexpr int kUnifiedSliderViewSpacing = 12;
constexpr int kUnifiedMenuPadding = 8; constexpr int kUnifiedMenuPadding = 8;
constexpr int kUnifiedMessageCenterBubbleSpacing = 8; constexpr int kUnifiedMessageCenterBubbleSpacing = 8;
constexpr int kUnifiedNotificationCenterSpacing = 16; constexpr int kUnifiedNotificationCenterSpacing = 16;
constexpr int kUnifiedNonInAppBubblePadding = 8;
constexpr int kUnifiedTrayIconSize = 20; constexpr int kUnifiedTrayIconSize = 20;
constexpr int kUnifiedTraySpacingBetweenIcons = 6; constexpr int kUnifiedTraySpacingBetweenIcons = 6;
constexpr int kUnifiedTrayBatteryWidth = 10; constexpr int kUnifiedTrayBatteryWidth = 10;
...@@ -200,7 +199,9 @@ constexpr int kStatusAreaLeftPaddingForOverflow = 100; ...@@ -200,7 +199,9 @@ constexpr int kStatusAreaLeftPaddingForOverflow = 100;
constexpr int kStatusAreaForceCollapseAvailableWidth = 200; constexpr int kStatusAreaForceCollapseAvailableWidth = 200;
constexpr int kStatusAreaOverflowGradientSize = 24; constexpr int kStatusAreaOverflowGradientSize = 24;
constexpr int kPopupCollectionHotseatHeightCompensation = 16; // Height compensations in tablet mode based on whether the hotseat is shown.
constexpr int kTrayBubbleInsetTabletModeCompensation = 8;
constexpr int kTrayBubbleInsetHotseatCompensation = 16;
} // namespace ash } // namespace ash
......
...@@ -4,8 +4,13 @@ ...@@ -4,8 +4,13 @@
#include "ash/system/tray/tray_utils.h" #include "ash/system/tray/tray_utils.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/shelf.h"
#include "ash/shell.h"
#include "ash/style/ash_color_provider.h" #include "ash/style/ash_color_provider.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/gfx/font_list.h" #include "ui/gfx/font_list.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -27,4 +32,49 @@ SkColor TrayIconColor(session_manager::SessionState session_state) { ...@@ -27,4 +32,49 @@ SkColor TrayIconColor(session_manager::SessionState session_state) {
: AshColorProvider::AshColorMode::kDark); : AshColorProvider::AshColorMode::kDark);
} }
gfx::Insets GetTrayBubbleInsets() {
// Decrease bottom and right insets to compensate for the adjustment of
// the respective edges in Shelf::GetSystemTrayAnchorRect().
gfx::Insets insets = gfx::Insets(
kUnifiedMenuPadding, kUnifiedMenuPadding, kUnifiedMenuPadding - 1,
kUnifiedMenuPadding - (base::i18n::IsRTL() ? 0 : 1));
// The work area in tablet mode always uses the in-app shelf height, which is
// shorter than the standard shelf height. In this state, we need to add back
// the difference to compensate (see crbug.com/1033302).
bool in_tablet_mode = Shell::Get()->tablet_mode_controller() &&
Shell::Get()->tablet_mode_controller()->InTabletMode();
if (!in_tablet_mode)
return insets;
Shelf* shelf = Shelf::ForWindow(Shell::GetPrimaryRootWindow());
bool is_bottom_alignment =
shelf->alignment() == ShelfAlignment::kBottom ||
shelf->alignment() == ShelfAlignment::kBottomLocked;
if (!is_bottom_alignment)
return insets;
if (!chromeos::switches::ShouldShowShelfHotseat())
return insets;
int height_compensation = kTrayBubbleInsetHotseatCompensation;
switch (shelf->GetBackgroundType()) {
case ShelfBackgroundType::kInApp:
// In-app mode does not require a height compensation.
height_compensation = 0;
break;
case ShelfBackgroundType::kLogin:
// The hotseat is not visible on the lock screen, so we need a smaller
// height compensation.
height_compensation = kTrayBubbleInsetTabletModeCompensation;
break;
default:
break;
}
insets.set_bottom(insets.bottom() + height_compensation);
return insets;
}
} // namespace ash } // namespace ash
...@@ -7,6 +7,7 @@ ...@@ -7,6 +7,7 @@
#include "components/session_manager/session_manager_types.h" #include "components/session_manager/session_manager_types.h"
#include "third_party/skia/include/core/SkColor.h" #include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/geometry/insets.h"
namespace views { namespace views {
class Label; class Label;
...@@ -20,6 +21,9 @@ void SetupLabelForTray(views::Label* label); ...@@ -20,6 +21,9 @@ void SetupLabelForTray(views::Label* label);
// Gets the current tray icon color for the given session state. // Gets the current tray icon color for the given session state.
SkColor TrayIconColor(session_manager::SessionState session_state); SkColor TrayIconColor(session_manager::SessionState session_state);
// Returns the insets above the shelf for positioning the tray bubble.
gfx::Insets GetTrayBubbleInsets();
} // namespace ash } // namespace ash
#endif // ASH_SYSTEM_TRAY_TRAY_UTILS_H_ #endif // ASH_SYSTEM_TRAY_TRAY_UTILS_H_
...@@ -12,11 +12,10 @@ ...@@ -12,11 +12,10 @@
#include "ash/system/keyboard_brightness/unified_keyboard_brightness_slider_controller.h" #include "ash/system/keyboard_brightness/unified_keyboard_brightness_slider_controller.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_utils.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/system/unified/unified_system_tray_view.h" #include "ash/system/unified/unified_system_tray_view.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/accessibility/ax_enums.mojom.h" #include "ui/accessibility/ax_enums.mojom.h"
using chromeos::CrasAudioHandler; using chromeos::CrasAudioHandler;
...@@ -167,7 +166,7 @@ void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) { ...@@ -167,7 +166,7 @@ void UnifiedSliderBubbleController::ShowBubble(SliderType slider_type) {
init_params.anchor_rect = tray_->shelf()->GetSystemTrayAnchorRect(); init_params.anchor_rect = tray_->shelf()->GetSystemTrayAnchorRect();
// Decrease bottom and right insets to compensate for the adjustment of // Decrease bottom and right insets to compensate for the adjustment of
// the respective edges in Shelf::GetSystemTrayAnchorRect(). // the respective edges in Shelf::GetSystemTrayAnchorRect().
init_params.insets = GetInsets(); init_params.insets = GetTrayBubbleInsets();
init_params.corner_radius = kUnifiedTrayCornerRadius; init_params.corner_radius = kUnifiedTrayCornerRadius;
init_params.has_shadow = false; init_params.has_shadow = false;
init_params.translucent = true; init_params.translucent = true;
...@@ -220,27 +219,4 @@ void UnifiedSliderBubbleController::StartAutoCloseTimer() { ...@@ -220,27 +219,4 @@ void UnifiedSliderBubbleController::StartAutoCloseTimer() {
&UnifiedSliderBubbleController::CloseBubble); &UnifiedSliderBubbleController::CloseBubble);
} }
gfx::Insets UnifiedSliderBubbleController::GetInsets() {
// Decrease bottom and right insets to compensate for the adjustment of
// the respective edges in Shelf::GetSystemTrayAnchorRect().
gfx::Insets insets = gfx::Insets(
kUnifiedMenuPadding, kUnifiedMenuPadding, kUnifiedMenuPadding - 1,
kUnifiedMenuPadding - (base::i18n::IsRTL() ? 0 : 1));
// The work area in tablet mode always uses the in-app shelf height, which
// ignores the height of the hotseat. We need to add additional height to the
// baseline to compensate.
bool in_tablet_mode = Shell::Get()->tablet_mode_controller() &&
Shell::Get()->tablet_mode_controller()->InTabletMode();
bool is_bottom_alignment =
tray_->shelf()->alignment() == ShelfAlignment::kBottom;
if (chromeos::switches::ShouldShowShelfHotseat() && in_tablet_mode &&
!ShelfConfig::Get()->is_in_app() && is_bottom_alignment) {
insets.set_bottom(insets.bottom() +
kPopupCollectionHotseatHeightCompensation);
}
return insets;
}
} // namespace ash } // namespace ash
...@@ -68,9 +68,6 @@ class ASH_EXPORT UnifiedSliderBubbleController ...@@ -68,9 +68,6 @@ class ASH_EXPORT UnifiedSliderBubbleController
// Start auto close timer. // Start auto close timer.
void StartAutoCloseTimer(); void StartAutoCloseTimer();
// Returns the insets for the bubble.
gfx::Insets GetInsets();
// Unowned. // Unowned.
UnifiedSystemTray* const tray_; UnifiedSystemTray* const tray_;
......
...@@ -5,13 +5,13 @@ ...@@ -5,13 +5,13 @@
#include "ash/system/unified/unified_system_tray_bubble.h" #include "ash/system/unified/unified_system_tray_bubble.h"
#include "ash/public/cpp/ash_features.h" #include "ash/public/cpp/ash_features.h"
#include "ash/public/cpp/shelf_config.h"
#include "ash/shelf/shelf.h" #include "ash/shelf/shelf.h"
#include "ash/shell.h" #include "ash/shell.h"
#include "ash/system/message_center/unified_message_center_bubble.h" #include "ash/system/message_center/unified_message_center_bubble.h"
#include "ash/system/status_area_widget.h" #include "ash/system/status_area_widget.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_event_filter.h" #include "ash/system/tray/tray_event_filter.h"
#include "ash/system/tray/tray_utils.h"
#include "ash/system/unified/unified_system_tray.h" #include "ash/system/unified/unified_system_tray.h"
#include "ash/system/unified/unified_system_tray_controller.h" #include "ash/system/unified/unified_system_tray_controller.h"
#include "ash/system/unified/unified_system_tray_view.h" #include "ash/system/unified/unified_system_tray_view.h"
...@@ -19,7 +19,6 @@ ...@@ -19,7 +19,6 @@
#include "ash/wm/tablet_mode/tablet_mode_controller.h" #include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "ash/wm/work_area_insets.h" #include "ash/wm/work_area_insets.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "chromeos/constants/chromeos_switches.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/native_theme/native_theme_dark_aura.h" #include "ui/native_theme/native_theme_dark_aura.h"
#include "ui/wm/core/window_util.h" #include "ui/wm/core/window_util.h"
...@@ -88,7 +87,7 @@ UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray, ...@@ -88,7 +87,7 @@ UnifiedSystemTrayBubble::UnifiedSystemTrayBubble(UnifiedSystemTray* tray,
init_params.anchor_view = nullptr; init_params.anchor_view = nullptr;
init_params.anchor_mode = TrayBubbleView::AnchorMode::kRect; init_params.anchor_mode = TrayBubbleView::AnchorMode::kRect;
init_params.anchor_rect = tray->shelf()->GetSystemTrayAnchorRect(); init_params.anchor_rect = tray->shelf()->GetSystemTrayAnchorRect();
init_params.insets = GetInsets(); init_params.insets = GetTrayBubbleInsets();
init_params.corner_radius = kUnifiedTrayCornerRadius; init_params.corner_radius = kUnifiedTrayCornerRadius;
init_params.has_shadow = false; init_params.has_shadow = false;
init_params.show_by_click = show_by_click; init_params.show_by_click = show_by_click;
...@@ -361,26 +360,4 @@ void UnifiedSystemTrayBubble::SetFrameVisible(bool visible) { ...@@ -361,26 +360,4 @@ void UnifiedSystemTrayBubble::SetFrameVisible(bool visible) {
bubble_widget_->non_client_view()->frame_view()->SetVisible(visible); bubble_widget_->non_client_view()->frame_view()->SetVisible(visible);
} }
gfx::Insets UnifiedSystemTrayBubble::GetInsets() {
// Decrease bottom and right insets to compensate for the adjustment of
// the respective edges in Shelf::GetSystemTrayAnchorRect().
gfx::Insets insets = gfx::Insets(
kUnifiedMenuPadding, kUnifiedMenuPadding, kUnifiedMenuPadding - 1,
kUnifiedMenuPadding - (base::i18n::IsRTL() ? 0 : 1));
// The work area in tablet mode always uses the in-app shelf height, which is
// shorter than the standard shelf height. In this state, we need to add back
// the difference to compensate (see crbug.com/1033302).
bool in_tablet_mode = Shell::Get()->tablet_mode_controller() &&
Shell::Get()->tablet_mode_controller()->InTabletMode();
bool is_bottom_alignment =
tray_->shelf()->alignment() == ShelfAlignment::kBottom;
if (chromeos::switches::ShouldShowShelfHotseat() && in_tablet_mode &&
!ShelfConfig::Get()->is_in_app() && is_bottom_alignment) {
insets.set_bottom(insets.bottom() + kUnifiedNonInAppBubblePadding);
}
return insets;
}
} // namespace ash } // namespace ash
...@@ -143,9 +143,6 @@ class ASH_EXPORT UnifiedSystemTrayBubble ...@@ -143,9 +143,6 @@ class ASH_EXPORT UnifiedSystemTrayBubble
// animation. // animation.
void SetFrameVisible(bool visible); void SetFrameVisible(bool visible);
// Returns the insets for the bubble.
gfx::Insets GetInsets();
// Controller of UnifiedSystemTrayView. As the view is owned by views // Controller of UnifiedSystemTrayView. As the view is owned by views
// hierarchy, we have to own the controller here. // hierarchy, we have to own the controller here.
std::unique_ptr<UnifiedSystemTrayController> controller_; std::unique_ptr<UnifiedSystemTrayController> controller_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment