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

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

Issue 10905005: Change browser/page action default icon defined in manifest to support hidpi. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 3 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 | Annotate | Revision Log
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 1768 matching lines...) Expand 10 before | Expand all | Expand 10 after
1779 } 1779 }
1780 1780
1781 //////////////////////////////////////////////////////////////////////////////// 1781 ////////////////////////////////////////////////////////////////////////////////
1782 // LocationBarViewGtk::PageActionViewGtk 1782 // LocationBarViewGtk::PageActionViewGtk
1783 1783
1784 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk( 1784 LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
1785 LocationBarViewGtk* owner, 1785 LocationBarViewGtk* owner,
1786 ExtensionAction* page_action) 1786 ExtensionAction* page_action)
1787 : owner_(NULL), 1787 : owner_(NULL),
1788 page_action_(page_action), 1788 page_action_(page_action),
1789 tracker_(this),
1790 current_tab_id_(-1), 1789 current_tab_id_(-1),
1791 window_(NULL), 1790 window_(NULL),
1792 accel_group_(NULL), 1791 accel_group_(NULL),
1793 preview_enabled_(false), 1792 preview_enabled_(false),
1794 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_( 1793 ALLOW_THIS_IN_INITIALIZER_LIST(scoped_icon_animation_observer_(
1795 page_action->GetIconAnimation( 1794 page_action->GetIconAnimation(
1796 SessionID::IdForTab(owner->GetTabContents()->web_contents())), 1795 SessionID::IdForTab(owner->GetTabContents()->web_contents())),
1797 this)) { 1796 this)) {
1798 event_box_.Own(gtk_event_box_new()); 1797 event_box_.Own(gtk_event_box_new());
1799 gtk_widget_set_size_request(event_box_.get(), 1798 gtk_widget_set_size_request(event_box_.get(),
(...skipping 10 matching lines...) Expand all
1810 G_CALLBACK(OnRealizeThunk), this); 1809 G_CALLBACK(OnRealizeThunk), this);
1811 1810
1812 image_.Own(gtk_image_new()); 1811 image_.Own(gtk_image_new());
1813 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get()); 1812 gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
1814 1813
1815 const Extension* extension = owner->browser()->profile()-> 1814 const Extension* extension = owner->browser()->profile()->
1816 GetExtensionService()->GetExtensionById(page_action->extension_id(), 1815 GetExtensionService()->GetExtensionById(page_action->extension_id(),
1817 false); 1816 false);
1818 DCHECK(extension); 1817 DCHECK(extension);
1819 1818
1820 // Load all the icons declared in the manifest. This is the contents of the 1819 icon_factory_.reset(new ExtensionActionIconFactory(extension, this));
1821 // icons array, plus the default_icon property, if any.
1822 std::vector<std::string> icon_paths(*page_action->icon_paths());
1823 if (!page_action_->default_icon_path().empty())
1824 icon_paths.push_back(page_action_->default_icon_path());
1825
1826 for (std::vector<std::string>::iterator iter = icon_paths.begin();
1827 iter != icon_paths.end(); ++iter) {
1828 tracker_.LoadImage(extension, extension->GetResource(*iter),
1829 gfx::Size(Extension::kPageActionIconMaxSize,
1830 Extension::kPageActionIconMaxSize),
1831 ImageLoadingTracker::DONT_CACHE);
1832 }
1833 1820
1834 // We set the owner last of all so that we can determine whether we are in 1821 // We set the owner last of all so that we can determine whether we are in
1835 // the process of initializing this class or not. 1822 // the process of initializing this class or not.
1836 owner_ = owner; 1823 owner_ = owner;
1837 } 1824 }
1838 1825
1839 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() { 1826 LocationBarViewGtk::PageActionViewGtk::~PageActionViewGtk() {
1840 DisconnectPageActionAccelerator(); 1827 DisconnectPageActionAccelerator();
1841 1828
1842 image_.Destroy(); 1829 image_.Destroy();
(...skipping 12 matching lines...) Expand all
1855 current_url_ = url; 1842 current_url_ = url;
1856 1843
1857 bool visible = contents && 1844 bool visible = contents &&
1858 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_)); 1845 (preview_enabled_ || page_action_->GetIsVisible(current_tab_id_));
1859 if (visible) { 1846 if (visible) {
1860 // Set the tooltip. 1847 // Set the tooltip.
1861 gtk_widget_set_tooltip_text(event_box_.get(), 1848 gtk_widget_set_tooltip_text(event_box_.get(),
1862 page_action_->GetTitle(current_tab_id_).c_str()); 1849 page_action_->GetTitle(current_tab_id_).c_str());
1863 1850
1864 // Set the image. 1851 // Set the image.
1865 gfx::Image icon = page_action_->GetIcon(current_tab_id_); 1852 gfx::Image icon =
1853 page_action_->GetIcon(current_tab_id_, icon_factory_.get());
1866 if (!icon.IsEmpty()) { 1854 if (!icon.IsEmpty()) {
1867 GdkPixbuf* pixbuf = icon.ToGdkPixbuf(); 1855 GdkPixbuf* pixbuf = icon.ToGdkPixbuf();
1868 DCHECK(pixbuf); 1856 DCHECK(pixbuf);
1869 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf); 1857 gtk_image_set_from_pixbuf(GTK_IMAGE(image_.get()), pixbuf);
1870 } 1858 }
1871 } 1859 }
1872 1860
1873 bool old_visible = IsVisible(); 1861 bool old_visible = IsVisible();
1874 if (visible) 1862 if (visible)
1875 gtk_widget_show_all(event_box_.get()); 1863 gtk_widget_show_all(event_box_.get());
1876 else 1864 else
1877 gtk_widget_hide_all(event_box_.get()); 1865 gtk_widget_hide_all(event_box_.get());
1878 1866
1879 if (visible != old_visible) { 1867 if (visible != old_visible) {
1880 content::NotificationService::current()->Notify( 1868 content::NotificationService::current()->Notify(
1881 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED, 1869 chrome::NOTIFICATION_EXTENSION_PAGE_ACTION_VISIBILITY_CHANGED,
1882 content::Source<ExtensionAction>(page_action_), 1870 content::Source<ExtensionAction>(page_action_),
1883 content::Details<WebContents>(contents)); 1871 content::Details<WebContents>(contents));
1884 } 1872 }
1885 } 1873 }
1886 1874
1887 void LocationBarViewGtk::PageActionViewGtk::OnImageLoaded( 1875 void LocationBarViewGtk::PageActionViewGtk::OnIconUpdated() {
1888 const gfx::Image& image,
1889 const std::string& extension_id,
1890 int index) {
1891 // We loaded icons()->size() icons, plus one extra if the page action had
1892 // a default icon.
1893 int total_icons = static_cast<int>(page_action_->icon_paths()->size());
1894 if (!page_action_->default_icon_path().empty())
1895 total_icons++;
1896 DCHECK(index < total_icons);
1897
1898 // Map the index of the loaded image back to its name. If we ever get an
1899 // index greater than the number of icons, it must be the default icon.
1900 if (index < static_cast<int>(page_action_->icon_paths()->size()))
1901 page_action_->CacheIcon(page_action_->icon_paths()->at(index), image);
1902 else
1903 page_action_->CacheIcon(page_action_->default_icon_path(), image);
1904
1905 // If we have no owner, that means this class is still being constructed. 1876 // If we have no owner, that means this class is still being constructed.
1906 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL; 1877 TabContents* tab_contents = owner_ ? owner_->GetTabContents() : NULL;
1907 if (tab_contents) 1878 if (tab_contents)
1908 UpdateVisibility(tab_contents->web_contents(), current_url_); 1879 UpdateVisibility(tab_contents->web_contents(), current_url_);
1909 } 1880 }
1910 1881
1911 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() { 1882 void LocationBarViewGtk::PageActionViewGtk::TestActivatePageAction() {
1912 GdkEventButton event = {}; 1883 GdkEventButton event = {};
1913 event.button = 1; 1884 event.button = 1;
1914 OnButtonPressed(widget(), &event); 1885 OnButtonPressed(widget(), &event);
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after
2114 } 2085 }
2115 2086
2116 void LocationBarViewGtk::PageActionViewGtk::InspectPopup( 2087 void LocationBarViewGtk::PageActionViewGtk::InspectPopup(
2117 ExtensionAction* action) { 2088 ExtensionAction* action) {
2118 ExtensionPopupGtk::Show( 2089 ExtensionPopupGtk::Show(
2119 action->GetPopupUrl(current_tab_id_), 2090 action->GetPopupUrl(current_tab_id_),
2120 owner_->browser_, 2091 owner_->browser_,
2121 event_box_.get(), 2092 event_box_.get(),
2122 ExtensionPopupGtk::SHOW_AND_INSPECT); 2093 ExtensionPopupGtk::SHOW_AND_INSPECT);
2123 } 2094 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698