diff options
author | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 18:05:31 +0000 |
---|---|---|
committer | thakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-10-15 18:05:31 +0000 |
commit | 86a6ec39a818dc47975c6b0042d80acdfdb70a66 (patch) | |
tree | 5b9cdc364b53af188f326e57aabad95dee752675 /chrome/browser/cocoa/find_bar_cocoa_controller.mm | |
parent | 570f328ddb63301935e22cfa2e61564d595e0288 (diff) | |
download | chromium_src-86a6ec39a818dc47975c6b0042d80acdfdb70a66.zip chromium_src-86a6ec39a818dc47975c6b0042d80acdfdb70a66.tar.gz chromium_src-86a6ec39a818dc47975c6b0042d80acdfdb70a66.tar.bz2 |
Update search state when search text is updated through find pasteboard.
BUG=none
TEST=
*Search for something. Switch to textedit, search for something else. Switch back to chrome. The outdated "x of y" text should be invisble in the find bar, but the prev/next find result buttons should be enabled. Hit enter. Pages should be searched, "x of y " text should return.
* Open a findbar, search for something. Open new chrome window, hit cmd-f. findbar in new window should contain the text you searched for in the last window.
Review URL: http://codereview.chromium.org/267022
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@29146 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/cocoa/find_bar_cocoa_controller.mm')
-rw-r--r-- | chrome/browser/cocoa/find_bar_cocoa_controller.mm | 35 |
1 files changed, 32 insertions, 3 deletions
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm index 9f4a62b..995f29c 100644 --- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm +++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm @@ -30,6 +30,10 @@ static float kFindBarCloseDuration = 0.15; - (void)setFindBarFrame:(NSRect)endFrame animate:(BOOL)animate duration:(float)duration; + +// Optionally stops the current search, puts |text| into the find bar, and +// enables the buttons, but doesn't start a new search for |text|. +- (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch; @end @implementation FindBarCocoaController @@ -61,6 +65,11 @@ static float kFindBarCloseDuration = 0.15; - (void)awakeFromNib { [findBarView_ setFrame:[self hiddenFindBarFrame]]; + + // Stopping the search requires a findbar controller, which isn't valid yet + // during setup. Furthermore, there is no active search yet anyway. + [self prepopulateText:[[FindPasteboard sharedInstance] findText] + stopSearch:NO]; } - (IBAction)close:(id)sender { @@ -83,7 +92,8 @@ static float kFindBarCloseDuration = 0.15; } - (void)findPboardUpdated:(NSNotification*)notification { - [self setFindText:[[FindPasteboard sharedInstance] findText]]; + [self prepopulateText:[[FindPasteboard sharedInstance] findText] + stopSearch:YES]; } // Positions the find bar container view in the correct location based on the @@ -143,9 +153,8 @@ static float kFindBarCloseDuration = 0.15; if ([event modifierFlags] & NSShiftKeyMask) [previousButton_ performClick:nil]; - else { + else [nextButton_ performClick:nil]; - } return YES; } else if (command == @selector(pageUp:) || @@ -345,4 +354,24 @@ static float kFindBarCloseDuration = 0.15; [currentAnimation_ startAnimation]; } +- (void)prepopulateText:(NSString*)text stopSearch:(BOOL)stopSearch{ + [self setFindText:text]; + + // End the find session, hide the "x of y" text and disable the + // buttons, but do not close the find bar or raise the window here. + if (stopSearch && findBarBridge_) { + TabContents* contents = + findBarBridge_->GetFindBarController()->tab_contents(); + if (contents) { + contents->StopFinding(true); + findBarBridge_->ClearResults(contents->find_result()); + } + } + + // Has to happen after |ClearResults()| above. + BOOL buttonsEnabled = [text length] > 0 ? YES : NO; + [previousButton_ setEnabled:buttonsEnabled]; + [nextButton_ setEnabled:buttonsEnabled]; +} + @end |