| 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 <X11/XF86keysym.h> | 7 #include <X11/XF86keysym.h> |
| 8 #include <gdk/gdkkeysyms.h> | 8 #include <gdk/gdkkeysyms.h> |
| 9 #include <gtk/gtk.h> | 9 #include <gtk/gtk.h> |
| 10 | 10 |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 67 | 67 |
| 68 // Height of the toolbar in pixels when we only show the location bar. | 68 // Height of the toolbar in pixels when we only show the location bar. |
| 69 const int kToolbarHeightLocationBarOnly = kToolbarHeight - 2; | 69 const int kToolbarHeightLocationBarOnly = kToolbarHeight - 2; |
| 70 | 70 |
| 71 // Interior spacing between toolbar widgets. | 71 // Interior spacing between toolbar widgets. |
| 72 const int kToolbarWidgetSpacing = 1; | 72 const int kToolbarWidgetSpacing = 1; |
| 73 | 73 |
| 74 // Amount of rounding on top corners of toolbar. Only used in Gtk theme mode. | 74 // Amount of rounding on top corners of toolbar. Only used in Gtk theme mode. |
| 75 const int kToolbarCornerSize = 3; | 75 const int kToolbarCornerSize = 3; |
| 76 | 76 |
| 77 // The offset in pixels of the upgrade dot on the app menu. | |
| 78 const int kUpgradeDotOffset = 6; | |
| 79 | |
| 80 // The duration of the upgrade notification animation (actually the duration | |
| 81 // of a half-throb). | |
| 82 const int kThrobDuration = 1000; | |
| 83 | |
| 84 void SetWidgetHeightRequest(GtkWidget* widget, gpointer user_data) { | 77 void SetWidgetHeightRequest(GtkWidget* widget, gpointer user_data) { |
| 85 gtk_widget_set_size_request(widget, -1, GPOINTER_TO_INT(user_data)); | 78 gtk_widget_set_size_request(widget, -1, GPOINTER_TO_INT(user_data)); |
| 86 } | 79 } |
| 87 | 80 |
| 88 } // namespace | 81 } // namespace |
| 89 | 82 |
| 90 // BrowserToolbarGtk, public --------------------------------------------------- | 83 // BrowserToolbarGtk, public --------------------------------------------------- |
| 91 | 84 |
| 92 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) | 85 BrowserToolbarGtk::BrowserToolbarGtk(Browser* browser, BrowserWindowGtk* window) |
| 93 : toolbar_(NULL), | 86 : toolbar_(NULL), |
| 94 location_bar_(new LocationBarViewGtk(browser)), | 87 location_bar_(new LocationBarViewGtk(browser)), |
| 95 model_(browser->toolbar_model()), | 88 model_(browser->toolbar_model()), |
| 96 wrench_menu_model_(this, browser), | 89 wrench_menu_model_(this, browser), |
| 97 browser_(browser), | 90 browser_(browser), |
| 98 window_(window), | 91 window_(window), |
| 99 profile_(NULL), | 92 profile_(NULL) { |
| 100 upgrade_reminder_animation_(this), | |
| 101 upgrade_reminder_canceled_(false) { | |
| 102 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); | 93 browser_->command_updater()->AddCommandObserver(IDC_BACK, this); |
| 103 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); | 94 browser_->command_updater()->AddCommandObserver(IDC_FORWARD, this); |
| 104 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); | 95 browser_->command_updater()->AddCommandObserver(IDC_HOME, this); |
| 105 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); | 96 browser_->command_updater()->AddCommandObserver(IDC_BOOKMARK_PAGE, this); |
| 106 | 97 |
| 107 registrar_.Add(this, | 98 registrar_.Add(this, |
| 108 NotificationType::BROWSER_THEME_CHANGED, | 99 NotificationType::BROWSER_THEME_CHANGED, |
| 109 NotificationService::AllSources()); | 100 NotificationService::AllSources()); |
| 110 registrar_.Add(this, | 101 registrar_.Add(this, |
| 111 NotificationType::UPGRADE_RECOMMENDED, | 102 NotificationType::UPGRADE_RECOMMENDED, |
| 112 NotificationService::AllSources()); | 103 NotificationService::AllSources()); |
| 113 | |
| 114 upgrade_reminder_animation_.SetThrobDuration(kThrobDuration); | |
| 115 | |
| 116 ActiveWindowWatcherX::AddObserver(this); | |
| 117 } | 104 } |
| 118 | 105 |
| 119 BrowserToolbarGtk::~BrowserToolbarGtk() { | 106 BrowserToolbarGtk::~BrowserToolbarGtk() { |
| 120 ActiveWindowWatcherX::RemoveObserver(this); | |
| 121 | |
| 122 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); | 107 browser_->command_updater()->RemoveCommandObserver(IDC_BACK, this); |
| 123 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); | 108 browser_->command_updater()->RemoveCommandObserver(IDC_FORWARD, this); |
| 124 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); | 109 browser_->command_updater()->RemoveCommandObserver(IDC_HOME, this); |
| 125 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); | 110 browser_->command_updater()->RemoveCommandObserver(IDC_BOOKMARK_PAGE, this); |
| 126 | 111 |
| 127 offscreen_entry_.Destroy(); | 112 offscreen_entry_.Destroy(); |
| 128 | 113 |
| 129 wrench_menu_.reset(); | 114 wrench_menu_.reset(); |
| 130 } | 115 } |
| 131 | 116 |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 222 | 207 |
| 223 // Put the wrench button in a box so that we can paint the update notification | 208 // Put the wrench button in a box so that we can paint the update notification |
| 224 // over it. | 209 // over it. |
| 225 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); | 210 GtkWidget* wrench_box = gtk_alignment_new(0, 0, 1, 1); |
| 226 g_signal_connect_after(wrench_box, "expose-event", | 211 g_signal_connect_after(wrench_box, "expose-event", |
| 227 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); | 212 G_CALLBACK(OnWrenchMenuButtonExposeThunk), this); |
| 228 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); | 213 gtk_container_add(GTK_CONTAINER(wrench_box), wrench_button); |
| 229 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); | 214 gtk_box_pack_start(GTK_BOX(toolbar_), wrench_box, FALSE, FALSE, 4); |
| 230 | 215 |
| 231 wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_)); | 216 wrench_menu_.reset(new MenuGtk(this, &wrench_menu_model_)); |
| 232 g_signal_connect(wrench_menu_->widget(), "show", | |
| 233 G_CALLBACK(OnWrenchMenuShowThunk), this); | |
| 234 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, | 217 registrar_.Add(this, NotificationType::ZOOM_LEVEL_CHANGED, |
| 235 Source<Profile>(browser_->profile())); | 218 Source<Profile>(browser_->profile())); |
| 236 | 219 |
| 237 if (ShouldOnlyShowLocation()) { | 220 if (ShouldOnlyShowLocation()) { |
| 238 gtk_widget_show(event_box_); | 221 gtk_widget_show(event_box_); |
| 239 gtk_widget_show(alignment_); | 222 gtk_widget_show(alignment_); |
| 240 gtk_widget_show(toolbar_); | 223 gtk_widget_show(toolbar_); |
| 241 gtk_widget_show_all(location_hbox_); | 224 gtk_widget_show_all(location_hbox_); |
| 242 gtk_widget_hide(reload_->widget()); | 225 gtk_widget_hide(reload_->widget()); |
| 243 } else { | 226 } else { |
| 244 gtk_widget_show_all(event_box_); | 227 gtk_widget_show_all(event_box_); |
| 245 if (actions_toolbar_->button_count() == 0) | 228 if (actions_toolbar_->button_count() == 0) |
| 246 gtk_widget_hide(actions_toolbar_->widget()); | 229 gtk_widget_hide(actions_toolbar_->widget()); |
| 247 } | 230 } |
| 248 // Initialize pref-dependent UI state. | 231 // Initialize pref-dependent UI state. |
| 249 NotifyPrefChanged(NULL); | 232 NotifyPrefChanged(NULL); |
| 250 | 233 |
| 251 // Because the above does a recursive show all on all widgets we need to | 234 // Because the above does a recursive show all on all widgets we need to |
| 252 // update the icon visibility to hide them. | 235 // update the icon visibility to hide them. |
| 253 location_bar_->UpdateContentSettingsIcons(); | 236 location_bar_->UpdateContentSettingsIcons(); |
| 254 | 237 |
| 255 SetViewIDs(); | 238 SetViewIDs(); |
| 256 theme_provider_->InitThemesFor(this); | 239 theme_provider_->InitThemesFor(this); |
| 257 | |
| 258 MaybeShowUpgradeReminder(); | |
| 259 } | 240 } |
| 260 | 241 |
| 261 void BrowserToolbarGtk::SetViewIDs() { | 242 void BrowserToolbarGtk::SetViewIDs() { |
| 262 ViewIDUtil::SetID(widget(), VIEW_ID_TOOLBAR); | 243 ViewIDUtil::SetID(widget(), VIEW_ID_TOOLBAR); |
| 263 ViewIDUtil::SetID(back_->widget(), VIEW_ID_BACK_BUTTON); | 244 ViewIDUtil::SetID(back_->widget(), VIEW_ID_BACK_BUTTON); |
| 264 ViewIDUtil::SetID(forward_->widget(), VIEW_ID_FORWARD_BUTTON); | 245 ViewIDUtil::SetID(forward_->widget(), VIEW_ID_FORWARD_BUTTON); |
| 265 ViewIDUtil::SetID(reload_->widget(), VIEW_ID_RELOAD_BUTTON); | 246 ViewIDUtil::SetID(reload_->widget(), VIEW_ID_RELOAD_BUTTON); |
| 266 ViewIDUtil::SetID(home_->widget(), VIEW_ID_HOME_BUTTON); | 247 ViewIDUtil::SetID(home_->widget(), VIEW_ID_HOME_BUTTON); |
| 267 ViewIDUtil::SetID(location_bar_->widget(), VIEW_ID_LOCATION_BAR); | 248 ViewIDUtil::SetID(location_bar_->widget(), VIEW_ID_LOCATION_BAR); |
| 268 ViewIDUtil::SetID(wrench_menu_button_->widget(), VIEW_ID_APP_MENU); | 249 ViewIDUtil::SetID(wrench_menu_button_->widget(), VIEW_ID_APP_MENU); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 if (use_gtk) { | 369 if (use_gtk) { |
| 389 // We need to manually update the icon if we are in GTK mode. (Note that | 370 // We need to manually update the icon if we are in GTK mode. (Note that |
| 390 // we set the initial value in Init()). | 371 // we set the initial value in Init()). |
| 391 gtk_image_set_from_pixbuf( | 372 gtk_image_set_from_pixbuf( |
| 392 GTK_IMAGE(wrench_menu_image_), | 373 GTK_IMAGE(wrench_menu_image_), |
| 393 theme_provider_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); | 374 theme_provider_->GetRTLEnabledPixbufNamed(IDR_TOOLS)); |
| 394 } | 375 } |
| 395 | 376 |
| 396 UpdateRoundedness(); | 377 UpdateRoundedness(); |
| 397 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { | 378 } else if (type == NotificationType::UPGRADE_RECOMMENDED) { |
| 398 MaybeShowUpgradeReminder(); | 379 gtk_widget_queue_draw(wrench_menu_button_->widget()); |
| 399 } else if (type == NotificationType::ZOOM_LEVEL_CHANGED) { | 380 } else if (type == NotificationType::ZOOM_LEVEL_CHANGED) { |
| 400 // If our zoom level changed, we need to tell the menu to update its state, | 381 // If our zoom level changed, we need to tell the menu to update its state, |
| 401 // since the menu could still be open. | 382 // since the menu could still be open. |
| 402 wrench_menu_->UpdateMenu(); | 383 wrench_menu_->UpdateMenu(); |
| 403 } else { | 384 } else { |
| 404 NOTREACHED(); | 385 NOTREACHED(); |
| 405 } | 386 } |
| 406 } | 387 } |
| 407 | 388 |
| 408 // BrowserToolbarGtk, public --------------------------------------------------- | 389 // BrowserToolbarGtk, public --------------------------------------------------- |
| (...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 } | 612 } |
| 632 } | 613 } |
| 633 | 614 |
| 634 if (!pref || | 615 if (!pref || |
| 635 *pref == prefs::kHomePage || | 616 *pref == prefs::kHomePage || |
| 636 *pref == prefs::kHomePageIsNewTabPage) | 617 *pref == prefs::kHomePageIsNewTabPage) |
| 637 SetUpDragForHomeButton(!home_page_.IsManaged() && | 618 SetUpDragForHomeButton(!home_page_.IsManaged() && |
| 638 !home_page_is_new_tab_page_.IsManaged()); | 619 !home_page_is_new_tab_page_.IsManaged()); |
| 639 } | 620 } |
| 640 | 621 |
| 641 void BrowserToolbarGtk::MaybeShowUpgradeReminder() { | |
| 642 // Only show the upgrade reminder animation for the currently active window. | |
| 643 if (window_->IsActive() && | |
| 644 Singleton<UpgradeDetector>::get()->notify_upgrade() && | |
| 645 !upgrade_reminder_canceled_) { | |
| 646 upgrade_reminder_animation_.StartThrobbing(-1); | |
| 647 } else { | |
| 648 upgrade_reminder_animation_.Reset(); | |
| 649 } | |
| 650 } | |
| 651 | |
| 652 bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { | 622 bool BrowserToolbarGtk::ShouldOnlyShowLocation() const { |
| 653 // If we're a popup window, only show the location bar (omnibox). | 623 // If we're a popup window, only show the location bar (omnibox). |
| 654 return browser_->type() != Browser::TYPE_NORMAL; | 624 return browser_->type() != Browser::TYPE_NORMAL; |
| 655 } | 625 } |
| 656 | 626 |
| 657 void BrowserToolbarGtk::AnimationEnded(const Animation* animation) { | |
| 658 DCHECK_EQ(animation, &upgrade_reminder_animation_); | |
| 659 gtk_widget_queue_draw(wrench_menu_button_->widget()->parent); | |
| 660 } | |
| 661 | |
| 662 void BrowserToolbarGtk::AnimationProgressed(const Animation* animation) { | |
| 663 DCHECK_EQ(animation, &upgrade_reminder_animation_); | |
| 664 if (UpgradeAnimationIsFaded()) | |
| 665 gtk_widget_queue_draw(wrench_menu_button_->widget()->parent); | |
| 666 } | |
| 667 | |
| 668 void BrowserToolbarGtk::AnimationCanceled(const Animation* animation) { | |
| 669 AnimationEnded(animation); | |
| 670 } | |
| 671 | |
| 672 void BrowserToolbarGtk::ActiveWindowChanged(GdkWindow* active_window) { | |
| 673 MaybeShowUpgradeReminder(); | |
| 674 } | |
| 675 | |
| 676 void BrowserToolbarGtk::OnWrenchMenuShow(GtkWidget* sender) { | |
| 677 if (upgrade_reminder_animation_.is_animating()) { | |
| 678 upgrade_reminder_canceled_ = true; | |
| 679 MaybeShowUpgradeReminder(); | |
| 680 } | |
| 681 } | |
| 682 | |
| 683 gboolean BrowserToolbarGtk::OnWrenchMenuButtonExpose(GtkWidget* sender, | 627 gboolean BrowserToolbarGtk::OnWrenchMenuButtonExpose(GtkWidget* sender, |
| 684 GdkEventExpose* expose) { | 628 GdkEventExpose* expose) { |
| 685 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) | 629 if (!Singleton<UpgradeDetector>::get()->notify_upgrade()) |
| 686 return FALSE; | 630 return FALSE; |
| 687 | 631 |
| 688 SkBitmap badge; | 632 const SkBitmap& badge = |
| 689 if (UpgradeAnimationIsFaded()) { | 633 *theme_provider_->GetBitmapNamed(IDR_UPDATE_BADGE); |
| 690 badge = SkBitmapOperations::CreateBlendedBitmap( | |
| 691 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_ACTIVE), | |
| 692 *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE), | |
| 693 upgrade_reminder_animation_.GetCurrentValue()); | |
| 694 } else { | |
| 695 badge = *theme_provider_->GetBitmapNamed(IDR_UPGRADE_DOT_INACTIVE); | |
| 696 } | |
| 697 | 634 |
| 698 // Draw the chrome app menu icon onto the canvas. | 635 // Draw the chrome app menu icon onto the canvas. |
| 699 gfx::CanvasSkiaPaint canvas(expose, false); | 636 gfx::CanvasSkiaPaint canvas(expose, false); |
| 700 int x_offset = base::i18n::IsRTL() ? | 637 int x_offset = base::i18n::IsRTL() ? 0 : |
| 701 sender->allocation.width - kUpgradeDotOffset - badge.width() : | 638 sender->allocation.width - badge.width(); |
| 702 kUpgradeDotOffset; | 639 int y_offset = 0; |
| 703 int y_offset = sender->allocation.height / 2 + badge.height(); | |
| 704 canvas.DrawBitmapInt( | 640 canvas.DrawBitmapInt( |
| 705 badge, | 641 badge, |
| 706 sender->allocation.x + x_offset, | 642 sender->allocation.x + x_offset, |
| 707 sender->allocation.y + y_offset); | 643 sender->allocation.y + y_offset); |
| 708 | 644 |
| 709 return FALSE; | 645 return FALSE; |
| 710 } | 646 } |
| 711 | |
| 712 bool BrowserToolbarGtk::UpgradeAnimationIsFaded() { | |
| 713 return upgrade_reminder_animation_.cycles_remaining() > 0 && | |
| 714 // This funky looking math makes the badge throb for 2 seconds once | |
| 715 // every 8 seconds. | |
| 716 ((upgrade_reminder_animation_.cycles_remaining() - 1) / 2) % 4 == 0; | |
| 717 } | |
| OLD | NEW |