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/strings/string16.h"
      9 #include "ui/gfx/insets.h"
     10 #include "ui/message_center/message_center_export.h"
     11 #include "ui/message_center/notification.h"
     12 #include "ui/views/controls/button/button.h"
     13 #include "ui/views/controls/slide_out_view.h"
     14 
     15 namespace views {
     16 class ImageButton;
     17 class ScrollView;
     18 }
     19 
     20 namespace message_center {
     21 
     22 class MessageCenter;
     23 class MessageCenterTray;
     24 class MessageViewContextMenuController;
     25 
     26 // Individual notifications constants.
     27 const int kPaddingBetweenItems = 10;
     28 const int kPaddingHorizontal = 18;
     29 const int kWebNotificationButtonWidth = 32;
     30 const int kWebNotificationIconSize = 40;
     31 
     32 // An abstract class that forms the basis of a view for a notification entry.
     33 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView,
     34                                           public views::ButtonListener {
     35  public:
     36   MessageView(const Notification& notification,
     37               MessageCenter* message_center,
     38               MessageCenterTray* tray,
     39               bool expanded);
     40   virtual ~MessageView();
     41 
     42   // Returns the insets for the shadow it will have for rich notification.
     43   static gfx::Insets GetShadowInsets();
     44 
     45   // Creates a shadow around the notification.
     46   void CreateShadowBorder();
     47 
     48   bool IsCloseButtonFocused();
     49   void RequestFocusOnCloseButton();
     50 
     51   void set_accessible_name(const string16& name) { accessible_name_ = name; }
     52 
     53   // Overridden from views::View:
     54   virtual void GetAccessibleState(ui::AccessibleViewState* state) OVERRIDE;
     55   virtual bool OnMousePressed(const ui::MouseEvent& event) OVERRIDE;
     56   virtual bool OnKeyPressed(const ui::KeyEvent& event) OVERRIDE;
     57   virtual bool OnKeyReleased(const ui::KeyEvent& event) OVERRIDE;
     58   virtual void OnPaintFocusBorder(gfx::Canvas* canvas) OVERRIDE;
     59 
     60   // Overridden from ui::EventHandler:
     61   virtual void OnGestureEvent(ui::GestureEvent* event) OVERRIDE;
     62 
     63   // Overridden from ButtonListener:
     64   virtual void ButtonPressed(views::Button* sender,
     65                              const ui::Event& event) OVERRIDE;
     66 
     67   const std::string& notification_id() { return notification_id_; }
     68   void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; }
     69 
     70  protected:
     71   MessageView();
     72 
     73   // Overridden from views::SlideOutView:
     74   virtual void OnSlideOut() OVERRIDE;
     75 
     76   MessageCenter* message_center() { return message_center_; }
     77   views::ImageButton* close_button() { return close_button_.get(); }
     78   views::ImageButton* expand_button() { return expand_button_.get(); }
     79   views::ScrollView* scroller() { return scroller_; }
     80   const bool is_expanded() { return is_expanded_; }
     81 
     82  private:
     83   MessageCenter* message_center_;  // Weak reference.
     84   std::string notification_id_;
     85 
     86   scoped_ptr<MessageViewContextMenuController> context_menu_controller_;
     87   scoped_ptr<views::ImageButton> close_button_;
     88   scoped_ptr<views::ImageButton> expand_button_;
     89   views::ScrollView* scroller_;
     90 
     91   string16 accessible_name_;
     92 
     93   bool is_expanded_;
     94 
     95   DISALLOW_COPY_AND_ASSIGN(MessageView);
     96 };
     97 
     98 }  // namespace message_center
     99 
    100 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_
    101