| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/gtk/accessible_widget_helper_gtk.h" | |
| 6 | |
| 7 #include "app/l10n_util.h" | |
| 8 #include "chrome/browser/accessibility_events.h" | |
| 9 #include "chrome/browser/profiles/profile.h" | |
| 10 #include "chrome/common/notification_service.h" | |
| 11 | |
| 12 AccessibleWidgetHelper::AccessibleWidgetHelper( | |
| 13 GtkWidget* root_widget, Profile* profile) | |
| 14 : accessibility_event_router_(AccessibilityEventRouterGtk::GetInstance()), | |
| 15 profile_(profile), | |
| 16 root_widget_(root_widget) { | |
| 17 CHECK(profile_); | |
| 18 accessibility_event_router_->AddRootWidget(root_widget_, profile_); | |
| 19 } | |
| 20 | |
| 21 AccessibleWidgetHelper::~AccessibleWidgetHelper() { | |
| 22 if (!window_title_.empty()) { | |
| 23 AccessibilityWindowInfo info(profile_, window_title_); | |
| 24 NotificationService::current()->Notify( | |
| 25 NotificationType::ACCESSIBILITY_WINDOW_CLOSED, | |
| 26 Source<Profile>(profile_), | |
| 27 Details<AccessibilityWindowInfo>(&info)); | |
| 28 } | |
| 29 | |
| 30 if (root_widget_) | |
| 31 accessibility_event_router_->RemoveRootWidget(root_widget_); | |
| 32 for (std::set<GtkWidget*>::iterator it = managed_widgets_.begin(); | |
| 33 it != managed_widgets_.end(); | |
| 34 ++it) { | |
| 35 accessibility_event_router_->RemoveWidgetNameOverride(*it); | |
| 36 } | |
| 37 } | |
| 38 | |
| 39 void AccessibleWidgetHelper::SendOpenWindowNotification( | |
| 40 const std::string& window_title) { | |
| 41 window_title_ = window_title; | |
| 42 AccessibilityWindowInfo info(profile_, window_title); | |
| 43 NotificationService::current()->Notify( | |
| 44 NotificationType::ACCESSIBILITY_WINDOW_OPENED, | |
| 45 Source<Profile>(profile_), | |
| 46 Details<AccessibilityWindowInfo>(&info)); | |
| 47 } | |
| 48 | |
| 49 void AccessibleWidgetHelper::SetWidgetName( | |
| 50 GtkWidget* widget, std::string name) { | |
| 51 if (managed_widgets_.find(widget) != managed_widgets_.end()) { | |
| 52 // AccessibilityEventRouterGtk reference-counts its widgets, but we | |
| 53 // don't. In order to avoid a memory leak, tell the event router | |
| 54 // to deref first, so the resulting refcount is unchanged after we | |
| 55 // call SetWidgetName. | |
| 56 accessibility_event_router_->RemoveWidgetNameOverride(widget); | |
| 57 } | |
| 58 | |
| 59 accessibility_event_router_->AddWidgetNameOverride(widget, name); | |
| 60 managed_widgets_.insert(widget); | |
| 61 } | |
| 62 | |
| 63 void AccessibleWidgetHelper::SetWidgetName( | |
| 64 GtkWidget* widget, int string_id) { | |
| 65 SetWidgetName(widget, l10n_util::GetStringUTF8(string_id)); | |
| 66 } | |
| OLD | NEW |