| 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/status_area_widget.h" |    5 #include "ash/system/status_area_widget.h" | 
|    6  |    6  | 
|    7 #include "ash/common/shelf/wm_shelf.h" |    7 #include "ash/common/shelf/wm_shelf.h" | 
|    8 #include "ash/common/shell_window_ids.h" |    8 #include "ash/common/shell_window_ids.h" | 
|    9 #include "ash/common/system/status_area_widget_delegate.h" |    9 #include "ash/common/system/status_area_widget_delegate.h" | 
|   10 #include "ash/common/system/tray/system_tray_delegate.h" |   10 #include "ash/common/system/tray/system_tray_delegate.h" | 
|   11 #include "ash/common/system/web_notification/web_notification_tray.h" |   11 #include "ash/common/system/web_notification/web_notification_tray.h" | 
|   12 #include "ash/common/wm_lookup.h" |   12 #include "ash/common/wm_lookup.h" | 
|   13 #include "ash/common/wm_root_window_controller.h" |   13 #include "ash/common/wm_root_window_controller.h" | 
|   14 #include "ash/common/wm_shell.h" |   14 #include "ash/common/wm_shell.h" | 
|   15 #include "ash/common/wm_window.h" |   15 #include "ash/common/wm_window.h" | 
|   16 #include "ash/system/overview/overview_button_tray.h" |   16 #include "ash/system/overview/overview_button_tray.h" | 
|   17 #include "ash/system/tray/system_tray.h" |   17 #include "ash/system/tray/system_tray.h" | 
|   18 #include "base/i18n/time_formatting.h" |   18 #include "base/i18n/time_formatting.h" | 
|   19  |   19  | 
|   20 #if defined(OS_CHROMEOS) |   20 #if defined(OS_CHROMEOS) | 
|   21 #include "ash/common/system/chromeos/session/logout_button_tray.h" |   21 #include "ash/common/system/chromeos/session/logout_button_tray.h" | 
|   22 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" |   22 #include "ash/common/system/chromeos/virtual_keyboard/virtual_keyboard_tray.h" | 
 |   23 #include "ash/system/chromeos/ime_menu/ime_menu_tray.h" | 
