OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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_POPUP_MODEL_H_ | 5 #ifndef CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_ |
6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_ | 6 #define CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_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 "chrome/browser/autocomplete/autocomplete.h" | 10 #include "chrome/browser/autocomplete/autocomplete.h" |
11 #include "chrome/browser/autocomplete/autocomplete_edit.h" | 11 #include "chrome/browser/autocomplete/autocomplete_edit.h" |
12 | 12 |
13 class AutocompletePopupView; | 13 class AutocompletePopupView; |
14 class Profile; | 14 class Profile; |
15 class SkBitmap; | 15 class SkBitmap; |
16 | 16 |
17 class AutocompletePopupModel { | 17 class AutocompletePopupModel { |
18 public: | 18 public: |
19 enum MatchState { | |
20 RESULT = 0, | |
Peter Kasting
2011/08/04 20:07:53
Nit: Maybe NORMAL would be better?
| |
21 KEYWORD | |
22 }; | |
23 | |
19 AutocompletePopupModel(AutocompletePopupView* popup_view, | 24 AutocompletePopupModel(AutocompletePopupView* popup_view, |
20 AutocompleteEditModel* edit_model, | 25 AutocompleteEditModel* edit_model, |
21 Profile* profile); | 26 Profile* profile); |
22 ~AutocompletePopupModel(); | 27 ~AutocompletePopupModel(); |
23 | 28 |
24 // Invoked when the profile has changed. | 29 // Invoked when the profile has changed. |
25 void set_profile(Profile* profile) { profile_ = profile; } | 30 void set_profile(Profile* profile) { profile_ = profile; } |
26 | 31 |
27 // TODO(sky): see about removing this. | 32 // TODO(sky): see about removing this. |
28 Profile* profile() const { return profile_; } | 33 Profile* profile() const { return profile_; } |
(...skipping 17 matching lines...) Expand all Loading... | |
46 } | 51 } |
47 | 52 |
48 // Call to change the hovered line. |line| should be within the range of | 53 // Call to change the hovered line. |line| should be within the range of |
49 // valid lines (to enable hover) or kNoMatch (to disable hover). | 54 // valid lines (to enable hover) or kNoMatch (to disable hover). |
50 void SetHoveredLine(size_t line); | 55 void SetHoveredLine(size_t line); |
51 | 56 |
52 size_t selected_line() const { | 57 size_t selected_line() const { |
53 return selected_line_; | 58 return selected_line_; |
54 } | 59 } |
55 | 60 |
61 MatchState selected_match() const { | |
62 return match_state_; | |
63 } | |
64 | |
56 // Call to change the selected line. This will update all state and repaint | 65 // Call to change the selected line. This will update all state and repaint |
57 // the necessary parts of the window, as well as updating the edit with the | 66 // the necessary parts of the window, as well as updating the edit with the |
58 // new temporary text. |line| will be clamped to the range of valid lines. | 67 // new temporary text. |line| will be clamped to the range of valid lines. |
59 // |reset_to_default| is true when the selection is being reset back to the | 68 // |reset_to_default| is true when the selection is being reset back to the |
60 // default match, and thus there is no temporary text (and no | 69 // default match, and thus there is no temporary text (and no |
61 // |manually_selected_match_|). If |force| is true then the selected line will | 70 // |manually_selected_match_|). If |force| is true then the selected line will |
62 // be updated forcibly even if the |line| is same as the current selected | 71 // be updated forcibly even if the |line| is same as the current selected |
63 // line. | 72 // line. |
64 // NOTE: This assumes the popup is open, and thus both old and new values for | 73 // NOTE: This assumes the popup is open, and thus both old and new values for |
65 // the selected line should not be kNoMatch. | 74 // the selected line should not be kNoMatch. |
66 void SetSelectedLine(size_t line, bool reset_to_default, bool force); | 75 void SetSelectedLine(size_t line, bool reset_to_default, bool force); |
67 | 76 |
68 // Called when the user hits escape after arrowing around the popup. This | 77 // Called when the user hits escape after arrowing around the popup. This |
69 // will change the selected line back to the default match and redraw. | 78 // will change the selected line back to the default match and redraw. |
70 void ResetToDefaultMatch(); | 79 void ResetToDefaultMatch(); |
71 | 80 |
72 // Gets the selected keyword or keyword hint for the given match. If the match | |
73 // is already keyword, then the keyword will be returned directly. Otherwise, | |
74 // it returns GetKeywordForText(match.fill_into_edit, keyword). | |
75 bool GetKeywordForMatch(const AutocompleteMatch& match, | |
76 string16* keyword) const; | |
77 | |
78 // Gets the selected keyword or keyword hint for the given text. Returns | |
79 // true if |keyword| represents a keyword hint, or false if |keyword| | |
80 // represents a selected keyword. (|keyword| will always be set [though | |
81 // possibly to the empty string], and you cannot have both a selected keyword | |
82 // and a keyword hint simultaneously.) | |
83 bool GetKeywordForText(const string16& text, string16* keyword) const; | |
84 | |
85 // Immediately updates and opens the popup if necessary, then moves the | 81 // Immediately updates and opens the popup if necessary, then moves the |
86 // current selection down (|count| > 0) or up (|count| < 0), clamping to the | 82 // current selection down (|count| > 0) or up (|count| < 0), clamping to the |
87 // first or last result if necessary. If |count| == 0, the selection will be | 83 // first or last result if necessary. If |count| == 0, the selection will be |
88 // unchanged, but the popup will still redraw and modify the text in the | 84 // unchanged, but the popup will still redraw and modify the text in the |
89 // AutocompleteEditModel. | 85 // AutocompleteEditModel. |
90 void Move(int count); | 86 void Move(int count); |
91 | 87 |
88 // If the selected line has both a normal match and a keyword match, this can | |
89 // be used to choose which to select. It is an error to call this when the | |
90 // selected line does not have both matches (or there is no selection). | |
91 void SetSelectedMatch(MatchState state); | |
92 | |
92 // Called when the user hits shift-delete. This should determine if the item | 93 // Called when the user hits shift-delete. This should determine if the item |
93 // can be removed from history, and if so, remove it and update the popup. | 94 // can be removed from history, and if so, remove it and update the popup. |
94 void TryDeletingCurrentItem(); | 95 void TryDeletingCurrentItem(); |
95 | 96 |
96 // If |match| is from an extension, returns the extension icon; otherwise | 97 // If |match| is from an extension, returns the extension icon; otherwise |
97 // returns NULL. | 98 // returns NULL. |
98 const SkBitmap* GetIconIfExtensionMatch(const AutocompleteMatch& match) const; | 99 const SkBitmap* GetIconIfExtensionMatch(const AutocompleteMatch& match) const; |
99 | 100 |
100 // The match the user has manually chosen, if any. | 101 // The match the user has manually chosen, if any. |
101 const AutocompleteResult::Selection& manually_selected_match() const { | 102 const AutocompleteResult::Selection& manually_selected_match() const { |
(...skipping 17 matching lines...) Expand all Loading... | |
119 Profile* profile_; | 120 Profile* profile_; |
120 | 121 |
121 // The line that's currently hovered. If we're not drawing a hover rect, | 122 // The line that's currently hovered. If we're not drawing a hover rect, |
122 // this will be kNoMatch, even if the cursor is over the popup contents. | 123 // this will be kNoMatch, even if the cursor is over the popup contents. |
123 size_t hovered_line_; | 124 size_t hovered_line_; |
124 | 125 |
125 // The currently selected line. This is kNoMatch when nothing is selected, | 126 // The currently selected line. This is kNoMatch when nothing is selected, |
126 // which should only be true when the popup is closed. | 127 // which should only be true when the popup is closed. |
127 size_t selected_line_; | 128 size_t selected_line_; |
128 | 129 |
130 // If the selected line has both a normal match and a keyword match, this | |
131 // determines whether the normal match (if SELECTED) or the keyword match | |
Peter Kasting
2011/08/04 20:07:53
Nit: Wrong enum value name
| |
132 // (if KEYWORD) is selected. | |
133 MatchState match_state_; | |
134 | |
129 // The match the user has manually chosen, if any. | 135 // The match the user has manually chosen, if any. |
130 AutocompleteResult::Selection manually_selected_match_; | 136 AutocompleteResult::Selection manually_selected_match_; |
131 | 137 |
132 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupModel); | 138 DISALLOW_COPY_AND_ASSIGN(AutocompletePopupModel); |
133 }; | 139 }; |
134 | 140 |
135 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_ | 141 #endif // CHROME_BROWSER_AUTOCOMPLETE_AUTOCOMPLETE_POPUP_MODEL_H_ |
OLD | NEW |