Commit 9068736c authored by Richard Knoll's avatar Richard Knoll Committed by Commit Bot

Fix inline reply opening with key press.

When opening the inline reply text view by clicking on the "Reply"
button, we get a LocatedEvent to start the ripple effect from. When this
is triggered via key press, after focusing the button, the event is not
a LocatedEvent and we hit a CHECK.
This fix shows the default ripple instead if we activate via keyboard.

Bug: 961233
Change-Id: I1f6488f9ce240b9c2cec07ff7342faa75781635a
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1602507Reviewed-by: default avatarPeter Beverloo <peter@chromium.org>
Commit-Queue: Richard Knoll <knollr@chromium.org>
Cr-Commit-Position: refs/heads/master@{#659054}
parent f43786de
......@@ -390,11 +390,13 @@ NotificationInputContainerMD::NotificationInputContainerMD(
NotificationInputContainerMD::~NotificationInputContainerMD() = default;
void NotificationInputContainerMD::AnimateBackground(
const ui::LocatedEvent& event) {
if (View::HitTestPoint(event.location()))
AnimateInkDrop(views::InkDropState::ACTION_PENDING,
ui::LocatedEvent::FromIfValid(&event));
void NotificationInputContainerMD::AnimateBackground(const ui::Event& event) {
// Try to get a located event. This can be NULL if triggered via keyboard.
const ui::LocatedEvent* located_event = ui::LocatedEvent::FromIfValid(&event);
// Use default animation if location is out of bounds.
if (located_event && !View::HitTestPoint(located_event->location()))
located_event = nullptr;
AnimateInkDrop(views::InkDropState::ACTION_PENDING, located_event);
}
void NotificationInputContainerMD::AddInkDropLayer(ui::Layer* ink_drop_layer) {
......@@ -742,7 +744,7 @@ void NotificationViewMD::ButtonPressed(views::Button* sender,
? l10n_util::GetStringUTF16(
IDS_MESSAGE_CENTER_NOTIFICATION_INLINE_REPLY_PLACEHOLDER)
: *placeholder);
inline_reply_->AnimateBackground(*event.AsLocatedEvent());
inline_reply_->AnimateBackground(event);
inline_reply_->SetVisible(true);
action_buttons_row_->SetVisible(false);
// RequestFocus() should be called after SetVisible().
......@@ -1330,14 +1332,17 @@ void NotificationViewMD::AddBackgroundAnimation(const ui::Event& event) {
const gfx::Point& location = event.AsLocatedEvent()->location();
gfx::Point converted_location(location);
View::ConvertPointToTarget(target, this, &converted_location);
// Use default animation if location is out of bounds.
if (!View::HitTestPoint(converted_location)) {
AnimateInkDrop(views::InkDropState::ACTION_PENDING, nullptr);
return;
}
std::unique_ptr<ui::Event> cloned_event = ui::Event::Clone(event);
ui::LocatedEvent* cloned_located_event = cloned_event->AsLocatedEvent();
cloned_located_event->set_location(converted_location);
if (View::HitTestPoint(event.AsLocatedEvent()->location())) {
AnimateInkDrop(views::InkDropState::ACTION_PENDING,
ui::LocatedEvent::FromIfValid(cloned_located_event));
}
AnimateInkDrop(views::InkDropState::ACTION_PENDING, cloned_located_event);
}
void NotificationViewMD::RemoveBackgroundAnimation() {
......
......@@ -123,7 +123,7 @@ class NotificationInputContainerMD : public views::InkDropHostView,
NotificationInputContainerMD(NotificationInputDelegate* delegate);
~NotificationInputContainerMD() override;
void AnimateBackground(const ui::LocatedEvent& event);
void AnimateBackground(const ui::Event& event);
// Overridden from views::InkDropHostView:
void AddInkDropLayer(ui::Layer* ink_drop_layer) override;
......@@ -223,6 +223,8 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestDeleteOnToggleExpanded);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestIconSizing);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, TestInlineReply);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest,
TestInlineReplyActivateWithKeyPress);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest,
TestInlineReplyRemovedByUpdate);
FRIEND_TEST_ALL_PREFIXES(NotificationViewMDTest, UpdateAddingIcon);
......
......@@ -739,6 +739,30 @@ TEST_F(NotificationViewMDTest, TestInlineReplyRemovedByUpdate) {
EXPECT_FALSE(notification_view()->actions_row_->visible());
}
TEST_F(NotificationViewMDTest, TestInlineReplyActivateWithKeyPress) {
std::unique_ptr<Notification> notification = CreateSimpleNotification();
std::vector<ButtonInfo> buttons = CreateButtons(2);
buttons[1].placeholder = base::string16();
notification->set_buttons(buttons);
UpdateNotificationViews(*notification);
widget()->Show();
// Action buttons are hidden by collapsed state.
if (!notification_view()->expanded_)
notification_view()->ToggleExpanded();
ui::test::EventGenerator generator(GetRootWindow(widget()));
// Press and release space key to open inline reply text field.
// Note: VKEY_RETURN should work too, but triggers a click on MacOS.
notification_view()->action_buttons_[1]->RequestFocus();
generator.PressKey(ui::VKEY_SPACE, ui::EF_NONE);
generator.ReleaseKey(ui::VKEY_SPACE, ui::EF_NONE);
EXPECT_TRUE(notification_view()->inline_reply_->visible());
}
// Synthetic scroll events are not supported on Mac in the views
// test framework.
#if defined(OS_MACOSX)
......
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