Commit 31c78ffa authored by Yuki Awano's avatar Yuki Awano Committed by Commit Bot

Do not reroute events for the tray

- Do not reroute events if it is targetted to the tray or its
  descendants, or if target of the event has window of the tray as a
  transient ancestor.
- When network info bubble is shown, the bubble is active but the tray
  itself is not active. The bubble is shown as another widget. The
  bubble should receive key events in this case. If the handler reroutes
  key events in this case, the tray is closed when esc key is pressed
  while the bubble is shown.

      information icon. Press esc key to close the info bubble. Confirm
      that it only closes the info bubble.

Bug: 758530
Test: Open network section of system tray by click. Click the
Change-Id: I0df0c81e4df28785f16fdefb9af37a73f00ef604
Reviewed-on: https://chromium-review.googlesource.com/776255Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Commit-Queue: Yuki Awano <yawano@chromium.org>
Cr-Commit-Position: refs/heads/master@{#523384}
parent 01c25d47
......@@ -1057,4 +1057,43 @@ TEST_F(SystemTrayTest, AcceleratorController) {
EXPECT_FALSE(tray->IsSystemBubbleVisible());
}
// When system tray has an active child widget, the child widget should consume
// key event and the tray shouldn't consume key event, i.e. RerouteEventHandler
// in TrayBubbleView should not reroute key events to the tray in this case.
TEST_F(SystemTrayTest, ActiveChildWidget) {
SystemTray* tray = GetPrimarySystemTray();
tray->ShowDefaultView(BUBBLE_CREATE_NEW, true /* show_by_click */);
// Create a child widget on system tray and focus it.
views::Widget* child_widget = views::Widget::CreateWindowWithParent(
nullptr, tray->GetBubbleView()->GetWidget()->GetNativeView());
std::unique_ptr<KeyEventConsumerView> consumer_view(
new KeyEventConsumerView());
child_widget->GetContentsView()->AddChildView(consumer_view.get());
child_widget->Show();
consumer_view->RequestFocus();
ASSERT_FALSE(tray->GetBubbleView()->GetWidget()->IsActive());
ASSERT_TRUE(child_widget->IsActive());
ui::test::EventGenerator& event_generator = GetEventGenerator();
// Press ESC key and confirm that child widget consumes it. Also confirm that
// the tray does not consume the key event.
ASSERT_EQ(0, consumer_view->number_of_consumed_key_events());
ASSERT_TRUE(tray->IsSystemBubbleVisible());
event_generator.PressKey(ui::VKEY_ESCAPE, ui::EF_NONE);
event_generator.ReleaseKey(ui::VKEY_ESCAPE, ui::EF_NONE);
EXPECT_EQ(2, consumer_view->number_of_consumed_key_events());
EXPECT_TRUE(tray->IsSystemBubbleVisible());
// Hide child widget and press ESC key. Confirm that the tray consumes it and
// the tray is closed even if the tray is not active.
child_widget->Hide();
ASSERT_FALSE(tray->GetBubbleView()->GetWidget()->IsActive());
event_generator.PressKey(ui::VKEY_ESCAPE, ui::EF_NONE);
event_generator.ReleaseKey(ui::VKEY_ESCAPE, ui::EF_NONE);
EXPECT_FALSE(tray->IsSystemBubbleVisible());
}
} // namespace ash
......@@ -30,6 +30,7 @@
#include "ui/views/views_delegate.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/shadow_types.h"
#include "ui/wm/core/window_util.h"
namespace views {
......@@ -157,6 +158,17 @@ TrayBubbleView::RerouteEventHandler::~RerouteEventHandler() {
}
void TrayBubbleView::RerouteEventHandler::OnKeyEvent(ui::KeyEvent* event) {
// Do not handle a key event if it is targeted to the tray or its descendants,
// or if the target has the tray as a transient ancestor. RerouteEventHandler
// is for rerouting events which are not targetted to the tray. Those events
// should be handled by the target.
aura::Window* target = static_cast<aura::Window*>(event->target());
aura::Window* tray_window = tray_bubble_view_->GetWidget()->GetNativeView();
if (target && (tray_window->Contains(target) ||
wm::HasTransientAncestor(target, tray_window))) {
return;
}
// Only passes Tab, Shift+Tab, Esc to the widget as it can consume more key
// events. e.g. Alt+Tab can be consumed as focus traversal by FocusManager.
ui::KeyboardCode key_code = event->key_code();
......
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