From f45d2a74d471efbe10c8f4e7ea044dbb0a351156 Mon Sep 17 00:00:00 2001 From: "xiyuan@chromium.org" Date: Mon, 8 Mar 2010 23:28:35 +0000 Subject: Use web app icon as ICON_BIG for Windows - Add a WindowDelegate::GetWindowAppIcon for BrowserView to expose an icon to use as ICON_BIG; - Add an app_icon_ memeber and accessor functions to TabContents; - Update/Set the app_icon_ of TabContents when web app icon is downloaded for converting a tab to app or for chrome web app shortcuts update (this happens when chrome is opened as an app; - Use the app icon as ICON_BIG in WindowWin::UpdateWindowIcon; BUG=32039 TEST=Verify fix for issue 32039 and also Alt-Tab list on XP/Vista uses big icon. Review URL: http://codereview.chromium.org/668265 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@40962 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/browser.cc | 14 ++++++++------ chrome/browser/tab_contents/tab_contents.cc | 5 +++++ chrome/browser/tab_contents/tab_contents.h | 11 +++++++++++ chrome/browser/views/create_application_shortcut_view.cc | 1 + chrome/browser/views/frame/browser_view.cc | 10 ++++++++++ chrome/browser/views/frame/browser_view.h | 1 + chrome/browser/web_applications/web_app.cc | 1 + views/window/window_delegate.cc | 5 +++++ views/window/window_delegate.h | 4 ++++ views/window/window_win.cc | 7 ++++++- 10 files changed, 52 insertions(+), 7 deletions(-) diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index 344a660..1c75cbc 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -382,12 +382,14 @@ void Browser::OpenApplicationWindow(Profile* profile, const GURL& url, // focus explicitly. tab_contents->view()->SetInitialFocus(); - // Set UPDATE_SHORTCUT as the pending web app action. This action is picked - // up in LoadingStateChanged to schedule a GetApplicationInfo. And when - // the web app info is available, TabContents notifies Browser via - // OnDidGetApplicationInfo, which calls web_app::UpdateShortcutForTabContents - // when it sees UPDATE_SHORTCUT as pending web app action. - browser->pending_web_app_action_ = UPDATE_SHORTCUT; + if (!as_panel) { + // Set UPDATE_SHORTCUT as the pending web app action. This action is picked + // up in LoadingStateChanged to schedule a GetApplicationInfo. And when + // the web app info is available, TabContents notifies Browser via + // OnDidGetApplicationInfo, which calls web_app::UpdateShortcutForTabContents + // when it sees UPDATE_SHORTCUT as pending web app action. + browser->pending_web_app_action_ = UPDATE_SHORTCUT; + } } #if defined(OS_MACOSX) diff --git a/chrome/browser/tab_contents/tab_contents.cc b/chrome/browser/tab_contents/tab_contents.cc index 2815391..db8e51f 100644 --- a/chrome/browser/tab_contents/tab_contents.cc +++ b/chrome/browser/tab_contents/tab_contents.cc @@ -2865,3 +2865,8 @@ void TabContents::SetSuppressMessageBoxes(bool suppress_message_boxes) { void TabContents::set_encoding(const std::string& encoding) { encoding_ = CharacterEncoding::GetCanonicalEncodingNameByAliasName(encoding); } + +void TabContents::SetAppIcon(const SkBitmap& app_icon) { + app_icon_ = app_icon; + NotifyNavigationStateChanged(INVALIDATE_TITLE); +} diff --git a/chrome/browser/tab_contents/tab_contents.h b/chrome/browser/tab_contents/tab_contents.h index 1fae555..0f00ae3 100644 --- a/chrome/browser/tab_contents/tab_contents.h +++ b/chrome/browser/tab_contents/tab_contents.h @@ -263,6 +263,14 @@ class TabContents : public PageNavigator, return web_app_info_; } + SkBitmap app_icon() const { + return app_icon_; + } + + // Sets an app icon associated with TabContents and fires an INVALIDATE_TITLE + // navigation state change to trigger repaint of title. + void SetAppIcon(const SkBitmap& app_icon); + // Internal state ------------------------------------------------------------ // This flag indicates whether the tab contents is currently being @@ -1017,6 +1025,9 @@ class TabContents : public PageNavigator, // Cached web app info data. webkit_glue::WebApplicationInfo web_app_info_; + // Cached web app icon. + SkBitmap app_icon_; + // Data for loading state ---------------------------------------------------- // Indicates whether we're currently loading a resource. diff --git a/chrome/browser/views/create_application_shortcut_view.cc b/chrome/browser/views/create_application_shortcut_view.cc index 81aabec..672f98f 100644 --- a/chrome/browser/views/create_application_shortcut_view.cc +++ b/chrome/browser/views/create_application_shortcut_view.cc @@ -387,6 +387,7 @@ bool CreateApplicationShortcutView::Accept() { shortcut_info_, NULL); + tab_contents_->SetAppIcon(shortcut_info_.favicon); if (tab_contents_->delegate()) tab_contents_->delegate()->ConvertContentsToApplication(tab_contents_); return true; diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index 0948c96..857c656 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -1387,6 +1387,16 @@ bool BrowserView::ShouldShowWindowTitle() const { return browser_->SupportsWindowFeature(Browser::FEATURE_TITLEBAR); } +SkBitmap BrowserView::GetWindowAppIcon() { + if (browser_->type() & Browser::TYPE_APP) { + TabContents* contents = browser_->GetSelectedTabContents(); + if (contents && !contents->app_icon().isNull()) + return contents->app_icon(); + } + + return GetWindowIcon(); +} + SkBitmap BrowserView::GetWindowIcon() { if (browser_->type() & Browser::TYPE_APP) return browser_->GetCurrentPageIcon(); diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index e683fdf..f29f810 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -352,6 +352,7 @@ class BrowserView : public BrowserBubbleHost, virtual std::wstring GetWindowTitle() const; virtual views::View* GetInitiallyFocusedView(); virtual bool ShouldShowWindowTitle() const; + virtual SkBitmap GetWindowAppIcon(); virtual SkBitmap GetWindowIcon(); virtual bool ShouldShowWindowIcon() const; virtual bool ExecuteWindowsCommand(int command_id); diff --git a/chrome/browser/web_applications/web_app.cc b/chrome/browser/web_applications/web_app.cc index b4ec742..0a9f582 100644 --- a/chrome/browser/web_applications/web_app.cc +++ b/chrome/browser/web_applications/web_app.cc @@ -520,6 +520,7 @@ void UpdateShortcutWorker::OnIconDownloaded(int download_id, if (!errored && !image.isNull()) { // Update icon with download image and update shortcut. shortcut_info_.favicon = image; + tab_contents_->SetAppIcon(image); UpdateShortcuts(); } else { // Try the next icon otherwise. diff --git a/views/window/window_delegate.cc b/views/window/window_delegate.cc index 4ac4d80..c909739 100644 --- a/views/window/window_delegate.cc +++ b/views/window/window_delegate.cc @@ -17,6 +17,11 @@ WindowDelegate::~WindowDelegate() { ReleaseWindow(); } +SkBitmap WindowDelegate::GetWindowAppIcon() { + // Use the window icon as app icon by default. + return GetWindowIcon(); +} + // Returns the icon to be displayed in the window. SkBitmap WindowDelegate::GetWindowIcon() { return SkBitmap(); diff --git a/views/window/window_delegate.h b/views/window/window_delegate.h index 7521b27..a5a3e24 100644 --- a/views/window/window_delegate.h +++ b/views/window/window_delegate.h @@ -68,6 +68,10 @@ class WindowDelegate { return true; } + // Returns the app icon for the window. On Windows, this is the ICON_BIG used + // in Alt-Tab list and Win7's taskbar. + virtual SkBitmap GetWindowAppIcon(); + // Returns the icon to be displayed in the window. virtual SkBitmap GetWindowIcon(); diff --git a/views/window/window_win.cc b/views/window/window_win.cc index 40781a8..635aedb 100644 --- a/views/window/window_win.cc +++ b/views/window/window_win.cc @@ -427,7 +427,12 @@ void WindowWin::UpdateWindowIcon() { reinterpret_cast(windows_icon))); if (old_icon) DestroyIcon(old_icon); - old_icon = reinterpret_cast( + } + + icon = window_delegate_->GetWindowAppIcon(); + if (!icon.isNull()) { + HICON windows_icon = IconUtil::CreateHICONFromSkBitmap(icon); + HICON old_icon = reinterpret_cast( SendMessage(GetNativeView(), WM_SETICON, ICON_BIG, reinterpret_cast(windows_icon))); if (old_icon) -- cgit v1.1