1 // Copyright (c) 2012 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.
5 #import <Cocoa/Cocoa.h>
7 #import "content/browser/accessibility/browser_accessibility_mac.h"
9 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
10 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
15 BrowserAccessibility* BrowserAccessibility::Create() {
16 return new BrowserAccessibilityMac();
19 BrowserAccessibilityMac::BrowserAccessibilityMac()
20 : browser_accessibility_cocoa_(NULL) {
23 void BrowserAccessibilityMac::OnDataChanged() {
24 BrowserAccessibility::OnDataChanged();
26 if (browser_accessibility_cocoa_) {
27 [browser_accessibility_cocoa_ childrenChanged];
31 // We take ownership of the cocoa obj here.
32 browser_accessibility_cocoa_ = [[BrowserAccessibilityCocoa alloc]
36 void BrowserAccessibilityMac::NativeReleaseReference() {
37 // Detach this object from |browser_accessibility_cocoa_| so it
38 // no longer has a pointer to this object.
39 [browser_accessibility_cocoa_ detach];
40 // Now, release it - but at this point, other processes may have a
41 // reference to the cocoa object.
42 [browser_accessibility_cocoa_ release];
43 // Finally, it's safe to delete this since we've detached.
47 bool BrowserAccessibilityMac::IsNative() const {
51 void BrowserAccessibilityMac::RecreateNativeObject() {
52 if (!browser_accessibility_cocoa_)
55 // Preserve the children so that recreating the native object doesn't
56 // end up recreating the whole subtree.
57 base::scoped_nsobject<NSMutableArray> children;
58 [browser_accessibility_cocoa_ swapChildren:&children];
59 [browser_accessibility_cocoa_ detach];
60 [browser_accessibility_cocoa_ release];
61 browser_accessibility_cocoa_ = [[BrowserAccessibilityCocoa alloc]
63 [browser_accessibility_cocoa_ swapChildren:&children];
66 BrowserAccessibilityCocoa* BrowserAccessibility::ToBrowserAccessibilityCocoa() {
67 return static_cast<BrowserAccessibilityMac*>(this)->
71 } // namespace content