| 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 "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 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 724 // If there are no visible content things, hide the top level box so it | 724 // If there are no visible content things, hide the top level box so it |
| 725 // doesn't mess with padding. | 725 // doesn't mess with padding. |
| 726 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); | 726 gtk_widget_set_visible(content_setting_hbox_.get(), any_visible); |
| 727 } | 727 } |
| 728 | 728 |
| 729 void LocationBarViewGtk::UpdatePageActions() { | 729 void LocationBarViewGtk::UpdatePageActions() { |
| 730 std::vector<ExtensionAction*> new_page_actions; | 730 std::vector<ExtensionAction*> new_page_actions; |
| 731 | 731 |
| 732 TabContents* tab_contents = GetTabContents(); | 732 TabContents* tab_contents = GetTabContents(); |
| 733 if (tab_contents) { | 733 if (tab_contents) { |
| 734 LocationBarController* controller = | 734 LocationBarController* location_bar_controller = |
| 735 tab_contents->extension_tab_helper()->location_bar_controller(); | 735 tab_contents->extension_tab_helper()->location_bar_controller(); |
| 736 new_page_actions = controller->GetCurrentActions(); | 736 new_page_actions = location_bar_controller->GetCurrentActions(); |
| 737 } | 737 } |
| 738 | 738 |
| 739 // Initialize on the first call, or re-initialize if more extensions have been | 739 // Initialize on the first call, or re-initialize if more extensions have been |
| 740 // loaded or added after startup. | 740 // loaded or added after startup. |
| 741 if (new_page_actions != page_actions_) { | 741 if (new_page_actions != page_actions_) { |
| 742 page_actions_.swap(new_page_actions); | 742 page_actions_.swap(new_page_actions); |
| 743 page_action_views_.reset(); | 743 page_action_views_.reset(); |
| 744 | 744 |
| 745 for (size_t i = 0; i < page_actions_.size(); ++i) { | 745 for (size_t i = 0; i < page_actions_.size(); ++i) { |
| 746 page_action_views_.push_back( | 746 page_action_views_.push_back( |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1657 icon_paths.push_back(page_action_->default_icon_path()); | 1657 icon_paths.push_back(page_action_->default_icon_path()); |
| 1658 | 1658 |
| 1659 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | 1659 for (std::vector<std::string>::iterator iter = icon_paths.begin(); |
| 1660 iter != icon_paths.end(); ++iter) { | 1660 iter != icon_paths.end(); ++iter) { |
| 1661 tracker_.LoadImage(extension, extension->GetResource(*iter), | 1661 tracker_.LoadImage(extension, extension->GetResource(*iter), |
| 1662 gfx::Size(Extension::kPageActionIconMaxSize, | 1662 gfx::Size(Extension::kPageActionIconMaxSize, |
| 1663 Extension::kPageActionIconMaxSize), | 1663 Extension::kPageActionIconMaxSize), |
| 1664 ImageLoadingTracker::DONT_CACHE); | 1664 ImageLoadingTracker::DONT_CACHE); |
| 1665 } | 1665 } |
| 1666 | 1666 |
| 1667 icon_animation_ = page_action->GetIconAnimation( |
| 1668 owner->GetTabContents()->extension_tab_helper()->tab_id()); |
| 1669 if (icon_animation_.get()) |
| 1670 icon_animation_->AddObserver(this); |
| 1671 |
| 1667 // We set the owner last of all so that we can determine whether we are in | 1672 // We set the owner last of all so that we can determine whether we are in |
| 1668 // the process of initializing this class or not. | 1673 // the process of initializing this class or not. |
| 1669 owner_ = owner; | 1674 owner_ = owner; |
| 1670 } | 1675 } |
| 1671 | 1676 |
| 1672 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { | 1677 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
| 1673 DisconnectPageActionAccelerator(); | 1678 DisconnectPageActionAccelerator(); |
| 1674 | 1679 |
| 1680 if (icon_animation_.get()) |
| 1681 icon_animation_->RemoveObserver(this); |
| 1682 |
| 1675 image_.Destroy(); | 1683 image_.Destroy(); |
| 1676 event_box_.Destroy(); | 1684 event_box_.Destroy(); |
| 1677 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); | 1685 for (PixbufMap::iterator iter = pixbufs_.begin(); iter != pixbufs_.end(); |
| 1678 ++iter) { | 1686 ++iter) { |
| 1679 g_object_unref(iter->second); | 1687 g_object_unref(iter->second); |
| 1680 } | 1688 } |
| 1681 if (last_icon_pixbuf_) | 1689 if (last_icon_pixbuf_) |
| 1682 g_object_unref(last_icon_pixbuf_); | 1690 g_object_unref(last_icon_pixbuf_); |
| 1683 } | 1691 } |
| 1684 | 1692 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 std::string icon_path = (icon_index < 0) ? | 1736 std::string icon_path = (icon_index < 0) ? |
| 1729 page_action_->default_icon_path() : | 1737 page_action_->default_icon_path() : |
| 1730 page_action_->icon_paths()->at(icon_index); | 1738 page_action_->icon_paths()->at(icon_index); |
| 1731 if (!icon_path.empty()) { | 1739 if (!icon_path.empty()) { |
| 1732 PixbufMap::iterator iter = pixbufs_.find(icon_path); | 1740 PixbufMap::iterator iter = pixbufs_.find(icon_path); |
| 1733 if (iter != pixbufs_.end()) | 1741 if (iter != pixbufs_.end()) |
| 1734 pixbuf = iter->second; | 1742 pixbuf = iter->second; |
| 1735 } | 1743 } |
| 1736 } | 1744 } |
| 1737 // The pixbuf might not be loaded yet. | 1745 // The pixbuf might not be loaded yet. |
| 1738 if (pixbuf) | 1746 if (pixbuf) { |
| 1739 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1747 if (icon_animation_.get()) { |
| 1748 // Draw |pixbuf| with the fade-in |icon_animation_| applied to it. |
| 1749 // Use a temporary gfx::Image to do the conversion to/from a SkBitmap. |
| 1750 g_object_ref(pixbuf); // don't let gfx::Image take ownership. |
| 1751 gfx::Image animated_image( |
| 1752 icon_animation_->Apply(*gfx::Image(pixbuf).ToSkBitmap())); |
| 1753 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), |
| 1754 animated_image.ToGdkPixbuf()); |
| 1755 } else { |
| 1756 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
| 1757 } |
| 1758 } |
| 1740 } | 1759 } |
| 1741 | 1760 |
| 1742 bool old_visible = IsVisible(); | 1761 bool old_visible = IsVisible(); |
| 1743 if (visible) | 1762 if (visible) |
| 1744 gtk_widget_show_all(event_box_.get()); | 1763 gtk_widget_show_all(event_box_.get()); |
| 1745 else | 1764 else |
| 1746 gtk_widget_hide_all(event_box_.get()); | 1765 gtk_widget_hide_all(event_box_.get()); |
| 1747 | 1766 |
| 1748 if (visible != old_visible) { | 1767 if (visible != old_visible) { |
| 1749 content::NotificationService::current()->Notify( | 1768 content::NotificationService::current()->Notify( |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1768 // index greater than the number of icons, it must be the default icon. | 1787 // index greater than the number of icons, it must be the default icon. |
| 1769 if (!image.IsEmpty()) { | 1788 if (!image.IsEmpty()) { |
| 1770 GdkPixbuf* pixbuf = | 1789 GdkPixbuf* pixbuf = |
| 1771 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); | 1790 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); |
| 1772 if (index < static_cast<int>(page_action_->icon_paths()->size())) | 1791 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
| 1773 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; | 1792 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; |
| 1774 else | 1793 else |
| 1775 pixbufs_[page_action_->default_icon_path()] = pixbuf; | 1794 pixbufs_[page_action_->default_icon_path()] = pixbuf; |
| 1776 } | 1795 } |
| 1777 | 1796 |
| 1778 // If we have no owner, that means this class is still being constructed and | 1797 // If we have no owner, that means this class is still being constructed. |
| 1779 // we should not UpdatePageActions, since it leads to the PageActions being | 1798 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
| 1780 // destroyed again and new ones recreated (causing an infinite loop). | 1799 if (tab_contents) |
| 1781 if (owner_) | 1800 UpdateVisibility(tab_contents->web_contents(), current_url_); |
| 1782 owner_->UpdatePageActions(); | |
| 1783 } | 1801 } |
| 1784 | 1802 |
| 1785 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1803 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
| 1786 GdkEventButton event = {}; | 1804 GdkEventButton event = {}; |
| 1787 event.button = 1; | 1805 event.button = 1; |
| 1788 OnButtonPressed(widget(), &event); | 1806 OnButtonPressed(widget(), &event); |
| 1789 } | 1807 } |
| 1790 | 1808 |
| 1791 void LocationBarViewGtk::PageActionViewGtk::Observe( | 1809 void LocationBarViewGtk::PageActionViewGtk::Observe( |
| 1792 int type, | 1810 int type, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1835 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); | 1853 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
| 1836 | 1854 |
| 1837 // Since we've added an accelerator, we'll need to unregister it before | 1855 // Since we've added an accelerator, we'll need to unregister it before |
| 1838 // the window is closed, so we listen for the window being closed. | 1856 // the window is closed, so we listen for the window being closed. |
| 1839 registrar_.Add(this, | 1857 registrar_.Add(this, |
| 1840 chrome::NOTIFICATION_WINDOW_CLOSED, | 1858 chrome::NOTIFICATION_WINDOW_CLOSED, |
| 1841 content::Source<GtkWindow>(window_)); | 1859 content::Source<GtkWindow>(window_)); |
| 1842 } | 1860 } |
| 1843 } | 1861 } |
| 1844 | 1862 |
| 1863 void LocationBarViewGtk::PageActionViewGtk::OnIconChanged( |
| 1864 const ExtensionAction::IconAnimation& animation) { |
| 1865 UpdateVisibility(owner_->GetWebContents(), current_url_); |
| 1866 } |
| 1867 |
| 1845 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { | 1868 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { |
| 1846 if (accel_group_) { | 1869 if (accel_group_) { |
| 1847 gtk_accel_group_disconnect_key( | 1870 gtk_accel_group_disconnect_key( |
| 1848 accel_group_, | 1871 accel_group_, |
| 1849 keybinding_.get()->GetGdkKeyCode(), | 1872 keybinding_.get()->GetGdkKeyCode(), |
| 1850 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); | 1873 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); |
| 1851 gtk_window_remove_accel_group(window_, accel_group_); | 1874 gtk_window_remove_accel_group(window_, accel_group_); |
| 1852 g_object_unref(accel_group_); | 1875 g_object_unref(accel_group_); |
| 1853 accel_group_ = NULL; | 1876 accel_group_ = NULL; |
| 1854 keybinding_.reset(NULL); | 1877 keybinding_.reset(NULL); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1951 } | 1974 } |
| 1952 | 1975 |
| 1953 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 1976 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
| 1954 ExtensionAction* action) { | 1977 ExtensionAction* action) { |
| 1955 ExtensionPopupGtk::Show( | 1978 ExtensionPopupGtk::Show( |
| 1956 action->GetPopupUrl(current_tab_id_), | 1979 action->GetPopupUrl(current_tab_id_), |
| 1957 owner_->browser_, | 1980 owner_->browser_, |
| 1958 event_box_.get(), | 1981 event_box_.get(), |
| 1959 ExtensionPopupGtk::SHOW_AND_INSPECT); | 1982 ExtensionPopupGtk::SHOW_AND_INSPECT); |
| 1960 } | 1983 } |
| OLD | NEW |