| 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/system_tray.h" | 5 #include "ash/system/tray/system_tray.h" |
| 6 | 6 |
| 7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
| 8 #include "ash/shell/panel_window.h" | 8 #include "ash/shell/panel_window.h" |
| 9 #include "ash/shell_window_ids.h" | 9 #include "ash/shell_window_ids.h" |
| 10 #include "ash/system/audio/tray_volume.h" | 10 #include "ash/system/audio/tray_volume.h" |
| (...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 drive_observer_(NULL), | 164 drive_observer_(NULL), |
| 165 ime_observer_(NULL), | 165 ime_observer_(NULL), |
| 166 locale_observer_(NULL), | 166 locale_observer_(NULL), |
| 167 network_observer_(NULL), | 167 network_observer_(NULL), |
| 168 power_status_observer_(NULL), | 168 power_status_observer_(NULL), |
| 169 update_observer_(NULL), | 169 update_observer_(NULL), |
| 170 user_observer_(NULL), | 170 user_observer_(NULL), |
| 171 widget_(NULL), | 171 widget_(NULL), |
| 172 background_(new internal::SystemTrayBackground), | 172 background_(new internal::SystemTrayBackground), |
| 173 should_show_launcher_(false), | 173 should_show_launcher_(false), |
| 174 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 174 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, | 175 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, |
| 175 0, kTrayBackgroundAlpha)), | 176 0, kTrayBackgroundAlpha)), |
| 176 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, | 177 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, |
| 177 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 178 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { |
| 178 tray_container_ = new internal::SystemTrayContainer; | 179 tray_container_ = new internal::SystemTrayContainer; |
| 179 tray_container_->SetLayoutManager(new views::BoxLayout( | 180 tray_container_->SetLayoutManager(new views::BoxLayout( |
| 180 views::BoxLayout::kHorizontal, 0, 0, 0)); | 181 views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 181 tray_container_->set_background(background_); | 182 tray_container_->set_background(background_); |
| 182 tray_container_->set_border( | 183 tray_container_->set_border( |
| 183 views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 184 views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
| 184 set_border(views::Border::CreateEmptyBorder(0, 0, | 185 set_border(views::Border::CreateEmptyBorder(0, 0, |
| 185 kPaddingFromBottomOfScreen, kPaddingFromRightEdgeOfScreen)); | 186 kPaddingFromBottomOfScreenBottomAlignment, |
| 187 kPaddingFromRightEdgeOfScreenBottomAlignment)); |
| 186 set_notify_enter_exit_on_child(true); | 188 set_notify_enter_exit_on_child(true); |
| 187 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 189 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 188 AddChildView(tray_container_); | 190 AddChildView(tray_container_); |
| 189 | 191 |
| 190 // Initially we want to paint the background, but without the hover effect. | 192 // Initially we want to paint the background, but without the hover effect. |
| 191 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 193 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 192 hover_background_animator_.SetPaintsBackground(false, | 194 hover_background_animator_.SetPaintsBackground(false, |
| 193 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 195 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 194 } | 196 } |
| 195 | 197 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 502 } |
| 501 | 503 |
| 502 void SystemTray::UpdateNotificationAnchor() { | 504 void SystemTray::UpdateNotificationAnchor() { |
| 503 if (!notification_bubble_.get()) | 505 if (!notification_bubble_.get()) |
| 504 return; | 506 return; |
| 505 notification_bubble_->bubble_view()->UpdateAnchor(); | 507 notification_bubble_->bubble_view()->UpdateAnchor(); |
| 506 // Ensure that the notification buble is above the launcher/status area. | 508 // Ensure that the notification buble is above the launcher/status area. |
| 507 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 509 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 508 } | 510 } |
| 509 | 511 |
| 512 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 513 if (alignment == shelf_alignment_) |
| 514 return; |
| 515 |
| 516 tray_container_->SetLayoutManager(new views::BoxLayout( |
| 517 alignment == SHELF_ALIGNMENT_BOTTOM ? |
| 518 views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, |
| 519 0, 0, 0)); |
| 520 shelf_alignment_ = alignment; |
| 521 } |
| 522 |
| 510 bool SystemTray::PerformAction(const views::Event& event) { | 523 bool SystemTray::PerformAction(const views::Event& event) { |
| 511 // If we're already showing the default view, hide it; otherwise, show it | 524 // If we're already showing the default view, hide it; otherwise, show it |
| 512 // (and hide any popup that's currently shown). | 525 // (and hide any popup that's currently shown). |
| 513 if (bubble_.get() && | 526 if (bubble_.get() && |
| 514 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 527 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
| 515 bubble_->Close(); | 528 bubble_->Close(); |
| 516 } else { | 529 } else { |
| 517 int arrow_offset = -1; | 530 int arrow_offset = -1; |
| 518 if (event.IsMouseEvent() || event.IsTouchEvent()) { | 531 if (event.IsMouseEvent() || event.IsTouchEvent()) { |
| 519 const views::LocatedEvent& located_event = | 532 const views::LocatedEvent& located_event = |
| 520 static_cast<const views::LocatedEvent&>(event); | 533 static_cast<const views::LocatedEvent&>(event); |
| 521 arrow_offset = base::i18n::IsRTL() ? | 534 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) |
| 522 located_event.x() : tray_container_->width() - located_event.x(); | 535 arrow_offset = base::i18n::IsRTL() ? |
| 536 located_event.x() : tray_container_->width() - located_event.x(); |
| 537 else |
| 538 arrow_offset = tray_container_->height() - located_event.y(); |
| 523 } | 539 } |
| 524 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 540 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
| 525 } | 541 } |
| 526 return true; | 542 return true; |
| 527 } | 543 } |
| 528 | 544 |
| 529 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { | 545 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { |
| 530 should_show_launcher_ = true; | 546 should_show_launcher_ = true; |
| 531 hover_background_animator_.SetPaintsBackground(true, | 547 hover_background_animator_.SetPaintsBackground(true, |
| 532 internal::BackgroundAnimator::CHANGE_ANIMATE); | 548 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 560 canvas->DrawFocusRect(tray_container_->bounds()); | 576 canvas->DrawFocusRect(tray_container_->bounds()); |
| 561 } | 577 } |
| 562 | 578 |
| 563 void SystemTray::UpdateBackground(int alpha) { | 579 void SystemTray::UpdateBackground(int alpha) { |
| 564 background_->set_alpha(hide_background_animator_.alpha() + | 580 background_->set_alpha(hide_background_animator_.alpha() + |
| 565 hover_background_animator_.alpha()); | 581 hover_background_animator_.alpha()); |
| 566 SchedulePaint(); | 582 SchedulePaint(); |
| 567 } | 583 } |
| 568 | 584 |
| 569 } // namespace ash | 585 } // namespace ash |
| OLD | NEW |