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 #include "ash/system/tray/tray_views.h" | 5 #include "ash/system/tray/tray_views.h" |
| 6 | 6 |
| 7 #include "ash/system/tray/tray_constants.h" | 7 #include "ash/system/tray/tray_constants.h" |
| 8 #include "third_party/skia/include/core/SkBitmap.h" | 8 #include "third_party/skia/include/core/SkBitmap.h" |
| 9 #include "grit/ash_strings.h" | 9 #include "grit/ash_strings.h" |
| 10 #include "grit/ui_resources.h" | 10 #include "grit/ui_resources.h" |
| (...skipping 438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 449 label->SetEnabledColor(SK_ColorWHITE); | 449 label->SetEnabledColor(SK_ColorWHITE); |
| 450 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); | 450 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); |
| 451 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), | 451 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), |
| 452 SkColorSetARGB(64, 0, 0, 0)); | 452 SkColorSetARGB(64, 0, 0, 0)); |
| 453 label->SetShadowOffset(0, 1); | 453 label->SetShadowOffset(0, 1); |
| 454 } | 454 } |
| 455 | 455 |
| 456 //////////////////////////////////////////////////////////////////////////////// | 456 //////////////////////////////////////////////////////////////////////////////// |
| 457 // TrayNotificationView | 457 // TrayNotificationView |
| 458 | 458 |
| 459 TrayNotificationView::TrayNotificationView() { | 459 TrayNotificationView::TrayNotificationView(int icon_id) : icon_id_(icon_id) { |
| 460 } | |
| 461 | |
| 462 TrayNotificationView::~TrayNotificationView() { | |
| 460 } | 463 } |
| 461 | 464 |
| 462 void TrayNotificationView::InitView(views::View* contents) { | 465 void TrayNotificationView::InitView(views::View* contents) { |
| 463 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 466 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 464 | 467 |
| 465 views::GridLayout* layout = new views::GridLayout(this); | 468 views::GridLayout* layout = new views::GridLayout(this); |
| 466 SetLayoutManager(layout); | 469 SetLayoutManager(layout); |
| 467 | 470 |
| 468 views::ImageButton* close_button = new views::ImageButton(this); | 471 views::ImageButton* close_button = new views::ImageButton(this); |
| 469 close_button->SetImage(views::CustomButton::BS_NORMAL, | 472 close_button->SetImage(views::CustomButton::BS_NORMAL, |
| 470 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 473 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 471 IDR_AURA_WINDOW_CLOSE)); | 474 IDR_AURA_WINDOW_CLOSE)); |
| 472 | 475 |
| 473 int contents_width = kTrayPopupWidth - kNotificationCloseButtonWidth; | 476 icon_ = new views::ImageView; |
| 477 if (icon_id_ != 0) { | |
| 478 icon_->SetImage( | |
| 479 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); | |
| 480 } | |
| 481 | |
| 474 views::ColumnSet* columns = layout->AddColumnSet(0); | 482 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 475 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 483 |
| 476 0, /* resize percent */ | 484 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); |
| 477 views::GridLayout::FIXED, | 485 |
| 478 contents_width, | 486 // Icon |
| 479 contents_width); | |
| 480 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | 487 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 481 0, /* resize percent */ | 488 0, /* resize percent */ |
| 482 views::GridLayout::FIXED, | 489 views::GridLayout::FIXED, |
| 483 kNotificationCloseButtonWidth, | 490 kNotificationIconWidth, kNotificationIconWidth); |
| 484 kNotificationCloseButtonWidth); | |
| 485 | 491 |
| 492 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 493 | |
| 494 // Contents | |
| 495 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, | |
| 496 0, /* resize percent */ | |
| 497 views::GridLayout::FIXED, | |
| 498 kTrayNotificationContentsWidth, | |
| 499 kTrayNotificationContentsWidth); | |
| 500 | |
| 501 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 502 | |
| 503 // Close button | |
| 504 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | |
| 505 0, /* resize percent */ | |
| 506 views::GridLayout::FIXED, | |
| 507 kNotificationIconWidth, kNotificationIconWidth); | |
| 508 | |
| 509 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); | |
| 510 | |
| 511 // Layout rows | |
| 512 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 486 layout->StartRow(0, 0); | 513 layout->StartRow(0, 0); |
| 514 layout->AddView(icon_); | |
| 487 layout->AddView(contents); | 515 layout->AddView(contents); |
| 488 layout->AddView(close_button); | 516 layout->AddView(close_button); |
| 517 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); | |
| 489 } | 518 } |
| 490 | 519 |
| 491 TrayNotificationView::~TrayNotificationView() { | 520 void TrayNotificationView::SetIconImage(const SkBitmap& image) { |
| 521 icon_->SetImage(image); | |
| 522 SchedulePaint(); | |
| 523 } | |
| 524 | |
| 525 void TrayNotificationView::UpdateView(views::View* new_contents) { | |
| 526 RemoveAllChildViews(true); | |
|
sadrul
2012/05/24 04:12:50
The indentation here and in UpdateViewAndImage see
stevenjb
2012/05/24 16:48:01
Done.
| |
| 527 InitView(new_contents); | |
| 528 Layout(); | |
| 529 PreferredSizeChanged(); | |
| 530 SchedulePaint(); | |
| 531 } | |
| 532 | |
| 533 void TrayNotificationView::UpdateViewAndImage(views::View* new_contents, | |
| 534 const SkBitmap& image) { | |
| 535 RemoveAllChildViews(true); | |
| 536 InitView(new_contents); | |
| 537 icon_->SetImage(image); | |
| 538 Layout(); | |
| 539 PreferredSizeChanged(); | |
| 540 SchedulePaint(); | |
| 492 } | 541 } |
| 493 | 542 |
| 494 void TrayNotificationView::ButtonPressed(views::Button* sender, | 543 void TrayNotificationView::ButtonPressed(views::Button* sender, |
| 495 const views::Event& event) { | 544 const views::Event& event) { |
| 496 OnClose(); | 545 OnClose(); |
| 497 } | 546 } |
| 498 | 547 |
| 499 } // namespace internal | 548 } // namespace internal |
| 500 } // namespace ash | 549 } // namespace ash |
| OLD | NEW |