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