| 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/tray/tray_constants.h" | 10 #include "ash/system/tray/tray_constants.h" |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 51 const int kArrowHeight = 10; | 51 const int kArrowHeight = 10; |
| 52 const int kArrowWidth = 20; | 52 const int kArrowWidth = 20; |
| 53 const int kArrowPaddingFromRight = 20; | 53 const int kArrowPaddingFromRight = 20; |
| 54 | 54 |
| 55 const int kShadowOffset = 3; | 55 const int kShadowOffset = 3; |
| 56 const int kShadowHeight = 3; | 56 const int kShadowHeight = 3; |
| 57 | 57 |
| 58 const int kLeftPadding = 4; | 58 const int kLeftPadding = 4; |
| 59 const int kBottomLineHeight = 1; | 59 const int kBottomLineHeight = 1; |
| 60 | 60 |
| 61 const int kTrayIconHeight = 29; | |
| 62 | |
| 63 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); | 61 const SkColor kShadowColor = SkColorSetARGB(25, 0, 0, 0); |
| 64 | 62 |
| 65 const SkColor kTrayBackgroundAlpha = 100; | 63 const SkColor kTrayBackgroundAlpha = 100; |
| 66 const SkColor kTrayBackgroundHoverAlpha = 150; | 64 const SkColor kTrayBackgroundHoverAlpha = 150; |
| 67 | 65 |
| 68 // Container for items in the tray. It makes sure the widget is updated | |
| 69 // correctly when the visibility/size of the tray item changes. | |
| 70 // TODO: setup animation. | |
| 71 class TrayItemContainer : public views::View { | |
| 72 public: | |
| 73 explicit TrayItemContainer(views::View* view) : child_(view) { | |
| 74 AddChildView(child_); | |
| 75 SetVisible(child_->visible()); | |
| 76 } | |
| 77 | |
| 78 virtual ~TrayItemContainer() {} | |
| 79 | |
| 80 private: | |
| 81 // Makes sure the widget relayouts after the size/visibility of the view | |
| 82 // changes. | |
| 83 void ApplyChange() { | |
| 84 // Forcing the widget to the new size is sufficient. The positing is taken | |
| 85 // care of by the layout manager (ShelfLayoutManager). | |
| 86 GetWidget()->SetSize(GetWidget()->GetContentsView()->GetPreferredSize()); | |
| 87 } | |
| 88 | |
| 89 // Overridden from views::View. | |
| 90 virtual void Layout() { | |
| 91 child_->SetBoundsRect(gfx::Rect(size())); | |
| 92 } | |
| 93 | |
| 94 virtual gfx::Size GetPreferredSize() OVERRIDE { | |
| 95 gfx::Size size = child_->GetPreferredSize(); | |
| 96 size.set_height(kTrayIconHeight); | |
| 97 return size; | |
| 98 } | |
| 99 | |
| 100 virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE { | |
| 101 ApplyChange(); | |
| 102 } | |
| 103 | |
| 104 virtual void ChildVisibilityChanged(views::View* child) OVERRIDE { | |
| 105 if (visible() == child_->visible()) | |
| 106 return; | |
| 107 SetVisible(child_->visible()); | |
| 108 ApplyChange(); | |
| 109 } | |
| 110 | |
| 111 views::View* child_; | |
| 112 | |
| 113 DISALLOW_COPY_AND_ASSIGN(TrayItemContainer); | |
| 114 }; | |
| 115 | |
| 116 // A view with some special behaviour for tray items in the popup: | 66 // A view with some special behaviour for tray items in the popup: |
| 117 // - changes background color on hover. | 67 // - changes background color on hover. |
| 118 // - TODO: accessibility | |
| 119 class TrayPopupItemContainer : public views::View { | 68 class TrayPopupItemContainer : public views::View { |
| 120 public: | 69 public: |
| 121 explicit TrayPopupItemContainer(views::View* view) : hover_(false) { | 70 explicit TrayPopupItemContainer(views::View* view) : hover_(false) { |
| 122 set_notify_enter_exit_on_child(true); | 71 set_notify_enter_exit_on_child(true); |
| 123 set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) : | 72 set_border(view->border() ? views::Border::CreateEmptyBorder(0, 0, 0, 0) : |
| 124 NULL); | 73 NULL); |
| 125 SetLayoutManager(new views::FillLayout); | 74 SetLayoutManager(new views::FillLayout); |
| 126 AddChildView(view); | 75 AddChildView(view); |
| 127 } | 76 } |
| 128 | 77 |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 if (popup_) | 441 if (popup_) |
| 493 popup_->CloseNow(); | 442 popup_->CloseNow(); |
| 494 } | 443 } |
| 495 | 444 |
| 496 void SystemTray::AddTrayItem(SystemTrayItem* item) { | 445 void SystemTray::AddTrayItem(SystemTrayItem* item) { |
| 497 items_.push_back(item); | 446 items_.push_back(item); |
| 498 | 447 |
| 499 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 448 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
| 500 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); | 449 views::View* tray_item = item->CreateTrayView(delegate->GetUserLoginStatus()); |
| 501 if (tray_item) { | 450 if (tray_item) { |
| 502 container_->AddChildViewAt(new TrayItemContainer(tray_item), 0); | 451 container_->AddChildViewAt(tray_item, 0); |
| 503 PreferredSizeChanged(); | 452 PreferredSizeChanged(); |
| 504 } | 453 } |
| 505 } | 454 } |
| 506 | 455 |
| 507 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { | 456 void SystemTray::RemoveTrayItem(SystemTrayItem* item) { |
| 508 NOTIMPLEMENTED(); | 457 NOTIMPLEMENTED(); |
| 509 } | 458 } |
| 510 | 459 |
| 511 void SystemTray::ShowDefaultView() { | 460 void SystemTray::ShowDefaultView() { |
| 512 if (popup_) { | 461 if (popup_) { |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 ++it) { | 500 ++it) { |
| 552 (*it)->DestroyTrayView(); | 501 (*it)->DestroyTrayView(); |
| 553 } | 502 } |
| 554 container_->RemoveAllChildViews(true); | 503 container_->RemoveAllChildViews(true); |
| 555 | 504 |
| 556 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); | 505 for (std::vector<SystemTrayItem*>::iterator it = items_.begin(); |
| 557 it != items_.end(); | 506 it != items_.end(); |
| 558 ++it) { | 507 ++it) { |
| 559 views::View* view = (*it)->CreateTrayView(login_status); | 508 views::View* view = (*it)->CreateTrayView(login_status); |
| 560 if (view) | 509 if (view) |
| 561 container_->AddChildViewAt(new TrayItemContainer(view), 0); | 510 container_->AddChildViewAt(view, 0); |
| 562 } | 511 } |
| 563 SetVisible(true); | 512 SetVisible(true); |
| 564 PreferredSizeChanged(); | 513 PreferredSizeChanged(); |
| 565 } | 514 } |
| 566 | 515 |
| 567 void SystemTray::SetPaintsBackground( | 516 void SystemTray::SetPaintsBackground( |
| 568 bool value, | 517 bool value, |
| 569 internal::BackgroundAnimator::ChangeType change_type) { | 518 internal::BackgroundAnimator::ChangeType change_type) { |
| 570 hide_background_animator_.SetPaintsBackground(value, change_type); | 519 hide_background_animator_.SetPaintsBackground(value, change_type); |
| 571 } | 520 } |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 682 popup_->Hide(); | 631 popup_->Hide(); |
| 683 } | 632 } |
| 684 } | 633 } |
| 685 return base::EVENT_CONTINUE; | 634 return base::EVENT_CONTINUE; |
| 686 } | 635 } |
| 687 | 636 |
| 688 void SystemTray::DidProcessEvent(const base::NativeEvent& event) { | 637 void SystemTray::DidProcessEvent(const base::NativeEvent& event) { |
| 689 } | 638 } |
| 690 | 639 |
| 691 } // namespace ash | 640 } // namespace ash |
| OLD | NEW |