| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tray/tray_notification_view.h" | 5 #include "ash/common/system/tray/tray_notification_view.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/system/tray/system_tray_item.h" | 8 #include "ash/common/system/tray/system_tray_item.h" |
| 9 #include "ash/common/system/tray/tray_constants.h" | 9 #include "ash/common/system/tray/tray_constants.h" |
| 10 #include "ash/resources/vector_icons/vector_icons.h" | 10 #include "ash/resources/vector_icons/vector_icons.h" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 | 22 |
| 23 namespace { | 23 namespace { |
| 24 | 24 |
| 25 // Maps a non-MD PNG resource id to its corresponding MD vector icon. | 25 // Maps a non-MD PNG resource id to its corresponding MD vector icon. |
| 26 // TODO(tdanderson): Remove this once material design is enabled by | 26 // TODO(tdanderson): Remove this once material design is enabled by |
| 27 // default. See crbug.com/614453. | 27 // default. See crbug.com/614453. |
| 28 const gfx::VectorIcon& ResourceIdToVectorIcon(int resource_id) { | 28 const gfx::VectorIcon& ResourceIdToVectorIcon(int resource_id) { |
| 29 switch (resource_id) { | 29 switch (resource_id) { |
| 30 case IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK: | 30 case IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK: |
| 31 return kSystemMenuAccessibilityIcon; | 31 return kSystemMenuAccessibilityIcon; |
| 32 case IDR_AURA_UBER_TRAY_SMS: | |
| 33 return kSystemMenuSmsIcon; | |
| 34 default: | 32 default: |
| 35 NOTREACHED(); | 33 NOTREACHED(); |
| 36 break; | 34 break; |
| 37 } | 35 } |
| 38 | 36 |
| 39 return gfx::kNoneIcon; | 37 return gfx::kNoneIcon; |
| 40 } | 38 } |
| 41 | 39 |
| 42 } // namespace | 40 } // namespace |
| 43 | 41 |
| 44 TrayNotificationView::TrayNotificationView(SystemTrayItem* owner, int icon_id) | 42 TrayNotificationView::TrayNotificationView(int icon_id) |
| 45 : owner_(owner), icon_id_(icon_id), icon_(NULL), autoclose_delay_(0) {} | 43 : icon_id_(icon_id), icon_(NULL) {} |
| 46 | 44 |
| 47 TrayNotificationView::~TrayNotificationView() {} | 45 TrayNotificationView::~TrayNotificationView() {} |
| 48 | 46 |
| 49 void TrayNotificationView::InitView(views::View* contents) { | 47 void TrayNotificationView::InitView(views::View* contents) { |
| 50 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 48 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 51 | 49 |
| 52 views::GridLayout* layout = new views::GridLayout(this); | 50 views::GridLayout* layout = new views::GridLayout(this); |
| 53 SetLayoutManager(layout); | 51 SetLayoutManager(layout); |
| 54 | 52 |
| 55 views::ImageButton* close_button = new views::ImageButton(this); | 53 views::ImageView* close_button = new views::ImageView(); |
| 56 close_button->SetImage( | 54 close_button->SetImage( |
| 57 views::CustomButton::STATE_NORMAL, | |
| 58 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); | 55 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); |
| 59 close_button->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | 56 close_button->SetHorizontalAlignment(views::ImageView::CENTER); |
| 60 views::ImageButton::ALIGN_MIDDLE); | 57 close_button->SetVerticalAlignment(views::ImageView::CENTER); |
| 61 | 58 |
| 62 icon_ = new views::ImageView; | 59 icon_ = new views::ImageView; |
| 63 if (icon_id_ != 0) { | 60 if (icon_id_ != 0) { |
| 64 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { | 61 if (MaterialDesignController::UseMaterialDesignSystemIcons()) { |
| 65 icon_->SetImage(gfx::CreateVectorIcon(ResourceIdToVectorIcon(icon_id_), | 62 icon_->SetImage(gfx::CreateVectorIcon(ResourceIdToVectorIcon(icon_id_), |
| 66 kMenuIconColor)); | 63 kMenuIconColor)); |
| 67 } else { | 64 } else { |
| 68 icon_->SetImage( | 65 icon_->SetImage( |
| 69 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); | 66 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); |
| 70 } | 67 } |
| (...skipping 27 matching lines...) Expand all Loading... |
| 98 | 95 |
| 99 // Layout rows | 96 // Layout rows |
| 100 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | 97 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| 101 layout->StartRow(0, 0); | 98 layout->StartRow(0, 0); |
| 102 layout->AddView(icon_); | 99 layout->AddView(icon_); |
| 103 layout->AddView(contents); | 100 layout->AddView(contents); |
| 104 layout->AddView(close_button); | 101 layout->AddView(close_button); |
| 105 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | 102 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| 106 } | 103 } |
| 107 | 104 |
| 108 void TrayNotificationView::UpdateView(views::View* new_contents) { | |
| 109 RemoveAllChildViews(true); | |
| 110 InitView(new_contents); | |
| 111 Layout(); | |
| 112 PreferredSizeChanged(); | |
| 113 SchedulePaint(); | |
| 114 } | |
| 115 | |
| 116 void TrayNotificationView::StartAutoCloseTimer(int seconds) { | |
| 117 autoclose_.Stop(); | |
| 118 autoclose_delay_ = seconds; | |
| 119 if (autoclose_delay_) { | |
| 120 autoclose_.Start(FROM_HERE, base::TimeDelta::FromSeconds(autoclose_delay_), | |
| 121 this, &TrayNotificationView::HandleClose); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 void TrayNotificationView::StopAutoCloseTimer() { | |
| 126 autoclose_.Stop(); | |
| 127 } | |
| 128 | |
| 129 void TrayNotificationView::RestartAutoCloseTimer() { | |
| 130 if (autoclose_delay_) | |
| 131 StartAutoCloseTimer(autoclose_delay_); | |
| 132 } | |
| 133 | |
| 134 void TrayNotificationView::ButtonPressed(views::Button* sender, | |
| 135 const ui::Event& event) { | |
| 136 HandleClose(); | |
| 137 } | |
| 138 | |
| 139 bool TrayNotificationView::OnMousePressed(const ui::MouseEvent& event) { | |
| 140 HandleClickAction(); | |
| 141 return true; | |
| 142 } | |
| 143 | |
| 144 void TrayNotificationView::OnGestureEvent(ui::GestureEvent* event) { | |
| 145 SlideOutView::OnGestureEvent(event); | |
| 146 if (event->handled()) | |
| 147 return; | |
| 148 if (event->type() != ui::ET_GESTURE_TAP) | |
| 149 return; | |
| 150 HandleClickAction(); | |
| 151 event->SetHandled(); | |
| 152 } | |
| 153 | |
| 154 void TrayNotificationView::OnClose() {} | |
| 155 | |
| 156 void TrayNotificationView::OnClickAction() {} | |
| 157 | |
| 158 void TrayNotificationView::OnSlideOut() { | |
| 159 owner_->HideNotificationView(); | |
| 160 } | |
| 161 | |
| 162 void TrayNotificationView::HandleClose() { | |
| 163 OnClose(); | |
| 164 owner_->HideNotificationView(); | |
| 165 } | |
| 166 | |
| 167 void TrayNotificationView::HandleClickAction() { | |
| 168 HandleClose(); | |
| 169 OnClickAction(); | |
| 170 } | |
| 171 | |
| 172 } // namespace ash | 105 } // namespace ash |
| OLD | NEW |