Commit 83b5b08e authored by Yuki Awano's avatar Yuki Awano Committed by Commit Bot

Activate and focus notification content view

- Activate and focus notification content view with text selection
  changed event in Android. If text selection changed is dispatched from
  Android, it means that user is trying to type something in Android
  notification.

Bug: 822140
Test: unit_tests:ArcAccessibilityHelperBridgeTest
Change-Id: I9e7613d2121cbd43e2cfd9ecc602a8834f18bfdf
Reviewed-on: https://chromium-review.googlesource.com/963960
Commit-Queue: Yuki Awano <yawano@chromium.org>
Reviewed-by: default avatarDavid Tseng <dtseng@chromium.org>
Reviewed-by: default avatarYusuke Sato <yusukes@chromium.org>
Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544951}
parent ec1efc85
......@@ -2165,6 +2165,7 @@ source_set("unit_tests") {
"//third_party/WebKit/public:blink_headers",
"//third_party/icu",
"//third_party/leveldatabase",
"//ui/arc:test_support",
"//ui/base/ime",
"//ui/chromeos/resources",
]
......
......@@ -281,13 +281,41 @@ void ArcAccessibilityHelperBridge::OnAccessibilityEvent(
tree_source->NotifyAccessibilityEvent(event_data.get());
ui::AXTreeData tree_data;
if (tree_source->GetTreeData(&tree_data) && is_notification_event &&
event_data->event_type ==
arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED) {
DCHECK(event_data->notification_key.has_value());
UpdateTreeIdOfNotificationSurface(event_data->notification_key.value(),
tree_data.tree_id);
if (is_notification_event) {
switch (event_data->event_type) {
case arc::mojom::AccessibilityEventType::VIEW_TEXT_SELECTION_CHANGED: {
// If text selection changed event is dispatched from Android, it
// means that user is trying to type a text in Android notification.
// Dispatch text selection changed event to notification content view
// as the view can take necessary actions, e.g. activate itself, etc.
auto* surface_manager = ArcNotificationSurfaceManager::Get();
if (!surface_manager)
break;
ArcNotificationSurface* surface = surface_manager->GetArcSurface(
event_data->notification_key.value());
if (!surface)
break;
surface->GetAttachedHost()->NotifyAccessibilityEvent(
ax::mojom::Event::kTextSelectionChanged, true);
break;
}
case arc::mojom::AccessibilityEventType::WINDOW_STATE_CHANGED: {
// TODO(yawano): Move this to OnNotificationStateChanged. This can be
// moved there if we don't need to care about backward compat.
ui::AXTreeData tree_data;
if (!tree_source->GetTreeData(&tree_data))
break;
DCHECK(event_data->notification_key.has_value());
UpdateTreeIdOfNotificationSurface(
event_data->notification_key.value(), tree_data.tree_id);
break;
}
default:
break;
}
}
return;
......
......@@ -52,6 +52,19 @@ static_library("arc") {
]
}
static_library("test_support") {
testonly = true
sources = [
"notification/mock_arc_notification_item.cc",
"notification/mock_arc_notification_item.h",
]
deps = [
":arc",
"//ui/gl:test_support",
]
}
test("ui_arc_unittests") {
testonly = true
sources = [
......@@ -63,6 +76,7 @@ test("ui_arc_unittests") {
deps = [
":arc",
":test_support",
"//ash:test_support_without_content",
"//base",
"//base/test:test_support",
......
......@@ -683,6 +683,19 @@ void ArcNotificationContentView::GetAccessibleNodeData(
node_data->SetName(accessible_name_);
}
void ArcNotificationContentView::OnAccessibilityEvent(ax::mojom::Event event) {
if (event == ax::mojom::Event::kTextSelectionChanged) {
// Activate and request focus on notification content view. If text
// selection changed event is dispatched, it indicates that user is going to
// type something inside Android notification. Widget of message center is
// not activated by default. We need to activate the widget. If other view
// in message center has focus, it can consume key event. We need to request
// focus to move it to this content view.
Activate();
RequestFocus();
}
}
void ArcNotificationContentView::OnWindowBoundsChanged(
aura::Window* window,
const gfx::Rect& old_bounds,
......
......@@ -91,6 +91,7 @@ class ArcNotificationContentView
void OnBlur() override;
views::FocusTraversable* GetFocusTraversable() override;
void GetAccessibleNodeData(ui::AXNodeData* node_data) override;
void OnAccessibilityEvent(ax::mojom::Event event) override;
// aura::WindowObserver
void OnWindowBoundsChanged(aura::Window* window,
......
......@@ -28,6 +28,7 @@
#include "ui/arc/notification/arc_notification_surface.h"
#include "ui/arc/notification/arc_notification_surface_manager_impl.h"
#include "ui/arc/notification/arc_notification_view.h"
#include "ui/arc/notification/mock_arc_notification_item.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/window.h"
#include "ui/events/keycodes/dom/dom_code.h"
......@@ -45,7 +46,6 @@ namespace arc {
namespace {
constexpr char kNotificationIdPrefix[] = "ARC_NOTIFICATION_";
constexpr gfx::Rect kNotificationSurfaceBounds(100, 100, 300, 300);
class MockKeyboardDelegate : public exo::KeyboardDelegate {
......@@ -69,68 +69,6 @@ aura::Window* GetFocusedWindow() {
} // anonymous namespace
class MockArcNotificationItem : public ArcNotificationItem {
public:
MockArcNotificationItem(const std::string& notification_key)
: notification_key_(notification_key),
notification_id_(kNotificationIdPrefix + notification_key),
weak_factory_(this) {}
// Methods for testing.
size_t count_close() { return count_close_; }
base::WeakPtr<MockArcNotificationItem> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
// Overriding methods for testing.
void Close(bool by_user) override { count_close_++; }
const gfx::ImageSkia& GetSnapshot() const override { return snapshot_; }
const std::string& GetNotificationKey() const override {
return notification_key_;
}
const std::string& GetNotificationId() const override {
return notification_id_;
}
// Overriding methods for returning dummy data or doing nothing.
void OnClosedFromAndroid() override {}
void Click() override {}
void ToggleExpansion() override {}
void OpenSettings() override {}
void AddObserver(Observer* observer) override {}
void RemoveObserver(Observer* observer) override {}
void IncrementWindowRefCount() override {}
void DecrementWindowRefCount() override {}
bool IsOpeningSettingsSupported() const override { return true; }
mojom::ArcNotificationType GetNotificationType() const override {
return mojom::ArcNotificationType::SIMPLE;
}
mojom::ArcNotificationExpandState GetExpandState() const override {
return mojom::ArcNotificationExpandState::FIXED_SIZE;
}
mojom::ArcNotificationShownContents GetShownContents() const override {
return mojom::ArcNotificationShownContents::CONTENTS_SHOWN;
}
gfx::Rect GetSwipeInputRect() const override { return gfx::Rect(); }
const base::string16& GetAccessibleName() const override {
return base::EmptyString16();
}
void OnUpdatedFromAndroid(mojom::ArcNotificationDataPtr data,
const std::string& app_id) override {}
bool IsManuallyExpandedOrCollapsed() const override { return false; }
private:
std::string notification_key_;
std::string notification_id_;
gfx::ImageSkia snapshot_;
size_t count_close_ = 0;
base::WeakPtrFactory<MockArcNotificationItem> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MockArcNotificationItem);
};
class DummyEvent : public ui::Event {
public:
DummyEvent() : Event(ui::ET_UNKNOWN, base::TimeTicks(), 0) {}
......
......@@ -75,6 +75,7 @@ class ArcNotificationView : public message_center::MessageView,
private:
friend class ArcNotificationContentViewTest;
friend class ArcNotificationViewTest;
friend class ArcAccessibilityHelperBridgeTest;
// TODO(yoshiki): Mmove this to message_center::MessageView.
void UpdateControlButtonsVisibilityWithNotification(
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/arc/notification/mock_arc_notification_item.h"
namespace arc {
namespace {
constexpr char kNotificationIdPrefix[] = "ARC_NOTIFICATION_";
} // namespace
MockArcNotificationItem::MockArcNotificationItem(
const std::string& notification_key)
: notification_key_(notification_key),
notification_id_(kNotificationIdPrefix + notification_key),
weak_factory_(this) {}
MockArcNotificationItem::~MockArcNotificationItem() = default;
void MockArcNotificationItem::Close(bool by_user) {
count_close_++;
}
const gfx::ImageSkia& MockArcNotificationItem::GetSnapshot() const {
return snapshot_;
}
const std::string& MockArcNotificationItem::GetNotificationKey() const {
return notification_key_;
}
const std::string& MockArcNotificationItem::GetNotificationId() const {
return notification_id_;
}
bool MockArcNotificationItem::IsOpeningSettingsSupported() const {
return true;
}
mojom::ArcNotificationType MockArcNotificationItem::GetNotificationType()
const {
return mojom::ArcNotificationType::SIMPLE;
}
mojom::ArcNotificationExpandState MockArcNotificationItem::GetExpandState()
const {
return mojom::ArcNotificationExpandState::FIXED_SIZE;
}
mojom::ArcNotificationShownContents MockArcNotificationItem::GetShownContents()
const {
return mojom::ArcNotificationShownContents::CONTENTS_SHOWN;
}
gfx::Rect MockArcNotificationItem::GetSwipeInputRect() const {
return gfx::Rect();
}
const base::string16& MockArcNotificationItem::GetAccessibleName() const {
return base::EmptyString16();
}
bool MockArcNotificationItem::IsManuallyExpandedOrCollapsed() const {
return false;
}
} // namespace arc
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef UI_ARC_NOTIFICATION_MOCK_ARC_NOTIFICATION_ITEM_H_
#define UI_ARC_NOTIFICATION_MOCK_ARC_NOTIFICATION_ITEM_H_
#include <string>
#include "ui/arc/notification/arc_notification_item.h"
namespace arc {
class MockArcNotificationItem : public ArcNotificationItem {
public:
MockArcNotificationItem(const std::string& notification_key);
~MockArcNotificationItem() override;
// Methods for testing.
size_t count_close() { return count_close_; }
base::WeakPtr<MockArcNotificationItem> GetWeakPtr() {
return weak_factory_.GetWeakPtr();
}
// Overriding methods for testing.
void Close(bool by_user) override;
const gfx::ImageSkia& GetSnapshot() const override;
const std::string& GetNotificationKey() const override;
const std::string& GetNotificationId() const override;
// Overriding methods for returning dummy data or doing nothing.
void OnClosedFromAndroid() override {}
void Click() override {}
void ToggleExpansion() override {}
void OpenSettings() override {}
void AddObserver(Observer* observer) override {}
void RemoveObserver(Observer* observer) override {}
void IncrementWindowRefCount() override {}
void DecrementWindowRefCount() override {}
bool IsOpeningSettingsSupported() const override;
mojom::ArcNotificationType GetNotificationType() const override;
mojom::ArcNotificationExpandState GetExpandState() const override;
mojom::ArcNotificationShownContents GetShownContents() const override;
gfx::Rect GetSwipeInputRect() const override;
const base::string16& GetAccessibleName() const override;
void OnUpdatedFromAndroid(mojom::ArcNotificationDataPtr data,
const std::string& app_id) override {}
bool IsManuallyExpandedOrCollapsed() const override;
private:
std::string notification_key_;
std::string notification_id_;
gfx::ImageSkia snapshot_;
size_t count_close_ = 0;
base::WeakPtrFactory<MockArcNotificationItem> weak_factory_;
DISALLOW_COPY_AND_ASSIGN(MockArcNotificationItem);
};
} // namespace arc
#endif // UI_ARC_NOTIFICATION_MOCK_ARC_NOTIFICATION_ITEM_H_
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