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; | |
65 virtual void SetFocus() OVERRIDE; | 49 virtual void SetFocus() OVERRIDE; |
66 virtual void OnTemporaryTextMaybeChanged( | 50 virtual void OnTemporaryTextMaybeChanged( |
67 const string16& display_text, | 51 const string16& display_text, |
68 bool save_original_selection) OVERRIDE; | 52 bool save_original_selection) OVERRIDE; |
69 virtual bool OnInlineAutocompleteTextMaybeChanged( | 53 virtual bool OnInlineAutocompleteTextMaybeChanged( |
70 const string16& display_text, size_t user_text_length) OVERRIDE; | 54 const string16& display_text, size_t user_text_length) OVERRIDE; |
71 virtual void OnStartingIME() OVERRIDE; | 55 virtual void OnStartingIME() OVERRIDE; |
72 virtual void OnRevertTemporaryText() OVERRIDE; | 56 virtual void OnRevertTemporaryText() OVERRIDE; |
73 virtual void OnBeforePossibleChange() OVERRIDE; | 57 virtual void OnBeforePossibleChange() OVERRIDE; |
74 virtual bool OnAfterPossibleChange() OVERRIDE; | 58 virtual bool OnAfterPossibleChange() OVERRIDE; |
75 virtual gfx::NativeView GetNativeView() const OVERRIDE; | 59 virtual gfx::NativeView GetNativeView() const OVERRIDE; |
76 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; | 60 virtual gfx::NativeView GetRelativeWindowForPopup() const OVERRIDE; |
77 virtual CommandUpdater* GetCommandUpdater() OVERRIDE; | |
78 virtual void SetInstantSuggestion(const string16& input, | 61 virtual void SetInstantSuggestion(const string16& input, |
79 bool animate_to_complete) OVERRIDE; | 62 bool animate_to_complete) OVERRIDE; |
80 virtual string16 GetInstantSuggestion() const OVERRIDE; | 63 virtual string16 GetInstantSuggestion() const OVERRIDE; |
81 virtual int TextWidth() const OVERRIDE; | 64 virtual int TextWidth() const OVERRIDE; |
82 virtual bool IsImeComposing() const OVERRIDE; | 65 virtual bool IsImeComposing() const OVERRIDE; |
83 | 66 |
84 // Implement the AutocompleteTextFieldObserver interface. | 67 // Implement the AutocompleteTextFieldObserver interface. |
85 virtual NSRange SelectionRangeForProposedRange( | 68 virtual NSRange SelectionRangeForProposedRange( |
86 NSRange proposed_range) OVERRIDE; | 69 NSRange proposed_range) OVERRIDE; |
87 virtual void OnControlKeyChanged(bool pressed) OVERRIDE; | 70 virtual void OnControlKeyChanged(bool pressed) OVERRIDE; |
88 virtual bool CanCopy() OVERRIDE; | 71 virtual bool CanCopy() OVERRIDE; |
89 virtual void CopyToPasteboard(NSPasteboard* pboard) OVERRIDE; | 72 virtual void CopyToPasteboard(NSPasteboard* pboard) OVERRIDE; |
90 virtual void OnPaste() OVERRIDE; | 73 virtual void OnPaste() OVERRIDE; |
91 virtual bool CanPasteAndGo() OVERRIDE; | 74 virtual bool CanPasteAndGo() OVERRIDE; |
92 virtual int GetPasteActionStringId() OVERRIDE; | 75 virtual int GetPasteActionStringId() OVERRIDE; |
93 virtual void OnPasteAndGo() OVERRIDE; | 76 virtual void OnPasteAndGo() OVERRIDE; |
94 virtual void OnFrameChanged() OVERRIDE; | 77 virtual void OnFrameChanged() OVERRIDE; |
| 78 virtual void ClosePopup() OVERRIDE; |
95 virtual void OnDidBeginEditing() OVERRIDE; | 79 virtual void OnDidBeginEditing() OVERRIDE; |
96 virtual void OnBeforeChange() OVERRIDE; | 80 virtual void OnBeforeChange() OVERRIDE; |
97 virtual void OnDidChange() OVERRIDE; | 81 virtual void OnDidChange() OVERRIDE; |
98 virtual void OnDidEndEditing() OVERRIDE; | 82 virtual void OnDidEndEditing() OVERRIDE; |
99 virtual bool OnDoCommandBySelector(SEL cmd) OVERRIDE; | 83 virtual bool OnDoCommandBySelector(SEL cmd) OVERRIDE; |
100 virtual void OnSetFocus(bool control_down) OVERRIDE; | 84 virtual void OnSetFocus(bool control_down) OVERRIDE; |
101 virtual void OnKillFocus() OVERRIDE; | 85 virtual void OnKillFocus() OVERRIDE; |
102 | 86 |
103 // Helper for LocationBarViewMac. Optionally selects all in |field_|. | 87 // Helper for LocationBarViewMac. Optionally selects all in |field_|. |
104 void FocusLocation(bool select_all); | 88 void FocusLocation(bool select_all); |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
149 | 133 |
150 // Returns the non-suggest portion of |field_|'s string value. | 134 // Returns the non-suggest portion of |field_|'s string value. |
151 NSString* GetNonSuggestTextSubstring() const; | 135 NSString* GetNonSuggestTextSubstring() const; |
152 | 136 |
153 // Returns the suggest portion of |field_|'s string value. | 137 // Returns the suggest portion of |field_|'s string value. |
154 NSString* GetSuggestTextSubstring() const; | 138 NSString* GetSuggestTextSubstring() const; |
155 | 139 |
156 // Pass the current content of |field_| to SetText(), maintaining | 140 // Pass the current content of |field_| to SetText(), maintaining |
157 // any selection. Named to be consistent with GTK and Windows, | 141 // any selection. Named to be consistent with GTK and Windows, |
158 // though here we cannot really do the in-place operation they do. | 142 // though here we cannot really do the in-place operation they do. |
159 void EmphasizeURLComponents(); | 143 virtual void EmphasizeURLComponents() OVERRIDE; |
160 | |
161 // Internally invoked whenever the text changes in some way. | |
162 void TextChanged(); | |
163 | 144 |
164 // Calculates text attributes according to |display_text| and applies them | 145 // Calculates text attributes according to |display_text| and applies them |
165 // to the given |as| object. | 146 // to the given |as| object. |
166 void ApplyTextAttributes(const string16& display_text, | 147 void ApplyTextAttributes(const string16& display_text, |
167 NSMutableAttributedString* as); | 148 NSMutableAttributedString* as); |
168 | 149 |
169 // Return the number of UTF-16 units in the current buffer, excluding the | 150 // Return the number of UTF-16 units in the current buffer, excluding the |
170 // suggested text. | 151 // suggested text. |
| 152 virtual int GetOmniboxTextLength() const OVERRIDE; |
171 NSUInteger GetTextLength() const; | 153 NSUInteger GetTextLength() const; |
172 | 154 |
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. | 155 // Returns true if the caret is at the end of the content. |
177 bool IsCaretAtEnd() const; | 156 bool IsCaretAtEnd() const; |
178 | 157 |
179 scoped_ptr<OmniboxEditModel> model_; | |
180 scoped_ptr<OmniboxPopupViewMac> popup_view_; | 158 scoped_ptr<OmniboxPopupViewMac> popup_view_; |
181 | 159 |
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 | 160 AutocompleteTextField* field_; // owned by tab controller |
190 | 161 |
191 // Selection at the point where the user started using the | 162 // Selection at the point where the user started using the |
192 // arrows to move around in the popup. | 163 // arrows to move around in the popup. |
193 NSRange saved_temporary_selection_; | 164 NSRange saved_temporary_selection_; |
194 | 165 |
195 // Tracking state before and after a possible change for reporting | 166 // Tracking state before and after a possible change for reporting |
196 // to model_. | 167 // to model_. |
197 NSRange selection_before_change_; | 168 NSRange selection_before_change_; |
198 string16 text_before_change_; | 169 string16 text_before_change_; |
199 NSRange marked_range_before_change_; | 170 NSRange marked_range_before_change_; |
200 | 171 |
201 // Length of the suggest text. The suggest text always appears at the end of | 172 // Length of the suggest text. The suggest text always appears at the end of |
202 // the field. | 173 // the field. |
203 size_t suggest_text_length_; | 174 size_t suggest_text_length_; |
204 | 175 |
205 // Was delete pressed? | 176 // Was delete pressed? |
206 bool delete_was_pressed_; | 177 bool delete_was_pressed_; |
207 | 178 |
208 // Was the delete key pressed with an empty selection at the end of the edit? | 179 // Was the delete key pressed with an empty selection at the end of the edit? |
209 bool delete_at_end_pressed_; | 180 bool delete_at_end_pressed_; |
210 | 181 |
211 // The maximum/standard line height for the displayed text. | 182 // The maximum/standard line height for the displayed text. |
212 CGFloat line_height_; | 183 CGFloat line_height_; |
213 | 184 |
214 DISALLOW_COPY_AND_ASSIGN(OmniboxViewMac); | 185 DISALLOW_COPY_AND_ASSIGN(OmniboxViewMac); |
215 }; | 186 }; |
216 | 187 |
217 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ | 188 #endif // CHROME_BROWSER_UI_COCOA_OMNIBOX_OMNIBOX_VIEW_MAC_H_ |
OLD | NEW |