| 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 #include "ui/message_center/views/notification_view.h" | 5 #include "ui/message_center/views/notification_view.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 #include "ui/views/controls/label.h" | 43 #include "ui/views/controls/label.h" |
| 44 #include "ui/views/controls/progress_bar.h" | 44 #include "ui/views/controls/progress_bar.h" |
| 45 #include "ui/views/layout/box_layout.h" | 45 #include "ui/views/layout/box_layout.h" |
| 46 #include "ui/views/layout/fill_layout.h" | 46 #include "ui/views/layout/fill_layout.h" |
| 47 #include "ui/views/native_cursor.h" | 47 #include "ui/views/native_cursor.h" |
| 48 #include "ui/views/painter.h" | 48 #include "ui/views/painter.h" |
| 49 #include "ui/views/view_targeter.h" | 49 #include "ui/views/view_targeter.h" |
| 50 #include "ui/views/widget/widget.h" | 50 #include "ui/views/widget/widget.h" |
| 51 #include "url/gurl.h" | 51 #include "url/gurl.h" |
| 52 | 52 |
| 53 #if defined(OS_WIN) | |
| 54 #include "ui/base/win/shell.h" | |
| 55 #endif | |
| 56 | |
| 57 namespace { | 53 namespace { |
| 58 | 54 |
| 59 // Dimensions. | 55 // Dimensions. |
| 60 const int kProgressBarBottomPadding = 0; | 56 const int kProgressBarBottomPadding = 0; |
| 61 | 57 |
| 62 // static | 58 // static |
| 63 std::unique_ptr<views::Border> MakeEmptyBorder(int top, | 59 std::unique_ptr<views::Border> MakeEmptyBorder(int top, |
| 64 int left, | 60 int left, |
| 65 int bottom, | 61 int bottom, |
| 66 int right) { | 62 int right) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 for (int i = 0; i < child_count(); ++i) | 135 for (int i = 0; i < child_count(); ++i) |
| 140 child_at(i)->SetVisible(visible); | 136 child_at(i)->SetVisible(visible); |
| 141 } | 137 } |
| 142 | 138 |
| 143 } // namespace | 139 } // namespace |
| 144 | 140 |
| 145 namespace message_center { | 141 namespace message_center { |
| 146 | 142 |
| 147 // NotificationView //////////////////////////////////////////////////////////// | 143 // NotificationView //////////////////////////////////////////////////////////// |
| 148 | 144 |
| 149 // static | |
| 150 MessageView* NotificationView::Create(MessageCenterController* controller, | |
| 151 const Notification& notification, | |
| 152 bool top_level) { | |
| 153 switch (notification.type()) { | |
| 154 case NOTIFICATION_TYPE_BASE_FORMAT: | |
| 155 case NOTIFICATION_TYPE_IMAGE: | |
| 156 case NOTIFICATION_TYPE_MULTIPLE: | |
| 157 case NOTIFICATION_TYPE_SIMPLE: | |
| 158 case NOTIFICATION_TYPE_PROGRESS: | |
| 159 break; | |
| 160 default: | |
| 161 // If the caller asks for an unrecognized kind of view (entirely possible | |
| 162 // if an application is running on an older version of this code that | |
| 163 // doesn't have the requested kind of notification template), we'll fall | |
| 164 // back to a notification instance that will provide at least basic | |
| 165 // functionality. | |
| 166 LOG(WARNING) << "Unable to fulfill request for unrecognized " | |
| 167 << "notification type " << notification.type() << ". " | |
| 168 << "Falling back to simple notification type."; | |
| 169 } | |
| 170 | |
| 171 // Currently all roads lead to the generic NotificationView. | |
| 172 NotificationView* notification_view = | |
| 173 new NotificationView(controller, notification); | |
| 174 | |
| 175 #if defined(OS_LINUX) && !defined(OS_CHROMEOS) | |
| 176 // Don't create shadows for notification toasts on linux wih aura. | |
| 177 if (top_level) | |
| 178 return notification_view; | |
| 179 #endif | |
| 180 | |
| 181 #if defined(OS_WIN) | |
| 182 // Don't create shadows for notifications on Windows under classic theme. | |
| 183 if (top_level && !ui::win::IsAeroGlassEnabled()) { | |
| 184 return notification_view; | |
| 185 } | |
| 186 #endif // OS_WIN | |
| 187 | |
| 188 notification_view->CreateShadowBorder(); | |
| 189 return notification_view; | |
| 190 } | |
| 191 | |
| 192 views::View* NotificationView::TargetForRect(views::View* root, | 145 views::View* NotificationView::TargetForRect(views::View* root, |
| 193 const gfx::Rect& rect) { | 146 const gfx::Rect& rect) { |
| 194 CHECK_EQ(root, this); | 147 CHECK_EQ(root, this); |
| 195 | 148 |
| 196 // TODO(tdanderson): Modify this function to support rect-based event | 149 // TODO(tdanderson): Modify this function to support rect-based event |
| 197 // targeting. Using the center point of |rect| preserves this function's | 150 // targeting. Using the center point of |rect| preserves this function's |
| 198 // expected behavior for the time being. | 151 // expected behavior for the time being. |
| 199 gfx::Point point = rect.CenterPoint(); | 152 gfx::Point point = rect.CenterPoint(); |
| 200 | 153 |
| 201 // Want to return this for underlying views, otherwise GetCursor is not | 154 // Want to return this for underlying views, otherwise GetCursor is not |
| (...skipping 556 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 758 | 711 |
| 759 return message_line_limit; | 712 return message_line_limit; |
| 760 } | 713 } |
| 761 | 714 |
| 762 int NotificationView::GetMessageHeight(int width, int limit) const { | 715 int NotificationView::GetMessageHeight(int width, int limit) const { |
| 763 return message_view_ ? | 716 return message_view_ ? |
| 764 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; | 717 message_view_->GetSizeForWidthAndLines(width, limit).height() : 0; |
| 765 } | 718 } |
| 766 | 719 |
| 767 } // namespace message_center | 720 } // namespace message_center |
| OLD | NEW |