diff options
author | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 19:16:43 +0000 |
---|---|---|
committer | shess@chromium.org <shess@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-09-03 19:16:43 +0000 |
commit | c6f2314ae5db5e171dc3e6507f5c1bc32ebdaefd (patch) | |
tree | cbd00c8422c3e86473c3955c15d6fcdea41c325a | |
parent | 8d4de926bd0e8db5ed59d3c42553755e6f560e6e (diff) | |
download | chromium_src-c6f2314ae5db5e171dc3e6507f5c1bc32ebdaefd.zip chromium_src-c6f2314ae5db5e171dc3e6507f5c1bc32ebdaefd.tar.gz chromium_src-c6f2314ae5db5e171dc3e6507f5c1bc32ebdaefd.tar.bz2 |
[Mac] Make I-beam cursor match editing area.
Due to our tweaking of the text area, the I-beam cursor was sometimes
janky.
http://crbug.com/20238
TEST=I don't even know how to really test this.
Review URL: http://codereview.chromium.org/181011
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25346 0039d316-1c4b-4281-b951-d872f2087c98
3 files changed, 22 insertions, 2 deletions
diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.h b/chrome/browser/cocoa/autocomplete_text_field_cell.h index 31fa6b1..9723226 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.h +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.h @@ -56,6 +56,9 @@ - (void)setSearchHintString:(NSString*)aString; - (void)clearKeywordAndHint; +// Return the portion of the cell to show the text cursor over. +- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; + // Return the portion of the cell to use for text display. - (NSRect)textFrameForFrame:(NSRect)cellFrame; diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell.mm b/chrome/browser/cocoa/autocomplete_text_field_cell.mm index d4ef0fe..7125774 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell.mm @@ -191,8 +191,12 @@ const NSInteger kBaselineOffset = 4; [self drawInteriorWithFrame:cellFrame inView:controlView]; } +- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame { + return NSInsetRect(cellFrame, 0, kBaselineAdjust); +} + - (NSRect)textFrameForFrame:(NSRect)cellFrame { - NSRect textFrame(cellFrame); + NSRect textFrame([self textCursorFrameForFrame:cellFrame]); if (hintString_) { DCHECK(!keywordString_); @@ -217,7 +221,7 @@ const NSInteger kBaselineOffset = 4; } } - return NSInsetRect(textFrame, 0, kBaselineAdjust); + return textFrame; } - (void)drawHintWithFrame:(NSRect)cellFrame inView:(NSView*)controlView { @@ -300,4 +304,9 @@ const NSInteger kBaselineOffset = 4; length:selLength]; } +- (void)resetCursorRect:(NSRect)cellFrame inView:(NSView *)controlView { + [super resetCursorRect:[self textCursorFrameForFrame:cellFrame] + inView:controlView]; +} + @end diff --git a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm index bdac762..fc10168 100644 --- a/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm +++ b/chrome/browser/cocoa/autocomplete_text_field_cell_unittest.mm @@ -202,12 +202,16 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) { const NSRect bounds([view_ bounds]); NSRect textFrame; + // The cursor frame should stay the same throughout. + const NSRect cursorFrame([cell textCursorFrameForFrame:bounds]); + // At default settings, everything goes to the text area. textFrame = [cell textFrameForFrame:bounds]; EXPECT_FALSE(NSIsEmptyRect(textFrame)); EXPECT_TRUE(NSContainsRect(bounds, textFrame)); EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); + EXPECT_TRUE(NSEqualRects(cursorFrame, textFrame)); // Small search hint leaves text frame to left. [cell setSearchHintString:@"Search hint"]; @@ -215,6 +219,7 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) { EXPECT_FALSE(NSIsEmptyRect(textFrame)); EXPECT_TRUE(NSContainsRect(bounds, textFrame)); EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); + EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); // Save search-hint's frame for future reference. const CGFloat searchHintMaxX(NSMaxX(textFrame)); @@ -230,6 +235,7 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) { EXPECT_TRUE(NSContainsRect(bounds, textFrame)); EXPECT_LT(NSMaxX(textFrame), NSMaxX(bounds)); EXPECT_LT(NSMaxX(textFrame), searchHintMaxX); + EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); // Keyword search leaves text area to right. [cell setKeywordString:@"Search Engine:"]; @@ -239,6 +245,7 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) { EXPECT_GT(NSMinX(textFrame), NSMinX(bounds)); EXPECT_LT(NSMinX(textFrame), searchHintMaxX); EXPECT_GT(NSMaxX(textFrame), searchHintMaxX); + EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); // Text frame should take everything over again on reset. [cell clearKeywordAndHint]; @@ -247,6 +254,7 @@ TEST_F(AutocompleteTextFieldCellTest, TextFrame) { EXPECT_TRUE(NSContainsRect(bounds, textFrame)); EXPECT_EQ(NSMinX(bounds), NSMinX(textFrame)); EXPECT_EQ(NSMaxX(bounds), NSMaxX(textFrame)); + EXPECT_TRUE(NSContainsRect(cursorFrame, textFrame)); } } // namespace |