Commit 15fa9ef8 authored by jennb@chromium.org's avatar jennb@chromium.org

Change panels to use gfx::Image instead of SkBitmap for favicon.

Completes a TODO added in r149891.

BUG=None
TEST=open panels and verify favicons look correct


Review URL: https://chromiumcodereview.appspot.com/10827259

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@151668 0039d316-1c4b-4281-b951-d872f2087c98
parent 0a4494f3
......@@ -570,7 +570,8 @@ string16 TaskManagerPanelResource::GetProfileName() const {
}
gfx::ImageSkia TaskManagerPanelResource::GetIcon() const {
return panel_->GetCurrentPageIcon();
gfx::Image icon = panel_->GetCurrentPageIcon();
return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
}
WebContents* TaskManagerPanelResource::GetWebContents() const {
......
......@@ -4,12 +4,15 @@
#include "chrome/browser/ui/panels/old_panel.h"
#include "chrome/browser/favicon/favicon_tab_helper.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/panels/panel_browser_window.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "chrome/browser/ui/browser_tabstrip.h"
#include "chrome/browser/ui/tab_contents/tab_contents.h"
#include "ui/gfx/image/image.h"
OldPanel::OldPanel(Browser* browser,
const gfx::Size& min_size, const gfx::Size& max_size)
......@@ -58,6 +61,9 @@ void OldPanel::ExecuteCommandWithDisposition(
chrome::ExecuteCommandWithDisposition(browser_, id, disposition);
}
SkBitmap OldPanel::GetCurrentPageIcon() const {
return browser_->GetCurrentPageIcon();
gfx::Image OldPanel::GetCurrentPageIcon() const {
// Browser has not been changed to return SkBitmap yet so we get the favicon
// directly rather than use browser_->GetCurrentPageIcon().
TabContents* contents = chrome::GetActiveTabContents(browser_);
return contents ? contents->favicon_tab_helper()->GetFavicon() : gfx::Image();
}
......@@ -30,7 +30,7 @@ class OldPanel : public Panel {
virtual void ExecuteCommandWithDisposition(
int id,
WindowOpenDisposition disposition) OVERRIDE;
virtual SkBitmap GetCurrentPageIcon() const OVERRIDE;
virtual gfx::Image GetCurrentPageIcon() const OVERRIDE;
private:
Browser* browser_; // Weak pointer. Owned by native panel.
......
......@@ -31,7 +31,7 @@
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/user_metrics.h"
#include "content/public/browser/web_contents.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
using content::RenderViewHost;
......@@ -750,7 +750,7 @@ void Panel::FormatTitleForDisplay(string16* title) {
}
}
SkBitmap Panel::GetCurrentPageIcon() const {
gfx::Image Panel::GetCurrentPageIcon() const {
return panel_host_->GetPageIcon();
}
......
......@@ -26,7 +26,6 @@ class PanelHost;
class PanelManager;
class PanelStrip;
class Profile;
class SkBitmap;
namespace content {
class WebContents;
......@@ -37,6 +36,10 @@ namespace extensions {
class WindowController;
}
namespace gfx {
class Image;
}
// A platform independent implementation of BaseWindow for Panels.
// This class gets the first crack at all the BaseWindow calls for Panels and
// does one or more of the following:
......@@ -291,7 +294,7 @@ class Panel : public BaseWindow,
string16 GetWindowTitle() const;
// Gets the Favicon of the web contents.
virtual SkBitmap GetCurrentPageIcon() const;
virtual gfx::Image GetCurrentPageIcon() const;
// Updates the title bar to display the current title and icon.
void UpdateTitleBar();
......
......@@ -17,10 +17,10 @@
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/gtk/gtk_compat.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/skia_utils_gtk.h"
namespace {
......@@ -235,15 +235,14 @@ void PanelBrowserTitlebarGtk::UpdateThrobber(
} else {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SkBitmap icon = browser_window_->panel()->GetCurrentPageIcon();
if (icon.empty()) {
gfx::Image icon = browser_window_->panel()->GetCurrentPageIcon();
if (icon.IsEmpty()) {
// Fallback to the Chromium icon if the page has no icon.
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_),
rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf());
} else {
GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon);
GdkPixbuf* icon_pixbuf = icon.ToGdkPixbuf();
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf);
g_object_unref(icon_pixbuf);
}
throbber_.Reset();
......
......@@ -27,7 +27,7 @@
#include "ui/gfx/image/image.h"
#include "ipc/ipc_message.h"
#include "ipc/ipc_message_macros.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/rect.h"
using content::UserMetricsAction;
......@@ -66,10 +66,9 @@ void PanelHost::DestroyWebContents() {
web_contents_.reset();
}
SkBitmap PanelHost::GetPageIcon() const {
// TODO: Make this function return gfx::Image.
gfx::Image PanelHost::GetPageIcon() const {
return favicon_tab_helper_.get() ?
favicon_tab_helper_->GetFavicon().AsBitmap() : SkBitmap();
favicon_tab_helper_->GetFavicon() : gfx::Image();
}
void PanelHost::NavigationStateChanged(const content::WebContents* source,
......
......@@ -27,6 +27,7 @@ class WindowController;
}
namespace gfx {
class Image;
class Rect;
}
......@@ -44,7 +45,7 @@ class PanelHost : public content::WebContentsDelegate,
void DestroyWebContents();
// Returns the icon for the current page.
SkBitmap GetPageIcon() const;
gfx::Image GetPageIcon() const;
// content::WebContentsDelegate overrides.
virtual void NavigationStateChanged(const content::WebContents* source,
......
......@@ -13,10 +13,10 @@
#include "content/public/browser/web_contents.h"
#include "grit/generated_resources.h"
#include "grit/theme_resources.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "ui/base/gtk/gtk_compat.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/skia_utils_gtk.h"
namespace {
......@@ -216,15 +216,13 @@ void PanelTitlebarGtk::UpdateThrobber(
} else {
ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
SkBitmap icon = panel_gtk_->panel()->GetCurrentPageIcon();
if (icon.empty()) {
gfx::Image icon = panel_gtk_->panel()->GetCurrentPageIcon();
if (icon.IsEmpty()) {
// Fallback to the Chromium icon if the page has no icon.
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_),
rb.GetNativeImageNamed(IDR_PRODUCT_LOGO_16).ToGdkPixbuf());
} else {
GdkPixbuf* icon_pixbuf = gfx::GdkPixbufFromSkBitmap(icon);
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon_pixbuf);
g_object_unref(icon_pixbuf);
gtk_image_set_from_pixbuf(GTK_IMAGE(icon_), icon.ToGdkPixbuf());
}
throbber_.Reset();
......
......@@ -13,6 +13,7 @@
#include "chrome/browser/ui/panels/panel_manager.h"
#include "content/public/browser/render_view_host.h"
#include "content/public/browser/render_widget_host_view.h"
#include "ui/gfx/image/image.h"
#include "ui/gfx/path.h"
#include "ui/gfx/screen.h"
#include "ui/views/controls/button/image_button.h"
......@@ -504,7 +505,8 @@ string16 PanelView::GetWindowTitle() const {
}
gfx::ImageSkia PanelView::GetWindowIcon() {
return panel_->GetCurrentPageIcon();
gfx::Image icon = panel_->GetCurrentPageIcon();
return icon.IsEmpty() ? gfx::ImageSkia() : *icon.ToImageSkia();
}
void PanelView::DeleteDelegate() {
......
......@@ -38,7 +38,6 @@
#include "content/public/browser/web_contents.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebCursorInfo.h"
#include "grit/ui_resources.h"
#include "skia/ext/skia_utils_mac.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/image/image.h"
#include "webkit/glue/webcursor.h"
......@@ -562,12 +561,10 @@ NSCursor* LoadWebKitCursor(WebKit::WebCursorInfo::Type type) {
icon = [ThrobberView filmstripThrobberViewWithFrame:iconFrame
image:iconImage];
} else {
SkBitmap bitmap = windowShim_->panel()->GetCurrentPageIcon();
gfx::Image page_icon = windowShim_->panel()->GetCurrentPageIcon();
ResourceBundle& rb = ResourceBundle::GetSharedInstance();
NSImage* iconImage = bitmap.isNull() ?
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON) :
gfx::SkBitmapToNSImageWithColorSpace(bitmap,
base::mac::GetSystemColorSpace());
NSImage* iconImage = page_icon.IsEmpty() ?
rb.GetNativeImageNamed(IDR_DEFAULT_FAVICON) : page_icon.ToNSImage();
NSImageView* iconView =
[[[NSImageView alloc] initWithFrame:iconFrame] autorelease];
[iconView setImage:iconImage];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment