Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(469)

Side by Side Diff: chrome/browser/ui/gtk/location_bar_view_gtk.cc

Issue 10559054: Animate the script badges. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: really sending for review... Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/browser/ui/gtk/location_bar_view_gtk.h" 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 // If there are no visible content things, hide the top level box so it 718 // If there are no visible content things, hide the top level box so it
719 // doesn't mess with padding. 719 // doesn't mess with padding.
720 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); 720 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible);
721 } 721 }
722 722
723 void LocationBarViewGtk::UpdatePageActions() { 723 void LocationBarViewGtk::UpdatePageActions() {
724 std::vector<ExtensionAction*> new_page_actions; 724 std::vector<ExtensionAction*> new_page_actions;
725 725
726 TabContents* tab_contents = GetTabContents(); 726 TabContents* tab_contents = GetTabContents();
727 if (tab_contents) { 727 LocationBarController* location_bar_controller = tab_contents ?
728 LocationBarController* controller = 728 tab_contents->extension_tab_helper()->location_bar_controller() : NULL;
729 tab_contents->extension_tab_helper()->location_bar_controller(); 729
730 new_page_actions = controller->GetCurrentActions(); 730 if (location_bar_controller)
731 } 731 new_page_actions = location_bar_controller->GetCurrentActions();
732 732
733 // Initialize on the first call, or re-initialize if more extensions have been 733 // Initialize on the first call, or re-initialize if more extensions have been
734 // loaded or added after startup. 734 // loaded or added after startup.
735 if (new_page_actions != page_actions_) { 735 if (new_page_actions != page_actions_) {
736 page_actions_.swap(new_page_actions); 736 page_actions_.swap(new_page_actions);
737 page_action_views_.reset(); 737 page_action_views_.reset();
738 738
739 for (size_t i = 0; i < page_actions_.size(); ++i) { 739 for (size_t i = 0; i < page_actions_.size(); ++i) {
740 page_action_views_.push_back( 740 ExtensionAction* page_action = page_actions_[i];
741 new PageActionViewGtk(this, page_actions_[i])); 741 page_action_views_.push_back(new PageActionViewGtk(
742 this,
743 page_action,
744 location_bar_controller->GetIconAnimation(page_action)));
742 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()), 745 gtk_box_pack_end(GTK_BOX(page_action_hbox_.get()),
743 page_action_views_[i]->widget(), FALSE, FALSE, 0); 746 page_action_views_[i]->widget(), FALSE, FALSE, 0);
744 } 747 }
745 content::NotificationService::current()->Notify( 748 content::NotificationService::current()->Notify(
746 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED, 749 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_COUNT_CHANGED,
747 content::Source<LocationBar>(this), 750 content::Source<LocationBar>(this),
748 content::NotificationService::NoDetails()); 751 content::NotificationService::NoDetails());
749 } 752 }
750 753
751 WebContents* contents = GetWebContents(); 754 WebContents* contents = GetWebContents();
(...skipping 853 matching lines...) Expand 10 before | Expand all | Expand 10 after
1605 BubbleGtk* bubble, 1608 BubbleGtk* bubble,
1606 bool closed_by_escape) { 1609 bool closed_by_escape) {
1607 content_setting_bubble_ = NULL; 1610 content_setting_bubble_ = NULL;
1608 } 1611 }
1609 1612
1610 //////////////////////////////////////////////////////////////////////////////// 1613 ////////////////////////////////////////////////////////////////////////////////
1611 // LocationBarViewGtk::PageActionViewGtk 1614 // LocationBarViewGtk::PageActionViewGtk
1612 1615
1613 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( 1616 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
1614 LocationBarViewGtk* owner, 1617 LocationBarViewGtk* owner,
1615 ExtensionAction* page_action) 1618 ExtensionAction* page_action,
1619 const base::WeakPtr<extensions::LocationBarController::IconAnimation>&
1620 icon_animation)
1616 : owner_(NULL), 1621 : owner_(NULL),
1617 page_action_(page_action), 1622 page_action_(page_action),
1618 last_icon_pixbuf_(NULL), 1623 last_icon_pixbuf_(NULL),
1619 tracker_(this), 1624 tracker_(this),
1620 current_tab_id_(-1), 1625 current_tab_id_(-1),
1621 window_(NULL), 1626 window_(NULL),
1622 accel_group_(NULL), 1627 accel_group_(NULL),
1623 preview_enabled_(false) { 1628 preview_enabled_(false),
1629 icon_animation_(icon_animation) {
1624 event_box_.Own(gtk_event_box_new()); 1630 event_box_.Own(gtk_event_box_new());
1625 gtk_widget_set_size_request(event_box_.get(), 1631 gtk_widget_set_size_request(event_box_.get(),
1626 Extension::kPageActionIconMaxSize, 1632 Extension::kPageActionIconMaxSize,
1627 Extension::kPageActionIconMaxSize); 1633 Extension::kPageActionIconMaxSize);
1628 1634
1629 // Make the event box not visible so it does not paint a background. 1635 // Make the event box not visible so it does not paint a background.
1630 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); 1636 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE);
1631 g_signal_connect(event_box_.get(), "button-press-event", 1637 g_signal_connect(event_box_.get(), "button-press-event",
1632 G_CALLBACK(&OnButtonPressedThunk), this); 1638 G_CALLBACK(&OnButtonPressedThunk), this);
1633 g_signal_connect_after(event_box_.get(), "expose-event", 1639 g_signal_connect_after(event_box_.get(), "expose-event",
(...skipping 16 matching lines...) Expand all
1650 icon_paths.push_back(page_action_->default_icon_path()); 1656 icon_paths.push_back(page_action_->default_icon_path());
1651 1657
1652 for (std::vector<std::string>::iterator iter = icon_paths.begin(); 1658 for (std::vector<std::string>::iterator iter = icon_paths.begin();
1653 iter != icon_paths.end(); ++iter) { 1659 iter != icon_paths.end(); ++iter) {
1654 tracker_.LoadImage(extension, extension->GetResource(*iter), 1660 tracker_.LoadImage(extension, extension->GetResource(*iter),
1655 gfx::Size(Extension::kPageActionIconMaxSize, 1661 gfx::Size(Extension::kPageActionIconMaxSize,
1656 Extension::kPageActionIconMaxSize), 1662 Extension::kPageActionIconMaxSize),
1657 ImageLoadingTracker::DONT_CACHE); 1663 ImageLoadingTracker::DONT_CACHE);
1658 } 1664 }
1659 1665
1666 if (icon_animation_.get())
1667 icon_animation_->AddObserver(this);
1668
1660 // We set the owner last of all so that we can determine whether we are in 1669 // We set the owner last of all so that we can determine whether we are in
1661 // the process of initializing this class or not. 1670 // the process of initializing this class or not.
1662 owner_ = owner; 1671 owner_ = owner;
1663 } 1672 }
1664 1673
1665 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { 1674 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() {
1666 DisconnectPageActionAccelerator(); 1675 DisconnectPageActionAccelerator();
1667 1676
1677 if (icon_animation_.get())
1678 icon_animation_->RemoveObserver(this);
1679
1668 image_.Destroy(); 1680 image_.Destroy();
1669 event_box_.Destroy(); 1681 event_box_.Destroy();
1670 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); 1682 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end();
1671 ++iter) { 1683 ++iter) {
1672 g_object_unref(iter->second); 1684 g_object_unref(iter->second);
1673 } 1685 }
1674 if (last_icon_pixbuf_) 1686 if (last_icon_pixbuf_)
1675 g_object_unref(last_icon_pixbuf_); 1687 g_object_unref(last_icon_pixbuf_);
1676 } 1688 }
1677 1689
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 std::string icon_path = (icon_index < 0) ? 1733 std::string icon_path = (icon_index < 0) ?
1722 page_action_->default_icon_path() : 1734 page_action_->default_icon_path() :
1723 page_action_->icon_paths()->at(icon_index); 1735 page_action_->icon_paths()->at(icon_index);
1724 if (!icon_path.empty()) { 1736 if (!icon_path.empty()) {
1725 PixbufMap::iterator iter = pixbufs_.find(icon_path); 1737 PixbufMap::iterator iter = pixbufs_.find(icon_path);
1726 if (iter != pixbufs_.end()) 1738 if (iter != pixbufs_.end())
1727 pixbuf = iter->second; 1739 pixbuf = iter->second;
1728 } 1740 }
1729 } 1741 }
1730 // The pixbuf might not be loaded yet. 1742 // The pixbuf might not be loaded yet.
1731 if (pixbuf) 1743 if (pixbuf) {
1732 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); 1744 if (icon_animation_.get()) {
1745 // Draw |pixbuf| with the fade-in |icon_animation_| applied to it.
1746 // Use a temporary gfx::Image to do the conversion to/from a SkBitmap.
1747 g_object_ref(pixbuf); // don't let gfx::Image take ownership.
1748 gfx::Image animated_image(
1749 icon_animation_->Apply(*gfx::Image(pixbuf).ToSkBitmap()));
1750 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()),
1751 animated_image.ToGdkPixbuf());
1752 } else {
1753 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf);
1754 }
1755 }
1733 } 1756 }
1734 1757
1735 bool old_visible = IsVisible(); 1758 bool old_visible = IsVisible();
1736 if (visible) 1759 if (visible)
1737 gtk_widget_show_all(event_box_.get()); 1760 gtk_widget_show_all(event_box_.get());
1738 else 1761 else
1739 gtk_widget_hide_all(event_box_.get()); 1762 gtk_widget_hide_all(event_box_.get());
1740 1763
1741 if (visible != old_visible) { 1764 if (visible != old_visible) {
1742 content::NotificationService::current()->Notify( 1765 content::NotificationService::current()->Notify(
(...skipping 18 matching lines...) Expand all
1761 // index greater than the number of icons, it must be the default icon. 1784 // index greater than the number of icons, it must be the default icon.
1762 if (!image.IsEmpty()) { 1785 if (!image.IsEmpty()) {
1763 GdkPixbuf* pixbuf = 1786 GdkPixbuf* pixbuf =
1764 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); 1787 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf()));
1765 if (index < static_cast<int>(page_action_->icon_paths()->size())) 1788 if (index < static_cast<int>(page_action_->icon_paths()->size()))
1766 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; 1789 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf;
1767 else 1790 else
1768 pixbufs_[page_action_->default_icon_path()] = pixbuf; 1791 pixbufs_[page_action_->default_icon_path()] = pixbuf;
1769 } 1792 }
1770 1793
1771 // If we have no owner, that means this class is still being constructed and 1794 // If we have no owner, that means this class is still being constructed.
1772 // we should not UpdatePageActions, since it leads to the PageActions being 1795 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
1773 // destroyed again and new ones recreated (causing an infinite loop). 1796 if (tab_contents)
1774 if (owner_) 1797 UpdateVisibility(tab_contents->web_contents(), current_url_);
not at google - send to devlin 2012/06/20 22:43:25 ditto
1775 owner_->UpdatePageActions();
1776 } 1798 }
1777 1799
1778 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { 1800 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() {
1779 GdkEventButton event = {}; 1801 GdkEventButton event = {};
1780 event.button = 1; 1802 event.button = 1;
1781 OnButtonPressed(widget(), &event); 1803 OnButtonPressed(widget(), &event);
1782 } 1804 }
1783 1805
1784 void LocationBarViewGtk::PageActionViewGtk::Observe( 1806 void LocationBarViewGtk::PageActionViewGtk::Observe(
1785 int type, 1807 int type,
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
1828 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); 1850 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL));
1829 1851
1830 // Since we've added an accelerator, we'll need to unregister it before 1852 // Since we've added an accelerator, we'll need to unregister it before
1831 // the window is closed, so we listen for the window being closed. 1853 // the window is closed, so we listen for the window being closed.
1832 registrar_.Add(this, 1854 registrar_.Add(this,
1833 chrome::NOTIFICATION_WINDOW_CLOSED, 1855 chrome::NOTIFICATION_WINDOW_CLOSED,
1834 content::Source<GtkWindow>(window_)); 1856 content::Source<GtkWindow>(window_));
1835 } 1857 }
1836 } 1858 }
1837 1859
1860 void LocationBarViewGtk::PageActionViewGtk::OnIconChanged(
1861 const LocationBarController::IconAnimation& animation,
1862 LocationBarController* controller) {
1863 TabContents* tab_contents = owner_->GetTabContents();
1864
1865 // Animation notification might be for another tab.
Yoyo Zhou 2012/06/22 00:50:29 Same comment as mac.
1866 LocationBarController* current_controller = tab_contents ?
1867 tab_contents->extension_tab_helper()->location_bar_controller() : NULL;
1868 if (controller != current_controller)
1869 return;
1870
1871 UpdateVisibility(tab_contents->web_contents(), current_url_);
1872 }
1873
1838 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { 1874 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() {
1839 if (accel_group_) { 1875 if (accel_group_) {
1840 gtk_accel_group_disconnect_key( 1876 gtk_accel_group_disconnect_key(
1841 accel_group_, 1877 accel_group_,
1842 keybinding_.get()->GetGdkKeyCode(), 1878 keybinding_.get()->GetGdkKeyCode(),
1843 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); 1879 static_cast<GdkModifierType>(keybinding_.get()->modifiers()));
1844 gtk_window_remove_accel_group(window_, accel_group_); 1880 gtk_window_remove_accel_group(window_, accel_group_);
1845 g_object_unref(accel_group_); 1881 g_object_unref(accel_group_);
1846 accel_group_ = NULL; 1882 accel_group_ = NULL;
1847 keybinding_.reset(NULL); 1883 keybinding_.reset(NULL);
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
1936 } 1972 }
1937 1973
1938 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 1974 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
1939 ExtensionAction* action) { 1975 ExtensionAction* action) {
1940 ExtensionPopupGtk::Show( 1976 ExtensionPopupGtk::Show(
1941 action->GetPopupUrl(current_tab_id_), 1977 action->GetPopupUrl(current_tab_id_),
1942 owner_->browser_, 1978 owner_->browser_,
1943 event_box_.get(), 1979 event_box_.get(),
1944 ExtensionPopupGtk::SHOW_AND_INSPECT); 1980 ExtensionPopupGtk::SHOW_AND_INSPECT);
1945 } 1981 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698