OLD | NEW |
1 // Copyright (c) 2009 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/autocomplete_text_field.h" | 5 #import "chrome/browser/cocoa/autocomplete_text_field.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" | 8 #import "chrome/browser/cocoa/autocomplete_text_field_cell.h" |
9 #import "chrome/browser/cocoa/browser_window_controller.h" | 9 #import "chrome/browser/cocoa/browser_window_controller.h" |
10 #import "chrome/browser/cocoa/toolbar_controller.h" | 10 #import "chrome/browser/cocoa/toolbar_controller.h" |
11 #import "chrome/browser/cocoa/url_drop_target.h" | 11 #import "chrome/browser/cocoa/url_drop_target.h" |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 NSEvent* currentEvent = [NSApp currentEvent]; | 108 NSEvent* currentEvent = [NSApp currentEvent]; |
109 if ([currentEvent type] == NSLeftMouseUp && | 109 if ([currentEvent type] == NSLeftMouseUp && |
110 ![editor selectedRange].length) { | 110 ![editor selectedRange].length) { |
111 [editor selectAll:nil]; | 111 [editor selectAll:nil]; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 return; | 115 return; |
116 } | 116 } |
117 | 117 |
118 // If the user clicked the security hint icon in the cell, display the page | 118 // If the user clicked on one of the icons (security icon, Page Actions, etc), |
119 // info window. | 119 // let the icon handle the click. |
120 const NSRect hintIconFrame = [cell securityImageFrameForFrame:bounds]; | |
121 if (NSMouseInRect(location, hintIconFrame, flipped)) { | |
122 [cell onSecurityIconMousePressed]; | |
123 return; | |
124 } | |
125 | |
126 const BOOL ctrlKey = ([theEvent modifierFlags] & NSControlKeyMask) != 0; | 120 const BOOL ctrlKey = ([theEvent modifierFlags] & NSControlKeyMask) != 0; |
127 // If the user left-clicked a Page Action icon, execute its action. | 121 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:bounds]) { |
128 const size_t pageActionCount = [cell pageActionCount]; | 122 if (NSMouseInRect(location, [icon rect], flipped) && !ctrlKey) { |
129 for (size_t i = 0; i < pageActionCount; ++i) { | 123 [icon view]->OnMousePressed([icon rect]); |
130 NSRect pageActionFrame = [cell pageActionFrameForIndex:i inFrame:bounds]; | |
131 if (NSMouseInRect(location, pageActionFrame, flipped) && !ctrlKey) { | |
132 [cell onPageActionMousePressedIn:pageActionFrame forIndex:i]; | |
133 return; | 124 return; |
134 } | 125 } |
135 } | 126 } |
136 | 127 |
137 NSText* editor = [self currentEditor]; | 128 NSText* editor = [self currentEditor]; |
138 | 129 |
139 // We should only be here if we accepted first-responder status and | 130 // We should only be here if we accepted first-responder status and |
140 // have a field editor. If one of these fires, it means some | 131 // have a field editor. If one of these fires, it means some |
141 // assumptions are being broken. | 132 // assumptions are being broken. |
142 DCHECK(editor != nil); | 133 DCHECK(editor != nil); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
197 [undoManager_ removeAllActions]; | 188 [undoManager_ removeAllActions]; |
198 } | 189 } |
199 | 190 |
200 // Show the I-beam cursor unless the mouse is over an image within the field | 191 // Show the I-beam cursor unless the mouse is over an image within the field |
201 // (Page Actions or the security icon) in which case show the arrow cursor. | 192 // (Page Actions or the security icon) in which case show the arrow cursor. |
202 - (void)resetCursorRects { | 193 - (void)resetCursorRects { |
203 NSRect fieldBounds = [self bounds]; | 194 NSRect fieldBounds = [self bounds]; |
204 [self addCursorRect:fieldBounds cursor:[NSCursor IBeamCursor]]; | 195 [self addCursorRect:fieldBounds cursor:[NSCursor IBeamCursor]]; |
205 | 196 |
206 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; | 197 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; |
207 NSRect iconRect = [cell securityImageFrameForFrame:fieldBounds]; | 198 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:fieldBounds]) |
208 [self addCursorRect:iconRect cursor:[NSCursor arrowCursor]]; | 199 [self addCursorRect:[icon rect] cursor:[NSCursor arrowCursor]]; |
209 | |
210 const size_t pageActionCount = [cell pageActionCount]; | |
211 for (size_t i = 0; i < pageActionCount; ++i) { | |
212 iconRect = [cell pageActionFrameForIndex:i inFrame:fieldBounds]; | |
213 [self addCursorRect:iconRect cursor:[NSCursor arrowCursor]]; | |
214 } | |
215 } | 200 } |
216 | 201 |
217 - (void)updateCursorAndToolTipRects { | 202 - (void)updateCursorAndToolTipRects { |
218 // This will force |resetCursorRects| to be called, as it is not to be called | 203 // This will force |resetCursorRects| to be called, as it is not to be called |
219 // directly. | 204 // directly. |
220 [[self window] invalidateCursorRectsForView:self]; | 205 [[self window] invalidateCursorRectsForView:self]; |
221 | 206 |
222 // |removeAllToolTips| only removes those set on the current NSView, not any | 207 // |removeAllToolTips| only removes those set on the current NSView, not any |
223 // subviews. Unless more tooltips are added to this view, this should suffice | 208 // subviews. Unless more tooltips are added to this view, this should suffice |
224 // in place of managing a set of NSToolTipTag objects. | 209 // in place of managing a set of NSToolTipTag objects. |
225 [self removeAllToolTips]; | 210 [self removeAllToolTips]; |
226 [currentToolTips_ removeAllObjects]; | 211 [currentToolTips_ removeAllObjects]; |
227 | 212 |
228 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; | 213 AutocompleteTextFieldCell* cell = [self autocompleteTextFieldCell]; |
229 const size_t pageActionCount = [cell pageActionCount]; | 214 for (AutocompleteTextFieldIcon* icon in [cell layedOutIcons:[self bounds]]) { |
230 for (size_t i = 0; i < pageActionCount; ++i) { | 215 NSRect iconRect = [icon rect]; |
231 NSRect iconRect = [cell pageActionFrameForIndex:i inFrame:[self bounds]]; | 216 NSString* tooltip = [icon view]->GetToolTip(); |
232 NSString* tooltip = [cell pageActionToolTipForIndex:i]; | |
233 if (!tooltip) | 217 if (!tooltip) |
234 continue; | 218 continue; |
235 | 219 |
236 // -[NSView addToolTipRect:owner:userData] does _not_ retain the owner! | 220 // -[NSView addToolTipRect:owner:userData] does _not_ retain its |owner:|. |
237 // Put the string in a collection so it can't be dealloced while in use. | 221 // Put the string in a collection so it can't be dealloced while in use. |
238 [currentToolTips_ addObject:tooltip]; | 222 [currentToolTips_ addObject:tooltip]; |
239 [self addToolTipRect:iconRect owner:tooltip userData:nil]; | 223 [self addToolTipRect:iconRect owner:tooltip userData:nil]; |
240 } | 224 } |
241 } | 225 } |
242 | 226 |
243 // NOTE(shess): http://crbug.com/19116 describes a weird bug which | 227 // NOTE(shess): http://crbug.com/19116 describes a weird bug which |
244 // happens when the user runs a Print panel on Leopard. After that, | 228 // happens when the user runs a Print panel on Leopard. After that, |
245 // spurious -controlTextDidBeginEditing notifications are sent when an | 229 // spurious -controlTextDidBeginEditing notifications are sent when an |
246 // NSTextField is firstResponder, even though -currentEditor on that | 230 // NSTextField is firstResponder, even though -currentEditor on that |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 - (void)draggingExited:(id<NSDraggingInfo>)sender { | 333 - (void)draggingExited:(id<NSDraggingInfo>)sender { |
350 return [dropHandler_ draggingExited:sender]; | 334 return [dropHandler_ draggingExited:sender]; |
351 } | 335 } |
352 | 336 |
353 // (URLDropTarget protocol) | 337 // (URLDropTarget protocol) |
354 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { | 338 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { |
355 return [dropHandler_ performDragOperation:sender]; | 339 return [dropHandler_ performDragOperation:sender]; |
356 } | 340 } |
357 | 341 |
358 @end | 342 @end |
OLD | NEW |