Commit 49d02cd2 authored by msw@chromium.org's avatar msw@chromium.org

Re-land: Store and restore view focus in OnWindowFocused.

r271281 reverted the first r271249 for Win XP test failures:

http://build.chromium.org/p/chromium.win/builders/XP%20Tests%20%281%29/builds/31239/steps/interactive_ui_tests/logs/stdio
[ RUN      ] ConstrainedWindowViewTest.ClosesOnEscape
[216:3316:0517/130516:ERROR:gpu_info_collector_win.cc(103)] Can't retrieve a valid WinSAT assessment.
c:\b\build\slave\cr-win-rel\build\src\chrome\browser\ui\views\constrained_window_views_browsertest.cc(206): error: Value of: dialog->GetWidget()
  Actual: 08C1F9C0
Expected: 0
Which is: NULL

This CL makes that test no-op on XP; I'll follow up in Issue 177482.

------------------------------------------------------------
Mimic [Desktop]NativeWidgetAura::OnWindowActivated.
Simplify OnNativeBlur calls and OnNative[Blur|Focus] impls.
(View focus changes update the TextInputClient as needed)
Rewrite and enable related ConstrainedWindowViewTests.

Print GetLastError() in SendInput() error case for tests.
(key presses get 5/ERROR_ACCESS_DENIED on locked desktops?)

BUG=368691, 170331, 177482, 163931
TEST=Automated tests; the focused Views change as expected between the browser, web contents, and web content modal dialogs (print preview, collected cookies, etc.).
TBR=sky@chromium.org

Review URL: https://codereview.chromium.org/285403003

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@271312 0039d316-1c4b-4281-b951-d872f2087c98
parent f4a752ee
......@@ -43,7 +43,7 @@ HRESULT ForegroundHelper::ForegroundHotKey(HWND window) {
hotkey.type = INPUT_KEYBOARD;
hotkey.ki.wVk = VK_F22;
if (1 != SendInput(1, &hotkey, sizeof(hotkey))) {
LOG(WARNING) << "Failed to send input";
LOG(WARNING) << "Failed to send input; GetLastError(): " << GetLastError();
return E_FAIL;
}
......
......@@ -258,6 +258,7 @@ DesktopNativeWidgetAura::DesktopNativeWidgetAura(
native_widget_delegate_(delegate),
last_drop_operation_(ui::DragDropTypes::DRAG_NONE),
restore_focus_on_activate_(false),
restore_focus_on_window_focus_(false),
cursor_(gfx::kNullCursor),
widget_type_(Widget::InitParams::TYPE_WINDOW) {
aura::client::SetFocusChangeObserver(content_window_, this);
......@@ -1082,15 +1083,23 @@ void DesktopNativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
native_widget_delegate_->OnNativeFocus(lost_focus);
// If focus is moving from a descendant Window to |content_window_| then
// native activation hasn't changed. We still need to inform the InputMethod
// we've been focused though.
// native activation hasn't changed. Still, the InputMethod and FocusManager
// must be informed of the Window focus change.
InputMethod* input_method = GetWidget()->GetInputMethod();
if (input_method)
input_method->OnFocus();
if (restore_focus_on_window_focus_) {
restore_focus_on_window_focus_ = false;
GetWidget()->GetFocusManager()->RestoreFocusedView();
}
} else if (content_window_ == lost_focus) {
desktop_window_tree_host_->OnNativeWidgetBlur();
native_widget_delegate_->OnNativeBlur(
aura::client::GetFocusClient(content_window_)->GetFocusedWindow());
native_widget_delegate_->OnNativeBlur(gained_focus);
DCHECK(!restore_focus_on_window_focus_);
restore_focus_on_window_focus_ = true;
GetWidget()->GetFocusManager()->StoreFocusedView(false);
}
}
......
......@@ -294,6 +294,7 @@ class VIEWS_EXPORT DesktopNativeWidgetAura
window_modality_controller_;
bool restore_focus_on_activate_;
bool restore_focus_on_window_focus_;
gfx::NativeCursor cursor_;
// We must manually reference count the number of users of |cursor_manager_|
......
......@@ -895,6 +895,7 @@ void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
if (GetWidget()->GetInputMethod()) // Null in tests.
GetWidget()->GetInputMethod()->OnFocus();
delegate_->OnNativeFocus(lost_focus);
GetWidget()->GetFocusManager()->RestoreFocusedView();
} else if (window_ == lost_focus) {
// GetInputMethod() recreates the input method if it's previously been
// destroyed. If we get called during destruction, the input method will be
......@@ -910,9 +911,8 @@ void NativeWidgetAura::OnWindowFocused(aura::Window* gained_focus,
DCHECK_EQ(ownership_, Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET);
}
aura::client::FocusClient* client = aura::client::GetFocusClient(window_);
if (client) // NULL during destruction of aura::Window.
delegate_->OnNativeBlur(client->GetFocusedWindow());
delegate_->OnNativeBlur(gained_focus);
GetWidget()->GetFocusManager()->StoreFocusedView(true);
}
}
......
......@@ -1045,19 +1045,11 @@ void Widget::OnNativeWidgetActivationChanged(bool active) {
}
void Widget::OnNativeFocus(gfx::NativeView old_focused_view) {
// Ensure the focused view's TextInputClient is used for text input.
views::FocusManager* focus_manager = GetFocusManager();
focus_manager->FocusTextInputClient(focus_manager->GetFocusedView());
WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(old_focused_view,
GetNativeView());
}
void Widget::OnNativeBlur(gfx::NativeView new_focused_view) {
// Ensure the focused view's TextInputClient is not used for text input.
views::FocusManager* focus_manager = GetFocusManager();
focus_manager->BlurTextInputClient(focus_manager->GetFocusedView());
WidgetFocusManager::GetInstance()->OnWidgetFocusEvent(GetNativeView(),
new_focused_view);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment