summaryrefslogtreecommitdiff
path: root/chromium/ui/views/accessibility/accessibility_alert_window.h
blob: d64082dfe8684b6e700ab553158c1fd7ac6dca00 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// 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_VIEWS_ACCESSIBILITY_ACCESSIBILITY_ALERT_WINDOW_H_
#define UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_ALERT_WINDOW_H_

#include <memory>
#include <string>

#include "base/gtest_prod_util.h"
#include "base/scoped_observation.h"
#include "ui/aura/env.h"
#include "ui/aura/env_observer.h"
#include "ui/views/views_export.h"

namespace aura {
class Window;
}

namespace views {
class AXAuraObjCache;

// This class provides a caller a way to alert an accessibility client such as
// ChromeVox with a text string without a backing visible window or view.
class VIEWS_EXPORT AccessibilityAlertWindow : public aura::EnvObserver {
 public:
  // |parent| is the window where a child alert window will be added.
  AccessibilityAlertWindow(aura::Window* parent, views::AXAuraObjCache* cache);
  AccessibilityAlertWindow(const AccessibilityAlertWindow&) = delete;
  AccessibilityAlertWindow& operator=(const AccessibilityAlertWindow&) = delete;
  ~AccessibilityAlertWindow() override;

  // Triggers an alert with the text |alert_string| to be sent to an
  // accessibility client.
  void HandleAlert(const std::string& alert_string);

 private:
  FRIEND_TEST_ALL_PREFIXES(AccessibilityAlertWindowTest, HandleAlert);
  FRIEND_TEST_ALL_PREFIXES(AccessibilityAlertWindowTest, OnWillDestroyEnv);

  // aura::EnvObserver:
  void OnWillDestroyEnv() override;

  // The child alert window.
  std::unique_ptr<aura::Window> alert_window_;

  // The accessibility cache associated with |alert_window_|.
  views::AXAuraObjCache* cache_;

  base::ScopedObservation<aura::Env, aura::EnvObserver> observation_{this};
};

}  // namespace views

#endif  // UI_VIEWS_ACCESSIBILITY_ACCESSIBILITY_ALERT_WINDOW_H_