#001
?
bool AutocompleteEdit::OnKeyDownOnlyWritable(TCHAR key,
#002
??????????????????????????????????????????????
UINT repeat_count,
#003
??????????????????????????????????????????????
UINT flags) {
#004
???
// NOTE: Annoyingly, ctrl-alt-<key> generates WM_KEYDOWN rather than
#005
???
// WM_SYSKEYDOWN, so we need to check (flags & KF_ALTDOWN) in various places
#006
???
// in this function even with a WM_SYSKEYDOWN handler.
#007
?
#008
???
int count = repeat_count;
#009
???
switch (key) {
#010
?????
case VK_RETURN:
#011
???????
AcceptInput((flags & KF_ALTDOWN) ? NEW_FOREGROUND_TAB : CURRENT_TAB,
#012
???????????????????
false);
#013
???????
return true;
#014
?
#015
?????
case VK_UP:
#016
???????
count = -count;
#017
???????
// FALL THROUGH
#018
????
?
case VK_DOWN:
當(dāng)用戶按下回車鍵,就會調(diào)用上面的函數(shù)
OnKeyDownOnlyWritable
,并且在
VK_RETURN
按鍵處理回車的事件,接著就是調(diào)用函數(shù)
AcceptInput
來處理。
這個函數(shù)的代碼如下:
#001
?
void AutocompleteEdit::AcceptInput(WindowOpenDisposition disposition,
#002
????????????????????????????????????
bool for_drop) {
#003
???
// Get the URL and transition type for the selected entry.
#004
???
PageTransition::Type transition;
#005
???
bool is_history_what_you_typed_match;
#006
???
std::wstring alternate_nav_url;
保存當(dāng)前獲取的
URL
連接串。
#007
???
const std::wstring url(GetURLForCurrentText(&transition,
#008
???????????????????????????????????????????????
&is_history_what_you_typed_match,
#009
???????????????????????????????????????????????
&alternate_nav_url));
#010
???
if (url.empty())
#011
?????
return;
#012
?
判斷是否重新加載當(dāng)前的網(wǎng)頁。
#013
???
if (url == permanent_text_) {
#014
???
??
// When the user hit enter on the existing permanent URL, treat it like a
#015
?????
// reload for scoring purposes.
?
We could detect this by just checking
#016
?????
// user_input_in_progress_, but it seems better to treat "edits" that end
#017
?????
// up leaving the URL unchanged (e.g. deleting the last character and then
#018
?????
// retyping it) as reloads too.
#019
?????
transition = PageTransition::RELOAD;
#020
???
} else if (for_drop || ((paste_state_ != NONE) &&
#021
???????????????????????????
is_history_what_you_typed_match)) {
下面是打開一個新的連接。
#022
?????
// When the user pasted in a URL and hit enter, score it like a link click
#023
?????
// rather than a normal typed URL, so it doesn't get inline autocompleted
#024
?????
// as aggressively later.
#025
?????
transition = PageTransition::LINK;
#026
???
}
#027
?
這里是調(diào)用
OpenURL
函數(shù)打開這個連接的內(nèi)容。
#028
???
OpenURL(url, disposition, transition, alternate_nav_url,
#029
???????????
AutocompletePopupModel::kNoMatch,
#030
???????????
is_keyword_hint_ ? std::wstring() : keyword_);
#031
?
}
這段代碼的流程很清楚,就是先通過判斷按鍵輸入,是否按下回車鍵,如果是回車鍵就調(diào)用函數(shù)
AcceptInput
處理,然后在這個函數(shù)就判斷這個連接是否已經(jīng)打開了,如果已經(jīng)打開,只需要重新加載就行了,如果不是當(dāng)前的,就是打開一個新的連接。下一次再來分析
OpenURL
函數(shù)是怎么樣通過連接來重新加載,還是打開一個新網(wǎng)頁。
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

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