Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1683)

Unified Diff: chrome/browser/cocoa/find_pasteboard.mm

Issue 206035: Support the OS X find pasteboard on OS X. (Closed)
Patch Set: foo Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/cocoa/find_pasteboard.h ('k') | chrome/browser/cocoa/find_pasteboard_unittest.mm » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/cocoa/find_pasteboard.mm
diff --git a/chrome/browser/cocoa/find_pasteboard.mm b/chrome/browser/cocoa/find_pasteboard.mm
new file mode 100644
index 0000000000000000000000000000000000000000..0d081d0c2c0679758fe1e5ef3632163172e1a04b
--- /dev/null
+++ b/chrome/browser/cocoa/find_pasteboard.mm
@@ -0,0 +1,82 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#import "chrome/browser/cocoa/find_pasteboard.h"
+
+#include "base/logging.h"
+#include "base/sys_string_conversions.h"
+
+NSString* kFindPasteboardChangedNotification =
+ @"kFindPasteboardChangedNotification_Chrome";
+
+@implementation FindPasteboard
+
++ (FindPasteboard*)sharedInstance {
+ static FindPasteboard* instance = nil;
+ if (!instance) {
+ instance = [[FindPasteboard alloc] init];
+ }
+ return instance;
+}
+
+- (id)init {
+ if ((self = [super init])) {
+ findText_.reset([[NSString alloc] init]);
+
+ // Check if the text in the findboard has changed on app activate.
+ [[NSNotificationCenter defaultCenter]
+ addObserver:self
+ selector:@selector(loadTextFromPasteboard:)
+ name:NSApplicationDidBecomeActiveNotification
+ object:nil];
+ [self loadTextFromPasteboard:nil];
+ }
+ return self;
+}
+
+- (void)dealloc {
+ // Since this is a singleton, this should only be executed in test code.
+ [[NSNotificationCenter defaultCenter] removeObserver:self];
+ [super dealloc];
+}
+
+- (NSPasteboard*)findPboard {
+ return [NSPasteboard pasteboardWithName:NSFindPboard];
+}
+
+- (void)loadTextFromPasteboard:(NSNotification*)notification {
+ NSPasteboard* findPboard = [self findPboard];
+ if ([[findPboard types] containsObject:NSStringPboardType])
+ [self setFindText:[findPboard stringForType:NSStringPboardType]];
+}
+
+- (NSString*)findText {
+ return findText_;
+}
+
+- (void)setFindText:(NSString*)newText {
+ DCHECK(newText);
+ if (!newText)
+ return;
+
+ DCHECK([NSThread isMainThread]);
+
+ BOOL needToSendNotification = ![findText_.get() isEqualToString:newText];
+ if (needToSendNotification) {
+ findText_.reset([newText copy]);
+ NSPasteboard* findPboard = [self findPboard];
+ [findPboard declareTypes:[NSArray arrayWithObject:NSStringPboardType]
+ owner:nil];
+ [findPboard setString:findText_.get() forType:NSStringPboardType];
+ [[NSNotificationCenter defaultCenter]
+ postNotificationName:kFindPasteboardChangedNotification
+ object:self];
+ }
+}
+
+@end
+
+string16 GetFindPboardText() {
+ return base::SysNSStringToUTF16([[FindPasteboard sharedInstance] findText]);
+}
« no previous file with comments | « chrome/browser/cocoa/find_pasteboard.h ('k') | chrome/browser/cocoa/find_pasteboard_unittest.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698