Commit b29b6322 authored by Sammie Quon's avatar Sammie Quon Committed by Commit Bot

shelf: Send key up press as well on back button click.

It originally send key down on tap down, and key up on tap, but this
was changed to just key down on tap, because some gestures send the tap
event and the browser listens to just the key up.

But ARC apps need the entire sequence, so this sends both on click.

Original bug: https://bugs.chromium.org/p/chromium/issues/detail?id=943154

Test: manual
Bug: b/129248267
Change-Id: I5e5d16f4dc6a675d1a96936ad938e5201ad74aa1
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1542224
Commit-Queue: Sammie Quon <sammiequon@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#646441}
parent d40ec85f
......@@ -10,7 +10,6 @@
#include "ui/base/hit_test.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/events/event_sink.h"
#include "ui/strings/grit/ui_strings.h"
#include "ui/views/widget/widget.h"
#include "ui/views/window/caption_button_layout_constants.h"
......@@ -29,15 +28,14 @@ FrameBackButton::~FrameBackButton() = default;
void FrameBackButton::ButtonPressed(Button* sender, const ui::Event& event) {
// Send up event as well as down event as ARC++ clients expect this sequence.
// TODO: Investigate if we should be using the current modifiers.
aura::Window* root_window = GetWidget()->GetNativeWindow()->GetRootWindow();
ui::KeyEvent press_key_event(ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
ignore_result(root_window->GetHost()->event_sink()->OnEventFromSource(
&press_key_event));
ignore_result(root_window->GetHost()->SendEventToSink(&press_key_event));
ui::KeyEvent release_key_event(ui::ET_KEY_RELEASED, ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
ignore_result(root_window->GetHost()->event_sink()->OnEventFromSource(
&release_key_event));
ignore_result(root_window->GetHost()->SendEventToSink(&release_key_event));
}
} // namespace ash
......@@ -5,24 +5,12 @@
#include "ash/shelf/back_button.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/shelf/shelf.h"
#include "ash/shelf/shelf_constants.h"
#include "ash/shelf/shelf_view.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/tray/tray_popup_utils.h"
#include "ash/wm/tablet_mode/tablet_mode_controller.h"
#include "base/metrics/user_metrics.h"
#include "base/metrics/user_metrics_action.h"
#include "ui/aura/window.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/events/event_sink.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/paint_vector_icon.h"
#include "ui/views/animation/flood_fill_ink_drop_ripple.h"
#include "ui/views/animation/ink_drop_impl.h"
#include "ui/views/animation/ink_drop_mask.h"
#include "ui/views/widget/widget.h"
namespace ash {
......@@ -36,15 +24,18 @@ BackButton::BackButton(ShelfView* shelf_view) : ShelfControlButton(shelf_view) {
BackButton::~BackButton() = default;
void BackButton::OnGestureEvent(ui::GestureEvent* event) {
ShelfButton::OnGestureEvent(event);
if (event->type() == ui::ET_GESTURE_TAP)
GenerateAndSendBackEvent();
}
void BackButton::OnMouseReleased(const ui::MouseEvent& event) {
ShelfButton::OnMouseReleased(event);
GenerateAndSendBackEvent();
void BackButton::NotifyClick(const ui::Event& event) {
Button::NotifyClick(event);
// Send up event as well as down event as ARC++ clients expect this sequence.
// TODO: Investigate if we should be using the current modifiers.
aura::Window* root_window = GetWidget()->GetNativeWindow()->GetRootWindow();
ui::KeyEvent press_key_event(ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
ignore_result(root_window->GetHost()->SendEventToSink(&press_key_event));
ui::KeyEvent release_key_event(ui::ET_KEY_RELEASED, ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
ignore_result(root_window->GetHost()->SendEventToSink(&release_key_event));
}
void BackButton::PaintButtonContents(gfx::Canvas* canvas) {
......@@ -59,18 +50,4 @@ const char* BackButton::GetClassName() const {
return kViewClassName;
}
void BackButton::GenerateAndSendBackEvent() {
base::RecordAction(base::UserMetricsAction("Tablet_BackButton"));
// Send the back event to the root window of the back button's widget.
const views::Widget* widget = GetWidget();
if (widget && widget->GetNativeWindow()) {
aura::Window* root_window = widget->GetNativeWindow()->GetRootWindow();
ui::KeyEvent key_event(ui::ET_KEY_PRESSED, ui::VKEY_BROWSER_BACK,
ui::EF_NONE);
ignore_result(
root_window->GetHost()->event_sink()->OnEventFromSource(&key_event));
}
}
} // namespace ash
......@@ -25,18 +25,11 @@ class ASH_EXPORT BackButton : public ShelfControlButton {
protected:
// views::Button:
void OnGestureEvent(ui::GestureEvent* event) override;
void OnMouseReleased(const ui::MouseEvent& event) override;
void NotifyClick(const ui::Event& event) override;
void PaintButtonContents(gfx::Canvas* canvas) override;
const char* GetClassName() const override;
private:
// Generate and send a VKEY_BROWSER_BACK key event sequence when the back
// button is pressed. This should on be called on a tap down or mouse release
// event, and will only send a key down event since that is the one which
// triggers the back event.
void GenerateAndSendBackEvent();
DISALLOW_COPY_AND_ASSIGN(BackButton);
};
......
......@@ -117,7 +117,7 @@ TEST_F(BackButtonTest, BackKeySequenceGenerated) {
generator->ReleaseLeftButton();
EXPECT_EQ(1, target_back_press.accelerator_count());
EXPECT_EQ(0, target_back_release.accelerator_count());
EXPECT_EQ(1, target_back_release.accelerator_count());
}
} // namespace ash
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