Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/common/system/chromeos/screen_security/screen_tray_item.h" | 5 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | 7 #include "ash/common/material_design/material_design_controller.h" |
| 8 #include "ash/common/shelf/wm_shelf_util.h" | 8 #include "ash/common/shelf/wm_shelf_util.h" |
| 9 #include "ash/common/system/tray/fixed_sized_image_view.h" | 9 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 10 #include "ash/common/system/tray/tray_constants.h" | 10 #include "ash/common/system/tray/tray_constants.h" |
| 11 #include "ash/common/system/tray/tray_popup_item_style.h" | 11 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 12 #include "ash/common/system/tray/tray_popup_utils.h" | 12 #include "ash/common/system/tray/tray_popup_utils.h" |
| 13 #include "ash/resources/vector_icons/vector_icons.h" | 13 #include "ash/resources/vector_icons/vector_icons.h" |
| 14 #include "grit/ash_resources.h" | 14 #include "grit/ash_resources.h" |
| 15 #include "ui/base/resource/resource_bundle.h" | 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/paint_vector_icon.h" | 16 #include "ui/gfx/paint_vector_icon.h" |
| 17 #include "ui/message_center/message_center.h" | 17 #include "ui/message_center/message_center.h" |
| 18 #include "ui/views/controls/button/label_button.h" | 18 #include "ui/views/controls/button/label_button.h" |
| 19 #include "ui/views/controls/label.h" | 19 #include "ui/views/controls/label.h" |
| 20 #include "ui/views/layout/box_layout.h" | 20 #include "ui/views/layout/fill_layout.h" |
| 21 | |
| 22 namespace { | |
| 23 const int kStopButtonRightPadding = 18; | |
| 24 } // namespace | |
| 25 | 21 |
| 26 namespace ash { | 22 namespace ash { |
| 27 namespace tray { | 23 namespace tray { |
| 28 | 24 |
| 29 // ScreenTrayView implementations. | 25 // ScreenTrayView implementations. |
| 30 ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item) | 26 ScreenTrayView::ScreenTrayView(ScreenTrayItem* screen_tray_item) |
| 31 : TrayItemView(screen_tray_item), screen_tray_item_(screen_tray_item) { | 27 : TrayItemView(screen_tray_item), screen_tray_item_(screen_tray_item) { |
| 32 CreateImageView(); | 28 CreateImageView(); |
| 33 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 29 if (!MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 34 image_view()->SetImage( | |
| 35 gfx::CreateVectorIcon(kSystemTrayScreenShareIcon, kTrayIconColor)); | |
| 36 } else { | |
| 37 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 30 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() |
| 38 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) | 31 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) |
| 39 .ToImageSkia()); | 32 .ToImageSkia()); |
| 40 } | 33 } |
| 41 Update(); | 34 Update(); |
| 42 } | 35 } |
| 43 | 36 |
| 44 ScreenTrayView::~ScreenTrayView() {} | 37 ScreenTrayView::~ScreenTrayView() {} |
| 45 | 38 |
| 46 void ScreenTrayView::Update() { | 39 void ScreenTrayView::Update() { |
| 47 SetVisible(screen_tray_item_->is_started()); | 40 SetVisible(screen_tray_item_->is_started()); |
| 41 | |
| 42 if (!MaterialDesignController::UseMaterialDesignSystemIcons()) { | |
| 43 return; | |
| 44 } | |
| 45 | |
| 46 TrayPopupItemStyle default_view_style( | |
| 47 GetNativeTheme(), TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | |
| 48 image_view()->SetImage(gfx::CreateVectorIcon( | |
| 49 kSystemTrayScreenShareIcon, default_view_style.GetIconColor())); | |
|
bruthig
2016/11/23 20:15:47
FYI The ScreenTrayView is the one shown beside the
yiyix
2016/11/24 21:38:16
Sorry. you are you right.
| |
| 48 } | 50 } |
| 49 | 51 |
| 50 // ScreenStatusView implementations. | 52 // ScreenStatusView implementations. |
| 51 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, | 53 ScreenStatusView::ScreenStatusView(ScreenTrayItem* screen_tray_item, |
| 52 const base::string16& label_text, | 54 const base::string16& label_text, |
| 53 const base::string16& stop_button_text) | 55 const base::string16& stop_button_text) |
| 54 : screen_tray_item_(screen_tray_item), | 56 : screen_tray_item_(screen_tray_item), |
| 55 icon_(nullptr), | 57 icon_(nullptr), |
| 56 label_(nullptr), | 58 label_(nullptr), |
| 57 stop_button_(nullptr), | 59 stop_button_(nullptr), |
| 58 label_text_(label_text), | 60 label_text_(label_text), |
| 59 stop_button_text_(stop_button_text) { | 61 stop_button_text_(stop_button_text) { |
| 60 CreateItems(); | 62 CreateItems(); |
| 63 TriView* tri_view(TrayPopupUtils::CreateDefaultRowView()); | |
| 64 SetLayoutManager(new views::FillLayout); | |
| 65 AddChildView(tri_view); | |
| 66 tri_view->AddView(TriView::Container::START, icon_); | |
| 67 tri_view->AddView(TriView::Container::CENTER, label_); | |
| 68 tri_view->AddView(TriView::Container::END, stop_button_); | |
| 69 SetBorder(views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); | |
|
bruthig
2016/11/23 20:15:47
I think it would be better if we didn't set custom
yiyix
2016/11/24 21:38:16
As we have discussed offline, for this code review
bruthig
2016/11/24 22:36:29
Awesome, thx :)
| |
| 70 | |
| 61 if (screen_tray_item_) | 71 if (screen_tray_item_) |
| 62 UpdateFromScreenTrayItem(); | 72 UpdateFromScreenTrayItem(); |
| 63 } | 73 } |
| 64 | 74 |
| 65 ScreenStatusView::~ScreenStatusView() {} | 75 ScreenStatusView::~ScreenStatusView() {} |
| 66 | 76 |
| 67 void ScreenStatusView::ButtonPressed(views::Button* sender, | 77 void ScreenStatusView::ButtonPressed(views::Button* sender, |
| 68 const ui::Event& event) { | 78 const ui::Event& event) { |
| 69 DCHECK(sender == stop_button_); | 79 DCHECK(sender == stop_button_); |
| 70 screen_tray_item_->Stop(); | 80 screen_tray_item_->Stop(); |
| 71 screen_tray_item_->RecordStoppedFromDefaultViewMetric(); | 81 screen_tray_item_->RecordStoppedFromDefaultViewMetric(); |
| 72 } | 82 } |
| 73 | 83 |
| 74 void ScreenStatusView::CreateItems() { | 84 void ScreenStatusView::CreateItems() { |
| 75 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); | 85 const bool use_md = MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 76 if (!use_md) | 86 icon_ = TrayPopupUtils::CreateMainImageView(); |
| 87 if (!use_md) { | |
| 77 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 88 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 78 | |
| 79 auto layout = | |
| 80 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, | |
| 81 use_md ? kTrayPopupPaddingBetweenItems : 0); | |
| 82 layout->set_cross_axis_alignment( | |
| 83 views::BoxLayout::CROSS_AXIS_ALIGNMENT_CENTER); | |
| 84 SetLayoutManager(layout); | |
| 85 SetBorder(views::CreateEmptyBorder( | |
| 86 0, kTrayPopupPaddingHorizontal, 0, | |
| 87 use_md ? kTrayPopupButtonEndMargin : kStopButtonRightPadding)); | |
| 88 | |
| 89 icon_ = TrayPopupUtils::CreateMainImageView(); | |
| 90 if (use_md) { | |
| 91 icon_->SetImage( | |
| 92 gfx::CreateVectorIcon(kSystemMenuScreenShareIcon, kMenuIconColor)); | |
| 93 } else { | |
| 94 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 89 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 95 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK) | 90 icon_->SetImage(bundle.GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE_DARK) |
| 96 .ToImageSkia()); | 91 .ToImageSkia()); |
| 97 } | 92 } |
| 98 AddChildView(icon_); | |
| 99 | 93 |
| 100 label_ = new views::Label; | 94 label_ = TrayPopupUtils::CreateDefaultLabel(); |
| 101 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
| 102 label_->SetMultiLine(true); | 95 label_->SetMultiLine(true); |
| 103 label_->SetText(label_text_); | 96 label_->SetText(label_text_); |
| 104 if (!use_md) { | |
| 105 label_->SetBorder( | |
| 106 views::CreateEmptyBorder(0, kTrayPopupPaddingBetweenItems, 0, 0)); | |
| 107 } | |
| 108 AddChildView(label_); | |
| 109 layout->SetFlexForView(label_, 1); | |
| 110 | 97 |
| 111 stop_button_ = TrayPopupUtils::CreateTrayPopupButton(this, stop_button_text_); | 98 stop_button_ = TrayPopupUtils::CreateTrayPopupButton(this, stop_button_text_); |
| 112 AddChildView(stop_button_); | |
| 113 } | 99 } |
| 114 | 100 |
| 115 void ScreenStatusView::UpdateFromScreenTrayItem() { | 101 void ScreenStatusView::UpdateFromScreenTrayItem() { |
| 116 // Hide the notification bubble when the ash tray bubble opens. | 102 // Hide the notification bubble when the ash tray bubble opens. |
| 117 screen_tray_item_->HideNotificationView(); | 103 screen_tray_item_->HideNotificationView(); |
| 118 SetVisible(screen_tray_item_->is_started()); | 104 SetVisible(screen_tray_item_->is_started()); |
| 119 } | 105 } |
| 120 | 106 |
| 121 void ScreenStatusView::OnNativeThemeChanged(const ui::NativeTheme* theme) { | 107 void ScreenStatusView::OnNativeThemeChanged(const ui::NativeTheme* theme) { |
| 122 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { | 108 if (!MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 123 views::View::OnNativeThemeChanged(theme); | 109 views::View::OnNativeThemeChanged(theme); |
| 124 return; | 110 return; |
| 125 } | 111 } |
| 112 | |
| 126 if (theme) { | 113 if (theme) { |
| 127 TrayPopupItemStyle style(theme, | 114 TrayPopupItemStyle style(theme, |
| 128 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); | 115 TrayPopupItemStyle::FontStyle::DEFAULT_VIEW_LABEL); |
| 116 icon_->SetImage(gfx::CreateVectorIcon(kSystemMenuScreenShareIcon, | |
| 117 style.GetIconColor())); | |
| 129 style.SetupLabel(label_); | 118 style.SetupLabel(label_); |
| 130 } | 119 } |
| 131 } | 120 } |
| 132 | 121 |
| 133 ScreenNotificationDelegate::ScreenNotificationDelegate( | 122 ScreenNotificationDelegate::ScreenNotificationDelegate( |
| 134 ScreenTrayItem* screen_tray) | 123 ScreenTrayItem* screen_tray) |
| 135 : screen_tray_(screen_tray) {} | 124 : screen_tray_(screen_tray) {} |
| 136 | 125 |
| 137 ScreenNotificationDelegate::~ScreenNotificationDelegate() {} | 126 ScreenNotificationDelegate::~ScreenNotificationDelegate() {} |
| 138 | 127 |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 205 | 194 |
| 206 void ScreenTrayItem::DestroyTrayView() { | 195 void ScreenTrayItem::DestroyTrayView() { |
| 207 tray_view_ = nullptr; | 196 tray_view_ = nullptr; |
| 208 } | 197 } |
| 209 | 198 |
| 210 void ScreenTrayItem::DestroyDefaultView() { | 199 void ScreenTrayItem::DestroyDefaultView() { |
| 211 default_view_ = nullptr; | 200 default_view_ = nullptr; |
| 212 } | 201 } |
| 213 | 202 |
| 214 } // namespace ash | 203 } // namespace ash |
| OLD | NEW |