| 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/system_tray_bubble.h" | 5 #include "ash/system/tray/system_tray_bubble.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
| 9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
| 10 #include "ash/system/tray/system_tray_item.h" | 10 #include "ash/system/tray/system_tray_item.h" |
| 11 #include "ash/system/tray/tray_bubble_wrapper.h" | 11 #include "ash/system/tray/tray_bubble_wrapper.h" |
| 12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
| 13 #include "ash/system/tray/tray_popup_item_container.h" |
| 13 #include "base/message_loop/message_loop.h" | 14 #include "base/message_loop/message_loop.h" |
| 14 #include "ui/aura/window.h" | 15 #include "ui/aura/window.h" |
| 15 #include "ui/compositor/layer.h" | 16 #include "ui/compositor/layer.h" |
| 16 #include "ui/compositor/layer_animation_observer.h" | 17 #include "ui/compositor/layer_animation_observer.h" |
| 17 #include "ui/compositor/scoped_layer_animation_settings.h" | 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 18 #include "ui/gfx/canvas.h" | 19 #include "ui/gfx/canvas.h" |
| 19 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/box_layout.h" |
| 20 #include "ui/views/view.h" | 21 #include "ui/views/view.h" |
| 21 #include "ui/views/widget/widget.h" | 22 #include "ui/views/widget/widget.h" |
| 22 | 23 |
| 23 using views::TrayBubbleView; | 24 using views::TrayBubbleView; |
| 24 | 25 |
| 25 namespace ash { | 26 namespace ash { |
| 26 | 27 |
| 27 namespace { | 28 namespace { |
| 28 | 29 |
| 29 // Normally a detailed view is the same size as the default view. However, | 30 // Normally a detailed view is the same size as the default view. However, |
| 30 // when showing a detailed view directly (e.g. clicking on a notification), | 31 // when showing a detailed view directly (e.g. clicking on a notification), |
| 31 // we may not know the height of the default view, or the default view may | 32 // we may not know the height of the default view, or the default view may |
| 32 // be too short, so we use this as a default and minimum height for any | 33 // be too short, so we use this as a default and minimum height for any |
| 33 // detailed view. | 34 // detailed view. |
| 34 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; | 35 const int kDetailedBubbleMaxHeight = kTrayPopupItemHeight * 5; |
| 35 | 36 |
| 36 // Duration of swipe animation used when transitioning from a default to | 37 // Duration of swipe animation used when transitioning from a default to |
| 37 // detailed view or vice versa. | 38 // detailed view or vice versa. |
| 38 const int kSwipeDelayMS = 150; | 39 const int kSwipeDelayMS = 150; |
| 39 | 40 |
| 40 // A view with some special behaviour for tray items in the popup: | |
| 41 // - optionally changes background color on hover. | |
| 42 class TrayPopupItemContainer : public views::View { | |
| 43 public: | |
| 44 TrayPopupItemContainer(views::View* view, | |
| 45 bool change_background, | |
| 46 bool draw_border) | |
| 47 : hover_(false), | |
| 48 change_background_(change_background) { | |
| 49 set_notify_enter_exit_on_child(true); | |
| 50 if (draw_border) { | |
| 51 SetBorder( | |
| 52 views::Border::CreateSolidSidedBorder(0, 0, 1, 0, kBorderLightColor)); | |
| 53 } | |
| 54 views::BoxLayout* layout = new views::BoxLayout( | |
| 55 views::BoxLayout::kVertical, 0, 0, 0); | |
| 56 layout->SetDefaultFlex(1); | |
| 57 SetLayoutManager(layout); | |
| 58 SetPaintToLayer(view->layer() != NULL); | |
| 59 if (view->layer()) | |
| 60 SetFillsBoundsOpaquely(view->layer()->fills_bounds_opaquely()); | |
| 61 AddChildView(view); | |
| 62 SetVisible(view->visible()); | |
| 63 } | |
| 64 | |
| 65 virtual ~TrayPopupItemContainer() {} | |
| 66 | |
| 67 private: | |
| 68 // Overridden from views::View. | |
| 69 virtual void ChildVisibilityChanged(View* child) override { | |
| 70 if (visible() == child->visible()) | |
| 71 return; | |
| 72 SetVisible(child->visible()); | |
| 73 PreferredSizeChanged(); | |
| 74 } | |
| 75 | |
| 76 virtual void ChildPreferredSizeChanged(View* child) override { | |
| 77 PreferredSizeChanged(); | |
| 78 } | |
| 79 | |
| 80 virtual void OnMouseEntered(const ui::MouseEvent& event) override { | |
| 81 hover_ = true; | |
| 82 SchedulePaint(); | |
| 83 } | |
| 84 | |
| 85 virtual void OnMouseExited(const ui::MouseEvent& event) override { | |
| 86 hover_ = false; | |
| 87 SchedulePaint(); | |
| 88 } | |
| 89 | |
| 90 virtual void OnPaintBackground(gfx::Canvas* canvas) override { | |
| 91 if (child_count() == 0) | |
| 92 return; | |
| 93 | |
| 94 views::View* view = child_at(0); | |
| 95 if (!view->background()) { | |
| 96 canvas->FillRect(gfx::Rect(size()), (hover_ && change_background_) ? | |
| 97 kHoverBackgroundColor : kBackgroundColor); | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 bool hover_; | |
| 102 bool change_background_; | |
| 103 | |
| 104 DISALLOW_COPY_AND_ASSIGN(TrayPopupItemContainer); | |
| 105 }; | |
| 106 | |
| 107 // Implicit animation observer that deletes itself and the layer at the end of | 41 // Implicit animation observer that deletes itself and the layer at the end of |
| 108 // the animation. | 42 // the animation. |
| 109 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { | 43 class AnimationObserverDeleteLayer : public ui::ImplicitAnimationObserver { |
| 110 public: | 44 public: |
| 111 explicit AnimationObserverDeleteLayer(ui::Layer* layer) | 45 explicit AnimationObserverDeleteLayer(ui::Layer* layer) |
| 112 : layer_(layer) { | 46 : layer_(layer) { |
| 113 } | 47 } |
| 114 | 48 |
| 115 virtual ~AnimationObserverDeleteLayer() { | 49 virtual ~AnimationObserverDeleteLayer() { |
| 116 } | 50 } |
| (...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 383 // 2 items, which are the bottom header row and the one just above it. | 317 // 2 items, which are the bottom header row and the one just above it. |
| 384 bubble_view_->AddChildView(new TrayPopupItemContainer( | 318 bubble_view_->AddChildView(new TrayPopupItemContainer( |
| 385 item_views[i], is_default_bubble, | 319 item_views[i], is_default_bubble, |
| 386 is_default_bubble && (i < item_views.size() - 2))); | 320 is_default_bubble && (i < item_views.size() - 2))); |
| 387 } | 321 } |
| 388 if (focus_view) | 322 if (focus_view) |
| 389 focus_view->RequestFocus(); | 323 focus_view->RequestFocus(); |
| 390 } | 324 } |
| 391 | 325 |
| 392 } // namespace ash | 326 } // namespace ash |
| OLD | NEW |