Roll src/third_party/WebKit f298044:aa8346d (svn 202628:202629)
[chromium-blink-merge.git] / content / browser / accessibility / browser_accessibility_mac.mm
blob1d4c2f92a7fc86ad24f2da6674598696a26d4e48
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"
12 namespace content {
14 // Static.
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];
28     return;
29   }
31   // We take ownership of the cocoa obj here.
32   browser_accessibility_cocoa_ = [[BrowserAccessibilityCocoa alloc]
33       initWithObject:this];
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.
44   delete this;
47 bool BrowserAccessibilityMac::IsNative() const {
48   return true;
51 void BrowserAccessibilityMac::RecreateNativeObject() {
52   if (!browser_accessibility_cocoa_)
53     return;
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]
62       initWithObject:this];
63   [browser_accessibility_cocoa_ swapChildren:&children];
66 BrowserAccessibilityCocoa* BrowserAccessibility::ToBrowserAccessibilityCocoa() {
67   return static_cast<BrowserAccessibilityMac*>(this)->
68       native_view();
71 }  // namespace content