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 3 // found in the LICENSE file. 4 5 #include <vector> 6 7 #import <Cocoa/Cocoa.h> 8 9 #import "chrome/browser/ui/cocoa/styled_text_field_cell.h" 10 11 @class AutocompleteTextField; 12 class LocationBarDecoration; 13 14 // AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for 15 // certain decorations to be applied to the field. These are the search hint 16 // ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to 17 // search Engine" on the right-hand side), and keyword mode ("Search Engine:" in 18 // a button-like token on the left-hand side). 19 @interface AutocompleteTextFieldCell : StyledTextFieldCell { 20 @private 21 // Decorations which live to the left and right of the text, ordered 22 // from outside in. Decorations are owned by |LocationBarViewMac|. 23 std::vector<LocationBarDecoration*> leftDecorations_; 24 std::vector<LocationBarDecoration*> rightDecorations_; 25 } 26 27 // Clear |leftDecorations_| and |rightDecorations_|. 28 - (void)clearDecorations; 29 30 // Add a new left-side decoration to the right of the existing 31 // left-side decorations. 32 - (void)addLeftDecoration:(LocationBarDecoration*)decoration; 33 34 // Add a new right-side decoration to the left of the existing 35 // right-side decorations. 36 - (void)addRightDecoration:(LocationBarDecoration*)decoration; 37 38 // The width available after accounting for decorations. 39 - (CGFloat)availableWidthInFrame:(const NSRect)frame; 40 41 // Return the frame for |aDecoration| if the cell is in |cellFrame|. 42 // Returns |NSZeroRect| for decorations which are not currently 43 // visible. 44 - (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration 45 inFrame:(NSRect)cellFrame; 46 47 // Find the decoration under the event. |NULL| if |theEvent| is not 48 // over anything. 49 - (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent 50 inRect:(NSRect)cellFrame 51 ofView:(AutocompleteTextField*)field; 52 53 // Return the appropriate menu for any decorations under event. 54 // Returns nil if no menu is present for the decoration, or if the 55 // event is not over a decoration. 56 - (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent 57 inRect:(NSRect)cellFrame 58 ofView:(AutocompleteTextField*)controlView; 59 60 // Called by |AutocompleteTextField| to let page actions intercept 61 // clicks. Returns |YES| if the click has been intercepted. 62 - (BOOL)mouseDown:(NSEvent*)theEvent 63 inRect:(NSRect)cellFrame 64 ofView:(AutocompleteTextField*)controlView; 65 66 // Overridden from StyledTextFieldCell to include decorations adjacent 67 // to the text area which don't handle mouse clicks themselves. 68 // Keyword-search bubble, for instance. 69 - (NSRect)textCursorFrameForFrame:(NSRect)cellFrame; 70 71 // Setup decoration tooltips on |controlView| by calling 72 // |-addToolTip:forRect:|. 73 - (void)updateToolTipsInRect:(NSRect)cellFrame 74 ofView:(AutocompleteTextField*)controlView; 75 76 @end 77