OLD | NEW |
| (Empty) |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/drive/tray_drive_notice.h" | |
6 | |
7 #include "ash/shell.h" | |
8 #include "ash/system/tray/actionable_view.h" | |
9 #include "ash/system/tray/hover_highlight_view.h" | |
10 #include "ash/system/tray/system_tray.h" | |
11 #include "ash/system/tray/system_tray_delegate.h" | |
12 #include "ash/system/tray/system_tray_notifier.h" | |
13 #include "ash/system/tray/tray_constants.h" | |
14 #include "base/strings/utf_string_conversions.h" | |
15 #include "grit/ash_resources.h" | |
16 #include "grit/ash_strings.h" | |
17 #include "ui/base/l10n/l10n_util.h" | |
18 #include "ui/base/resource/resource_bundle.h" | |
19 #include "ui/views/controls/label.h" | |
20 #include "ui/views/layout/box_layout.h" | |
21 | |
22 namespace ash { | |
23 namespace internal { | |
24 | |
25 namespace { | |
26 | |
27 // Vertical spacing between notice label and the detailed view container. | |
28 const int kNoticeLabelVerticalSpacing = 3; | |
29 | |
30 // Bottom spacing inside border for notice label in detailed view. | |
31 const int kNoticeLabelBorderBottomSpacing = 5; | |
32 | |
33 // The time to show the tray item notice. | |
34 const int kTimeVisibleSeconds = 30; | |
35 | |
36 } // namespace | |
37 | |
38 class DriveNoticeDefaultView : public TrayItemMore { | |
39 public: | |
40 DriveNoticeDefaultView(SystemTrayItem* owner) : | |
41 TrayItemMore(owner, true) { | |
42 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
43 SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_DRIVE).ToImageSkia()); | |
44 SetLabel( | |
45 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DRIVE_OFFLINE_NOTICE)); | |
46 } | |
47 | |
48 virtual ~DriveNoticeDefaultView() {} | |
49 }; | |
50 | |
51 class DriveNoticeDetailedView : public TrayDetailsView, | |
52 public ViewClickListener { | |
53 public: | |
54 DriveNoticeDetailedView(SystemTrayItem* owner) | |
55 : TrayDetailsView(owner), | |
56 settings_button_(NULL) { | |
57 Reset(); | |
58 | |
59 CreateScrollableList(); | |
60 CreateNoticeLabel(); | |
61 CreateSettingsButton(); | |
62 CreateSpecialRow(IDS_ASH_STATUS_TRAY_DRIVE_OFFLINE_FOOTER, this); | |
63 | |
64 Layout(); | |
65 } | |
66 | |
67 virtual ~DriveNoticeDetailedView() {} | |
68 | |
69 private: | |
70 void CreateNoticeLabel() { | |
71 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
72 views::Label* notice_label = new views::Label( | |
73 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_DRIVE_DISABLE_OFFLINE)); | |
74 notice_label->SetLayoutManager(new views::BoxLayout( | |
75 views::BoxLayout::kHorizontal, | |
76 0, | |
77 kNoticeLabelVerticalSpacing, | |
78 kTrayPopupPaddingBetweenItems)); | |
79 notice_label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
80 notice_label->SetMultiLine(true); | |
81 notice_label->SetFont( | |
82 notice_label->font().DeriveFont(0, gfx::Font::NORMAL)); | |
83 | |
84 int margin = kTrayPopupPaddingHorizontal + | |
85 kTrayPopupDetailsLabelExtraLeftMargin; | |
86 int left_margin = base::i18n::IsRTL() ? 0 : margin; | |
87 int right_margin = base::i18n::IsRTL() ? margin : 0; | |
88 notice_label->set_border( | |
89 views::Border::CreateEmptyBorder( | |
90 kTrayPopupPaddingBetweenItems, | |
91 left_margin, | |
92 kNoticeLabelBorderBottomSpacing, | |
93 right_margin)); | |
94 | |
95 scroll_content()->AddChildView(notice_label); | |
96 } | |
97 | |
98 void CreateSettingsButton() { | |
99 HoverHighlightView* redirect_button = new HoverHighlightView(this); | |
100 redirect_button->AddLabel( | |
101 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DRIVE_SETTINGS), | |
102 gfx::Font::NORMAL); | |
103 AddChildView(redirect_button); | |
104 settings_button_ = redirect_button; | |
105 } | |
106 | |
107 // Overridden from ViewClickListener. | |
108 virtual void OnViewClicked(views::View* sender) OVERRIDE { | |
109 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | |
110 if (sender == footer()->content()) { | |
111 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
112 } else if (sender == settings_button_) { | |
113 delegate->ShowDriveSettings(); | |
114 } | |
115 } | |
116 | |
117 views::View* settings_button_; | |
118 | |
119 DISALLOW_COPY_AND_ASSIGN(DriveNoticeDetailedView); | |
120 }; | |
121 | |
122 TrayDriveNotice::TrayDriveNotice(SystemTray* system_tray) | |
123 : TrayImageItem(system_tray, IDR_AURA_UBER_TRAY_DRIVE_LIGHT), | |
124 default_view_(NULL), | |
125 detailed_view_(NULL), | |
126 showing_item_(false), | |
127 time_visible_secs_(kTimeVisibleSeconds) { | |
128 Shell::GetInstance()->system_tray_notifier()->AddDriveObserver(this); | |
129 } | |
130 | |
131 TrayDriveNotice::~TrayDriveNotice() { | |
132 Shell::GetInstance()->system_tray_notifier()->RemoveDriveObserver(this); | |
133 } | |
134 | |
135 views::View* TrayDriveNotice::GetTrayView() { | |
136 return TrayImageItem::tray_view(); | |
137 } | |
138 | |
139 void TrayDriveNotice::SetTimeVisibleForTest(int time_visible_secs) { | |
140 time_visible_secs_ = time_visible_secs; | |
141 } | |
142 | |
143 bool TrayDriveNotice::GetInitialVisibility() { | |
144 return false; | |
145 } | |
146 | |
147 views::View* TrayDriveNotice::CreateDefaultView(user::LoginStatus status) { | |
148 CHECK(default_view_ == NULL); | |
149 if (!showing_item_) | |
150 return NULL; | |
151 | |
152 default_view_ = new DriveNoticeDefaultView(this); | |
153 return default_view_; | |
154 } | |
155 | |
156 views::View* TrayDriveNotice::CreateDetailedView(user::LoginStatus status) { | |
157 if (!showing_item_) | |
158 return NULL; | |
159 | |
160 detailed_view_ = new DriveNoticeDetailedView(this); | |
161 return detailed_view_; | |
162 } | |
163 | |
164 void TrayDriveNotice::DestroyDefaultView() { | |
165 default_view_ = NULL; | |
166 } | |
167 | |
168 void TrayDriveNotice::DestroyDetailedView() { | |
169 detailed_view_ = NULL; | |
170 } | |
171 | |
172 void TrayDriveNotice::UpdateAfterLoginStatusChange(user::LoginStatus status) { | |
173 } | |
174 | |
175 void TrayDriveNotice::OnDriveJobUpdated(const DriveOperationStatus& status) { | |
176 } | |
177 | |
178 void TrayDriveNotice::OnDriveOfflineEnabled() { | |
179 showing_item_ = true; | |
180 tray_view()->SetVisible(true); | |
181 visibility_timer_.Start(FROM_HERE, | |
182 base::TimeDelta::FromSeconds(time_visible_secs_), | |
183 this, | |
184 &TrayDriveNotice::HideNotice); | |
185 } | |
186 | |
187 void TrayDriveNotice::HideNotice() { | |
188 showing_item_ = false; | |
189 tray_view()->SetVisible(false); | |
190 } | |
191 | |
192 } // namespace internal | |
193 } // namespace ash | |
OLD | NEW |