|   23 #endif |   24 #endif | 
|   24  |   25  | 
|   25 namespace ash { |   26 namespace ash { | 
|   26  |   27  | 
|   27 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, |   28 StatusAreaWidget::StatusAreaWidget(WmWindow* status_container, | 
|   28                                    WmShelf* wm_shelf) |   29                                    WmShelf* wm_shelf) | 
|   29     : status_area_widget_delegate_(new StatusAreaWidgetDelegate), |   30     : status_area_widget_delegate_(new StatusAreaWidgetDelegate), | 
|   30       overview_button_tray_(NULL), |   31       overview_button_tray_(NULL), | 
|   31       system_tray_(NULL), |   32       system_tray_(NULL), | 
|   32       web_notification_tray_(NULL), |   33       web_notification_tray_(NULL), | 
|   33 #if defined(OS_CHROMEOS) |   34 #if defined(OS_CHROMEOS) | 
|   34       logout_button_tray_(NULL), |   35       logout_button_tray_(NULL), | 
|   35       virtual_keyboard_tray_(NULL), |   36       virtual_keyboard_tray_(NULL), | 
 |   37       ime_menu_tray_(nullptr), | 
|   36 #endif |   38 #endif | 
|   37       login_status_(LoginStatus::NOT_LOGGED_IN), |   39       login_status_(LoginStatus::NOT_LOGGED_IN), | 
|   38       wm_shelf_(wm_shelf) { |   40       wm_shelf_(wm_shelf) { | 
|   39   views::Widget::InitParams params( |   41   views::Widget::InitParams params( | 
|   40       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); |   42       views::Widget::InitParams::TYPE_WINDOW_FRAMELESS); | 
|   41   params.delegate = status_area_widget_delegate_; |   43   params.delegate = status_area_widget_delegate_; | 
|   42   params.name = "StatusAreaWidget"; |   44   params.name = "StatusAreaWidget"; | 
|   43   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |   45   params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; | 
|   44   status_container->GetRootWindowController() |   46   status_container->GetRootWindowController() | 
|   45       ->ConfigureWidgetInitParamsForContainer( |   47       ->ConfigureWidgetInitParamsForContainer( | 
|   46           this, status_container->GetShellWindowId(), ¶ms); |   48           this, status_container->GetShellWindowId(), ¶ms); | 
|   47   Init(params); |   49   Init(params); | 
|   48   set_focus_on_creation(false); |   50   set_focus_on_creation(false); | 
|   49   SetContentsView(status_area_widget_delegate_); |   51   SetContentsView(status_area_widget_delegate_); | 
|   50 } |   52 } | 
|   51  |   53  | 
|   52 StatusAreaWidget::~StatusAreaWidget() {} |   54 StatusAreaWidget::~StatusAreaWidget() {} | 
|   53  |   55  | 
|   54 void StatusAreaWidget::CreateTrayViews() { |   56 void StatusAreaWidget::CreateTrayViews() { | 
|   55   AddOverviewButtonTray(); |   57   AddOverviewButtonTray(); | 
|   56   AddSystemTray(); |   58   AddSystemTray(); | 
|   57   AddWebNotificationTray(); |   59   AddWebNotificationTray(); | 
|   58 #if defined(OS_CHROMEOS) |   60 #if defined(OS_CHROMEOS) | 
|   59   AddLogoutButtonTray(); |   61   AddLogoutButtonTray(); | 
|   60   AddVirtualKeyboardTray(); |   62   AddVirtualKeyboardTray(); | 
 |   63   AddImeMenuTray(); | 
|   61 #endif |   64 #endif | 
|   62  |   65  | 
|   63   SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); |   66   SystemTrayDelegate* delegate = WmShell::Get()->system_tray_delegate(); | 
|   64   DCHECK(delegate); |   67   DCHECK(delegate); | 
|   65   // Initialize after all trays have been created. |   68   // Initialize after all trays have been created. | 
|   66   system_tray_->InitializeTrayItems(delegate, web_notification_tray_); |   69   system_tray_->InitializeTrayItems(delegate, web_notification_tray_); | 
|   67   web_notification_tray_->Initialize(); |   70   web_notification_tray_->Initialize(); | 
|   68 #if defined(OS_CHROMEOS) |   71 #if defined(OS_CHROMEOS) | 
|   69   logout_button_tray_->Initialize(); |   72   logout_button_tray_->Initialize(); | 
|   70   virtual_keyboard_tray_->Initialize(); |   73   virtual_keyboard_tray_->Initialize(); | 
 |   74   ime_menu_tray_->Initialize(); | 
|   71 #endif |   75 #endif | 
|   72   overview_button_tray_->Initialize(); |   76   overview_button_tray_->Initialize(); | 
|   73   SetShelfAlignment(system_tray_->shelf_alignment()); |   77   SetShelfAlignment(system_tray_->shelf_alignment()); | 
|   74   UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); |   78   UpdateAfterLoginStatusChange(delegate->GetUserLoginStatus()); | 
|   75 } |   79 } | 
|   76  |   80  | 
|   77 void StatusAreaWidget::Shutdown() { |   81 void StatusAreaWidget::Shutdown() { | 
|   78   system_tray_->Shutdown(); |   82   system_tray_->Shutdown(); | 
|   79   // Destroy the trays early, causing them to be removed from the view |   83   // Destroy the trays early, causing them to be removed from the view | 
|   80   // hierarchy. Do not used scoped pointers since we don't want to destroy them |   84   // hierarchy. Do not used scoped pointers since we don't want to destroy them | 
|   81   // in the destructor if Shutdown() is not called (e.g. in tests). |   85   // in the destructor if Shutdown() is not called (e.g. in tests). | 
|   82   delete web_notification_tray_; |   86   delete web_notification_tray_; | 
|   83   web_notification_tray_ = NULL; |   87   web_notification_tray_ = NULL; | 
|   84   // Must be destroyed after |web_notification_tray_|. |   88   // Must be destroyed after |web_notification_tray_|. | 
|   85   delete system_tray_; |   89   delete system_tray_; | 
|   86   system_tray_ = NULL; |   90   system_tray_ = NULL; | 
|   87 #if defined(OS_CHROMEOS) |   91 #if defined(OS_CHROMEOS) | 
 |   92   delete ime_menu_tray_; | 
 |   93   ime_menu_tray_ = nullptr; | 
|   88   delete virtual_keyboard_tray_; |   94   delete virtual_keyboard_tray_; | 
|   89   virtual_keyboard_tray_ = NULL; |   95   virtual_keyboard_tray_ = NULL; | 
|   90   delete logout_button_tray_; |   96   delete logout_button_tray_; | 
|   91   logout_button_tray_ = NULL; |   97   logout_button_tray_ = NULL; | 
|   92 #endif |   98 #endif | 
|   93   delete overview_button_tray_; |   99   delete overview_button_tray_; | 
|   94   overview_button_tray_ = NULL; |  100   overview_button_tray_ = NULL; | 
|   95 } |  101 } | 
|   96  |  102  | 
|   97 bool StatusAreaWidget::ShouldShowShelf() const { |  103 bool StatusAreaWidget::ShouldShowShelf() const { | 
| (...skipping 18 matching lines...) Expand all  Loading... | 
|  116            web_notification_tray_->IsMessageCenterBubbleVisible())); |  122            web_notification_tray_->IsMessageCenterBubbleVisible())); | 
|  117 } |  123 } | 
|  118  |  124  | 
|  119 void StatusAreaWidget::SchedulePaint() { |  125 void StatusAreaWidget::SchedulePaint() { | 
|  120   status_area_widget_delegate_->SchedulePaint(); |  126   status_area_widget_delegate_->SchedulePaint(); | 
|  121   web_notification_tray_->SchedulePaint(); |  127   web_notification_tray_->SchedulePaint(); | 
|  122   system_tray_->SchedulePaint(); |  128   system_tray_->SchedulePaint(); | 
|  123 #if defined(OS_CHROMEOS) |  129 #if defined(OS_CHROMEOS) | 
|  124   virtual_keyboard_tray_->SchedulePaint(); |  130   virtual_keyboard_tray_->SchedulePaint(); | 
|  125   logout_button_tray_->SchedulePaint(); |  131   logout_button_tray_->SchedulePaint(); | 
 |  132   ime_menu_tray_->SchedulePaint(); | 
|  126 #endif |  133 #endif | 
|  127   overview_button_tray_->SchedulePaint(); |  134   overview_button_tray_->SchedulePaint(); | 
|  128 } |  135 } | 
|  129  |  136  | 
|  130 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { |  137 void StatusAreaWidget::OnNativeWidgetActivationChanged(bool active) { | 
|  131   Widget::OnNativeWidgetActivationChanged(active); |  138   Widget::OnNativeWidgetActivationChanged(active); | 
|  132   if (active) |  139   if (active) | 
|  133     status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); |  140     status_area_widget_delegate_->SetPaneFocusAndFocusDefault(); | 
|  134 } |  141 } | 
|  135  |  142  | 
| (...skipping 22 matching lines...) Expand all  Loading... | 
|  158 #if defined(OS_CHROMEOS) |  165 #if defined(OS_CHROMEOS) | 
|  159 void StatusAreaWidget::AddLogoutButtonTray() { |  166 void StatusAreaWidget::AddLogoutButtonTray() { | 
|  160   logout_button_tray_ = new LogoutButtonTray(wm_shelf_); |  167   logout_button_tray_ = new LogoutButtonTray(wm_shelf_); | 
|  161   status_area_widget_delegate_->AddTray(logout_button_tray_); |  168   status_area_widget_delegate_->AddTray(logout_button_tray_); | 
|  162 } |  169 } | 
|  163  |  170  | 
|  164 void StatusAreaWidget::AddVirtualKeyboardTray() { |  171 void StatusAreaWidget::AddVirtualKeyboardTray() { | 
|  165   virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); |  172   virtual_keyboard_tray_ = new VirtualKeyboardTray(wm_shelf_); | 
|  166   status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); |  173   status_area_widget_delegate_->AddTray(virtual_keyboard_tray_); | 
|  167 } |  174 } | 
 |  175  | 
 |  176 void StatusAreaWidget::AddImeMenuTray() { | 
 |  177   ime_menu_tray_ = new ImeMenuTray(this); | 
 |  178   status_area_widget_delegate_->AddTray(ime_menu_tray_); | 
 |  179 } | 
