summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 21:14:15 +0000
committerscr@chromium.org <scr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-10-15 21:14:15 +0000
commit74c316dc610f010cf74a8dbe8423997fdf549dfb (patch)
tree619475f96396d8aa5d9ee5d9ce51e4ce5da5ffbb
parent6a61700060ce63e72b9b6dc70c2672c71d9e5438 (diff)
downloadchromium_src-74c316dc610f010cf74a8dbe8423997fdf549dfb.zip
chromium_src-74c316dc610f010cf74a8dbe8423997fdf549dfb.tar.gz
chromium_src-74c316dc610f010cf74a8dbe8423997fdf549dfb.tar.bz2
[Mac] Added Support for DIM AutoComplete Match Classification specifiers.
BUG=55418 TEST=Type "yout" in the autocomplete and look for "youtube" in the autocomplete popup. The letters "yout" should be dimmer than the suggested letters "ube" which should be "normal". Review URL: http://codereview.chromium.org/3750008 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@62791 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.h2
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac.mm26
-rw-r--r--chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm39
3 files changed, 49 insertions, 18 deletions
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
index 8e2de8c..885522b 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.h
@@ -97,7 +97,7 @@ class AutocompletePopupViewMac : public AutocompletePopupView {
static NSMutableAttributedString* DecorateMatchedString(
const std::wstring &matchString,
const AutocompleteMatch::ACMatchClassifications &classifications,
- NSColor* textColor, gfx::Font& font);
+ NSColor* textColor, NSColor* dimTextColor, gfx::Font& font);
// Helper for MatchText() to elide a marked-up string using
// gfx::ElideText() as a model. Modifies |aString| in place.
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
index a6c7bb7..1f255a8 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac.mm
@@ -81,13 +81,12 @@ NSColor* HoveredBackgroundColor() {
static NSColor* ContentTextColor() {
return [NSColor blackColor];
}
+static NSColor* DimContentTextColor() {
+ return [NSColor darkGrayColor];
+}
static NSColor* URLTextColor() {
return [NSColor colorWithCalibratedRed:0.0 green:0.55 blue:0.0 alpha:1.0];
}
-static NSColor* DescriptionTextColor() {
- return [NSColor darkGrayColor];
-}
-
} // namespace
// Helper for MatchText() to allow sharing code between the contents
@@ -96,7 +95,7 @@ static NSColor* DescriptionTextColor() {
NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString(
const std::wstring &matchString,
const AutocompleteMatch::ACMatchClassifications &classifications,
- NSColor* textColor, gfx::Font& font) {
+ NSColor* textColor, NSColor* dimTextColor, gfx::Font& font) {
// Cache for on-demand computation of the bold version of |font|.
NSFont* boldFont = nil;
@@ -133,6 +132,12 @@ NSMutableAttributedString* AutocompletePopupViewMac::DecorateMatchedString(
}
[as addAttribute:NSFontAttributeName value:boldFont range:range];
}
+
+ if (0 != (i->style & ACMatchClassification::DIM)) {
+ [as addAttribute:NSForegroundColorAttributeName
+ value:dimTextColor
+ range:range];
+ }
}
return as;
@@ -181,7 +186,9 @@ NSAttributedString* AutocompletePopupViewMac::MatchText(
NSMutableAttributedString *as =
DecorateMatchedString(match.contents,
match.contents_class,
- ContentTextColor(), font);
+ ContentTextColor(),
+ DimContentTextColor(),
+ font);
// If there is a description, append it, separated from the contents
// with an en dash, and decorated with a distinct color.
@@ -205,9 +212,14 @@ NSAttributedString* AutocompletePopupViewMac::MatchText(
[[[NSAttributedString alloc] initWithString:rawEnDash
attributes:attributes] autorelease];
+ // In Windows, a boolean force_dim is passed as true for the
+ // description. Here, we pass the dim text color for both normal and dim,
+ // to accomplish the same thing.
NSAttributedString* description =
DecorateMatchedString(match.description, match.description_class,
- DescriptionTextColor(), font);
+ DimContentTextColor(),
+ DimContentTextColor(),
+ font);
[as appendAttributedString:enDash];
[as appendAttributedString:description];
diff --git a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
index b6be8dc..3ad4b33 100644
--- a/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
+++ b/chrome/browser/autocomplete/autocomplete_popup_view_mac_unittest.mm
@@ -24,6 +24,7 @@ class AutocompletePopupViewMacTest : public PlatformTest {
// These are here because there is no autorelease pool for the
// constructor.
color_ = [NSColor blackColor];
+ dimColor_ = [NSColor darkGrayColor];
font_ = gfx::Font(
base::SysNSStringToWide([[NSFont userFontOfSize:12] fontName]), 12);
}
@@ -93,6 +94,7 @@ class AutocompletePopupViewMacTest : public PlatformTest {
}
NSColor* color_; // weak
+ NSColor* dimColor_; // weak
gfx::Font font_;
};
@@ -106,7 +108,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringNoMatch) {
NSAttributedString* decorated =
AutocompletePopupViewMac::DecorateMatchedString(
base::SysNSStringToWide(string), classifications,
- color_, font_);
+ color_, dimColor_, font_);
// Result has same characters as the input.
EXPECT_EQ([decorated length], [string length]);
@@ -136,7 +138,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLNoMatch) {
NSAttributedString* decorated =
AutocompletePopupViewMac::DecorateMatchedString(
base::SysNSStringToWide(string), classifications,
- color_, font_);
+ color_, dimColor_, font_);
// Result has same characters as the input.
EXPECT_EQ([decorated length], [string length]);
@@ -154,32 +156,49 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLNoMatch) {
EXPECT_FALSE(RunHasFontTrait(decorated, 0U, NSBoldFontMask));
}
-// Test that DIM doesn't have any impact - true at this time.
+// Test that DIM works as expected.
TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringDimNoMatch) {
NSString* const string = @"This is a test";
+ // Dim "is".
+ const NSUInteger runLength1 = 5, runLength2 = 2, runLength3 = 7;
+ // Make sure nobody messed up the inputs.
+ EXPECT_EQ(runLength1 + runLength2 + runLength3, [string length]);
- // Switch to DIM halfway through.
+ // Push each run onto classifications.
AutocompleteMatch::ACMatchClassifications classifications;
classifications.push_back(
ACMatchClassification(0, ACMatchClassification::NONE));
classifications.push_back(
- ACMatchClassification([string length] / 2, ACMatchClassification::DIM));
+ ACMatchClassification(runLength1, ACMatchClassification::DIM));
+ classifications.push_back(
+ ACMatchClassification(runLength1 + runLength2,
+ ACMatchClassification::NONE));
NSAttributedString* decorated =
AutocompletePopupViewMac::DecorateMatchedString(
base::SysNSStringToWide(string), classifications,
- color_, font_);
+ color_, dimColor_, font_);
// Result has same characters as the input.
EXPECT_EQ([decorated length], [string length]);
EXPECT_TRUE([[decorated string] isEqualToString:string]);
- // Our passed-in color for the entire string.
+ // Should have three font runs, normal, dim, normal.
EXPECT_EQ(RunLengthForAttribute(decorated, 0U,
NSForegroundColorAttributeName),
- [string length]);
+ runLength1);
EXPECT_TRUE(RunHasColor(decorated, 0U, color_));
+ EXPECT_EQ(RunLengthForAttribute(decorated, runLength1,
+ NSForegroundColorAttributeName),
+ runLength2);
+ EXPECT_TRUE(RunHasColor(decorated, runLength1, dimColor_));
+
+ EXPECT_EQ(RunLengthForAttribute(decorated, runLength1 + runLength2,
+ NSForegroundColorAttributeName),
+ runLength3);
+ EXPECT_TRUE(RunHasColor(decorated, runLength1 + runLength2, color_));
+
// An unbolded font for the entire string.
EXPECT_EQ(RunLengthForAttribute(decorated, 0U,
NSFontAttributeName), [string length]);
@@ -208,7 +227,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringMatch) {
NSAttributedString* decorated =
AutocompletePopupViewMac::DecorateMatchedString(
base::SysNSStringToWide(string), classifications,
- color_, font_);
+ color_, dimColor_, font_);
// Result has same characters as the input.
EXPECT_EQ([decorated length], [string length]);
@@ -256,7 +275,7 @@ TEST_F(AutocompletePopupViewMacTest, DecorateMatchedStringURLMatch) {
NSAttributedString* decorated =
AutocompletePopupViewMac::DecorateMatchedString(
base::SysNSStringToWide(string), classifications,
- color_, font_);
+ color_, dimColor_, font_);
// Result has same characters as the input.
EXPECT_EQ([decorated length], [string length]);