#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:
当用户按下回车键,就会调用上面的函数
OnKeyDownOnlyWritable
,并且在
VK_RETURN
按键处理回车的事件,接着就是调用函数
AcceptInput
来处理。
这个函数的代码如下:
#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;
保存当前获取的
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
判断是否重新加载当前的网页。
#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
这里是调用
OpenURL
函数打开这个连接的内容。
#028
OpenURL(url, disposition, transition, alternate_nav_url,
#029
AutocompletePopupModel::kNoMatch,
#030
is_keyword_hint_ ? std::wstring() : keyword_);
#031
}
这段代码的流程很清楚,就是先通过判断按键输入,是否按下回车键,如果是回车键就调用函数
AcceptInput
处理,然后在这个函数就判断这个连接是否已经打开了,如果已经打开,只需要重新加载就行了,如果不是当前的,就是打开一个新的连接。下一次再来分析
OpenURL
函数是怎么样通过连接来重新加载,还是打开一个新网页。