Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(181)

Unified Diff: ash/system/web_notification/web_notification_tray.h

Issue 10546125: Add WebNotificationTray to the status area (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/web_notification/web_notification_tray.h
diff --git a/ash/system/web_notification/web_notification_tray.h b/ash/system/web_notification/web_notification_tray.h
new file mode 100644
index 0000000000000000000000000000000000000000..b696afb2c5c72128cfc2921c8d5471746970cc3f
--- /dev/null
+++ b/ash/system/web_notification/web_notification_tray.h
@@ -0,0 +1,158 @@
+// Copyright (c) 2012 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
+#define ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_
+#pragma once
+
+#include "ash/ash_export.h"
+#include "ash/system/tray/tray_background_view.h"
+#include "base/gtest_prod_util.h"
+#include "ui/aura/event_filter.h"
+
+namespace aura {
+class LocatedEvent;
+}
+
+namespace gfx {
+class ImageSkia;
+}
+
+namespace views {
+class ImageView;
+}
+
+namespace ash {
+
+namespace internal {
+class StatusAreaWidget;
+class WebNotificationList;
+}
+
+// Status area tray for showing browser and app notifications. The client
+// (e.g. Chrome) calls [Add|Remove|Update]Notification to create and update
+// notifications in the tray. It can also implement Delegate to receive
+// callbacks when a notification is removed (closed), clicked on, or a menu
+// item is triggered.
+//
+// Note: These are not related to system notifications (i.e NotificationView
+// generated by SystemTrayItem). Visibility of one notification type or other
+// is controlled by StatusAreaWidget.
+
+class ASH_EXPORT WebNotificationTray : public aura::EventFilter,
+ public internal::TrayBackgroundView {
+ public:
+ class Delegate {
+ public:
+ virtual ~Delegate() {}
+
+ // Called when the notification associated with |notification_id| is
+ // removed (i.e. closed by the user).
+ virtual void NotificationRemoved(const std::string& notifcation_id) = 0;
+
+ // Request to disable the extension associated with |notification_id|.
+ virtual void DisableExtension(const std::string& notifcation_id) = 0;
+
+ // Request to disable notifications from the source of |notification_id|.
+ virtual void DisableNotificationsFromSource(
+ const std::string& notifcation_id) = 0;
+
+ // Request to show the notification settings (|notification_id| is used
+ // to identify the requesting browser context).
+ virtual void ShowSettings(const std::string& notifcation_id) = 0;
+
+ // Called when the notification body is clicked on.
+ virtual void OnClicked(const std::string& notifcation_id) = 0;
+ };
+
+ explicit WebNotificationTray(internal::StatusAreaWidget* status_area_widget);
+ virtual ~WebNotificationTray();
+
+ // Called once to set the delegate.
+ void SetDelegate(Delegate* delegate);
+
+ // Add a new notification. Use SetNotificationImage to set the icon image.
+ void AddNotification(const std::string& id,
+ const string16& title,
+ const string16& message,
+ const string16& source,
+ const std::string& extension);
sadrul 2012/06/13 16:37:56 What are |source| and |extension|?
stevenjb 2012/06/13 19:05:02 Yeah, this comment is rather lacking. Much more de
+
+ // Update an existing notification.
+ void UpdateNotification(const std::string& id,
+ const string16& title,
+ const string16& message);
+
+ // Remove an existing notification and notify the delegate.
+ void RemoveNotification(const std::string& id);
+
+ // Remove all notifications and notify the delegate.
+ void RemoveAllNotifications();
+
+ // Set the notification image.
+ void SetNotificationImage(const std::string& id,
+ const gfx::ImageSkia& image);
+
+ // Disable all notifications matching notification |id|.
+ void DisableByExtension(const std::string& id);
+ void DisableByUrl(const std::string& id);
+
+ // Show the notification bubble. Should only be called by StatusAreaWidget.
+ void ShowBubble();
+
+ // Hide the notification bubble. Should only be called by StatusAreaWidget.
+ void HideBubble();
+
+ // Request the Delegate to the settings dialog.
+ void ShowSettings(const std::string& id);
+
+ // Called when a notification is clicked on. Event is passed to the Delegate.
+ void OnClicked(const std::string& id);
+
+ // Overridden from aura::EventFilter.
+ virtual bool PreHandleKeyEvent(aura::Window* target,
+ aura::KeyEvent* event) OVERRIDE;
+ virtual bool PreHandleMouseEvent(aura::Window* target,
+ aura::MouseEvent* event) OVERRIDE;
+ virtual ui::TouchStatus PreHandleTouchEvent(aura::Window* target,
+ aura::TouchEvent* event) OVERRIDE;
+ virtual ui::GestureStatus PreHandleGestureEvent(
+ aura::Window* target,
+ aura::GestureEvent* event) OVERRIDE;
+
+ // Overridden from TrayBackgroundView.
+ virtual void SetShelfAlignment(ShelfAlignment alignment) OVERRIDE;
+
+ // Overridden from internal::ActionableView.
+ virtual bool PerformAction(const views::Event& event) OVERRIDE;
+
+ private:
+ class Bubble;
+ class BubbleContentsView;
+ FRIEND_TEST_ALL_PREFIXES(WebNotificationTrayTest, WebNotifications);
+
+ int GetNotificationCount() const;
+ void UpdateIcon();
+ void UpdateBubbleAndIcon();
+ bool ProcessLocatedEvent(const aura::LocatedEvent& event);
+
+ const internal::WebNotificationList* notification_list() const {
+ return notification_list_.get();
+ }
+ views::View* tray_container() const { return tray_container_; }
+ Bubble* bubble() const { return bubble_.get(); }
+
+ internal::StatusAreaWidget* status_area_widget_; // Unowned parent.
+ scoped_ptr<internal::WebNotificationList> notification_list_;
+ scoped_ptr<Bubble> bubble_;
+ views::View* tray_container_;
+ views::ImageView* icon_;
+ Delegate* delegate_;
+
+ DISALLOW_COPY_AND_ASSIGN(WebNotificationTray);
+};
+
+} // namespace ash
+
+#endif // ASH_SYSTEM_NOTIFICATION_WEB_NOTIFICATION_TRAY_H_

Powered by Google App Engine
This is Rietveld 408576698