| 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 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 87 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); | 87 DISALLOW_COPY_AND_ASSIGN(SystemTrayBackground); |
| 88 }; | 88 }; |
| 89 | 89 |
| 90 // Container for all the items in the tray. The container auto-resizes the | 90 // Container for all the items in the tray. The container auto-resizes the |
| 91 // widget when necessary. | 91 // widget when necessary. |
| 92 class SystemTrayContainer : public views::View { | 92 class SystemTrayContainer : public views::View { |
| 93 public: | 93 public: |
| 94 SystemTrayContainer() {} | 94 SystemTrayContainer() {} |
| 95 virtual ~SystemTrayContainer() {} | 95 virtual ~SystemTrayContainer() {} |
| 96 | 96 |
| 97 void SetLayoutManager(views::LayoutManager* layout_manager) { |
| 98 views::View::SetLayoutManager(layout_manager); |
| 99 UpdateWidgetSize(); |
| 100 } |
| 101 |
| 97 private: | 102 private: |
| 98 void UpdateWidgetSize() { | 103 void UpdateWidgetSize() { |
| 99 if (GetWidget()) | 104 if (GetWidget()) |
| 100 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); | 105 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); |
| 101 } | 106 } |
| 102 | 107 |
| 103 // Overridden from views::View. | 108 // Overridden from views::View. |
| 104 virtual void ChildPreferredSizeChanged(views::View* child) { | 109 virtual void ChildPreferredSizeChanged(views::View* child) { |
| 105 views::View::ChildPreferredSizeChanged(child); | 110 views::View::ChildPreferredSizeChanged(child); |
| 106 UpdateWidgetSize(); | 111 UpdateWidgetSize(); |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 164 drive_observer_(NULL), | 169 drive_observer_(NULL), |
| 165 ime_observer_(NULL), | 170 ime_observer_(NULL), |
| 166 locale_observer_(NULL), | 171 locale_observer_(NULL), |
| 167 network_observer_(NULL), | 172 network_observer_(NULL), |
| 168 power_status_observer_(NULL), | 173 power_status_observer_(NULL), |
| 169 update_observer_(NULL), | 174 update_observer_(NULL), |
| 170 user_observer_(NULL), | 175 user_observer_(NULL), |
| 171 widget_(NULL), | 176 widget_(NULL), |
| 172 background_(new internal::SystemTrayBackground), | 177 background_(new internal::SystemTrayBackground), |
| 173 should_show_launcher_(false), | 178 should_show_launcher_(false), |
| 179 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), |
| 174 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, | 180 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, |
| 175 0, kTrayBackgroundAlpha)), | 181 0, kTrayBackgroundAlpha)), |
| 176 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, | 182 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, |
| 177 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 183 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { |
| 178 tray_container_ = new internal::SystemTrayContainer; | 184 tray_container_ = new internal::SystemTrayContainer; |
| 179 tray_container_->SetLayoutManager(new views::BoxLayout( | 185 tray_container_->SetLayoutManager(new views::BoxLayout( |
| 180 views::BoxLayout::kHorizontal, 0, 0, 0)); | 186 views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 181 tray_container_->set_background(background_); | 187 tray_container_->set_background(background_); |
| 182 tray_container_->set_border( | 188 tray_container_->set_border( |
| 183 views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 189 views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
| 184 set_border(views::Border::CreateEmptyBorder(0, 0, | 190 set_border(views::Border::CreateEmptyBorder(0, 0, |
| 185 kPaddingFromBottomOfScreen, kPaddingFromRightEdgeOfScreen)); | 191 kPaddingFromBottomOfScreenBottomAlignment, |
| 192 kPaddingFromRightEdgeOfScreenBottomAlignment)); |
| 186 set_notify_enter_exit_on_child(true); | 193 set_notify_enter_exit_on_child(true); |
| 187 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 194 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 188 AddChildView(tray_container_); | 195 AddChildView(tray_container_); |
| 189 | 196 |
| 190 // Initially we want to paint the background, but without the hover effect. | 197 // Initially we want to paint the background, but without the hover effect. |
| 191 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 198 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 192 hover_background_animator_.SetPaintsBackground(false, | 199 hover_background_animator_.SetPaintsBackground(false, |
| 193 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 200 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 194 } | 201 } |
| 195 | 202 |
| (...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 500 } | 507 } |
| 501 | 508 |
| 502 void SystemTray::UpdateNotificationAnchor() { | 509 void SystemTray::UpdateNotificationAnchor() { |
| 503 if (!notification_bubble_.get()) | 510 if (!notification_bubble_.get()) |
| 504 return; | 511 return; |
| 505 notification_bubble_->bubble_view()->UpdateAnchor(); | 512 notification_bubble_->bubble_view()->UpdateAnchor(); |
| 506 // Ensure that the notification buble is above the launcher/status area. | 513 // Ensure that the notification buble is above the launcher/status area. |
| 507 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 514 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 508 } | 515 } |
| 509 | 516 |
| 517 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 518 if (alignment == shelf_alignment_) |
| 519 return; |
| 520 |
| 521 tray_container_->SetLayoutManager(new views::BoxLayout( |
| 522 alignment == SHELF_ALIGNMENT_BOTTOM ? |
| 523 views::BoxLayout::kHorizontal : views::BoxLayout::kVertical, |
| 524 0, 0, 0)); |
| 525 shelf_alignment_ = alignment; |
| 526 } |
| 527 |
| 510 bool SystemTray::PerformAction(const views::Event& event) { | 528 bool SystemTray::PerformAction(const views::Event& event) { |
| 511 // If we're already showing the default view, hide it; otherwise, show it | 529 // If we're already showing the default view, hide it; otherwise, show it |
| 512 // (and hide any popup that's currently shown). | 530 // (and hide any popup that's currently shown). |
| 513 if (bubble_.get() && | 531 if (bubble_.get() && |
| 514 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 532 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
| 515 bubble_->Close(); | 533 bubble_->Close(); |
| 516 } else { | 534 } else { |
| 517 int arrow_offset = -1; | 535 int arrow_offset = -1; |
| 518 if (event.IsMouseEvent() || event.IsTouchEvent()) { | 536 if (event.IsMouseEvent() || event.IsTouchEvent()) { |
| 519 const views::LocatedEvent& located_event = | 537 const views::LocatedEvent& located_event = |
| 520 static_cast<const views::LocatedEvent&>(event); | 538 static_cast<const views::LocatedEvent&>(event); |
| 521 arrow_offset = base::i18n::IsRTL() ? | 539 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) |
| 522 located_event.x() : tray_container_->width() - located_event.x(); | 540 arrow_offset = base::i18n::IsRTL() ? |
| 541 located_event.x() : tray_container_->width() - located_event.x(); |
| 542 else |
| 543 arrow_offset = tray_container_->height() - located_event.y(); |
| 523 } | 544 } |
| 524 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 545 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
| 525 } | 546 } |
| 526 return true; | 547 return true; |
| 527 } | 548 } |
| 528 | 549 |
| 529 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { | 550 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { |
| 530 should_show_launcher_ = true; | 551 should_show_launcher_ = true; |
| 531 hover_background_animator_.SetPaintsBackground(true, | 552 hover_background_animator_.SetPaintsBackground(true, |
| 532 internal::BackgroundAnimator::CHANGE_ANIMATE); | 553 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 560 canvas->DrawFocusRect(tray_container_->bounds()); | 581 canvas->DrawFocusRect(tray_container_->bounds()); |
| 561 } | 582 } |
| 562 | 583 |
| 563 void SystemTray::UpdateBackground(int alpha) { | 584 void SystemTray::UpdateBackground(int alpha) { |
| 564 background_->set_alpha(hide_background_animator_.alpha() + | 585 background_->set_alpha(hide_background_animator_.alpha() + |
| 565 hover_background_animator_.alpha()); | 586 hover_background_animator_.alpha()); |
| 566 SchedulePaint(); | 587 SchedulePaint(); |
| 567 } | 588 } |
| 568 | 589 |
| 569 } // namespace ash | 590 } // namespace ash |
| OLD | NEW |