0

capture-mode-demo-tools: Do not show widget when focusing input field

To respect user privacy and be consistent in certain use cases, we
will not show key combo viewer when the input text field is focused.
The demo for this CL is available at http://b/266014677#comment2

Fixed: b:266014677
Test: Manually + modified unit test
Change-Id: If4dcf1cf7164fd90f5024abe0fb11f4cb71b7980
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4179636
Reviewed-by: Ahmed Fakhry <afakhry@chromium.org>
Commit-Queue: Michele Fan <michelefan@chromium.org>
Cr-Commit-Position: refs/heads/main@{#1094609}
This commit is contained in:
Michele Fan
2023-01-19 19:44:42 +00:00
committed by Chromium LUCI CQ
parent 82649ed39c
commit e156f19271
3 changed files with 65 additions and 50 deletions

@ -127,14 +127,6 @@ void CaptureModeDemoToolsController::OnKeyEvent(ui::KeyEvent* event) {
return;
}
// We will not show key combo widget if the cursor is in the input text field
// to respect the user privacy. This check needs to be placed after checking
// the key up event as the key combo widget on display will still need to be
// refreshed.
if (in_password_text_input_) {
return;
}
DCHECK_EQ(event->type(), ui::ET_KEY_PRESSED);
OnKeyDownEvent(event);
}
@ -237,6 +229,14 @@ void CaptureModeDemoToolsController::OnKeyUpEvent(ui::KeyEvent* event) {
}
void CaptureModeDemoToolsController::OnKeyDownEvent(ui::KeyEvent* event) {
// We will not show key combo widget if the cursor is in the input text field
// to respect the user privacy. This check needs to be placed after checking
// the key up event as the key combo widget on display will still need to be
// refreshed.
if (in_text_input_) {
return;
}
const ui::KeyboardCode key_code = event->key_code();
// Return directly if it is a repeated key event for non-modifier key.
@ -301,8 +301,8 @@ void CaptureModeDemoToolsController::AnimateToResetTheWidget() {
void CaptureModeDemoToolsController::UpdateTextInputType(
const ui::TextInputClient* client) {
in_password_text_input_ =
client && client->GetTextInputType() == ui::TEXT_INPUT_TYPE_PASSWORD;
in_text_input_ =
client && client->GetTextInputType() != ui::TEXT_INPUT_TYPE_NONE;
}
void CaptureModeDemoToolsController::OnMouseHighlightAnimationEnded(

@ -118,9 +118,9 @@ class CaptureModeDemoToolsController : public ui::InputMethodObserver {
// The most recently pressed non-modifier key.
ui::KeyboardCode last_non_modifier_key_ = ui::VKEY_UNKNOWN;
// True if the cursor and focus is currently in a password text input
// True if the cursor and focus is currently in a text input
// field, false otherwise.
bool in_password_text_input_ = false;
bool in_text_input_ = false;
// Used to hold on `RefreshKeyComboViewer`. The key combo widget will be
// scheduled to hide after `capture_mode::kRefreshKeyComboWidgetLongDelay`

@ -34,6 +34,7 @@
#include "base/timer/timer.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/ime/fake_text_input_client.h"
#include "ui/base/ime/text_input_type.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/events/event_constants.h"
#include "ui/events/keycodes/keyboard_codes_posix.h"
@ -487,50 +488,64 @@ TEST_F(CaptureModeDemoToolsTest, AllIconKeysTest) {
}
}
// Tests that the key combo viewer widget will not show if the password input
// Tests that the key combo viewer widget will not show if the input
// field is currently focused and will display in a normal way when the focus is
// detached.
TEST_F(CaptureModeDemoToolsTest, DoNotShowKeyComboViewerInInputField) {
EnableTextInputFocus(ui::TEXT_INPUT_TYPE_PASSWORD);
CaptureModeController* controller = StartCaptureSession(
CaptureModeSource::kFullscreen, CaptureModeType::kVideo);
controller->EnableDemoTools(true);
StartVideoRecordingImmediately();
EXPECT_TRUE(controller->is_recording_in_progress());
CaptureModeDemoToolsController* demo_tools_controller =
GetCaptureModeDemoToolsController();
CaptureModeDemoToolsTestApi demo_tools_test_api(demo_tools_controller);
auto* event_generator = GetEventGenerator();
for (const auto input_type :
{ui::TEXT_INPUT_TYPE_TEXT, ui::TEXT_INPUT_TYPE_PASSWORD,
ui::TEXT_INPUT_TYPE_SEARCH, ui::TEXT_INPUT_TYPE_EMAIL,
ui::TEXT_INPUT_TYPE_NUMBER, ui::TEXT_INPUT_TYPE_TELEPHONE,
ui::TEXT_INPUT_TYPE_URL, ui::TEXT_INPUT_TYPE_DATE,
ui::TEXT_INPUT_TYPE_DATE_TIME, ui::TEXT_INPUT_TYPE_DATE_TIME_LOCAL,
ui::TEXT_INPUT_TYPE_MONTH, ui::TEXT_INPUT_TYPE_TIME,
ui::TEXT_INPUT_TYPE_WEEK, ui::TEXT_INPUT_TYPE_TEXT_AREA,
ui::TEXT_INPUT_TYPE_CONTENT_EDITABLE,
ui::TEXT_INPUT_TYPE_DATE_TIME_FIELD, ui::TEXT_INPUT_TYPE_NULL}) {
EnableTextInputFocus(input_type);
CaptureModeController* controller = StartCaptureSession(
CaptureModeSource::kFullscreen, CaptureModeType::kVideo);
controller->EnableDemoTools(true);
StartVideoRecordingImmediately();
EXPECT_TRUE(controller->is_recording_in_progress());
CaptureModeDemoToolsController* demo_tools_controller =
GetCaptureModeDemoToolsController();
CaptureModeDemoToolsTestApi demo_tools_test_api(demo_tools_controller);
auto* event_generator = GetEventGenerator();
// With the password input text focus enabled before the video recording, the
// key combo viewer will not display when pressing 'Ctrl' and 'T'.
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_FALSE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_FALSE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
// With the input text focus enabled before the video recording, the
// key combo viewer will not display when pressing 'Ctrl' and 'T'.
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_FALSE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_FALSE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
// Disable the input text focus, the key combo viewer will show when
// pressing 'Ctrl' and 'T' in a non-input-text field.
DisableTextInputFocus();
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_TRUE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_TRUE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
FireTimerAndVerifyWidget(/*should_hide_view=*/true);
// Disable the input text focus, the key combo viewer will show when
// pressing 'Ctrl' and 'T' in a non-input-text field.
DisableTextInputFocus();
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_TRUE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_TRUE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
FireTimerAndVerifyWidget(/*should_hide_view=*/true);
// Enable the password text input focus during the recording, the key combo
// viewer will not display when pressing 'Ctrl' and 'T'.
EnableTextInputFocus(ui::TEXT_INPUT_TYPE_PASSWORD);
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_FALSE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_FALSE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
// Enable the text input focus during the recording, the key combo
// viewer will not display when pressing 'Ctrl' and 'T'.
EnableTextInputFocus(input_type);
event_generator->PressKey(ui::VKEY_CONTROL, ui::EF_NONE);
event_generator->PressKey(ui::VKEY_T, ui::EF_NONE);
EXPECT_FALSE(demo_tools_test_api.GetDemoToolsWidget());
EXPECT_FALSE(demo_tools_test_api.GetKeyComboView());
event_generator->ReleaseKey(ui::VKEY_T, ui::EF_NONE);
event_generator->ReleaseKey(ui::VKEY_CONTROL, ui::EF_NONE);
controller->EndVideoRecording(EndRecordingReason::kStopRecordingButton);
WaitForCaptureFileToBeSaved();
}
}
// verifies that after any key release, if the remaining pressed keys are no