Home | History | Annotate | Download | only in accessibility
      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.
      4 
      5 #import <Cocoa/Cocoa.h>
      6 
      7 #import "content/browser/accessibility/browser_accessibility_mac.h"
      8 
      9 #import "content/browser/accessibility/browser_accessibility_cocoa.h"
     10 #import "content/browser/accessibility/browser_accessibility_delegate_mac.h"
     11 #include "content/browser/accessibility/browser_accessibility_manager_mac.h"
     12 
     13 namespace content {
     14 
     15 // Static.
     16 BrowserAccessibility* BrowserAccessibility::Create() {
     17   return new BrowserAccessibilityMac();
     18 }
     19 
     20 BrowserAccessibilityMac::BrowserAccessibilityMac()
     21     : browser_accessibility_cocoa_(NULL) {
     22 }
     23 
     24 void BrowserAccessibilityMac::PreInitialize() {
     25   BrowserAccessibility::PreInitialize();
     26 
     27   if (browser_accessibility_cocoa_)
     28     return;
     29 
     30   // We take ownership of the cocoa obj here.
     31   BrowserAccessibilityManagerMac* manager =
     32       static_cast<BrowserAccessibilityManagerMac*>(manager_);
     33   browser_accessibility_cocoa_ = [[BrowserAccessibilityCocoa alloc]
     34       initWithObject:this
     35       delegate:
     36           (id<BrowserAccessibilityDelegateCocoa>)manager->parent_view()];
     37 }
     38 
     39 void BrowserAccessibilityMac::NativeReleaseReference() {
     40   // Detach this object from |browser_accessibility_cocoa_| so it
     41   // no longer has a pointer to this object.
     42   [browser_accessibility_cocoa_ detach];
     43   // Now, release it - but at this point, other processes may have a
     44   // reference to the cocoa object.
     45   [browser_accessibility_cocoa_ release];
     46   // Finally, it's safe to delete this since we've detached.
     47   delete this;
     48 }
     49 
     50 bool BrowserAccessibilityMac::IsNative() const {
     51   return true;
     52 }
     53 
     54 void BrowserAccessibilityMac::DetachTree(
     55     std::vector<BrowserAccessibility*>* nodes) {
     56   [browser_accessibility_cocoa_ childrenChanged];
     57   BrowserAccessibility::DetachTree(nodes);
     58 }
     59 
     60 void BrowserAccessibilityMac::SwapChildren(
     61     std::vector<BrowserAccessibility*>& children) {
     62   [browser_accessibility_cocoa_ childrenChanged];
     63   BrowserAccessibility::SwapChildren(children);
     64 }
     65 
     66 BrowserAccessibilityCocoa* BrowserAccessibility::ToBrowserAccessibilityCocoa() {
     67   return static_cast<BrowserAccessibilityMac*>(this)->
     68       native_view();
     69 }
     70 
     71 }  // namespace content
     72