Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(183)

Side by Side Diff: chrome/browser/autocomplete/autocomplete_edit.h

Issue 9570064: Fix keyword search erroneously not triggering in two obscure cases: (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_
7 #pragma once 7 #pragma once
8 8
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/string16.h" 10 #include "base/string16.h"
(...skipping 301 matching lines...) Expand 10 before | Expand all | Expand 10 after
312 // or the currently selected keyword if |is_keyword_hint| is false (see 312 // or the currently selected keyword if |is_keyword_hint| is false (see
313 // comments on keyword_ and is_keyword_hint_). 313 // comments on keyword_ and is_keyword_hint_).
314 void OnPopupDataChanged( 314 void OnPopupDataChanged(
315 const string16& text, 315 const string16& text,
316 GURL* destination_for_temporary_text_change, 316 GURL* destination_for_temporary_text_change,
317 const string16& keyword, 317 const string16& keyword,
318 bool is_keyword_hint); 318 bool is_keyword_hint);
319 319
320 // Called by the OmniboxView after something changes, with details about what 320 // Called by the OmniboxView after something changes, with details about what
321 // state changes occured. Updates internal state, updates the popup if 321 // state changes occured. Updates internal state, updates the popup if
322 // necessary, and returns true if any significant changes occurred. 322 // necessary, and returns true if any significant changes occurred. Note that
323 // |text_differs| may be set even if |old_text| == |new_text|, e.g. if we've
324 // just committed an IME composition.
325 //
323 // If |allow_keyword_ui_change| is false then the change should not affect 326 // If |allow_keyword_ui_change| is false then the change should not affect
324 // keyword ui state, even if the text matches a keyword exactly. This value 327 // keyword ui state, even if the text matches a keyword exactly. This value
325 // may be false when the user is composing a text with an IME. 328 // may be false when the user is composing a text with an IME.
326 bool OnAfterPossibleChange(const string16& new_text, 329 bool OnAfterPossibleChange(const string16& old_text,
330 const string16& new_text,
327 size_t selection_start, 331 size_t selection_start,
328 size_t selection_end, 332 size_t selection_end,
329 bool selection_differs, 333 bool selection_differs,
330 bool text_differs, 334 bool text_differs,
331 bool just_deleted_text, 335 bool just_deleted_text,
332 bool allow_keyword_ui_change); 336 bool allow_keyword_ui_change);
333 337
334 // Invoked when the popup is going to change its bounds to |bounds|. 338 // Invoked when the popup is going to change its bounds to |bounds|.
335 void PopupBoundsChangedTo(const gfx::Rect& bounds); 339 void PopupBoundsChangedTo(const gfx::Rect& bounds);
336 340
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
405 409
406 // Returns the default match for the current text, as well as the alternate 410 // Returns the default match for the current text, as well as the alternate
407 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL. 411 // nav URL, if |alternate_nav_url| is non-NULL and there is such a URL.
408 void GetInfoForCurrentText(AutocompleteMatch* match, 412 void GetInfoForCurrentText(AutocompleteMatch* match,
409 GURL* alternate_nav_url) const; 413 GURL* alternate_nav_url) const;
410 414
411 // Reverts the edit box from a temporary text back to the original user text. 415 // Reverts the edit box from a temporary text back to the original user text.
412 // If |revert_popup| is true then the popup will be reverted as well. 416 // If |revert_popup| is true then the popup will be reverted as well.
413 void RevertTemporaryText(bool revert_popup); 417 void RevertTemporaryText(bool revert_popup);
414 418
415 // Accepts current keyword if the user only typed a space at the end of 419 // Accepts current keyword if the user just typed a space at the end of
416 // |new_user_text| comparing to the |old_user_text|. 420 // |new_text|. This handles both of the following cases:
421 // (assume "foo" is a keyword, | is the input caret, [] is selected text)
422 // foo| -> foo | (a space was appended to a keyword)
423 // foo[bar] -> foo | (a space replaced other text after a keyword)
417 // Returns true if the current keyword is accepted. 424 // Returns true if the current keyword is accepted.
418 bool MaybeAcceptKeywordBySpace(const string16& old_user_text, 425 bool MaybeAcceptKeywordBySpace(const string16& new_text);
419 const string16& new_user_text);
420 426
421 // Checks if |allow_exact_keyword_match_| should be set to true according to 427 // Checks whether the user inserted a space into |old_text| and by doing so
422 // the old and new user text and the current caret position. It does not take 428 // created a |new_text| that looks like "<keyword> <search phrase>".
423 // other factors into account, e.g. if the view is ready to change the keyword 429 bool CreatedKeywordSearchByInsertingSpaceInMiddle(
424 // ui or not. This is only for the case of inserting a space character in the 430 const string16& old_text,
425 // middle of the text. See the comment of |allow_exact_keyword_match_| below. 431 const string16& new_text,
426 bool ShouldAllowExactKeywordMatch(const string16& old_user_text, 432 size_t caret_position) const;
427 const string16& new_user_text,
428 size_t caret_position);
429 433
430 // Tries to start an instant preview for |match|. Returns true if instant 434 // Tries to start an instant preview for |match|. Returns true if instant
431 // processed the match. 435 // processed the match.
432 bool DoInstant(const AutocompleteMatch& match, string16* suggested_text); 436 bool DoInstant(const AutocompleteMatch& match, string16* suggested_text);
433 437
434 // Starts a prerender for the given |match|. 438 // Starts a prerender for the given |match|.
435 void DoPrerender(const AutocompleteMatch& match); 439 void DoPrerender(const AutocompleteMatch& match);
436 440
437 // Starts a DNS prefetch for the given |match|. 441 // Starts a DNS prefetch for the given |match|.
438 void DoPreconnect(const AutocompleteMatch& match); 442 void DoPreconnect(const AutocompleteMatch& match);
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after
540 mutable GURL paste_and_go_alternate_nav_url_; 544 mutable GURL paste_and_go_alternate_nav_url_;
541 545
542 Profile* profile_; 546 Profile* profile_;
543 547
544 // This is needed as prior to accepting the current text the model is 548 // This is needed as prior to accepting the current text the model is
545 // reverted, which triggers resetting instant. We don't want to update instant 549 // reverted, which triggers resetting instant. We don't want to update instant
546 // in this case, so we use the flag to determine if this is happening. 550 // in this case, so we use the flag to determine if this is happening.
547 bool in_revert_; 551 bool in_revert_;
548 552
549 // Indicates if the upcoming autocomplete search is allowed to be treated as 553 // Indicates if the upcoming autocomplete search is allowed to be treated as
550 // an exact keyword match. If it's true then keyword mode will be triggered 554 // an exact keyword match. If this is true then keyword mode will be
551 // automatically if the input is "<keyword> <search string>". We only allow 555 // triggered automatically if the input is "<keyword> <search string>". We
552 // such trigger when: 556 // allow this when CreatedKeywordSearchByInsertingSpaceInMiddle() is true.
553 // 1.A single space character is added at the end of a keyword, such as: 557 // This has no effect if we're already in keyword mode.
554 // (assume "foo" is a keyword, | is the input caret)
555 // foo| -> foo |
556 // foo[bar] -> foo | ([bar] indicates a selected text "bar")
557 // 2.A single space character is inserted after a keyword when the caret is
558 // not at the end of the line, such as:
559 // foo|bar -> foo |bar
560 //
561 // It has no effect if a keyword is already selected.
562 bool allow_exact_keyword_match_; 558 bool allow_exact_keyword_match_;
563 559
564 // Last value of InstantCompleteBehavior supplied to |SetSuggestedText|. 560 // Last value of InstantCompleteBehavior supplied to |SetSuggestedText|.
565 InstantCompleteBehavior instant_complete_behavior_; 561 InstantCompleteBehavior instant_complete_behavior_;
566 562
567 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel); 563 DISALLOW_COPY_AND_ASSIGN(AutocompleteEditModel);
568 }; 564 };
569 565
570 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_ 566 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_EDIT_H_
OLDNEW
« no previous file with comments | « no previous file | chrome/browser/autocomplete/autocomplete_edit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698