Home | History | Annotate | Download | only in views
      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 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
      6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
      7 
      8 #include <vector>
      9 
     10 #include "ui/message_center/message_center_export.h"
     11 #include "ui/message_center/views/message_view.h"
     12 
     13 namespace views {
     14 class ProgressBar;
     15 }
     16 
     17 namespace message_center {
     18 
     19 class BoundedLabel;
     20 class MessageCenter;
     21 class MessageCenterController;
     22 class NotificationView;
     23 class PaddedButton;
     24 
     25 // View that displays all current types of notification (web, basic, image, and
     26 // list). Future notification types may be handled by other classes, in which
     27 // case instances of those classes would be returned by the Create() factory
     28 // method below.
     29 class MESSAGE_CENTER_EXPORT NotificationView : public MessageView,
     30                                                public MessageViewController {
     31  public:
     32   // Creates appropriate MessageViews for notifications. Those currently are
     33   // always NotificationView instances but in the future
     34   // may be instances of other classes, with the class depending on the
     35   // notification type. A notification is top level if it needs to be rendered
     36   // outside the browser window. No custom shadows are created for top level
     37   // notifications on Linux with Aura.
     38   // |controller| may be NULL, but has to be set before the view is shown.
     39   static NotificationView* Create(MessageCenterController* controller,
     40                                   const Notification& notification,
     41                                   bool expanded,
     42                                   bool top_level);
     43 
     44     virtual ~NotificationView();
     45 
     46   // Overridden from views::View:
     47   virtual gfx::Size GetPreferredSize() OVERRIDE;
     48   virtual int GetHeightForWidth(int width) OVERRIDE;
     49   virtual void Layout() OVERRIDE;
     50   virtual void OnFocus() OVERRIDE;
     51   virtual void ScrollRectToVisible(const gfx::Rect& rect) OVERRIDE;
     52   virtual views::View* GetEventHandlerForRect(const gfx::Rect& rect) OVERRIDE;
     53   virtual gfx::NativeCursor GetCursor(const ui::MouseEvent& event) OVERRIDE;
     54 
     55   // Overridden from MessageView:
     56   virtual void ButtonPressed(views::Button* sender,
     57                              const ui::Event& event) OVERRIDE;
     58 
     59   // Overridden from MessageViewController:
     60   virtual void ClickOnNotification(const std::string& notification_id) OVERRIDE;
     61   virtual void RemoveNotification(const std::string& notification_id,
     62                                   bool by_user) OVERRIDE;
     63   virtual void DisableNotificationsFromThisSource(
     64       const NotifierId& notifier_id) OVERRIDE;
     65   virtual void ShowNotifierSettingsBubble() OVERRIDE;
     66 
     67   void set_controller(MessageCenterController* controller) {
     68     controller_ = controller;
     69   }
     70 
     71  protected:
     72   NotificationView(MessageCenterController* controller,
     73                    const Notification& notification,
     74                    bool expanded);
     75 
     76  private:
     77   bool IsExpansionNeeded(int width);
     78   bool IsMessageExpansionNeeded(int width);
     79   int GetMessageLineLimit(int width);
     80   int GetMessageLines(int width, int limit);
     81   int GetMessageHeight(int width, int limit);
     82 
     83   MessageCenterController* controller_;  // Weak, lives longer then views.
     84 
     85   // Describes whether the view should display a hand pointer or not.
     86   bool clickable_;
     87   bool is_expanded_;
     88 
     89   // Weak references to NotificationView descendants owned by their parents.
     90   views::View* background_view_;
     91   views::View* top_view_;
     92   BoundedLabel* title_view_;
     93   BoundedLabel* message_view_;
     94   BoundedLabel* context_message_view_;
     95   std::vector<views::View*> item_views_;
     96   views::View* icon_view_;
     97   views::View* bottom_view_;
     98   views::View* image_view_;
     99   views::ProgressBar* progress_bar_view_;
    100   std::vector<views::View*> action_buttons_;
    101   PaddedButton* expand_button_;
    102 
    103   DISALLOW_COPY_AND_ASSIGN(NotificationView);
    104 };
    105 
    106 }  // namespace message_center
    107 
    108 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_
    109