Chromium Code Reviews| 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 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 161 clock_observer_(NULL), | 161 clock_observer_(NULL), |
| 162 drive_observer_(NULL), | 162 drive_observer_(NULL), |
| 163 ime_observer_(NULL), | 163 ime_observer_(NULL), |
| 164 network_observer_(NULL), | 164 network_observer_(NULL), |
| 165 power_status_observer_(NULL), | 165 power_status_observer_(NULL), |
| 166 update_observer_(NULL), | 166 update_observer_(NULL), |
| 167 user_observer_(NULL), | 167 user_observer_(NULL), |
| 168 widget_(NULL), | 168 widget_(NULL), |
| 169 background_(new internal::SystemTrayBackground), | 169 background_(new internal::SystemTrayBackground), |
| 170 should_show_launcher_(false), | 170 should_show_launcher_(false), |
| 171 shelf_alignment_(SHELF_ALIGNMENT_BOTTOM), | |
| 171 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, | 172 ALLOW_THIS_IN_INITIALIZER_LIST(hide_background_animator_(this, |
| 172 0, kTrayBackgroundAlpha)), | 173 0, kTrayBackgroundAlpha)), |
| 173 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, | 174 ALLOW_THIS_IN_INITIALIZER_LIST(hover_background_animator_(this, |
| 174 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { | 175 0, kTrayBackgroundHoverAlpha - kTrayBackgroundAlpha)) { |
| 175 tray_container_ = new internal::SystemTrayContainer; | 176 tray_container_ = new internal::SystemTrayContainer; |
| 176 tray_container_->SetLayoutManager(new views::BoxLayout( | 177 tray_container_->SetLayoutManager(new views::BoxLayout( |
| 177 views::BoxLayout::kHorizontal, 0, 0, 0)); | 178 views::BoxLayout::kHorizontal, 0, 0, 0)); |
| 178 tray_container_->set_background(background_); | 179 tray_container_->set_background(background_); |
| 179 tray_container_->set_border( | 180 tray_container_->set_border( |
| 180 views::Border::CreateEmptyBorder(1, 1, 1, 1)); | 181 views::Border::CreateEmptyBorder(1, 1, 1, 1)); |
| 181 set_border(views::Border::CreateEmptyBorder(0, 0, | 182 set_border(views::Border::CreateEmptyBorder(0, 0, |
| 182 kPaddingFromBottomOfScreen, kPaddingFromRightEdgeOfScreen)); | 183 kPaddingFromBottomOfScreenBottomAlignment, |
| 184 kPaddingFromRightEdgeOfScreenBottomAlignment)); | |
| 183 set_notify_enter_exit_on_child(true); | 185 set_notify_enter_exit_on_child(true); |
| 184 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); | 186 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kVertical, 0, 0, 0)); |
| 185 AddChildView(tray_container_); | 187 AddChildView(tray_container_); |
| 186 | 188 |
| 187 // Initially we want to paint the background, but without the hover effect. | 189 // Initially we want to paint the background, but without the hover effect. |
| 188 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 190 SetPaintsBackground(true, internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 189 hover_background_animator_.SetPaintsBackground(false, | 191 hover_background_animator_.SetPaintsBackground(false, |
| 190 internal::BackgroundAnimator::CHANGE_IMMEDIATE); | 192 internal::BackgroundAnimator::CHANGE_IMMEDIATE); |
| 191 } | 193 } |
| 192 | 194 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 471 } | 473 } |
| 472 | 474 |
| 473 void SystemTray::UpdateNotificationAnchor() { | 475 void SystemTray::UpdateNotificationAnchor() { |
| 474 if (!notification_bubble_.get()) | 476 if (!notification_bubble_.get()) |
| 475 return; | 477 return; |
| 476 notification_bubble_->bubble_view()->UpdateAnchor(); | 478 notification_bubble_->bubble_view()->UpdateAnchor(); |
| 477 // Ensure that the notification buble is above the launcher/status area. | 479 // Ensure that the notification buble is above the launcher/status area. |
| 478 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); | 480 notification_bubble_->bubble_view()->GetWidget()->StackAtTop(); |
| 479 } | 481 } |
| 480 | 482 |
| 483 void SystemTray::SetShelfAlignment(ShelfAlignment alignment) { | |
| 484 if (alignment == shelf_alignment_) | |
| 485 return; | |
| 486 | |
| 487 if (alignment == SHELF_ALIGNMENT_BOTTOM){ | |
| 488 tray_container_->SetLayoutManager(new views::BoxLayout( | |
| 489 views::BoxLayout::kHorizontal, 0, 0, 0)); | |
| 490 } else if (alignment == SHELF_ALIGNMENT_LEFT || | |
|
sadrul
2012/05/17 23:30:29
two many spaces here
jennyz
2012/05/18 00:00:42
Done.
| |
| 491 alignment == SHELF_ALIGNMENT_RIGHT) { | |
| 492 if (shelf_alignment_ == SHELF_ALIGNMENT_BOTTOM) | |
| 493 tray_container_->SetLayoutManager(new views::BoxLayout( | |
| 494 views::BoxLayout::kVertical, 0, 0, 0)); | |
| 495 } | |
|
sadrul
2012/05/17 23:30:29
I think this could just be:
tray_container_->Set
jennyz
2012/05/18 00:00:42
Done. I was trying to save a little for switching
| |
| 496 shelf_alignment_ = alignment; | |
| 497 } | |
| 498 | |
| 481 bool SystemTray::PerformAction(const views::Event& event) { | 499 bool SystemTray::PerformAction(const views::Event& event) { |
| 482 // If we're already showing the default view, hide it; otherwise, show it | 500 // If we're already showing the default view, hide it; otherwise, show it |
| 483 // (and hide any popup that's currently shown). | 501 // (and hide any popup that's currently shown). |
| 484 if (bubble_.get() && | 502 if (bubble_.get() && |
| 485 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { | 503 bubble_->bubble_type() == SystemTrayBubble::BUBBLE_TYPE_DEFAULT) { |
| 486 bubble_->Close(); | 504 bubble_->Close(); |
| 487 } else { | 505 } else { |
| 488 int arrow_offset = -1; | 506 int arrow_offset = -1; |
| 489 if (event.IsMouseEvent() || event.IsTouchEvent()) { | 507 if (event.IsMouseEvent() || event.IsTouchEvent()) { |
| 490 const views::LocatedEvent& located_event = | 508 const views::LocatedEvent& located_event = |
| 491 static_cast<const views::LocatedEvent&>(event); | 509 static_cast<const views::LocatedEvent&>(event); |
| 492 arrow_offset = base::i18n::IsRTL() ? | 510 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM) |
| 493 located_event.x() : tray_container_->width() - located_event.x(); | 511 arrow_offset = base::i18n::IsRTL() ? |
| 512 located_event.x() : tray_container_->width() - located_event.x(); | |
| 513 else | |
| 514 arrow_offset = tray_container_->height() - located_event.y(); | |
| 494 } | 515 } |
| 495 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); | 516 ShowDefaultViewWithOffset(BUBBLE_CREATE_NEW, arrow_offset); |
| 496 } | 517 } |
| 497 return true; | 518 return true; |
| 498 } | 519 } |
| 499 | 520 |
| 500 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { | 521 void SystemTray::OnMouseEntered(const views::MouseEvent& event) { |
| 501 should_show_launcher_ = true; | 522 should_show_launcher_ = true; |
| 502 hover_background_animator_.SetPaintsBackground(true, | 523 hover_background_animator_.SetPaintsBackground(true, |
| 503 internal::BackgroundAnimator::CHANGE_ANIMATE); | 524 internal::BackgroundAnimator::CHANGE_ANIMATE); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 531 canvas->DrawFocusRect(tray_container_->bounds()); | 552 canvas->DrawFocusRect(tray_container_->bounds()); |
| 532 } | 553 } |
| 533 | 554 |
| 534 void SystemTray::UpdateBackground(int alpha) { | 555 void SystemTray::UpdateBackground(int alpha) { |
| 535 background_->set_alpha(hide_background_animator_.alpha() + | 556 background_->set_alpha(hide_background_animator_.alpha() + |
| 536 hover_background_animator_.alpha()); | 557 hover_background_animator_.alpha()); |
| 537 SchedulePaint(); | 558 SchedulePaint(); |
| 538 } | 559 } |
| 539 | 560 |
| 540 } // namespace ash | 561 } // namespace ash |
| OLD | NEW |