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

Unified Diff: ash/common/system/tray/tray_background_view.cc

Issue 2491033006: Adjust positioning of cros tray bubbles. (Closed)
Patch Set: . Created 4 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: ash/common/system/tray/tray_background_view.cc
diff --git a/ash/common/system/tray/tray_background_view.cc b/ash/common/system/tray/tray_background_view.cc
index 727b1ae57d1dd317b82a6d566d01702d389ecdf5..3be8603db379ecbbedd3c9c73d45aab71e699264 100644
--- a/ash/common/system/tray/tray_background_view.cc
+++ b/ash/common/system/tray/tray_background_view.cc
@@ -233,12 +233,15 @@ void TrayBackgroundView::TrayContainer::UpdateLayout() {
: gfx::Insets(kHitRegionPadding, 0,
kHitRegionPadding + kSeparatorWidth, 0)
: gfx::Insets(kBackgroundAdjustPadding));
- const gfx::Insets margin(
- is_horizontal ? gfx::Insets(cross_axis_margin_, main_axis_margin_)
- : gfx::Insets(main_axis_margin_, cross_axis_margin_));
- SetBorder(views::CreateEmptyBorder(insets + margin));
+ SetBorder(views::CreateEmptyBorder(insets));
+
+ int horizontal_margin = main_axis_margin_;
+ int vertical_margin = cross_axis_margin_;
+ if (!is_horizontal)
+ std::swap(horizontal_margin, vertical_margin);
+ views::BoxLayout* layout =
+ new views::BoxLayout(orientation, horizontal_margin, vertical_margin, 0);
- views::BoxLayout* layout = new views::BoxLayout(orientation, 0, 0, 0);
if (!ash::MaterialDesignController::IsShelfMaterial())
layout->SetDefaultFlex(1);
layout->set_minimum_cross_axis_size(kTrayItemSize);
@@ -389,6 +392,7 @@ void TrayBackgroundView::SetContents(views::View* contents) {
SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
AddChildView(contents);
}
+
void TrayBackgroundView::SetContentsBackground() {
background_ = new TrayBackground(this);
tray_container_->set_background(background_);
@@ -429,84 +433,6 @@ void TrayBackgroundView::HideTransformation() {
layer()->SetTransform(transform);
}
-gfx::Rect TrayBackgroundView::GetBubbleAnchorRect(
- views::Widget* anchor_widget,
- TrayBubbleView::AnchorType anchor_type,
- TrayBubbleView::AnchorAlignment anchor_alignment) const {
- gfx::Rect rect;
- if (anchor_widget && anchor_widget->IsVisible()) {
- rect = anchor_widget->GetWindowBoundsInScreen();
- if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
- if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
- bool rtl = base::i18n::IsRTL();
- rect.Inset(rtl ? kBubblePaddingHorizontalSide : 0,
- kBubblePaddingHorizontalBottom,
- rtl ? 0 : kBubblePaddingHorizontalSide, 0);
- } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
- rect.Inset(0, 0, kBubblePaddingVerticalSide + 4,
- kBubblePaddingVerticalBottom);
- } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
- rect.Inset(kBubblePaddingVerticalSide, 0, 0,
- kBubblePaddingVerticalBottom);
- } else {
- // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
- // ie. ANCHOR_ALIGNMENT_TOP
- DCHECK(false) << "Unhandled anchor alignment.";
- }
- } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) {
- // Invert the offsets to align with the bubble below.
- // Note that with the alternate shelf layout the tips are not shown and
- // the offsets for left and right alignment do not need to be applied.
- int vertical_alignment = 0;
- int horizontal_alignment = kBubblePaddingVerticalBottom;
- if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
- rect.Inset(vertical_alignment, 0, 0, horizontal_alignment);
- else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT)
- rect.Inset(0, 0, vertical_alignment, horizontal_alignment);
- } else {
- DCHECK(false) << "Unhandled anchor type.";
- }
- } else {
- WmWindow* target_root = anchor_widget
- ? WmLookup::Get()
- ->GetWindowForWidget(anchor_widget)
- ->GetRootWindow()
- : WmShell::Get()->GetPrimaryRootWindow();
- rect = target_root->GetBounds();
- if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
- if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
- rect = gfx::Rect(
- base::i18n::IsRTL()
- ? kPaddingFromRightEdgeOfScreenBottomAlignment
- : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
- rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0);
- rect = target_root->ConvertRectToScreen(rect);
- } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
- rect = gfx::Rect(
- kPaddingFromRightEdgeOfScreenBottomAlignment,
- rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1);
- rect = target_root->ConvertRectToScreen(rect);
- } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
- rect = gfx::Rect(
- rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
- rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 1, 1);
- rect = target_root->ConvertRectToScreen(rect);
- } else {
- // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
- // ie. ANCHOR_ALIGNMENT_TOP
- DCHECK(false) << "Unhandled anchor alignment.";
- }
- } else {
- rect = gfx::Rect(
- base::i18n::IsRTL()
- ? kPaddingFromRightEdgeOfScreenBottomAlignment
- : rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
- rect.height() - kPaddingFromBottomOfScreenBottomAlignment, 0, 0);
- }
- }
- return rect;
-}
-
TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
if (shelf_alignment_ == SHELF_ALIGNMENT_LEFT)
return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT;
@@ -541,6 +467,29 @@ void TrayBackgroundView::SetSeparatorVisibility(bool is_shown) {
SchedulePaint();
}
+views::View* TrayBackgroundView::GetBubbleAnchor() const {
+ return tray_container_;
+}
+
+gfx::Insets TrayBackgroundView::GetBubbleAnchorInsets() const {
+ gfx::Insets anchor_insets = GetBubbleAnchor()->GetInsets();
+ gfx::Insets tray_bg_insets = GetInsets();
+ const bool bottom =
+ GetAnchorAlignment() == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
+ // TODO(estade): for reasons I don't understand, BubbleBorder distances the
+ // bubble by the arrow's "interior" thickness even when the paint type is
+ // PAINT_NONE.
+ const int kBigShadowArrowInteriorThickness = 9;
+ return gfx::Insets(
+ bottom ? kBigShadowArrowInteriorThickness - tray_bg_insets.top()
+ : anchor_insets.top(),
+ bottom ? anchor_insets.left()
+ : kBigShadowArrowInteriorThickness - tray_bg_insets.left(),
+ bottom ? -tray_bg_insets.bottom() : anchor_insets.bottom(),
+ bottom ? anchor_insets.right()
+ : kBigShadowArrowInteriorThickness - tray_bg_insets.right());
+}
+
void TrayBackgroundView::OnPaint(gfx::Canvas* canvas) {
ActionableView::OnPaint(canvas);
if (!MaterialDesignController::IsShelfMaterial() ||

Powered by Google App Engine
This is Rietveld 408576698