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_ash.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 set_border(views::Border::CreateEmptyBorder(
291 horizontal_padding));
293 views::BoxLayout* layout =
294 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
295 layout->set_spread_blank_space(true);
296 views::View::SetLayoutManager(layout);
298 int vertical_padding = kTrayContainerVerticalPaddingVerticalAlignment;
299 int horizontal_padding = kTrayContainerHorizontalPaddingVerticalAlignment;
300 if (ash::switches::UseAlternateShelfLayout()) {
301 vertical_padding = kPaddingFromEdgeOfShelf;
302 horizontal_padding = kPaddingFromEdgeOfShelf;
304 set_border(views::Border::CreateEmptyBorder(
308 horizontal_padding));
310 views::BoxLayout* layout =
311 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
312 layout->set_spread_blank_space(true);
313 views::View::SetLayoutManager(layout);
315 PreferredSizeChanged();
318 ////////////////////////////////////////////////////////////////////////////////
319 // TrayBackgroundView
321 TrayBackgroundView::TrayBackgroundView(
322 internal::StatusAreaWidget* status_area_widget)
323 : status_area_widget_(status_area_widget),
324 tray_container_(NULL),
325 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
327 hide_background_animator_(this, 0, kTrayBackgroundAlpha),
328 hover_background_animator_(
329 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha),
331 draw_background_as_active_(false),
332 widget_observer_(new TrayWidgetObserver(this)) {
333 set_notify_enter_exit_on_child(true);
335 // Initially we want to paint the background, but without the hover effect.
336 hide_background_animator_.SetPaintsBackground(true,
337 internal::BackgroundAnimator::CHANGE_IMMEDIATE);
338 hover_background_animator_.SetPaintsBackground(false,
339 internal::BackgroundAnimator::CHANGE_IMMEDIATE);
341 tray_container_ = new TrayContainer(shelf_alignment_);
342 SetContents(tray_container_);
343 tray_event_filter_.reset(new TrayEventFilter);
346 TrayBackgroundView::~TrayBackgroundView() {
348 GetWidget()->RemoveObserver(widget_observer_.get());
351 void TrayBackgroundView::Initialize() {
352 GetWidget()->AddObserver(widget_observer_.get());
356 const char* TrayBackgroundView::GetClassName() const {
357 return kViewClassName;
360 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
362 if (!background_ || draw_background_as_active_ ||
363 ash::switches::UseAlternateShelfLayout())
365 hover_background_animator_.SetPaintsBackground(true,
366 internal::BackgroundAnimator::CHANGE_ANIMATE);
369 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
371 if (!background_ || draw_background_as_active_ ||
372 ash::switches::UseAlternateShelfLayout())
374 hover_background_animator_.SetPaintsBackground(false,
375 internal::BackgroundAnimator::CHANGE_ANIMATE);
378 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
379 PreferredSizeChanged();
382 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) {
383 // The tray itself expands to the right and bottom edge of the screen to make
384 // sure clicking on the edges brings up the popup. However, the focus border
385 // should be only around the container.
386 if (HasFocus() && (focusable() || IsAccessibilityFocusable()))
387 DrawBorder(canvas, GetContentsBounds());
390 void TrayBackgroundView::GetAccessibleState(ui::AccessibleViewState* state) {
391 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON;
392 state->name = GetAccessibleNameForTray();
395 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
396 // Return focus to the login view. See crbug.com/120500.
397 views::View* v = GetNextFocusableView();
399 v->AboutToRequestFocusFromTabTraversal(reverse);
402 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
406 void TrayBackgroundView::UpdateBackground(int alpha) {
407 // The animator should never fire when the alternate shelf layout is used.
408 if (!background_ || draw_background_as_active_)
410 DCHECK(!ash::switches::UseAlternateShelfLayout());
411 background_->set_alpha(hide_background_animator_.alpha() +
412 hover_background_animator_.alpha());
416 void TrayBackgroundView::SetContents(views::View* contents) {
417 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
418 AddChildView(contents);
421 void TrayBackgroundView::SetPaintsBackground(
423 internal::BackgroundAnimator::ChangeType change_type) {
424 DCHECK(!ash::switches::UseAlternateShelfLayout());
425 hide_background_animator_.SetPaintsBackground(value, change_type);
428 void TrayBackgroundView::SetContentsBackground() {
429 background_ = new internal::TrayBackground(this);
430 tray_container_->set_background(background_);
433 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() {
434 return ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView());
437 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
438 shelf_alignment_ = alignment;
440 tray_container_->SetAlignment(alignment);
443 void TrayBackgroundView::SetBorder() {
444 views::View* parent = status_area_widget_->status_area_widget_delegate();
445 // Tray views are laid out right-to-left or bottom-to-top
446 bool on_edge = (this == parent->child_at(0));
447 int left_edge, top_edge, right_edge, bottom_edge;
448 if (ash::switches::UseAlternateShelfLayout()) {
449 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
450 top_edge = ShelfLayoutManager::kShelfItemInset;
452 bottom_edge = ShelfLayoutManager::GetPreferredShelfSize() -
453 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
454 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
455 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) {
457 left_edge = ShelfLayoutManager::GetPreferredShelfSize() -
458 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
459 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
460 right_edge = ShelfLayoutManager::kShelfItemInset;
461 } else { // SHELF_ALIGNMENT_RIGHT
463 left_edge = ShelfLayoutManager::kShelfItemInset;
464 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
465 right_edge = ShelfLayoutManager::GetPreferredShelfSize() -
466 ShelfLayoutManager::kShelfItemInset - GetShelfItemHeight();
469 // Change the border padding for different shelf alignment.
470 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
473 bottom_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment :
474 kPaddingFromBottomOfScreenBottomAlignment - 1;
475 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0;
476 } else if (shelf_alignment() == SHELF_ALIGNMENT_TOP) {
477 top_edge = on_edge ? kPaddingFromBottomOfScreenBottomAlignment :
478 kPaddingFromBottomOfScreenBottomAlignment - 1;
481 right_edge = on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0;
482 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) {
484 left_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment;
485 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0;
486 right_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
489 left_edge = kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
490 bottom_edge = on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0;
491 right_edge = kPaddingFromOuterEdgeOfLauncherVerticalAlignment;
494 set_border(views::Border::CreateEmptyBorder(
495 top_edge, left_edge, bottom_edge, right_edge));
498 void TrayBackgroundView::InitializeBubbleAnimations(
499 views::Widget* bubble_widget) {
500 views::corewm::SetWindowVisibilityAnimationType(
501 bubble_widget->GetNativeWindow(),
502 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
503 views::corewm::SetWindowVisibilityAnimationTransition(
504 bubble_widget->GetNativeWindow(),
505 views::corewm::ANIMATE_HIDE);
506 views::corewm::SetWindowVisibilityAnimationDuration(
507 bubble_widget->GetNativeWindow(),
508 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS));
511 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const {
512 return ash::Shell::GetContainer(
513 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
514 ash::internal::kShellWindowId_SettingBubbleContainer);
517 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect(
518 views::Widget* anchor_widget,
519 TrayBubbleView::AnchorType anchor_type,
520 TrayBubbleView::AnchorAlignment anchor_alignment) const {
522 if (anchor_widget && anchor_widget->IsVisible()) {
523 rect = anchor_widget->GetWindowBoundsInScreen();
524 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
525 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
526 bool rtl = base::i18n::IsRTL();
527 if (!ash::switches::UseAlternateShelfLayout()) {
529 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0,
530 kTrayBubbleAnchorTopInsetBottomAnchor,
531 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment,
532 kPaddingFromBottomOfScreenBottomAlignment);
535 rtl ? kAlternateLayoutBubblePaddingHorizontalSide : 0,
536 kAlternateLayoutBubblePaddingHorizontalBottom,
537 rtl ? 0 : kAlternateLayoutBubblePaddingHorizontalSide,
540 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
541 if (!ash::switches::UseAlternateShelfLayout()) {
542 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 5,
543 kPaddingFromBottomOfScreenVerticalAlignment);
545 rect.Inset(0, 0, kAlternateLayoutBubblePaddingVerticalSide + 4,
546 kAlternateLayoutBubblePaddingVerticalBottom);
549 if (!ash::switches::UseAlternateShelfLayout()) {
550 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment + 1,
551 0, 0, kPaddingFromBottomOfScreenVerticalAlignment);
553 rect.Inset(kAlternateLayoutBubblePaddingVerticalSide, 0, 0,
554 kAlternateLayoutBubblePaddingVerticalBottom);
557 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) {
558 // Invert the offsets to align with the bubble below.
559 // Note that with the alternate shelf layout the tips are not shown and
560 // the offsets for left and right alignment do not need to be applied.
561 int vertical_alignment = ash::switches::UseAlternateShelfLayout() ?
563 kPaddingFromInnerEdgeOfLauncherVerticalAlignment;
564 int horizontal_alignment = ash::switches::UseAlternateShelfLayout() ?
565 kAlternateLayoutBubblePaddingVerticalBottom :
566 kPaddingFromBottomOfScreenVerticalAlignment;
567 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
568 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment);
569 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT)
570 rect.Inset(0, 0, vertical_alignment, horizontal_alignment);
574 // TODO(jennyz): May need to add left/right alignment in the following code.
575 if (rect.IsEmpty()) {
576 aura::Window* target_root = anchor_widget ?
577 anchor_widget->GetNativeView()->GetRootWindow() :
578 Shell::GetPrimaryRootWindow();
579 rect = target_root->bounds();
581 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment :
582 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
583 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
585 rect = ScreenAsh::ConvertRectToScreen(target_root, rect);
590 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
591 switch (shelf_alignment_) {
592 case SHELF_ALIGNMENT_BOTTOM:
593 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
594 case SHELF_ALIGNMENT_LEFT:
595 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT;
596 case SHELF_ALIGNMENT_RIGHT:
597 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT;
598 case SHELF_ALIGNMENT_TOP:
599 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP;
602 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
605 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
606 draw_background_as_active_ = visible;
607 if (!background_ || !switches::UseAlternateShelfLayout())
610 // Do not change gradually, changing color between grey and blue is weird.
611 if (draw_background_as_active_)
612 background_->set_color(kTrayBackgroundPressedColor);
614 background_->set_alpha(kTrayBackgroundHoverAlpha);
616 background_->set_alpha(kTrayBackgroundAlpha);
620 void TrayBackgroundView::UpdateBubbleViewArrow(
621 views::TrayBubbleView* bubble_view) {
622 if (switches::UseAlternateShelfLayout())
625 aura::Window* root_window =
626 bubble_view->GetWidget()->GetNativeView()->GetRootWindow();
627 ash::internal::ShelfLayoutManager* shelf =
628 ShelfLayoutManager::ForLauncher(root_window);
629 bubble_view->SetArrowPaintType(
630 (shelf && shelf->IsVisible()) ?
631 views::BubbleBorder::PAINT_NORMAL :
632 views::BubbleBorder::PAINT_TRANSPARENT);
635 } // namespace internal