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

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

Issue 408663006: Revert 284065 "Revert of Revert of Migrate accessibility from Re..." (Closed) Base URL: svn://svn.chromium.org/chrome/
Patch Set: 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 2038 matching lines...) Expand 10 before | Expand all | Expand 10 after
2049 RenderWidgetHostViewMacDictionaryHelper helper(this); 2049 RenderWidgetHostViewMacDictionaryHelper helper(this);
2050 helper.ShowDefinitionForSelection(); 2050 helper.ShowDefinitionForSelection();
2051 } 2051 }
2052 2052
2053 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { 2053 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) {
2054 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); 2054 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque);
2055 if (render_widget_host_) 2055 if (render_widget_host_)
2056 render_widget_host_->SetBackgroundOpaque(opaque); 2056 render_widget_host_->SetBackgroundOpaque(opaque);
2057 } 2057 }
2058 2058
2059 BrowserAccessibilityManager* 2059 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() {
2060 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( 2060 if (!GetBrowserAccessibilityManager()) {
2061 BrowserAccessibilityDelegate* delegate) { 2061 SetBrowserAccessibilityManager(
2062 return new BrowserAccessibilityManagerMac( 2062 new BrowserAccessibilityManagerMac(
2063 cocoa_view_, 2063 cocoa_view_,
2064 BrowserAccessibilityManagerMac::GetEmptyDocument(), 2064 BrowserAccessibilityManagerMac::GetEmptyDocument(),
2065 delegate); 2065 render_widget_host_));
2066 }
2066 } 2067 }
2067 2068
2068 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( 2069 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen(
2069 const gfx::Rect& bounds) { 2070 const gfx::Rect& bounds) {
2070 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); 2071 NSPoint origin = NSMakePoint(bounds.x(), bounds.y());
2071 NSSize size = NSMakeSize(bounds.width(), bounds.height()); 2072 NSSize size = NSMakeSize(bounds.width(), bounds.height());
2072 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; 2073 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y;
2073 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; 2074 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil];
2074 NSPoint originInScreen = 2075 NSPoint originInScreen =
2075 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; 2076 [[cocoa_view_ window] convertBaseToScreen:originInWindow];
2076 originInScreen.y = originInScreen.y - size.height; 2077 originInScreen.y = originInScreen.y - size.height;
2077 return gfx::Point(originInScreen.x, originInScreen.y); 2078 return gfx::Point(originInScreen.x, originInScreen.y);
2078 } 2079 }
2079 2080
2080 void RenderWidgetHostViewMac::AccessibilityShowMenu(const gfx::Point& point) { 2081 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) {
2081 NSPoint location = NSMakePoint(point.x(), point.y()); 2082 // Immediately set the focused item even though we have not officially set
2083 // focus on it as VoiceOver expects to get the focused item after this
2084 // method returns.
2085 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2086 if (manager)
2087 manager->SetFocus(manager->GetFromID(accObjId), false);
2088 }
2089
2090 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) {
2091 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager();
2092 if (!manager)
2093 return;
2094 BrowserAccessibilityCocoa* obj =
2095 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa();
2096
2097 // Performs a right click copying WebKit's
2098 // accessibilityPerformShowMenuAction.
2099 NSPoint objOrigin = [obj origin];
2100 NSSize size = [[obj size] sizeValue];
2101 gfx::Point origin = AccessibilityOriginInScreen(
2102 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height));
2103 NSPoint location = NSMakePoint(origin.x(), origin.y());
2082 location = [[cocoa_view_ window] convertScreenToBase:location]; 2104 location = [[cocoa_view_ window] convertScreenToBase:location];
2105 location.x += size.width/2;
2106 location.y += size.height/2;
2107
2083 NSEvent* fakeRightClick = [NSEvent 2108 NSEvent* fakeRightClick = [NSEvent
2084 mouseEventWithType:NSRightMouseDown 2109 mouseEventWithType:NSRightMouseDown
2085 location:location 2110 location:location
2086 modifierFlags:0 2111 modifierFlags:0
2087 timestamp:0 2112 timestamp:0
2088 windowNumber:[[cocoa_view_ window] windowNumber] 2113 windowNumber:[[cocoa_view_ window] windowNumber]
2089 context:[NSGraphicsContext currentContext] 2114 context:[NSGraphicsContext currentContext]
2090 eventNumber:0 2115 eventNumber:0
2091 clickCount:1 2116 clickCount:1
2092 pressure:0]; 2117 pressure:0];
2093 2118
2094 [cocoa_view_ mouseEvent:fakeRightClick]; 2119 [cocoa_view_ mouseEvent:fakeRightClick];
2095 } 2120 }
2096 2121
2122
2123
2097 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { 2124 void RenderWidgetHostViewMac::SetTextInputActive(bool active) {
2098 if (active) { 2125 if (active) {
2099 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 2126 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
2100 EnablePasswordInput(); 2127 EnablePasswordInput();
2101 else 2128 else
2102 DisablePasswordInput(); 2129 DisablePasswordInput();
2103 } else { 2130 } else {
2104 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) 2131 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD)
2105 DisablePasswordInput(); 2132 DisablePasswordInput();
2106 } 2133 }
(...skipping 1028 matching lines...) Expand 10 before | Expand all | Expand 10 after
3135 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; 3162 return [fullArray subarrayWithRange:NSMakeRange(index, length)];
3136 } 3163 }
3137 3164
3138 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { 3165 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute {
3139 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; 3166 NSArray* fullArray = [self accessibilityAttributeValue:attribute];
3140 return [fullArray count]; 3167 return [fullArray count];
3141 } 3168 }
3142 3169
3143 - (id)accessibilityAttributeValue:(NSString *)attribute { 3170 - (id)accessibilityAttributeValue:(NSString *)attribute {
3144 BrowserAccessibilityManager* manager = 3171 BrowserAccessibilityManager* manager =
3145 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); 3172 renderWidgetHostView_->GetBrowserAccessibilityManager();
3146 3173
3147 // Contents specifies document view of RenderWidgetHostViewCocoa provided by 3174 // Contents specifies document view of RenderWidgetHostViewCocoa provided by
3148 // BrowserAccessibilityManager. Children includes all subviews in addition to 3175 // BrowserAccessibilityManager. Children includes all subviews in addition to
3149 // contents. Currently we do not have subviews besides the document view. 3176 // contents. Currently we do not have subviews besides the document view.
3150 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || 3177 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] ||
3151 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && 3178 [attribute isEqualToString:NSAccessibilityContentsAttribute]) &&
3152 manager) { 3179 manager) {
3153 return [NSArray arrayWithObjects:manager-> 3180 return [NSArray arrayWithObjects:manager->
3154 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; 3181 GetRoot()->ToBrowserAccessibilityCocoa(), nil];
3155 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { 3182 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) {
3156 return NSAccessibilityScrollAreaRole; 3183 return NSAccessibilityScrollAreaRole;
3157 } 3184 }
3158 id ret = [super accessibilityAttributeValue:attribute]; 3185 id ret = [super accessibilityAttributeValue:attribute];
3159 return ret; 3186 return ret;
3160 } 3187 }
3161 3188
3162 - (NSArray*)accessibilityAttributeNames { 3189 - (NSArray*)accessibilityAttributeNames {
3163 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; 3190 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease];
3164 [ret addObject:NSAccessibilityContentsAttribute]; 3191 [ret addObject:NSAccessibilityContentsAttribute];
3165 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; 3192 [ret addObjectsFromArray:[super accessibilityAttributeNames]];
3166 return ret; 3193 return ret;
3167 } 3194 }
3168 3195
3169 - (id)accessibilityHitTest:(NSPoint)point { 3196 - (id)accessibilityHitTest:(NSPoint)point {
3170 BrowserAccessibilityManager* manager = 3197 if (!renderWidgetHostView_->GetBrowserAccessibilityManager())
3171 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3172 if (!manager)
3173 return self; 3198 return self;
3174 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; 3199 NSPoint pointInWindow = [[self window] convertScreenToBase:point];
3175 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; 3200 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil];
3176 localPoint.y = NSHeight([self bounds]) - localPoint.y; 3201 localPoint.y = NSHeight([self bounds]) - localPoint.y;
3177 BrowserAccessibilityCocoa* root = 3202 BrowserAccessibilityCocoa* root = renderWidgetHostView_->
3178 manager->GetRoot()->ToBrowserAccessibilityCocoa(); 3203 GetBrowserAccessibilityManager()->
3204 GetRoot()->ToBrowserAccessibilityCocoa();
3179 id obj = [root accessibilityHitTest:localPoint]; 3205 id obj = [root accessibilityHitTest:localPoint];
3180 return obj; 3206 return obj;
3181 } 3207 }
3182 3208
3183 - (BOOL)accessibilityIsIgnored { 3209 - (BOOL)accessibilityIsIgnored {
3184 BrowserAccessibilityManager* manager = 3210 return !renderWidgetHostView_->GetBrowserAccessibilityManager();
3185 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager();
3186 return !manager;
3187 } 3211 }
3188 3212
3189 - (NSUInteger)accessibilityGetIndexOf:(id)child { 3213 - (NSUInteger)accessibilityGetIndexOf:(id)child {
3190 BrowserAccessibilityManager* manager = 3214 BrowserAccessibilityManager* manager =
3191 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); 3215 renderWidgetHostView_->GetBrowserAccessibilityManager();
3192 // Only child is root. 3216 // Only child is root.
3193 if (manager && 3217 if (manager &&
3194 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { 3218 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) {
3195 return 0; 3219 return 0;
3196 } else { 3220 } else {
3197 return NSNotFound; 3221 return NSNotFound;
3198 } 3222 }
3199 } 3223 }
3200 3224
3201 - (id)accessibilityFocusedUIElement { 3225 - (id)accessibilityFocusedUIElement {
3202 BrowserAccessibilityManager* manager = 3226 BrowserAccessibilityManager* manager =
3203 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); 3227 renderWidgetHostView_->GetBrowserAccessibilityManager();
3204 if (manager) { 3228 if (manager) {
3205 BrowserAccessibility* focused_item = manager->GetFocus(NULL); 3229 BrowserAccessibility* focused_item = manager->GetFocus(NULL);
3206 DCHECK(focused_item); 3230 DCHECK(focused_item);
3207 if (focused_item) { 3231 if (focused_item) {
3208 BrowserAccessibilityCocoa* focused_item_cocoa = 3232 BrowserAccessibilityCocoa* focused_item_cocoa =
3209 focused_item->ToBrowserAccessibilityCocoa(); 3233 focused_item->ToBrowserAccessibilityCocoa();
3210 DCHECK(focused_item_cocoa); 3234 DCHECK(focused_item_cocoa);
3211 if (focused_item_cocoa) 3235 if (focused_item_cocoa)
3212 return focused_item_cocoa; 3236 return focused_item_cocoa;
3213 } 3237 }
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after
3950 3974
3951 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding 3975 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding
3952 // regions that are not draggable. (See ControlRegionView in 3976 // regions that are not draggable. (See ControlRegionView in
3953 // native_app_window_cocoa.mm). This requires the render host view to be 3977 // native_app_window_cocoa.mm). This requires the render host view to be
3954 // draggable by default. 3978 // draggable by default.
3955 - (BOOL)mouseDownCanMoveWindow { 3979 - (BOOL)mouseDownCanMoveWindow {
3956 return YES; 3980 return YES;
3957 } 3981 }
3958 3982
3959 @end 3983 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698