| 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 // This file defines the interface class OmniboxView. Each toolkit will | 5 // This file defines the interface class OmniboxView. Each toolkit will |
| 6 // implement the edit view differently, so that code is inherently platform | 6 // implement the edit view differently, so that code is inherently platform |
| 7 // specific. However, the OmniboxEditModel needs to do some communication with | 7 // specific. However, the OmniboxEditModel needs to do some communication with |
| 8 // the view. Since the model is shared between platforms, we need to define an | 8 // the view. Since the model is shared between platforms, we need to define an |
| 9 // interface that all view implementations will share. | 9 // interface that all view implementations will share. |
| 10 | 10 |
| 11 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 11 #ifndef CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
| 12 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 12 #define CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
| 13 | 13 |
| 14 #include <string> | 14 #include <string> |
| 15 | 15 |
| 16 #include "base/string16.h" | 16 #include "base/string16.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
| 19 #include "chrome/browser/autocomplete/autocomplete_match.h" | 19 #include "chrome/browser/autocomplete/autocomplete_match.h" |
| 20 #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" |
| 21 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 20 #include "content/public/common/url_constants.h" | 22 #include "content/public/common/url_constants.h" |
| 21 #include "ui/gfx/native_widget_types.h" | 23 #include "ui/gfx/native_widget_types.h" |
| 22 #include "webkit/glue/window_open_disposition.h" | 24 #include "webkit/glue/window_open_disposition.h" |
| 23 | 25 |
| 24 class CommandUpdater; | 26 class CommandUpdater; |
| 25 class GURL; | 27 class GURL; |
| 26 class OmniboxEditModel; | 28 class OmniboxEditController; |
| 29 class Profile; |
| 30 class ToolbarModel; |
| 27 | 31 |
| 28 namespace content { | 32 namespace content { |
| 29 class WebContents; | 33 class WebContents; |
| 30 } | 34 } |
| 31 | 35 |
| 32 #if defined(TOOLKIT_VIEWS) | 36 #if defined(TOOLKIT_VIEWS) |
| 33 // TODO(beng): Move all views-related code to a views-specific sub-interface. | 37 // TODO(beng): Move all views-related code to a views-specific sub-interface. |
| 34 namespace gfx { | 38 namespace gfx { |
| 35 class Font; | 39 class Font; |
| 36 } | 40 } |
| 37 | 41 |
| 38 namespace views { | 42 namespace views { |
| 39 class DropTargetEvent; | 43 class DropTargetEvent; |
| 40 class View; | 44 class View; |
| 41 } | 45 } |
| 42 #endif | 46 #endif |
| 43 | 47 |
| 44 class OmniboxView { | 48 class OmniboxView { |
| 45 public: | 49 public: |
| 50 virtual ~OmniboxView(); |
| 51 |
| 46 // Used by the automation system for getting at the model from the view. | 52 // Used by the automation system for getting at the model from the view. |
| 47 virtual OmniboxEditModel* model() = 0; | 53 OmniboxEditModel* model() { return model_.get(); } |
| 48 virtual const OmniboxEditModel* model() const = 0; | 54 const OmniboxEditModel* model() const { return model_.get(); } |
| 55 |
| 56 CommandUpdater* command_updater() { return command_updater_; } |
| 57 const CommandUpdater* command_updater() const { return command_updater_; } |
| 49 | 58 |
| 50 // For use when switching tabs, this saves the current state onto the tab so | 59 // For use when switching tabs, this saves the current state onto the tab so |
| 51 // that it can be restored during a later call to Update(). | 60 // that it can be restored during a later call to Update(). |
| 52 virtual void SaveStateToTab(content::WebContents* tab) = 0; | 61 virtual void SaveStateToTab(content::WebContents* tab) = 0; |
| 53 | 62 |
| 54 // Called when any LocationBarView state changes. If | 63 // Called when any LocationBarView state changes. If |
| 55 // |tab_for_state_restoring| is non-NULL, it points to a WebContents whose | 64 // |tab_for_state_restoring| is non-NULL, it points to a WebContents whose |
| 56 // state we should restore. | 65 // state we should restore. |
| 57 virtual void Update(const content::WebContents* tab_for_state_restoring) = 0; | 66 virtual void Update(const content::WebContents* tab_for_state_restoring) = 0; |
| 58 | 67 |
| 59 // Asks the browser to load the specified match's |destination_url|, which | 68 // Asks the browser to load the specified match's |destination_url|, which |
| 60 // is assumed to be one of the popup entries, using the supplied disposition | 69 // is assumed to be one of the popup entries, using the supplied disposition |
| 61 // and transition type. |alternate_nav_url|, if non-empty, contains the | 70 // and transition type. |alternate_nav_url|, if non-empty, contains the |
| 62 // alternate navigation URL for for this match. See comments on | 71 // alternate navigation URL for for this match. See comments on |
| 63 // AutocompleteResult::GetAlternateNavURL(). | 72 // AutocompleteResult::GetAlternateNavURL(). |
| 64 // | 73 // |
| 65 // |selected_line| is passed to SendOpenNotification(); see comments there. | 74 // |selected_line| is passed to SendOpenNotification(); see comments there. |
| 66 // | 75 // |
| 67 // This may close the popup. | 76 // This may close the popup. |
| 68 virtual void OpenMatch(const AutocompleteMatch& match, | 77 virtual void OpenMatch(const AutocompleteMatch& match, |
| 69 WindowOpenDisposition disposition, | 78 WindowOpenDisposition disposition, |
| 70 const GURL& alternate_nav_url, | 79 const GURL& alternate_nav_url, |
| 71 size_t selected_line) = 0; | 80 size_t selected_line); |
| 72 | 81 |
| 73 // Returns the current text of the edit control, which could be the | 82 // Returns the current text of the edit control, which could be the |
| 74 // "temporary" text set by the popup, the "permanent" text set by the | 83 // "temporary" text set by the popup, the "permanent" text set by the |
| 75 // browser, or just whatever the user has currently typed. | 84 // browser, or just whatever the user has currently typed. |
| 76 virtual string16 GetText() const = 0; | 85 virtual string16 GetText() const = 0; |
| 77 | 86 |
| 78 // |true| if the user is in the process of editing the field, or if | 87 // |true| if the user is in the process of editing the field, or if |
| 79 // the field is empty. | 88 // the field is empty. |
| 80 virtual bool IsEditingOrEmpty() const = 0; | 89 bool IsEditingOrEmpty() const; |
| 81 | 90 |
| 82 // Returns the resource ID of the icon to show for the current text. | 91 // Returns the resource ID of the icon to show for the current text. |
| 83 virtual int GetIcon() const = 0; | 92 int GetIcon() const; |
| 84 | 93 |
| 85 // The user text is the text the user has manually keyed in. When present, | 94 // The user text is the text the user has manually keyed in. When present, |
| 86 // this is shown in preference to the permanent text; hitting escape will | 95 // this is shown in preference to the permanent text; hitting escape will |
| 87 // revert to the permanent text. | 96 // revert to the permanent text. |
| 88 virtual void SetUserText(const string16& text) = 0; | 97 void SetUserText(const string16& text); |
| 89 virtual void SetUserText(const string16& text, | 98 virtual void SetUserText(const string16& text, |
| 90 const string16& display_text, | 99 const string16& display_text, |
| 91 bool update_popup) = 0; | 100 bool update_popup); |
| 92 | 101 |
| 93 // Sets the window text and the caret position. | 102 // Sets the window text and the caret position. |
| 94 virtual void SetWindowTextAndCaretPos(const string16& text, | 103 virtual void SetWindowTextAndCaretPos(const string16& text, |
| 95 size_t caret_pos, | 104 size_t caret_pos, |
| 96 bool update_popup, | 105 bool update_popup, |
| 97 bool notify_text_changed) = 0; | 106 bool notify_text_changed) = 0; |
| 98 | 107 |
| 99 // Sets the edit to forced query mode. Practically speaking, this means that | 108 // Sets the edit to forced query mode. Practically speaking, this means that |
| 100 // if the edit is not in forced query mode, its text is set to "?" with the | 109 // if the edit is not in forced query mode, its text is set to "?" with the |
| 101 // cursor at the end, and if the edit is in forced query mode (its first | 110 // cursor at the end, and if the edit is in forced query mode (its first |
| (...skipping 14 matching lines...) Expand all Loading... |
| 116 // directed. If there is no selection, |start| and |end| will both be equal | 125 // directed. If there is no selection, |start| and |end| will both be equal |
| 117 // to the current cursor position. | 126 // to the current cursor position. |
| 118 virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0; | 127 virtual void GetSelectionBounds(size_t* start, size_t* end) const = 0; |
| 119 | 128 |
| 120 // Selects all the text in the edit. Use this in place of SetSelAll() to | 129 // Selects all the text in the edit. Use this in place of SetSelAll() to |
| 121 // avoid selecting the "phantom newline" at the end of the edit. | 130 // avoid selecting the "phantom newline" at the end of the edit. |
| 122 virtual void SelectAll(bool reversed) = 0; | 131 virtual void SelectAll(bool reversed) = 0; |
| 123 | 132 |
| 124 // Reverts the edit and popup back to their unedited state (permanent text | 133 // Reverts the edit and popup back to their unedited state (permanent text |
| 125 // showing, popup closed, no user input in progress). | 134 // showing, popup closed, no user input in progress). |
| 126 virtual void RevertAll() = 0; | 135 virtual void RevertAll(); |
| 127 | 136 |
| 128 // Updates the autocomplete popup and other state after the text has been | 137 // Updates the autocomplete popup and other state after the text has been |
| 129 // changed by the user. | 138 // changed by the user. |
| 130 virtual void UpdatePopup() = 0; | 139 virtual void UpdatePopup() = 0; |
| 131 | 140 |
| 132 // Closes the autocomplete popup, if it's open. | 141 // Closes the autocomplete popup, if it's open. The name |ClosePopup| |
| 133 virtual void ClosePopup() = 0; | 142 // conflicts with the OSX class override as that has a base class that also |
| 143 // defines a method with that name. |
| 144 virtual void CloseOmniboxPopup(); |
| 134 | 145 |
| 135 // Sets the focus to the autocomplete view. | 146 // Sets the focus to the autocomplete view. |
| 136 virtual void SetFocus() = 0; | 147 virtual void SetFocus() = 0; |
| 137 | 148 |
| 138 // Called when the temporary text in the model may have changed. | 149 // Called when the temporary text in the model may have changed. |
| 139 // |display_text| is the new text to show; |save_original_selection| is true | 150 // |display_text| is the new text to show; |save_original_selection| is true |
| 140 // when there wasn't previously a temporary text and thus we need to save off | 151 // when there wasn't previously a temporary text and thus we need to save off |
| 141 // the user's existing selection. | 152 // the user's existing selection. |
| 142 virtual void OnTemporaryTextMaybeChanged(const string16& display_text, | 153 virtual void OnTemporaryTextMaybeChanged(const string16& display_text, |
| 143 bool save_original_selection) = 0; | 154 bool save_original_selection) = 0; |
| (...skipping 19 matching lines...) Expand all Loading... |
| 163 | 174 |
| 164 // Returns the gfx::NativeView of the edit view. | 175 // Returns the gfx::NativeView of the edit view. |
| 165 virtual gfx::NativeView GetNativeView() const = 0; | 176 virtual gfx::NativeView GetNativeView() const = 0; |
| 166 | 177 |
| 167 // Gets the relative window for the pop up window of OmniboxPopupView. The pop | 178 // Gets the relative window for the pop up window of OmniboxPopupView. The pop |
| 168 // up window will be shown under the relative window. When an IME is attached | 179 // up window will be shown under the relative window. When an IME is attached |
| 169 // to the rich edit control, the IME window is the relative window. Otherwise, | 180 // to the rich edit control, the IME window is the relative window. Otherwise, |
| 170 // the top-most window is the relative window. | 181 // the top-most window is the relative window. |
| 171 virtual gfx::NativeView GetRelativeWindowForPopup() const = 0; | 182 virtual gfx::NativeView GetRelativeWindowForPopup() const = 0; |
| 172 | 183 |
| 173 // Returns the command updater for this view. | |
| 174 virtual CommandUpdater* GetCommandUpdater() = 0; | |
| 175 | |
| 176 // Shows the instant suggestion text. If |animate_to_complete| is true the | 184 // Shows the instant suggestion text. If |animate_to_complete| is true the |
| 177 // view should start an animation that when done commits the text. | 185 // view should start an animation that when done commits the text. |
| 178 virtual void SetInstantSuggestion(const string16& input, | 186 virtual void SetInstantSuggestion(const string16& input, |
| 179 bool animate_to_complete) = 0; | 187 bool animate_to_complete) = 0; |
| 180 | 188 |
| 181 // Returns the current instant suggestion text. | 189 // Returns the current instant suggestion text. |
| 182 virtual string16 GetInstantSuggestion() const = 0; | 190 virtual string16 GetInstantSuggestion() const = 0; |
| 183 | 191 |
| 184 // Returns the width in pixels needed to display the current text. The | 192 // Returns the width in pixels needed to display the current text. The |
| 185 // returned value includes margins. | 193 // returned value includes margins. |
| (...skipping 22 matching lines...) Expand all Loading... |
| 208 | 216 |
| 209 // Returns a string with any leading javascript schemas stripped from the | 217 // Returns a string with any leading javascript schemas stripped from the |
| 210 // input text. | 218 // input text. |
| 211 static string16 StripJavascriptSchemas(const string16& text); | 219 static string16 StripJavascriptSchemas(const string16& text); |
| 212 | 220 |
| 213 // Returns the current clipboard contents as a string that can be pasted in. | 221 // Returns the current clipboard contents as a string that can be pasted in. |
| 214 // In addition to just getting CF_UNICODETEXT out, this can also extract URLs | 222 // In addition to just getting CF_UNICODETEXT out, this can also extract URLs |
| 215 // from bookmarks on the clipboard. | 223 // from bookmarks on the clipboard. |
| 216 static string16 GetClipboardText(); | 224 static string16 GetClipboardText(); |
| 217 | 225 |
| 218 virtual ~OmniboxView() {} | 226 protected: |
| 227 OmniboxView(Profile* profile, |
| 228 OmniboxEditController* controller, |
| 229 ToolbarModel* toolbar_model, |
| 230 CommandUpdater* command_updater); |
| 231 |
| 232 // Internally invoked whenever the text changes in some way. |
| 233 virtual void TextChanged(); |
| 234 |
| 235 // Return the number of characters in the current buffer. The name |
| 236 // |GetTextLength| can't be used as the Windows override of this class |
| 237 // inherits from a class that defines a method with that name. |
| 238 virtual int GetOmniboxTextLength() const = 0; |
| 239 |
| 240 // Try to parse the current text as a URL and colorize the components. |
| 241 virtual void EmphasizeURLComponents() = 0; |
| 242 |
| 243 OmniboxEditController* controller() { return controller_; } |
| 244 ToolbarModel* toolbar_model() { return toolbar_model_; } |
| 245 |
| 246 private: |
| 247 // |model_| can be NULL in tests. |
| 248 scoped_ptr<OmniboxEditModel> model_; |
| 249 OmniboxEditController* controller_; |
| 250 ToolbarModel* toolbar_model_; |
| 251 |
| 252 // The object that handles additional command functionality exposed on the |
| 253 // edit, such as invoking the keyword editor. |
| 254 CommandUpdater* command_updater_; |
| 219 }; | 255 }; |
| 220 | 256 |
| 221 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ | 257 #endif // CHROME_BROWSER_UI_OMNIBOX_OMNIBOX_VIEW_H_ |
| OLD | NEW |