summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/accessible_widget_helper_gtk.cc
blob: 50bc10723065cb48bf4d81c6216a70d0353bec09 (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
57
58
59
60
61
62
// Copyright (c) 2010 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 "chrome/browser/gtk/accessible_widget_helper_gtk.h"

#include "app/l10n_util.h"
#include "chrome/browser/accessibility_events.h"
#include "chrome/browser/profile.h"
#include "chrome/common/notification_service.h"

AccessibleWidgetHelper::AccessibleWidgetHelper(
    GtkWidget* root_widget, Profile* profile)
    : accessibility_event_router_(AccessibilityEventRouterGtk::GetInstance()),
      profile_(profile),
      root_widget_(root_widget) {
  accessibility_event_router_->AddRootWidget(root_widget_, profile);
}

AccessibleWidgetHelper::~AccessibleWidgetHelper() {
  if (!window_title_.empty()) {
    AccessibilityWindowInfo info(profile_, window_title_);
    NotificationService::current()->Notify(
        NotificationType::ACCESSIBILITY_WINDOW_CLOSED,
        Source<Profile>(profile_),
        Details<AccessibilityWindowInfo>(&info));
  }

  if (root_widget_)
    accessibility_event_router_->RemoveRootWidget(root_widget_);
  for (unsigned int i = 0; i < managed_widgets_.size(); i++) {
    accessibility_event_router_->RemoveWidget(managed_widgets_[i]);
  }
}

void AccessibleWidgetHelper::SendOpenWindowNotification(
    const std::string& window_title) {
  window_title_ = window_title;
  AccessibilityWindowInfo info(profile_, window_title);
  NotificationService::current()->Notify(
      NotificationType::ACCESSIBILITY_WINDOW_OPENED,
      Source<Profile>(profile_),
      Details<AccessibilityWindowInfo>(&info));
}

void AccessibleWidgetHelper::IgnoreWidget(GtkWidget* widget) {
  accessibility_event_router_->IgnoreWidget(widget);
  managed_widgets_.push_back(widget);
}

void AccessibleWidgetHelper::SetWidgetName(
    GtkWidget* widget, std::string name) {
  accessibility_event_router_->SetWidgetName(widget, name);
  managed_widgets_.push_back(widget);
}

void AccessibleWidgetHelper::SetWidgetName(
    GtkWidget* widget, int string_id) {
  std::string name = l10n_util::GetStringUTF8(string_id);
  accessibility_event_router_->SetWidgetName(widget, name);
  managed_widgets_.push_back(widget);
}