Home | History | Annotate | Download | only in date
      1 // Copyright 2014 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/date_default_view.h"
      6 
      7 #include "ash/metrics/user_metrics_recorder.h"
      8 #include "ash/session/session_state_delegate.h"
      9 #include "ash/shell.h"
     10 #include "ash/system/date/date_view.h"
     11 #include "ash/system/tray/special_popup_row.h"
     12 #include "ash/system/tray/system_tray_delegate.h"
     13 #include "ash/system/tray/tray_constants.h"
     14 #include "ash/system/tray/tray_popup_header_button.h"
     15 #include "grit/ash_resources.h"
     16 #include "grit/ash_strings.h"
     17 #include "ui/base/l10n/l10n_util.h"
     18 #include "ui/views/border.h"
     19 #include "ui/views/controls/button/button.h"
     20 #include "ui/views/layout/fill_layout.h"
     21 #include "ui/views/view.h"
     22 
     23 namespace {
     24 
     25 const int kPaddingVertical = 19;
     26 
     27 }  // namespace
     28 
     29 namespace ash {
     30 
     31 DateDefaultView::DateDefaultView(ash::user::LoginStatus login)
     32     : help_(NULL),
     33       shutdown_(NULL),
     34       lock_(NULL),
     35       date_view_(NULL) {
     36   SetLayoutManager(new views::FillLayout);
     37 
     38   date_view_ = new tray::DateView();
     39   date_view_->SetBorder(views::Border::CreateEmptyBorder(
     40       kPaddingVertical, ash::kTrayPopupPaddingHorizontal, 0, 0));
     41   SpecialPopupRow* view = new SpecialPopupRow();
     42   view->SetContent(date_view_);
     43   AddChildView(view);
     44 
     45   if (login == ash::user::LOGGED_IN_LOCKED ||
     46       login == ash::user::LOGGED_IN_NONE)
     47     return;
     48 
     49   date_view_->SetAction(TrayDate::SHOW_DATE_SETTINGS);
     50 
     51   help_ = new TrayPopupHeaderButton(this,
     52                                     IDR_AURA_UBER_TRAY_HELP,
     53                                     IDR_AURA_UBER_TRAY_HELP,
     54                                     IDR_AURA_UBER_TRAY_HELP_HOVER,
     55                                     IDR_AURA_UBER_TRAY_HELP_HOVER,
     56                                     IDS_ASH_STATUS_TRAY_HELP);
     57   help_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_HELP));
     58   view->AddButton(help_);
     59 
     60 #if !defined(OS_WIN)
     61   if (login != ash::user::LOGGED_IN_LOCKED &&
     62       login != ash::user::LOGGED_IN_RETAIL_MODE) {
     63     shutdown_ = new TrayPopupHeaderButton(this,
     64                                           IDR_AURA_UBER_TRAY_SHUTDOWN,
     65                                           IDR_AURA_UBER_TRAY_SHUTDOWN,
     66                                           IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
     67                                           IDR_AURA_UBER_TRAY_SHUTDOWN_HOVER,
     68                                           IDS_ASH_STATUS_TRAY_SHUTDOWN);
     69     shutdown_->SetTooltipText(
     70         l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_SHUTDOWN));
     71     view->AddButton(shutdown_);
     72   }
     73 
     74   if (ash::Shell::GetInstance()->session_state_delegate()->CanLockScreen()) {
     75     lock_ = new TrayPopupHeaderButton(this,
     76                                       IDR_AURA_UBER_TRAY_LOCKSCREEN,
     77                                       IDR_AURA_UBER_TRAY_LOCKSCREEN,
     78                                       IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
     79                                       IDR_AURA_UBER_TRAY_LOCKSCREEN_HOVER,
     80                                       IDS_ASH_STATUS_TRAY_LOCK);
     81     lock_->SetTooltipText(l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_LOCK));
     82     view->AddButton(lock_);
     83   }
     84 #endif  // !defined(OS_WIN)
     85 }
     86 
     87 DateDefaultView::~DateDefaultView() {
     88 }
     89 
     90 views::View* DateDefaultView::GetHelpButtonView() {
     91   return help_;
     92 }
     93 
     94 tray::DateView* DateDefaultView::GetDateView() {
     95   return date_view_;
     96 }
     97 
     98 const tray::DateView* DateDefaultView::GetDateView() const {
     99   return date_view_;
    100 }
    101 
    102 void DateDefaultView::ButtonPressed(views::Button* sender,
    103                                     const ui::Event& event) {
    104   ash::Shell* shell = ash::Shell::GetInstance();
    105   ash::SystemTrayDelegate* tray_delegate = shell->system_tray_delegate();
    106   if (sender == help_) {
    107     shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_HELP);
    108     tray_delegate->ShowHelp();
    109   } else if (sender == shutdown_) {
    110     shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_SHUT_DOWN);
    111     tray_delegate->ShutDown();
    112   } else if (sender == lock_) {
    113     shell->metrics()->RecordUserMetricsAction(ash::UMA_TRAY_LOCK_SCREEN);
    114     tray_delegate->RequestLockScreen();
    115   } else {
    116     NOTREACHED();
    117   }
    118 }
    119 
    120 }  // namespace ash
    121