| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ | 5 #ifndef UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ |
| 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ | 6 #define UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ |
| 7 | 7 |
| 8 #include <memory> | 8 #include <memory> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "base/strings/string16.h" | 11 #include "base/strings/string16.h" |
| 12 #include "third_party/skia/include/core/SkBitmap.h" | 12 #include "third_party/skia/include/core/SkBitmap.h" |
| 13 #include "third_party/skia/include/core/SkColor.h" | 13 #include "third_party/skia/include/core/SkColor.h" |
| 14 #include "ui/gfx/geometry/insets.h" | 14 #include "ui/gfx/geometry/insets.h" |
| 15 #include "ui/gfx/image/image.h" | 15 #include "ui/gfx/image/image.h" |
| 16 #include "ui/gfx/image/image_skia.h" | 16 #include "ui/gfx/image/image_skia.h" |
| 17 #include "ui/message_center/message_center_export.h" | 17 #include "ui/message_center/message_center_export.h" |
| 18 #include "ui/message_center/notification.h" | 18 #include "ui/message_center/notification.h" |
| 19 #include "ui/views/controls/button/button.h" | |
| 20 #include "ui/views/controls/slide_out_view.h" | 19 #include "ui/views/controls/slide_out_view.h" |
| 21 | 20 |
| 22 namespace views { | 21 namespace views { |
| 23 class ImageButton; | |
| 24 class ImageView; | 22 class ImageView; |
| 25 class Painter; | 23 class Painter; |
| 26 class ScrollView; | 24 class ScrollView; |
| 27 } | 25 } |
| 28 | 26 |
| 29 namespace message_center { | 27 namespace message_center { |
| 30 | 28 |
| 31 class MessageCenterController; | 29 class MessageCenterController; |
| 32 | 30 |
| 33 // Individual notifications constants. | 31 // Individual notifications constants. |
| 34 const int kPaddingBetweenItems = 10; | 32 const int kPaddingBetweenItems = 10; |
| 35 const int kPaddingHorizontal = 18; | 33 const int kPaddingHorizontal = 18; |
| 36 const int kWebNotificationButtonWidth = 32; | 34 const int kWebNotificationButtonWidth = 32; |
| 37 const int kWebNotificationIconSize = 40; | 35 const int kWebNotificationIconSize = 40; |
| 38 | 36 |
| 39 // An base class for a notification entry. Contains background and other | 37 // An base class for a notification entry. Contains background and other |
| 40 // elements shared by derived notification views. | 38 // elements shared by derived notification views. |
| 41 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView, | 39 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView { |
| 42 public views::ButtonListener { | |
| 43 public: | 40 public: |
| 44 MessageView(MessageCenterController* controller, | 41 MessageView(MessageCenterController* controller, |
| 45 const Notification& notification); | 42 const Notification& notification); |
| 46 ~MessageView() override; | 43 ~MessageView() override; |
| 47 | 44 |
| 48 // Updates this view with the new data contained in the notification. | 45 // Updates this view with the new data contained in the notification. |
| 49 virtual void UpdateWithNotification(const Notification& notification); | 46 virtual void UpdateWithNotification(const Notification& notification); |
| 50 | 47 |
| 51 // Returns the insets for the shadow it will have for rich notification. | 48 // Returns the insets for the shadow it will have for rich notification. |
| 52 static gfx::Insets GetShadowInsets(); | 49 static gfx::Insets GetShadowInsets(); |
| 53 | 50 |
| 54 // Creates a shadow around the notification. | 51 // Creates a shadow around the notification. |
| 55 void CreateShadowBorder(); | 52 void CreateShadowBorder(); |
| 56 | 53 |
| 57 bool IsCloseButtonFocused(); | 54 virtual bool IsCloseButtonFocused() const = 0; |
| 58 void RequestFocusOnCloseButton(); | 55 virtual void RequestFocusOnCloseButton() = 0; |
| 59 bool IsPinned(); | 56 virtual bool IsPinned() const = 0; |
| 60 | 57 |
| 61 // Overridden from views::View: | 58 // Overridden from views::View: |
| 62 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 59 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
| 63 bool OnMousePressed(const ui::MouseEvent& event) override; | 60 bool OnMousePressed(const ui::MouseEvent& event) override; |
| 64 bool OnKeyPressed(const ui::KeyEvent& event) override; | 61 bool OnKeyPressed(const ui::KeyEvent& event) override; |
| 65 bool OnKeyReleased(const ui::KeyEvent& event) override; | 62 bool OnKeyReleased(const ui::KeyEvent& event) override; |
| 66 void OnPaint(gfx::Canvas* canvas) override; | 63 void OnPaint(gfx::Canvas* canvas) override; |
| 67 void OnFocus() override; | 64 void OnFocus() override; |
| 68 void OnBlur() override; | 65 void OnBlur() override; |
| 69 void Layout() override; | 66 void Layout() override; |
| 70 | 67 |
| 71 // Overridden from ui::EventHandler: | 68 // Overridden from ui::EventHandler: |
| 72 void OnGestureEvent(ui::GestureEvent* event) override; | 69 void OnGestureEvent(ui::GestureEvent* event) override; |
| 73 | 70 |
| 74 // Overridden from ButtonListener: | |
| 75 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 76 | |
| 77 void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; } | 71 void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; } |
| 78 std::string notification_id() { return notification_id_; } | 72 std::string notification_id() { return notification_id_; } |
| 79 NotifierId notifier_id() { return notifier_id_; } | 73 NotifierId notifier_id() { return notifier_id_; } |
| 80 const base::string16& display_source() const { return display_source_; } | 74 const base::string16& display_source() const { return display_source_; } |
| 81 | 75 |
| 82 void set_controller(MessageCenterController* controller) { | 76 void set_controller(MessageCenterController* controller) { |
| 83 controller_ = controller; | 77 controller_ = controller; |
| 84 } | 78 } |
| 85 | 79 |
| 86 protected: | 80 protected: |
| 87 // Overridden from views::SlideOutView: | 81 // Overridden from views::SlideOutView: |
| 88 void OnSlideOut() override; | 82 void OnSlideOut() override; |
| 89 | 83 |
| 90 // Creates and add close button to view hierarchy when necessary. Derived | 84 // Creates and add close button to view hierarchy when necessary. Derived |
| 91 // classes should call this after its view hierarchy is populated to ensure | 85 // classes should call this after its view hierarchy is populated to ensure |
| 92 // it is on top of other views. | 86 // it is on top of other views. |
| 93 void CreateOrUpdateCloseButtonView(const Notification& notification); | 87 void CreateOrUpdateCloseButtonView(const Notification& notification); |
| 94 | 88 |
| 95 // Changes the background color being used by |background_view_| and schedules | 89 // Changes the background color being used by |background_view_| and schedules |
| 96 // a paint. | 90 // a paint. |
| 97 virtual void SetDrawBackgroundAsActive(bool active); | 91 virtual void SetDrawBackgroundAsActive(bool active); |
| 98 | 92 |
| 99 views::View* background_view() { return background_view_; } | 93 views::View* background_view() { return background_view_; } |
| 100 views::ImageView* small_image() { return small_image_view_.get(); } | 94 views::ImageView* small_image() { return small_image_view_.get(); } |
| 101 views::ImageButton* close_button() { return close_button_.get(); } | |
| 102 views::ScrollView* scroller() { return scroller_; } | 95 views::ScrollView* scroller() { return scroller_; } |
| 103 MessageCenterController* controller() { return controller_; } | 96 MessageCenterController* controller() { return controller_; } |
| 104 | 97 |
| 105 private: | 98 private: |
| 106 MessageCenterController* controller_; // Weak, lives longer then views. | 99 MessageCenterController* controller_; // Weak, lives longer then views. |
| 107 std::string notification_id_; | 100 std::string notification_id_; |
| 108 NotifierId notifier_id_; | 101 NotifierId notifier_id_; |
| 109 views::View* background_view_ = nullptr; // Owned by views hierarchy. | 102 views::View* background_view_ = nullptr; // Owned by views hierarchy. |
| 110 std::unique_ptr<views::ImageView> small_image_view_; | 103 std::unique_ptr<views::ImageView> small_image_view_; |
| 111 std::unique_ptr<views::ImageButton> close_button_; | |
| 112 views::ScrollView* scroller_ = nullptr; | 104 views::ScrollView* scroller_ = nullptr; |
| 113 | 105 |
| 114 base::string16 accessible_name_; | 106 base::string16 accessible_name_; |
| 115 | 107 |
| 116 base::string16 display_source_; | 108 base::string16 display_source_; |
| 117 | 109 |
| 118 std::unique_ptr<views::Painter> focus_painter_; | 110 std::unique_ptr<views::Painter> focus_painter_; |
| 119 | 111 |
| 120 DISALLOW_COPY_AND_ASSIGN(MessageView); | 112 DISALLOW_COPY_AND_ASSIGN(MessageView); |
| 121 }; | 113 }; |
| 122 | 114 |
| 123 } // namespace message_center | 115 } // namespace message_center |
| 124 | 116 |
| 125 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ | 117 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ |
| OLD | NEW |