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_MESSAGE_VIEW_H_
      6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_
      7 
      8 #include "base/memory/scoped_ptr.h"
      9 #include "base/strings/string16.h"
     10 #include "ui/gfx/insets.h"
     11 #include "ui/message_center/message_center_export.h"
     12 #include "ui/message_center/notification.h"
     13 #include "ui/views/controls/button/button.h"
     14 #include "ui/views/controls/slide_out_view.h"
     15 
     16 namespace views {
     17 class ImageButton;
     18 class Painter;
     19 class ScrollView;
     20 }
     21 
     22 namespace message_center {
     23 
     24 // Interface that MessageView uses to report clicks and other user actions.
     25 // Provided by creator of MessageView.
     26 class MessageViewController {
     27  public:
     28   virtual void ClickOnNotification(const std::string& notification_id) = 0;
     29   virtual void RemoveNotification(const std::string& notification_id,
     30                                   bool by_user) = 0;
     31   virtual void DisableNotificationsFromThisSource(
     32       const NotifierId& notifier_id) = 0;
     33   virtual void ShowNotifierSettingsBubble() = 0;
     34 };
     35 
     36 class MessageViewContextMenuController;
     37 
     38 // Individual notifications constants.
     39 const int kPaddingBetweenItems = 10;
     40 const int kPaddingHorizontal = 18;
     41 const int kWebNotificationButtonWidth = 32;
     42 const int kWebNotificationIconSize = 40;
     43 
     44 // An abstract class that forms the basis of a view for a notification entry.
     45 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView,
     46                                           public views::ButtonListener {
     47  public:
     48   MessageView(MessageViewController* controller,
     49               const std::string& notification_id,
     50               const NotifierId& notifier_id,
     51               const string16& display_source);
     52   virtual ~MessageView();
     53 
     54   // Returns the insets for the shadow it will have for rich notification.
     55   static gfx::Insets GetShadowInsets();
     56 
     57   // Creates a shadow around the notification.
     58   void CreateShadowBorder();
     59 
     60   bool IsCloseButtonFocused();
     61   void RequestFocusOnCloseButton();
     62 
     63   void set_accessible_name(const string16& name) { accessible_name_ = name; }
     64 
     65   // Overridden from views::View:
     66   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     67   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
     68   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
     69   virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE;
     70   virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE;
     71   virtual void OnFocus() OVERRIDE;
     72   virtual void OnBlur() OVERRIDE;
     73 
     74   // Overridden from ui::EventHandler:
     75   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
     76 
     77   // Overridden from ButtonListener:
     78   virtual void ButtonPressed(views::Button* sender,
     79                              const ui::Event& event) OVERRIDE;
     80 
     81   void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; }
     82   std::string notification_id() { return notification_id_; }
     83   NotifierId notifier_id() { return notifier_id_; }
     84 
     85  protected:
     86   // Overridden from views::SlideOutView:
     87   virtual void OnSlideOut() OVERRIDE;
     88 
     89   views::ImageButton* close_button() { return close_button_.get(); }
     90   views::ScrollView* scroller() { return scroller_; }
     91 
     92  private:
     93   MessageViewController* controller_;
     94   std::string notification_id_;
     95   NotifierId notifier_id_;
     96   scoped_ptr<MessageViewContextMenuController> context_menu_controller_;
     97   scoped_ptr<views::ImageButton> close_button_;
     98   views::ScrollView* scroller_;
     99 
    100   string16 accessible_name_;
    101 
    102   scoped_ptr<views::Painter> focus_painter_;
    103 
    104   DISALLOW_COPY_AND_ASSIGN(MessageView);
    105 };
    106 
    107 }  // namespace message_center
    108 
    109 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_
    110