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/notification_view.h" | 5 #include "ui/message_center/notification_view.h" |
6 | 6 |
7 #include "base/utf_string_conversions.h" | 7 #include "base/utf_string_conversions.h" |
8 #include "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "ui/base/accessibility/accessible_view_state.h" | 9 #include "ui/base/accessibility/accessible_view_state.h" |
10 #include "ui/base/resource/resource_bundle.h" | 10 #include "ui/base/resource/resource_bundle.h" |
(...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
219 NotificationList::Delegate* list_delegate, | 219 NotificationList::Delegate* list_delegate, |
220 const NotificationList::Notification& notification) | 220 const NotificationList::Notification& notification) |
221 : MessageView(list_delegate, notification) { | 221 : MessageView(list_delegate, notification) { |
222 } | 222 } |
223 | 223 |
224 NotificationView::~NotificationView() { | 224 NotificationView::~NotificationView() { |
225 } | 225 } |
226 | 226 |
227 void NotificationView::Layout() { | 227 void NotificationView::Layout() { |
228 if (content_view_) { | 228 if (content_view_) { |
229 content_view_->SetBoundsRect(GetLocalBounds()); | 229 gfx::Rect contents_bounds = GetContentsBounds(); |
| 230 content_view_->SetBoundsRect(contents_bounds); |
230 if (close_button()) { | 231 if (close_button()) { |
231 gfx::Size size(close_button()->GetPreferredSize()); | 232 gfx::Size size(close_button()->GetPreferredSize()); |
232 close_button()->SetBounds(width() - size.width(), 0, | 233 close_button()->SetBounds(contents_bounds.right() - size.width(), 0, |
233 size.width(), size.height()); | 234 size.width(), size.height()); |
234 } | 235 } |
235 } | 236 } |
236 } | 237 } |
237 | 238 |
238 gfx::Size NotificationView::GetPreferredSize() { | 239 gfx::Size NotificationView::GetPreferredSize() { |
239 return content_view_ ? content_view_->GetPreferredSize() : gfx::Size(); | 240 if (!content_view_) |
| 241 return gfx::Size(); |
| 242 gfx::Size size = content_view_->GetPreferredSize(); |
| 243 if (border()) { |
| 244 gfx::Insets border_insets = border()->GetInsets(); |
| 245 size.Enlarge(border_insets.width(), border_insets.height()); |
| 246 } |
| 247 return size; |
240 } | 248 } |
241 | 249 |
242 void NotificationView::SetUpView() { | 250 void NotificationView::SetUpView() { |
243 // This view is composed of two layers: The first layer has the notification | 251 // This view is composed of two layers: The first layer has the notification |
244 // content (text, images, action buttons, ...). This is overlaid by a second | 252 // content (text, images, action buttons, ...). This is overlaid by a second |
245 // layer that has the notification close button and will later also have the | 253 // layer that has the notification close button and will later also have the |
246 // expand button. This allows the close and expand buttons to overlap the | 254 // expand button. This allows the close and expand buttons to overlap the |
247 // content as needed to provide a large enough click area | 255 // content as needed to provide a large enough click area |
248 // (<http://crbug.com/168822> and touch area <http://crbug.com/168856>). | 256 // (<http://crbug.com/168822> and touch area <http://crbug.com/168856>). |
249 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | |
250 AddChildView(MakeContentView()); | 257 AddChildView(MakeContentView()); |
251 AddChildView(close_button()); | 258 AddChildView(close_button()); |
252 } | 259 } |
253 | 260 |
254 void NotificationView::ButtonPressed(views::Button* sender, | 261 void NotificationView::ButtonPressed(views::Button* sender, |
255 const ui::Event& event) { | 262 const ui::Event& event) { |
256 for (size_t i = 0; i < action_buttons_.size(); ++i) { | 263 for (size_t i = 0; i < action_buttons_.size(); ++i) { |
257 if (action_buttons_[i] == sender) { | 264 if (action_buttons_[i] == sender) { |
258 list_delegate()->OnButtonClicked(notification().id, i); | 265 list_delegate()->OnButtonClicked(notification().id, i); |
259 return; | 266 return; |
260 } | 267 } |
261 } | 268 } |
262 MessageView::ButtonPressed(sender, event); | 269 MessageView::ButtonPressed(sender, event); |
263 } | 270 } |
264 | 271 |
265 views::View* NotificationView::MakeContentView() { | 272 views::View* NotificationView::MakeContentView() { |
266 content_view_ = new views::View(); | 273 content_view_ = new views::View(); |
| 274 content_view_->set_background( |
| 275 views::Background::CreateSolidBackground(kBackgroundColor)); |
267 | 276 |
268 // The top part of the content view is composed of an icon view on the left | 277 // The top part of the content view is composed of an icon view on the left |
269 // and a certain number of text views on the right (title and message or list | 278 // and a certain number of text views on the right (title and message or list |
270 // items), followed by a padding view. Laying out the icon view will require | 279 // items), followed by a padding view. Laying out the icon view will require |
271 // information about the text views, so these are created first and collected | 280 // information about the text views, so these are created first and collected |
272 // in this vector. | 281 // in this vector. |
273 std::vector<views::View*> texts; | 282 std::vector<views::View*> texts; |
274 | 283 |
275 // Title if it exists. | 284 // Title if it exists. |
276 if (!notification().title.empty()) { | 285 if (!notification().title.empty()) { |
(...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 action_buttons_.push_back(button); | 386 action_buttons_.push_back(button); |
378 layout->StartRow(0, 0); | 387 layout->StartRow(0, 0); |
379 layout->AddView(button, 2, 1, | 388 layout->AddView(button, 2, 1, |
380 views::GridLayout::FILL, views::GridLayout::FILL, 0, 40); | 389 views::GridLayout::FILL, views::GridLayout::FILL, 0, 40); |
381 } | 390 } |
382 | 391 |
383 return content_view_; | 392 return content_view_; |
384 } | 393 } |
385 | 394 |
386 } // namespace message_center | 395 } // namespace message_center |
OLD | NEW |