|  168 #endif |  180 #endif | 
|  169  |  181  | 
|  170 void StatusAreaWidget::AddOverviewButtonTray() { |  182 void StatusAreaWidget::AddOverviewButtonTray() { | 
|  171   overview_button_tray_ = new OverviewButtonTray(wm_shelf_); |  183   overview_button_tray_ = new OverviewButtonTray(wm_shelf_); | 
|  172   status_area_widget_delegate_->AddTray(overview_button_tray_); |  184   status_area_widget_delegate_->AddTray(overview_button_tray_); | 
|  173 } |  185 } | 
|  174  |  186  | 
|  175 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { |  187 void StatusAreaWidget::SetShelfAlignment(ShelfAlignment alignment) { | 
|  176   status_area_widget_delegate_->set_alignment(alignment); |  188   status_area_widget_delegate_->set_alignment(alignment); | 
|  177   if (system_tray_) |  189   if (system_tray_) | 
|  178     system_tray_->SetShelfAlignment(alignment); |  190     system_tray_->SetShelfAlignment(alignment); | 
|  179   if (web_notification_tray_) |  191   if (web_notification_tray_) | 
|  180     web_notification_tray_->SetShelfAlignment(alignment); |  192     web_notification_tray_->SetShelfAlignment(alignment); | 
|  181 #if defined(OS_CHROMEOS) |  193 #if defined(OS_CHROMEOS) | 
|  182   if (logout_button_tray_) |  194   if (logout_button_tray_) | 
|  183     logout_button_tray_->SetShelfAlignment(alignment); |  195     logout_button_tray_->SetShelfAlignment(alignment); | 
|  184   if (virtual_keyboard_tray_) |  196   if (virtual_keyboard_tray_) | 
|  185     virtual_keyboard_tray_->SetShelfAlignment(alignment); |  197     virtual_keyboard_tray_->SetShelfAlignment(alignment); | 
 |  198   if (ime_menu_tray_) | 
 |  199     ime_menu_tray_->SetShelfAlignment(alignment); | 
|  186 #endif |  200 #endif | 
|  187   if (overview_button_tray_) |  201   if (overview_button_tray_) | 
|  188     overview_button_tray_->SetShelfAlignment(alignment); |  202     overview_button_tray_->SetShelfAlignment(alignment); | 
|  189   status_area_widget_delegate_->UpdateLayout(); |  203   status_area_widget_delegate_->UpdateLayout(); | 
|  190 } |  204 } | 
|  191  |  205  | 
|  192 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { |  206 void StatusAreaWidget::UpdateAfterLoginStatusChange(LoginStatus login_status) { | 
|  193   if (login_status_ == login_status) |  207   if (login_status_ == login_status) | 
|  194     return; |  208     return; | 
|  195   login_status_ = login_status; |  209   login_status_ = login_status; | 
|  196   if (system_tray_) |  210   if (system_tray_) | 
|  197     system_tray_->UpdateAfterLoginStatusChange(login_status); |  211     system_tray_->UpdateAfterLoginStatusChange(login_status); | 
|  198   if (web_notification_tray_) |  212   if (web_notification_tray_) | 
|  199     web_notification_tray_->UpdateAfterLoginStatusChange(login_status); |  213     web_notification_tray_->UpdateAfterLoginStatusChange(login_status); | 
|  200 #if defined(OS_CHROMEOS) |  214 #if defined(OS_CHROMEOS) | 
|  201   if (logout_button_tray_) |  215   if (logout_button_tray_) | 
|  202     logout_button_tray_->UpdateAfterLoginStatusChange(login_status); |  216     logout_button_tray_->UpdateAfterLoginStatusChange(login_status); | 
|  203 #endif |  217 #endif | 
|  204   if (overview_button_tray_) |  218   if (overview_button_tray_) | 
|  205     overview_button_tray_->UpdateAfterLoginStatusChange(login_status); |  219     overview_button_tray_->UpdateAfterLoginStatusChange(login_status); | 
|  206 } |  220 } | 
|  207  |  221  | 
|  208 }  // namespace ash |  222 }  // namespace ash | 
| OLD | NEW |