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_VIEW_IOS_H_ |
| 6 #define IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_IOS_H_ |
| 7 |
| 8 #include <UIKit/UIKit.h> |
| 9 |
| 10 #include <memory> |
| 11 |
| 12 #include "base/mac/scoped_nsobject.h" |
| 13 #include "components/omnibox/browser/omnibox_view.h" |
| 14 #include "components/toolbar/toolbar_model.h" |
| 15 #import "ios/chrome/browser/ui/omnibox/omnibox_text_field_ios.h" |
| 16 |
| 17 struct AutocompleteMatch; |
| 18 class AutocompleteResult; |
| 19 @class AutocompleteTextFieldDelegate; |
| 20 class GURL; |
| 21 @class OmniboxTextFieldIOS; |
| 22 @protocol OmniboxPopupPositioner; |
| 23 class WebOmniboxEditController; |
| 24 class OmniboxPopupViewIOS; |
| 25 @protocol PreloadProvider; |
| 26 |
| 27 namespace ios { |
| 28 class ChromeBrowserState; |
| 29 } |
| 30 |
| 31 // iOS implementation of OmniBoxView. Wraps a UITextField and |
| 32 // interfaces with the rest of the autocomplete system. |
| 33 class OmniboxViewIOS : public OmniboxView { |
| 34 public: |
| 35 // Retains |field|. |
| 36 OmniboxViewIOS(OmniboxTextFieldIOS* field, |
| 37 WebOmniboxEditController* controller, |
| 38 ios::ChromeBrowserState* browser_state, |
| 39 id<PreloadProvider> prerender, |
| 40 id<OmniboxPopupPositioner> positioner); |
| 41 ~OmniboxViewIOS() override; |
| 42 |
| 43 // OmniboxView implementation. |
| 44 void OpenMatch(const AutocompleteMatch& match, |
| 45 WindowOpenDisposition disposition, |
| 46 const GURL& alternate_nav_url, |
| 47 const base::string16& pasted_text, |
| 48 size_t selected_line) override; |
| 49 base::string16 GetText() const override; |
| 50 void SetWindowTextAndCaretPos(const base::string16& text, |
| 51 size_t caret_pos, |
| 52 bool update_popup, |
| 53 bool notify_text_changed) override; |
| 54 void RevertAll() override; |
| 55 void UpdatePopup() override; |
| 56 void OnTemporaryTextMaybeChanged(const base::string16& display_text, |
| 57 bool save_original_selection, |
| 58 bool notify_text_changed) override; |
| 59 bool OnInlineAutocompleteTextMaybeChanged(const base::string16& display_text, |
| 60 size_t user_text_length) override; |
| 61 void OnBeforePossibleChange() override; |
| 62 bool OnAfterPossibleChange(bool allow_keyword_ui_change) override; |
| 63 bool IsImeComposing() const override; |
| 64 bool IsIndicatingQueryRefinement() const override; |
| 65 |
| 66 // OmniboxView stubs. |
| 67 void Update() override {} |
| 68 void EnterKeywordModeForDefaultSearchProvider() override {} |
| 69 bool IsSelectAll() const override; |
| 70 bool DeleteAtEndPressed() override; |
| 71 void GetSelectionBounds(base::string16::size_type* start, |
| 72 base::string16::size_type* end) const override; |
| 73 void SelectAll(bool reversed) override {} |
| 74 void SetFocus() override {} |
| 75 void ApplyCaretVisibility() override {} |
| 76 void OnInlineAutocompleteTextCleared() override {} |
| 77 void OnRevertTemporaryText() override {} |
| 78 gfx::NativeView GetNativeView() const override; |
| 79 gfx::NativeView GetRelativeWindowForPopup() const override; |
| 80 int GetTextWidth() const override; |
| 81 int GetWidth() const override; |
| 82 |
| 83 // AutocompleteTextFieldDelegate methods |
| 84 void OnDidBeginEditing(); |
| 85 bool OnWillChange(NSRange range, NSString* new_text); |
| 86 void OnDidChange(bool processing_user_input); |
| 87 void OnDidEndEditing(); |
| 88 void OnAccept(); |
| 89 void OnClear(); |
| 90 bool OnCopy(); |
| 91 bool OnCopyURL(); |
| 92 bool CanCopyURL(); |
| 93 void WillPaste(); |
| 94 void OnDeleteBackward(); |
| 95 |
| 96 ios::ChromeBrowserState* browser_state() { return browser_state_; } |
| 97 |
| 98 // Updates this edit view to show the proper text, highlight and images. |
| 99 void UpdateAppearance(); |
| 100 |
| 101 // Clears the text from the omnibox. |
| 102 void ClearText(); |
| 103 |
| 104 // Set first result image. |
| 105 void SetLeftImage(const int imageId); |
| 106 |
| 107 // Hide keyboard and call OnDidEndEditing. This dismisses the keyboard and |
| 108 // also finalizes the editing state of the omnibox. |
| 109 void HideKeyboardAndEndEditing(); |
| 110 |
| 111 // Hide keyboard only. Used when omnibox popups grab focus but editing isn't |
| 112 // complete. |
| 113 void HideKeyboard(); |
| 114 |
| 115 // Focus the omnibox field. This is used when the omnibox popup copies a |
| 116 // search query to the omnibox so the user can modify it further. |
| 117 // This does not affect the popup state and is a NOOP if the omnibox is |
| 118 // already focused. |
| 119 void FocusOmnibox(); |
| 120 |
| 121 // Called when the popup results change. Used to update prerendering. |
| 122 void OnPopupResultsChanged(const AutocompleteResult& result); |
| 123 |
| 124 // Returns |true| if AutocompletePopupView is currently open. |
| 125 BOOL IsPopupOpen(); |
| 126 |
| 127 // Returns the resource ID of the icon to show for the current text. Takes |
| 128 // into account the security level of the page, and |offline_page|. |
| 129 int GetIcon(bool offline_page) const; |
| 130 |
| 131 protected: |
| 132 int GetOmniboxTextLength() const override; |
| 133 void EmphasizeURLComponents() override; |
| 134 |
| 135 private: |
| 136 // Calculates text attributes according to |display_text| and |
| 137 // returns them in an autoreleased object. |
| 138 NSAttributedString* ApplyTextAttributes(const base::string16& text); |
| 139 |
| 140 // Removes the query refinement chip from the omnibox. |
| 141 void RemoveQueryRefinementChip(); |
| 142 |
| 143 // Returns true if user input should currently be ignored. On iOS7, |
| 144 // modifying the contents of a text field while Siri is pending leads to a |
| 145 // UIKit crash. In order to sidestep that crash, OmniboxViewIOS checks that |
| 146 // voice search is not pending before attempting to process user actions that |
| 147 // may modify text field contents. |
| 148 // TODO(crbug.com/303212): Remove this workaround once the crash is fixed. |
| 149 bool ShouldIgnoreUserInputDueToPendingVoiceSearch(); |
| 150 |
| 151 ios::ChromeBrowserState* browser_state_; |
| 152 |
| 153 base::scoped_nsobject<OmniboxTextFieldIOS> field_; |
| 154 WebOmniboxEditController* controller_; // weak, owns us |
| 155 std::unique_ptr<OmniboxPopupViewIOS> popup_view_; |
| 156 id<PreloadProvider> preloader_; |
| 157 |
| 158 State state_before_change_; |
| 159 base::scoped_nsobject<NSString> marked_text_before_change_; |
| 160 NSRange current_selection_; |
| 161 NSRange old_selection_; |
| 162 |
| 163 // TODO(rohitrao): This is a monster hack, needed because closing the popup |
| 164 // ends up inadvertently triggering a new round of autocomplete. Fix the |
| 165 // underlying problem, which is that textDidChange: is called when closing the |
| 166 // popup, and then remove this hack. b/5877366. |
| 167 BOOL ignore_popup_updates_; |
| 168 |
| 169 // Bridges delegate method calls from |field_| to C++ land. |
| 170 base::scoped_nsobject<AutocompleteTextFieldDelegate> field_delegate_; |
| 171 }; |
| 172 |
| 173 #endif // IOS_CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_IOS_H_ |
OLD | NEW |