tray_date.cc revision 5821806d5e7f356e8fa4b058a389a808ea183019
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 3// found in the LICENSE file. 4 5#include "ash/system/date/tray_date.h" 6 7#include "ash/shell.h" 8#include "ash/system/date/date_view.h" 9#include "ash/system/tray/system_tray.h" 10#include "ash/system/tray/system_tray_delegate.h" 11#include "ash/system/tray/tray_constants.h" 12#include "ash/system/tray/tray_item_view.h" 13#include "ash/system/tray/tray_views.h" 14#include "base/i18n/time_formatting.h" 15#include "base/stringprintf.h" 16#include "base/time.h" 17#include "base/timer.h" 18#include "base/utf_string_conversions.h" 19#include "grit/ash_resources.h" 20#include "grit/ash_strings.h" 21#include "third_party/skia/include/core/SkRect.h" 22#include "ui/base/resource/resource_bundle.h" 23#include "ui/gfx/image/image.h" 24#include "ui/gfx/image/image_skia.h" 25#include "ui/gfx/size.h" 26#include "ui/views/controls/button/button.h" 27#include "ui/views/controls/button/text_button.h" 28#include "ui/views/controls/image_view.h" 29#include "ui/views/controls/label.h" 30#include "ui/views/layout/box_layout.h" 31#include "ui/views/layout/fill_layout.h" 32#include "ui/views/painter.h" 33#include "ui/views/view.h" 34#include "ui/views/widget/widget.h" 35#include "unicode/datefmt.h" 36#include "unicode/fieldpos.h" 37#include "unicode/fmtable.h" 38 39namespace { 40 41const int kPaddingVertical = 19; 42 43class DateDefaultView : public views::View, 44 public views::ButtonListener { 45 public: 46 explicit DateDefaultView(ash::user::LoginStatus login) 47 : help_(NULL), 48 shutdown_(NULL), 49 lock_(NULL) { 50 SetLayoutManager(new views::FillLayout); 51 52 ash::internal::tray::DateView* date_view = 53 new ash::internal::tray::DateView(); 54 date_view->set_border(views::Border::CreateEmptyBorder(kPaddingVertical, 55 ash::kTrayPopupPaddingHorizontal, 56 0, 57 0)); 58 ash::internal::SpecialPopupRow* view = new ash::internal::SpecialPopupRow(); 59 view->SetContent(date_view); 60 AddChildView(view); 61 62 if (login == ash::user::LOGGED_IN_LOCKED || 63 login == ash::user::LOGGED_IN_NONE) 64 return; 65 66 date_view->SetActionable(true); 67 68 help_ = new ash::internal::TrayPopupHeaderButton(this, 69 IDR_AURA_UBER_TRAY_HELP, 70 IDR_AURA_UBER_TRAY_HELP, 71 IDR_AURA_UBER_TRAY_HELP_HOVER, 72 IDR_AURA_UBER_TRAY_HELP_HOVER, 73 IDS_ASH_STATUS_TRAY_HELP); 74 view->AddButton(help_); 75 76 if (login != ash::user::LOGGED_IN_LOCKED && 77 login != ash::user::LOGGED_IN_KIOSK) { 78 shutdown_ = new ash::internal::TrayPopupHeaderButton(this, 79 IDR_AURA_UBER_TRAY_SHUTDOWN, 80 IDR_AURA_UBER_TRAY_SHUTDOWN, 81 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, 82 IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER, 83 IDS_ASH_STATUS_TRAY_SHUTDOWN); 84 view->AddButton(shutdown_); 85 86 if (login != ash::user::LOGGED_IN_GUEST) { 87 lock_ = new ash::internal::TrayPopupHeaderButton(this, 88 IDR_AURA_UBER_TRAY_LOCKSCREEN, 89 IDR_AURA_UBER_TRAY_LOCKSCREEN, 90 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, 91 IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER, 92 IDS_ASH_STATUS_TRAY_LOCK); 93 view->AddButton(lock_); 94 } 95 } 96 } 97 98 virtual ~DateDefaultView() {} 99 100 private: 101 // Overridden from views::ButtonListener. 102 virtual void ButtonPressed(views::Button* sender, 103 const ui::Event& event) OVERRIDE { 104 ash::SystemTrayDelegate* tray = ash::Shell::GetInstance()->tray_delegate(); 105 if (sender == help_) 106 tray->ShowHelp(); 107 else if (sender == shutdown_) 108 tray->ShutDown(); 109 else if (sender == lock_) 110 tray->RequestLockScreen(); 111 else 112 NOTREACHED(); 113 } 114 115 ash::internal::TrayPopupHeaderButton* help_; 116 ash::internal::TrayPopupHeaderButton* shutdown_; 117 ash::internal::TrayPopupHeaderButton* lock_; 118 119 DISALLOW_COPY_AND_ASSIGN(DateDefaultView); 120}; 121 122} // namespace 123 124namespace ash { 125namespace internal { 126 127TrayDate::TrayDate() 128 : time_tray_(NULL) { 129} 130 131TrayDate::~TrayDate() { 132} 133 134views::View* TrayDate::CreateTrayView(user::LoginStatus status) { 135 CHECK(time_tray_ == NULL); 136 ClockLayout clock_layout = 137 ash::Shell::GetInstance()->system_tray()->shelf_alignment() == 138 SHELF_ALIGNMENT_BOTTOM ? 139 HORIZONTAL_CLOCK : VERTICAL_CLOCK; 140 time_tray_ = new tray::TimeView(clock_layout); 141 views::View* view = new TrayItemView; 142 view->AddChildView(time_tray_); 143 return view; 144} 145 146views::View* TrayDate::CreateDefaultView(user::LoginStatus status) { 147 return new DateDefaultView(status); 148} 149 150views::View* TrayDate::CreateDetailedView(user::LoginStatus status) { 151 return NULL; 152} 153 154void TrayDate::DestroyTrayView() { 155 time_tray_ = NULL; 156} 157 158void TrayDate::DestroyDefaultView() { 159} 160 161void TrayDate::DestroyDetailedView() { 162} 163 164void TrayDate::UpdateAfterLoginStatusChange(user::LoginStatus status) { 165} 166 167void TrayDate::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { 168 if (time_tray_) { 169 ClockLayout clock_layout = alignment == SHELF_ALIGNMENT_BOTTOM ? 170 HORIZONTAL_CLOCK : VERTICAL_CLOCK; 171 time_tray_->UpdateClockLayout(clock_layout); 172 } 173} 174 175void TrayDate::OnDateFormatChanged() { 176 if (time_tray_) 177 time_tray_->UpdateTimeFormat(); 178} 179 180void TrayDate::Refresh() { 181 if (time_tray_) 182 time_tray_->UpdateText(); 183} 184 185} // namespace internal 186} // namespace ash 187