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

Side by Side 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 unified diff | 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 »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #import <Cocoa/Cocoa.h> 5 #import <Cocoa/Cocoa.h>
6 6
7 #include "base/auto_reset.h" 7 #include "base/auto_reset.h"
8 #include "base/mac/bundle_locations.h" 8 #include "base/mac/bundle_locations.h"
9 #include "base/strings/sys_string_conversions.h" 9 #include "base/strings/sys_string_conversions.h"
10 #include "chrome/app/vector_icons/vector_icons.h" 10 #include "chrome/app/vector_icons/vector_icons.h"
(...skipping 23 matching lines...) Expand all
34 #include "ui/gfx/image/image_skia_util_mac.h" 34 #include "ui/gfx/image/image_skia_util_mac.h"
35 #include "ui/gfx/paint_vector_icon.h" 35 #include "ui/gfx/paint_vector_icon.h"
36 36
37 using content::NativeWebKeyboardEvent; 37 using content::NativeWebKeyboardEvent;
38 38
39 const float kFindBarOpenDuration = 0.2; 39 const float kFindBarOpenDuration = 0.2;
40 const float kFindBarCloseDuration = 0.15; 40 const float kFindBarCloseDuration = 0.15;
41 const float kFindBarMoveDuration = 0.15; 41 const float kFindBarMoveDuration = 0.15;
42 const float kRightEdgeOffset = 25; 42 const float kRightEdgeOffset = 25;
43 const int kMaxCharacters = 4000; 43 const int kMaxCharacters = 4000;
44 const int kUndefinedResultCount = -1;
44 45
45 @interface FindBarCocoaController (PrivateMethods) <NSAnimationDelegate> 46 @interface FindBarCocoaController (PrivateMethods) <NSAnimationDelegate>
46 // Returns the appropriate frame for a hidden find bar. 47 // Returns the appropriate frame for a hidden find bar.
47 - (NSRect)hiddenFindBarFrame; 48 - (NSRect)hiddenFindBarFrame;
48 49
49 // Animates the given |view| to the given |endFrame| within |duration| seconds. 50 // Animates the given |view| to the given |endFrame| within |duration| seconds.
50 // Returns a new NSViewAnimation. 51 // Returns a new NSViewAnimation.
51 - (NSViewAnimation*)createAnimationForView:(NSView*)view 52 - (NSViewAnimation*)createAnimationForView:(NSView*)view
52 toFrame:(NSRect)endFrame 53 toFrame:(NSRect)endFrame
53 duration:(float)duration; 54 duration:(float)duration;
(...skipping 14 matching lines...) Expand all
68 // Puts |text| into the find bar and enables the buttons, but doesn't start a 69 // Puts |text| into the find bar and enables the buttons, but doesn't start a
69 // new search for |text|. 70 // new search for |text|.
70 - (void)prepopulateText:(NSString*)text; 71 - (void)prepopulateText:(NSString*)text;
71 72
72 // Clears the find results for all tabs in browser associated with this find 73 // Clears the find results for all tabs in browser associated with this find
73 // bar. If |suppressPboardUpdateActions_| is true then the current tab is not 74 // bar. If |suppressPboardUpdateActions_| is true then the current tab is not
74 // cleared. 75 // cleared.
75 - (void)clearFindResultsForCurrentBrowser; 76 - (void)clearFindResultsForCurrentBrowser;
76 77
77 - (BrowserWindowController*)browserWindowController; 78 - (BrowserWindowController*)browserWindowController;
79
80 // Returns the number of matches from the last find results of the active
81 // web contents. Returns kUndefinedResultCount if unable to determine the count.
82 - (int)lastNumberOfMatchesForActiveWebContents;
78 @end 83 @end
79 84
80 @implementation FindBarCocoaController 85 @implementation FindBarCocoaController
81 86
82 @synthesize findBarView = findBarView_; 87 @synthesize findBarView = findBarView_;
83 88
84 - (id)initWithBrowser:(Browser*)browser { 89 - (id)initWithBrowser:(Browser*)browser {
85 if ((self = [super initWithNibName:@"FindBar" 90 if ((self = [super initWithNibName:@"FindBar"
86 bundle:base::mac::FrameworkBundle()])) { 91 bundle:base::mac::FrameworkBundle()])) {
87 [[NSNotificationCenter defaultCenter] 92 [[NSNotificationCenter defaultCenter]
(...skipping 267 matching lines...) Expand 10 before | Expand all | Expand 10 after
355 showHideAnimation_.reset(nil); 360 showHideAnimation_.reset(nil);
356 } 361 }
357 if (moveAnimation_.get()) { 362 if (moveAnimation_.get()) {
358 [moveAnimation_ stopAnimation]; 363 [moveAnimation_ stopAnimation];
359 moveAnimation_.reset(nil); 364 moveAnimation_.reset(nil);
360 } 365 }
361 } 366 }
362 367
363 - (void)setFocusAndSelection { 368 - (void)setFocusAndSelection {
364 [[findText_ window] makeFirstResponder:findText_]; 369 [[findText_ window] makeFirstResponder:findText_];
370 BOOL buttonsEnabled = ([self lastNumberOfMatchesForActiveWebContents] != 0);
365 371
366 // Enable the buttons if the find text is non-empty.
367 BOOL buttonsEnabled = ([[findText_ stringValue] length] > 0) ? YES : NO;
368 [previousButton_ setEnabled:buttonsEnabled]; 372 [previousButton_ setEnabled:buttonsEnabled];
369 [nextButton_ setEnabled:buttonsEnabled]; 373 [nextButton_ setEnabled:buttonsEnabled];
370 } 374 }
371 375
372 - (void)restoreSavedFocus { 376 - (void)restoreSavedFocus {
373 if (!(focusTracker_.get() && 377 if (!(focusTracker_.get() &&
374 [focusTracker_ restoreFocusInWindow:[findBarView_ window]])) { 378 [focusTracker_ restoreFocusInWindow:[findBarView_ window]])) {
375 // Fall back to giving focus to the tab contents. 379 // Fall back to giving focus to the tab contents.
376 findBarBridge_->GetFindBarController()->web_contents()->Focus(); 380 findBarBridge_->GetFindBarController()->web_contents()->Focus();
377 } 381 }
(...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 } 665 }
662 } 666 }
663 667
664 - (BrowserWindowController*)browserWindowController { 668 - (BrowserWindowController*)browserWindowController {
665 if (!browser_) 669 if (!browser_)
666 return nil; 670 return nil;
667 return [BrowserWindowController 671 return [BrowserWindowController
668 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()]; 672 browserWindowControllerForWindow:browser_->window()->GetNativeWindow()];
669 } 673 }
670 674
675 - (int)lastNumberOfMatchesForActiveWebContents {
676 if (!browser_)
677 return kUndefinedResultCount;
678
679 content::WebContents* contents =
680 findBarBridge_->GetFindBarController()->web_contents();
681 FindTabHelper* findTabHelper = FindTabHelper::FromWebContents(contents);
682 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
683 }
671 @end 684 @end
OLDNEW
« 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