OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/system/tray/tray_background_view.h" | 5 #include "ash/system/tray/tray_background_view.h" |
6 | 6 |
7 #include "ash/launcher/background_animator.h" | 7 #include "ash/launcher/background_animator.h" |
8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
10 #include "ash/system/status_area_widget.h" | 10 #include "ash/system/status_area_widget.h" |
11 #include "ash/system/status_area_widget_delegate.h" | 11 #include "ash/system/status_area_widget_delegate.h" |
12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/wm/window_animations.h" | |
14 #include "ui/aura/event_filter.h" | |
13 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
14 #include "ui/base/accessibility/accessible_view_state.h" | 16 #include "ui/base/accessibility/accessible_view_state.h" |
15 #include "ui/compositor/layer_animation_observer.h" | 17 #include "ui/compositor/layer_animation_observer.h" |
16 #include "ui/gfx/canvas.h" | 18 #include "ui/gfx/canvas.h" |
19 #include "ui/gfx/screen.h" | |
17 #include "ui/gfx/skia_util.h" | 20 #include "ui/gfx/skia_util.h" |
18 #include "ui/views/background.h" | 21 #include "ui/views/background.h" |
19 #include "ui/views/layout/box_layout.h" | 22 #include "ui/views/layout/box_layout.h" |
20 | 23 |
21 namespace { | 24 namespace { |
22 | 25 |
23 const SkColor kTrayBackgroundAlpha = 100; | 26 const SkColor kTrayBackgroundAlpha = 100; |
24 const SkColor kTrayBackgroundHoverAlpha = 150; | 27 const SkColor kTrayBackgroundHoverAlpha = 150; |
25 | 28 |
26 // Adjust the size of TrayContainer with additional padding. | 29 // Adjust the size of TrayContainer with additional padding. |
27 const int kTrayContainerVerticalPaddingBottomAlignment = 1; | 30 const int kTrayContainerVerticalPaddingBottomAlignment = 1; |
28 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 31 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
29 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 32 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
30 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; | 33 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; |
31 | 34 |
35 const int kAnimationDurationForPopupMS = 200; | |
36 | |
32 } // namespace | 37 } // namespace |
33 | 38 |
34 namespace ash { | 39 namespace ash { |
35 namespace internal { | 40 namespace internal { |
36 | 41 |
37 // Observe the tray layer animation and update the anchor when it changes. | 42 // Observe the tray layer animation and update the anchor when it changes. |
38 // TODO(stevenjb): Observe or mirror the actual animation, not just the start | 43 // TODO(stevenjb): Observe or mirror the actual animation, not just the start |
39 // and end points. | 44 // and end points. |
40 class TrayLayerAnimationObserver : public ui::LayerAnimationObserver { | 45 class TrayLayerAnimationObserver : public ui::LayerAnimationObserver { |
41 public: | 46 public: |
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
269 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, | 274 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, |
270 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 275 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
271 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); | 276 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); |
272 } else { | 277 } else { |
273 set_border(views::Border::CreateEmptyBorder( | 278 set_border(views::Border::CreateEmptyBorder( |
274 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | 279 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, |
275 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 280 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
276 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | 281 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); |
277 } | 282 } |
278 } | 283 } |
279 | 284 |
stevenjb
2012/10/11 17:15:15
Functionality moved from TrayBubbleView
| |
285 void TrayBackgroundView::InitializeBubbleAnimations( | |
286 views::Widget* bubble_widget) { | |
287 ash::SetWindowVisibilityAnimationType( | |
288 bubble_widget->GetNativeWindow(), | |
289 ash::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | |
290 ash::SetWindowVisibilityAnimationTransition( | |
291 bubble_widget->GetNativeWindow(), | |
292 ash::ANIMATE_BOTH); | |
293 ash::SetWindowVisibilityAnimationDuration( | |
294 bubble_widget->GetNativeWindow(), | |
295 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | |
296 } | |
297 | |
298 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | |
299 return ash::Shell::GetContainer( | |
300 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | |
301 ash::internal::kShellWindowId_SettingBubbleContainer); | |
302 } | |
303 | |
304 gfx::Rect TrayBackgroundView::GetAnchorRect( | |
305 views::Widget* anchor_widget, | |
306 TrayBubbleView::AnchorType anchor_type, | |
307 TrayBubbleView::AnchorAlignment anchor_alignment) const { | |
308 gfx::Rect rect; | |
309 if (anchor_widget && anchor_widget->IsVisible()) { | |
310 rect = anchor_widget->GetWindowBoundsInScreen(); | |
311 if (anchor_type == TrayBubbleView::ANCHOR_TYPE_TRAY) { | |
312 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | |
313 bool rtl = base::i18n::IsRTL(); | |
314 rect.Inset( | |
315 rtl ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0, | |
316 0, | |
317 rtl ? 0 : kPaddingFromRightEdgeOfScreenBottomAlignment, | |
318 kPaddingFromBottomOfScreenBottomAlignment); | |
319 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | |
320 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
321 kPaddingFromBottomOfScreenVerticalAlignment); | |
322 } else { | |
323 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
324 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
325 } | |
326 } else if (anchor_type == TrayBubbleView::ANCHOR_TYPE_BUBBLE) { | |
327 // Invert the offsets to align with the bubble below. | |
328 if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) { | |
329 rect.Inset(kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
330 0, 0, kPaddingFromBottomOfScreenVerticalAlignment); | |
331 } else if (anchor_alignment == TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT) { | |
332 rect.Inset(0, 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | |
333 kPaddingFromBottomOfScreenVerticalAlignment); | |
334 } | |
335 } | |
336 } | |
337 | |
338 // TODO(jennyz): May need to add left/right alignment in the following code. | |
339 if (rect.IsEmpty()) { | |
340 rect = gfx::Screen::GetPrimaryDisplay().bounds(); | |
341 rect = gfx::Rect( | |
342 base::i18n::IsRTL() ? kPaddingFromRightEdgeOfScreenBottomAlignment : | |
343 rect.width() - kPaddingFromRightEdgeOfScreenBottomAlignment, | |
344 rect.height() - kPaddingFromBottomOfScreenBottomAlignment, | |
345 0, 0); | |
346 } | |
347 return rect; | |
348 } | |
349 | |
350 TrayBubbleView::AnchorAlignment TrayBackgroundView::GetAnchorAlignment() const { | |
351 switch (shelf_alignment_) { | |
352 case SHELF_ALIGNMENT_BOTTOM: | |
353 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | |
354 case SHELF_ALIGNMENT_LEFT: | |
355 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; | |
356 case SHELF_ALIGNMENT_RIGHT: | |
357 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; | |
358 } | |
359 NOTREACHED(); | |
360 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | |
361 } | |
362 | |
280 } // namespace internal | 363 } // namespace internal |
281 } // namespace ash | 364 } // namespace ash |
OLD | NEW |