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" | |
8 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
9 #include "ash/screen_ash.h" | 8 #include "ash/screen_ash.h" |
| 9 #include "ash/shelf/shelf_layout_manager.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/status_area_widget.h" | 12 #include "ash/system/status_area_widget.h" |
13 #include "ash/system/status_area_widget_delegate.h" | 13 #include "ash/system/status_area_widget_delegate.h" |
14 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
15 #include "ash/system/tray/tray_event_filter.h" | 15 #include "ash/system/tray/tray_event_filter.h" |
16 #include "ash/wm/property_util.h" | 16 #include "ash/wm/property_util.h" |
17 #include "ash/wm/shelf_layout_manager.h" | |
18 #include "ash/wm/window_animations.h" | 17 #include "ash/wm/window_animations.h" |
19 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
20 #include "ui/aura/window.h" | 19 #include "ui/aura/window.h" |
21 #include "ui/base/accessibility/accessible_view_state.h" | 20 #include "ui/base/accessibility/accessible_view_state.h" |
22 #include "ui/gfx/canvas.h" | 21 #include "ui/gfx/canvas.h" |
23 #include "ui/gfx/rect.h" | 22 #include "ui/gfx/rect.h" |
24 #include "ui/gfx/screen.h" | 23 #include "ui/gfx/screen.h" |
25 #include "ui/gfx/skia_util.h" | 24 #include "ui/gfx/skia_util.h" |
26 #include "ui/views/background.h" | 25 #include "ui/views/background.h" |
27 #include "ui/views/layout/box_layout.h" | 26 #include "ui/views/layout/box_layout.h" |
28 | 27 |
29 namespace { | 28 namespace { |
30 | |
31 const SkColor kTrayBackgroundAlpha = 100; | |
32 const SkColor kTrayBackgroundHoverAlpha = 150; | 29 const SkColor kTrayBackgroundHoverAlpha = 150; |
33 | 30 |
34 // Adjust the size of TrayContainer with additional padding. | 31 // Adjust the size of TrayContainer with additional padding. |
35 const int kTrayContainerVerticalPaddingBottomAlignment = 1; | 32 const int kTrayContainerVerticalPaddingBottomAlignment = 1; |
36 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; | 33 const int kTrayContainerHorizontalPaddingBottomAlignment = 1; |
37 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; | 34 const int kTrayContainerVerticalPaddingVerticalAlignment = 1; |
38 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; | 35 const int kTrayContainerHorizontalPaddingVerticalAlignment = 1; |
39 | 36 |
40 const int kAnimationDurationForPopupMS = 200; | 37 const int kAnimationDurationForPopupMS = 200; |
41 | 38 |
(...skipping 23 matching lines...) Expand all Loading... |
65 } | 62 } |
66 | 63 |
67 private: | 64 private: |
68 TrayBackgroundView* host_; | 65 TrayBackgroundView* host_; |
69 | 66 |
70 DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver); | 67 DISALLOW_COPY_AND_ASSIGN(TrayWidgetObserver); |
71 }; | 68 }; |
72 | 69 |
73 class TrayBackground : public views::Background { | 70 class TrayBackground : public views::Background { |
74 public: | 71 public: |
75 TrayBackground() : alpha_(kTrayBackgroundAlpha) {} | 72 TrayBackground() : alpha_(0) {} |
76 virtual ~TrayBackground() {} | 73 virtual ~TrayBackground() {} |
77 | 74 |
78 void set_alpha(int alpha) { alpha_ = alpha; } | 75 void set_alpha(int alpha) { alpha_ = alpha; } |
79 | 76 |
80 private: | 77 private: |
81 // Overridden from views::Background. | 78 // Overridden from views::Background. |
82 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { | 79 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { |
83 SkPaint paint; | 80 SkPaint paint; |
84 paint.setAntiAlias(true); | 81 paint.setAntiAlias(true); |
85 paint.setStyle(SkPaint::kFill_Style); | 82 paint.setStyle(SkPaint::kFill_Style); |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 | 157 |
161 //////////////////////////////////////////////////////////////////////////////// | 158 //////////////////////////////////////////////////////////////////////////////// |
162 // TrayBackgroundView | 159 // TrayBackgroundView |
163 | 160 |
164 TrayBackgroundView::TrayBackgroundView( | 161 TrayBackgroundView::TrayBackgroundView( |
165 internal::StatusAreaWidget* status_area_widget) | 162 internal::StatusAreaWidget* status_area_widget) |
166 : status_area_widget_(status_area_widget), | 163 : status_area_widget_(status_area_widget), |
167 tray_container_(NULL), | 164 tray_container_(NULL), |
168 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 165 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
169 background_(NULL), | 166 background_(NULL), |
170 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_( | |
171 this, 0, kTrayBackgroundAlpha)), | |
172 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( | 167 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_( |
173 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)), | 168 this, 0, kTrayBackgroundHoverAlpha)), |
174 ALLOW_THIS_IN_INITIALIZER_LIST(widget_observer_( | 169 ALLOW_THIS_IN_INITIALIZER_LIST(widget_observer_( |
175 new TrayWidgetObserver(this))) { | 170 new TrayWidgetObserver(this))) { |
176 set_notify_enter_exit_on_child(true); | 171 set_notify_enter_exit_on_child(true); |
177 | 172 |
178 // Initially we want to paint the background, but without the hover effect. | 173 // Initially we want to paint the background, but without the hover effect. |
179 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | |
180 hover_background_animator_.SetPaintsBackground(false, | 174 hover_background_animator_.SetPaintsBackground(false, |
181 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 175 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
182 | 176 |
183 tray_container_ = new TrayContainer(shelf_alignment_); | 177 tray_container_ = new TrayContainer(shelf_alignment_); |
184 SetContents(tray_container_); | 178 SetContents(tray_container_); |
185 tray_event_filter_.reset(new TrayEventFilter); | 179 tray_event_filter_.reset(new TrayEventFilter); |
186 } | 180 } |
187 | 181 |
188 TrayBackgroundView::~TrayBackgroundView() { | 182 TrayBackgroundView::~TrayBackgroundView() { |
189 if (GetWidget()) | 183 if (GetWidget()) |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
228 if (v) | 222 if (v) |
229 v->AboutToRequestFocusFromTabTraversal(reverse); | 223 v->AboutToRequestFocusFromTabTraversal(reverse); |
230 } | 224 } |
231 | 225 |
232 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 226 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
233 return false; | 227 return false; |
234 } | 228 } |
235 | 229 |
236 void TrayBackgroundView::UpdateBackground(int alpha) { | 230 void TrayBackgroundView::UpdateBackground(int alpha) { |
237 if (background_) { | 231 if (background_) { |
238 background_->set_alpha(hide_background_animator_.alpha() + | 232 background_->set_alpha(hover_background_animator_.alpha()); |
239 hover_background_animator_.alpha()); | |
240 } | 233 } |
241 SchedulePaint(); | 234 SchedulePaint(); |
242 } | 235 } |
243 | 236 |
244 void TrayBackgroundView::SetContents(views::View* contents) { | 237 void TrayBackgroundView::SetContents(views::View* contents) { |
245 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 238 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
246 AddChildView(contents); | 239 AddChildView(contents); |
247 } | 240 } |
248 | 241 |
249 void TrayBackgroundView::SetContentsBackground() { | 242 void TrayBackgroundView::SetContentsBackground() { |
250 background_ = new internal::TrayBackground; | 243 background_ = new internal::TrayBackground; |
251 tray_container_->set_background(background_); | 244 tray_container_->set_background(background_); |
252 } | 245 } |
253 | 246 |
254 void TrayBackgroundView::SetPaintsBackground( | |
255 bool value, | |
256 internal::BackgroundAnimator::ChangeType change_type) { | |
257 hide_background_animator_.SetPaintsBackground(value, change_type); | |
258 } | |
259 | |
260 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { | 247 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { |
261 return | 248 return ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); |
262 RootWindowController::ForLauncher(GetWidget()->GetNativeView())->shelf(); | |
263 } | 249 } |
264 | 250 |
265 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { | 251 void TrayBackgroundView::SetShelfAlignment(ShelfAlignment alignment) { |
266 shelf_alignment_ = alignment; | 252 shelf_alignment_ = alignment; |
267 SetBorder(); | 253 SetBorder(); |
268 tray_container_->SetAlignment(alignment); | 254 tray_container_->SetAlignment(alignment); |
269 } | 255 } |
270 | 256 |
271 void TrayBackgroundView::SetBorder() { | 257 void TrayBackgroundView::SetBorder() { |
272 views::View* parent = status_area_widget_->status_area_widget_delegate(); | 258 views::View* parent = status_area_widget_->status_area_widget_delegate(); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
380 } | 366 } |
381 NOTREACHED(); | 367 NOTREACHED(); |
382 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | 368 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; |
383 } | 369 } |
384 | 370 |
385 void TrayBackgroundView::UpdateBubbleViewArrow( | 371 void TrayBackgroundView::UpdateBubbleViewArrow( |
386 views::TrayBubbleView* bubble_view) { | 372 views::TrayBubbleView* bubble_view) { |
387 aura::RootWindow* root_window = | 373 aura::RootWindow* root_window = |
388 bubble_view->GetWidget()->GetNativeView()->GetRootWindow(); | 374 bubble_view->GetWidget()->GetNativeView()->GetRootWindow(); |
389 ash::internal::ShelfLayoutManager* shelf = | 375 ash::internal::ShelfLayoutManager* shelf = |
390 ash::GetRootWindowController(root_window)->shelf(); | 376 ShelfLayoutManager::ForLauncher(root_window); |
391 bubble_view->SetArrowPaintType( | 377 bubble_view->SetArrowPaintType( |
392 shelf->IsVisible() ? views::BubbleBorder::PAINT_NORMAL : | 378 shelf->IsVisible() ? views::BubbleBorder::PAINT_NORMAL : |
393 views::BubbleBorder::PAINT_TRANSPARENT); | 379 views::BubbleBorder::PAINT_TRANSPARENT); |
394 } | 380 } |
395 | 381 |
396 } // namespace internal | 382 } // namespace internal |
397 } // namespace ash | 383 } // namespace ash |
OLD | NEW |