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