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/accessibility/browser_accessibility_manager_win.h"
6
7 #include "chrome/browser/accessibility/browser_accessibility_win.h"
8 #include "content/common/view_messages.h"
9
10 using webkit_glue::WebAccessibility;
11
12 // static
Create(gfx::NativeView parent_view,const WebAccessibility & src,BrowserAccessibilityDelegate * delegate,BrowserAccessibilityFactory * factory)13 BrowserAccessibilityManager* BrowserAccessibilityManager::Create(
14 gfx::NativeView parent_view,
15 const WebAccessibility& src,
16 BrowserAccessibilityDelegate* delegate,
17 BrowserAccessibilityFactory* factory) {
18 return new BrowserAccessibilityManagerWin(
19 parent_view,
20 src,
21 delegate,
22 factory);
23 }
24
25 BrowserAccessibilityManagerWin*
toBrowserAccessibilityManagerWin()26 BrowserAccessibilityManager::toBrowserAccessibilityManagerWin() {
27 return static_cast<BrowserAccessibilityManagerWin*>(this);
28 }
29
BrowserAccessibilityManagerWin(HWND parent_view,const WebAccessibility & src,BrowserAccessibilityDelegate * delegate,BrowserAccessibilityFactory * factory)30 BrowserAccessibilityManagerWin::BrowserAccessibilityManagerWin(
31 HWND parent_view,
32 const WebAccessibility& src,
33 BrowserAccessibilityDelegate* delegate,
34 BrowserAccessibilityFactory* factory)
35 : BrowserAccessibilityManager(parent_view, src, delegate, factory) {
36 // Allow NULL parent_view for unit testing.
37 if (parent_view == NULL) {
38 window_iaccessible_ = NULL;
39 return;
40 }
41
42 HRESULT hr = ::CreateStdAccessibleObject(
43 parent_view, OBJID_WINDOW, IID_IAccessible,
44 reinterpret_cast<void **>(&window_iaccessible_));
45 DCHECK(SUCCEEDED(hr));
46 }
47
~BrowserAccessibilityManagerWin()48 BrowserAccessibilityManagerWin::~BrowserAccessibilityManagerWin() {
49 }
50
GetParentWindowIAccessible()51 IAccessible* BrowserAccessibilityManagerWin::GetParentWindowIAccessible() {
52 return window_iaccessible_;
53 }
54
NotifyAccessibilityEvent(int type,BrowserAccessibility * node)55 void BrowserAccessibilityManagerWin::NotifyAccessibilityEvent(
56 int type,
57 BrowserAccessibility* node) {
58 LONG event_id = EVENT_MIN;
59 switch (type) {
60 case ViewHostMsg_AccessibilityNotification_Type::
61 NOTIFICATION_TYPE_CHECK_STATE_CHANGED:
62 event_id = EVENT_OBJECT_STATECHANGE;
63 break;
64 case ViewHostMsg_AccessibilityNotification_Type::
65 NOTIFICATION_TYPE_CHILDREN_CHANGED:
66 event_id = EVENT_OBJECT_REORDER;
67 break;
68 case ViewHostMsg_AccessibilityNotification_Type::
69 NOTIFICATION_TYPE_FOCUS_CHANGED:
70 event_id = EVENT_OBJECT_FOCUS;
71 break;
72 case ViewHostMsg_AccessibilityNotification_Type::
73 NOTIFICATION_TYPE_LOAD_COMPLETE:
74 event_id = IA2_EVENT_DOCUMENT_LOAD_COMPLETE;
75 break;
76 case ViewHostMsg_AccessibilityNotification_Type::
77 NOTIFICATION_TYPE_VALUE_CHANGED:
78 event_id = EVENT_OBJECT_VALUECHANGE;
79 break;
80 case ViewHostMsg_AccessibilityNotification_Type::
81 NOTIFICATION_TYPE_SELECTED_TEXT_CHANGED:
82 event_id = IA2_EVENT_TEXT_CARET_MOVED;
83 break;
84 default:
85 NOTREACHED();
86 break;
87 }
88
89 NotifyWinEvent(event_id, GetParentView(), OBJID_CLIENT, node->child_id());
90 }
91