1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <vector>
#import <Cocoa/Cocoa.h>
#include "base/mac/scoped_nsobject.h"
#import "chrome/browser/ui/cocoa/styled_text_field_cell.h"
@class AutocompleteTextField;
class LocationBarDecoration;
// AutocompleteTextFieldCell extends StyledTextFieldCell to provide support for
// certain decorations to be applied to the field. These are the search hint
// ("Type to search" on the right-hand side), the keyword hint ("Press [Tab] to
// search Engine" on the right-hand side), and keyword mode ("Search Engine:" in
// a button-like token on the left-hand side).
@interface AutocompleteTextFieldCell : StyledTextFieldCell {
@private
// Decorations which live before and after the text, ordered
// from outside in. Decorations are owned by |LocationBarViewMac|.
std::vector<LocationBarDecoration*> leadingDecorations_;
std::vector<LocationBarDecoration*> trailingDecorations_;
// The decoration associated to the current dragging session.
LocationBarDecoration* draggedDecoration_;
// Decorations with tracking areas attached to the AutocompleteTextField.
std::vector<LocationBarDecoration*> mouseTrackingDecorations_;
// If YES then the text field will not draw a focus ring or show the insertion
// pointer.
BOOL hideFocusState_;
// YES if this field is shown in a popup window.
BOOL isPopupMode_;
// Retains the NSEvent that caused the controlView to become firstResponder.
base::scoped_nsobject<NSEvent> focusEvent_;
// The coordinate system line width that draws a single pixel line.
CGFloat singlePixelLineWidth_;
}
@property(assign, nonatomic) BOOL isPopupMode;
@property(assign, nonatomic) CGFloat singlePixelLineWidth;
// Line height used for text in this cell.
- (CGFloat)lineHeight;
// Remove all of the tracking areas.
- (void)clearTrackingArea;
// Clear |leftDecorations_| and |rightDecorations_|.
- (void)clearDecorations;
// Add a new leading decoration after the existing
// leading decorations.
- (void)addLeadingDecoration:(LocationBarDecoration*)decoration;
// Add a new trailing decoration before the existing
// trailing decorations.
- (void)addTrailingDecoration:(LocationBarDecoration*)decoration;
// The width available after accounting for decorations.
- (CGFloat)availableWidthInFrame:(const NSRect)frame;
// Return the frame for |aDecoration| if the cell is in |cellFrame|.
// Returns |NSZeroRect| for decorations which are not currently visible.
- (NSRect)frameForDecoration:(const LocationBarDecoration*)aDecoration
inFrame:(NSRect)cellFrame;
// Returns the frame representing the background of |decoration|. Also sets
// |isLeftDecoration| according to whether the decoration appears on the left or
// the right side of the text field.
- (NSRect)backgroundFrameForDecoration:(LocationBarDecoration*)decoration
inFrame:(NSRect)cellFrame
isLeftDecoration:(BOOL*)isLeftDecoration;
// Returns true if it's okay to drop dragged data into the view at the
// given location.
- (BOOL)canDropAtLocationInWindow:(NSPoint)location
ofView:(AutocompleteTextField*)controlView;
// Find the decoration under the location in the window. Return |NULL| if
// there's nothing in the location.
- (LocationBarDecoration*)decorationForLocationInWindow:(NSPoint)location
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)
field;
// Find the decoration under the event. |NULL| if |theEvent| is not
// over anything.
- (LocationBarDecoration*)decorationForEvent:(NSEvent*)theEvent
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)field;
// Return the appropriate menu for any decorations under event.
// Returns nil if no menu is present for the decoration, or if the
// event is not over a decoration.
- (NSMenu*)decorationMenuForEvent:(NSEvent*)theEvent
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView;
// Called by |AutocompleteTextField| to let page actions intercept
// clicks. Returns |YES| if the click has been intercepted.
- (BOOL)mouseDown:(NSEvent*)theEvent
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView;
// Called by |AutocompleteTextField| to pass the mouse up event to the omnibox
// decorations.
- (void)mouseUp:(NSEvent*)theEvent
inRect:(NSRect)cellFrame
ofView:(AutocompleteTextField*)controlView;
// Overridden from StyledTextFieldCell to include decorations adjacent
// to the text area which don't handle mouse clicks themselves.
// Keyword-search bubble, for instance.
- (NSRect)textCursorFrameForFrame:(NSRect)cellFrame;
// Setup decoration tooltips and mouse tracking on |controlView| by calling
// |-addToolTip:forRect:| and |SetupTrackingArea()|.
- (void)updateMouseTrackingAndToolTipsInRect:(NSRect)cellFrame
ofView:
(AutocompleteTextField*)controlView;
// Gets and sets |hideFocusState|. This allows the text field to have focus but
// to appear unfocused.
- (BOOL)hideFocusState;
- (void)setHideFocusState:(BOOL)hideFocusState
ofView:(AutocompleteTextField*)controlView;
// Handles the |event| that caused |controlView| to become firstResponder.
- (void)handleFocusEvent:(NSEvent*)event
ofView:(AutocompleteTextField*)controlView;
@end
// Methods which are either only for testing, or only public for testing.
@interface AutocompleteTextFieldCell (TestingAPI)
// Returns |mouseTrackingDecorations_|.
- (const std::vector<LocationBarDecoration*>&)mouseTrackingDecorations;
@end
|