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