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   WindowSelectorController* controller =
     58       Shell::GetInstance()->window_selector_controller();
     59   controller->ToggleOverview();
     60   SetDrawBackgroundAsActive(controller->IsSelecting());
     61   return true;
     62 }
     63 
     64 void OverviewButtonTray::OnMaximizeModeStarted() {
     65   UpdateIconVisibility();
     66 }
     67 
     68 void OverviewButtonTray::OnMaximizeModeEnded() {
     69   UpdateIconVisibility();
     70 }
     71 
     72 bool OverviewButtonTray::ClickedOutsideBubble() {
     73   // This class has no bubbles dismiss, but acknowledge that the message was
     74   // handled.
     75   return true;
     76 }
     77 
     78 base::string16 OverviewButtonTray::GetAccessibleNameForTray() {
     79   return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME);
     80 }
     81 
     82 void OverviewButtonTray::HideBubbleWithView(
     83     const views::TrayBubbleView* bubble_view) {
     84   // This class has no bubbles to hide.
     85 }
     86 
     87 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) {
     88   if (alignment == shelf_alignment())
     89     return;
     90 
     91   TrayBackgroundView::SetShelfAlignment(alignment);
     92   SetIconBorderForShelfAlignment();
     93 }
     94 
     95 void OverviewButtonTray::SetIconBorderForShelfAlignment() {
     96   if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM ||
     97       shelf_alignment() == SHELF_ALIGNMENT_TOP) {
     98     icon_->SetBorder(views::Border::CreateEmptyBorder(
     99         kHorizontalShelfVerticalPadding,
    100         kHorizontalShelfHorizontalPadding,
    101         kHorizontalShelfVerticalPadding,
    102         kHorizontalShelfHorizontalPadding));
    103   } else {
    104     icon_->SetBorder(views::Border::CreateEmptyBorder(
    105         kVerticalShelfVerticalPadding,
    106         kVerticalShelfHorizontalPadding,
    107         kVerticalShelfVerticalPadding,
    108         kVerticalShelfHorizontalPadding));
    109   }
    110 }
    111 
    112 void OverviewButtonTray::UpdateIconVisibility() {
    113   SetVisible(Shell::GetInstance()->maximize_mode_controller()->
    114                  IsMaximizeModeWindowManagerEnabled() &&
    115              Shell::GetInstance()->window_selector_controller()->CanSelect());
    116 }
    117 
    118 }  // namespace ash
    119