| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/views/toolbar_view.h" | 5 #include "chrome/browser/views/toolbar_view.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.h" |
| 9 #include "chrome/app/chrome_dll_resource.h" | 9 #include "chrome/app/chrome_dll_resource.h" |
| 10 #include "chrome/browser/accessibility/browser_accessibility_state.h" | 10 #include "chrome/browser/accessibility/browser_accessibility_state.h" |
| (...skipping 23 matching lines...) Expand all Loading... |
| 34 #include "views/window/window.h" | 34 #include "views/window/window.h" |
| 35 | 35 |
| 36 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
| 37 #include "chrome/browser/chromeos/cros/cros_library.h" | 37 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 38 #include "chrome/browser/chromeos/cros/update_library.h" | 38 #include "chrome/browser/chromeos/cros/update_library.h" |
| 39 #include "chrome/browser/chromeos/dom_ui/wrench_menu_ui.h" | 39 #include "chrome/browser/chromeos/dom_ui/wrench_menu_ui.h" |
| 40 #include "views/controls/menu/menu_2.h" | 40 #include "views/controls/menu/menu_2.h" |
| 41 #endif | 41 #endif |
| 42 #include "chrome/browser/views/wrench_menu.h" | 42 #include "chrome/browser/views/wrench_menu.h" |
| 43 | 43 |
| 44 #if defined(OS_WIN) |
| 45 #include "chrome/browser/enumerate_modules_model_win.h" |
| 46 #endif |
| 47 |
| 44 // The space between items is 4 px in general. | 48 // The space between items is 4 px in general. |
| 45 const int ToolbarView::kStandardSpacing = 4; | 49 const int ToolbarView::kStandardSpacing = 4; |
| 46 // The top of the toolbar has an edge we have to skip over in addition to the 4 | 50 // The top of the toolbar has an edge we have to skip over in addition to the 4 |
| 47 // px of spacing. | 51 // px of spacing. |
| 48 const int ToolbarView::kVertSpacing = kStandardSpacing + 1; | 52 const int ToolbarView::kVertSpacing = kStandardSpacing + 1; |
| 49 // The edge graphics have some built-in spacing/shadowing, so we have to adjust | 53 // The edge graphics have some built-in spacing/shadowing, so we have to adjust |
| 50 // our spacing to make it still appear to be 4 px. | 54 // our spacing to make it still appear to be 4 px. |
| 51 static const int kEdgeSpacing = ToolbarView::kStandardSpacing - 1; | 55 static const int kEdgeSpacing = ToolbarView::kStandardSpacing - 1; |
| 52 // The buttons to the left of the omnibox are close together. | 56 // The buttons to the left of the omnibox are close together. |
| 53 static const int kButtonSpacing = 1; | 57 static const int kButtonSpacing = 1; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 95 | 99 |
| 96 if (!kPopupBackgroundEdge) { | 100 if (!kPopupBackgroundEdge) { |
| 97 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( | 101 kPopupBackgroundEdge = ResourceBundle::GetSharedInstance().GetBitmapNamed( |
| 98 IDR_LOCATIONBG_POPUPMODE_EDGE); | 102 IDR_LOCATIONBG_POPUPMODE_EDGE); |
| 99 } | 103 } |
| 100 | 104 |
| 101 if (!IsUpgradeRecommended()) { | 105 if (!IsUpgradeRecommended()) { |
| 102 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, | 106 registrar_.Add(this, NotificationType::UPGRADE_RECOMMENDED, |
| 103 NotificationService::AllSources()); | 107 NotificationService::AllSources()); |
| 104 } | 108 } |
| 109 registrar_.Add(this, NotificationType::MODULE_INCOMPATIBILITY_DETECTED, |
| 110 NotificationService::AllSources()); |
| 105 } | 111 } |
| 106 | 112 |
| 107 ToolbarView::~ToolbarView() { | 113 ToolbarView::~ToolbarView() { |
| 108 if (destroyed_flag_) | 114 if (destroyed_flag_) |
| 109 *destroyed_flag_ = true; | 115 *destroyed_flag_ = true; |
| 110 | 116 |
| 111 // NOTE: Don't remove the command observers here. This object gets destroyed | 117 // NOTE: Don't remove the command observers here. This object gets destroyed |
| 112 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is | 118 // after the Browser (which owns the CommandUpdater), so the CommandUpdater is |
| 113 // already gone. | 119 // already gone. |
| 114 } | 120 } |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 | 174 |
| 169 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); | 175 app_menu_ = new views::MenuButton(NULL, std::wstring(), this, false); |
| 170 app_menu_->set_border(NULL); | 176 app_menu_->set_border(NULL); |
| 171 app_menu_->EnableCanvasFlippingForRTLUI(true); | 177 app_menu_->EnableCanvasFlippingForRTLUI(true); |
| 172 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); | 178 app_menu_->SetAccessibleName(l10n_util::GetString(IDS_ACCNAME_APP)); |
| 173 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, | 179 app_menu_->SetTooltipText(l10n_util::GetStringF(IDS_APPMENU_TOOLTIP, |
| 174 l10n_util::GetString(IDS_PRODUCT_NAME))); | 180 l10n_util::GetString(IDS_PRODUCT_NAME))); |
| 175 app_menu_->SetID(VIEW_ID_APP_MENU); | 181 app_menu_->SetID(VIEW_ID_APP_MENU); |
| 176 | 182 |
| 177 // Catch the case where the window is created after we detect a new version. | 183 // Catch the case where the window is created after we detect a new version. |
| 178 if (IsUpgradeRecommended()) | 184 if (IsUpgradeRecommended() || ShouldShowIncompatibilityWarning()) |
| 179 ShowUpgradeReminder(); | 185 ShowNotificationDot(); |
| 180 | 186 |
| 181 LoadImages(); | 187 LoadImages(); |
| 182 | 188 |
| 183 // Always add children in order from left to right, for accessibility. | 189 // Always add children in order from left to right, for accessibility. |
| 184 AddChildView(back_); | 190 AddChildView(back_); |
| 185 AddChildView(forward_); | 191 AddChildView(forward_); |
| 186 AddChildView(reload_); | 192 AddChildView(reload_); |
| 187 AddChildView(home_); | 193 AddChildView(home_); |
| 188 AddChildView(location_bar_); | 194 AddChildView(location_bar_); |
| 189 AddChildView(browser_actions_); | 195 AddChildView(browser_actions_); |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 310 | 316 |
| 311 wrench_menu_->RunMenu(app_menu_); | 317 wrench_menu_->RunMenu(app_menu_); |
| 312 | 318 |
| 313 #if defined(OS_CHROMEOS) | 319 #if defined(OS_CHROMEOS) |
| 314 cleanup: | 320 cleanup: |
| 315 #endif | 321 #endif |
| 316 if (destroyed_flag) | 322 if (destroyed_flag) |
| 317 return; | 323 return; |
| 318 destroyed_flag_ = NULL; | 324 destroyed_flag_ = NULL; |
| 319 | 325 |
| 320 // Stop pulsating the upgrade reminder on the app menu, if active. | 326 // Stop pulsating the notification dot on the app menu (if active). |
| 321 upgrade_reminder_pulse_timer_.Stop(); | 327 notification_dot_pulse_timer_.Stop(); |
| 322 } | 328 } |
| 323 | 329 |
| 324 //////////////////////////////////////////////////////////////////////////////// | 330 //////////////////////////////////////////////////////////////////////////////// |
| 325 // ToolbarView, LocationBarView::Delegate implementation: | 331 // ToolbarView, LocationBarView::Delegate implementation: |
| 326 | 332 |
| 327 TabContents* ToolbarView::GetTabContents() { | 333 TabContents* ToolbarView::GetTabContents() { |
| 328 return browser_->GetSelectedTabContents(); | 334 return browser_->GetSelectedTabContents(); |
| 329 } | 335 } |
| 330 | 336 |
| 331 InstantController* ToolbarView::GetInstant() { | 337 InstantController* ToolbarView::GetInstant() { |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 void ToolbarView::Observe(NotificationType type, | 400 void ToolbarView::Observe(NotificationType type, |
| 395 const NotificationSource& source, | 401 const NotificationSource& source, |
| 396 const NotificationDetails& details) { | 402 const NotificationDetails& details) { |
| 397 if (type == NotificationType::PREF_CHANGED) { | 403 if (type == NotificationType::PREF_CHANGED) { |
| 398 std::string* pref_name = Details<std::string>(details).ptr(); | 404 std::string* pref_name = Details<std::string>(details).ptr(); |
| 399 if (*pref_name == prefs::kShowHomeButton) { | 405 if (*pref_name == prefs::kShowHomeButton) { |
| 400 Layout(); | 406 Layout(); |
| 401 SchedulePaint(); | 407 SchedulePaint(); |
| 402 } | 408 } |
| 403 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { | 409 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { |
| 404 ShowUpgradeReminder(); | 410 ShowNotificationDot(); |
| 411 } else if (type == NotificationType::MODULE_INCOMPATIBILITY_DETECTED) { |
| 412 bool confirmed_bad = *Details<bool>(details).ptr(); |
| 413 if (confirmed_bad) |
| 414 ShowNotificationDot(); |
| 405 } | 415 } |
| 406 } | 416 } |
| 407 | 417 |
| 408 //////////////////////////////////////////////////////////////////////////////// | 418 //////////////////////////////////////////////////////////////////////////////// |
| 409 // ToolbarView, menus::AcceleratorProvider implementation: | 419 // ToolbarView, menus::AcceleratorProvider implementation: |
| 410 | 420 |
| 411 bool ToolbarView::GetAcceleratorForCommandId(int command_id, | 421 bool ToolbarView::GetAcceleratorForCommandId(int command_id, |
| 412 menus::Accelerator* accelerator) { | 422 menus::Accelerator* accelerator) { |
| 413 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators | 423 // The standard Ctrl-X, Ctrl-V and Ctrl-C are not defined as accelerators |
| 414 // anywhere so we need to check for them explicitly here. | 424 // anywhere so we need to check for them explicitly here. |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 573 | 583 |
| 574 bool ToolbarView::IsUpgradeRecommended() { | 584 bool ToolbarView::IsUpgradeRecommended() { |
| 575 #if defined(OS_CHROMEOS) | 585 #if defined(OS_CHROMEOS) |
| 576 return (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == | 586 return (chromeos::CrosLibrary::Get()->GetUpdateLibrary()->status().status == |
| 577 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT); | 587 chromeos::UPDATE_STATUS_UPDATED_NEED_REBOOT); |
| 578 #else | 588 #else |
| 579 return (Singleton<UpgradeDetector>::get()->notify_upgrade()); | 589 return (Singleton<UpgradeDetector>::get()->notify_upgrade()); |
| 580 #endif | 590 #endif |
| 581 } | 591 } |
| 582 | 592 |
| 593 bool ToolbarView::ShouldShowIncompatibilityWarning() { |
| 594 #if defined(OS_WIN) |
| 595 EnumerateModulesModel* loaded_modules = EnumerateModulesModel::GetSingleton(); |
| 596 return loaded_modules->confirmed_bad_modules_detected() > 0; |
| 597 #else |
| 598 return false; |
| 599 #endif |
| 600 } |
| 601 |
| 583 int ToolbarView::PopupTopSpacing() const { | 602 int ToolbarView::PopupTopSpacing() const { |
| 584 return GetWindow()->GetNonClientView()->UseNativeFrame() ? | 603 return GetWindow()->GetNonClientView()->UseNativeFrame() ? |
| 585 0 : kPopupTopSpacingNonGlass; | 604 0 : kPopupTopSpacingNonGlass; |
| 586 } | 605 } |
| 587 | 606 |
| 588 void ToolbarView::LoadImages() { | 607 void ToolbarView::LoadImages() { |
| 589 ThemeProvider* tp = GetThemeProvider(); | 608 ThemeProvider* tp = GetThemeProvider(); |
| 590 | 609 |
| 591 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); | 610 back_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_BACK)); |
| 592 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); | 611 back_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_BACK_H)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 622 home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); | 641 home_->SetImage(views::CustomButton::BS_NORMAL, tp->GetBitmapNamed(IDR_HOME)); |
| 623 home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); | 642 home_->SetImage(views::CustomButton::BS_HOT, tp->GetBitmapNamed(IDR_HOME_H)); |
| 624 home_->SetImage(views::CustomButton::BS_PUSHED, | 643 home_->SetImage(views::CustomButton::BS_PUSHED, |
| 625 tp->GetBitmapNamed(IDR_HOME_P)); | 644 tp->GetBitmapNamed(IDR_HOME_P)); |
| 626 | 645 |
| 627 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); | 646 app_menu_->SetIcon(GetAppMenuIcon(views::CustomButton::BS_NORMAL)); |
| 628 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); | 647 app_menu_->SetHoverIcon(GetAppMenuIcon(views::CustomButton::BS_HOT)); |
| 629 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); | 648 app_menu_->SetPushedIcon(GetAppMenuIcon(views::CustomButton::BS_PUSHED)); |
| 630 } | 649 } |
| 631 | 650 |
| 632 void ToolbarView::ShowUpgradeReminder() { | 651 void ToolbarView::ShowNotificationDot() { |
| 633 update_reminder_animation_.reset(new SlideAnimation(this)); | 652 notification_dot_animation_.reset(new SlideAnimation(this)); |
| 634 update_reminder_animation_->SetSlideDuration(kPulseDuration); | 653 notification_dot_animation_->SetSlideDuration(kPulseDuration); |
| 635 | 654 |
| 636 // Then start the recurring timer for pulsating it. | 655 // Then start the recurring timer for pulsating it. |
| 637 upgrade_reminder_pulse_timer_.Start( | 656 notification_dot_pulse_timer_.Stop(); |
| 657 notification_dot_pulse_timer_.Start( |
| 638 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), | 658 base::TimeDelta::FromMilliseconds(kPulsateEveryMs), |
| 639 this, &ToolbarView::PulsateUpgradeNotifier); | 659 this, &ToolbarView::PulsateNotificationDot); |
| 640 } | 660 } |
| 641 | 661 |
| 642 void ToolbarView::PulsateUpgradeNotifier() { | 662 void ToolbarView::PulsateNotificationDot() { |
| 643 // Start the pulsating animation. | 663 // Start the pulsating animation. |
| 644 update_reminder_animation_->Reset(0.0); | 664 notification_dot_animation_->Reset(0.0); |
| 645 update_reminder_animation_->Show(); | 665 notification_dot_animation_->Show(); |
| 646 } | 666 } |
| 647 | 667 |
| 648 SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { | 668 SkBitmap ToolbarView::GetAppMenuIcon(views::CustomButton::ButtonState state) { |
| 649 ThemeProvider* tp = GetThemeProvider(); | 669 ThemeProvider* tp = GetThemeProvider(); |
| 650 | 670 |
| 651 int id = 0; | 671 int id = 0; |
| 652 switch (state) { | 672 switch (state) { |
| 653 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break; | 673 case views::CustomButton::BS_NORMAL: id = IDR_TOOLS; break; |
| 654 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break; | 674 case views::CustomButton::BS_HOT: id = IDR_TOOLS_H; break; |
| 655 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break; | 675 case views::CustomButton::BS_PUSHED: id = IDR_TOOLS_P; break; |
| 656 default: NOTREACHED(); break; | 676 default: NOTREACHED(); break; |
| 657 } | 677 } |
| 658 SkBitmap icon = *tp->GetBitmapNamed(id); | 678 SkBitmap icon = *tp->GetBitmapNamed(id); |
| 659 | 679 |
| 660 if (!IsUpgradeRecommended()) | 680 bool add_badge = IsUpgradeRecommended() || ShouldShowIncompatibilityWarning(); |
| 681 if (!add_badge) |
| 661 return icon; | 682 return icon; |
| 662 | 683 |
| 663 // Draw the chrome app menu icon onto the canvas. | 684 // Draw the chrome app menu icon onto the canvas. |
| 664 scoped_ptr<gfx::CanvasSkia> canvas( | 685 scoped_ptr<gfx::CanvasSkia> canvas( |
| 665 new gfx::CanvasSkia(icon.width(), icon.height(), false)); | 686 new gfx::CanvasSkia(icon.width(), icon.height(), false)); |
| 666 canvas->DrawBitmapInt(icon, 0, 0); | 687 canvas->DrawBitmapInt(icon, 0, 0); |
| 667 | 688 |
| 668 SkBitmap badge; | 689 SkBitmap badge; |
| 669 static bool has_faded_in = false; | 690 static bool has_faded_in = false; |
| 670 if (!has_faded_in) { | 691 if (!has_faded_in) { |
| 671 SkBitmap* dot = tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); | 692 SkBitmap* dot = NULL; |
| 693 if (ShouldShowIncompatibilityWarning()) { |
| 694 #if defined(OS_WIN) |
| 695 dot = tp->GetBitmapNamed(IDR_INCOMPATIBILITY_DOT_INACTIVE); |
| 696 #else |
| 697 NOTREACHED(); |
| 698 #endif |
| 699 } else { |
| 700 dot = tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); |
| 701 } |
| 672 SkBitmap transparent; | 702 SkBitmap transparent; |
| 673 transparent.setConfig(dot->getConfig(), dot->width(), dot->height()); | 703 transparent.setConfig(dot->getConfig(), dot->width(), dot->height()); |
| 674 transparent.allocPixels(); | 704 transparent.allocPixels(); |
| 675 transparent.eraseARGB(0, 0, 0, 0); | 705 transparent.eraseARGB(0, 0, 0, 0); |
| 676 badge = SkBitmapOperations::CreateBlendedBitmap( | 706 badge = SkBitmapOperations::CreateBlendedBitmap( |
| 677 *dot, transparent, 1.0 - update_reminder_animation_->GetCurrentValue()); | 707 *dot, transparent, |
| 678 if (update_reminder_animation_->GetCurrentValue() == 1.0) | 708 1.0 - notification_dot_animation_->GetCurrentValue()); |
| 709 if (notification_dot_animation_->GetCurrentValue() == 1.0) |
| 679 has_faded_in = true; | 710 has_faded_in = true; |
| 680 } else { | 711 } else { |
| 681 // Convert animation values that start from 0.0 and incrementally go | 712 // Convert animation values that start from 0.0 and incrementally go |
| 682 // up to 1.0 into values that start in 0.0, go to 1.0 and then back | 713 // up to 1.0 into values that start in 0.0, go to 1.0 and then back |
| 683 // to 0.0 (to create a pulsing effect). | 714 // to 0.0 (to create a pulsing effect). |
| 684 double value = | 715 double value = |
| 685 1.0 - abs(2.0 * update_reminder_animation_->GetCurrentValue() - 1.0); | 716 1.0 - abs(2.0 * notification_dot_animation_->GetCurrentValue() - 1.0); |
| 686 | 717 |
| 687 // Add the badge to it. | 718 // Add the badge to it. |
| 688 badge = SkBitmapOperations::CreateBlendedBitmap( | 719 if (ShouldShowIncompatibilityWarning()) { |
| 689 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), | 720 #if defined(OS_WIN) |
| 690 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), | 721 badge = SkBitmapOperations::CreateBlendedBitmap( |
| 691 value); | 722 *tp->GetBitmapNamed(IDR_INCOMPATIBILITY_DOT_INACTIVE), |
| 723 *tp->GetBitmapNamed(IDR_INCOMPATIBILITY_DOT_ACTIVE), |
| 724 value); |
| 725 #else |
| 726 NOTREACHED(); |
| 727 #endif |
| 728 } else { |
| 729 badge = SkBitmapOperations::CreateBlendedBitmap( |
| 730 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), |
| 731 *tp->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), |
| 732 value); |
| 733 } |
| 692 } | 734 } |
| 693 | 735 |
| 694 static const int kBadgeLeftSpacing = 8; | 736 static const int kBadgeLeftSpacing = 8; |
| 695 static const int kBadgeTopSpacing = 18; | 737 static const int kBadgeTopSpacing = 18; |
| 696 canvas->DrawBitmapInt(badge, kBadgeLeftSpacing, kBadgeTopSpacing); | 738 canvas->DrawBitmapInt(badge, kBadgeLeftSpacing, kBadgeTopSpacing); |
| 697 | 739 |
| 698 return canvas->ExtractBitmap(); | 740 return canvas->ExtractBitmap(); |
| 699 } | 741 } |
| OLD | NEW |