OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" | 5 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "chrome/browser/cocoa/browser_window_controller.h" | 8 #import "chrome/browser/cocoa/browser_window_controller.h" |
9 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" | 9 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_cell.h" |
10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.h" | 10 #import "chrome/browser/cocoa/location_bar/autocomplete_text_field_editor.h" |
(...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 | 213 |
214 AutocompleteTextFieldCell* cell = [self cell]; | 214 AutocompleteTextFieldCell* cell = [self cell]; |
215 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:fieldBounds]) | 215 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:fieldBounds]) |
216 [self addCursorRect:[icon rect] cursor:[NSCursor arrowCursor]]; | 216 [self addCursorRect:[icon rect] cursor:[NSCursor arrowCursor]]; |
217 | 217 |
218 // TODO(shess): This needs to traverse the LocationBarDecorations | 218 // TODO(shess): This needs to traverse the LocationBarDecorations |
219 // and put up a cursor for them, too. Except for the keyword-search | 219 // and put up a cursor for them, too. Except for the keyword-search |
220 // stuff? Sigh. | 220 // stuff? Sigh. |
221 } | 221 } |
222 | 222 |
| 223 - (void)addToolTip:(NSString*)tooltip forRect:(NSRect)aRect { |
| 224 [currentToolTips_ addObject:tooltip]; |
| 225 [self addToolTipRect:aRect owner:tooltip userData:nil]; |
| 226 } |
| 227 |
223 // TODO(shess): -resetFieldEditorFrameIfNeeded is the place where | 228 // TODO(shess): -resetFieldEditorFrameIfNeeded is the place where |
224 // changes to the cell layout should be flushed. LocationBarViewMac | 229 // changes to the cell layout should be flushed. LocationBarViewMac |
225 // and ToolbarController are calling this routine directly, and I | 230 // and ToolbarController are calling this routine directly, and I |
226 // think they are probably wrong. | 231 // think they are probably wrong. |
227 // http://crbug.com/40053 | 232 // http://crbug.com/40053 |
228 - (void)updateCursorAndToolTipRects { | 233 - (void)updateCursorAndToolTipRects { |
229 // This will force |resetCursorRects| to be called, as it is not to be called | 234 // This will force |resetCursorRects| to be called, as it is not to be called |
230 // directly. | 235 // directly. |
231 [[self window] invalidateCursorRectsForView:self]; | 236 [[self window] invalidateCursorRectsForView:self]; |
232 | 237 |
233 // |removeAllToolTips| only removes those set on the current NSView, not any | 238 // |removeAllToolTips| only removes those set on the current NSView, not any |
234 // subviews. Unless more tooltips are added to this view, this should suffice | 239 // subviews. Unless more tooltips are added to this view, this should suffice |
235 // in place of managing a set of NSToolTipTag objects. | 240 // in place of managing a set of NSToolTipTag objects. |
236 [self removeAllToolTips]; | 241 [self removeAllToolTips]; |
| 242 |
| 243 // Reload the decoration tooltips. |
237 [currentToolTips_ removeAllObjects]; | 244 [currentToolTips_ removeAllObjects]; |
238 | 245 [[self cell] updateToolTipsInRect:[self bounds] ofView:self]; |
239 AutocompleteTextFieldCell* cell = [self cell]; | |
240 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:[self bounds]]) { | |
241 NSRect iconRect = [icon rect]; | |
242 NSString* tooltip = [icon view]->GetToolTip(); | |
243 if (!tooltip) | |
244 continue; | |
245 | |
246 // -[NSView addToolTipRect:owner:userData] does _not_ retain its |owner:|. | |
247 // Put the string in a collection so it can't be dealloced while in use. | |
248 [currentToolTips_ addObject:tooltip]; | |
249 [self addToolTipRect:iconRect owner:tooltip userData:nil]; | |
250 } | |
251 } | 246 } |
252 | 247 |
253 // NOTE(shess): http://crbug.com/19116 describes a weird bug which | 248 // NOTE(shess): http://crbug.com/19116 describes a weird bug which |
254 // happens when the user runs a Print panel on Leopard. After that, | 249 // happens when the user runs a Print panel on Leopard. After that, |
255 // spurious -controlTextDidBeginEditing notifications are sent when an | 250 // spurious -controlTextDidBeginEditing notifications are sent when an |
256 // NSTextField is firstResponder, even though -currentEditor on that | 251 // NSTextField is firstResponder, even though -currentEditor on that |
257 // field returns nil. That notification caused significant problems | 252 // field returns nil. That notification caused significant problems |
258 // in AutocompleteEditViewMac. -textDidBeginEditing: was NOT being | 253 // in AutocompleteEditViewMac. -textDidBeginEditing: was NOT being |
259 // sent in those cases, so this approach doesn't have the problem. | 254 // sent in those cases, so this approach doesn't have the problem. |
260 - (void)textDidBeginEditing:(NSNotification*)aNotification { | 255 - (void)textDidBeginEditing:(NSNotification*)aNotification { |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 398 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
404 return [dropHandler_ performDragOperation:sender]; | 399 return [dropHandler_ performDragOperation:sender]; |
405 } | 400 } |
406 | 401 |
407 - (NSMenu*)decorationMenuForEvent:(NSEvent*)event { | 402 - (NSMenu*)decorationMenuForEvent:(NSEvent*)event { |
408 AutocompleteTextFieldCell* cell = [self cell]; | 403 AutocompleteTextFieldCell* cell = [self cell]; |
409 return [cell decorationMenuForEvent:event inRect:[self bounds] ofView:self]; | 404 return [cell decorationMenuForEvent:event inRect:[self bounds] ofView:self]; |
410 } | 405 } |
411 | 406 |
412 @end | 407 @end |
OLD | NEW |