| 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/chromeos/enterprise/tray_enterprise.h" | 5 #include "ash/system/chromeos/enterprise/tray_enterprise.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/hover_highlight_view.h" | 7 #include "ash/system/chromeos/label_tray_view.h" |
| 8 #include "ash/system/tray/system_tray_notifier.h" | 8 #include "ash/system/tray/system_tray_notifier.h" |
| 9 #include "ash/system/tray/tray_constants.h" | |
| 10 #include "ash/system/tray/tray_views.h" | |
| 11 #include "ash/system/user/login_status.h" | 9 #include "ash/system/user/login_status.h" |
| 12 #include "base/logging.h" | 10 #include "base/logging.h" |
| 13 #include "grit/ash_resources.h" | 11 #include "grit/ash_resources.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | |
| 15 #include "ui/gfx/font.h" | |
| 16 #include "ui/views/controls/label.h" | |
| 17 #include "ui/views/layout/fill_layout.h" | |
| 18 | 12 |
| 19 namespace ash { | 13 namespace ash { |
| 20 namespace internal { | 14 namespace internal { |
| 21 | 15 |
| 22 class EnterpriseDefaultView : public views::View { | |
| 23 public: | |
| 24 explicit EnterpriseDefaultView(ViewClickListener* click_listener); | |
| 25 virtual ~EnterpriseDefaultView(); | |
| 26 void SetMessage(const base::string16& message); | |
| 27 private: | |
| 28 views::View* CreateChildView(const base::string16& message) const; | |
| 29 | |
| 30 ViewClickListener* click_listener_; | |
| 31 base::string16 message_; | |
| 32 | |
| 33 DISALLOW_COPY_AND_ASSIGN(EnterpriseDefaultView); | |
| 34 }; | |
| 35 | |
| 36 EnterpriseDefaultView::EnterpriseDefaultView( | |
| 37 ViewClickListener* click_listener) | |
| 38 : click_listener_(click_listener) { | |
| 39 SetLayoutManager(new views::FillLayout()); | |
| 40 SetVisible(false); | |
| 41 } | |
| 42 | |
| 43 EnterpriseDefaultView::~EnterpriseDefaultView() { | |
| 44 } | |
| 45 | |
| 46 void EnterpriseDefaultView::SetMessage(const base::string16& message) { | |
| 47 if (message_ == message) | |
| 48 return; | |
| 49 | |
| 50 message_ = message; | |
| 51 RemoveAllChildViews(true); | |
| 52 if (!message_.empty()) { | |
| 53 AddChildView(CreateChildView(message_)); | |
| 54 SetVisible(true); | |
| 55 } else { | |
| 56 SetVisible(false); | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 views::View* EnterpriseDefaultView::CreateChildView( | |
| 61 const base::string16& message) const { | |
| 62 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 63 const gfx::ImageSkia* icon = | |
| 64 rb.GetImageSkiaNamed(IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); | |
| 65 HoverHighlightView* child = new HoverHighlightView(click_listener_); | |
| 66 child->AddIconAndLabel(*icon, message, gfx::Font::NORMAL); | |
| 67 child->text_label()->SetMultiLine(true); | |
| 68 child->text_label()->SetAllowCharacterBreak(true); | |
| 69 child->set_border(views::Border::CreateEmptyBorder(0, | |
| 70 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingHorizontal)); | |
| 71 child->SetExpandable(true); | |
| 72 child->SetVisible(true); | |
| 73 return child; | |
| 74 } | |
| 75 | |
| 76 TrayEnterprise::TrayEnterprise(SystemTray* system_tray) | 16 TrayEnterprise::TrayEnterprise(SystemTray* system_tray) |
| 77 : SystemTrayItem(system_tray), | 17 : SystemTrayItem(system_tray), |
| 78 default_view_(NULL) { | 18 tray_view_(NULL) { |
| 79 Shell::GetInstance()->system_tray_notifier()-> | 19 Shell::GetInstance()->system_tray_notifier()-> |
| 80 AddEnterpriseDomainObserver(this); | 20 AddEnterpriseDomainObserver(this); |
| 81 } | 21 } |
| 82 | 22 |
| 83 TrayEnterprise::~TrayEnterprise() { | 23 TrayEnterprise::~TrayEnterprise() { |
| 84 Shell::GetInstance()->system_tray_notifier()-> | 24 Shell::GetInstance()->system_tray_notifier()-> |
| 85 RemoveEnterpriseDomainObserver(this); | 25 RemoveEnterpriseDomainObserver(this); |
| 86 } | 26 } |
| 87 | 27 |
| 88 void TrayEnterprise::UpdateEnterpriseMessage() { | 28 void TrayEnterprise::UpdateEnterpriseMessage() { |
| 89 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> | 29 base::string16 message = Shell::GetInstance()->system_tray_delegate()-> |
| 90 GetEnterpriseMessage(); | 30 GetEnterpriseMessage(); |
| 91 if (default_view_) | 31 if (tray_view_) |
| 92 default_view_->SetMessage(message); | 32 tray_view_->SetMessage(message); |
| 93 } | 33 } |
| 94 | 34 |
| 95 views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) { | 35 views::View* TrayEnterprise::CreateDefaultView(user::LoginStatus status) { |
| 96 CHECK(default_view_ == NULL); | 36 CHECK(tray_view_ == NULL); |
| 97 // For public accounts, enterprise ownership is indicated in the user details | 37 // For public accounts, enterprise ownership is indicated in the user details |
| 98 // instead. | 38 // instead. |
| 99 if (status == ash::user::LOGGED_IN_PUBLIC) | 39 if (status == ash::user::LOGGED_IN_PUBLIC) |
| 100 return NULL; | 40 return NULL; |
| 101 default_view_ = new EnterpriseDefaultView(this); | 41 tray_view_ = new LabelTrayView(this, IDR_AURA_UBER_TRAY_ENTERPRISE_DARK); |
| 102 UpdateEnterpriseMessage(); | 42 UpdateEnterpriseMessage(); |
| 103 return default_view_; | 43 return tray_view_; |
| 104 } | 44 } |
| 105 | 45 |
| 106 void TrayEnterprise::DestroyDefaultView() { | 46 void TrayEnterprise::DestroyDefaultView() { |
| 107 default_view_ = NULL; | 47 tray_view_ = NULL; |
| 108 } | 48 } |
| 109 | 49 |
| 110 void TrayEnterprise::OnEnterpriseDomainChanged() { | 50 void TrayEnterprise::OnEnterpriseDomainChanged() { |
| 111 UpdateEnterpriseMessage(); | 51 UpdateEnterpriseMessage(); |
| 112 } | 52 } |
| 113 | 53 |
| 114 void TrayEnterprise::OnViewClicked(views::View* sender) { | 54 void TrayEnterprise::OnViewClicked(views::View* sender) { |
| 115 Shell::GetInstance()->system_tray_delegate()->ShowEnterpriseInfo(); | 55 Shell::GetInstance()->system_tray_delegate()->ShowEnterpriseInfo(); |
| 116 } | 56 } |
| 117 | 57 |
| 118 } // namespace internal | 58 } // namespace internal |
| 119 } // namespace ash | 59 } // namespace ash |
| 120 | 60 |
| OLD | NEW |