OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012 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 #ifndef IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_TEXT_FIELD_IOS_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_TEXT_FIELD_IOS_H_ |
| 7 |
| 8 #import <UIKit/UIKit.h> |
| 9 |
| 10 #include "base/mac/scoped_nsobject.h" |
| 11 #include "base/strings/string16.h" |
| 12 |
| 13 @protocol OmniboxTextFieldDelegate<UITextFieldDelegate> |
| 14 |
| 15 @optional |
| 16 // Called when the OmniboxTextField performs a copy operation. Returns YES if |
| 17 // the delegate handled the copy operation itself. If the delegate returns NO, |
| 18 // the field must perform the copy. Some platforms (iOS 4) do not expose an API |
| 19 // that allows the delegate to handle the copy. |
| 20 - (BOOL)onCopy; |
| 21 |
| 22 // Called when the OmniboxTextField performs a 'Copy URL' operation. |
| 23 - (BOOL)onCopyURL; |
| 24 |
| 25 // Returns true if the 'Copy URL' operation can performed (i.e. the text in the |
| 26 // omnibox still reflects the current navigation entry). |
| 27 - (BOOL)canCopyURL; |
| 28 |
| 29 // Called before the OmniboxTextField performs a paste operation. |
| 30 - (void)willPaste; |
| 31 |
| 32 // Called when the backspace button is tapped in the OmniboxTextField. |
| 33 - (void)onDeleteBackward; |
| 34 @end |
| 35 |
| 36 // Enum type specifying the direction of fade animations. |
| 37 typedef enum { |
| 38 OMNIBOX_TEXT_FIELD_FADE_STYLE_IN, |
| 39 OMNIBOX_TEXT_FIELD_FADE_STYLE_OUT |
| 40 } OmniboxTextFieldFadeStyle; |
| 41 |
| 42 // UITextField subclass to allow for adjusting borders. |
| 43 @interface OmniboxTextFieldIOS : UITextField |
| 44 |
| 45 // Initialize the omnibox with the given frame, font, text color, and tint |
| 46 // color. |
| 47 - (instancetype)initWithFrame:(CGRect)frame |
| 48 font:(UIFont*)font |
| 49 textColor:(UIColor*)textColor |
| 50 tintColor:(UIColor*)tintColor NS_DESIGNATED_INITIALIZER; |
| 51 |
| 52 - (instancetype)initWithCoder:(NSCoder*)aDecoder NS_UNAVAILABLE; |
| 53 |
| 54 // Delegate getter and setter. Overridden to use OmniboxTextFieldDelegate |
| 55 // instead of UITextFieldDelegate. |
| 56 - (id<OmniboxTextFieldDelegate>)delegate; |
| 57 - (void)setDelegate:(id<OmniboxTextFieldDelegate>)delegate; |
| 58 |
| 59 // Sets the field's text to |text|. If |userTextLength| is less than the length |
| 60 // of |text|, the excess is displayed as inline autocompleted text. When the |
| 61 // field is not in editing mode, it will respect the text attributes set on |
| 62 // |text|. |
| 63 - (void)setText:(NSAttributedString*)text userTextLength:(size_t)userTextLength; |
| 64 |
| 65 // Sets |chipText_|. |
| 66 - (void)setChipText:(NSString*)text; |
| 67 |
| 68 // Returns YES if the omnibox is currently showing a query refinement chip. |
| 69 - (BOOL)isShowingQueryRefinementChip; |
| 70 |
| 71 // Inserts the given |text| into the text field. The text replaces the current |
| 72 // selection, if there is one; otherwise the text is inserted at the current |
| 73 // cursor position. This method should only be called while editing. |
| 74 - (void)insertTextWhileEditing:(NSString*)text; |
| 75 |
| 76 // Returns the text that is displayed in the field, including any inline |
| 77 // autocomplete text that may be present. |
| 78 - (base::string16)displayedText; |
| 79 |
| 80 // Returns just the portion of |-displayedText| that is inline autocompleted. |
| 81 - (base::string16)autocompleteText; |
| 82 |
| 83 // Returns YES if this field is currently displaying any inline autocompleted |
| 84 // text. |
| 85 - (BOOL)hasAutocompleteText; |
| 86 |
| 87 // Removes any inline autocompleted text that may be present. Any text that is |
| 88 // actually present in the field (not inline autocompleted) remains untouched. |
| 89 - (void)clearAutocompleteText; |
| 90 |
| 91 // On iOS 5.0+, returns any marked text in the field. Marked text is text that |
| 92 // is part of a pending IME composition. It is an error to call this function |
| 93 // on older version of iOS. |
| 94 - (NSString*)markedText; |
| 95 |
| 96 // Display a placeholder image. There is no iOS concept of placeholder images, |
| 97 // circumventing it by using leftView property of UITextField and controlling |
| 98 // its visibility programatically. |
| 99 - (void)showPlaceholderImage; |
| 100 |
| 101 // Hide a placeholder image. There is no iOS concept of placeholder images, |
| 102 // circumventing it by using leftView property of UITextField and controlling |
| 103 // its visibility programatically. |
| 104 - (void)hidePlaceholderImage; |
| 105 |
| 106 // Select which placeholder image to display. |
| 107 - (void)setPlaceholderImage:(int)imageId; |
| 108 |
| 109 // Initial touch on the Omnibox triggers a "pre-edit" state. The current |
| 110 // URL is shown without any insertion point. First character typed replaces |
| 111 // the URL. A second touch turns on the insertion point. |preEditStaticLabel| |
| 112 // is normally hidden. In pre-edit state, |preEditStaticLabel| is unhidden |
| 113 // and displays the URL that will be edited on the second touch. |
| 114 - (void)enterPreEditState; |
| 115 - (void)exitPreEditState; |
| 116 - (BOOL)isPreEditing; |
| 117 |
| 118 // Enable or disable the padlock button. |
| 119 - (void)enableLeftViewButton:(BOOL)isEnabled; |
| 120 |
| 121 // Returns the current selected text range as an NSRange. |
| 122 - (NSRange)selectedNSRange; |
| 123 |
| 124 // Returns the most likely text alignment, Left or Right, based on the best |
| 125 // language match for |self.text|. |
| 126 - (NSTextAlignment)bestTextAlignment; |
| 127 |
| 128 // Checks if direction of the omnibox text changed, and updates the UITextField. |
| 129 // alignment if necessary. |
| 130 - (void)updateTextDirection; |
| 131 |
| 132 // The color of the displayed text. Does not return the UITextField's textColor |
| 133 // property. |
| 134 - (UIColor*)displayedTextColor; |
| 135 |
| 136 // Fade in/out the text and auxillary views depending on |style|. |
| 137 - (void)animateFadeWithStyle:(OmniboxTextFieldFadeStyle)style; |
| 138 // Reverses animations added by |-animateFadeWithStyle:|. |
| 139 - (void)reverseFadeAnimations; |
| 140 // Called when animations added by |-animateFadeWithStyle:| can be removed. |
| 141 - (void)cleanUpFadeAnimations; |
| 142 |
| 143 // Redeclare the delegate property to be the more specific |
| 144 // OmniboxTextFieldDelegate. |
| 145 @property(nonatomic, assign) id<OmniboxTextFieldDelegate> delegate; |
| 146 |
| 147 @property(nonatomic, retain) NSString* preEditText; |
| 148 @property(nonatomic) BOOL clearingPreEditText; |
| 149 @property(nonatomic, retain) UIColor* selectedTextBackgroundColor; |
| 150 @property(nonatomic, retain) UIColor* placeholderTextColor; |
| 151 @property(nonatomic, assign) BOOL incognito; |
| 152 |
| 153 @end |
| 154 |
| 155 // A category for defining new methods that access private ivars. |
| 156 @interface OmniboxTextFieldIOS (TestingUtilities) |
| 157 - (UILabel*)preEditStaticLabel; |
| 158 @end |
| 159 |
| 160 #endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_TEXT_FIELD_IOS_H_ |
OLD | NEW |