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 "ui/aura/window.h" | 13 #include "ui/aura/window.h" |
| 14 #include "ui/compositor/layer_animation_observer.h" |
14 #include "ui/gfx/canvas.h" | 15 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/skia_util.h" | 16 #include "ui/gfx/skia_util.h" |
16 #include "ui/views/background.h" | 17 #include "ui/views/background.h" |
17 #include "ui/views/layout/box_layout.h" | 18 #include "ui/views/layout/box_layout.h" |
18 | 19 |
19 namespace { | 20 namespace { |
20 | 21 |
21 const SkColor kTrayBackgroundAlpha = 100; | 22 const SkColor kTrayBackgroundAlpha = 100; |
22 const SkColor kTrayBackgroundHoverAlpha = 150; | 23 const SkColor kTrayBackgroundHoverAlpha = 150; |
23 | 24 |
24 // Adjust the size of TrayContainer with additional padding. | 25 // Adjust the size of TrayContainer with additional padding. |
25 const int kTrayContainerVerticalPaddingBottomAlignment = 1; | 26 const int kTrayContainerVerticalPaddingBottomAlignment = 1; |
26 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 27 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
27 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 28 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
28 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; | 29 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; |
29 | 30 |
30 } // namespace | 31 } // namespace |
31 | 32 |
32 namespace ash { | 33 namespace ash { |
33 namespace internal { | 34 namespace internal { |
34 | 35 |
| 36 // Observe the tray layer animation and update the anchor when it changes. |
| 37 // TODO(stevenjb): Observe or mirror the actual animation, not just the start |
| 38 // and end points. |
| 39 class TrayLayerAnimationObserver : public ui::LayerAnimationObserver { |
| 40 public: |
| 41 explicit TrayLayerAnimationObserver(TrayBackgroundView* host) |
| 42 : host_(host) { |
| 43 } |
| 44 |
| 45 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| 46 host_->AnchorUpdated(); |
| 47 } |
| 48 |
| 49 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) { |
| 50 host_->AnchorUpdated(); |
| 51 } |
| 52 |
| 53 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) { |
| 54 host_->AnchorUpdated(); |
| 55 } |
| 56 |
| 57 private: |
| 58 TrayBackgroundView* host_; |
| 59 |
| 60 DISALLOW_COPY_AND_ASSIGN(TrayLayerAnimationObserver); |
| 61 }; |
| 62 |
35 class TrayBackground : public views::Background { | 63 class TrayBackground : public views::Background { |
36 public: | 64 public: |
37 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} | 65 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} |
38 virtual ~TrayBackground() {} | 66 virtual ~TrayBackground() {} |
39 | 67 |
40 void set_alpha(int alpha) { alpha_ = alpha; } | 68 void set_alpha(int alpha) { alpha_ = alpha; } |
41 | 69 |
42 private: | 70 private: |
43 // Overridden from views::Background. | 71 // Overridden from views::Background. |
44 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 72 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 | 152 |
125 TrayBackgroundView::TrayBackgroundView( | 153 TrayBackgroundView::TrayBackgroundView( |
126 internal::StatusAreaWidget* status_area_widget) | 154 internal::StatusAreaWidget* status_area_widget) |
127 : status_area_widget_(status_area_widget), | 155 : status_area_widget_(status_area_widget), |
128 tray_container_(NULL), | 156 tray_container_(NULL), |
129 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 157 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
130 background_(NULL), | 158 background_(NULL), |
131 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( | 159 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( |
132 this, 0, kTrayBackgroundAlpha)), | 160 this, 0, kTrayBackgroundAlpha)), |
133 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( | 161 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( |
134 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 162 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)), |
| 163 ALLOW_THIS_IN_INITIALIZER_LIST(layer_animation_observer_( |
| 164 new TrayLayerAnimationObserver(this))) { |
135 set_notify_enter_exit_on_child(true); | 165 set_notify_enter_exit_on_child(true); |
136 | 166 |
137 // Initially we want to paint the background, but without the hover effect. | 167 // Initially we want to paint the background, but without the hover effect. |
138 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 168 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
139 hover_background_animator_.SetPaintsBackground(false, | 169 hover_background_animator_.SetPaintsBackground(false, |
140 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 170 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
141 | 171 |
142 tray_container_ = new TrayContainer(shelf_alignment_); | 172 tray_container_ = new TrayContainer(shelf_alignment_); |
143 SetContents(tray_container_); | 173 SetContents(tray_container_); |
144 } | 174 } |
145 | 175 |
146 TrayBackgroundView::~TrayBackgroundView() { | 176 TrayBackgroundView::~TrayBackgroundView() { |
| 177 if (GetWidget()) { |
| 178 GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver( |
| 179 layer_animation_observer_.get()); |
| 180 } |
| 181 } |
| 182 |
| 183 void TrayBackgroundView::Initialize() { |
| 184 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver( |
| 185 layer_animation_observer_.get()); |
| 186 SetBorder(); |
147 } | 187 } |
148 | 188 |
149 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 189 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
150 hover_background_animator_.SetPaintsBackground(true, | 190 hover_background_animator_.SetPaintsBackground(true, |
151 internal::BackgroundAnimator::CHANGE_ANIMATE); | 191 internal::BackgroundAnimator::CHANGE_ANIMATE); |
152 } | 192 } |
153 | 193 |
154 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 194 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
155 hover_background_animator_.SetPaintsBackground(false, | 195 hover_background_animator_.SetPaintsBackground(false, |
156 internal::BackgroundAnimator::CHANGE_ANIMATE); | 196 internal::BackgroundAnimator::CHANGE_ANIMATE); |
157 } | 197 } |
158 | 198 |
159 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 199 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
160 PreferredSizeChanged(); | 200 PreferredSizeChanged(); |
161 } | 201 } |
162 | 202 |
| 203 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 204 // The tray itself expands to the right and bottom edge of the screen to make |
| 205 // sure clicking on the edges brings up the popup. However, the focus border |
| 206 // should be only around the container. |
| 207 if (GetWidget() && GetWidget()->IsActive()) |
| 208 DrawBorder(canvas, GetContentsBounds()); |
| 209 } |
| 210 |
| 211 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 212 // Return focus to the login view. See crbug.com/120500. |
| 213 views::View* v = GetNextFocusableView(); |
| 214 if (v) |
| 215 v->AboutToRequestFocusFromTabTraversal(reverse); |
| 216 } |
| 217 |
163 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 218 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
164 return false; | 219 return false; |
165 } | 220 } |
166 | 221 |
167 void TrayBackgroundView::UpdateBackground(int alpha) { | 222 void TrayBackgroundView::UpdateBackground(int alpha) { |
168 if (background_) { | 223 if (background_) { |
169 background_->set_alpha(hide_background_animator_.alpha() + | 224 background_->set_alpha(hide_background_animator_.alpha() + |
170 hover_background_animator_.alpha()); | 225 hover_background_animator_.alpha()); |
171 } | 226 } |
172 SchedulePaint(); | 227 SchedulePaint(); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
210 } else { | 265 } else { |
211 set_border(views::Border::CreateEmptyBorder( | 266 set_border(views::Border::CreateEmptyBorder( |
212 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | 267 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, |
213 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 268 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
214 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | 269 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); |
215 } | 270 } |
216 } | 271 } |
217 | 272 |
218 } // namespace internal | 273 } // namespace internal |
219 } // namespace ash | 274 } // namespace ash |
OLD | NEW |