summaryrefslogtreecommitdiffstats
path: root/ash/system/tray
diff options
context:
space:
mode:
Diffstat (limited to 'ash/system/tray')
-rw-r--r--ash/system/tray/tray_views.cc50
-rw-r--r--ash/system/tray/tray_views.h24
2 files changed, 74 insertions, 0 deletions
diff --git a/ash/system/tray/tray_views.cc b/ash/system/tray/tray_views.cc
index 84f5f16..50aa8aa 100644
--- a/ash/system/tray/tray_views.cc
+++ b/ash/system/tray/tray_views.cc
@@ -8,14 +8,17 @@
#include "third_party/skia/include/core/SkBitmap.h"
#include "grit/ash_strings.h"
#include "grit/ui_resources.h"
+#include "grit/ui_resources_standard.h"
#include "ui/base/accessibility/accessible_view_state.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/image/image.h"
#include "ui/views/border.h"
+#include "ui/views/controls/button/image_button.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/layout/fill_layout.h"
+#include "ui/views/layout/grid_layout.h"
#include "ui/views/painter.h"
namespace ash {
@@ -33,6 +36,7 @@ views::View* CreatePopupHeaderButtonsContainer() {
return view;
}
+const int kNotificationCloseButtonWidth = 60;
}
////////////////////////////////////////////////////////////////////////////////
@@ -448,5 +452,51 @@ void SetupLabelForTray(views::Label* label) {
label->SetShadowOffset(0, 1);
}
+////////////////////////////////////////////////////////////////////////////////
+// TrayNotificationView
+
+TrayNotificationView::TrayNotificationView() {
+}
+
+void TrayNotificationView::InitView(views::View* contents) {
+ set_background(views::Background::CreateSolidBackground(kBackgroundColor));
+
+ views::GridLayout* layout = new views::GridLayout(this);
+ SetLayoutManager(layout);
+
+ AddChildView(contents);
+
+ views::ImageButton* close_button = new views::ImageButton(this);
+ close_button->SetImage(views::CustomButton::BS_NORMAL,
+ ResourceBundle::GetSharedInstance().GetBitmapNamed(
+ IDR_AURA_WINDOW_CLOSE));
+ AddChildView(close_button);
+
+ int contents_width = kTrayPopupWidth - kNotificationCloseButtonWidth;
+ views::ColumnSet* columns = layout->AddColumnSet(0);
+ columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL,
+ 0, /* resize percent */
+ views::GridLayout::FIXED,
+ contents_width,
+ contents_width);
+ columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER,
+ 0, /* resize percent */
+ views::GridLayout::FIXED,
+ kNotificationCloseButtonWidth,
+ kNotificationCloseButtonWidth);
+
+ layout->StartRow(0, 0);
+ layout->AddView(contents);
+ layout->AddView(close_button);
+}
+
+TrayNotificationView::~TrayNotificationView() {
+}
+
+void TrayNotificationView::ButtonPressed(views::Button* sender,
+ const views::Event& event) {
+ OnClose();
+}
+
} // namespace internal
} // namespace ash
diff --git a/ash/system/tray/tray_views.h b/ash/system/tray/tray_views.h
index dab672e..440036d 100644
--- a/ash/system/tray/tray_views.h
+++ b/ash/system/tray/tray_views.h
@@ -238,6 +238,30 @@ class SpecialPopupRow : public views::View {
DISALLOW_COPY_AND_ASSIGN(SpecialPopupRow);
};
+// A view for closable notification views, laid out like:
+// [ contents (x) ]
+// The close button will call OnClose() when pressed.
+class TrayNotificationView : public views::View,
+ public views::ButtonListener {
+ public:
+ TrayNotificationView();
+ virtual ~TrayNotificationView();
+
+ // InitView must be called once with the contents to be displayed.
+ void InitView(views::View* contents);
+
+ // Overridden from ButtonListener.
+ virtual void ButtonPressed(views::Button* sender,
+ const views::Event& event) OVERRIDE;
+
+ protected:
+ // Called when the closed button is pressed.
+ virtual void OnClose() = 0;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(TrayNotificationView);
+};
+
// Sets up a Label properly for the tray (sets color, font etc.).
void SetupLabelForTray(views::Label* label);