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

Unified Diff: chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm

Issue 2928333002: Mac:Dont always enable findbar buttons when restoring focus with search string (Closed)
Patch Set: Use FindNotificationDetails number of matches to determine button enablement. Created 3 years, 5 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/ui/cocoa/find_bar/find_bar_browsertest.mm ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm
diff --git a/chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm b/chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm
index 70013f041d886eb5aa94239a9046d75455f96ab7..cea789c1c0927a83f526498127ea361412a38932 100644
--- a/chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm
+++ b/chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.mm
@@ -41,6 +41,7 @@ const float kFindBarCloseDuration = 0.15;
const float kFindBarMoveDuration = 0.15;
const float kRightEdgeOffset = 25;
const int kMaxCharacters = 4000;
+const int kUndefinedResultCount = -1;
@interface FindBarCocoaController (PrivateMethods) <NSAnimationDelegate>
// Returns the appropriate frame for a hidden find bar.
@@ -75,6 +76,10 @@ const int kMaxCharacters = 4000;
- (void)clearFindResultsForCurrentBrowser;
- (BrowserWindowController*)browserWindowController;
+
+// Returns the number of matches from the last find results of the active
+// web contents. Returns kUndefinedResultCount if unable to determine the count.
+- (int)lastNumberOfMatchesForActiveWebContents;
@end
@implementation FindBarCocoaController
@@ -362,9 +367,8 @@ const int kMaxCharacters = 4000;
- (void)setFocusAndSelection {
[[findText_ window] makeFirstResponder:findText_];
+ BOOL buttonsEnabled = ([self lastNumberOfMatchesForActiveWebContents] != 0);
- // Enable the buttons if the find text is non-empty.
- BOOL buttonsEnabled = ([[findText_ stringValue] length] > 0) ? YES : NO;
[previousButton_ setEnabled:buttonsEnabled];
[nextButton_ setEnabled:buttonsEnabled];
}
@@ -668,4 +672,13 @@ const int kMaxCharacters = 4000;
browserWindowControllerForWindow:browser_->window()->GetNativeWindow()];
}
+- (int)lastNumberOfMatchesForActiveWebContents {
+ if (!browser_)
+ return kUndefinedResultCount;
+
+ content::WebContents* contents =
+ findBarBridge_->GetFindBarController()->web_contents();
+ FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(contents);
+ return findTabHelper->find_result().number_of_matches();
rohitrao (ping after 24h) 2017/07/26 14:55:31 For my own reference, number_of_matches() appears
+}
@end
« no previous file with comments | « chrome/browser/ui/cocoa/find_bar/find_bar_browsertest.mm ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698