Chromium Code Reviews| 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_NOTIFICATION_VIEW_H_ | 5 #ifndef UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ |
| 6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ | 6 #define UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ |
| 7 | 7 |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/gtest_prod_util.h" | 10 #include "base/gtest_prod_util.h" |
| 11 #include "base/macros.h" | 11 #include "base/macros.h" |
| 12 #include "ui/message_center/message_center_export.h" | 12 #include "ui/message_center/message_center_export.h" |
| 13 #include "ui/message_center/views/message_view.h" | 13 #include "ui/message_center/views/message_view.h" |
| 14 #include "ui/views/view_targeter_delegate.h" | 14 #include "ui/views/view_targeter_delegate.h" |
| 15 | 15 |
| 16 class GURL; | 16 class GURL; |
| 17 | 17 |
| 18 namespace views { | 18 namespace views { |
| 19 class ProgressBar; | 19 class ProgressBar; |
| 20 } | 20 } |
| 21 | 21 |
| 22 namespace message_center { | 22 namespace message_center { |
| 23 | 23 |
| 24 class BoundedLabel; | 24 class BoundedLabel; |
| 25 class MessageCenter; | 25 class MessageCenter; |
| 26 class MessageCenterController; | |
| 27 class NotificationButton; | 26 class NotificationButton; |
| 28 class NotificationProgressBarBase; | 27 class NotificationProgressBarBase; |
| 29 class NotificationView; | 28 class NotificationView; |
| 30 class PaddedButton; | 29 class PaddedButton; |
| 31 class ProportionalImageView; | 30 class ProportionalImageView; |
| 32 | 31 |
| 33 // View that displays all current types of notification (web, basic, image, and | 32 // View that displays all current types of notification (web, basic, image, and |
| 34 // list). Future notification types may be handled by other classes, in which | 33 // list). Future notification types may be handled by other classes, in which |
| 35 // case instances of those classes would be returned by the Create() factory | 34 // case instances of those classes would be returned by the Create() factory |
| 36 // method below. | 35 // method below. |
| 37 class MESSAGE_CENTER_EXPORT NotificationView | 36 class MESSAGE_CENTER_EXPORT NotificationView |
| 38 : public MessageView, | 37 : public MessageView, |
| 39 public views::ViewTargeterDelegate, | 38 public views::ViewTargeterDelegate { |
| 40 public MessageViewController { | |
| 41 public: | 39 public: |
| 42 // Creates appropriate MessageViews for notifications. Those currently are | 40 // Creates appropriate MessageViews for notifications. Those currently are |
| 43 // always NotificationView instances but in the future | 41 // always NotificationView instances but in the future |
| 44 // may be instances of other classes, with the class depending on the | 42 // may be instances of other classes, with the class depending on the |
| 45 // notification type. A notification is top level if it needs to be rendered | 43 // notification type. A notification is top level if it needs to be rendered |
| 46 // outside the browser window. No custom shadows are created for top level | 44 // outside the browser window. No custom shadows are created for top level |
| 47 // notifications on Linux with Aura. | 45 // notifications on Linux with Aura. |
| 48 // |controller| may be NULL, but has to be set before the view is shown. | 46 // |controller| may be NULL, but has to be set before the view is shown. |
| 49 static NotificationView* Create(MessageCenterController* controller, | 47 static MessageView* Create(MessageCenterController* controller, |
|
dewittj
2016/05/13 20:24:32
Is there a reason to return a MessageView here?
xiyuan
2016/05/13 21:07:39
Yes. The incoming CustomNotificationView will be c
| |
| 50 const Notification& notification, | 48 const Notification& notification, |
| 51 bool top_level); | 49 bool top_level); |
| 52 ~NotificationView() override; | 50 ~NotificationView() override; |
| 53 | 51 |
| 54 // Overridden from views::View: | 52 // Overridden from views::View: |
| 55 gfx::Size GetPreferredSize() const override; | 53 gfx::Size GetPreferredSize() const override; |
| 56 int GetHeightForWidth(int width) const override; | 54 int GetHeightForWidth(int width) const override; |
| 57 void Layout() override; | 55 void Layout() override; |
| 58 void OnFocus() override; | 56 void OnFocus() override; |
| 59 void ScrollRectToVisible(const gfx::Rect& rect) override; | 57 void ScrollRectToVisible(const gfx::Rect& rect) override; |
| 60 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; | 58 gfx::NativeCursor GetCursor(const ui::MouseEvent& event) override; |
| 61 | 59 |
| 62 // Overridden from MessageView: | 60 // Overridden from MessageView: |
| 63 void UpdateWithNotification(const Notification& notification) override; | 61 void UpdateWithNotification(const Notification& notification) override; |
| 64 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | 62 void ButtonPressed(views::Button* sender, const ui::Event& event) override; |
| 65 bool IsCloseButtonFocused() override; | 63 bool IsCloseButtonFocused() override; |
| 66 void RequestFocusOnCloseButton() override; | 64 void RequestFocusOnCloseButton() override; |
| 67 bool IsPinned() override; | 65 bool IsPinned() override; |
| 68 | 66 |
| 69 // Overridden from MessageViewController: | |
| 70 void ClickOnNotification(const std::string& notification_id) override; | |
| 71 void RemoveNotification(const std::string& notification_id, | |
| 72 bool by_user) override; | |
| 73 | |
| 74 void set_controller(MessageCenterController* controller) { | |
| 75 controller_ = controller; | |
| 76 } | |
| 77 | |
| 78 protected: | 67 protected: |
| 79 NotificationView(MessageCenterController* controller, | 68 NotificationView(MessageCenterController* controller, |
| 80 const Notification& notification); | 69 const Notification& notification); |
| 81 | 70 |
| 82 private: | 71 private: |
| 83 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, CreateOrUpdateTest); | 72 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, CreateOrUpdateTest); |
| 84 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, | 73 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, |
| 85 CreateOrUpdateTestSettingsButton); | 74 CreateOrUpdateTestSettingsButton); |
| 86 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, FormatContextMessageTest); | 75 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, FormatContextMessageTest); |
| 87 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, SettingsButtonTest); | 76 FRIEND_TEST_ALL_PREFIXES(NotificationViewTest, SettingsButtonTest); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 112 | 101 |
| 113 int GetMessageLineLimit(int title_lines, int width) const; | 102 int GetMessageLineLimit(int title_lines, int width) const; |
| 114 int GetMessageHeight(int width, int limit) const; | 103 int GetMessageHeight(int width, int limit) const; |
| 115 | 104 |
| 116 // Formats the context message to be displayed based on |context| | 105 // Formats the context message to be displayed based on |context| |
| 117 // so it shows as much information as possible | 106 // so it shows as much information as possible |
| 118 // given the space available in the ContextMessage section of the | 107 // given the space available in the ContextMessage section of the |
| 119 // notification. | 108 // notification. |
| 120 base::string16 FormatContextMessage(const Notification& notification) const; | 109 base::string16 FormatContextMessage(const Notification& notification) const; |
| 121 | 110 |
| 122 MessageCenterController* controller_; // Weak, lives longer then views. | |
| 123 | |
| 124 // Describes whether the view should display a hand pointer or not. | 111 // Describes whether the view should display a hand pointer or not. |
| 125 bool clickable_; | 112 bool clickable_; |
| 126 | 113 |
| 127 // Weak references to NotificationView descendants owned by their parents. | 114 // Weak references to NotificationView descendants owned by their parents. |
| 128 views::View* top_view_; | 115 views::View* top_view_; |
| 129 BoundedLabel* title_view_; | 116 BoundedLabel* title_view_; |
| 130 BoundedLabel* message_view_; | 117 BoundedLabel* message_view_; |
| 131 BoundedLabel* context_message_view_; | 118 BoundedLabel* context_message_view_; |
| 132 views::ImageButton* settings_button_view_; | 119 views::ImageButton* settings_button_view_; |
| 133 std::vector<views::View*> item_views_; | 120 std::vector<views::View*> item_views_; |
| 134 ProportionalImageView* icon_view_; | 121 ProportionalImageView* icon_view_; |
| 135 views::View* bottom_view_; | 122 views::View* bottom_view_; |
| 136 views::View* image_container_; | 123 views::View* image_container_; |
| 137 ProportionalImageView* image_view_; | 124 ProportionalImageView* image_view_; |
| 138 NotificationProgressBarBase* progress_bar_view_; | 125 NotificationProgressBarBase* progress_bar_view_; |
| 139 std::vector<NotificationButton*> action_buttons_; | 126 std::vector<NotificationButton*> action_buttons_; |
| 140 std::unique_ptr<views::ImageButton> close_button_; | 127 std::unique_ptr<views::ImageButton> close_button_; |
| 141 std::vector<views::View*> separators_; | 128 std::vector<views::View*> separators_; |
| 142 | 129 |
| 143 DISALLOW_COPY_AND_ASSIGN(NotificationView); | 130 DISALLOW_COPY_AND_ASSIGN(NotificationView); |
| 144 }; | 131 }; |
| 145 | 132 |
| 146 } // namespace message_center | 133 } // namespace message_center |
| 147 | 134 |
| 148 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ | 135 #endif // UI_MESSAGE_CENTER_VIEWS_NOTIFICATION_VIEW_H_ |
| OLD | NEW |