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