OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #ifndef CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ | 5 #ifndef CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ |
6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ | 6 #define CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ |
7 | 7 |
8 #import <Cocoa/Cocoa.h> | 8 #import <Cocoa/Cocoa.h> |
9 | 9 |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
11 #include "base/string16.h" | 11 #include "base/string16.h" |
12 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" | 12 #include "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field.h" |
13 #include "chrome/browser/ui/omnibox/omnibox_view.h" | 13 #include "chrome/browser/ui/omnibox/omnibox_view.h" |
14 | 14 |
15 class OmniboxEditController; | |
16 class OmniboxPopupViewMac; | 15 class OmniboxPopupViewMac; |
17 class Profile; | |
18 class ToolbarModel; | |
19 | 16 |
20 namespace ui { | 17 namespace ui { |
21 class Clipboard; | 18 class Clipboard; |
22 } | 19 } |
23 | 20 |
24 // Implements OmniboxView on an AutocompleteTextField. | 21 // Implements OmniboxView on an AutocompleteTextField. |
25 class OmniboxViewMac : public OmniboxView, | 22 class OmniboxViewMac : public OmniboxView, |
26 public AutocompleteTextFieldObserver { | 23 public AutocompleteTextFieldObserver { |
27 public: | 24 public: |
28 OmniboxViewMac(OmniboxEditController* controller, | 25 OmniboxViewMac(OmniboxEditController* controller, |
29 ToolbarModel* toolbar_model, | 26 ToolbarModel* toolbar_model, |
30 Profile* profile, | 27 Profile* profile, |
31 CommandUpdater* command_updater, | 28 CommandUpdater* command_updater, |
32 AutocompleteTextField* field); | 29 AutocompleteTextField* field); |
33 virtual ~OmniboxViewMac(); | 30 virtual ~OmniboxViewMac(); |
34 | 31 |
35 // OmniboxView: | 32 // OmniboxView: |
36 virtual OmniboxEditModel* model() OVERRIDE; | |
37 virtual const OmniboxEditModel* model() const OVERRIDE; | |
38 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; | 33 virtual void SaveStateToTab(content::WebContents* tab) OVERRIDE; |
39 virtual void Update( | 34 virtual void Update( |
40 const content::WebContents* tab_for_state_restoring) OVERRIDE; | 35 const content::WebContents* tab_for_state_restoring) OVERRIDE; |
41 virtual void OpenMatch(const AutocompleteMatch& match, | |
42 WindowOpenDisposition disposition, | |
43 const GURL& alternate_nav_url, | |
44 size_t index) OVERRIDE; | |
45 virtual string16 GetText() const OVERRIDE; | 36 virtual string16 GetText() const OVERRIDE; |
46 virtual bool IsEditingOrEmpty() const OVERRIDE; | |
47 virtual int GetIcon() const OVERRIDE; | |
48 virtual void SetUserText(const string16& text) OVERRIDE; | |
49 virtual void SetUserText(const string16& text, | |
50 const string16& display_text, | |
51 bool update_popup) OVERRIDE; | |
52 virtual void SetWindowTextAndCaretPos(const string16& text, | 37 virtual void SetWindowTextAndCaretPos(const string16& text, |
53 size_t caret_pos, | 38 size_t caret_pos, |
54 bool update_popup, | 39 bool update_popup, |
55 bool notify_text_changed) OVERRIDE; | 40 bool notify_text_changed) OVERRIDE; |
56 virtual void SetForcedQuery() OVERRIDE; | 41 virtual void SetForcedQuery() OVERRIDE; |
57 virtual bool IsSelectAll() const OVERRIDE; | 42 virtual bool IsSelectAll() const OVERRIDE; |
58 virtual bool DeleteAtEndPressed() OVERRIDE; | 43 virtual bool DeleteAtEndPressed() OVERRIDE; |
59 virtual void GetSelectionBounds(string16::size_type* start, | 44 virtual void GetSelectionBounds(string16::size_type* start, |
60 string16::size_type* end) const OVERRIDE; | 45 string16::size_type* end) const OVERRIDE; |
61 virtual void SelectAll(bool reversed) OVERRIDE; | 46 virtual void SelectAll(bool reversed) OVERRIDE; |
62 virtual void RevertAll() OVERRIDE; | 47 virtual void RevertAll() OVERRIDE; |
63 virtual void UpdatePopup() OVERRIDE; | 48 virtual void UpdatePopup() OVERRIDE; |
64 virtual void ClosePopup() OVERRIDE; | 49 virtual void CloseOmniboxPopup() OVERRIDE; |
65 virtual void SetFocus() OVERRIDE; | 50 virtual void SetFocus() OVERRIDE; |
66 virtual void OnTemporaryTextMaybeChanged( | 51 virtual void OnTemporaryTextMaybeChanged( |
67 const string16& display_text, | 52 const string16& display_text, |
68 bool save_original_selection) OVERRIDE; | 53 bool save_original_selection) OVERRIDE; |
69 virtual bool OnInlineAutocompleteTextMaybeChanged( | 54 virtual bool OnInlineAutocompleteTextMaybeChanged( |
70 const string16& display_text, size_t user_text_length) OVERRIDE; | 55 const string16& display_text, size_t user_text_length) OVERRIDE; |
71 virtual void OnStartingIME() OVERRIDE; | 56 virtual void OnStartingIME() OVERRIDE; |
72 virtual void OnRevertTemporaryText() OVERRIDE; | 57 virtual void OnRevertTemporaryText() OVERRIDE; |
73 virtual void OnBeforePossibleChange() OVERRIDE; | 58 virtual void OnBeforePossibleChange() OVERRIDE; |
74 virtual bool OnAfterPossibleChange() OVERRIDE; | 59 virtual bool OnAfterPossibleChange() OVERRIDE; |
75 virtual gfx::NativeView GetNativeView() const OVERRIDE; | 60 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
76 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; | 61 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; |
77 virtual CommandUpdater* GetCommandUpdater() OVERRIDE; | |
78 virtual void SetInstantSuggestion(const string16& input, | 62 virtual void SetInstantSuggestion(const string16& input, |
79 bool animate_to_complete) OVERRIDE; | 63 bool animate_to_complete) OVERRIDE; |
80 virtual string16 GetInstantSuggestion() const OVERRIDE; | 64 virtual string16 GetInstantSuggestion() const OVERRIDE; |
81 virtual int TextWidth() const OVERRIDE; | 65 virtual int TextWidth() const OVERRIDE; |
82 virtual bool IsImeComposing() const OVERRIDE; | 66 virtual bool IsImeComposing() const OVERRIDE; |
83 | 67 |
84 // Implement the AutocompleteTextFieldObserver interface. | 68 // Implement the AutocompleteTextFieldObserver interface. |
85 virtual NSRange SelectionRangeForProposedRange( | 69 virtual NSRange SelectionRangeForProposedRange( |
86 NSRange proposed_range) OVERRIDE; | 70 NSRange proposed_range) OVERRIDE; |
87 virtual void OnControlKeyChanged(bool pressed) OVERRIDE; | 71 virtual void OnControlKeyChanged(bool pressed) OVERRIDE; |
88 virtual bool CanCopy() OVERRIDE; | 72 virtual bool CanCopy() OVERRIDE; |
89 virtual void CopyToPasteboard(NSPasteboard* pboard) OVERRIDE; | 73 virtual void CopyToPasteboard(NSPasteboard* pboard) OVERRIDE; |
90 virtual void OnPaste() OVERRIDE; | 74 virtual void OnPaste() OVERRIDE; |
91 virtual bool CanPasteAndGo() OVERRIDE; | 75 virtual bool CanPasteAndGo() OVERRIDE; |
92 virtual int GetPasteActionStringId() OVERRIDE; | 76 virtual int GetPasteActionStringId() OVERRIDE; |
93 virtual void OnPasteAndGo() OVERRIDE; | 77 virtual void OnPasteAndGo() OVERRIDE; |
94 virtual void OnFrameChanged() OVERRIDE; | 78 virtual void OnFrameChanged() OVERRIDE; |
| 79 virtual void ClosePopup() OVERRIDE; |
95 virtual void OnDidBeginEditing() OVERRIDE; | 80 virtual void OnDidBeginEditing() OVERRIDE; |
96 virtual void OnBeforeChange() OVERRIDE; | 81 virtual void OnBeforeChange() OVERRIDE; |
97 virtual void OnDidChange() OVERRIDE; | 82 virtual void OnDidChange() OVERRIDE; |
98 virtual void OnDidEndEditing() OVERRIDE; | 83 virtual void OnDidEndEditing() OVERRIDE; |
99 virtual bool OnDoCommandBySelector(SEL cmd) OVERRIDE; | 84 virtual bool OnDoCommandBySelector(SEL cmd) OVERRIDE; |
100 virtual void OnSetFocus(bool control_down) OVERRIDE; | 85 virtual void OnSetFocus(bool control_down) OVERRIDE; |
101 virtual void OnKillFocus() OVERRIDE; | 86 virtual void OnKillFocus() OVERRIDE; |
102 | 87 |
103 // Helper for LocationBarViewMac. Optionally selects all in |field_|. | 88 // Helper for LocationBarViewMac. Optionally selects all in |field_|. |
104 void FocusLocation(bool select_all); | 89 void FocusLocation(bool select_all); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 134 |
150 // Returns the non-suggest portion of |field_|'s string value. | 135 // Returns the non-suggest portion of |field_|'s string value. |
151 NSString* GetNonSuggestTextSubstring() const; | 136 NSString* GetNonSuggestTextSubstring() const; |
152 | 137 |
153 // Returns the suggest portion of |field_|'s string value. | 138 // Returns the suggest portion of |field_|'s string value. |
154 NSString* GetSuggestTextSubstring() const; | 139 NSString* GetSuggestTextSubstring() const; |
155 | 140 |
156 // Pass the current content of |field_| to SetText(), maintaining | 141 // Pass the current content of |field_| to SetText(), maintaining |
157 // any selection. Named to be consistent with GTK and Windows, | 142 // any selection. Named to be consistent with GTK and Windows, |
158 // though here we cannot really do the in-place operation they do. | 143 // though here we cannot really do the in-place operation they do. |
159 void EmphasizeURLComponents(); | 144 virtual void EmphasizeURLComponents() OVERRIDE; |
160 | |
161 // Internally invoked whenever the text changes in some way. | |
162 void TextChanged(); | |
163 | 145 |
164 // Calculates text attributes according to |display_text| and applies them | 146 // Calculates text attributes according to |display_text| and applies them |
165 // to the given |as| object. | 147 // to the given |as| object. |
166 void ApplyTextAttributes(const string16& display_text, | 148 void ApplyTextAttributes(const string16& display_text, |
167 NSMutableAttributedString* as); | 149 NSMutableAttributedString* as); |
168 | 150 |
169 // Return the number of UTF-16 units in the current buffer, excluding the | 151 // Return the number of UTF-16 units in the current buffer, excluding the |
170 // suggested text. | 152 // suggested text. |
| 153 virtual int GetOmniboxTextLength() const OVERRIDE; |
171 NSUInteger GetTextLength() const; | 154 NSUInteger GetTextLength() const; |
172 | 155 |
173 // Places the caret at the given position. This clears any selection. | |
174 void PlaceCaretAt(NSUInteger pos); | |
175 | |
176 // Returns true if the caret is at the end of the content. | 156 // Returns true if the caret is at the end of the content. |
177 bool IsCaretAtEnd() const; | 157 bool IsCaretAtEnd() const; |
178 | 158 |
179 scoped_ptr<OmniboxEditModel> model_; | |
180 scoped_ptr<OmniboxPopupViewMac> popup_view_; | 159 scoped_ptr<OmniboxPopupViewMac> popup_view_; |
181 | 160 |
182 OmniboxEditController* controller_; | |
183 ToolbarModel* toolbar_model_; | |
184 | |
185 // The object that handles additional command functionality exposed on the | |
186 // edit, such as invoking the keyword editor. | |
187 CommandUpdater* command_updater_; | |
188 | |
189 AutocompleteTextField* field_; // owned by tab controller | 161 AutocompleteTextField* field_; // owned by tab controller |
190 | 162 |
191 // Selection at the point where the user started using the | 163 // Selection at the point where the user started using the |
192 // arrows to move around in the popup. | 164 // arrows to move around in the popup. |
193 NSRange saved_temporary_selection_; | 165 NSRange saved_temporary_selection_; |
194 | 166 |
195 // Tracking state before and after a possible change for reporting | 167 // Tracking state before and after a possible change for reporting |
196 // to model_. | 168 // to model_. |
197 NSRange selection_before_change_; | 169 NSRange selection_before_change_; |
198 string16 text_before_change_; | 170 string16 text_before_change_; |
199 NSRange marked_range_before_change_; | 171 NSRange marked_range_before_change_; |
200 | 172 |
201 // Length of the suggest text. The suggest text always appears at the end of | 173 // Length of the suggest text. The suggest text always appears at the end of |
202 // the field. | 174 // the field. |
203 size_t suggest_text_length_; | 175 size_t suggest_text_length_; |
204 | 176 |
205 // Was delete pressed? | 177 // Was delete pressed? |
206 bool delete_was_pressed_; | 178 bool delete_was_pressed_; |
207 | 179 |
208 // Was the delete key pressed with an empty selection at the end of the edit? | 180 // Was the delete key pressed with an empty selection at the end of the edit? |
209 bool delete_at_end_pressed_; | 181 bool delete_at_end_pressed_; |
210 | 182 |
211 // The maximum/standard line height for the displayed text. | 183 // The maximum/standard line height for the displayed text. |
212 CGFloat line_height_; | 184 CGFloat line_height_; |
213 | 185 |
214 DISALLOW_COPY_AND_ASSIGN(OmniboxViewMac); | 186 DISALLOW_COPY_AND_ASSIGN(OmniboxViewMac); |
215 }; | 187 }; |
216 | 188 |
217 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ | 189 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ |
OLD | NEW |