Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/cast/tray_cast.h" | 5 #include "ash/common/system/cast/tray_cast.h" |
| 6 | 6 |
| 7 #include "ash/common/material_design/material_design_controller.h" | |
| 7 #include "ash/common/session/session_state_delegate.h" | 8 #include "ash/common/session/session_state_delegate.h" |
| 8 #include "ash/common/shelf/shelf_types.h" | 9 #include "ash/common/shelf/shelf_types.h" |
| 9 #include "ash/common/shelf/wm_shelf_util.h" | 10 #include "ash/common/shelf/wm_shelf_util.h" |
| 10 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" | 11 #include "ash/common/system/chromeos/screen_security/screen_tray_item.h" |
| 11 #include "ash/common/system/tray/fixed_sized_image_view.h" | 12 #include "ash/common/system/tray/fixed_sized_image_view.h" |
| 12 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | 13 #include "ash/common/system/tray/fixed_sized_scroll_view.h" |
| 13 #include "ash/common/system/tray/hover_highlight_view.h" | 14 #include "ash/common/system/tray/hover_highlight_view.h" |
| 14 #include "ash/common/system/tray/system_tray.h" | 15 #include "ash/common/system/tray/system_tray.h" |
| 15 #include "ash/common/system/tray/system_tray_delegate.h" | 16 #include "ash/common/system/tray/system_tray_delegate.h" |
| 16 #include "ash/common/system/tray/throbber_view.h" | 17 #include "ash/common/system/tray/throbber_view.h" |
| 17 #include "ash/common/system/tray/tray_constants.h" | 18 #include "ash/common/system/tray/tray_constants.h" |
| 18 #include "ash/common/system/tray/tray_details_view.h" | 19 #include "ash/common/system/tray/tray_details_view.h" |
| 19 #include "ash/common/system/tray/tray_item_more.h" | 20 #include "ash/common/system/tray/tray_item_more.h" |
| 20 #include "ash/common/system/tray/tray_item_view.h" | 21 #include "ash/common/system/tray/tray_item_view.h" |
| 21 #include "ash/common/system/tray/tray_popup_label_button.h" | 22 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 22 #include "ash/common/system/tray/view_click_listener.h" | 23 #include "ash/common/system/tray/view_click_listener.h" |
| 23 #include "ash/common/wm_shell.h" | 24 #include "ash/common/wm_shell.h" |
| 24 #include "base/bind.h" | 25 #include "base/bind.h" |
| 25 #include "grit/ash_resources.h" | 26 #include "grit/ash_resources.h" |
| 26 #include "grit/ash_strings.h" | 27 #include "grit/ash_strings.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/image/image.h" | 30 #include "ui/gfx/image/image.h" |
| 31 #include "ui/gfx/paint_vector_icon.h" | |
| 30 #include "ui/gfx/text_elider.h" | 32 #include "ui/gfx/text_elider.h" |
| 33 #include "ui/gfx/vector_icons_public.h" | |
| 31 #include "ui/views/controls/button/button.h" | 34 #include "ui/views/controls/button/button.h" |
| 32 #include "ui/views/controls/image_view.h" | 35 #include "ui/views/controls/image_view.h" |
| 33 #include "ui/views/controls/label.h" | 36 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/layout/box_layout.h" | 37 #include "ui/views/layout/box_layout.h" |
| 35 #include "ui/views/layout/fill_layout.h" | 38 #include "ui/views/layout/fill_layout.h" |
| 36 | 39 |
| 37 namespace ash { | 40 namespace ash { |
| 38 | 41 |
| 39 namespace { | 42 namespace { |
| 40 | 43 |
| 41 const size_t kMaximumStatusStringLength = 100; | 44 const size_t kMaximumStatusStringLength = 100; |
| 42 const int kStopButtonRightPadding = 18; | 45 const int kStopButtonRightPadding = 18; |
| 43 | 46 |
| 44 // Returns the active CastConfigDelegate instance. | 47 // Returns the active CastConfigDelegate instance. |
| 45 CastConfigDelegate* GetCastConfigDelegate() { | 48 CastConfigDelegate* GetCastConfigDelegate() { |
| 46 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate(); | 49 return WmShell::Get()->system_tray_delegate()->GetCastConfigDelegate(); |
| 47 } | 50 } |
| 48 | 51 |
| 49 // Helper method to elide the given string to the maximum length. If a string is | 52 // Helper method to elide the given string to the maximum length. If a string is |
| 50 // contains user-input and is displayed, we should elide it. | 53 // contains user-input and is displayed, we should elide it. |
| 51 // TODO(jdufault): This does not properly trim unicode characters. We should | 54 // TODO(jdufault): This does not properly trim unicode characters. We should |
| 52 // implement this properly by using views::Label::SetElideBehavior(...). See | 55 // implement this properly by using views::Label::SetElideBehavior(...). See |
| 53 // crbug.com/532496. | 56 // crbug.com/532496. |
| 54 base::string16 ElideString(const base::string16& text) { | 57 base::string16 ElideString(const base::string16& text) { |
| 55 base::string16 elided; | 58 base::string16 elided; |
| 56 gfx::ElideString(text, kMaximumStatusStringLength, &elided); | 59 gfx::ElideString(text, kMaximumStatusStringLength, &elided); |
| 57 return elided; | 60 return elided; |
| 58 } | 61 } |
| 59 | 62 |
| 63 // Returns a vectorized version of the Cast icon. The icon's interior region is | |
| 64 // filled in if |is_casting| is true. | |
| 65 gfx::ImageSkia GetCastIconForSystemMenu(bool is_casting) { | |
| 66 return gfx::CreateVectorIcon( | |
| 67 gfx::VectorIconId::SYSTEM_MENU_CAST, | |
| 68 is_casting ? kMenuIconColor : SK_ColorTRANSPARENT); | |
| 69 } | |
| 70 | |
| 60 } // namespace | 71 } // namespace |
| 61 | 72 |
| 62 namespace tray { | 73 namespace tray { |
| 63 | 74 |
| 64 // This view is displayed in the system tray when the cast extension is active. | 75 // This view is displayed in the system tray when the cast extension is active. |
| 65 // It asks the user if they want to cast the desktop. If they click on the | 76 // It asks the user if they want to cast the desktop. If they click on the |
| 66 // chevron, then a detail view will replace this view where the user will | 77 // chevron, then a detail view will replace this view where the user will |
| 67 // actually pick the cast receiver. | 78 // actually pick the cast receiver. |
| 68 class CastSelectDefaultView : public TrayItemMore { | 79 class CastSelectDefaultView : public TrayItemMore { |
| 69 public: | 80 public: |
| 70 CastSelectDefaultView(SystemTrayItem* owner, bool show_more); | 81 CastSelectDefaultView(SystemTrayItem* owner, bool show_more); |
| 71 ~CastSelectDefaultView() override; | 82 ~CastSelectDefaultView() override; |
| 72 | 83 |
| 73 private: | 84 private: |
| 74 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); | 85 DISALLOW_COPY_AND_ASSIGN(CastSelectDefaultView); |
| 75 }; | 86 }; |
| 76 | 87 |
| 77 CastSelectDefaultView::CastSelectDefaultView(SystemTrayItem* owner, | 88 CastSelectDefaultView::CastSelectDefaultView(SystemTrayItem* owner, |
| 78 bool show_more) | 89 bool show_more) |
| 79 : TrayItemMore(owner, show_more) { | 90 : TrayItemMore(owner, show_more) { |
| 80 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 91 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 81 | 92 |
| 82 // Update the image and label. | 93 // Update the image and label. |
| 83 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); | 94 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 95 gfx::ImageSkia image_md = GetCastIconForSystemMenu(false); | |
| 96 SetImage(&image_md); | |
|
Evan Stade
2016/08/10 22:07:56
can you make TrayItemMore support SetImage with a
tdanderson
2016/08/11 16:31:22
Done.
| |
| 97 } else { | |
| 98 SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); | |
| 99 } | |
| 100 | |
| 84 base::string16 label = | 101 base::string16 label = |
| 85 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP); | 102 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP); |
| 86 SetLabel(label); | 103 SetLabel(label); |
| 87 SetAccessibleName(label); | 104 SetAccessibleName(label); |
| 88 } | 105 } |
| 89 | 106 |
| 90 CastSelectDefaultView::~CastSelectDefaultView() {} | 107 CastSelectDefaultView::~CastSelectDefaultView() {} |
| 91 | 108 |
| 92 // This view is displayed when the screen is actively being casted; it allows | 109 // This view is displayed when the screen is actively being casted; it allows |
| 93 // the user to easily stop casting. It fully replaces the | 110 // the user to easily stop casting. It fully replaces the |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 129 | 146 |
| 130 CastCastView::CastCastView() { | 147 CastCastView::CastCastView() { |
| 131 // We will initialize the primary tray view which shows a stop button here. | 148 // We will initialize the primary tray view which shows a stop button here. |
| 132 | 149 |
| 133 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 150 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 134 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 151 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 135 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 152 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 136 kTrayPopupPaddingHorizontal, 0, | 153 kTrayPopupPaddingHorizontal, 0, |
| 137 kTrayPopupPaddingBetweenItems)); | 154 kTrayPopupPaddingBetweenItems)); |
| 138 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 155 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
| 139 icon_->SetImage( | 156 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 140 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); | 157 icon_->SetImage(GetCastIconForSystemMenu(true)); |
| 158 } else { | |
| 159 icon_->SetImage( | |
| 160 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); | |
| 161 } | |
| 141 AddChildView(icon_); | 162 AddChildView(icon_); |
| 142 | 163 |
| 143 // The label which describes both what we are casting (ie, the desktop) and | 164 // The label which describes both what we are casting (ie, the desktop) and |
| 144 // where we are casting it to. | 165 // where we are casting it to. |
| 145 label_ = new views::Label; | 166 label_ = new views::Label; |
| 146 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 167 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
| 147 label_->SetMultiLine(true); | 168 label_->SetMultiLine(true); |
| 148 label_->SetText( | 169 label_->SetText( |
| 149 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN)); | 170 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN)); |
| 150 AddChildView(label_); | 171 AddChildView(label_); |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 335 // itself. | 356 // itself. |
| 336 void UpdateAlignment(ShelfAlignment alignment); | 357 void UpdateAlignment(ShelfAlignment alignment); |
| 337 | 358 |
| 338 private: | 359 private: |
| 339 DISALLOW_COPY_AND_ASSIGN(CastTrayView); | 360 DISALLOW_COPY_AND_ASSIGN(CastTrayView); |
| 340 }; | 361 }; |
| 341 | 362 |
| 342 CastTrayView::CastTrayView(SystemTrayItem* tray_item) | 363 CastTrayView::CastTrayView(SystemTrayItem* tray_item) |
| 343 : TrayItemView(tray_item) { | 364 : TrayItemView(tray_item) { |
| 344 CreateImageView(); | 365 CreateImageView(); |
| 345 | 366 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 346 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 367 image_view()->SetImage(gfx::CreateVectorIcon( |
| 347 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) | 368 gfx::VectorIconId::SYSTEM_TRAY_CAST, kTrayIconColor)); |
| 348 .ToImageSkia()); | 369 } else { |
| 370 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | |
| 371 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) | |
| 372 .ToImageSkia()); | |
| 373 } | |
| 349 } | 374 } |
| 350 | 375 |
| 351 CastTrayView::~CastTrayView() {} | 376 CastTrayView::~CastTrayView() {} |
| 352 | 377 |
| 353 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { | 378 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { |
| 354 // Center the item dependent on the orientation of the shelf. | 379 // Center the item dependent on the orientation of the shelf. |
| 355 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) | 380 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) |
| 356 ? views::BoxLayout::kHorizontal | 381 ? views::BoxLayout::kHorizontal |
| 357 : views::BoxLayout::kVertical; | 382 : views::BoxLayout::kVertical; |
| 358 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | 383 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); |
| (...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 662 is_casting_ = started; | 687 is_casting_ = started; |
| 663 UpdatePrimaryView(); | 688 UpdatePrimaryView(); |
| 664 } | 689 } |
| 665 | 690 |
| 666 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 691 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 667 if (tray_) | 692 if (tray_) |
| 668 tray_->UpdateAlignment(alignment); | 693 tray_->UpdateAlignment(alignment); |
| 669 } | 694 } |
| 670 | 695 |
| 671 } // namespace ash | 696 } // namespace ash |
| OLD | NEW |