#001
?
void AutocompleteEdit::UpdatePopup() {
凍結輸入。
#002
???
ScopedFreeze freeze(this, GetTextObjectModel());
設置正在輸入過程中。
#003
???
SetInputInProgress(true);
#004
?
如果輸入的
EDIT
框沒有焦點,就直接返回。
#005
???
if (!has_focus_) {
#006
?????
// When we're in the midst of losing focus, don't rerun autocomplete.
?
This
#007
?????
// can happen when losing focus causes the IME to cancel/finalize a
#008
?????
// composition.
?
We still want to note that user input is in progress, we
#009
?????
// just don't want to do anything else.
#010
?????
//
#011
?????
// Note that in this case the ScopedFreeze above was unnecessary; however,
#012
?????
// we're inside the callstack of OnKillFocus(), which has already frozen the
#013
?????
// edit, so this will never result in an unnecessary UpdateWindow() call.
#014
?????
return;
#015
???
}
#016
?
#017
???
// Figure out whether the user is trying to compose something in an IME.
判斷是否從輸入法打開,如果是就從輸入法窗口里獲取字符串。
#018
???
bool ime_composing = false;
#019
???
HIMC context = ImmGetContext(m_hWnd);
#020
???
if (context) {
#021
?????
ime_composing = !!ImmGetCompositionString(context, GCS_COMPSTR, NULL, 0);
#022
?????
ImmReleaseContext(m_hWnd, context);
#023
???
}
#024
?
#025
???
// Don't inline autocomplete when:
#026
???
//
??
* The user is deleting text
#027
???
//
??
* The caret/selection isn't at the end of the text
#028
???
//
??
* The user has just pasted in something that replaced all the text
#029
???
//
??
* The user is trying to compose something in an IME
獲取當前選擇的字符串。
#030
???
CHARRANGE sel;
#031
???
GetSel(sel);
根據用戶輸入的字符串來查找智能提示菜單的內容。
#032
???
popup_->StartAutocomplete(user_text_, GetDesiredTLD(),
#033
???????
just_deleted_text_ || (sel.cpMax < GetTextLength()) ||
#034
???????
(paste_state_ != NONE) || ime_composing);
#035
?
}
在這個函數里主要調用類
AutocompletePopupModel
的函數
StartAutocomplete
來完成智能提示。而類
AutocompletePopupModel
的聲明如下:
class AutocompletePopupModel : public ACControllerListener, public Task {
?
public:
?
AutocompletePopupModel(const ChromeFont& font,
????????????????????????
AutocompleteEdit* editor,
????????????????????????
Profile* profile);
?
~AutocompletePopupModel();
從這個類里可以看到它是繼承類
ACControllerListener
,說明它是響應一個返回結果的監聽器;繼承類
Task
說明它是一個任務線程類。由這兩個類可以看出,它是把關鍵字給一個線程,然后讓這個線程去查詢結果,當結果返回時,就再更新到顯示窗口里。
雖然上面理解它的查詢過程了,但是向誰查詢呢?這是一個一定需要了解的問題。現在就來分析類
AutocompleteController
,它在構造函數時,就會創建三個查詢的對象:
#001
?
AutocompleteController::AutocompleteController(ACControllerListener* listener,
#002
????????????????????????????????????????????????
Profile* profile)
#003
?????
: listener_(listener) {
#004
???
providers_.push_back(new
SearchProvider
(this, profile));
#005
???
providers_.push_back(new
HistoryURLProvider
(this, profile));
#006
???
keyword_provider_ = new
KeywordProvider
(this, profile);
#007
???
providers_.push_back(keyword_provider_);
#008
???
if (listener) {
#009
?????
// These providers are async-only, so there's no need to create them when
#010
?????
// we'll only be doing synchronous queries.
#011
?????
history_contents_provider_ = new
HistoryContentsProvider
(this, profile);
#012
?????
providers_.push_back(history_contents_provider_);
#013
???
} else {
#014
?????
history_contents_provider_ = NULL;
#015
???
}
#016
???
for (ACProviders::iterator i(providers_.begin()); i != providers_.end(); ++i)
#017
?????
(*i)->AddRef();
#018
?
}
從上面的代碼,可以看到它是向
SearchProvider
、
HistoryURLProvider
、
KeywordProvider
和
HistoryContentsProvider
來查找到合適的智能提示。類
SearchProvider
是從搜索引擎里查找合適的內容;類
HistoryURLProvider
是從歷史的
URL
里查找合適的內容;類
KeywordProvider
是從關鍵字搜索引擎里查找合適的內容;類
HistoryContentsProvider
是從歷史內容里查找合適內容。從上面四種智能提示里,在以前的瀏覽器里一般只能做到從歷史的
URL
里提示,現在“可多米”可以做到從搜索引擎和關鍵字引擎里查找到相應的結果回來,可見它是智能提示完美的體現,智能的水平可想而知了。這就是強大的云計算典型應用,如果沒有強大的服務器群是做不到幾億人輸入關鍵字時,還能快速返回結果的。
分析到這里,也許知道為什么
GOOGLE
開發瀏覽器的原因了吧,如果其它瀏覽是不可能采用這樣的技術來分析用戶的輸入的,頂多是到歷史記錄里查找一下就算了。
雖然提供這么強大的搜索,它們又是怎么樣實現的呢?下一次再來分析它們。
更多文章、技術交流、商務合作、聯系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號聯系: 360901061
您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
