diff options
author | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-12 00:18:10 +0000 |
---|---|---|
committer | mirandac@chromium.org <mirandac@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-02-12 00:18:10 +0000 |
commit | f6141cc0a87f6fbb33a993811efa105bca7dc283 (patch) | |
tree | c8093e86713ce4389e6df9bc82542ec65547bd8d /chrome/browser/cocoa | |
parent | fe83079ba0e123456b6c6cf7547ef3be7644a21d (diff) | |
download | chromium_src-f6141cc0a87f6fbb33a993811efa105bca7dc283.zip chromium_src-f6141cc0a87f6fbb33a993811efa105bca7dc283.tar.gz chromium_src-f6141cc0a87f6fbb33a993811efa105bca7dc283.tar.bz2 |
Make fonts not be clipped at large sizes in fonts and languages panel. Also, left-align fonts and vertical-align them so that their baseline lines up with the baseline of their labels.
BUG= 33296
TEST= adjust fonts and languages. name of font size should not be clipped.
Review URL: http://codereview.chromium.org/572046
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@38860 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa')
3 files changed, 77 insertions, 15 deletions
diff --git a/chrome/browser/cocoa/font_language_settings_controller.h b/chrome/browser/cocoa/font_language_settings_controller.h index 3d4dfea..81c5d4b 100644 --- a/chrome/browser/cocoa/font_language_settings_controller.h +++ b/chrome/browser/cocoa/font_language_settings_controller.h @@ -35,16 +35,19 @@ extern NSString* const kCharacterInfoID; // NSNumber value. IBOutlet NSButton* serifButton_; IBOutlet NSTextField* serifField_; scoped_nsobject<NSFont> serifFont_; + IBOutlet NSTextField* serifLabel_; BOOL changedSerif_; IBOutlet NSButton* sansSerifButton_; IBOutlet NSTextField* sansSerifField_; scoped_nsobject<NSFont> sansSerifFont_; + IBOutlet NSTextField* sansSerifLabel_; BOOL changedSansSerif_; IBOutlet NSButton* fixedWidthButton_; IBOutlet NSTextField* fixedWidthField_; scoped_nsobject<NSFont> fixedWidthFont_; + IBOutlet NSTextField* fixedWidthLabel_; BOOL changedFixedWidth_; // The actual preference members. diff --git a/chrome/browser/cocoa/font_language_settings_controller.mm b/chrome/browser/cocoa/font_language_settings_controller.mm index a080658..480653c 100644 --- a/chrome/browser/cocoa/font_language_settings_controller.mm +++ b/chrome/browser/cocoa/font_language_settings_controller.mm @@ -24,7 +24,9 @@ void ShowFontsLanguagesWindow(gfx::NativeWindow window, } @interface FontLanguageSettingsController (Private) -- (void)updateDisplayField:(NSTextField*)field withFont:(NSFont*)font; +- (void)updateDisplayField:(NSTextField*)field + withFont:(NSFont*)font + withLabel:(NSTextField*)label; @end @implementation FontLanguageSettingsController @@ -122,9 +124,15 @@ void ShowFontsLanguagesWindow(gfx::NativeWindow window, [[self window] setDelegate:self]; // Set up the font display. - [self updateDisplayField:serifField_ withFont:serifFont_.get()]; - [self updateDisplayField:sansSerifField_ withFont:sansSerifFont_.get()]; - [self updateDisplayField:fixedWidthField_ withFont:fixedWidthFont_.get()]; + [self updateDisplayField:serifField_ + withFont:serifFont_.get() + withLabel:serifLabel_]; + [self updateDisplayField:sansSerifField_ + withFont:sansSerifFont_.get() + withLabel:sansSerifLabel_]; + [self updateDisplayField:fixedWidthField_ + withFont:fixedWidthFont_.get() + withLabel:fixedWidthLabel_]; } - (void)windowWillClose:(NSNotification*)notif { @@ -159,19 +167,24 @@ void ShowFontsLanguagesWindow(gfx::NativeWindow window, switch (currentType_) { case FontSettingSerif: serifFont_.reset([[fontManager convertFont:serifFont_] retain]); - [self updateDisplayField:serifField_ withFont:serifFont_.get()]; + [self updateDisplayField:serifField_ + withFont:serifFont_.get() + withLabel:serifLabel_]; changedSerif_ = YES; break; case FontSettingSansSerif: sansSerifFont_.reset([[fontManager convertFont:sansSerifFont_] retain]); - [self updateDisplayField:sansSerifField_ withFont:sansSerifFont_.get()]; + [self updateDisplayField:sansSerifField_ + withFont:sansSerifFont_.get() + withLabel:sansSerifLabel_]; changedSansSerif_ = YES; break; case FontSettingFixed: fixedWidthFont_.reset( [[fontManager convertFont:fixedWidthFont_] retain]); [self updateDisplayField:fixedWidthField_ - withFont:fixedWidthFont_.get()]; + withFont:fixedWidthFont_.get() + withLabel:fixedWidthLabel_]; changedFixedWidth_ = YES; break; default: @@ -232,9 +245,25 @@ void ShowFontsLanguagesWindow(gfx::NativeWindow window, #pragma mark Private +// Set the baseline for the font field to be aligned with the baseline +// of its corresponding label. +- (NSPoint)getFontFieldOrigin:(NSTextField*)field + forLabel:(NSTextField*)label { + [field sizeToFit]; + NSRect labelFrame = [label frame]; + NSPoint newOrigin = + [[label superview] convertPoint:labelFrame.origin + toView:[field superview]]; + newOrigin.x = 0; // Left-align font field. + newOrigin.y += [[field font] descender] - [[label font] descender]; + return newOrigin; +} + // This will set the font on |field| to be |font|, and will set the string // value to something human-readable. -- (void)updateDisplayField:(NSTextField*)field withFont:(NSFont*)font { +- (void)updateDisplayField:(NSTextField*)field + withFont:(NSFont*)font + withLabel:(NSTextField*)label { if (!font) { // Something has gone really wrong. Don't make things worse by showing the // user "(null)". @@ -244,6 +273,7 @@ void ShowFontsLanguagesWindow(gfx::NativeWindow window, NSString* value = [NSString stringWithFormat:@"%@, %g", [font fontName], [font pointSize]]; [field setStringValue:value]; + [field setFrameOrigin:[self getFontFieldOrigin:field forLabel:label]]; } @end diff --git a/chrome/browser/cocoa/font_language_settings_controller_unittest.mm b/chrome/browser/cocoa/font_language_settings_controller_unittest.mm index 560c81f..59d41bb 100644 --- a/chrome/browser/cocoa/font_language_settings_controller_unittest.mm +++ b/chrome/browser/cocoa/font_language_settings_controller_unittest.mm @@ -11,8 +11,31 @@ #include "testing/gtest/include/gtest/gtest.h" #include "testing/platform_test.h" +// The FontLanguageSettingsControllerForTest overrides the getFontFieldOrigin +// method to provide a dummy point, so we don't have to actually display the +// window to test the controller. +@interface FontLanguageSettingsControllerForTest : + FontLanguageSettingsController { +} + +- (NSPoint)getFontFieldOrigin:(NSTextField*)field + forLabel:(NSTextField*)label; + +@end + +@implementation FontLanguageSettingsControllerForTest + +- (NSPoint)getFontFieldOrigin:(NSTextField*)field + forLabel:(NSTextField*)label { + return NSMakePoint(10, 10); +} + +@end + @interface FontLanguageSettingsController (Testing) -- (void)updateDisplayField:(NSTextField*)field withFont:(NSFont*)font; +- (void)updateDisplayField:(NSTextField*)field + withFont:(NSFont*)font + withLabel:(NSTextField*)label; @end class FontLanguageSettingsControllerTest : public CocoaTest { @@ -20,7 +43,7 @@ class FontLanguageSettingsControllerTest : public CocoaTest { FontLanguageSettingsControllerTest() { Profile* profile = helper_.profile(); font_controller_.reset( - [[FontLanguageSettingsController alloc] initWithProfile:profile]); + [[FontLanguageSettingsControllerForTest alloc] initWithProfile:profile]); } ~FontLanguageSettingsControllerTest() {} @@ -37,8 +60,11 @@ TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayField) { NSFont* font = [NSFont fontWithName:@"Times-Roman" size:12.0]; scoped_nsobject<NSTextField> field( [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); - - [font_controller_ updateDisplayField:field.get() withFont:font]; + scoped_nsobject<NSTextField> label( + [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); + [font_controller_ updateDisplayField:field.get() + withFont:font + withLabel:label]; ASSERT_TRUE([[font fontName] isEqualToString:[[field font] fontName]]); ASSERT_TRUE([@"Times-Roman, 12" isEqualToString:[field stringValue]]); @@ -47,9 +73,12 @@ TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayField) { TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayFieldNilFont) { scoped_nsobject<NSTextField> field( [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); + scoped_nsobject<NSTextField> label( + [[NSTextField alloc] initWithFrame:NSMakeRect(100, 100, 100, 100)]); [field setStringValue:@"foo"]; - - [font_controller_ updateDisplayField:field.get() withFont:nil]; + [font_controller_ updateDisplayField:field.get() + withFont:nil + withLabel:label]; ASSERT_TRUE([@"foo" isEqualToString:[field stringValue]]); } @@ -57,5 +86,5 @@ TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayFieldNilFont) { TEST_F(FontLanguageSettingsControllerTest, UpdateDisplayFieldNilField) { // Don't crash. NSFont* font = [NSFont fontWithName:@"Times-Roman" size:12.0]; - [font_controller_ updateDisplayField:nil withFont:font]; + [font_controller_ updateDisplayField:nil withFont:font withLabel:nil]; } |