OLD | NEW |
(Empty) | |
| 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/tray_utils.h" |
| 10 #include "ash/wm/overview/window_selector_controller.h" |
| 11 #include "grit/ash_resources.h" |
| 12 #include "grit/ash_strings.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/views/border.h" |
| 16 #include "ui/views/controls/image_view.h" |
| 17 |
| 18 namespace { |
| 19 |
| 20 // Predefined padding for the icon used in this tray. These are to be set to the |
| 21 // border of the icon, depending on the current shelf_alignment() |
| 22 const int kHorizontalShelfHorizontalPadding = 8; |
| 23 const int kHorizontalShelfVerticalPadding = 4; |
| 24 const int kVerticalShelfHorizontalPadding = 2; |
| 25 const int kVerticalShelfVerticalPadding = 5; |
| 26 |
| 27 } // namespace |
| 28 |
| 29 namespace ash { |
| 30 |
| 31 OverviewButtonTray::OverviewButtonTray( |
| 32 internal::StatusAreaWidget* status_area_widget) |
| 33 : TrayBackgroundView(status_area_widget), |
| 34 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 SetVisible(Shell::GetInstance()->IsMaximizeModeWindowManagerEnabled()); |
| 45 |
| 46 Shell::GetInstance()->AddShellObserver(this); |
| 47 } |
| 48 |
| 49 OverviewButtonTray::~OverviewButtonTray() { |
| 50 Shell::GetInstance()->RemoveShellObserver(this); |
| 51 } |
| 52 |
| 53 bool OverviewButtonTray::PerformAction(const ui::Event& event) { |
| 54 Shell::GetInstance()->window_selector_controller()->ToggleOverview(); |
| 55 return true; |
| 56 } |
| 57 |
| 58 void OverviewButtonTray::OnMaximizeModeStarted() { |
| 59 SetVisible(true); |
| 60 } |
| 61 |
| 62 void OverviewButtonTray::OnMaximizeModeEnded() { |
| 63 SetVisible(false); |
| 64 } |
| 65 |
| 66 bool OverviewButtonTray::ClickedOutsideBubble() { |
| 67 // This class has no bubbles dismiss, but acknowledge that the message was |
| 68 // handled. |
| 69 return true; |
| 70 } |
| 71 |
| 72 base::string16 OverviewButtonTray::GetAccessibleNameForTray() { |
| 73 return l10n_util::GetStringUTF16(IDS_ASH_OVERVIEW_BUTTON_ACCESSIBLE_NAME); |
| 74 } |
| 75 |
| 76 void OverviewButtonTray::HideBubbleWithView( |
| 77 const views::TrayBubbleView* bubble_view) { |
| 78 // This class has no bubbles to hide. |
| 79 } |
| 80 |
| 81 void OverviewButtonTray::SetShelfAlignment(ShelfAlignment alignment) { |
| 82 if (alignment == shelf_alignment()) |
| 83 return; |
| 84 |
| 85 TrayBackgroundView::SetShelfAlignment(alignment); |
| 86 SetIconBorderForShelfAlignment(); |
| 87 } |
| 88 |
| 89 void OverviewButtonTray::SetIconBorderForShelfAlignment() { |
| 90 if (shelf_alignment() == SHELF_ALIGNMENT_BOTTOM || |
| 91 shelf_alignment() == SHELF_ALIGNMENT_TOP) { |
| 92 icon_->SetBorder(views::Border::CreateEmptyBorder( |
| 93 kHorizontalShelfVerticalPadding, |
| 94 kHorizontalShelfHorizontalPadding, |
| 95 kHorizontalShelfVerticalPadding, |
| 96 kHorizontalShelfHorizontalPadding)); |
| 97 } else { |
| 98 icon_->SetBorder(views::Border::CreateEmptyBorder( |
| 99 kVerticalShelfVerticalPadding, |
| 100 kVerticalShelfHorizontalPadding, |
| 101 kVerticalShelfVerticalPadding, |
| 102 kVerticalShelfHorizontalPadding)); |
| 103 } |
| 104 } |
| 105 |
| 106 } // namespace ash |
OLD | NEW |