| 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 873 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1620 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1620 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
| 1621 LocationBarViewGtk* owner, | 1621 LocationBarViewGtk* owner, |
| 1622 ExtensionAction* page_action) | 1622 ExtensionAction* page_action) |
| 1623 : owner_(NULL), | 1623 : owner_(NULL), |
| 1624 page_action_(page_action), | 1624 page_action_(page_action), |
| 1625 last_icon_pixbuf_(NULL), | 1625 last_icon_pixbuf_(NULL), |
| 1626 tracker_(this), | 1626 tracker_(this), |
| 1627 current_tab_id_(-1), | 1627 current_tab_id_(-1), |
| 1628 window_(NULL), | 1628 window_(NULL), |
| 1629 accel_group_(NULL), | 1629 accel_group_(NULL), |
| 1630 preview_enabled_(false) { | 1630 preview_enabled_(false), |
| 1631 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( |
| 1632 page_action->GetIconAnimation( |
| 1633 owner->GetTabContents()->extension_tab_helper()->tab_id()), |
| 1634 this)) { |
| 1631 event_box_.Own(gtk_event_box_new()); | 1635 event_box_.Own(gtk_event_box_new()); |
| 1632 gtk_widget_set_size_request(event_box_.get(), | 1636 gtk_widget_set_size_request(event_box_.get(), |
| 1633 Extension::kPageActionIconMaxSize, | 1637 Extension::kPageActionIconMaxSize, |
| 1634 Extension::kPageActionIconMaxSize); | 1638 Extension::kPageActionIconMaxSize); |
| 1635 | 1639 |
| 1636 // Make the event box not visible so it does not paint a background. | 1640 // Make the event box not visible so it does not paint a background. |
| 1637 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); | 1641 gtk_event_box_set_visible_window(GTK_EVENT_BOX(event_box_.get()), FALSE); |
| 1638 g_signal_connect(event_box_.get(), "button-press-event", | 1642 g_signal_connect(event_box_.get(), "button-press-event", |
| 1639 G_CALLBACK(&OnButtonPressedThunk), this); | 1643 G_CALLBACK(&OnButtonPressedThunk), this); |
| 1640 g_signal_connect_after(event_box_.get(), "expose-event", | 1644 g_signal_connect_after(event_box_.get(), "expose-event", |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1728 std::string icon_path = (icon_index < 0) ? | 1732 std::string icon_path = (icon_index < 0) ? |
| 1729 page_action_->default_icon_path() : | 1733 page_action_->default_icon_path() : |
| 1730 page_action_->icon_paths()->at(icon_index); | 1734 page_action_->icon_paths()->at(icon_index); |
| 1731 if (!icon_path.empty()) { | 1735 if (!icon_path.empty()) { |
| 1732 PixbufMap::iterator iter = pixbufs_.find(icon_path); | 1736 PixbufMap::iterator iter = pixbufs_.find(icon_path); |
| 1733 if (iter != pixbufs_.end()) | 1737 if (iter != pixbufs_.end()) |
| 1734 pixbuf = iter->second; | 1738 pixbuf = iter->second; |
| 1735 } | 1739 } |
| 1736 } | 1740 } |
| 1737 // The pixbuf might not be loaded yet. | 1741 // The pixbuf might not be loaded yet. |
| 1738 if (pixbuf) | 1742 if (pixbuf) { |
| 1739 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1743 const ExtensionAction::IconAnimation* icon_animation = |
| 1744 scoped_icon_animation_observer_.icon_animation(); |
| 1745 if (icon_animation) { |
| 1746 // Draw |pixbuf| with the fade-in |icon_animation_| applied to it. |
| 1747 // Use a temporary gfx::Image to do the conversion to/from a SkBitmap. |
| 1748 g_object_ref(pixbuf); // don't let gfx::Image take ownership. |
| 1749 gfx::Image animated_image( |
| 1750 icon_animation->Apply(*gfx::Image(pixbuf).ToSkBitmap())); |
| 1751 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), |
| 1752 animated_image.ToGdkPixbuf()); |
| 1753 } else { |
| 1754 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
| 1755 } |
| 1756 } |
| 1740 } | 1757 } |
| 1741 | 1758 |
| 1742 bool old_visible = IsVisible(); | 1759 bool old_visible = IsVisible(); |
| 1743 if (visible) | 1760 if (visible) |
| 1744 gtk_widget_show_all(event_box_.get()); | 1761 gtk_widget_show_all(event_box_.get()); |
| 1745 else | 1762 else |
| 1746 gtk_widget_hide_all(event_box_.get()); | 1763 gtk_widget_hide_all(event_box_.get()); |
| 1747 | 1764 |
| 1748 if (visible != old_visible) { | 1765 if (visible != old_visible) { |
| 1749 content::NotificationService::current()->Notify( | 1766 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. | 1785 // index greater than the number of icons, it must be the default icon. |
| 1769 if (!image.IsEmpty()) { | 1786 if (!image.IsEmpty()) { |
| 1770 GdkPixbuf* pixbuf = | 1787 GdkPixbuf* pixbuf = |
| 1771 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); | 1788 static_cast<GdkPixbuf*>(g_object_ref(image.ToGdkPixbuf())); |
| 1772 if (index < static_cast<int>(page_action_->icon_paths()->size())) | 1789 if (index < static_cast<int>(page_action_->icon_paths()->size())) |
| 1773 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; | 1790 pixbufs_[page_action_->icon_paths()->at(index)] = pixbuf; |
| 1774 else | 1791 else |
| 1775 pixbufs_[page_action_->default_icon_path()] = pixbuf; | 1792 pixbufs_[page_action_->default_icon_path()] = pixbuf; |
| 1776 } | 1793 } |
| 1777 | 1794 |
| 1778 // If we have no owner, that means this class is still being constructed and | 1795 // 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 | 1796 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
| 1780 // destroyed again and new ones recreated (causing an infinite loop). | 1797 if (tab_contents) |
| 1781 if (owner_) | 1798 UpdateVisibility(tab_contents->web_contents(), current_url_); |
| 1782 owner_->UpdatePageActions(); | |
| 1783 } | 1799 } |
| 1784 | 1800 |
| 1785 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1801 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
| 1786 GdkEventButton event = {}; | 1802 GdkEventButton event = {}; |
| 1787 event.button = 1; | 1803 event.button = 1; |
| 1788 OnButtonPressed(widget(), &event); | 1804 OnButtonPressed(widget(), &event); |
| 1789 } | 1805 } |
| 1790 | 1806 |
| 1791 void LocationBarViewGtk::PageActionViewGtk::Observe( | 1807 void LocationBarViewGtk::PageActionViewGtk::Observe( |
| 1792 int type, | 1808 int type, |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1836 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); | 1852 g_cclosure_new(G_CALLBACK(OnGtkAccelerator), this, NULL)); |
| 1837 | 1853 |
| 1838 // Since we've added an accelerator, we'll need to unregister it before | 1854 // Since we've added an accelerator, we'll need to unregister it before |
| 1839 // the window is closed, so we listen for the window being closed. | 1855 // the window is closed, so we listen for the window being closed. |
| 1840 registrar_.Add(this, | 1856 registrar_.Add(this, |
| 1841 chrome::NOTIFICATION_WINDOW_CLOSED, | 1857 chrome::NOTIFICATION_WINDOW_CLOSED, |
| 1842 content::Source<GtkWindow>(window_)); | 1858 content::Source<GtkWindow>(window_)); |
| 1843 } | 1859 } |
| 1844 } | 1860 } |
| 1845 | 1861 |
| 1862 void LocationBarViewGtk::PageActionViewGtk::OnIconChanged( |
| 1863 const ExtensionAction::IconAnimation& animation) { |
| 1864 UpdateVisibility(owner_->GetWebContents(), current_url_); |
| 1865 } |
| 1866 |
| 1846 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { | 1867 void LocationBarViewGtk::PageActionViewGtk::DisconnectPageActionAccelerator() { |
| 1847 if (accel_group_) { | 1868 if (accel_group_) { |
| 1848 gtk_accel_group_disconnect_key( | 1869 gtk_accel_group_disconnect_key( |
| 1849 accel_group_, | 1870 accel_group_, |
| 1850 keybinding_.get()->GetGdkKeyCode(), | 1871 keybinding_.get()->GetGdkKeyCode(), |
| 1851 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); | 1872 static_cast<GdkModifierType>(keybinding_.get()->modifiers())); |
| 1852 gtk_window_remove_accel_group(window_, accel_group_); | 1873 gtk_window_remove_accel_group(window_, accel_group_); |
| 1853 g_object_unref(accel_group_); | 1874 g_object_unref(accel_group_); |
| 1854 accel_group_ = NULL; | 1875 accel_group_ = NULL; |
| 1855 keybinding_.reset(NULL); | 1876 keybinding_.reset(NULL); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1952 } | 1973 } |
| 1953 | 1974 |
| 1954 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 1975 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
| 1955 ExtensionAction* action) { | 1976 ExtensionAction* action) { |
| 1956 ExtensionPopupGtk::Show( | 1977 ExtensionPopupGtk::Show( |
| 1957 action->GetPopupUrl(current_tab_id_), | 1978 action->GetPopupUrl(current_tab_id_), |
| 1958 owner_->browser_, | 1979 owner_->browser_, |
| 1959 event_box_.get(), | 1980 event_box_.get(), |
| 1960 ExtensionPopupGtk::SHOW_AND_INSPECT); | 1981 ExtensionPopupGtk::SHOW_AND_INSPECT); |
| 1961 } | 1982 } |
| OLD | NEW |