| 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 437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 448 button_container_->SetBoundsRect(bounds); | 448 button_container_->SetBoundsRect(bounds); |
| 449 | 449 |
| 450 bounds = content_->bounds(); | 450 bounds = content_->bounds(); |
| 451 bounds.set_width(button_container_->x()); | 451 bounds.set_width(button_container_->x()); |
| 452 content_->SetBoundsRect(bounds); | 452 content_->SetBoundsRect(bounds); |
| 453 } | 453 } |
| 454 | 454 |
| 455 //////////////////////////////////////////////////////////////////////////////// | 455 //////////////////////////////////////////////////////////////////////////////// |
| 456 // TrayNotificationView | 456 // TrayNotificationView |
| 457 | 457 |
| 458 TrayNotificationView::TrayNotificationView() { | 458 TrayNotificationView::TrayNotificationView(int icon_id) : icon_id_(icon_id) { |
| 459 } |
| 460 |
| 461 TrayNotificationView::~TrayNotificationView() { |
| 459 } | 462 } |
| 460 | 463 |
| 461 void TrayNotificationView::InitView(views::View* contents) { | 464 void TrayNotificationView::InitView(views::View* contents) { |
| 462 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); | 465 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 463 | 466 |
| 464 views::GridLayout* layout = new views::GridLayout(this); | 467 views::GridLayout* layout = new views::GridLayout(this); |
| 465 SetLayoutManager(layout); | 468 SetLayoutManager(layout); |
| 466 | 469 |
| 467 views::ImageButton* close_button = new views::ImageButton(this); | 470 views::ImageButton* close_button = new views::ImageButton(this); |
| 468 close_button->SetImage(views::CustomButton::BS_NORMAL, | 471 close_button->SetImage(views::CustomButton::BS_NORMAL, |
| 469 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 472 ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 470 IDR_AURA_WINDOW_CLOSE)); | 473 IDR_AURA_WINDOW_CLOSE)); |
| 471 | 474 |
| 472 int contents_width = kTrayPopupWidth - kNotificationCloseButtonWidth; | 475 icon_ = new views::ImageView; |
| 476 if (icon_id_ != 0) { |
| 477 icon_->SetImage( |
| 478 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(icon_id_)); |
| 479 } |
| 480 |
| 473 views::ColumnSet* columns = layout->AddColumnSet(0); | 481 views::ColumnSet* columns = layout->AddColumnSet(0); |
| 474 columns->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, | 482 |
| 475 0, /* resize percent */ | 483 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); |
| 476 views::GridLayout::FIXED, | 484 |
| 477 contents_width, | 485 // Icon |
| 478 contents_width); | |
| 479 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, | 486 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 480 0, /* resize percent */ | 487 0, /* resize percent */ |
| 481 views::GridLayout::FIXED, | 488 views::GridLayout::FIXED, |
| 482 kNotificationCloseButtonWidth, | 489 kNotificationIconWidth, kNotificationIconWidth); |
| 483 kNotificationCloseButtonWidth); | |
| 484 | 490 |
| 491 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); |
| 492 |
| 493 // Contents |
| 494 columns->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, |
| 495 0, /* resize percent */ |
| 496 views::GridLayout::FIXED, |
| 497 kTrayNotificationContentsWidth, |
| 498 kTrayNotificationContentsWidth); |
| 499 |
| 500 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); |
| 501 |
| 502 // Close button |
| 503 columns->AddColumn(views::GridLayout::CENTER, views::GridLayout::CENTER, |
| 504 0, /* resize percent */ |
| 505 views::GridLayout::FIXED, |
| 506 kNotificationIconWidth, kNotificationIconWidth); |
| 507 |
| 508 columns->AddPaddingColumn(0, kTrayPopupPaddingHorizontal/2); |
| 509 |
| 510 // Layout rows |
| 511 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| 485 layout->StartRow(0, 0); | 512 layout->StartRow(0, 0); |
| 513 layout->AddView(icon_); |
| 486 layout->AddView(contents); | 514 layout->AddView(contents); |
| 487 layout->AddView(close_button); | 515 layout->AddView(close_button); |
| 516 layout->AddPaddingRow(0, kTrayPopupPaddingBetweenItems); |
| 488 } | 517 } |
| 489 | 518 |
| 490 TrayNotificationView::~TrayNotificationView() { | 519 void TrayNotificationView::SetIconImage(const SkBitmap& image) { |
| 520 icon_->SetImage(image); |
| 521 SchedulePaint(); |
| 522 } |
| 523 |
| 524 void TrayNotificationView::UpdateView(views::View* new_contents) { |
| 525 RemoveAllChildViews(true); |
| 526 InitView(new_contents); |
| 527 Layout(); |
| 528 PreferredSizeChanged(); |
| 529 SchedulePaint(); |
| 530 } |
| 531 |
| 532 void TrayNotificationView::UpdateViewAndImage(views::View* new_contents, |
| 533 const SkBitmap& image) { |
| 534 RemoveAllChildViews(true); |
| 535 InitView(new_contents); |
| 536 icon_->SetImage(image); |
| 537 Layout(); |
| 538 PreferredSizeChanged(); |
| 539 SchedulePaint(); |
| 491 } | 540 } |
| 492 | 541 |
| 493 void TrayNotificationView::ButtonPressed(views::Button* sender, | 542 void TrayNotificationView::ButtonPressed(views::Button* sender, |
| 494 const views::Event& event) { | 543 const views::Event& event) { |
| 495 OnClose(); | 544 OnClose(); |
| 496 } | 545 } |
| 497 | 546 |
| 498 void SetupLabelForTray(views::Label* label) { | 547 void SetupLabelForTray(views::Label* label) { |
| 499 label->SetFont( | 548 label->SetFont( |
| 500 label->font().DeriveFont(2, gfx::Font::BOLD)); | 549 label->font().DeriveFont(2, gfx::Font::BOLD)); |
| 501 label->SetAutoColorReadabilityEnabled(false); | 550 label->SetAutoColorReadabilityEnabled(false); |
| 502 label->SetEnabledColor(SK_ColorWHITE); | 551 label->SetEnabledColor(SK_ColorWHITE); |
| 503 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); | 552 label->SetBackgroundColor(SkColorSetARGB(0, 255, 255, 255)); |
| 504 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), | 553 label->SetShadowColors(SkColorSetARGB(64, 0, 0, 0), |
| 505 SkColorSetARGB(64, 0, 0, 0)); | 554 SkColorSetARGB(64, 0, 0, 0)); |
| 506 label->SetShadowOffset(0, 1); | 555 label->SetShadowOffset(0, 1); |
| 507 } | 556 } |
| 508 | 557 |
| 509 } // namespace internal | 558 } // namespace internal |
| 510 } // namespace ash | 559 } // namespace ash |
| OLD | NEW |