summaryrefslogtreecommitdiffstats
path: root/chrome/browser/cocoa/find_bar_cocoa_controller.mm
diff options
context:
space:
mode:
authorthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 22:43:00 +0000
committerthakis@chromium.org <thakis@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-23 22:43:00 +0000
commit6a4f5af29737b966d1cb9e0ab149d7cd0055e5fd (patch)
treef97c014a06b7ce43c372d9dc1946bfad9878f026 /chrome/browser/cocoa/find_bar_cocoa_controller.mm
parent80d5f425f45ccd05330a0d326229e7b5d684a06f (diff)
downloadchromium_src-6a4f5af29737b966d1cb9e0ab149d7cd0055e5fd.zip
chromium_src-6a4f5af29737b966d1cb9e0ab149d7cd0055e5fd.tar.gz
chromium_src-6a4f5af29737b966d1cb9e0ab149d7cd0055e5fd.tar.bz2
Let cmd-f/cmd-g use the findboard.
In a nutshell, this means that the find bars honor the global find pasteboard, which is like a clipboard, but for searches. See the TEST section below for consequences, and also see the bug for more information. BUG=14562 TEST= * Select some text, hit cmd-e, cmd-g. This should search for the marked text and open the find bar if it's not open. * Open TextEdit, hit cmd-f. Enter some text, hit enter. Switch back to Chrome with an open find bar. The find bar should now contain the text you entered in TextEdit * Enter different text into chrome's find bar, switch back to TextEdit. Its find window should now contain the new text. * Search for something in one tab, switch to another tab. It should contain the same text in the findbar as the first one. * Open the findbar, select some text, hit cmd-e. The find bar should be updated with the selected text and this text should be highlighted in the web page. Find bars in other tabs should be updated with that text as well. Review URL: http://codereview.chromium.org/206035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@27015 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.mm32
1 files changed, 25 insertions, 7 deletions
diff --git a/chrome/browser/cocoa/find_bar_cocoa_controller.mm b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
index 35274e9..265483e 100644
--- a/chrome/browser/cocoa/find_bar_cocoa_controller.mm
+++ b/chrome/browser/cocoa/find_bar_cocoa_controller.mm
@@ -12,6 +12,7 @@
#include "chrome/browser/cocoa/browser_window_cocoa.h"
#import "chrome/browser/cocoa/find_bar_cocoa_controller.h"
#import "chrome/browser/cocoa/find_bar_bridge.h"
+#import "chrome/browser/cocoa/find_pasteboard.h"
#import "chrome/browser/cocoa/focus_tracker.h"
#import "chrome/browser/cocoa/tab_strip_controller.h"
#include "chrome/browser/tab_contents/tab_contents.h"
@@ -36,6 +37,11 @@ static float kFindBarCloseDuration = 0.15;
- (id)init {
if ((self = [super initWithNibName:@"FindBar"
bundle:mac_util::MainAppBundle()])) {
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(findPboardUpdated:)
+ name:kFindPasteboardChangedNotification
+ object:[FindPasteboard sharedInstance]];
}
return self;
}
@@ -44,6 +50,7 @@ static float kFindBarCloseDuration = 0.15;
// All animations should be explicitly stopped by the TabContents before a tab
// is closed.
DCHECK(!currentAnimation_.get());
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
[super dealloc];
}
@@ -75,6 +82,10 @@ static float kFindBarCloseDuration = 0.15;
true, false);
}
+- (void)findPboardUpdated:(NSNotification*)notification {
+ [self setFindText:[[FindPasteboard sharedInstance] findText]];
+}
+
// Positions the find bar container view in the correct location based on the
// current state of the window. The find bar container is always positioned one
// pixel above the infobar container. Note that we are using the infobar
@@ -110,14 +121,16 @@ static float kFindBarCloseDuration = 0.15;
if (!tab_contents)
return;
- string16 findText = base::SysNSStringToUTF16([findText_ stringValue]);
- if (findText.length() > 0) {
- tab_contents->StartFinding(findText, true, false);
+ NSString* findText = [findText_ stringValue];
+ [[FindPasteboard sharedInstance] setFindText:findText];
+
+ if ([findText length] > 0) {
+ tab_contents->StartFinding(base::SysNSStringToUTF16(findText), true, false);
} else {
// The textbox is empty so we reset.
tab_contents->StopFinding(true); // true = clear selection on page.
[self updateUIForFindResult:tab_contents->find_result()
- withText:string16()];
+ withText:string16()];
}
}
@@ -210,8 +223,12 @@ static float kFindBarCloseDuration = 0.15;
focusTracker_.reset(nil);
}
-- (void)setFindText:(const string16&)findText {
- [findText_ setStringValue:base::SysUTF16ToNSString(findText)];
+- (void)setFindText:(NSString*)findText {
+ [findText_ setStringValue:findText];
+
+ // Make sure the text in the find bar always ends up in the find pasteboard
+ // (and, via notifications, in the other find bars too).
+ [[FindPasteboard sharedInstance] setFindText:findText];
}
- (void)clearResults:(const FindNotificationDetails&)results {
@@ -266,7 +283,8 @@ static float kFindBarCloseDuration = 0.15;
[resultsLabel_ setFrame:labelFrame];
// TODO(rohitrao): If the search string is too long, then it will overlap with
- // the results label. Fix.
+ // the results label. Fix. Perhaps use the code that fades out the tab titles
+ // if they are too long.
}
- (BOOL)isFindBarVisible {