Home | History | Annotate | Download | only in overview
      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/overview/overview_button_tray.h"
      6 
      7 #include "ash/shelf/shelf_types.h"
      8 #include "ash/shell.h"
      9 #include "ash/system/tray/system_tray_delegate.h"
     10 #include "ash/system/tray/tray_utils.h"
     11 #include "ash/wm/maximize_mode/maximize_mode_controller.h"
     12 #include "ash/wm/overview/window_selector_controller.h"
     13 #include "grit/ash_resources.h"
     14 #include "grit/ash_strings.h"
     15 #include "ui/base/l10n/l10n_util.h"
     16 #include "ui/base/resource/resource_bundle.h"
     17 #include "ui/views/border.h"
     18 #include "ui/views/controls/image_view.h"
     19 
     20 namespace {
     21 
     22 // Predefined padding for the icon used in this tray. These are to be set to the
     23 // border of the icon, depending on the current shelf_alignment()
     24 const int kHorizontalShelfHorizontalPadding = 8;
     25 const int kHorizontalShelfVerticalPadding = 4;
     26 const int kVerticalShelfHorizontalPadding = 2;
     27 const int kVerticalShelfVerticalPadding = 5;
     28 
     29 }  // namespace
     30 
     31 namespace ash {
     32 
     33 OverviewButtonTray::OverviewButtonTray(StatusAreaWidget* status_area_widget)
     34     : TrayBackgroundView(status_area_widget), icon_(NULL) {
     35   SetContentsBackground();
     36 
     37   ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
     38   icon_ = new views::ImageView();
     39   icon_->SetImage(
     40       bundle.GetImageNamed(IDR_AURA_UBER_TRAY_OVERVIEW_MODE).ToImageSkia());
     41   SetIconBorderForShelfAlignment();
     42   tray_container()->AddChildView(icon_);
     43 
     44   Shell::GetInstance()->AddShellObserver(this);
     45 }
     46 
     47 OverviewButtonTray::~OverviewButtonTray() {
     48   Shell::GetInstance()->RemoveShellObserver(this);
     49 }
     50 
     51 void OverviewButtonTray::UpdateAfterLoginStatusChange(
     52     user::LoginStatus status) {
     53   UpdateIconVisibility();
     54 }
     55 
     56 bool OverviewButtonTray::PerformAction(const ui::Event& event) {
     57   Shell::GetInstance()->window_selector_controller()->ToggleOverview();
     58   return true;
     59 }
     60 
     61 void OverviewButtonTray::OnMaximizeModeStarted() {
     62   UpdateIconVisibility();
     63 }
     64 
     65 void OverviewButtonTray::OnMaximizeModeEnded() {
     66   UpdateIconVisibility();
     67 }
     68 
     69 bool OverviewButtonTray::ClickedOutsideBubble() {
     70   // This class has no bubbles dismiss, but acknowledge that the message was
     71   // handled.
     72   return true;
     73 }
     74 
     75 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
     76   return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
     77 }
     78 
     79 void OverviewButtonTray::HideBubbleWithView(
     80     const views::TrayBubbleView* bubble_view) {
     81   // This class has no bubbles to hide.
     82 }
     83 
     84 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
     85   if (alignment == shelf_alignment())
     86     return;
     87 
     88   TrayBackgroundView::SetShelfAlignment(alignment);
     89   SetIconBorderForShelfAlignment();
     90 }
     91 
     92 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
     93   if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM ||
     94       shelf_alignment() == SHELF_ALIGNMENT_TOP) {
     95     icon_->SetBorder(views::Border::CreateEmptyBorder(
     96         kHorizontalShelfVerticalPadding,
     97         kHorizontalShelfHorizontalPadding,
     98         kHorizontalShelfVerticalPadding,
     99         kHorizontalShelfHorizontalPadding));
    100   } else {
    101     icon_->SetBorder(views::Border::CreateEmptyBorder(
    102         kVerticalShelfVerticalPadding,
    103         kVerticalShelfHorizontalPadding,
    104         kVerticalShelfVerticalPadding,
    105         kVerticalShelfHorizontalPadding));
    106   }
    107 }
    108 
    109 void OverviewButtonTray::UpdateIconVisibility() {
    110   SetVisible(Shell::GetInstance()->maximize_mode_controller()->
    111                  IsMaximizeModeWindowManagerEnabled() &&
    112              Shell::GetInstance()->window_selector_controller()->CanSelect());
    113 }
    114 
    115 }  // namespace ash
    116