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 SetImage(GetCastIconForSystemMenu(false)); |
| 96 else |
| 97 SetImage(*rb.GetImageNamed(IDR_AURA_UBER_TRAY_CAST).ToImageSkia()); |
| 98 |
84 base::string16 label = | 99 base::string16 label = |
85 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP); | 100 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_DESKTOP); |
86 SetLabel(label); | 101 SetLabel(label); |
87 SetAccessibleName(label); | 102 SetAccessibleName(label); |
88 } | 103 } |
89 | 104 |
90 CastSelectDefaultView::~CastSelectDefaultView() {} | 105 CastSelectDefaultView::~CastSelectDefaultView() {} |
91 | 106 |
92 // This view is displayed when the screen is actively being casted; it allows | 107 // This view is displayed when the screen is actively being casted; it allows |
93 // the user to easily stop casting. It fully replaces the | 108 // the user to easily stop casting. It fully replaces the |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 | 144 |
130 CastCastView::CastCastView() { | 145 CastCastView::CastCastView() { |
131 // We will initialize the primary tray view which shows a stop button here. | 146 // We will initialize the primary tray view which shows a stop button here. |
132 | 147 |
133 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 148 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
134 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 149 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
135 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, | 150 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
136 kTrayPopupPaddingHorizontal, 0, | 151 kTrayPopupPaddingHorizontal, 0, |
137 kTrayPopupPaddingBetweenItems)); | 152 kTrayPopupPaddingBetweenItems)); |
138 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); | 153 icon_ = new FixedSizedImageView(0, GetTrayConstant(TRAY_POPUP_ITEM_HEIGHT)); |
139 icon_->SetImage( | 154 if (MaterialDesignController::IsSystemTrayMenuMaterial()) { |
140 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); | 155 icon_->SetImage(GetCastIconForSystemMenu(true)); |
| 156 } else { |
| 157 icon_->SetImage( |
| 158 bundle.GetImageNamed(IDR_AURA_UBER_TRAY_CAST_ENABLED).ToImageSkia()); |
| 159 } |
141 AddChildView(icon_); | 160 AddChildView(icon_); |
142 | 161 |
143 // The label which describes both what we are casting (ie, the desktop) and | 162 // The label which describes both what we are casting (ie, the desktop) and |
144 // where we are casting it to. | 163 // where we are casting it to. |
145 label_ = new views::Label; | 164 label_ = new views::Label; |
146 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); | 165 label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); |
147 label_->SetMultiLine(true); | 166 label_->SetMultiLine(true); |
148 label_->SetText( | 167 label_->SetText( |
149 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN)); | 168 bundle.GetLocalizedString(IDS_ASH_STATUS_TRAY_CAST_CAST_UNKNOWN)); |
150 AddChildView(label_); | 169 AddChildView(label_); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
335 // itself. | 354 // itself. |
336 void UpdateAlignment(ShelfAlignment alignment); | 355 void UpdateAlignment(ShelfAlignment alignment); |
337 | 356 |
338 private: | 357 private: |
339 DISALLOW_COPY_AND_ASSIGN(CastTrayView); | 358 DISALLOW_COPY_AND_ASSIGN(CastTrayView); |
340 }; | 359 }; |
341 | 360 |
342 CastTrayView::CastTrayView(SystemTrayItem* tray_item) | 361 CastTrayView::CastTrayView(SystemTrayItem* tray_item) |
343 : TrayItemView(tray_item) { | 362 : TrayItemView(tray_item) { |
344 CreateImageView(); | 363 CreateImageView(); |
345 | 364 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
346 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() | 365 image_view()->SetImage(gfx::CreateVectorIcon( |
347 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) | 366 gfx::VectorIconId::SYSTEM_TRAY_CAST, kTrayIconColor)); |
348 .ToImageSkia()); | 367 } else { |
| 368 image_view()->SetImage(ui::ResourceBundle::GetSharedInstance() |
| 369 .GetImageNamed(IDR_AURA_UBER_TRAY_SCREENSHARE) |
| 370 .ToImageSkia()); |
| 371 } |
349 } | 372 } |
350 | 373 |
351 CastTrayView::~CastTrayView() {} | 374 CastTrayView::~CastTrayView() {} |
352 | 375 |
353 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { | 376 void CastTrayView::UpdateAlignment(ShelfAlignment alignment) { |
354 // Center the item dependent on the orientation of the shelf. | 377 // Center the item dependent on the orientation of the shelf. |
355 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) | 378 views::BoxLayout::Orientation layout = IsHorizontalAlignment(alignment) |
356 ? views::BoxLayout::kHorizontal | 379 ? views::BoxLayout::kHorizontal |
357 : views::BoxLayout::kVertical; | 380 : views::BoxLayout::kVertical; |
358 SetLayoutManager(new views::BoxLayout(layout, 0, 0, 0)); | 381 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; | 685 is_casting_ = started; |
663 UpdatePrimaryView(); | 686 UpdatePrimaryView(); |
664 } | 687 } |
665 | 688 |
666 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 689 void TrayCast::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
667 if (tray_) | 690 if (tray_) |
668 tray_->UpdateAlignment(alignment); | 691 tray_->UpdateAlignment(alignment); |
669 } | 692 } |
670 | 693 |
671 } // namespace ash | 694 } // namespace ash |
OLD | NEW |