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/slide_out_view.h" | 19 #include "ui/message_center/views/slide_out_controller.h" |
| 20 #include "ui/views/view.h" |
20 | 21 |
21 namespace views { | 22 namespace views { |
22 class Painter; | 23 class Painter; |
23 class ScrollView; | 24 class ScrollView; |
24 } | 25 } |
25 | 26 |
26 namespace message_center { | 27 namespace message_center { |
27 | 28 |
28 class MessageCenterController; | 29 class MessageCenterController; |
29 | 30 |
30 // Individual notifications constants. | 31 // Individual notifications constants. |
31 const int kPaddingBetweenItems = 10; | 32 const int kPaddingBetweenItems = 10; |
32 const int kPaddingHorizontal = 18; | 33 const int kPaddingHorizontal = 18; |
33 const int kWebNotificationButtonWidth = 32; | 34 const int kWebNotificationButtonWidth = 32; |
34 const int kWebNotificationIconSize = 40; | 35 const int kWebNotificationIconSize = 40; |
35 | 36 |
36 // An base class for a notification entry. Contains background and other | 37 // An base class for a notification entry. Contains background and other |
37 // elements shared by derived notification views. | 38 // elements shared by derived notification views. |
38 class MESSAGE_CENTER_EXPORT MessageView : public views::SlideOutView { | 39 class MESSAGE_CENTER_EXPORT MessageView |
| 40 : public views::View, |
| 41 public views::SlideOutController::Delegate { |
39 public: | 42 public: |
40 MessageView(MessageCenterController* controller, | 43 MessageView(MessageCenterController* controller, |
41 const Notification& notification); | 44 const Notification& notification); |
42 ~MessageView() override; | 45 ~MessageView() override; |
43 | 46 |
44 // Updates this view with the new data contained in the notification. | 47 // Updates this view with the new data contained in the notification. |
45 virtual void UpdateWithNotification(const Notification& notification); | 48 virtual void UpdateWithNotification(const Notification& notification); |
46 | 49 |
47 // Returns the insets for the shadow it will have for rich notification. | 50 // Returns the insets for the shadow it will have for rich notification. |
48 static gfx::Insets GetShadowInsets(); | 51 static gfx::Insets GetShadowInsets(); |
49 | 52 |
50 // Creates a shadow around the notification. | 53 // Creates a shadow around the notification and changes slide-out behavior. |
51 void CreateShadowBorder(); | 54 void SetIsNested(); |
52 | 55 |
53 virtual bool IsCloseButtonFocused() const = 0; | 56 virtual bool IsCloseButtonFocused() const = 0; |
54 virtual void RequestFocusOnCloseButton() = 0; | 57 virtual void RequestFocusOnCloseButton() = 0; |
55 virtual bool IsPinned() const = 0; | 58 virtual bool IsPinned() const = 0; |
56 virtual void UpdateControlButtonsVisibility() = 0; | 59 virtual void UpdateControlButtonsVisibility() = 0; |
57 | 60 |
58 void OnCloseButtonPressed(); | 61 void OnCloseButtonPressed(); |
59 | 62 |
60 // Overridden from views::View: | 63 // views::View |
61 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; | 64 void GetAccessibleNodeData(ui::AXNodeData* node_data) override; |
62 bool OnMousePressed(const ui::MouseEvent& event) override; | 65 bool OnMousePressed(const ui::MouseEvent& event) override; |
63 bool OnKeyPressed(const ui::KeyEvent& event) override; | 66 bool OnKeyPressed(const ui::KeyEvent& event) override; |
64 bool OnKeyReleased(const ui::KeyEvent& event) override; | 67 bool OnKeyReleased(const ui::KeyEvent& event) override; |
65 void OnPaint(gfx::Canvas* canvas) override; | 68 void OnPaint(gfx::Canvas* canvas) override; |
66 void OnFocus() override; | 69 void OnFocus() override; |
67 void OnBlur() override; | 70 void OnBlur() override; |
68 void Layout() override; | 71 void Layout() override; |
| 72 void OnGestureEvent(ui::GestureEvent* event) override; |
69 | 73 |
70 // Overridden from ui::EventHandler: | 74 // views::SlideOutController::Delegate |
71 void OnGestureEvent(ui::GestureEvent* event) override; | 75 ui::Layer* GetSlideOutLayer() override; |
| 76 void OnSlideOut() override; |
72 | 77 |
73 void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; } | 78 void set_scroller(views::ScrollView* scroller) { scroller_ = scroller; } |
74 std::string notification_id() { return notification_id_; } | 79 std::string notification_id() { return notification_id_; } |
75 NotifierId notifier_id() { return notifier_id_; } | 80 NotifierId notifier_id() { return notifier_id_; } |
76 const base::string16& display_source() const { return display_source_; } | 81 const base::string16& display_source() const { return display_source_; } |
77 | 82 |
78 void set_controller(MessageCenterController* controller) { | 83 void set_controller(MessageCenterController* controller) { |
79 controller_ = controller; | 84 controller_ = controller; |
80 } | 85 } |
81 | 86 |
82 protected: | 87 protected: |
83 // Overridden from views::SlideOutView: | |
84 void OnSlideOut() override; | |
85 | |
86 // Creates and add close button to view hierarchy when necessary. Derived | 88 // Creates and add close button to view hierarchy when necessary. Derived |
87 // classes should call this after its view hierarchy is populated to ensure | 89 // classes should call this after its view hierarchy is populated to ensure |
88 // it is on top of other views. | 90 // it is on top of other views. |
89 void CreateOrUpdateCloseButtonView(const Notification& notification); | 91 void CreateOrUpdateCloseButtonView(const Notification& notification); |
90 | 92 |
91 // Changes the background color being used by |background_view_| and schedules | 93 // Changes the background color being used by |background_view_| and schedules |
92 // a paint. | 94 // a paint. |
93 virtual void SetDrawBackgroundAsActive(bool active); | 95 virtual void SetDrawBackgroundAsActive(bool active); |
94 | 96 |
95 views::View* background_view() { return background_view_; } | 97 views::View* background_view() { return background_view_; } |
96 views::ScrollView* scroller() { return scroller_; } | 98 views::ScrollView* scroller() { return scroller_; } |
97 MessageCenterController* controller() { return controller_; } | 99 MessageCenterController* controller() { return controller_; } |
98 | 100 |
99 private: | 101 private: |
100 MessageCenterController* controller_; // Weak, lives longer then views. | 102 MessageCenterController* controller_; // Weak, lives longer then views. |
101 std::string notification_id_; | 103 std::string notification_id_; |
102 NotifierId notifier_id_; | 104 NotifierId notifier_id_; |
103 views::View* background_view_ = nullptr; // Owned by views hierarchy. | 105 views::View* background_view_ = nullptr; // Owned by views hierarchy. |
104 views::ScrollView* scroller_ = nullptr; | 106 views::ScrollView* scroller_ = nullptr; |
105 | 107 |
106 base::string16 accessible_name_; | 108 base::string16 accessible_name_; |
107 | 109 |
108 base::string16 display_source_; | 110 base::string16 display_source_; |
109 | 111 |
110 std::unique_ptr<views::Painter> focus_painter_; | 112 std::unique_ptr<views::Painter> focus_painter_; |
111 | 113 |
| 114 views::SlideOutController slide_out_controller_; |
| 115 |
| 116 // True if |this| is embedded in another view. Equivalent to |!top_level| in |
| 117 // MessageViewFactory parlance. |
| 118 bool is_nested_ = false; |
| 119 |
112 DISALLOW_COPY_AND_ASSIGN(MessageView); | 120 DISALLOW_COPY_AND_ASSIGN(MessageView); |
113 }; | 121 }; |
114 | 122 |
115 } // namespace message_center | 123 } // namespace message_center |
116 | 124 |
117 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ | 125 #endif // UI_MESSAGE_CENTER_VIEWS_MESSAGE_VIEW_H_ |
OLD | NEW |