| 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/common/system/tray/tray_notification_view.h" | |
| 6 | |
| 7 #include "ash/common/system/tray/tray_constants.h" | |
| 8 #include "ash/resources/grit/ash_resources.h" | |
| 9 #include "ash/resources/vector_icons/vector_icons.h" | |
| 10 #include "ui/base/resource/resource_bundle.h" | |
| 11 #include "ui/gfx/paint_vector_icon.h" | |
| 12 #include "ui/resources/grit/ui_resources.h" | |
| 13 #include "ui/views/background.h" | |
| 14 #include "ui/views/controls/image_view.h" | |
| 15 #include "ui/views/layout/grid_layout.h" | |
| 16 | |
| 17 namespace ash { | |
| 18 | |
| 19 namespace { | |
| 20 | |
| 21 // Maps a non-MD PNG resource id to its corresponding MD vector icon. | |
| 22 // TODO(tdanderson): Remove this once material design is enabled by | |
| 23 // default. See crbug.com/614453. | |
| 24 const gfx::VectorIcon& ResourceIdToVectorIcon(int resource_id) { | |
| 25 switch (resource_id) { | |
| 26 case IDR_AURA_UBER_TRAY_ACCESSIBILITY_DARK: | |
| 27 return kSystemMenuAccessibilityIcon; | |
| 28 default: | |
| 29 NOTREACHED(); | |
| 30 break; | |
| 31 } | |
| 32 | |
| 33 return gfx::kNoneIcon; | |
| 34 } | |
| 35 | |
| 36 } // namespace | |
| 37 | |
| 38 TrayNotificationView::TrayNotificationView(int icon_id) | |
| 39 : icon_id_(icon_id), icon_(NULL) {} | |
| 40 | |
| 41 TrayNotificationView::~TrayNotificationView() {} | |
| 42 | |
| 43 void TrayNotificationView::InitView(views::View* contents) { | |
| 44 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
| 45 | |
| 46 views::GridLayout* layout = new views::GridLayout(this); | |
| 47 SetLayoutManager(layout); | |
| 48 | |
| 49 views::ImageView* close_button = new views::ImageView(); | |
| 50 close_button->SetImage( | |
| 51 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(IDR_MESSAGE_CLOSE)); | |
| 52 close_button->SetHorizontalAlignment(views::ImageView::CENTER); | |
| 53 close_button->SetVerticalAlignment(views::ImageView::CENTER); | |
| 54 | |
| 55 icon_ = new views::ImageView; | |
| 56 if (icon_id_ != 0) { | |
| 57 icon_->SetImage(gfx::CreateVectorIcon(ResourceIdToVectorIcon(icon_id_), | |
| 58 kMenuIconColor)); | |
| 59 } | |
| 60 | |
| 61 views::ColumnSet* columns = layout->AddColumnSet(0); | |
| 62 | |
| 63 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 64 | |
| 65 // Icon | |
| 66 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
| 67 0, /* resize percent */ | |
| 68 views::GridLayout::FIXED, kNotificationIconWidth, | |
| 69 kNotificationIconWidth); | |
| 70 | |
| 71 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 72 | |
| 73 // Contents | |
| 74 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 75 100, /* resize percent */ | |
| 76 views::GridLayout::FIXED, kTrayNotificationContentsWidth, | |
| 77 kTrayNotificationContentsWidth); | |
| 78 | |
| 79 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal / 2); | |
| 80 | |
| 81 // Close button | |
| 82 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::LEADING, | |
| 83 0, /* resize percent */ | |
| 84 views::GridLayout::FIXED, kNotificationButtonWidth, | |
| 85 kNotificationButtonWidth); | |
| 86 | |
| 87 // Layout rows | |
| 88 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 89 layout->StartRow(0, 0); | |
| 90 layout->AddView(icon_); | |
| 91 layout->AddView(contents); | |
| 92 layout->AddView(close_button); | |
| 93 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 94 } | |
| 95 | |
| 96 } // namespace ash | |
| OLD | NEW |