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#import <Cocoa/Cocoa.h> 6 7#import "chrome/browser/accessibility/browser_accessibility_mac.h" 8 9#import "chrome/browser/accessibility/browser_accessibility_cocoa.h" 10#import "chrome/browser/accessibility/browser_accessibility_delegate_mac.h" 11#include "chrome/browser/accessibility/browser_accessibility_manager.h" 12#import "chrome/browser/renderer_host/render_widget_host_view_mac.h" 13 14 15// Static. 16BrowserAccessibility* BrowserAccessibility::Create() { 17 return new BrowserAccessibilityMac(); 18} 19 20BrowserAccessibilityMac::BrowserAccessibilityMac() 21 : browser_accessibility_cocoa_(NULL) { 22} 23 24void BrowserAccessibilityMac::Initialize() { 25 BrowserAccessibility::Initialize(); 26 27 if (browser_accessibility_cocoa_) 28 return; 29 30 // We take ownership of the cocoa obj here. 31 browser_accessibility_cocoa_ = [[BrowserAccessibilityCocoa alloc] 32 initWithObject:this 33 delegate:(RenderWidgetHostViewCocoa*)manager_->GetParentView()]; 34} 35 36void BrowserAccessibilityMac::NativeReleaseReference() { 37 if (browser_accessibility_cocoa_) { 38 BrowserAccessibilityCocoa* temp = browser_accessibility_cocoa_; 39 browser_accessibility_cocoa_ = nil; 40 // Relinquish ownership of the cocoa obj. 41 [temp release]; 42 // At this point, other processes may have a reference to 43 // the cocoa object. When the retain count hits zero, it will 44 // destroy us in dealloc. 45 // For that reason, do *not* make any more calls here after 46 // as we might have been deleted. 47 } 48} 49 50void BrowserAccessibilityMac::ReplaceChild( 51 BrowserAccessibility* old_acc, 52 BrowserAccessibility* new_acc) { 53 BrowserAccessibility::ReplaceChild(old_acc, new_acc); 54 [browser_accessibility_cocoa_ childrenChanged]; 55} 56 57BrowserAccessibilityCocoa* BrowserAccessibility::toBrowserAccessibilityCocoa() { 58 return static_cast<BrowserAccessibilityMac*>(this)-> 59 native_view(); 60} 61