| OLD | NEW |
| (Empty) |
| 1 // Copyright 2013 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/common/system/chromeos/screen_security/screen_tray_item.h" | |
| 6 | |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | |
| 9 #include "ash/common/system/tray/fixed_sized_image_view.h" | |
| 10 #include "ash/common/system/tray/tray_constants.h" | |
| 11 #include "ash/common/system/tray/tray_popup_item_style.h" | |
| 12 #include "ash/common/system/tray/tray_popup_utils.h" | |
| 13 #include "ash/resources/grit/ash_resources.h" | |
| 14 #include "ash/resources/vector_icons/vector_icons.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | |
| 16 #include "ui/gfx/paint_vector_icon.h" | |
| 17 #include "ui/message_center/message_center.h" | |
| 18 #include "ui/views/controls/button/label_button.h" | |
| 19 #include "ui/views/controls/label.h" | |
| 20 #include "ui/views/layout/fill_layout.h" | |
| 21 | |
| 22 namespace ash { | |
| 23 namespace tray { | |
| 24 | |
| 25 // ScreenTrayView implementations. | |
| 26 ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item) | |
| 27 : TrayItemView(screen_tray_item), screen_tray_item_(screen_tray_item) { | |
| 28 CreateImageView(); | |
| 29 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | |
| 30 image_view()->SetImage( | |
| 31 gfx::CreateVectorIcon(kSystemTrayScreenShareIcon, kTrayIconColor)); | |
| 32 } else { | |
| 33 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 34 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) | |
| 35 .ToImageSkia()); | |
| 36 } | |
| 37 Update(); | |
| 38 } | |
| 39 | |
| 40 ScreenTrayView::~ScreenTrayView() {} | |
| 41 | |
| 42 void ScreenTrayView::Update() { | |
| 43 SetVisible(screen_tray_item_->is_started()); | |
| 44 } | |
| 45 | |
| 46 // ScreenStatusView implementations. | |
| 47 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, | |
| 48 const base::string16& label_text, | |
| 49 const base::string16& stop_button_text) | |
| 50 : screen_tray_item_(screen_tray_item), | |
| 51 icon_(nullptr), | |
| 52 label_(nullptr), | |
| 53 stop_button_(nullptr), | |
| 54 label_text_(label_text), | |
| 55 stop_button_text_(stop_button_text) { | |
| 56 CreateItems(); | |
| 57 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); | |
| 58 SetLayoutManager(new views::FillLayout); | |
| 59 AddChildView(tri_view); | |
| 60 tri_view->AddView(TriView::Container::START, icon_); | |
| 61 // TODO(bruthig): Multiline Labels don't lay out well with borders so we add | |
| 62 // the border to the Label's container instead. See https://crbug.com/678337 & | |
| 63 // https://crbug.com/682221. | |
| 64 tri_view->SetContainerBorder( | |
| 65 TriView::Container::CENTER, | |
| 66 views::CreateEmptyBorder(0, 0, 0, kTrayPopupLabelRightPadding)); | |
| 67 tri_view->AddView(TriView::Container::CENTER, label_); | |
| 68 tri_view->AddView(TriView::Container::END, stop_button_); | |
| 69 tri_view->SetContainerBorder( | |
| 70 TriView::Container::END, | |
| 71 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); | |
| 72 if (screen_tray_item_) | |
| 73 UpdateFromScreenTrayItem(); | |
| 74 } | |
| 75 | |
| 76 ScreenStatusView::~ScreenStatusView() {} | |
| 77 | |
| 78 void ScreenStatusView::ButtonPressed(views::Button* sender, | |
| 79 const ui::Event& event) { | |
| 80 DCHECK(sender == stop_button_); | |
| 81 screen_tray_item_->Stop(); | |
| 82 screen_tray_item_->RecordStoppedFromDefaultViewMetric(); | |
| 83 } | |
| 84 | |
| 85 void ScreenStatusView::CreateItems() { | |
| 86 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); | |
| 87 icon_ = TrayPopupUtils::CreateMainImageView(); | |
| 88 icon_->SetImage(gfx::CreateVectorIcon( | |
| 89 kSystemMenuScreenShareIcon, TrayPopupItemStyle::GetIconColor( | |
| 90 TrayPopupItemStyle::ColorStyle::ACTIVE))); | |
| 91 if (!use_md) { | |
| 92 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 93 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | |
| 94 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK) | |
| 95 .ToImageSkia()); | |
| 96 } | |
| 97 | |
| 98 label_ = TrayPopupUtils::CreateDefaultLabel(); | |
| 99 label_->SetMultiLine(true); | |
| 100 label_->SetText(label_text_); | |
| 101 // TODO(bruthig): Multiline Labels don't lay out well with borders. | |
| 102 // See https://crbug.com/678337 & https://crbug.com/682221. | |
| 103 label_->SetBorder(nullptr); | |
| 104 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | |
| 105 style.SetupLabel(label_); | |
| 106 | |
| 107 stop_button_ = TrayPopupUtils::CreateTrayPopupButton(this, stop_button_text_); | |
| 108 } | |
| 109 | |
| 110 void ScreenStatusView::UpdateFromScreenTrayItem() { | |
| 111 SetVisible(screen_tray_item_->is_started()); | |
| 112 } | |
| 113 | |
| 114 ScreenNotificationDelegate::ScreenNotificationDelegate( | |
| 115 ScreenTrayItem* screen_tray) | |
| 116 : screen_tray_(screen_tray) {} | |
| 117 | |
| 118 ScreenNotificationDelegate::~ScreenNotificationDelegate() {} | |
| 119 | |
| 120 void ScreenNotificationDelegate::ButtonClick(int button_index) { | |
| 121 DCHECK_EQ(0, button_index); | |
| 122 screen_tray_->Stop(); | |
| 123 screen_tray_->RecordStoppedFromNotificationViewMetric(); | |
| 124 } | |
| 125 | |
| 126 } // namespace tray | |
| 127 | |
| 128 ScreenTrayItem::ScreenTrayItem(SystemTray* system_tray, UmaType uma_type) | |
| 129 : SystemTrayItem(system_tray, uma_type), | |
| 130 tray_view_(nullptr), | |
| 131 default_view_(nullptr), | |
| 132 is_started_(false), | |
| 133 stop_callback_(base::Bind(&base::DoNothing)) {} | |
| 134 | |
| 135 ScreenTrayItem::~ScreenTrayItem() {} | |
| 136 | |
| 137 void ScreenTrayItem::Update() { | |
| 138 if (tray_view_) | |
| 139 tray_view_->Update(); | |
| 140 if (default_view_) | |
| 141 default_view_->UpdateFromScreenTrayItem(); | |
| 142 if (is_started_) { | |
| 143 CreateOrUpdateNotification(); | |
| 144 } else { | |
| 145 message_center::MessageCenter::Get()->RemoveNotification( | |
| 146 GetNotificationId(), false /* by_user */); | |
| 147 } | |
| 148 } | |
| 149 | |
| 150 void ScreenTrayItem::Start(const base::Closure& stop_callback) { | |
| 151 stop_callback_ = stop_callback; | |
| 152 is_started_ = true; | |
| 153 | |
| 154 if (tray_view_) | |
| 155 tray_view_->Update(); | |
| 156 | |
| 157 if (default_view_) | |
| 158 default_view_->UpdateFromScreenTrayItem(); | |
| 159 | |
| 160 if (!system_tray()->HasSystemBubbleType( | |
| 161 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | |
| 162 CreateOrUpdateNotification(); | |
| 163 } | |
| 164 } | |
| 165 | |
| 166 void ScreenTrayItem::Stop() { | |
| 167 is_started_ = false; | |
| 168 Update(); | |
| 169 | |
| 170 if (stop_callback_.is_null()) | |
| 171 return; | |
| 172 | |
| 173 base::Closure callback = stop_callback_; | |
| 174 stop_callback_.Reset(); | |
| 175 callback.Run(); | |
| 176 } | |
| 177 | |
| 178 views::View* ScreenTrayItem::CreateTrayView(LoginStatus status) { | |
| 179 tray_view_ = new tray::ScreenTrayView(this); | |
| 180 return tray_view_; | |
| 181 } | |
| 182 | |
| 183 void ScreenTrayItem::RecordStoppedFromDefaultViewMetric() {} | |
| 184 | |
| 185 void ScreenTrayItem::RecordStoppedFromNotificationViewMetric() {} | |
| 186 | |
| 187 void ScreenTrayItem::DestroyTrayView() { | |
| 188 tray_view_ = nullptr; | |
| 189 } | |
| 190 | |
| 191 void ScreenTrayItem::DestroyDefaultView() { | |
| 192 default_view_ = nullptr; | |
| 193 } | |
| 194 | |
| 195 } // namespace ash | |
| OLD | NEW |