Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_mac.mm

Issue 273423004: Migrate accessibility from RenderView to RenderFrame. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 6 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h"
6 6
7 #import <objc/runtime.h> 7 #import <objc/runtime.h>
8 #include <OpenGL/gl.h> 8 #include <OpenGL/gl.h>
9 #include <QuartzCore/QuartzCore.h> 9 #include <QuartzCore/QuartzCore.h>
10 10
(...skipping 2035 matching lines...) Expand 10 before | Expand all | Expand 10 after
2046 RenderWidgetHostViewMacDictionaryHelper helper(this); 2046 RenderWidgetHostViewMacDictionaryHelper helper(this);
2047 helper.ShowDefinitionForSelection(); 2047 helper.ShowDefinitionForSelection();
2048 } 2048 }
2049 2049
2050 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { 2050 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) {
2051 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); 2051 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque);
2052 if (render_widget_host_) 2052 if (render_widget_host_)
2053 render_widget_host_->SetBackgroundOpaque(opaque); 2053 render_widget_host_->SetBackgroundOpaque(opaque);
2054 } 2054 }
2055 2055
2056 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { 2056 BrowserAccessibilityManager*
2057 if (!GetBrowserAccessibilityManager()) { 2057 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager(
2058 SetBrowserAccessibilityManager( 2058 BrowserAccessibilityDelegate* delegate) {
2059 new BrowserAccessibilityManagerMac( 2059 return new BrowserAccessibilityManagerMac(
2060 cocoa_view_, 2060 cocoa_view_,
2061 BrowserAccessibilityManagerMac::GetEmptyDocument(), 2061 BrowserAccessibilityManagerMac::GetEmptyDocument(),
2062 render_widget_host_)); 2062 delegate);
2063 }
2064 } 2063 }
2065 2064
2066 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( 2065 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen(
2067 const gfx::Rect& bounds) { 2066 const gfx::Rect& bounds) {
2068 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); 2067 NSPoint origin = NSMakePoint(bounds.x(), bounds.y());
2069 NSSize size = NSMakeSize(bounds.width(), bounds.height()); 2068 NSSize size = NSMakeSize(bounds.width(), bounds.height());
2070 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; 2069 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y;
2071 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; 2070 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil];
2072 NSPoint originInScreen = 2071 NSPoint originInScreen =
2073 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; 2072 [[cocoa_view_ window] convertBaseToScreen:originInWindow];
2074 originInScreen.y = originInScreen.y - size.height; 2073 originInScreen.y = originInScreen.y - size.height;
2075 return gfx::Point(originInScreen.x, originInScreen.y); 2074 return gfx::Point(originInScreen.x, originInScreen.y);
2076 } 2075 }
2077 2076
2078 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { 2077 void RenderWidgetHostViewMac::AccessibilityShowMenu(const gfx::Point& point) {
2079 // Immediately set the focused item even though we have not officially set 2078 NSPoint location = NSMakePoint(point.x(), point.y());
2080 // focus on it as VoiceOver expects to get the focused item after this
2081 // method returns.
2082 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2083 if (manager)
2084 manager->SetFocus(manager->GetFromID(accObjId), false);
2085 }
2086
2087 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) {
2088 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2089 if (!manager)
2090 return;
2091 BrowserAccessibilityCocoa* obj =
2092 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa();
2093
2094 // Performs a right click copying WebKit's
2095 // accessibilityPerformShowMenuAction.
2096 NSPoint objOrigin = [obj origin];
2097 NSSize size = [[obj size] sizeValue];
2098 gfx::Point origin = AccessibilityOriginInScreen(
2099 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height));
2100 NSPoint location = NSMakePoint(origin.x(), origin.y());
2101 location = [[cocoa_view_ window] convertScreenToBase:location]; 2079 location = [[cocoa_view_ window] convertScreenToBase:location];
2102 location.x += size.width/2;
2103 location.y += size.height/2;
2104
2105 NSEvent* fakeRightClick = [NSEvent 2080 NSEvent* fakeRightClick = [NSEvent
2106 mouseEventWithType:NSRightMouseDown 2081 mouseEventWithType:NSRightMouseDown
2107 location:location 2082 location:location
2108 modifierFlags:0 2083 modifierFlags:0
2109 timestamp:0 2084 timestamp:0
2110 windowNumber:[[cocoa_view_ window] windowNumber] 2085 windowNumber:[[cocoa_view_ window] windowNumber]
2111 context:[NSGraphicsContext currentContext] 2086 context:[NSGraphicsContext currentContext]
2112 eventNumber:0 2087 eventNumber:0
2113 clickCount:1 2088 clickCount:1
2114 pressure:0]; 2089 pressure:0];
2115 2090
2116 [cocoa_view_ mouseEvent:fakeRightClick]; 2091 [cocoa_view_ mouseEvent:fakeRightClick];
2117 } 2092 }
2118 2093
2119
2120
2121 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { 2094 void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
2122 if (active) { 2095 if (active) {
2123 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 2096 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
2124 EnablePasswordInput(); 2097 EnablePasswordInput();
2125 else 2098 else
2126 DisablePasswordInput(); 2099 DisablePasswordInput();
2127 } else { 2100 } else {
2128 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 2101 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
2129 DisablePasswordInput(); 2102 DisablePasswordInput();
2130 } 2103 }
(...skipping 1011 matching lines...) Expand 10 before | Expand all | Expand 10 after
3142 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; 3115 return [fullArray subarrayWithRange:NSMakeRange(index, length)];
3143 } 3116 }
3144 3117
3145 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { 3118 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute {
3146 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; 3119 NSArray* fullArray = [self accessibilityAttributeValue:attribute];
3147 return [fullArray count]; 3120 return [fullArray count];
3148 } 3121 }
3149 3122
3150 - (id)accessibilityAttributeValue:(NSString *)attribute { 3123 - (id)accessibilityAttributeValue:(NSString *)attribute {
3151 BrowserAccessibilityManager* manager = 3124 BrowserAccessibilityManager* manager =
3152 renderWidgetHostView_->GetBrowserAccessibilityManager(); 3125 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3153 3126
3154 // Contents specifies document view of RenderWidgetHostViewCocoa provided by 3127 // Contents specifies document view of RenderWidgetHostViewCocoa provided by
3155 // BrowserAccessibilityManager. Children includes all subviews in addition to 3128 // BrowserAccessibilityManager. Children includes all subviews in addition to
3156 // contents. Currently we do not have subviews besides the document view. 3129 // contents. Currently we do not have subviews besides the document view.
3157 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || 3130 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] ||
3158 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && 3131 [attribute isEqualToString:NSAccessibilityContentsAttribute]) &&
3159 manager) { 3132 manager) {
3160 return [NSArray arrayWithObjects:manager-> 3133 return [NSArray arrayWithObjects:manager->
3161 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; 3134 GetRoot()->ToBrowserAccessibilityCocoa(), nil];
3162 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { 3135 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
3163 return NSAccessibilityScrollAreaRole; 3136 return NSAccessibilityScrollAreaRole;
3164 } 3137 }
3165 id ret = [super accessibilityAttributeValue:attribute]; 3138 id ret = [super accessibilityAttributeValue:attribute];
3166 return ret; 3139 return ret;
3167 } 3140 }
3168 3141
3169 - (NSArray*)accessibilityAttributeNames { 3142 - (NSArray*)accessibilityAttributeNames {
3170 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; 3143 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease];
3171 [ret addObject:NSAccessibilityContentsAttribute]; 3144 [ret addObject:NSAccessibilityContentsAttribute];
3172 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; 3145 [ret addObjectsFromArray:[super accessibilityAttributeNames]];
3173 return ret; 3146 return ret;
3174 } 3147 }
3175 3148
3176 - (id)accessibilityHitTest:(NSPoint)point { 3149 - (id)accessibilityHitTest:(NSPoint)point {
3177 if (!renderWidgetHostView_->GetBrowserAccessibilityManager()) 3150 BrowserAccessibilityManager* manager =
3151 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3152 if (!manager)
3178 return self; 3153 return self;
3179 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; 3154 NSPoint pointInWindow = [[self window] convertScreenToBase:point];
3180 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; 3155 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil];
3181 localPoint.y = NSHeight([self bounds]) - localPoint.y; 3156 localPoint.y = NSHeight([self bounds]) - localPoint.y;
3182 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> 3157 BrowserAccessibilityCocoa* root =
3183 GetBrowserAccessibilityManager()-> 3158 manager->GetRoot()->ToBrowserAccessibilityCocoa();
3184 GetRoot()->ToBrowserAccessibilityCocoa();
3185 id obj = [root accessibilityHitTest:localPoint]; 3159 id obj = [root accessibilityHitTest:localPoint];
3186 return obj; 3160 return obj;
3187 } 3161 }
3188 3162
3189 - (BOOL)accessibilityIsIgnored { 3163 - (BOOL)accessibilityIsIgnored {
3190 return !renderWidgetHostView_->GetBrowserAccessibilityManager(); 3164 BrowserAccessibilityManager* manager =
3165 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3166 return !manager;
3191 } 3167 }
3192 3168
3193 - (NSUInteger)accessibilityGetIndexOf:(id)child { 3169 - (NSUInteger)accessibilityGetIndexOf:(id)child {
3194 BrowserAccessibilityManager* manager = 3170 BrowserAccessibilityManager* manager =
3195 renderWidgetHostView_->GetBrowserAccessibilityManager(); 3171 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3196 // Only child is root. 3172 // Only child is root.
3197 if (manager && 3173 if (manager &&
3198 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { 3174 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) {
3199 return 0; 3175 return 0;
3200 } else { 3176 } else {
3201 return NSNotFound; 3177 return NSNotFound;
3202 } 3178 }
3203 } 3179 }
3204 3180
3205 - (id)accessibilityFocusedUIElement { 3181 - (id)accessibilityFocusedUIElement {
3206 BrowserAccessibilityManager* manager = 3182 BrowserAccessibilityManager* manager =
3207 renderWidgetHostView_->GetBrowserAccessibilityManager(); 3183 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3208 if (manager) { 3184 if (manager) {
3209 BrowserAccessibility* focused_item = manager->GetFocus(NULL); 3185 BrowserAccessibility* focused_item = manager->GetFocus(NULL);
3210 DCHECK(focused_item); 3186 DCHECK(focused_item);
3211 if (focused_item) { 3187 if (focused_item) {
3212 BrowserAccessibilityCocoa* focused_item_cocoa = 3188 BrowserAccessibilityCocoa* focused_item_cocoa =
3213 focused_item->ToBrowserAccessibilityCocoa(); 3189 focused_item->ToBrowserAccessibilityCocoa();
3214 DCHECK(focused_item_cocoa); 3190 DCHECK(focused_item_cocoa);
3215 if (focused_item_cocoa) 3191 if (focused_item_cocoa)
3216 return focused_item_cocoa; 3192 return focused_item_cocoa;
3217 } 3193 }
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
3954 3930
3955 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3931 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3956 // regions that are not draggable. (See ControlRegionView in 3932 // regions that are not draggable. (See ControlRegionView in
3957 // native_app_window_cocoa.mm). This requires the render host view to be 3933 // native_app_window_cocoa.mm). This requires the render host view to be
3958 // draggable by default. 3934 // draggable by default.
3959 - (BOOL)mouseDownCanMoveWindow { 3935 - (BOOL)mouseDownCanMoveWindow {
3960 return YES; 3936 return YES;
3961 } 3937 }
3962 3938
3963 @end 3939 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698