| 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/status_area_widget_delegate.h" | 5 #include "ash/system/status_area_widget_delegate.h" |
| 6 | 6 |
| 7 #include "ash/ash_export.h" | 7 #include "ash/ash_export.h" |
| 8 #include "ash/ash_switches.h" | 8 #include "ash/ash_switches.h" |
| 9 #include "ash/focus_cycler.h" | 9 #include "ash/focus_cycler.h" |
| 10 #include "ash/shell.h" | 10 #include "ash/shell.h" |
| 11 #include "ash/shell_window_ids.h" | 11 #include "ash/shell_window_ids.h" |
| 12 #include "ash/system/tray/tray_constants.h" | 12 #include "ash/system/tray/tray_constants.h" |
| 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 14 #include "ui/aura/window_event_dispatcher.h" | 15 #include "ui/aura/window_event_dispatcher.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 16 #include "ui/base/resource/resource_bundle.h" |
| 17 #include "ui/compositor/layer.h" |
| 18 #include "ui/compositor/scoped_layer_animation_settings.h" |
| 19 #include "ui/gfx/animation/tween.h" |
| 16 #include "ui/gfx/canvas.h" | 20 #include "ui/gfx/canvas.h" |
| 17 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 18 #include "ui/views/accessible_pane_view.h" | 22 #include "ui/views/accessible_pane_view.h" |
| 19 #include "ui/views/layout/grid_layout.h" | 23 #include "ui/views/layout/grid_layout.h" |
| 20 #include "ui/views/widget/widget.h" | 24 #include "ui/views/widget/widget.h" |
| 21 | 25 |
| 26 namespace { |
| 27 |
| 28 const int kAnimationDurationMs = 250; |
| 29 |
| 30 class StatusAreaWidgetDelegateAnimationSettings |
| 31 : public ui::ScopedLayerAnimationSettings { |
| 32 public: |
| 33 explicit StatusAreaWidgetDelegateAnimationSettings(ui::Layer* layer) |
| 34 : ui::ScopedLayerAnimationSettings(layer->GetAnimator()) { |
| 35 SetTransitionDuration( |
| 36 base::TimeDelta::FromMilliseconds(kAnimationDurationMs)); |
| 37 SetPreemptionStrategy( |
| 38 ui::LayerAnimator::IMMEDIATELY_ANIMATE_TO_NEW_TARGET); |
| 39 SetTweenType(gfx::Tween::EASE_IN_OUT); |
| 40 } |
| 41 |
| 42 virtual ~StatusAreaWidgetDelegateAnimationSettings() {} |
| 43 |
| 44 private: |
| 45 DISALLOW_COPY_AND_ASSIGN(StatusAreaWidgetDelegateAnimationSettings); |
| 46 }; |
| 47 |
| 48 } // namespace |
| 49 |
| 22 namespace ash { | 50 namespace ash { |
| 23 | 51 |
| 24 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() | 52 StatusAreaWidgetDelegate::StatusAreaWidgetDelegate() |
| 25 : focus_cycler_for_testing_(NULL), | 53 : focus_cycler_for_testing_(NULL), |
| 26 alignment_(SHELF_ALIGNMENT_BOTTOM) { | 54 alignment_(SHELF_ALIGNMENT_BOTTOM) { |
| 27 // Allow the launcher to surrender the focus to another window upon | 55 // Allow the launcher to surrender the focus to another window upon |
| 28 // navigation completion by the user. | 56 // navigation completion by the user. |
| 29 set_allow_deactivate_on_esc(true); | 57 set_allow_deactivate_on_esc(true); |
| 58 SetPaintToLayer(true); |
| 59 SetFillsBoundsOpaquely(false); |
| 30 } | 60 } |
| 31 | 61 |
| 32 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { | 62 StatusAreaWidgetDelegate::~StatusAreaWidgetDelegate() { |
| 33 } | 63 } |
| 34 | 64 |
| 35 void StatusAreaWidgetDelegate::SetFocusCyclerForTesting( | 65 void StatusAreaWidgetDelegate::SetFocusCyclerForTesting( |
| 36 const FocusCycler* focus_cycler) { | 66 const FocusCycler* focus_cycler) { |
| 37 focus_cycler_for_testing_ = focus_cycler; | 67 focus_cycler_for_testing_ = focus_cycler; |
| 38 } | 68 } |
| 39 | 69 |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 110 views::View* child = child_at(c); | 140 views::View* child = child_at(c); |
| 111 if (!child->visible()) | 141 if (!child->visible()) |
| 112 continue; | 142 continue; |
| 113 if (!is_first_visible_child) | 143 if (!is_first_visible_child) |
| 114 layout->AddPaddingRow(0, kTraySpacing); | 144 layout->AddPaddingRow(0, kTraySpacing); |
| 115 is_first_visible_child = false; | 145 is_first_visible_child = false; |
| 116 layout->StartRow(0, 0); | 146 layout->StartRow(0, 0); |
| 117 layout->AddView(child); | 147 layout->AddView(child); |
| 118 } | 148 } |
| 119 } | 149 } |
| 150 |
| 151 layer()->GetAnimator()->StopAnimating(); |
| 152 StatusAreaWidgetDelegateAnimationSettings settings(layer()); |
| 153 |
| 120 Layout(); | 154 Layout(); |
| 121 UpdateWidgetSize(); | 155 UpdateWidgetSize(); |
| 122 } | 156 } |
| 123 | 157 |
| 124 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { | 158 void StatusAreaWidgetDelegate::ChildPreferredSizeChanged(View* child) { |
| 125 // Need to resize the window when trays or items are added/removed. | 159 // Need to resize the window when trays or items are added/removed. |
| 160 StatusAreaWidgetDelegateAnimationSettings settings(layer()); |
| 126 UpdateWidgetSize(); | 161 UpdateWidgetSize(); |
| 127 } | 162 } |
| 128 | 163 |
| 129 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { | 164 void StatusAreaWidgetDelegate::ChildVisibilityChanged(View* child) { |
| 130 UpdateLayout(); | 165 UpdateLayout(); |
| 131 } | 166 } |
| 132 | 167 |
| 133 void StatusAreaWidgetDelegate::UpdateWidgetSize() { | 168 void StatusAreaWidgetDelegate::UpdateWidgetSize() { |
| 134 if (GetWidget()) | 169 if (GetWidget()) |
| 135 GetWidget()->SetSize(GetPreferredSize()); | 170 GetWidget()->SetSize(GetPreferredSize()); |
| 136 } | 171 } |
| 137 | 172 |
| 138 } // namespace ash | 173 } // namespace ash |
| OLD | NEW |