Chromium Code Reviews| 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/system/tray/system_tray_item.h" | |
| 8 #include "ash/system/tray/tray_constants.h" | |
| 9 #include "grit/ash_strings.h" | |
| 10 #include "grit/ui_resources_standard.h" | |
| 11 #include "ui/base/resource/resource_bundle.h" | |
| 12 #include "ui/gfx/image/image_skia.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 namespace internal { | |
| 19 | |
| 20 TrayNotificationView::TrayNotificationView(SystemTrayItem* tray, int icon_id) | |
| 21 : tray_(tray), | |
| 22 icon_id_(icon_id), | |
| 23 icon_(NULL) { | |
| 24 } | |
| 25 | |
| 26 TrayNotificationView::~TrayNotificationView() { | |
| 27 } | |
| 28 | |
| 29 void TrayNotificationView::InitView(views::View* contents) { | |
|
stevenjb
2012/06/29 22:37:02
InitView through UpdateViewAndImage are unchanged.
| |
| 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::BS_NORMAL, | |
| 37 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 38 IDR_AURA_WINDOW_CLOSE)); | |
| 39 | |
| 40 icon_ = new views::ImageView; | |
| 41 if (icon_id_ != 0) { | |
| 42 icon_->SetImage( | |
| 43 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); | |
| 44 } | |
| 45 | |
| 46 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 47 | |
| 48 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 49 | |
| 50 // Icon | |
| 51 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
| 52 0, /* resize percent */ | |
| 53 views::GridLayout::FIXED, | |
| 54 kNotificationIconWidth, kNotificationIconWidth); | |
| 55 | |
| 56 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 57 | |
| 58 // Contents | |
| 59 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 60 0, /* resize percent */ | |
| 61 views::GridLayout::FIXED, | |
| 62 kTrayNotificationContentsWidth, | |
| 63 kTrayNotificationContentsWidth); | |
| 64 | |
| 65 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 66 | |
| 67 // Close button | |
| 68 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
| 69 0, /* resize percent */ | |
| 70 views::GridLayout::FIXED, | |
| 71 kNotificationIconWidth, kNotificationIconWidth); | |
| 72 | |
| 73 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 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 | |
|
stevenjb
2012/06/29 22:37:02
Changed code starts here:
| |
| 107 void TrayNotificationView::ButtonPressed(views::Button* sender, | |
| 108 const views::Event& event) { | |
| 109 HandleClose(); | |
| 110 } | |
| 111 | |
| 112 bool TrayNotificationView::OnMousePressed(const views::MouseEvent& event) { | |
| 113 HandleClickAction(); | |
| 114 return true; | |
| 115 } | |
| 116 | |
| 117 ui::GestureStatus TrayNotificationView::OnGestureEvent( | |
| 118 const views::GestureEvent& event) { | |
| 119 if (event.type() != ui::ET_GESTURE_TAP) | |
| 120 return ui::GESTURE_STATUS_UNKNOWN; | |
| 121 HandleClickAction(); | |
| 122 return ui::GESTURE_STATUS_CONSUMED; | |
| 123 } | |
| 124 | |
| 125 void TrayNotificationView::OnClose() { | |
| 126 } | |
| 127 | |
| 128 void TrayNotificationView::OnClickAction() { | |
| 129 } | |
| 130 | |
| 131 void TrayNotificationView::HandleClose() { | |
| 132 OnClose(); | |
| 133 tray_->HideNotificationView(); | |
| 134 } | |
| 135 | |
| 136 void TrayNotificationView::HandleClickAction() { | |
| 137 HandleClose(); | |
| 138 OnClickAction(); | |
| 139 } | |
| 140 | |
| 141 } // namespace internal | |
| 142 } // namespace ash | |
| OLD | NEW |