1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ash/system/tray/tray_background_view.h"
7 #include "ash/ash_switches.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/screen_util.h"
10 #include "ash/shelf/shelf_layout_manager.h"
11 #include "ash/shelf/shelf_widget.h"
12 #include "ash/shell.h"
13 #include "ash/shell_window_ids.h"
14 #include "ash/system/status_area_widget.h"
15 #include "ash/system/status_area_widget_delegate.h"
16 #include "ash/system/tray/system_tray.h"
17 #include "ash/system/tray/tray_constants.h"
18 #include "ash/system/tray/tray_event_filter.h"
19 #include "ash/wm/window_animations.h"
20 #include "grit/ash_resources.h"
21 #include "ui/aura/root_window.h"
22 #include "ui/aura/window.h"
23 #include "ui/base/accessibility/accessible_view_state.h"
24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/gfx/canvas.h"
26 #include "ui/gfx/image/image_skia.h"
27 #include "ui/gfx/image/image_skia_operations.h"
28 #include "ui/gfx/rect.h"
29 #include "ui/gfx/screen.h"
30 #include "ui/gfx/skia_util.h"
31 #include "ui/views/background.h"
32 #include "ui/views/layout/box_layout.h"
36 const int kTrayBackgroundAlpha = 100;
37 const int kTrayBackgroundHoverAlpha = 150;
38 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244);
40 // Adjust the size of TrayContainer with additional padding.
41 const int kTrayContainerVerticalPaddingBottomAlignment = 1;
42 const int kTrayContainerHorizontalPaddingBottomAlignment = 1;
43 const int kTrayContainerVerticalPaddingVerticalAlignment = 1;
44 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1;
46 const int kAnimationDurationForPopupMS = 200;
50 using views::TrayBubbleView;
56 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
58 // Used to track when the anchor widget changes position on screen so that the
59 // bubble position can be updated.
60 class TrayBackgroundView::TrayWidgetObserver : public views::WidgetObserver {
62 explicit TrayWidgetObserver(TrayBackgroundView* host)
66 virtual void OnWidgetBoundsChanged(views::Widget* widget,
67 const gfx::Rect& new_bounds) OVERRIDE {
68 host_->AnchorUpdated();
71 virtual void OnWidgetVisibilityChanged(views::Widget* widget,
72 bool visible) OVERRIDE {
73 host_->AnchorUpdated();
77 TrayBackgroundView* host_;
79 DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver);
82 class TrayBackground : public views::Background {
84 const static int kImageTypeDefault = 0;
85 const static int kImageTypeOnBlack = 1;
86 const static int kImageTypePressed = 2;
87 const static int kNumStates = 3;
89 const static int kImageHorizontal = 0;
90 const static int kImageVertical = 1;
91 const static int kNumOrientations = 2;
93 explicit TrayBackground(TrayBackgroundView* tray_background_view) :
94 tray_background_view_(tray_background_view) {
95 set_alpha(kTrayBackgroundAlpha);
96 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
97 leading_images_[kImageHorizontal][kImageTypeDefault] =
98 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT).ToImageSkia();
99 middle_images_[kImageHorizontal][kImageTypeDefault] =
100 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER).ToImageSkia();
101 trailing_images_[kImageHorizontal][kImageTypeDefault] =
102 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT).ToImageSkia();
104 leading_images_[kImageHorizontal][kImageTypeOnBlack] =
105 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK).ToImageSkia();
106 middle_images_[kImageHorizontal][kImageTypeOnBlack] =
107 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK).ToImageSkia();
108 trailing_images_[kImageHorizontal][kImageTypeOnBlack] =
109 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK).ToImageSkia();
111 leading_images_[kImageHorizontal][kImageTypePressed] =
112 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED).ToImageSkia();
113 middle_images_[kImageHorizontal][kImageTypePressed] =
114 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED).ToImageSkia();
115 trailing_images_[kImageHorizontal][kImageTypePressed] =
116 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED).ToImageSkia();
118 leading_images_[kImageVertical][kImageTypeDefault] =
119 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP).ToImageSkia();
120 middle_images_[kImageVertical][kImageTypeDefault] =
122 IDR_AURA_TRAY_BG_VERTICAL_CENTER).ToImageSkia();
123 trailing_images_[kImageVertical][kImageTypeDefault] =
124 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_BOTTOM).ToImageSkia();
126 leading_images_[kImageVertical][kImageTypeOnBlack] =
127 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK).ToImageSkia();
128 middle_images_[kImageVertical][kImageTypeOnBlack] =
130 IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK).ToImageSkia();
131 trailing_images_[kImageVertical][kImageTypeOnBlack] =
133 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK).ToImageSkia();
135 leading_images_[kImageVertical][kImageTypePressed] =
136 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED).ToImageSkia();
137 middle_images_[kImageVertical][kImageTypePressed] =
139 IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED).ToImageSkia();
140 trailing_images_[kImageVertical][kImageTypePressed] =
142 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED).ToImageSkia();
145 virtual ~TrayBackground() {}
147 SkColor color() { return color_; }
148 void set_color(SkColor color) { color_ = color; }
149 void set_alpha(int alpha) { color_ = SkColorSetARGB(alpha, 0, 0, 0); }
152 ShelfWidget* GetShelfWidget() const {
153 return RootWindowController::ForWindow(tray_background_view_->
154 status_area_widget()->GetNativeWindow())->shelf();
157 void PaintForAlternateShelf(gfx::Canvas* canvas, views::View* view) const {
158 int orientation = kImageHorizontal;
159 ShelfWidget* shelf_widget = GetShelfWidget();
161 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment())
162 orientation = kImageVertical;
164 int state = kImageTypeDefault;
165 if (tray_background_view_->draw_background_as_active())
166 state = kImageTypePressed;
167 else if (shelf_widget && shelf_widget->GetDimsShelf())
168 state = kImageTypeOnBlack;
170 state = kImageTypeDefault;
172 const gfx::ImageSkia* leading = leading_images_[orientation][state];
173 const gfx::ImageSkia* middle = middle_images_[orientation][state];
174 const gfx::ImageSkia* trailing = trailing_images_[orientation][state];
176 gfx::Rect bounds(view->GetLocalBounds());
177 gfx::Point leading_location, trailing_location;
178 gfx::Rect middle_bounds;
180 if (orientation == kImageHorizontal) {
181 leading_location = gfx::Point(0, 0);
182 trailing_location = gfx::Point(bounds.width() - trailing->width(), 0);
183 middle_bounds = gfx::Rect(
186 bounds.width() - (leading->width() + trailing->width()),
189 leading_location = gfx::Point(0, 0);
190 trailing_location = gfx::Point(0, bounds.height() - trailing->height());
191 middle_bounds = gfx::Rect(
195 bounds.height() - (leading->height() + trailing->height()));
198 canvas->DrawImageInt(*leading,
199 leading_location.x(),
200 leading_location.y());
202 canvas->DrawImageInt(*trailing,
203 trailing_location.x(),
204 trailing_location.y());
206 canvas->TileImageInt(*middle,
209 middle_bounds.width(),
210 middle_bounds.height());
213 // Overridden from views::Background.
214 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
215 if (ash::switches::UseAlternateShelfLayout()) {
216 PaintForAlternateShelf(canvas, view);
219 paint.setAntiAlias(true);
220 paint.setStyle(SkPaint::kFill_Style);
221 paint.setColor(color_);
223 gfx::Rect bounds(view->GetLocalBounds());
224 SkScalar radius = SkIntToScalar(kTrayRoundedBorderRadius);
225 path.addRoundRect(gfx::RectToSkRect(bounds), radius, radius);
226 canvas->DrawPath(path, paint);
231 // Reference to the TrayBackgroundView for which this is a background.
232 TrayBackgroundView* tray_background_view_;
234 // References to the images used as backgrounds, they are owned by the
235 // resource bundle class.
236 const gfx::ImageSkia* leading_images_[kNumOrientations][kNumStates];
237 const gfx::ImageSkia* middle_images_[kNumOrientations][kNumStates];
238 const gfx::ImageSkia* trailing_images_[kNumOrientations][kNumStates];
240 DISALLOW_COPY_AND_ASSIGN(TrayBackground);
243 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment)
244 : alignment_(alignment) {
248 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) {
249 if (alignment_ == alignment)
251 alignment_ = alignment;
255 gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() {
257 return views::View::GetPreferredSize();
261 void TrayBackgroundView::TrayContainer::ChildPreferredSizeChanged(
262 views::View* child) {
263 PreferredSizeChanged();
266 void TrayBackgroundView::TrayContainer::ChildVisibilityChanged(View* child) {
267 PreferredSizeChanged();
270 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged(
271 const ViewHierarchyChangedDetails& details) {
272 if (details.parent == this)
273 PreferredSizeChanged();
276 void TrayBackgroundView::TrayContainer::UpdateLayout() {
277 // Adjust the size of status tray dark background by adding additional
279 if (alignment_ == SHELF_ALIGNMENT_BOTTOM ||
280 alignment_ == SHELF_ALIGNMENT_TOP) {
281 int vertical_padding = kTrayContainerVerticalPaddingBottomAlignment;
282 int horizontal_padding = kTrayContainerHorizontalPaddingBottomAlignment;
283 if (ash::switches::UseAlternateShelfLayout()) {
284 vertical_padding = kPaddingFromEdgeOfShelf;
285 horizontal_padding = kPaddingFromEdgeOfShelf;
287 SetBorder(views::Border::CreateEmptyBorder(vertical_padding,
290 horizontal_padding));
292 views::BoxLayout* layout =
293 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
294 layout->set_spread_blank_space(true);
295 views::View::SetLayoutManager(layout);
297 int vertical_padding = kTrayContainerVerticalPaddingVerticalAlignment;
298 int horizontal_padding = kTrayContainerHorizontalPaddingVerticalAlignment;
299 if (ash::switches::UseAlternateShelfLayout()) {
300 vertical_padding = kPaddingFromEdgeOfShelf;
301 horizontal_padding = kPaddingFromEdgeOfShelf;
303 SetBorder(views::Border::CreateEmptyBorder(vertical_padding,
306 horizontal_padding));
308 views::BoxLayout* layout =
309 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
310 layout->set_spread_blank_space(true);
311 views::View::SetLayoutManager(layout);
313 PreferredSizeChanged();
316 ////////////////////////////////////////////////////////////////////////////////
317 // TrayBackgroundView
319 TrayBackgroundView::TrayBackgroundView(
320 internal::StatusAreaWidget* status_area_widget)
321 : status_area_widget_(status_area_widget),
322 tray_container_(NULL),
323 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
325 hide_background_animator_(this, 0, kTrayBackgroundAlpha),
326 hover_background_animator_(
327 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha),
329 draw_background_as_active_(false),
330 widget_observer_(new TrayWidgetObserver(this)) {
331 set_notify_enter_exit_on_child(true);
333 // Initially we want to paint the background, but without the hover effect.
334 hide_background_animator_.SetPaintsBackground(
335 true, BACKGROUND_CHANGE_IMMEDIATE);
336 hover_background_animator_.SetPaintsBackground(
337 false, BACKGROUND_CHANGE_IMMEDIATE);
339 tray_container_ = new TrayContainer(shelf_alignment_);
340 SetContents(tray_container_);
341 tray_event_filter_.reset(new TrayEventFilter);
344 TrayBackgroundView::~TrayBackgroundView() {
346 GetWidget()->RemoveObserver(widget_observer_.get());
349 void TrayBackgroundView::Initialize() {
350 GetWidget()->AddObserver(widget_observer_.get());
354 const char* TrayBackgroundView::GetClassName() const {
355 return kViewClassName;
358 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
360 if (!background_ || draw_background_as_active_ ||
361 ash::switches::UseAlternateShelfLayout())
363 hover_background_animator_.SetPaintsBackground(
364 true, BACKGROUND_CHANGE_ANIMATE);
367 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
369 if (!background_ || draw_background_as_active_ ||
370 ash::switches::UseAlternateShelfLayout())
372 hover_background_animator_.SetPaintsBackground(
373 false, BACKGROUND_CHANGE_ANIMATE);
376 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
377 PreferredSizeChanged();
380 void TrayBackgroundView::GetAccessibleState(ui::AccessibleViewState* state) {
381 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
382 state->name = GetAccessibleNameForTray();
385 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
386 // Return focus to the login view. See crbug.com/120500.
387 views::View* v = GetNextFocusableView();
389 v->AboutToRequestFocusFromTabTraversal(reverse);
392 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
396 gfx::Rect TrayBackgroundView::GetFocusBounds() {
397 // The tray itself expands to the right and bottom edge of the screen to make
398 // sure clicking on the edges brings up the popup. However, the focus border
399 // should be only around the container.
400 return GetContentsBounds();
403 void TrayBackgroundView::UpdateBackground(int alpha) {
404 // The animator should never fire when the alternate shelf layout is used.
405 if (!background_ || draw_background_as_active_)
407 DCHECK(!ash::switches::UseAlternateShelfLayout());
408 background_->set_alpha(hide_background_animator_.alpha() +
409 hover_background_animator_.alpha());
413 void TrayBackgroundView::SetContents(views::View* contents) {
414 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
415 AddChildView(contents);
418 void TrayBackgroundView::SetPaintsBackground(
419 bool value, BackgroundAnimatorChangeType change_type) {
420 DCHECK(!ash::switches::UseAlternateShelfLayout());
421 hide_background_animator_.SetPaintsBackground(value, change_type);
424 void TrayBackgroundView::SetContentsBackground() {
425 background_ = new internal::TrayBackground(this);
426 tray_container_->set_background(background_);
429 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() {
430 return ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView());
433 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
434 shelf_alignment_ = alignment;
436 tray_container_->SetAlignment(alignment);
439 void TrayBackgroundView::SetTrayBorder() {
440 views::View* parent = status_area_widget_->status_area_widget_delegate();
441 // Tray views are laid out right-to-left or bottom-to-top
442 bool on_edge = (this == parent->child_at(0));
443 int left_edge, top_edge, right_edge, bottom_edge;
444 if (ash::switches::UseAlternateShelfLayout()) {
445 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
446 top_edge = ShelfLayoutManager::kShelfItemInset;
448 bottom_edge = ShelfLayoutManager::GetPreferredShelfSize() -
449 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
450 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
451 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) {
453 left_edge = ShelfLayoutManager::GetPreferredShelfSize() -
454 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
455 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
456 right_edge = ShelfLayoutManager::kShelfItemInset;
457 } else { // SHELF_ALIGNMENT_RIGHT
459 left_edge = ShelfLayoutManager::kShelfItemInset;
460 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
461 right_edge = ShelfLayoutManager::GetPreferredShelfSize() -
462 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
465 // Change the border padding for different shelf alignment.
466 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
469 bottom_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment :
470 kPaddingFromBottomOfScreenBottomAlignment - 1;
471 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0;
472 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) {
473 top_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment :
474 kPaddingFromBottomOfScreenBottomAlignment - 1;
477 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0;
478 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) {
480 left_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment;
481 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0;
482 right_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
485 left_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
486 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0;
487 right_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment;
490 SetBorder(views::Border::CreateEmptyBorder(
491 top_edge, left_edge, bottom_edge, right_edge));
494 void TrayBackgroundView::InitializeBubbleAnimations(
495 views::Widget* bubble_widget) {
496 views::corewm::SetWindowVisibilityAnimationType(
497 bubble_widget->GetNativeWindow(),
498 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
499 views::corewm::SetWindowVisibilityAnimationTransition(
500 bubble_widget->GetNativeWindow(),
501 views::corewm::ANIMATE_HIDE);
502 views::corewm::SetWindowVisibilityAnimationDuration(
503 bubble_widget->GetNativeWindow(),
504 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
507 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const {
508 return ash::Shell::GetContainer(
509 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
510 ash::internal::kShellWindowId_SettingBubbleContainer);
513 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect(
514 views::Widget* anchor_widget,
515 TrayBubbleView::AnchorType anchor_type,
516 TrayBubbleView::AnchorAlignment anchor_alignment) const {
518 if (anchor_widget && anchor_widget->IsVisible()) {
519 rect = anchor_widget->GetWindowBoundsInScreen();
520 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
521 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
522 bool rtl = base::i18n::IsRTL();
523 if (!ash::switches::UseAlternateShelfLayout()) {
525 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0,
526 kTrayBubbleAnchorTopInsetBottomAnchor,
527 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment,
528 kPaddingFromBottomOfScreenBottomAlignment);
531 rtl ? kAlternateLayoutBubblePaddingHorizontalSide : 0,
532 kAlternateLayoutBubblePaddingHorizontalBottom,
533 rtl ? 0 : kAlternateLayoutBubblePaddingHorizontalSide,
536 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
537 if (!ash::switches::UseAlternateShelfLayout()) {
538 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5,
539 kPaddingFromBottomOfScreenVerticalAlignment);
541 rect.Inset(0, 0, kAlternateLayoutBubblePaddingVerticalSide + 4,
542 kAlternateLayoutBubblePaddingVerticalBottom);
545 if (!ash::switches::UseAlternateShelfLayout()) {
546 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1,
547 0, 0, kPaddingFromBottomOfScreenVerticalAlignment);
549 rect.Inset(kAlternateLayoutBubblePaddingVerticalSide, 0, 0,
550 kAlternateLayoutBubblePaddingVerticalBottom);
553 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) {
554 // Invert the offsets to align with the bubble below.
555 // Note that with the alternate shelf layout the tips are not shown and
556 // the offsets for left and right alignment do not need to be applied.
557 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ?
559 kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
560 int horizontal_alignment = ash::switches::UseAlternateShelfLayout() ?
561 kAlternateLayoutBubblePaddingVerticalBottom :
562 kPaddingFromBottomOfScreenVerticalAlignment;
563 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
564 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment);
565 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT)
566 rect.Inset(0, 0, vertical_alignment, horizontal_alignment);
570 // TODO(jennyz): May need to add left/right alignment in the following code.
571 if (rect.IsEmpty()) {
572 aura::Window* target_root = anchor_widget ?
573 anchor_widget->GetNativeView()->GetRootWindow() :
574 Shell::GetPrimaryRootWindow();
575 rect = target_root->bounds();
577 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment :
578 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
579 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
581 rect = ScreenUtil::ConvertRectToScreen(target_root, rect);
586 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
587 switch (shelf_alignment_) {
588 case SHELF_ALIGNMENT_BOTTOM:
589 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
590 case SHELF_ALIGNMENT_LEFT:
591 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT;
592 case SHELF_ALIGNMENT_RIGHT:
593 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT;
594 case SHELF_ALIGNMENT_TOP:
595 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP;
598 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
601 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
602 draw_background_as_active_ = visible;
603 if (!background_ || !switches::UseAlternateShelfLayout())
606 // Do not change gradually, changing color between grey and blue is weird.
607 if (draw_background_as_active_)
608 background_->set_color(kTrayBackgroundPressedColor);
610 background_->set_alpha(kTrayBackgroundHoverAlpha);
612 background_->set_alpha(kTrayBackgroundAlpha);
616 void TrayBackgroundView::UpdateBubbleViewArrow(
617 views::TrayBubbleView* bubble_view) {
618 if (switches::UseAlternateShelfLayout())
621 aura::Window* root_window =
622 bubble_view->GetWidget()->GetNativeView()->GetRootWindow();
623 ash::internal::ShelfLayoutManager* shelf =
624 ShelfLayoutManager::ForShelf(root_window);
625 bubble_view->SetArrowPaintType(
626 (shelf && shelf->IsVisible()) ?
627 views::BubbleBorder::PAINT_NORMAL :
628 views::BubbleBorder::PAINT_TRANSPARENT);
631 } // namespace internal