Chromium Code Reviews| 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 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 28 class GURL; | 28 class GURL; |
| 29 class OmniboxClient; | 29 class OmniboxClient; |
| 30 class OmniboxEditController; | 30 class OmniboxEditController; |
| 31 class OmniboxViewMacTest; | 31 class OmniboxViewMacTest; |
| 32 class ToolbarModel; | 32 class ToolbarModel; |
| 33 | 33 |
| 34 namespace gfx { | 34 namespace gfx { |
| 35 enum class VectorIconId; | 35 enum class VectorIconId; |
| 36 } | 36 } |
| 37 | 37 |
| 38 // Represents the changes between two State objects. This is used by the | |
| 39 // model to determine how its internal state should be updated after the view | |
| 40 // state changes. See OmniboxEditModel::OnAfterPossibleChange(). | |
| 41 struct OmniboxViewStateChanges { | |
|
Peter Kasting
2016/06/05 01:20:27
Rather than declare this outside OmniboxView, can
| |
| 42 // |old_text| and |new_text| are not owned. | |
| 43 const base::string16* old_text; | |
| 44 const base::string16* new_text; | |
| 45 size_t new_sel_start; | |
| 46 size_t new_sel_end; | |
| 47 bool selection_differs; | |
| 48 bool text_differs; | |
| 49 bool keyword_differs; | |
| 50 bool just_deleted_text; | |
| 51 }; | |
| 52 | |
| 38 class OmniboxView { | 53 class OmniboxView { |
| 39 public: | 54 public: |
| 40 virtual ~OmniboxView(); | 55 virtual ~OmniboxView(); |
| 41 | 56 |
| 42 // Used by the automation system for getting at the model from the view. | 57 // Used by the automation system for getting at the model from the view. |
| 43 OmniboxEditModel* model() { return model_.get(); } | 58 OmniboxEditModel* model() { return model_.get(); } |
| 44 const OmniboxEditModel* model() const { return model_.get(); } | 59 const OmniboxEditModel* model() const { return model_.get(); } |
| 45 | 60 |
| 46 // Shared cross-platform focus handling. | 61 // Shared cross-platform focus handling. |
| 47 void OnDidKillFocus(); | 62 void OnDidKillFocus(); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 88 virtual void SetUserText(const base::string16& text, | 103 virtual void SetUserText(const base::string16& text, |
| 89 bool update_popup); | 104 bool update_popup); |
| 90 | 105 |
| 91 // Sets the window text and the caret position. |notify_text_changed| is true | 106 // Sets the window text and the caret position. |notify_text_changed| is true |
| 92 // if the model should be notified of the change. | 107 // if the model should be notified of the change. |
| 93 virtual void SetWindowTextAndCaretPos(const base::string16& text, | 108 virtual void SetWindowTextAndCaretPos(const base::string16& text, |
| 94 size_t caret_pos, | 109 size_t caret_pos, |
| 95 bool update_popup, | 110 bool update_popup, |
| 96 bool notify_text_changed) = 0; | 111 bool notify_text_changed) = 0; |
| 97 | 112 |
| 98 // Sets the edit to forced query mode. Practically speaking, this means that | 113 // Transitions the user into keyword mode with their default search provider, |
| 99 // if the edit is not in forced query mode, its text is set to "?" with the | 114 // preserving and selecting the user's text if they already typed in a query. |
| 100 // cursor at the end, and if the edit is in forced query mode (its first | 115 virtual void EnterKeywordModeForDefaultSearchProvider() = 0; |
| 101 // non-whitespace character is '?'), the text after the '?' is selected. | |
| 102 // | |
| 103 // In the future we should display the search engine UI for the default engine | |
| 104 // rather than '?'. | |
| 105 virtual void SetForcedQuery() = 0; | |
| 106 | 116 |
| 107 // Returns true if all text is selected or there is no text at all. | 117 // Returns true if all text is selected or there is no text at all. |
| 108 virtual bool IsSelectAll() const = 0; | 118 virtual bool IsSelectAll() const = 0; |
| 109 | 119 |
| 110 // Returns true if the user deleted the suggested text. | 120 // Returns true if the user deleted the suggested text. |
| 111 virtual bool DeleteAtEndPressed() = 0; | 121 virtual bool DeleteAtEndPressed() = 0; |
| 112 | 122 |
| 113 // Fills |start| and |end| with the indexes of the current selection's bounds. | 123 // Fills |start| and |end| with the indexes of the current selection's bounds. |
| 114 // It is not guaranteed that |*start < *end|, as the selection can be | 124 // It is not guaranteed that |*start < *end|, as the selection can be |
| 115 // 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 |
| (...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 232 // First, calls StripJavascriptSchemas(). Then automatically collapses | 242 // First, calls StripJavascriptSchemas(). Then automatically collapses |
| 233 // internal whitespace as follows: | 243 // internal whitespace as follows: |
| 234 // * If the only whitespace in |text| is newlines, users are most likely | 244 // * If the only whitespace in |text| is newlines, users are most likely |
| 235 // pasting in URLs split into multiple lines by terminals, email programs, | 245 // pasting in URLs split into multiple lines by terminals, email programs, |
| 236 // etc. So all newlines are removed. | 246 // etc. So all newlines are removed. |
| 237 // * Otherwise, users may be pasting in search data, e.g. street addresses. In | 247 // * Otherwise, users may be pasting in search data, e.g. street addresses. In |
| 238 // this case, runs of whitespace are collapsed down to single spaces. | 248 // this case, runs of whitespace are collapsed down to single spaces. |
| 239 static base::string16 SanitizeTextForPaste(const base::string16& text); | 249 static base::string16 SanitizeTextForPaste(const base::string16& text); |
| 240 | 250 |
| 241 protected: | 251 protected: |
| 252 // Tracks important state that may change between OnBeforePossibleChange() and | |
| 253 // OnAfterPossibleChange(). | |
| 254 struct State { | |
| 255 base::string16 text; | |
| 256 base::string16 keyword; | |
| 257 bool is_keyword_selected; | |
| 258 size_t sel_start; | |
| 259 size_t sel_end; | |
| 260 }; | |
| 261 | |
| 242 OmniboxView(OmniboxEditController* controller, | 262 OmniboxView(OmniboxEditController* controller, |
| 243 std::unique_ptr<OmniboxClient> client); | 263 std::unique_ptr<OmniboxClient> client); |
| 244 | 264 |
| 265 // Fills |state| with the current text state. | |
| 266 void GetState(State* state); | |
| 267 | |
| 268 // Returns the delta between |before| and |after|. | |
| 269 OmniboxViewStateChanges GetStateChanges(const State& before, | |
| 270 const State& after); | |
| 271 | |
| 245 // Internally invoked whenever the text changes in some way. | 272 // Internally invoked whenever the text changes in some way. |
| 246 virtual void TextChanged(); | 273 virtual void TextChanged(); |
| 247 | 274 |
| 248 // Return the number of characters in the current buffer. The name | 275 // Return the number of characters in the current buffer. The name |
| 249 // |GetTextLength| can't be used as the Windows override of this class | 276 // |GetTextLength| can't be used as the Windows override of this class |
| 250 // inherits from a class that defines a method with that name. | 277 // inherits from a class that defines a method with that name. |
| 251 virtual int GetOmniboxTextLength() const = 0; | 278 virtual int GetOmniboxTextLength() const = 0; |
| 252 | 279 |
| 253 // Try to parse the current text as a URL and colorize the components. | 280 // Try to parse the current text as a URL and colorize the components. |
| 254 virtual void EmphasizeURLComponents() = 0; | 281 virtual void EmphasizeURLComponents() = 0; |
| 255 | 282 |
| 256 OmniboxEditController* controller() { return controller_; } | 283 OmniboxEditController* controller() { return controller_; } |
| 257 const OmniboxEditController* controller() const { return controller_; } | 284 const OmniboxEditController* controller() const { return controller_; } |
| 258 | 285 |
| 259 private: | 286 private: |
| 260 friend class OmniboxViewMacTest; | 287 friend class OmniboxViewMacTest; |
| 261 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL); | 288 FRIEND_TEST_ALL_PREFIXES(InstantExtendedTest, ShowURL); |
| 262 | 289 |
| 263 // |model_| can be NULL in tests. | 290 // |model_| can be NULL in tests. |
| 264 std::unique_ptr<OmniboxEditModel> model_; | 291 std::unique_ptr<OmniboxEditModel> model_; |
| 265 OmniboxEditController* controller_; | 292 OmniboxEditController* controller_; |
| 266 | 293 |
| 267 DISALLOW_COPY_AND_ASSIGN(OmniboxView); | 294 DISALLOW_COPY_AND_ASSIGN(OmniboxView); |
| 268 }; | 295 }; |
| 269 | 296 |
| 270 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ | 297 #endif // COMPONENTS_OMNIBOX_BROWSER_OMNIBOX_VIEW_H_ |
| OLD | NEW |