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/gtk/browser_toolbar_gtk.h" | 5 #include "chrome/browser/gtk/browser_toolbar_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #include <X11/XF86keysym.h> | 9 #include <X11/XF86keysym.h> |
10 | 10 |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 location_bar_(new LocationBarViewGtk(browser)), | 88 location_bar_(new LocationBarViewGtk(browser)), |
89 model_(browser->toolbar_model()), | 89 model_(browser->toolbar_model()), |
90 page_menu_model_(this, browser), | 90 page_menu_model_(this, browser), |
91 app_menu_model_(this, browser), | 91 app_menu_model_(this, browser), |
92 wrench_menu_model_(this, browser), | 92 wrench_menu_model_(this, browser), |
93 browser_(browser), | 93 browser_(browser), |
94 window_(window), | 94 window_(window), |
95 profile_(NULL), | 95 profile_(NULL), |
96 menu_bar_helper_(this), | 96 menu_bar_helper_(this), |
97 upgrade_reminder_animation_(this), | 97 upgrade_reminder_animation_(this), |
| 98 upgrade_reminder_canceled_(false), |
98 collapsed_(false) { | 99 collapsed_(false) { |
99 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 100 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
100 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 101 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
101 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 102 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
102 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); | 103 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); |
103 | 104 |
104 registrar_.Add(this, | 105 registrar_.Add(this, |
105 NotificationType::BROWSER_THEME_CHANGED, | 106 NotificationType::BROWSER_THEME_CHANGED, |
106 NotificationService::AllSources()); | 107 NotificationService::AllSources()); |
107 registrar_.Add(this, | 108 registrar_.Add(this, |
108 NotificationType::UPGRADE_RECOMMENDED, | 109 NotificationType::UPGRADE_RECOMMENDED, |
109 NotificationService::AllSources()); | 110 NotificationService::AllSources()); |
110 | 111 |
111 upgrade_reminder_animation_.SetThrobDuration(kThrobDuration); | 112 upgrade_reminder_animation_.SetThrobDuration(kThrobDuration); |
112 | 113 |
113 if (Singleton<UpgradeDetector>::get()->notify_upgrade()) | 114 ActiveWindowWatcherX::AddObserver(this); |
114 ShowUpgradeReminder(); | 115 MaybeShowUpgradeReminder(); |
115 } | 116 } |
116 | 117 |
117 BrowserToolbarGtk::~BrowserToolbarGtk() { | 118 BrowserToolbarGtk::~BrowserToolbarGtk() { |
| 119 ActiveWindowWatcherX::RemoveObserver(this); |
| 120 |
118 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); | 121 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); |
119 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); | 122 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); |
120 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); | 123 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); |
121 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); | 124 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); |
122 | 125 |
123 offscreen_entry_.Destroy(); | 126 offscreen_entry_.Destroy(); |
124 | 127 |
125 page_menu_.reset(); | 128 page_menu_.reset(); |
126 app_menu_.reset(); | 129 app_menu_.reset(); |
127 page_menu_button_.Destroy(); | 130 page_menu_button_.Destroy(); |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
441 gtk_widget_set_size_request(location_hbox_, -1, | 444 gtk_widget_set_size_request(location_hbox_, -1, |
442 use_gtk ? -1 : toolbar_height); | 445 use_gtk ? -1 : toolbar_height); |
443 | 446 |
444 // When using the GTK+ theme, we need to have the event box be visible so | 447 // When using the GTK+ theme, we need to have the event box be visible so |
445 // buttons don't get a halo color from the background. When using Chromium | 448 // buttons don't get a halo color from the background. When using Chromium |
446 // themes, we want to let the background show through the toolbar. | 449 // themes, we want to let the background show through the toolbar. |
447 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_), use_gtk); | 450 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_), use_gtk); |
448 | 451 |
449 UpdateRoundedness(); | 452 UpdateRoundedness(); |
450 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { | 453 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { |
451 ShowUpgradeReminder(); | 454 MaybeShowUpgradeReminder(); |
452 } else { | 455 } else { |
453 NOTREACHED(); | 456 NOTREACHED(); |
454 } | 457 } |
455 } | 458 } |
456 | 459 |
457 // BrowserToolbarGtk, public --------------------------------------------------- | 460 // BrowserToolbarGtk, public --------------------------------------------------- |
458 | 461 |
459 void BrowserToolbarGtk::SetProfile(Profile* profile) { | 462 void BrowserToolbarGtk::SetProfile(Profile* profile) { |
460 if (profile == profile_) | 463 if (profile == profile_) |
461 return; | 464 return; |
(...skipping 276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
738 } | 741 } |
739 } | 742 } |
740 | 743 |
741 if (!pref || | 744 if (!pref || |
742 *pref == prefs::kHomePage || | 745 *pref == prefs::kHomePage || |
743 *pref == prefs::kHomePageIsNewTabPage) | 746 *pref == prefs::kHomePageIsNewTabPage) |
744 SetUpDragForHomeButton(!home_page_.IsManaged() && | 747 SetUpDragForHomeButton(!home_page_.IsManaged() && |
745 !home_page_is_new_tab_page_.IsManaged()); | 748 !home_page_is_new_tab_page_.IsManaged()); |
746 } | 749 } |
747 | 750 |
748 void BrowserToolbarGtk::ShowUpgradeReminder() { | 751 void BrowserToolbarGtk::MaybeShowUpgradeReminder() { |
749 upgrade_reminder_animation_.StartThrobbing(-1); | 752 // Only show the upgrade reminder animation for the currently active window. |
| 753 if (window_->IsActive() && |
| 754 Singleton<UpgradeDetector>::get()->notify_upgrade() && |
| 755 !upgrade_reminder_canceled_) { |
| 756 upgrade_reminder_animation_.StartThrobbing(-1); |
| 757 } else { |
| 758 upgrade_reminder_animation_.Reset(); |
| 759 } |
750 } | 760 } |
751 | 761 |
752 bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { | 762 bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { |
753 // If we're a popup window, only show the location bar (omnibox). | 763 // If we're a popup window, only show the location bar (omnibox). |
754 return browser_->type() != Browser::TYPE_NORMAL; | 764 return browser_->type() != Browser::TYPE_NORMAL; |
755 } | 765 } |
756 | 766 |
757 void BrowserToolbarGtk::PopupForButton(GtkWidget* button) { | 767 void BrowserToolbarGtk::PopupForButton(GtkWidget* button) { |
758 if (page_menu_.get()) | 768 if (page_menu_.get()) |
759 page_menu_->Cancel(); | 769 page_menu_->Cancel(); |
(...skipping 12 matching lines...) Expand all Loading... |
772 GtkMenuDirectionType dir) { | 782 GtkMenuDirectionType dir) { |
773 GtkWidget* other_button = button == page_menu_button_.get() ? | 783 GtkWidget* other_button = button == page_menu_button_.get() ? |
774 app_menu_button_.get() : page_menu_button_.get(); | 784 app_menu_button_.get() : page_menu_button_.get(); |
775 // TODO(erg): When we move to wrench menu only, remove |menu_bar_helper_| so | 785 // TODO(erg): When we move to wrench menu only, remove |menu_bar_helper_| so |
776 // this won't be necessary. | 786 // this won't be necessary. |
777 if (other_button) | 787 if (other_button) |
778 PopupForButton(other_button); | 788 PopupForButton(other_button); |
779 } | 789 } |
780 | 790 |
781 void BrowserToolbarGtk::AnimationEnded(const Animation* animation) { | 791 void BrowserToolbarGtk::AnimationEnded(const Animation* animation) { |
782 AnimationProgressed(animation); | 792 DCHECK_EQ(animation, &upgrade_reminder_animation_); |
| 793 gtk_widget_queue_draw(app_menu_image_.get()); |
783 } | 794 } |
784 | 795 |
785 void BrowserToolbarGtk::AnimationProgressed(const Animation* animation) { | 796 void BrowserToolbarGtk::AnimationProgressed(const Animation* animation) { |
786 DCHECK_EQ(animation, &upgrade_reminder_animation_); | 797 DCHECK_EQ(animation, &upgrade_reminder_animation_); |
787 gtk_widget_queue_draw(app_menu_image_.get()); | 798 |
| 799 if (UpgradeAnimationIsFaded()) |
| 800 gtk_widget_queue_draw(app_menu_image_.get()); |
788 } | 801 } |
789 | 802 |
790 void BrowserToolbarGtk::AnimationCanceled(const Animation* animation) { | 803 void BrowserToolbarGtk::AnimationCanceled(const Animation* animation) { |
791 AnimationProgressed(animation); | 804 AnimationEnded(animation); |
| 805 } |
| 806 |
| 807 void BrowserToolbarGtk::ActiveWindowChanged(GdkWindow* active_window) { |
| 808 MaybeShowUpgradeReminder(); |
792 } | 809 } |
793 | 810 |
794 void BrowserToolbarGtk::OnAppMenuShow(GtkWidget* sender) { | 811 void BrowserToolbarGtk::OnAppMenuShow(GtkWidget* sender) { |
795 upgrade_reminder_animation_.Reset(); | 812 if (upgrade_reminder_animation_.is_animating()) { |
| 813 upgrade_reminder_canceled_ = true; |
| 814 MaybeShowUpgradeReminder(); |
| 815 } |
796 } | 816 } |
797 | 817 |
798 gboolean BrowserToolbarGtk::OnAppMenuImageExpose(GtkWidget* sender, | 818 gboolean BrowserToolbarGtk::OnAppMenuImageExpose(GtkWidget* sender, |
799 GdkEventExpose* expose) { | 819 GdkEventExpose* expose) { |
800 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) | 820 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) |
801 return FALSE; | 821 return FALSE; |
802 | 822 |
803 SkBitmap badge; | 823 SkBitmap badge; |
804 if (upgrade_reminder_animation_.cycles_remaining() > 0 && | 824 if (UpgradeAnimationIsFaded()) { |
805 // This funky looking math makes the badge throb for 2 seconds once | |
806 // every 8 seconds. | |
807 ((upgrade_reminder_animation_.cycles_remaining() - 1) / 2) % 4 == 0) { | |
808 badge = SkBitmapOperations::CreateBlendedBitmap( | 825 badge = SkBitmapOperations::CreateBlendedBitmap( |
809 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), | 826 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), |
810 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), | 827 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), |
811 upgrade_reminder_animation_.GetCurrentValue()); | 828 upgrade_reminder_animation_.GetCurrentValue()); |
812 } else { | 829 } else { |
813 badge = *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); | 830 badge = *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); |
814 } | 831 } |
815 | 832 |
816 // Draw the chrome app menu icon onto the canvas. | 833 // Draw the chrome app menu icon onto the canvas. |
817 gfx::CanvasSkiaPaint canvas(expose, false); | 834 gfx::CanvasSkiaPaint canvas(expose, false); |
818 int x_offset = base::i18n::IsRTL() ? | 835 int x_offset = base::i18n::IsRTL() ? |
819 sender->allocation.width - kUpgradeDotOffset - badge.width() : | 836 sender->allocation.width - kUpgradeDotOffset - badge.width() : |
820 kUpgradeDotOffset; | 837 kUpgradeDotOffset; |
821 canvas.DrawBitmapInt( | 838 canvas.DrawBitmapInt( |
822 badge, | 839 badge, |
823 sender->allocation.x + x_offset, | 840 sender->allocation.x + x_offset, |
824 sender->allocation.y + sender->allocation.height - badge.height()); | 841 sender->allocation.y + sender->allocation.height - badge.height()); |
825 | 842 |
826 return FALSE; | 843 return FALSE; |
827 } | 844 } |
| 845 |
| 846 bool BrowserToolbarGtk::UpgradeAnimationIsFaded() { |
| 847 return upgrade_reminder_animation_.cycles_remaining() > 0 && |
| 848 // This funky looking math makes the badge throb for 2 seconds once |
| 849 // every 8 seconds. |
| 850 ((upgrade_reminder_animation_.cycles_remaining() - 1) / 2) % 4 == 0; |
| 851 } |
OLD | NEW |