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 1772 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1783 } | 1783 } |
1784 | 1784 |
1785 //////////////////////////////////////////////////////////////////////////////// | 1785 //////////////////////////////////////////////////////////////////////////////// |
1786 // LocationBarViewGtk::PageActionViewGtk | 1786 // LocationBarViewGtk::PageActionViewGtk |
1787 | 1787 |
1788 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1788 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
1789 LocationBarViewGtk* owner, | 1789 LocationBarViewGtk* owner, |
1790 ExtensionAction* page_action) | 1790 ExtensionAction* page_action) |
1791 : owner_(NULL), | 1791 : owner_(NULL), |
1792 page_action_(page_action), | 1792 page_action_(page_action), |
1793 tracker_(this), | |
1794 current_tab_id_(-1), | 1793 current_tab_id_(-1), |
1795 window_(NULL), | 1794 window_(NULL), |
1796 accel_group_(NULL), | 1795 accel_group_(NULL), |
1797 preview_enabled_(false), | 1796 preview_enabled_(false), |
1798 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( | 1797 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( |
1799 page_action->GetIconAnimation( | 1798 page_action->GetIconAnimation( |
1800 SessionID::IdForTab(owner->GetTabContents()->web_contents())), | 1799 SessionID::IdForTab(owner->GetTabContents()->web_contents())), |
1801 this)) { | 1800 this)) { |
1802 event_box_.Own(gtk_event_box_new()); | 1801 event_box_.Own(gtk_event_box_new()); |
1803 gtk_widget_set_size_request(event_box_.get(), | 1802 gtk_widget_set_size_request(event_box_.get(), |
(...skipping 10 matching lines...) Expand all Loading... |
1814 G_CALLBACK(OnRealizeThunk), this); | 1813 G_CALLBACK(OnRealizeThunk), this); |
1815 | 1814 |
1816 image_.Own(gtk_image_new()); | 1815 image_.Own(gtk_image_new()); |
1817 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1816 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
1818 | 1817 |
1819 const Extension* extension = owner->browser()->profile()-> | 1818 const Extension* extension = owner->browser()->profile()-> |
1820 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1819 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
1821 false); | 1820 false); |
1822 DCHECK(extension); | 1821 DCHECK(extension); |
1823 | 1822 |
1824 std::string path = page_action_->default_icon_path(); | 1823 icon_factory_.reset( |
1825 if (!path.empty()) { | 1824 new ExtensionActionIconFactory(extension, page_action, this)); |
1826 tracker_.LoadImage(extension, extension->GetResource(path), | |
1827 gfx::Size(Extension::kPageActionIconMaxSize, | |
1828 Extension::kPageActionIconMaxSize), | |
1829 ImageLoadingTracker::DONT_CACHE); | |
1830 } | |
1831 | 1825 |
1832 // We set the owner last of all so that we can determine whether we are in | 1826 // We set the owner last of all so that we can determine whether we are in |
1833 // the process of initializing this class or not. | 1827 // the process of initializing this class or not. |
1834 owner_ = owner; | 1828 owner_ = owner; |
1835 } | 1829 } |
1836 | 1830 |
1837 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { | 1831 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
1838 DisconnectPageActionAccelerator(); | 1832 DisconnectPageActionAccelerator(); |
1839 | 1833 |
1840 image_.Destroy(); | 1834 image_.Destroy(); |
(...skipping 12 matching lines...) Expand all Loading... |
1853 current_url_ = url; | 1847 current_url_ = url; |
1854 | 1848 |
1855 bool visible = contents && | 1849 bool visible = contents && |
1856 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); | 1850 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); |
1857 if (visible) { | 1851 if (visible) { |
1858 // Set the tooltip. | 1852 // Set the tooltip. |
1859 gtk_widget_set_tooltip_text(event_box_.get(), | 1853 gtk_widget_set_tooltip_text(event_box_.get(), |
1860 page_action_->GetTitle(current_tab_id_).c_str()); | 1854 page_action_->GetTitle(current_tab_id_).c_str()); |
1861 | 1855 |
1862 // Set the image. | 1856 // Set the image. |
1863 gfx::Image icon = page_action_->GetIcon(current_tab_id_); | 1857 gfx::Image icon = icon_factory_->GetIcon(current_tab_id_); |
1864 if (!icon.IsEmpty()) { | 1858 if (!icon.IsEmpty()) { |
1865 GdkPixbuf* pixbuf = icon.ToGdkPixbuf(); | 1859 GdkPixbuf* pixbuf = icon.ToGdkPixbuf(); |
1866 DCHECK(pixbuf); | 1860 DCHECK(pixbuf); |
1867 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1861 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
1868 } | 1862 } |
1869 } | 1863 } |
1870 | 1864 |
1871 bool old_visible = IsVisible(); | 1865 bool old_visible = IsVisible(); |
1872 if (visible) | 1866 if (visible) |
1873 gtk_widget_show_all(event_box_.get()); | 1867 gtk_widget_show_all(event_box_.get()); |
1874 else | 1868 else |
1875 gtk_widget_hide_all(event_box_.get()); | 1869 gtk_widget_hide_all(event_box_.get()); |
1876 | 1870 |
1877 if (visible != old_visible) { | 1871 if (visible != old_visible) { |
1878 content::NotificationService::current()->Notify( | 1872 content::NotificationService::current()->Notify( |
1879 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1873 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
1880 content::Source<ExtensionAction>(page_action_), | 1874 content::Source<ExtensionAction>(page_action_), |
1881 content::Details<WebContents>(contents)); | 1875 content::Details<WebContents>(contents)); |
1882 } | 1876 } |
1883 } | 1877 } |
1884 | 1878 |
1885 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1879 void LocationBarViewGtk::PageActionViewGtk::OnIconUpdated() { |
1886 const gfx::Image& image, | |
1887 const std::string& extension_id, | |
1888 int index) { | |
1889 page_action_->CacheIcon(image); | |
1890 | |
1891 // If we have no owner, that means this class is still being constructed. | 1880 // If we have no owner, that means this class is still being constructed. |
1892 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; | 1881 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
1893 if (tab_contents) | 1882 if (tab_contents) |
1894 UpdateVisibility(tab_contents->web_contents(), current_url_); | 1883 UpdateVisibility(tab_contents->web_contents(), current_url_); |
1895 } | 1884 } |
1896 | 1885 |
1897 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1886 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
1898 GdkEventButton event = {}; | 1887 GdkEventButton event = {}; |
1899 event.button = 1; | 1888 event.button = 1; |
1900 OnButtonPressed(widget(), &event); | 1889 OnButtonPressed(widget(), &event); |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2101 } | 2090 } |
2102 | 2091 |
2103 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2092 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
2104 ExtensionAction* action) { | 2093 ExtensionAction* action) { |
2105 ExtensionPopupGtk::Show( | 2094 ExtensionPopupGtk::Show( |
2106 action->GetPopupUrl(current_tab_id_), | 2095 action->GetPopupUrl(current_tab_id_), |
2107 owner_->browser_, | 2096 owner_->browser_, |
2108 event_box_.get(), | 2097 event_box_.get(), |
2109 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2098 ExtensionPopupGtk::SHOW_AND_INSPECT); |
2110 } | 2099 } |
OLD | NEW |