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/base/accessibility/accessible_view_state.h" |
| 15 #include "ui/compositor/layer_animation_observer.h" |
14 #include "ui/gfx/canvas.h" | 16 #include "ui/gfx/canvas.h" |
15 #include "ui/gfx/skia_util.h" | 17 #include "ui/gfx/skia_util.h" |
16 #include "ui/views/background.h" | 18 #include "ui/views/background.h" |
17 #include "ui/views/layout/box_layout.h" | 19 #include "ui/views/layout/box_layout.h" |
18 | 20 |
19 namespace { | 21 namespace { |
20 | 22 |
21 const SkColor kTrayBackgroundAlpha = 100; | 23 const SkColor kTrayBackgroundAlpha = 100; |
22 const SkColor kTrayBackgroundHoverAlpha = 150; | 24 const SkColor kTrayBackgroundHoverAlpha = 150; |
23 | 25 |
24 // Adjust the size of TrayContainer with additional padding. | 26 // Adjust the size of TrayContainer with additional padding. |
25 const int kTrayContainerVerticalPaddingBottomAlignment = 1; | 27 const int kTrayContainerVerticalPaddingBottomAlignment = 1; |
26 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 28 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
27 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 29 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
28 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; | 30 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; |
29 | 31 |
30 } // namespace | 32 } // namespace |
31 | 33 |
32 namespace ash { | 34 namespace ash { |
33 namespace internal { | 35 namespace internal { |
34 | 36 |
| 37 // 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 |
| 39 // and end points. |
| 40 class TrayLayerAnimationObserver : public ui::LayerAnimationObserver { |
| 41 public: |
| 42 explicit TrayLayerAnimationObserver(TrayBackgroundView* host) |
| 43 : host_(host) { |
| 44 } |
| 45 |
| 46 virtual void OnLayerAnimationEnded(ui::LayerAnimationSequence* sequence) { |
| 47 host_->AnchorUpdated(); |
| 48 } |
| 49 |
| 50 virtual void OnLayerAnimationAborted(ui::LayerAnimationSequence* sequence) { |
| 51 host_->AnchorUpdated(); |
| 52 } |
| 53 |
| 54 virtual void OnLayerAnimationScheduled(ui::LayerAnimationSequence* sequence) { |
| 55 host_->AnchorUpdated(); |
| 56 } |
| 57 |
| 58 private: |
| 59 TrayBackgroundView* host_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(TrayLayerAnimationObserver); |
| 62 }; |
| 63 |
35 class TrayBackground : public views::Background { | 64 class TrayBackground : public views::Background { |
36 public: | 65 public: |
37 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} | 66 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} |
38 virtual ~TrayBackground() {} | 67 virtual ~TrayBackground() {} |
39 | 68 |
40 void set_alpha(int alpha) { alpha_ = alpha; } | 69 void set_alpha(int alpha) { alpha_ = alpha; } |
41 | 70 |
42 private: | 71 private: |
43 // Overridden from views::Background. | 72 // Overridden from views::Background. |
44 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 73 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 // Initially we want to paint the background, but without the hover effect. | 166 // Initially we want to paint the background, but without the hover effect. |
138 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 167 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
139 hover_background_animator_.SetPaintsBackground(false, | 168 hover_background_animator_.SetPaintsBackground(false, |
140 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 169 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
141 | 170 |
142 tray_container_ = new TrayContainer(shelf_alignment_); | 171 tray_container_ = new TrayContainer(shelf_alignment_); |
143 SetContents(tray_container_); | 172 SetContents(tray_container_); |
144 } | 173 } |
145 | 174 |
146 TrayBackgroundView::~TrayBackgroundView() { | 175 TrayBackgroundView::~TrayBackgroundView() { |
| 176 GetWidget()->GetNativeView()->layer()->GetAnimator()->RemoveObserver( |
| 177 layer_animation_observer_.get()); |
| 178 } |
| 179 |
| 180 void TrayBackgroundView::Initialize() { |
| 181 layer_animation_observer_.reset(new TrayLayerAnimationObserver(this)); |
| 182 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver( |
| 183 layer_animation_observer_.get()); |
| 184 SetBorder(); |
147 } | 185 } |
148 | 186 |
149 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 187 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
150 hover_background_animator_.SetPaintsBackground(true, | 188 hover_background_animator_.SetPaintsBackground(true, |
151 internal::BackgroundAnimator::CHANGE_ANIMATE); | 189 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 190 UpdateShouldShowLauncher(); |
152 } | 191 } |
153 | 192 |
154 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 193 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
155 hover_background_animator_.SetPaintsBackground(false, | 194 hover_background_animator_.SetPaintsBackground(false, |
156 internal::BackgroundAnimator::CHANGE_ANIMATE); | 195 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 196 UpdateShouldShowLauncher(); |
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 (HasFocus() && (focusable() || IsAccessibilityFocusable())) |
| 208 DrawBorder(canvas, GetContentsBounds()); |
| 209 } |
| 210 |
| 211 void TrayBackgroundView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 212 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 213 state->name = GetAccessibleName(); |
| 214 } |
| 215 |
| 216 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 217 // Return focus to the login view. See crbug.com/120500. |
| 218 views::View* v = GetNextFocusableView(); |
| 219 if (v) |
| 220 v->AboutToRequestFocusFromTabTraversal(reverse); |
| 221 } |
| 222 |
163 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 223 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
164 return false; | 224 return false; |
165 } | 225 } |
166 | 226 |
167 void TrayBackgroundView::UpdateBackground(int alpha) { | 227 void TrayBackgroundView::UpdateBackground(int alpha) { |
168 if (background_) { | 228 if (background_) { |
169 background_->set_alpha(hide_background_animator_.alpha() + | 229 background_->set_alpha(hide_background_animator_.alpha() + |
170 hover_background_animator_.alpha()); | 230 hover_background_animator_.alpha()); |
171 } | 231 } |
172 SchedulePaint(); | 232 SchedulePaint(); |
(...skipping 14 matching lines...) Expand all Loading... |
187 } | 247 } |
188 | 248 |
189 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 249 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
190 shelf_alignment_ = alignment; | 250 shelf_alignment_ = alignment; |
191 SetBorder(); | 251 SetBorder(); |
192 tray_container_->SetAlignment(alignment); | 252 tray_container_->SetAlignment(alignment); |
193 } | 253 } |
194 | 254 |
195 void TrayBackgroundView::SetBorder() { | 255 void TrayBackgroundView::SetBorder() { |
196 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 256 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
197 int child_count = parent->child_count(); | 257 // Tray views are laid out right-to-left or bottom-to-top |
198 DCHECK(child_count > 0); | 258 int on_edge = (this == parent->child_at(0)); |
199 int on_edge = (this == parent->child_at(child_count-1)); | |
200 // Change the border padding for different shelf alignment. | 259 // Change the border padding for different shelf alignment. |
201 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 260 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
202 set_border(views::Border::CreateEmptyBorder( | 261 set_border(views::Border::CreateEmptyBorder( |
203 0, 0, kPaddingFromBottomOfScreenBottomAlignment, | 262 0, 0, kPaddingFromBottomOfScreenBottomAlignment, |
204 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); | 263 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); |
205 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 264 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
206 set_border(views::Border::CreateEmptyBorder( | 265 set_border(views::Border::CreateEmptyBorder( |
207 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, | 266 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, |
208 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 267 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
209 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); | 268 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); |
210 } else { | 269 } else { |
211 set_border(views::Border::CreateEmptyBorder( | 270 set_border(views::Border::CreateEmptyBorder( |
212 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | 271 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, |
213 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 272 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
214 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | 273 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); |
215 } | 274 } |
216 } | 275 } |
217 | 276 |
| 277 void TrayBackgroundView::UpdateShouldShowLauncher() { |
| 278 status_area_widget()->UpdateShouldShowLauncher(); |
| 279 } |
| 280 |
218 } // namespace internal | 281 } // namespace internal |
219 } // namespace ash | 282 } // namespace ash |
OLD | NEW |