summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 21:30:50 +0000
committeravi@google.com <avi@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-15 21:30:50 +0000
commit57e68dbaed7d1c9479570de42930727d527cc340 (patch)
treec5f2e796b98b1fb3e911e05f492aeff7ead087b1
parente7e21c8163aa4b71d69d19ba5c9a7d5bfd0d8da9 (diff)
downloadchromium_src-57e68dbaed7d1c9479570de42930727d527cc340.zip
chromium_src-57e68dbaed7d1c9479570de42930727d527cc340.tar.gz
chromium_src-57e68dbaed7d1c9479570de42930727d527cc340.tar.bz2
Explicitly set the window title in the dock when minimizing a window/updating the current tab's title.
http://crbug.com/11982 Review URL: http://codereview.chromium.org/113430 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16187 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/browser.cc5
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.h3
-rw-r--r--chrome/browser/cocoa/browser_window_cocoa.mm34
-rw-r--r--chrome/browser/cocoa/browser_window_controller.mm29
4 files changed, 53 insertions, 18 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc
index 9aaddee..e6b6598 100644
--- a/chrome/browser/browser.cc
+++ b/chrome/browser/browser.cc
@@ -420,12 +420,17 @@ std::wstring Browser::GetCurrentPageTitle() const {
if (title.empty())
title = l10n_util::GetString(IDS_TAB_UNTITLED_TITLE);
+#if defined(OS_WIN) || defined(OS_LINUX)
int string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT;
// Don't append the app name to window titles when we're not displaying a
// distributor logo for the frame.
if (!ShouldShowDistributorLogo())
string_id = IDS_BROWSER_WINDOW_TITLE_FORMAT_NO_LOGO;
return l10n_util::GetStringF(string_id, title);
+#elif defined(OS_MACOSX)
+ // On Mac, we don't want to suffix the page title with the application name.
+ return title;
+#endif
}
// static
diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h
index 9d9e792..ba9ea70 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.h
+++ b/chrome/browser/cocoa/browser_window_cocoa.h
@@ -11,6 +11,7 @@
class Browser;
@class BrowserWindowController;
@class FindBarCocoaController;
+@class NSString;
@class NSWindow;
@class NSMenu;
@@ -80,6 +81,8 @@ class BrowserWindowCocoa : public BrowserWindow,
virtual void DestroyBrowser();
private:
+ void SetMinimizedWindowTitle(NSWindow* window, NSString* title);
+
NSWindow* window_; // weak, owned by controller
Browser* browser_; // weak, owned by controller
BrowserWindowController* controller_; // weak, owns us
diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm
index b09965c..395817b 100644
--- a/chrome/browser/cocoa/browser_window_cocoa.mm
+++ b/chrome/browser/cocoa/browser_window_cocoa.mm
@@ -4,6 +4,8 @@
#include "base/gfx/rect.h"
#include "base/logging.h"
+#include "base/scoped_cftyperef.h"
+#include "base/sys_string_conversions.h"
#include "chrome/browser/bookmarks/bookmark_utils.h"
#include "chrome/browser/cocoa/browser_window_cocoa.h"
#include "chrome/browser/cocoa/browser_window_controller.h"
@@ -13,6 +15,8 @@
#include "chrome/common/pref_service.h"
#include "chrome/browser/profile.h"
+#include <ApplicationServices/ApplicationServices.h>
+
BrowserWindowCocoa::BrowserWindowCocoa(Browser* browser,
BrowserWindowController* controller,
NSWindow* window)
@@ -87,8 +91,15 @@ void BrowserWindowCocoa::SelectedTabToolbarSizeChanged(bool is_animating) {
}
void BrowserWindowCocoa::UpdateTitleBar() {
- // This is used on windows to update the favicon and title in the window
- // icon, which we don't use on the mac.
+ NSString* newTitle =
+ base::SysWideToNSString(browser_->GetCurrentPageTitle());
+
+ // Window menu
+ [NSApp changeWindowsItem:window_ title:newTitle filename:NO];
+
+ // Dock (if applicable)
+ if ([window_ isMiniaturized])
+ SetMinimizedWindowTitle(window_, newTitle);
}
void BrowserWindowCocoa::UpdateLoadingAnimations(bool should_animate) {
@@ -242,3 +253,22 @@ void BrowserWindowCocoa::DestroyBrowser() {
// at this point the controller is dead (autoreleased), so
// make sure we don't try to reference it any more.
}
+
+void BrowserWindowCocoa::SetMinimizedWindowTitle(NSWindow* window,
+ NSString* title) {
+ typedef OSStatus (*CoreDockSetItemTitlePtr)(CGWindowID wid,
+ CFStringRef title);
+
+ scoped_cftyperef<CFBundleRef> hi_services(
+ CFBundleGetBundleWithIdentifier(CFSTR("com.apple.HIServices")));
+ if (!hi_services)
+ return;
+
+ CoreDockSetItemTitlePtr CoreDockSetItemTitle =
+ (CoreDockSetItemTitlePtr)
+ CFBundleGetFunctionPointerForName(hi_services,
+ CFSTR("CoreDockSetItemTitle"));
+
+ if (CoreDockSetItemTitle)
+ CoreDockSetItemTitle([window windowNumber], (CFStringRef)title);
+}
diff --git a/chrome/browser/cocoa/browser_window_controller.mm b/chrome/browser/cocoa/browser_window_controller.mm
index 92f3527..d542151 100644
--- a/chrome/browser/cocoa/browser_window_controller.mm
+++ b/chrome/browser/cocoa/browser_window_controller.mm
@@ -58,6 +58,10 @@ const int kWindowGradientHeight = 24;
- (NSRect)window:(NSWindow *)window
willPositionSheet:(NSWindow *)sheet
usingRect:(NSRect)defaultSheetRect;
+
+// We need to know when the window was miniaturized so we can set the dock
+// title correctly.
+- (void)windowDidMiniaturize:(NSNotification *)notification;
@end
@@ -529,17 +533,10 @@ willPositionSheet:(NSWindow *)sheet
#endif
newContents->DidBecomeSelected();
- // Change the entry in the Window menu to match the title of the
- // currently selected tab. This will create an entry if one does
- // not already exist.
- [NSApp changeWindowsItem:[self window]
- title:base::SysUTF16ToNSString(newContents->GetTitle())
- filename:NO];
-
+ // Update all the UI bits.
+ windowShim_->UpdateTitleBar();
#if 0
// TODO(pinkerton):Update as more things become window-specific
- // Update all the UI bits.
- UpdateTitleBar();
toolbar_->SetProfile(new_contents->profile());
UpdateToolbar(new_contents, true);
UpdateUIForContents(new_contents);
@@ -549,13 +546,9 @@ willPositionSheet:(NSWindow *)sheet
- (void)tabChangedWithContents:(TabContents*)contents
atIndex:(NSInteger)index
loadingOnly:(BOOL)loading {
- // Change the entry in the Window menu to match the new title of the tab,
- // but only if this is the currently selected tab.
- if (index == browser_->tabstrip_model()->selected_index()) {
- [NSApp changeWindowsItem:[self window]
- title:base::SysUTF16ToNSString(contents->GetTitle())
- filename:NO];
- }
+ // Update titles if this is the currently selected tab.
+ if (index == browser_->tabstrip_model()->selected_index())
+ windowShim_->UpdateTitleBar();
}
@end
@@ -659,6 +652,10 @@ willPositionSheet:(NSWindow *)sheet
return defaultSheetRect;
}
+- (void)windowDidMiniaturize:(NSNotification *)notification {
+ windowShim_->UpdateTitleBar();
+}
+
// In addition to the tab strip and content area, which the superview's impl
// takes care of, we need to add the toolbar and bookmark bar to the
// overlay so they draw correctly when dragging out a new window.