summaryrefslogtreecommitdiffstats
path: root/chrome/browser/ui/cocoa
diff options
context:
space:
mode:
authormiu@chromium.org <miu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 23:34:37 +0000
committermiu@chromium.org <miu@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-10-25 23:34:37 +0000
commitef7cb527912d5b37a73e0b43dcd49623bd2ab482 (patch)
treeb5e51b590ddd53e32c63296d50053e1ffcd797a7 /chrome/browser/ui/cocoa
parent0ff08a372f26e388e35d4dc78c6760c6659bab15 (diff)
downloadchromium_src-ef7cb527912d5b37a73e0b43dcd49623bd2ab482.zip
chromium_src-ef7cb527912d5b37a73e0b43dcd49623bd2ab482.tar.gz
chromium_src-ef7cb527912d5b37a73e0b43dcd49623bd2ab482.tar.bz2
Re-land r230914 (tab tooltip strings) with fix for generated_resources.grd issue, per joi@ and tony@.
It turns out adding strings to generated_resources.grd has caused us to reach our limit in the ID key space. Per e-mail thread on chromium-dev@, we decided to make an ID bump in tools/gritsettings/resource_ids, to the starting point for webkit_strings.grd, in order to make room for more strings in generated_resources.grd. TBR=sky,tony Review URL: https://codereview.chromium.org/46043002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@231149 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/ui/cocoa')
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_controller.h2
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_controller.mm5
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm13
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.h5
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm19
-rw-r--r--chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm60
6 files changed, 81 insertions, 23 deletions
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.h b/chrome/browser/ui/cocoa/tabs/tab_controller.h
index ad0a6a1..825b853 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_controller.h
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller.h
@@ -69,6 +69,7 @@ class MenuDelegate;
@property(assign, nonatomic) BOOL app;
@property(assign, nonatomic) BOOL mini;
@property(assign, nonatomic) BOOL pinned;
+@property(assign, nonatomic) NSString* toolTip;
// Note that |-selected| will return YES if the controller is |-active|, too.
// |-setSelected:| affects the selection, while |-setActive:| affects the key
// status/focus of the content.
@@ -115,7 +116,6 @@ class MenuDelegate;
@end
@interface TabController(TestingAPI)
-- (NSString*)toolTip;
- (int)iconCapacity;
- (BOOL)shouldShowIcon;
- (BOOL)shouldShowMediaIndicator;
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_controller.mm
index ff67592..b602e26 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller.mm
@@ -192,7 +192,6 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate {
- (void)setTitle:(NSString*)title {
[titleView_ setStringValue:title];
- [[self view] setToolTip:title];
if ([self mini] && ![self selected]) {
TabView* tabView = static_cast<TabView*>([self view]);
DCHECK([tabView isKindOfClass:[TabView class]]);
@@ -201,6 +200,10 @@ class MenuDelegate : public ui::SimpleMenuModel::Delegate {
[super setTitle:title];
}
+- (void)setToolTip:(NSString*)toolTip {
+ [[self view] setToolTip:toolTip];
+}
+
- (void)setActive:(BOOL)active {
if (active != active_) {
active_ = active;
diff --git a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm
index b530b32..25bafc6 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_controller_unittest.mm
@@ -280,19 +280,6 @@ TEST_F(TabControllerTest, APISelection) {
[[controller view] removeFromSuperview];
}
-// Tests that setting the title of a tab sets the tooltip as well.
-TEST_F(TabControllerTest, ToolTip) {
- NSWindow* window = test_window();
-
- base::scoped_nsobject<TabController> controller([[TabController alloc] init]);
- [[window contentView] addSubview:[controller view]];
-
- EXPECT_TRUE([[controller toolTip] length] == 0);
- NSString *tooltip_string = @"Some text to use as a tab title";
- [controller setTitle:tooltip_string];
- EXPECT_NSEQ(tooltip_string, [controller toolTip]);
-}
-
// Tests setting the |loading| property via code.
TEST_F(TabControllerTest, Loading) {
NSWindow* window = test_window();
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h
index 203502e..86e01bd 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.h
@@ -237,6 +237,11 @@ class WebContents;
@end
+@interface TabStripController(TestingAPI)
+- (void)setTabTitle:(TabController*)tab
+ withContents:(content::WebContents*)contents;
+@end
+
// Returns the parent view to use when showing a sheet for a given web contents.
NSView* GetSheetParentViewForWebContents(content::WebContents* web_contents);
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
index 364a353..b98dc32 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller.mm
@@ -1222,14 +1222,19 @@ NSImage* Overlay(NSImage* ground, NSImage* overlay, CGFloat alpha) {
// Handles setting the title of the tab based on the given |contents|. Uses
// a canned string if |contents| is NULL.
-- (void)setTabTitle:(NSViewController*)tab withContents:(WebContents*)contents {
- NSString* titleString = nil;
+- (void)setTabTitle:(TabController*)tab withContents:(WebContents*)contents {
+ // TODO(miu): Rectify inconsistent tooltip behavior. http://crbug.com/310947
+
+ base::string16 title;
if (contents)
- titleString = base::SysUTF16ToNSString(contents->GetTitle());
- if (![titleString length]) {
- titleString = l10n_util::GetNSString(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED);
- }
- [tab setTitle:titleString];
+ title = contents->GetTitle();
+ if (title.empty())
+ title = l10n_util::GetStringUTF16(IDS_BROWSER_WINDOW_MAC_TAB_UNTITLED);
+ [tab setTitle:base::SysUTF16ToNSString(title)];
+
+ const base::string16& toolTip = chrome::AssembleTabTooltipText(
+ title, chrome::GetTabMediaStateForContents(contents));
+ [tab setToolTip:base::SysUTF16ToNSString(toolTip)];
}
// Called when a notification is received from the model to insert a new tab
diff --git a/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm b/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
index 3ffb531..b8277e7 100644
--- a/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
+++ b/chrome/browser/ui/cocoa/tabs/tab_strip_controller_unittest.mm
@@ -4,7 +4,10 @@
#import <Cocoa/Cocoa.h>
+#include "base/bind_helpers.h"
#include "base/mac/scoped_nsautorelease_pool.h"
+#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/media/media_stream_capture_indicator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/cocoa_profile_test.h"
#import "chrome/browser/ui/cocoa/new_tab_button.h"
@@ -12,10 +15,13 @@
#import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h"
#import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h"
#import "chrome/browser/ui/cocoa/tabs/tab_view.h"
+#include "chrome/browser/ui/tabs/tab_utils.h"
#include "chrome/browser/ui/tabs/test_tab_strip_model_delegate.h"
#include "chrome/test/base/testing_profile.h"
#include "content/public/browser/site_instance.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/common/media_stream_request.h"
+#import "testing/gtest_mac.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "ui/base/test/cocoa_test_event_utils.h"
@@ -174,7 +180,7 @@ TEST_F(TabStripControllerTest, RearrangeTabs) {
// TODO(pinkerton): Implement http://crbug.com/10899
}
-TEST_F(TabStripControllerTest, CorrectToolTipText) {
+TEST_F(TabStripControllerTest, CorrectToolTipMouseHoverBehavior) {
// Set tab 1 tooltip.
TabView* tab1 = CreateTab();
[tab1 setToolTip:@"Tab1"];
@@ -228,6 +234,58 @@ TEST_F(TabStripControllerTest, CorrectToolTipText) {
userData:nil] cStringUsingEncoding:NSASCIIStringEncoding]);
}
+TEST_F(TabStripControllerTest, CorrectTitleAndToolTipTextFromSetTabTitle) {
+ using content::MediaStreamDevice;
+ using content::MediaStreamDevices;
+ using content::MediaStreamUI;
+
+ TabView* const tab = CreateTab();
+ TabController* const tabController = [tab controller];
+ WebContents* const contents = model_->GetActiveWebContents();
+
+ // Initially, tab title and tooltip text are equivalent.
+ EXPECT_EQ(TAB_MEDIA_STATE_NONE,
+ chrome::GetTabMediaStateForContents(contents));
+ [controller_ setTabTitle:tabController withContents:contents];
+ NSString* const baseTitle = [tabController title];
+ EXPECT_NSEQ(baseTitle, [tabController toolTip]);
+
+ // Simulate the start of tab video capture. Tab title remains the same, but
+ // the tooltip text should include the following appended: 1) a line break;
+ // 2) a non-empty string with a localized description of the media state.
+ scoped_refptr<MediaStreamCaptureIndicator> indicator =
+ MediaCaptureDevicesDispatcher::GetInstance()->
+ GetMediaStreamCaptureIndicator();
+ const MediaStreamDevice dummyVideoCaptureDevice(
+ content::MEDIA_TAB_VIDEO_CAPTURE, "dummy_id", "dummy name");
+ scoped_ptr<MediaStreamUI> streamUi(indicator->RegisterMediaStream(
+ contents, MediaStreamDevices(1, dummyVideoCaptureDevice)));
+ streamUi->OnStarted(base::Bind(&base::DoNothing));
+ EXPECT_EQ(TAB_MEDIA_STATE_CAPTURING,
+ chrome::GetTabMediaStateForContents(contents));
+ [controller_ setTabTitle:tabController withContents:contents];
+ EXPECT_NSEQ(baseTitle, [tabController title]);
+ NSString* const toolTipText = [tabController toolTip];
+ if ([baseTitle length] > 0) {
+ EXPECT_TRUE(NSEqualRanges(NSMakeRange(0, [baseTitle length]),
+ [toolTipText rangeOfString:baseTitle]));
+ EXPECT_TRUE(NSEqualRanges(NSMakeRange([baseTitle length], 1),
+ [toolTipText rangeOfString:@"\n"]));
+ EXPECT_LT([baseTitle length] + 1, [toolTipText length]);
+ } else {
+ EXPECT_LT(0u, [toolTipText length]);
+ }
+
+ // Simulate the end of tab video capture. Tab title and tooltip should become
+ // equivalent again.
+ streamUi.reset();
+ EXPECT_EQ(TAB_MEDIA_STATE_NONE,
+ chrome::GetTabMediaStateForContents(contents));
+ [controller_ setTabTitle:tabController withContents:contents];
+ EXPECT_NSEQ(baseTitle, [tabController title]);
+ EXPECT_NSEQ(baseTitle, [tabController toolTip]);
+}
+
TEST_F(TabStripControllerTest, TabCloseDuringDrag) {
TabController* tab;
// The TabController gets autoreleased when created, but is owned by the