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 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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() { |
147 } | 176 } |
148 | 177 |
| 178 void TrayBackgroundView::Initialize() { |
| 179 layer_animation_observer_.reset(new TrayLayerAnimationObserver(this)); |
| 180 GetWidget()->GetNativeView()->layer()->GetAnimator()->AddObserver( |
| 181 layer_animation_observer_.get()); |
| 182 SetBorder(); |
| 183 } |
| 184 |
149 void TrayBackgroundView::OnMouseEntered(const views::MouseEvent& event) { | 185 void TrayBackgroundView::OnMouseEntered(const views::MouseEvent& event) { |
150 hover_background_animator_.SetPaintsBackground(true, | 186 hover_background_animator_.SetPaintsBackground(true, |
151 internal::BackgroundAnimator::CHANGE_ANIMATE); | 187 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 188 UpdateShouldShowLauncher(); |
152 } | 189 } |
153 | 190 |
154 void TrayBackgroundView::OnMouseExited(const views::MouseEvent& event) { | 191 void TrayBackgroundView::OnMouseExited(const views::MouseEvent& event) { |
155 hover_background_animator_.SetPaintsBackground(false, | 192 hover_background_animator_.SetPaintsBackground(false, |
156 internal::BackgroundAnimator::CHANGE_ANIMATE); | 193 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| 194 UpdateShouldShowLauncher(); |
157 } | 195 } |
158 | 196 |
159 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 197 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
160 PreferredSizeChanged(); | 198 PreferredSizeChanged(); |
161 } | 199 } |
162 | 200 |
| 201 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) { |
| 202 // The tray itself expands to the right and bottom edge of the screen to make |
| 203 // sure clicking on the edges brings up the popup. However, the focus border |
| 204 // should be only around the container. |
| 205 if (HasFocus() && (focusable() || IsAccessibilityFocusable())) |
| 206 DrawBorder(canvas, GetContentsBounds()); |
| 207 } |
| 208 |
| 209 void TrayBackgroundView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 210 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 211 state->name = GetAccessibleName(); |
| 212 } |
| 213 |
| 214 void TrayBackgroundView::AboutToRequestFocusFromTabTraversal(bool reverse) { |
| 215 // Return focus to the login view. See crbug.com/120500. |
| 216 views::View* v = GetNextFocusableView(); |
| 217 if (v) |
| 218 v->AboutToRequestFocusFromTabTraversal(reverse); |
| 219 } |
| 220 |
163 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 221 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
164 return false; | 222 return false; |
165 } | 223 } |
166 | 224 |
167 void TrayBackgroundView::UpdateBackground(int alpha) { | 225 void TrayBackgroundView::UpdateBackground(int alpha) { |
168 if (background_) { | 226 if (background_) { |
169 background_->set_alpha(hide_background_animator_.alpha() + | 227 background_->set_alpha(hide_background_animator_.alpha() + |
170 hover_background_animator_.alpha()); | 228 hover_background_animator_.alpha()); |
171 } | 229 } |
172 SchedulePaint(); | 230 SchedulePaint(); |
(...skipping 14 matching lines...) Expand all Loading... |
187 } | 245 } |
188 | 246 |
189 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 247 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
190 shelf_alignment_ = alignment; | 248 shelf_alignment_ = alignment; |
191 SetBorder(); | 249 SetBorder(); |
192 tray_container_->SetAlignment(alignment); | 250 tray_container_->SetAlignment(alignment); |
193 } | 251 } |
194 | 252 |
195 void TrayBackgroundView::SetBorder() { | 253 void TrayBackgroundView::SetBorder() { |
196 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 254 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
197 int child_count = parent->child_count(); | 255 // Tray views are laid out right-to-left or bottom-to-top |
198 DCHECK(child_count > 0); | 256 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. | 257 // Change the border padding for different shelf alignment. |
201 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { | 258 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) { |
202 set_border(views::Border::CreateEmptyBorder( | 259 set_border(views::Border::CreateEmptyBorder( |
203 0, 0, kPaddingFromBottomOfScreenBottomAlignment, | 260 0, 0, kPaddingFromBottomOfScreenBottomAlignment, |
204 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); | 261 on_edge ? kPaddingFromRightEdgeOfScreenBottomAlignment : 0)); |
205 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { | 262 } else if (shelf_alignment() == SHELF_ALIGNMENT_LEFT) { |
206 set_border(views::Border::CreateEmptyBorder( | 263 set_border(views::Border::CreateEmptyBorder( |
207 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, | 264 0, kPaddingFromOuterEdgeOfLauncherVerticalAlignment, |
208 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 265 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
209 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); | 266 kPaddingFromInnerEdgeOfLauncherVerticalAlignment)); |
210 } else { | 267 } else { |
211 set_border(views::Border::CreateEmptyBorder( | 268 set_border(views::Border::CreateEmptyBorder( |
212 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, | 269 0, kPaddingFromInnerEdgeOfLauncherVerticalAlignment, |
213 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, | 270 on_edge ? kPaddingFromBottomOfScreenVerticalAlignment : 0, |
214 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); | 271 kPaddingFromOuterEdgeOfLauncherVerticalAlignment)); |
215 } | 272 } |
216 } | 273 } |
217 | 274 |
| 275 void TrayBackgroundView::UpdateShouldShowLauncher() { |
| 276 status_area_widget()->UpdateShouldShowLauncher(); |
| 277 } |
| 278 |
218 } // namespace internal | 279 } // namespace internal |
219 } // namespace ash | 280 } // namespace ash |
OLD | NEW |