| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/system/tray/tray_notification_view.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/system_tray_item.h" | |
| 8 #include "ash/common/system/tray/tray_constants.h" | |
| 9 #include "ui/base/resource/resource_bundle.h" | |
| 10 #include "ui/gfx/image/image_skia.h" | |
| 11 #include "ui/resources/grit/ui_resources.h" | |
| 12 #include "ui/views/background.h" | |
| 13 #include "ui/views/controls/button/image_button.h" | |
| 14 #include "ui/views/controls/image_view.h" | |
| 15 #include "ui/views/layout/grid_layout.h" | |
| 16 | |
| 17 namespace ash { | |
| 18 | |
| 19 TrayNotificationView::TrayNotificationView(SystemTrayItem* owner, int icon_id) | |
| 20 : owner_(owner), | |
| 21 icon_id_(icon_id), | |
| 22 icon_(NULL), | |
| 23 autoclose_delay_(0) { | |
| 24 } | |
| 25 | |
| 26 TrayNotificationView::~TrayNotificationView() { | |
| 27 } | |
| 28 | |
| 29 void TrayNotificationView::InitView(views::View* contents) { | |
| 30 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 31 | |
| 32 views::GridLayout* layout = new views::GridLayout(this); | |
| 33 SetLayoutManager(layout); | |
| 34 | |
| 35 views::ImageButton* close_button = new views::ImageButton(this); | |
| 36 close_button->SetImage(views::CustomButton::STATE_NORMAL, | |
| 37 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 38 IDR_MESSAGE_CLOSE)); | |
| 39 close_button->SetImageAlignment(views::ImageButton::ALIGN_CENTER, | |
| 40 views::ImageButton::ALIGN_MIDDLE); | |
| 41 | |
| 42 icon_ = new views::ImageView; | |
| 43 if (icon_id_ != 0) { | |
| 44 icon_->SetImage( | |
| 45 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); | |
| 46 } | |
| 47 | |
| 48 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 49 | |
| 50 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 51 | |
| 52 // Icon | |
| 53 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
| 54 0, /* resize percent */ | |
| 55 views::GridLayout::FIXED, | |
| 56 kNotificationIconWidth, kNotificationIconWidth); | |
| 57 | |
| 58 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 59 | |
| 60 // Contents | |
| 61 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 62 100, /* resize percent */ | |
| 63 views::GridLayout::FIXED, | |
| 64 kTrayNotificationContentsWidth, | |
| 65 kTrayNotificationContentsWidth); | |
| 66 | |
| 67 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 68 | |
| 69 // Close button | |
| 70 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | |
| 71 0, /* resize percent */ | |
| 72 views::GridLayout::FIXED, | |
| 73 kNotificationButtonWidth, kNotificationButtonWidth); | |
| 74 | |
| 75 // Layout rows | |
| 76 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 77 layout->StartRow(0, 0); | |
| 78 layout->AddView(icon_); | |
| 79 layout->AddView(contents); | |
| 80 layout->AddView(close_button); | |
| 81 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 82 } | |
| 83 | |
| 84 void TrayNotificationView::SetIconImage(const gfx::ImageSkia& image) { | |
| 85 icon_->SetImage(image); | |
| 86 SchedulePaint(); | |
| 87 } | |
| 88 | |
| 89 void TrayNotificationView::UpdateView(views::View* new_contents) { | |
| 90 RemoveAllChildViews(true); | |
| 91 InitView(new_contents); | |
| 92 Layout(); | |
| 93 PreferredSizeChanged(); | |
| 94 SchedulePaint(); | |
| 95 } | |
| 96 | |
| 97 void TrayNotificationView::UpdateViewAndImage(views::View* new_contents, | |
| 98 const gfx::ImageSkia& image) { | |
| 99 RemoveAllChildViews(true); | |
| 100 InitView(new_contents); | |
| 101 icon_->SetImage(image); | |
| 102 Layout(); | |
| 103 PreferredSizeChanged(); | |
| 104 SchedulePaint(); | |
| 105 } | |
| 106 | |
| 107 void TrayNotificationView::StartAutoCloseTimer(int seconds) { | |
| 108 autoclose_.Stop(); | |
| 109 autoclose_delay_ = seconds; | |
| 110 if (autoclose_delay_) { | |
| 111 autoclose_.Start(FROM_HERE, | |
| 112 base::TimeDelta::FromSeconds(autoclose_delay_), | |
| 113 this, &TrayNotificationView::HandleClose); | |
| 114 } | |
| 115 } | |
| 116 | |
| 117 void TrayNotificationView::StopAutoCloseTimer() { | |
| 118 autoclose_.Stop(); | |
| 119 } | |
| 120 | |
| 121 void TrayNotificationView::RestartAutoCloseTimer() { | |
| 122 if (autoclose_delay_) | |
| 123 StartAutoCloseTimer(autoclose_delay_); | |
| 124 } | |
| 125 | |
| 126 void TrayNotificationView::ButtonPressed(views::Button* sender, | |
| 127 const ui::Event& event) { | |
| 128 HandleClose(); | |
| 129 } | |
| 130 | |
| 131 bool TrayNotificationView::OnMousePressed(const ui::MouseEvent& event) { | |
| 132 HandleClickAction(); | |
| 133 return true; | |
| 134 } | |
| 135 | |
| 136 void TrayNotificationView::OnGestureEvent(ui::GestureEvent* event) { | |
| 137 SlideOutView::OnGestureEvent(event); | |
| 138 if (event->handled()) | |
| 139 return; | |
| 140 if (event->type() != ui::ET_GESTURE_TAP) | |
| 141 return; | |
| 142 HandleClickAction(); | |
| 143 event->SetHandled(); | |
| 144 } | |
| 145 | |
| 146 void TrayNotificationView::OnClose() { | |
| 147 } | |
| 148 | |
| 149 void TrayNotificationView::OnClickAction() { | |
| 150 } | |
| 151 | |
| 152 void TrayNotificationView::OnSlideOut() { | |
| 153 owner_->HideNotificationView(); | |
| 154 } | |
| 155 | |
| 156 void TrayNotificationView::HandleClose() { | |
| 157 OnClose(); | |
| 158 owner_->HideNotificationView(); | |
| 159 } | |
| 160 | |
| 161 void TrayNotificationView::HandleClickAction() { | |
| 162 HandleClose(); | |
| 163 OnClickAction(); | |
| 164 } | |
| 165 | |
| 166 } // namespace ash | |
| OLD | NEW |