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/ash_switches.h" | 7 #include "ash/ash_switches.h" |
8 #include "ash/root_window_controller.h" | 8 #include "ash/root_window_controller.h" |
9 #include "ash/screen_ash.h" | 9 #include "ash/screen_ash.h" |
10 #include "ash/shelf/shelf_layout_manager.h" | 10 #include "ash/shelf/shelf_layout_manager.h" |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 } | 156 } |
157 | 157 |
158 void PaintForAlternateShelf(gfx::Canvas* canvas, views::View* view) const { | 158 void PaintForAlternateShelf(gfx::Canvas* canvas, views::View* view) const { |
159 int orientation = kImageHorizontal; | 159 int orientation = kImageHorizontal; |
160 ShelfWidget* shelf_widget = GetShelfWidget(); | 160 ShelfWidget* shelf_widget = GetShelfWidget(); |
161 if (shelf_widget && | 161 if (shelf_widget && |
162 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) | 162 !shelf_widget->shelf_layout_manager()->IsHorizontalAlignment()) |
163 orientation = kImageVertical; | 163 orientation = kImageVertical; |
164 | 164 |
165 int state = kImageTypeDefault; | 165 int state = kImageTypeDefault; |
166 if (tray_background_view_->IsPressed()) | 166 if (tray_background_view_->draw_background_as_active()) |
167 state = kImageTypePressed; | 167 state = kImageTypePressed; |
168 else if (shelf_widget && shelf_widget->GetDimsShelf()) | 168 else if (shelf_widget && shelf_widget->GetDimsShelf()) |
169 state = kImageTypeOnBlack; | 169 state = kImageTypeOnBlack; |
170 else | 170 else |
171 state = kImageTypeDefault; | 171 state = kImageTypeDefault; |
172 | 172 |
173 const gfx::ImageSkia* leading = leading_images_[orientation][state]; | 173 const gfx::ImageSkia* leading = leading_images_[orientation][state]; |
174 const gfx::ImageSkia* middle = middle_images_[orientation][state]; | 174 const gfx::ImageSkia* middle = middle_images_[orientation][state]; |
175 const gfx::ImageSkia* trailing = trailing_images_[orientation][state]; | 175 const gfx::ImageSkia* trailing = trailing_images_[orientation][state]; |
176 | 176 |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
322 TrayBackgroundView::TrayBackgroundView( | 322 TrayBackgroundView::TrayBackgroundView( |
323 internal::StatusAreaWidget* status_area_widget) | 323 internal::StatusAreaWidget* status_area_widget) |
324 : status_area_widget_(status_area_widget), | 324 : status_area_widget_(status_area_widget), |
325 tray_container_(NULL), | 325 tray_container_(NULL), |
326 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | 326 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
327 background_(NULL), | 327 background_(NULL), |
328 hide_background_animator_(this, 0, kTrayBackgroundAlpha), | 328 hide_background_animator_(this, 0, kTrayBackgroundAlpha), |
329 hover_background_animator_( | 329 hover_background_animator_( |
330 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), | 330 this, 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha), |
331 hovered_(false), | 331 hovered_(false), |
332 pressed_(false), | 332 draw_background_as_active_(false), |
333 widget_observer_(new TrayWidgetObserver(this)) { | 333 widget_observer_(new TrayWidgetObserver(this)) { |
334 set_notify_enter_exit_on_child(true); | 334 set_notify_enter_exit_on_child(true); |
335 | 335 |
336 // Initially we want to paint the background, but without the hover effect. | 336 // Initially we want to paint the background, but without the hover effect. |
337 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 337 hide_background_animator_.SetPaintsBackground(true, |
| 338 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
338 hover_background_animator_.SetPaintsBackground(false, | 339 hover_background_animator_.SetPaintsBackground(false, |
339 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 340 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
340 | 341 |
341 tray_container_ = new TrayContainer(shelf_alignment_); | 342 tray_container_ = new TrayContainer(shelf_alignment_); |
342 SetContents(tray_container_); | 343 SetContents(tray_container_); |
343 tray_event_filter_.reset(new TrayEventFilter); | 344 tray_event_filter_.reset(new TrayEventFilter); |
344 } | 345 } |
345 | 346 |
346 TrayBackgroundView::~TrayBackgroundView() { | 347 TrayBackgroundView::~TrayBackgroundView() { |
347 if (GetWidget()) | 348 if (GetWidget()) |
348 GetWidget()->RemoveObserver(widget_observer_.get()); | 349 GetWidget()->RemoveObserver(widget_observer_.get()); |
349 } | 350 } |
350 | 351 |
351 void TrayBackgroundView::Initialize() { | 352 void TrayBackgroundView::Initialize() { |
352 GetWidget()->AddObserver(widget_observer_.get()); | 353 GetWidget()->AddObserver(widget_observer_.get()); |
353 SetBorder(); | 354 SetBorder(); |
354 } | 355 } |
355 | 356 |
356 const char* TrayBackgroundView::GetClassName() const { | 357 const char* TrayBackgroundView::GetClassName() const { |
357 return kViewClassName; | 358 return kViewClassName; |
358 } | 359 } |
359 | 360 |
360 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { | 361 void TrayBackgroundView::OnMouseEntered(const ui::MouseEvent& event) { |
361 hovered_ = true; | 362 hovered_ = true; |
362 if (!background_) | 363 if (!background_ || draw_background_as_active_ || |
| 364 ash::switches::UseAlternateShelfLayout()) |
363 return; | 365 return; |
364 if (pressed_) | |
365 return; | |
366 | |
367 hover_background_animator_.SetPaintsBackground(true, | 366 hover_background_animator_.SetPaintsBackground(true, |
368 internal::BackgroundAnimator::CHANGE_ANIMATE); | 367 internal::BackgroundAnimator::CHANGE_ANIMATE); |
369 } | 368 } |
370 | 369 |
371 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { | 370 void TrayBackgroundView::OnMouseExited(const ui::MouseEvent& event) { |
372 hovered_ = false; | 371 hovered_ = false; |
373 if (!background_) | 372 if (!background_ || draw_background_as_active_ || |
| 373 ash::switches::UseAlternateShelfLayout()) |
374 return; | 374 return; |
375 if (pressed_) | |
376 return; | |
377 | |
378 hover_background_animator_.SetPaintsBackground(false, | 375 hover_background_animator_.SetPaintsBackground(false, |
379 internal::BackgroundAnimator::CHANGE_ANIMATE); | 376 internal::BackgroundAnimator::CHANGE_ANIMATE); |
380 } | 377 } |
381 | 378 |
382 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { | 379 void TrayBackgroundView::ChildPreferredSizeChanged(views::View* child) { |
383 PreferredSizeChanged(); | 380 PreferredSizeChanged(); |
384 } | 381 } |
385 | 382 |
386 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) { | 383 void TrayBackgroundView::OnPaintFocusBorder(gfx::Canvas* canvas) { |
387 // The tray itself expands to the right and bottom edge of the screen to make | 384 // The tray itself expands to the right and bottom edge of the screen to make |
(...skipping 13 matching lines...) Expand all Loading... |
401 views::View* v = GetNextFocusableView(); | 398 views::View* v = GetNextFocusableView(); |
402 if (v) | 399 if (v) |
403 v->AboutToRequestFocusFromTabTraversal(reverse); | 400 v->AboutToRequestFocusFromTabTraversal(reverse); |
404 } | 401 } |
405 | 402 |
406 bool TrayBackgroundView::PerformAction(const ui::Event& event) { | 403 bool TrayBackgroundView::PerformAction(const ui::Event& event) { |
407 return false; | 404 return false; |
408 } | 405 } |
409 | 406 |
410 void TrayBackgroundView::UpdateBackground(int alpha) { | 407 void TrayBackgroundView::UpdateBackground(int alpha) { |
411 if (!background_) | 408 // The animator should never fire when the alternate shelf layout is used. |
| 409 if (!background_ || draw_background_as_active_) |
412 return; | 410 return; |
413 if (pressed_) | 411 DCHECK(!ash::switches::UseAlternateShelfLayout()); |
414 return; | |
415 | |
416 background_->set_alpha(hide_background_animator_.alpha() + | 412 background_->set_alpha(hide_background_animator_.alpha() + |
417 hover_background_animator_.alpha()); | 413 hover_background_animator_.alpha()); |
418 SchedulePaint(); | 414 SchedulePaint(); |
419 } | 415 } |
420 | 416 |
421 void TrayBackgroundView::SetContents(views::View* contents) { | 417 void TrayBackgroundView::SetContents(views::View* contents) { |
422 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 418 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
423 AddChildView(contents); | 419 AddChildView(contents); |
424 } | 420 } |
425 | 421 |
426 void TrayBackgroundView::SetPaintsBackground( | 422 void TrayBackgroundView::SetPaintsBackground( |
427 bool value, | 423 bool value, |
428 internal::BackgroundAnimator::ChangeType change_type) { | 424 internal::BackgroundAnimator::ChangeType change_type) { |
| 425 DCHECK(!ash::switches::UseAlternateShelfLayout()); |
429 hide_background_animator_.SetPaintsBackground(value, change_type); | 426 hide_background_animator_.SetPaintsBackground(value, change_type); |
430 } | 427 } |
431 | 428 |
432 void TrayBackgroundView::SetContentsBackground() { | 429 void TrayBackgroundView::SetContentsBackground() { |
433 background_ = new internal::TrayBackground(this); | 430 background_ = new internal::TrayBackground(this); |
434 tray_container_->set_background(background_); | 431 tray_container_->set_background(background_); |
435 } | 432 } |
436 | 433 |
437 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { | 434 ShelfLayoutManager* TrayBackgroundView::GetShelfLayoutManager() { |
438 return ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); | 435 return ShelfLayoutManager::ForLauncher(GetWidget()->GetNativeView()); |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
489 bubble_widget->GetNativeWindow(), | 486 bubble_widget->GetNativeWindow(), |
490 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); | 487 views::corewm::WINDOW_VISIBILITY_ANIMATION_TYPE_FADE); |
491 views::corewm::SetWindowVisibilityAnimationTransition( | 488 views::corewm::SetWindowVisibilityAnimationTransition( |
492 bubble_widget->GetNativeWindow(), | 489 bubble_widget->GetNativeWindow(), |
493 views::corewm::ANIMATE_HIDE); | 490 views::corewm::ANIMATE_HIDE); |
494 views::corewm::SetWindowVisibilityAnimationDuration( | 491 views::corewm::SetWindowVisibilityAnimationDuration( |
495 bubble_widget->GetNativeWindow(), | 492 bubble_widget->GetNativeWindow(), |
496 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); | 493 base::TimeDelta::FromMilliseconds(kAnimationDurationForPopupMS)); |
497 } | 494 } |
498 | 495 |
499 bool TrayBackgroundView::IsPressed() { | |
500 return pressed_; | |
501 } | |
502 | |
503 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { | 496 aura::Window* TrayBackgroundView::GetBubbleWindowContainer() const { |
504 return ash::Shell::GetContainer( | 497 return ash::Shell::GetContainer( |
505 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), | 498 tray_container()->GetWidget()->GetNativeWindow()->GetRootWindow(), |
506 ash::internal::kShellWindowId_SettingBubbleContainer); | 499 ash::internal::kShellWindowId_SettingBubbleContainer); |
507 } | 500 } |
508 | 501 |
509 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( | 502 gfx::Rect TrayBackgroundView::GetBubbleAnchorRect( |
510 views::Widget* anchor_widget, | 503 views::Widget* anchor_widget, |
511 TrayBubbleView::AnchorType anchor_type, | 504 TrayBubbleView::AnchorType anchor_type, |
512 TrayBubbleView::AnchorAlignment anchor_alignment) const { | 505 TrayBubbleView::AnchorAlignment anchor_alignment) const { |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
568 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; | 561 return TrayBubbleView::ANCHOR_ALIGNMENT_LEFT; |
569 case SHELF_ALIGNMENT_RIGHT: | 562 case SHELF_ALIGNMENT_RIGHT: |
570 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; | 563 return TrayBubbleView::ANCHOR_ALIGNMENT_RIGHT; |
571 case SHELF_ALIGNMENT_TOP: | 564 case SHELF_ALIGNMENT_TOP: |
572 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; | 565 return TrayBubbleView::ANCHOR_ALIGNMENT_TOP; |
573 } | 566 } |
574 NOTREACHED(); | 567 NOTREACHED(); |
575 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; | 568 return TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM; |
576 } | 569 } |
577 | 570 |
578 void TrayBackgroundView::SetBubbleVisible(bool visible) { | 571 void TrayBackgroundView::SetDrawBackgroundAsActive(bool visible) { |
579 pressed_ = visible; | 572 draw_background_as_active_ = visible; |
580 if (!background_) | 573 if (!background_ || !switches::UseAlternateShelfLayout()) |
581 return; | 574 return; |
582 | 575 |
583 // Do not change gradually, changing color between grey and blue is weird. | 576 // Do not change gradually, changing color between grey and blue is weird. |
584 if (pressed_) | 577 if (draw_background_as_active_) |
585 background_->set_color(kTrayBackgroundPressedColor); | 578 background_->set_color(kTrayBackgroundPressedColor); |
586 else if (hovered_) | 579 else if (hovered_) |
587 background_->set_alpha(kTrayBackgroundHoverAlpha); | 580 background_->set_alpha(kTrayBackgroundHoverAlpha); |
588 else | 581 else |
589 background_->set_alpha(kTrayBackgroundAlpha); | 582 background_->set_alpha(kTrayBackgroundAlpha); |
590 SchedulePaint(); | 583 SchedulePaint(); |
591 } | 584 } |
592 | 585 |
593 void TrayBackgroundView::UpdateBubbleViewArrow( | 586 void TrayBackgroundView::UpdateBubbleViewArrow( |
594 views::TrayBubbleView* bubble_view) { | 587 views::TrayBubbleView* bubble_view) { |
595 if (switches::UseAlternateShelfLayout()) | 588 if (switches::UseAlternateShelfLayout()) |
596 return; | 589 return; |
597 | 590 |
598 aura::RootWindow* root_window = | 591 aura::RootWindow* root_window = |
599 bubble_view->GetWidget()->GetNativeView()->GetRootWindow(); | 592 bubble_view->GetWidget()->GetNativeView()->GetRootWindow(); |
600 ash::internal::ShelfLayoutManager* shelf = | 593 ash::internal::ShelfLayoutManager* shelf = |
601 ShelfLayoutManager::ForLauncher(root_window); | 594 ShelfLayoutManager::ForLauncher(root_window); |
602 bubble_view->SetArrowPaintType( | 595 bubble_view->SetArrowPaintType( |
603 (shelf && shelf->IsVisible()) ? | 596 (shelf && shelf->IsVisible()) ? |
604 views::BubbleBorder::PAINT_NORMAL : | 597 views::BubbleBorder::PAINT_NORMAL : |
605 views::BubbleBorder::PAINT_TRANSPARENT); | 598 views::BubbleBorder::PAINT_TRANSPARENT); |
606 } | 599 } |
607 | 600 |
608 } // namespace internal | 601 } // namespace internal |
609 } // namespace ash | 602 } // namespace ash |
OLD | NEW |