| 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 1781 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1792 } | 1792 } |
| 1793 | 1793 |
| 1794 //////////////////////////////////////////////////////////////////////////////// | 1794 //////////////////////////////////////////////////////////////////////////////// |
| 1795 // LocationBarViewGtk::PageActionViewGtk | 1795 // LocationBarViewGtk::PageActionViewGtk |
| 1796 | 1796 |
| 1797 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( | 1797 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( |
| 1798 LocationBarViewGtk* owner, | 1798 LocationBarViewGtk* owner, |
| 1799 ExtensionAction* page_action) | 1799 ExtensionAction* page_action) |
| 1800 : owner_(NULL), | 1800 : owner_(NULL), |
| 1801 page_action_(page_action), | 1801 page_action_(page_action), |
| 1802 tracker_(this), | |
| 1803 current_tab_id_(-1), | 1802 current_tab_id_(-1), |
| 1804 window_(NULL), | 1803 window_(NULL), |
| 1805 accel_group_(NULL), | 1804 accel_group_(NULL), |
| 1806 preview_enabled_(false), | 1805 preview_enabled_(false), |
| 1807 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( | 1806 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( |
| 1808 page_action->GetIconAnimation( | 1807 page_action->GetIconAnimation( |
| 1809 SessionID::IdForTab(owner->GetTabContents())), | 1808 SessionID::IdForTab(owner->GetTabContents())), |
| 1810 this)) { | 1809 this)) { |
| 1811 event_box_.Own(gtk_event_box_new()); | 1810 event_box_.Own(gtk_event_box_new()); |
| 1812 gtk_widget_set_size_request(event_box_.get(), | 1811 gtk_widget_set_size_request(event_box_.get(), |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1823 G_CALLBACK(OnRealizeThunk), this); | 1822 G_CALLBACK(OnRealizeThunk), this); |
| 1824 | 1823 |
| 1825 image_.Own(gtk_image_new()); | 1824 image_.Own(gtk_image_new()); |
| 1826 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); | 1825 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); |
| 1827 | 1826 |
| 1828 const Extension* extension = owner->browser()->profile()-> | 1827 const Extension* extension = owner->browser()->profile()-> |
| 1829 GetExtensionService()->GetExtensionById(page_action->extension_id(), | 1828 GetExtensionService()->GetExtensionById(page_action->extension_id(), |
| 1830 false); | 1829 false); |
| 1831 DCHECK(extension); | 1830 DCHECK(extension); |
| 1832 | 1831 |
| 1833 // Load all the icons declared in the manifest. This is the contents of the | 1832 icon_factory_.reset(new ExtensionActionIconFactory(extension, this)); |
| 1834 // icons array, plus the default_icon property, if any. | |
| 1835 std::vector<std::string> icon_paths(*page_action->icon_paths()); | |
| 1836 if (!page_action_->default_icon_path().empty()) | |
| 1837 icon_paths.push_back(page_action_->default_icon_path()); | |
| 1838 | |
| 1839 for (std::vector<std::string>::iterator iter = icon_paths.begin(); | |
| 1840 iter != icon_paths.end(); ++iter) { | |
| 1841 tracker_.LoadImage(extension, extension->GetResource(*iter), | |
| 1842 gfx::Size(Extension::kPageActionIconMaxSize, | |
| 1843 Extension::kPageActionIconMaxSize), | |
| 1844 ImageLoadingTracker::DONT_CACHE); | |
| 1845 } | |
| 1846 | 1833 |
| 1847 // We set the owner last of all so that we can determine whether we are in | 1834 // We set the owner last of all so that we can determine whether we are in |
| 1848 // the process of initializing this class or not. | 1835 // the process of initializing this class or not. |
| 1849 owner_ = owner; | 1836 owner_ = owner; |
| 1850 } | 1837 } |
| 1851 | 1838 |
| 1852 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { | 1839 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { |
| 1853 DisconnectPageActionAccelerator(); | 1840 DisconnectPageActionAccelerator(); |
| 1854 | 1841 |
| 1855 image_.Destroy(); | 1842 image_.Destroy(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1868 current_url_ = url; | 1855 current_url_ = url; |
| 1869 | 1856 |
| 1870 bool visible = contents && | 1857 bool visible = contents && |
| 1871 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); | 1858 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); |
| 1872 if (visible) { | 1859 if (visible) { |
| 1873 // Set the tooltip. | 1860 // Set the tooltip. |
| 1874 gtk_widget_set_tooltip_text(event_box_.get(), | 1861 gtk_widget_set_tooltip_text(event_box_.get(), |
| 1875 page_action_->GetTitle(current_tab_id_).c_str()); | 1862 page_action_->GetTitle(current_tab_id_).c_str()); |
| 1876 | 1863 |
| 1877 // Set the image. | 1864 // Set the image. |
| 1878 gfx::Image icon = page_action_->GetIcon(current_tab_id_); | 1865 gfx::Image icon = |
| 1866 page_action_->GetIcon(current_tab_id_, icon_factory_.get()); |
| 1879 if (!icon.IsEmpty()) { | 1867 if (!icon.IsEmpty()) { |
| 1880 GdkPixbuf* pixbuf = icon.ToGdkPixbuf(); | 1868 GdkPixbuf* pixbuf = icon.ToGdkPixbuf(); |
| 1881 DCHECK(pixbuf); | 1869 DCHECK(pixbuf); |
| 1882 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); | 1870 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); |
| 1883 } | 1871 } |
| 1884 } | 1872 } |
| 1885 | 1873 |
| 1886 bool old_visible = IsVisible(); | 1874 bool old_visible = IsVisible(); |
| 1887 if (visible) | 1875 if (visible) |
| 1888 gtk_widget_show_all(event_box_.get()); | 1876 gtk_widget_show_all(event_box_.get()); |
| 1889 else | 1877 else |
| 1890 gtk_widget_hide_all(event_box_.get()); | 1878 gtk_widget_hide_all(event_box_.get()); |
| 1891 | 1879 |
| 1892 if (visible != old_visible) { | 1880 if (visible != old_visible) { |
| 1893 content::NotificationService::current()->Notify( | 1881 content::NotificationService::current()->Notify( |
| 1894 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, | 1882 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, |
| 1895 content::Source<ExtensionAction>(page_action_), | 1883 content::Source<ExtensionAction>(page_action_), |
| 1896 content::Details<WebContents>(contents)); | 1884 content::Details<WebContents>(contents)); |
| 1897 } | 1885 } |
| 1898 } | 1886 } |
| 1899 | 1887 |
| 1900 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( | 1888 void LocationBarViewGtk::PageActionViewGtk::OnIconUpdated() { |
| 1901 const gfx::Image& image, | |
| 1902 const std::string& extension_id, | |
| 1903 int index) { | |
| 1904 // We loaded icons()->size() icons, plus one extra if the page action had | |
| 1905 // a default icon. | |
| 1906 int total_icons = static_cast<int>(page_action_->icon_paths()->size()); | |
| 1907 if (!page_action_->default_icon_path().empty()) | |
| 1908 total_icons++; | |
| 1909 DCHECK(index < total_icons); | |
| 1910 | |
| 1911 // Map the index of the loaded image back to its name. If we ever get an | |
| 1912 // index greater than the number of icons, it must be the default icon. | |
| 1913 if (index < static_cast<int>(page_action_->icon_paths()->size())) | |
| 1914 page_action_->CacheIcon(page_action_->icon_paths()->at(index), image); | |
| 1915 else | |
| 1916 page_action_->CacheIcon(page_action_->default_icon_path(), image); | |
| 1917 | |
| 1918 // If we have no owner, that means this class is still being constructed. | 1889 // If we have no owner, that means this class is still being constructed. |
| 1919 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; | 1890 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; |
| 1920 if (tab_contents) | 1891 if (tab_contents) |
| 1921 UpdateVisibility(tab_contents->web_contents(), current_url_); | 1892 UpdateVisibility(tab_contents->web_contents(), current_url_); |
| 1922 } | 1893 } |
| 1923 | 1894 |
| 1924 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { | 1895 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { |
| 1925 GdkEventButton event = {}; | 1896 GdkEventButton event = {}; |
| 1926 event.button = 1; | 1897 event.button = 1; |
| 1927 OnButtonPressed(widget(), &event); | 1898 OnButtonPressed(widget(), &event); |
| (...skipping 206 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2134 } | 2105 } |
| 2135 | 2106 |
| 2136 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( | 2107 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( |
| 2137 ExtensionAction* action) { | 2108 ExtensionAction* action) { |
| 2138 ExtensionPopupGtk::Show( | 2109 ExtensionPopupGtk::Show( |
| 2139 action->GetPopupUrl(current_tab_id_), | 2110 action->GetPopupUrl(current_tab_id_), |
| 2140 owner_->browser_, | 2111 owner_->browser_, |
| 2141 event_box_.get(), | 2112 event_box_.get(), |
| 2142 ExtensionPopupGtk::SHOW_AND_INSPECT); | 2113 ExtensionPopupGtk::SHOW_AND_INSPECT); |
| 2143 } | 2114 } |
| OLD | NEW |