| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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 "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "base/mac_util.h" | 8 #include "base/mac_util.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
| 11 #include "chrome/browser/find_bar_controller.h" | 11 #include "chrome/browser/find_bar_controller.h" |
| 12 #include "chrome/browser/cocoa/browser_window_cocoa.h" | 12 #include "chrome/browser/cocoa/browser_window_cocoa.h" |
| 13 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" | 13 #import "chrome/browser/cocoa/find_bar_cocoa_controller.h" |
| 14 #import "chrome/browser/cocoa/find_bar_bridge.h" | 14 #import "chrome/browser/cocoa/find_bar_bridge.h" |
| 15 #import "chrome/browser/cocoa/focus_tracker.h" | |
| 16 #import "chrome/browser/cocoa/tab_strip_controller.h" | 15 #import "chrome/browser/cocoa/tab_strip_controller.h" |
| 17 #include "chrome/browser/tab_contents/tab_contents.h" | 16 #include "chrome/browser/tab_contents/tab_contents.h" |
| 18 | 17 |
| 19 @implementation FindBarCocoaController | 18 @implementation FindBarCocoaController |
| 20 | 19 |
| 21 - (id)init { | 20 - (id)init { |
| 22 if ((self = [super initWithNibName:@"FindBar" | 21 if ((self = [super initWithNibName:@"FindBar" |
| 23 bundle:mac_util::MainAppBundle()])) { | 22 bundle:mac_util::MainAppBundle()])) { |
| 24 } | 23 } |
| 25 return self; | 24 return self; |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 113 |
| 115 return YES; | 114 return YES; |
| 116 } | 115 } |
| 117 | 116 |
| 118 return NO; | 117 return NO; |
| 119 } | 118 } |
| 120 | 119 |
| 121 // Methods from FindBar | 120 // Methods from FindBar |
| 122 - (void)showFindBar { | 121 - (void)showFindBar { |
| 123 [[self view] setHidden:NO]; | 122 [[self view] setHidden:NO]; |
| 124 | |
| 125 // Save the currently-focused view. |[self view]| is in the view | |
| 126 // hierarchy by now. showFindBar can be called even when the | |
| 127 // findbar is already open, so do not overwrite an already saved | |
| 128 // view. | |
| 129 if (!focusTracker_.get()) | |
| 130 focusTracker_.reset( | |
| 131 [[FocusTracker alloc] initWithWindow:[[self view] window]]); | |
| 132 } | 123 } |
| 133 | 124 |
| 134 - (void)hideFindBar { | 125 - (void)hideFindBar { |
| 135 [[self view] setHidden:YES]; | 126 [[self view] setHidden:YES]; |
| 136 } | 127 } |
| 137 | 128 |
| 138 - (void)setFocusAndSelection { | 129 - (void)setFocusAndSelection { |
| 139 [[findText_ window] makeFirstResponder:findText_]; | 130 [[findText_ window] makeFirstResponder:findText_]; |
| 140 | 131 |
| 141 // Enable the buttons if the find text is non-empty. | 132 // Enable the buttons if the find text is non-empty. |
| 142 BOOL buttonsEnabled = ([[findText_ stringValue] length] > 0) ? YES : NO; | 133 BOOL buttonsEnabled = ([[findText_ stringValue] length] > 0) ? YES : NO; |
| 143 [previousButton_ setEnabled:buttonsEnabled]; | 134 [previousButton_ setEnabled:buttonsEnabled]; |
| 144 [nextButton_ setEnabled:buttonsEnabled]; | 135 [nextButton_ setEnabled:buttonsEnabled]; |
| 145 | 136 |
| 146 } | 137 } |
| 147 | 138 |
| 148 - (void)restoreSavedFocus { | |
| 149 if (!(focusTracker_.get() && | |
| 150 [focusTracker_ restoreFocusInWindow:[[self view] window]])) { | |
| 151 // Fall back to giving focus to the tab contents. | |
| 152 findBarBridge_->GetFindBarController()->tab_contents()->Focus(); | |
| 153 } | |
| 154 focusTracker_.reset(nil); | |
| 155 } | |
| 156 | |
| 157 - (void)setFindText:(const string16&)findText { | 139 - (void)setFindText:(const string16&)findText { |
| 158 [findText_ setStringValue:base::SysUTF16ToNSString(findText)]; | 140 [findText_ setStringValue:base::SysUTF16ToNSString(findText)]; |
| 159 } | 141 } |
| 160 | 142 |
| 161 - (void)clearResults:(const FindNotificationDetails&)results { | 143 - (void)clearResults:(const FindNotificationDetails&)results { |
| 162 // Just call updateUIForFindResult, which will take care of clearing | 144 // Just call updateUIForFindResult, which will take care of clearing |
| 163 // the search text and the results label. | 145 // the search text and the results label. |
| 164 [self updateUIForFindResult:results withText:string16()]; | 146 [self updateUIForFindResult:results withText:string16()]; |
| 165 } | 147 } |
| 166 | 148 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 188 [resultsLabel_ setStringValue:base::SysWideToNSString( | 170 [resultsLabel_ setStringValue:base::SysWideToNSString( |
| 189 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, | 171 l10n_util::GetStringF(IDS_FIND_IN_PAGE_COUNT, |
| 190 IntToWString(result.active_match_ordinal()), | 172 IntToWString(result.active_match_ordinal()), |
| 191 IntToWString(result.number_of_matches())))]; | 173 IntToWString(result.number_of_matches())))]; |
| 192 } else { | 174 } else { |
| 193 // If there was no text entered, we don't show anything in the result count | 175 // If there was no text entered, we don't show anything in the result count |
| 194 // area. | 176 // area. |
| 195 [resultsLabel_ setStringValue:@""]; | 177 [resultsLabel_ setStringValue:@""]; |
| 196 } | 178 } |
| 197 | 179 |
| 198 // If we found any results, reset the focus tracker, so we always | |
| 199 // restore focus to the tab contents. | |
| 200 if (result.number_of_matches() > 0) | |
| 201 focusTracker_.reset(nil); | |
| 202 | |
| 203 // Resize |resultsLabel_| to completely contain its string and right-justify | 180 // Resize |resultsLabel_| to completely contain its string and right-justify |
| 204 // it within |findText_|. sizeToFit may shrink the frame vertically, which we | 181 // it within |findText_|. sizeToFit may shrink the frame vertically, which we |
| 205 // don't want, so we save the original vertical positioning. | 182 // don't want, so we save the original vertical positioning. |
| 206 NSRect labelFrame = [resultsLabel_ frame]; | 183 NSRect labelFrame = [resultsLabel_ frame]; |
| 207 [resultsLabel_ sizeToFit]; | 184 [resultsLabel_ sizeToFit]; |
| 208 labelFrame.size.width = [resultsLabel_ frame].size.width; | 185 labelFrame.size.width = [resultsLabel_ frame].size.width; |
| 209 labelFrame.origin.x = NSMaxX([findText_ frame]) - labelFrame.size.width; | 186 labelFrame.origin.x = NSMaxX([findText_ frame]) - labelFrame.size.width; |
| 210 [resultsLabel_ setFrame:labelFrame]; | 187 [resultsLabel_ setFrame:labelFrame]; |
| 211 | 188 |
| 212 // TODO(rohitrao): If the search string is too long, then it will overlap with | 189 // TODO(rohitrao): If the search string is too long, then it will overlap with |
| 213 // the results label. Fix. | 190 // the results label. Fix. |
| 214 } | 191 } |
| 215 | 192 |
| 216 - (BOOL)isFindBarVisible { | 193 - (BOOL)isFindBarVisible { |
| 217 return [[self view] isHidden] ? NO : YES; | 194 return [[self view] isHidden] ? NO : YES; |
| 218 } | 195 } |
| 219 | 196 |
| 220 @end | 197 @end |
| OLD | NEW |