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/root_window_controller.h"
8 #include "ash/screen_util.h"
9 #include "ash/shelf/shelf_layout_manager.h"
10 #include "ash/shelf/shelf_widget.h"
11 #include "ash/shell.h"
12 #include "ash/shell_window_ids.h"
13 #include "ash/system/status_area_widget.h"
14 #include "ash/system/status_area_widget_delegate.h"
15 #include "ash/system/tray/system_tray.h"
16 #include "ash/system/tray/tray_constants.h"
17 #include "ash/system/tray/tray_event_filter.h"
18 #include "ash/wm/window_animations.h"
19 #include "base/command_line.h"
20 #include "grit/ash_resources.h"
21 #include "ui/accessibility/ax_view_state.h"
22 #include "ui/aura/window.h"
23 #include "ui/aura/window_event_dispatcher.h"
24 #include "ui/base/resource/resource_bundle.h"
25 #include "ui/base/ui_base_switches_util.h"
26 #include "ui/compositor/layer.h"
27 #include "ui/compositor/layer_animation_element.h"
28 #include "ui/compositor/scoped_layer_animation_settings.h"
29 #include "ui/events/event_constants.h"
30 #include "ui/gfx/animation/tween.h"
31 #include "ui/gfx/canvas.h"
32 #include "ui/gfx/image/image_skia.h"
33 #include "ui/gfx/image/image_skia_operations.h"
34 #include "ui/gfx/rect.h"
35 #include "ui/gfx/screen.h"
36 #include "ui/gfx/skia_util.h"
37 #include "ui/gfx/transform.h"
38 #include "ui/views/background.h"
39 #include "ui/views/layout/box_layout.h"
43 const int kTrayBackgroundAlpha = 100;
44 const int kTrayBackgroundHoverAlpha = 150;
45 const SkColor kTrayBackgroundPressedColor = SkColorSetRGB(66, 129, 244);
47 const int kAnimationDurationForPopupMs = 200;
49 // Duration of opacity animation for visibility changes.
50 const int kAnimationDurationForVisibilityMs = 250;
52 // When becoming visible delay the animation so that StatusAreaWidgetDelegate
53 // can animate sibling views out of the position to be occuped by the
54 // TrayBackgroundView.
55 const int kShowAnimationDelayMs = 100;
59 using views::TrayBubbleView;
64 const char TrayBackgroundView::kViewClassName[] = "tray/TrayBackgroundView";
66 // Used to track when the anchor widget changes position on screen so that the
67 // bubble position can be updated.
68 class TrayBackgroundView::TrayWidgetObserver : public views::WidgetObserver {
70 explicit TrayWidgetObserver(TrayBackgroundView* host)
74 void OnWidgetBoundsChanged(views::Widget* widget,
75 const gfx::Rect& new_bounds) override {
76 host_->AnchorUpdated();
79 void OnWidgetVisibilityChanged(views::Widget* widget, bool visible) override {
80 host_->AnchorUpdated();
84 TrayBackgroundView* host_;
86 DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver);
89 class TrayBackground : public views::Background {
91 const static int kImageTypeDefault = 0;
92 const static int kImageTypeOnBlack = 1;
93 const static int kImageTypePressed = 2;
94 const static int kNumStates = 3;
96 const static int kImageHorizontal = 0;
97 const static int kImageVertical = 1;
98 const static int kNumOrientations = 2;
100 explicit TrayBackground(TrayBackgroundView* tray_background_view) :
101 tray_background_view_(tray_background_view) {
102 set_alpha(kTrayBackgroundAlpha);
103 ResourceBundle& rb = ResourceBundle::GetSharedInstance();
104 leading_images_[kImageHorizontal][kImageTypeDefault] =
105 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT).ToImageSkia();
106 middle_images_[kImageHorizontal][kImageTypeDefault] =
107 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER).ToImageSkia();
108 trailing_images_[kImageHorizontal][kImageTypeDefault] =
109 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT).ToImageSkia();
111 leading_images_[kImageHorizontal][kImageTypeOnBlack] =
112 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_ONBLACK).ToImageSkia();
113 middle_images_[kImageHorizontal][kImageTypeOnBlack] =
114 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_ONBLACK).ToImageSkia();
115 trailing_images_[kImageHorizontal][kImageTypeOnBlack] =
116 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_ONBLACK).ToImageSkia();
118 leading_images_[kImageHorizontal][kImageTypePressed] =
119 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_LEFT_PRESSED).ToImageSkia();
120 middle_images_[kImageHorizontal][kImageTypePressed] =
121 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_CENTER_PRESSED).ToImageSkia();
122 trailing_images_[kImageHorizontal][kImageTypePressed] =
123 rb.GetImageNamed(IDR_AURA_TRAY_BG_HORIZ_RIGHT_PRESSED).ToImageSkia();
125 leading_images_[kImageVertical][kImageTypeDefault] =
126 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP).ToImageSkia();
127 middle_images_[kImageVertical][kImageTypeDefault] =
129 IDR_AURA_TRAY_BG_VERTICAL_CENTER).ToImageSkia();
130 trailing_images_[kImageVertical][kImageTypeDefault] =
131 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_BOTTOM).ToImageSkia();
133 leading_images_[kImageVertical][kImageTypeOnBlack] =
134 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_ONBLACK).ToImageSkia();
135 middle_images_[kImageVertical][kImageTypeOnBlack] =
137 IDR_AURA_TRAY_BG_VERTICAL_CENTER_ONBLACK).ToImageSkia();
138 trailing_images_[kImageVertical][kImageTypeOnBlack] =
140 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_ONBLACK).ToImageSkia();
142 leading_images_[kImageVertical][kImageTypePressed] =
143 rb.GetImageNamed(IDR_AURA_TRAY_BG_VERTICAL_TOP_PRESSED).ToImageSkia();
144 middle_images_[kImageVertical][kImageTypePressed] =
146 IDR_AURA_TRAY_BG_VERTICAL_CENTER_PRESSED).ToImageSkia();
147 trailing_images_[kImageVertical][kImageTypePressed] =
149 IDR_AURA_TRAY_BG_VERTICAL_BOTTOM_PRESSED).ToImageSkia();
152 ~TrayBackground() override {}
154 SkColor color() { return color_; }
155 void set_color(SkColor color) { color_ = color; }
156 void set_alpha(int alpha) { color_ = SkColorSetARGB(alpha, 0, 0, 0); }
159 ShelfWidget* GetShelfWidget() const {
160 return RootWindowController::ForWindow(tray_background_view_->
161 status_area_widget()->GetNativeWindow())->shelf();
164 // Overridden from views::Background.
165 void Paint(gfx::Canvas* canvas, views::View* view) const override {
166 int orientation = kImageHorizontal;
167 ShelfWidget* shelf_widget = GetShelfWidget();
169 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment())
170 orientation = kImageVertical;
172 int state = kImageTypeDefault;
173 if (tray_background_view_->draw_background_as_active())
174 state = kImageTypePressed;
175 else if (shelf_widget && shelf_widget->GetDimsShelf())
176 state = kImageTypeOnBlack;
178 state = kImageTypeDefault;
180 const gfx::ImageSkia* leading = leading_images_[orientation][state];
181 const gfx::ImageSkia* middle = middle_images_[orientation][state];
182 const gfx::ImageSkia* trailing = trailing_images_[orientation][state];
184 gfx::Rect bounds(view->GetLocalBounds());
185 gfx::Point leading_location, trailing_location;
186 gfx::Rect middle_bounds;
188 if (orientation == kImageHorizontal) {
189 leading_location = gfx::Point(0, 0);
190 trailing_location = gfx::Point(bounds.width() - trailing->width(), 0);
191 middle_bounds = gfx::Rect(
194 bounds.width() - (leading->width() + trailing->width()),
197 leading_location = gfx::Point(0, 0);
198 trailing_location = gfx::Point(0, bounds.height() - trailing->height());
199 middle_bounds = gfx::Rect(
203 bounds.height() - (leading->height() + trailing->height()));
206 canvas->DrawImageInt(*leading,
207 leading_location.x(),
208 leading_location.y());
210 canvas->DrawImageInt(*trailing,
211 trailing_location.x(),
212 trailing_location.y());
214 canvas->TileImageInt(*middle,
217 middle_bounds.width(),
218 middle_bounds.height());
222 // Reference to the TrayBackgroundView for which this is a background.
223 TrayBackgroundView* tray_background_view_;
225 // References to the images used as backgrounds, they are owned by the
226 // resource bundle class.
227 const gfx::ImageSkia* leading_images_[kNumOrientations][kNumStates];
228 const gfx::ImageSkia* middle_images_[kNumOrientations][kNumStates];
229 const gfx::ImageSkia* trailing_images_[kNumOrientations][kNumStates];
231 DISALLOW_COPY_AND_ASSIGN(TrayBackground);
234 TrayBackgroundView::TrayContainer::TrayContainer(ShelfAlignment alignment)
235 : alignment_(alignment) {
239 void TrayBackgroundView::TrayContainer::SetAlignment(ShelfAlignment alignment) {
240 if (alignment_ == alignment)
242 alignment_ = alignment;
246 gfx::Size TrayBackgroundView::TrayContainer::GetPreferredSize() const {
248 return views::View::GetPreferredSize();
252 void TrayBackgroundView::TrayContainer::ChildPreferredSizeChanged(
253 views::View* child) {
254 PreferredSizeChanged();
257 void TrayBackgroundView::TrayContainer::ChildVisibilityChanged(View* child) {
258 PreferredSizeChanged();
261 void TrayBackgroundView::TrayContainer::ViewHierarchyChanged(
262 const ViewHierarchyChangedDetails& details) {
263 if (details.parent == this)
264 PreferredSizeChanged();
267 void TrayBackgroundView::TrayContainer::UpdateLayout() {
268 // Adjust the size of status tray dark background by adding additional
270 if (alignment_ == SHELF_ALIGNMENT_BOTTOM ||
271 alignment_ == SHELF_ALIGNMENT_TOP) {
272 SetBorder(views::Border::CreateEmptyBorder(
273 kPaddingFromEdgeOfShelf,
274 kPaddingFromEdgeOfShelf,
275 kPaddingFromEdgeOfShelf,
276 kPaddingFromEdgeOfShelf));
278 views::BoxLayout* layout =
279 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0);
280 layout->SetDefaultFlex(1);
281 views::View::SetLayoutManager(layout);
283 SetBorder(views::Border::CreateEmptyBorder(
284 kPaddingFromEdgeOfShelf,
285 kPaddingFromEdgeOfShelf,
286 kPaddingFromEdgeOfShelf,
287 kPaddingFromEdgeOfShelf));
289 views::BoxLayout* layout =
290 new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0);
291 layout->SetDefaultFlex(1);
292 views::View::SetLayoutManager(layout);
294 PreferredSizeChanged();
297 ////////////////////////////////////////////////////////////////////////////////
298 // TrayBackgroundView
300 TrayBackgroundView::TrayBackgroundView(StatusAreaWidget* status_area_widget)
301 : status_area_widget_(status_area_widget),
302 tray_container_(NULL),
303 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM),
305 hide_background_animator_(this, 0, kTrayBackgroundAlpha),
306 hover_background_animator_(
309 kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha),
311 draw_background_as_active_(false),
312 widget_observer_(new TrayWidgetObserver(this)) {
313 set_notify_enter_exit_on_child(true);
315 // Initially we want to paint the background, but without the hover effect.
316 hide_background_animator_.SetPaintsBackground(
317 true, BACKGROUND_CHANGE_IMMEDIATE);
318 hover_background_animator_.SetPaintsBackground(
319 false, BACKGROUND_CHANGE_IMMEDIATE);
321 tray_container_ = new TrayContainer(shelf_alignment_);
322 SetContents(tray_container_);
323 tray_event_filter_.reset(new TrayEventFilter);
325 SetPaintToLayer(true);
326 SetFillsBoundsOpaquely(false);
327 // Start the tray items not visible, because visibility changes are animated.
328 views::View::SetVisible(false);
331 TrayBackgroundView::~TrayBackgroundView() {
333 GetWidget()->RemoveObserver(widget_observer_.get());
336 void TrayBackgroundView::Initialize() {
337 GetWidget()->AddObserver(widget_observer_.get());
341 void TrayBackgroundView::SetVisible(bool visible) {
342 if (visible == layer()->GetTargetVisibility())
346 // The alignment of the shelf can change while the TrayBackgroundView is
347 // hidden. Reset the offscreen transform so that the animation to becoming
348 // visible reflects the current layout.
349 HideTransformation();
350 // SetVisible(false) is defered until the animation for hiding is done.
351 // Otherwise the view is immediately hidden and the animation does not
353 views::View::SetVisible(true);
354 // If SetVisible(true) is called while animating to not visible, then
355 // views::View::SetVisible(true) is a no-op. When the previous animation
356 // ends layer->SetVisible(false) is called. To prevent this
357 // layer->SetVisible(true) immediately interrupts the animation of this
358 // property, and keeps the layer visible.
359 layer()->SetVisible(true);
362 ui::ScopedLayerAnimationSettings animation(layer()->GetAnimator());
363 animation.SetTransitionDuration(base::TimeDelta::FromMilliseconds(
364 kAnimationDurationForVisibilityMs));
365 animation.SetPreemptionStrategy(
366 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET);
369 animation.SetTweenType(gfx::Tween::EASE_OUT);
370 // Show is delayed so as to allow time for other children of
371 // StatusAreaWidget to begin animating to their new positions.
372 layer()->GetAnimator()->SchedulePauseForProperties(
373 base::TimeDelta::FromMilliseconds(kShowAnimationDelayMs),
374 ui::LayerAnimationElement::OPACITY |
375 ui::LayerAnimationElement::TRANSFORM);
376 layer()->SetOpacity(1.0f);
377 gfx::Transform transform;
378 transform.Translate(0.0f, 0.0f);
379 layer()->SetTransform(transform);
381 // Listen only to the hide animation. As we cannot turn off visibility
382 // until the animation is over.
383 animation.AddObserver(this);
384 animation.SetTweenType(gfx::Tween::EASE_IN);
385 layer()->SetOpacity(0.0f);
386 layer()->SetVisible(false);
387 HideTransformation();
391 const char* TrayBackgroundView::GetClassName() const {
392 return kViewClassName;
395 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) {
399 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) {
403 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) {
404 PreferredSizeChanged();
407 void TrayBackgroundView::GetAccessibleState(ui::AXViewState* state) {
408 state->role = ui::AX_ROLE_BUTTON;
409 state->name = GetAccessibleNameForTray();
412 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) {
413 // Return focus to the login view. See crbug.com/120500.
414 views::View* v = GetNextFocusableView();
416 v->AboutToRequestFocusFromTabTraversal(reverse);
419 bool TrayBackgroundView::PerformAction(const ui::Event& event) {
423 gfx::Rect TrayBackgroundView::GetFocusBounds() {
424 // The tray itself expands to the right and bottom edge of the screen to make
425 // sure clicking on the edges brings up the popup. However, the focus border
426 // should be only around the container.
427 return GetContentsBounds();
430 void TrayBackgroundView::OnGestureEvent(ui::GestureEvent* event) {
431 if (switches::IsTouchFeedbackEnabled()) {
432 if (event->type() == ui::ET_GESTURE_TAP_DOWN) {
433 SetDrawBackgroundAsActive(true);
434 } else if (event->type() == ui::ET_GESTURE_SCROLL_BEGIN ||
435 event->type() == ui::ET_GESTURE_TAP_CANCEL) {
436 SetDrawBackgroundAsActive(false);
439 ActionableView::OnGestureEvent(event);
442 void TrayBackgroundView::UpdateBackground(int alpha) {
443 // The animator should never fire when the alternate shelf layout is used.
444 if (!background_ || draw_background_as_active_)
446 background_->set_alpha(hide_background_animator_.alpha() +
447 hover_background_animator_.alpha());
451 void TrayBackgroundView::SetContents(views::View* contents) {
452 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0));
453 AddChildView(contents);
456 void TrayBackgroundView::SetPaintsBackground(
457 bool value, BackgroundAnimatorChangeType change_type) {
458 hide_background_animator_.SetPaintsBackground(value, change_type);
461 void TrayBackgroundView::SetContentsBackground() {
462 background_ = new TrayBackground(this);
463 tray_container_->set_background(background_);
466 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() {
467 return ShelfLayoutManager::ForShelf(GetWidget()->GetNativeView());
470 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) {
471 shelf_alignment_ = alignment;
473 tray_container_->SetAlignment(alignment);
476 void TrayBackgroundView::SetTrayBorder() {
477 views::View* parent = status_area_widget_->status_area_widget_delegate();
478 // Tray views are laid out right-to-left or bottom-to-top
479 bool on_edge = (this == parent->child_at(0));
480 int left_edge, top_edge, right_edge, bottom_edge;
481 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) {
482 top_edge = ShelfLayoutManager::kShelfItemInset;
484 bottom_edge = kShelfSize -
485 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
486 right_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
487 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) {
489 left_edge = kShelfSize -
490 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
491 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
492 right_edge = ShelfLayoutManager::kShelfItemInset;
493 } else { // SHELF_ALIGNMENT_RIGHT
495 left_edge = ShelfLayoutManager::kShelfItemInset;
496 bottom_edge = on_edge ? kPaddingFromEdgeOfShelf : 0;
497 right_edge = kShelfSize -
498 ShelfLayoutManager::kShelfItemInset - kShelfItemHeight;
500 SetBorder(views::Border::CreateEmptyBorder(
501 top_edge, left_edge, bottom_edge, right_edge));
504 void TrayBackgroundView::OnImplicitAnimationsCompleted() {
505 // If there is another animation in the queue, the reverse animation was
506 // triggered before the completion of animating to invisible. Do not turn off
507 // the visibility so that the next animation may render. The value of
508 // layer()->GetTargetVisibility() can be incorrect if the hide animation was
509 // aborted to schedule an animation to become visible. As the new animation
510 // is not yet added to the queue. crbug.com/374236
511 if(layer()->GetAnimator()->is_animating() ||
512 layer()->GetTargetVisibility())
514 views::View::SetVisible(false);
517 void TrayBackgroundView::HideTransformation() {
518 gfx::Transform transform;
519 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM ||
520 shelf_alignment_ == SHELF_ALIGNMENT_TOP)
521 transform.Translate(width(), 0.0f);
523 transform.Translate(0.0f, height());
524 layer()->SetTransform(transform);
527 void TrayBackgroundView::InitializeBubbleAnimations(
528 views::Widget* bubble_widget) {
529 wm::SetWindowVisibilityAnimationType(
530 bubble_widget->GetNativeWindow(),
531 wm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE);
532 wm::SetWindowVisibilityAnimationTransition(
533 bubble_widget->GetNativeWindow(),
535 wm::SetWindowVisibilityAnimationDuration(
536 bubble_widget->GetNativeWindow(),
537 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMs));
540 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const {
541 return ash::Shell::GetContainer(
542 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(),
543 ash::kShellWindowId_SettingBubbleContainer);
546 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect(
547 views::Widget* anchor_widget,
548 TrayBubbleView::AnchorType anchor_type,
549 TrayBubbleView::AnchorAlignment anchor_alignment) const {
551 if (anchor_widget && anchor_widget->IsVisible()) {
552 rect = anchor_widget->GetWindowBoundsInScreen();
553 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
554 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
555 bool rtl = base::i18n::IsRTL();
557 rtl ? kBubblePaddingHorizontalSide : 0,
558 kBubblePaddingHorizontalBottom,
559 rtl ? 0 : kBubblePaddingHorizontalSide,
561 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
562 rect.Inset(0, 0, kBubblePaddingVerticalSide + 4,
563 kBubblePaddingVerticalBottom);
564 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
565 rect.Inset(kBubblePaddingVerticalSide, 0, 0,
566 kBubblePaddingVerticalBottom);
568 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
569 // ie. ANCHOR_ALIGNMENT_TOP
570 DCHECK(false) << "Unhandled anchor alignment.";
572 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) {
573 // Invert the offsets to align with the bubble below.
574 // Note that with the alternate shelf layout the tips are not shown and
575 // the offsets for left and right alignment do not need to be applied.
576 int vertical_alignment = 0;
577 int horizontal_alignment = kBubblePaddingVerticalBottom;
578 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT)
579 rect.Inset(vertical_alignment, 0, 0, horizontal_alignment);
580 else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT)
581 rect.Inset(0, 0, vertical_alignment, horizontal_alignment);
583 DCHECK(false) << "Unhandled anchor type.";
586 aura::Window* target_root = anchor_widget ?
587 anchor_widget->GetNativeView()->GetRootWindow() :
588 Shell::GetPrimaryRootWindow();
589 rect = target_root->bounds();
590 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) {
591 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) {
593 base::i18n::IsRTL() ?
594 kPaddingFromRightEdgeOfScreenBottomAlignment :
595 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
596 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
598 rect = ScreenUtil::ConvertRectToScreen(target_root, rect);
599 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) {
601 kPaddingFromRightEdgeOfScreenBottomAlignment,
602 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
604 rect = ScreenUtil::ConvertRectToScreen(target_root, rect);
605 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) {
607 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
608 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
610 rect = ScreenUtil::ConvertRectToScreen(target_root, rect);
612 // TODO(bruthig) May need to handle other ANCHOR_ALIGNMENT_ values.
613 // ie. ANCHOR_ALIGNMENT_TOP
614 DCHECK(false) << "Unhandled anchor alignment.";
618 base::i18n::IsRTL() ?
619 kPaddingFromRightEdgeOfScreenBottomAlignment :
620 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment,
621 rect.height() - kPaddingFromBottomOfScreenBottomAlignment,
628 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const {
629 switch (shelf_alignment_) {
630 case SHELF_ALIGNMENT_BOTTOM:
631 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
632 case SHELF_ALIGNMENT_LEFT:
633 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT;
634 case SHELF_ALIGNMENT_RIGHT:
635 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT;
636 case SHELF_ALIGNMENT_TOP:
637 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP;
640 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM;
643 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) {
644 if (draw_background_as_active_ == visible)
646 draw_background_as_active_ = visible;
650 // Do not change gradually, changing color between grey and blue is weird.
651 if (draw_background_as_active_)
652 background_->set_color(kTrayBackgroundPressedColor);
654 background_->set_alpha(kTrayBackgroundHoverAlpha);
656 background_->set_alpha(kTrayBackgroundAlpha);
660 void TrayBackgroundView::UpdateBubbleViewArrow(
661 views::TrayBubbleView* bubble_view) {
662 // Nothing to do here.