OLD | NEW |
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 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2041 RenderWidgetHostViewMacDictionaryHelper helper(this); | 2041 RenderWidgetHostViewMacDictionaryHelper helper(this); |
2042 helper.ShowDefinitionForSelection(); | 2042 helper.ShowDefinitionForSelection(); |
2043 } | 2043 } |
2044 | 2044 |
2045 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { | 2045 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { |
2046 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); | 2046 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); |
2047 if (render_widget_host_) | 2047 if (render_widget_host_) |
2048 render_widget_host_->SetBackgroundOpaque(opaque); | 2048 render_widget_host_->SetBackgroundOpaque(opaque); |
2049 } | 2049 } |
2050 | 2050 |
2051 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { | 2051 BrowserAccessibilityManager* |
2052 if (!GetBrowserAccessibilityManager()) { | 2052 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( |
2053 SetBrowserAccessibilityManager( | 2053 BrowserAccessibilityDelegate* delegate) { |
2054 new BrowserAccessibilityManagerMac( | 2054 return new BrowserAccessibilityManagerMac( |
2055 cocoa_view_, | 2055 cocoa_view_, |
2056 BrowserAccessibilityManagerMac::GetEmptyDocument(), | 2056 BrowserAccessibilityManagerMac::GetEmptyDocument(), |
2057 render_widget_host_)); | 2057 delegate); |
2058 } | |
2059 } | 2058 } |
2060 | 2059 |
2061 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( | 2060 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
2062 const gfx::Rect& bounds) { | 2061 const gfx::Rect& bounds) { |
2063 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); | 2062 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
2064 NSSize size = NSMakeSize(bounds.width(), bounds.height()); | 2063 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
2065 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 2064 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
2066 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 2065 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
2067 NSPoint originInScreen = | 2066 NSPoint originInScreen = |
2068 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; | 2067 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
2069 originInScreen.y = originInScreen.y - size.height; | 2068 originInScreen.y = originInScreen.y - size.height; |
2070 return gfx::Point(originInScreen.x, originInScreen.y); | 2069 return gfx::Point(originInScreen.x, originInScreen.y); |
2071 } | 2070 } |
2072 | 2071 |
2073 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { | 2072 void RenderWidgetHostViewMac::AccessibilityShowMenu(const gfx::Point& point) { |
2074 // Immediately set the focused item even though we have not officially set | 2073 NSPoint location = NSMakePoint(point.x(), point.y()); |
2075 // focus on it as VoiceOver expects to get the focused item after this | |
2076 // method returns. | |
2077 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2078 if (manager) | |
2079 manager->SetFocus(manager->GetFromID(accObjId), false); | |
2080 } | |
2081 | |
2082 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) { | |
2083 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2084 if (!manager) | |
2085 return; | |
2086 BrowserAccessibilityCocoa* obj = | |
2087 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa(); | |
2088 | |
2089 // Performs a right click copying WebKit's | |
2090 // accessibilityPerformShowMenuAction. | |
2091 NSPoint objOrigin = [obj origin]; | |
2092 NSSize size = [[obj size] sizeValue]; | |
2093 gfx::Point origin = AccessibilityOriginInScreen( | |
2094 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height)); | |
2095 NSPoint location = NSMakePoint(origin.x(), origin.y()); | |
2096 location = [[cocoa_view_ window] convertScreenToBase:location]; | 2074 location = [[cocoa_view_ window] convertScreenToBase:location]; |
2097 location.x += size.width/2; | |
2098 location.y += size.height/2; | |
2099 | |
2100 NSEvent* fakeRightClick = [NSEvent | 2075 NSEvent* fakeRightClick = [NSEvent |
2101 mouseEventWithType:NSRightMouseDown | 2076 mouseEventWithType:NSRightMouseDown |
2102 location:location | 2077 location:location |
2103 modifierFlags:0 | 2078 modifierFlags:0 |
2104 timestamp:0 | 2079 timestamp:0 |
2105 windowNumber:[[cocoa_view_ window] windowNumber] | 2080 windowNumber:[[cocoa_view_ window] windowNumber] |
2106 context:[NSGraphicsContext currentContext] | 2081 context:[NSGraphicsContext currentContext] |
2107 eventNumber:0 | 2082 eventNumber:0 |
2108 clickCount:1 | 2083 clickCount:1 |
2109 pressure:0]; | 2084 pressure:0]; |
2110 | 2085 |
2111 [cocoa_view_ mouseEvent:fakeRightClick]; | 2086 [cocoa_view_ mouseEvent:fakeRightClick]; |
2112 } | 2087 } |
2113 | 2088 |
2114 | |
2115 | |
2116 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 2089 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
2117 if (active) { | 2090 if (active) { |
2118 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2091 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2119 EnablePasswordInput(); | 2092 EnablePasswordInput(); |
2120 else | 2093 else |
2121 DisablePasswordInput(); | 2094 DisablePasswordInput(); |
2122 } else { | 2095 } else { |
2123 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2096 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2124 DisablePasswordInput(); | 2097 DisablePasswordInput(); |
2125 } | 2098 } |
(...skipping 1072 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3198 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; | 3171 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; |
3199 } | 3172 } |
3200 | 3173 |
3201 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { | 3174 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { |
3202 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; | 3175 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; |
3203 return [fullArray count]; | 3176 return [fullArray count]; |
3204 } | 3177 } |
3205 | 3178 |
3206 - (id)accessibilityAttributeValue:(NSString *)attribute { | 3179 - (id)accessibilityAttributeValue:(NSString *)attribute { |
3207 BrowserAccessibilityManager* manager = | 3180 BrowserAccessibilityManager* manager = |
3208 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3181 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3209 | 3182 |
3210 // Contents specifies document view of RenderWidgetHostViewCocoa provided by | 3183 // Contents specifies document view of RenderWidgetHostViewCocoa provided by |
3211 // BrowserAccessibilityManager. Children includes all subviews in addition to | 3184 // BrowserAccessibilityManager. Children includes all subviews in addition to |
3212 // contents. Currently we do not have subviews besides the document view. | 3185 // contents. Currently we do not have subviews besides the document view. |
3213 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || | 3186 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || |
3214 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && | 3187 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && |
3215 manager) { | 3188 manager) { |
3216 return [NSArray arrayWithObjects:manager-> | 3189 return [NSArray arrayWithObjects:manager-> |
3217 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; | 3190 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; |
3218 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { | 3191 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { |
3219 return NSAccessibilityScrollAreaRole; | 3192 return NSAccessibilityScrollAreaRole; |
3220 } | 3193 } |
3221 id ret = [super accessibilityAttributeValue:attribute]; | 3194 id ret = [super accessibilityAttributeValue:attribute]; |
3222 return ret; | 3195 return ret; |
3223 } | 3196 } |
3224 | 3197 |
3225 - (NSArray*)accessibilityAttributeNames { | 3198 - (NSArray*)accessibilityAttributeNames { |
3226 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 3199 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
3227 [ret addObject:NSAccessibilityContentsAttribute]; | 3200 [ret addObject:NSAccessibilityContentsAttribute]; |
3228 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; | 3201 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; |
3229 return ret; | 3202 return ret; |
3230 } | 3203 } |
3231 | 3204 |
3232 - (id)accessibilityHitTest:(NSPoint)point { | 3205 - (id)accessibilityHitTest:(NSPoint)point { |
3233 if (!renderWidgetHostView_->GetBrowserAccessibilityManager()) | 3206 BrowserAccessibilityManager* manager = |
| 3207 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3208 if (!manager) |
3234 return self; | 3209 return self; |
3235 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; | 3210 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; |
3236 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; | 3211 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; |
3237 localPoint.y = NSHeight([self bounds]) - localPoint.y; | 3212 localPoint.y = NSHeight([self bounds]) - localPoint.y; |
3238 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> | 3213 BrowserAccessibilityCocoa* root = |
3239 GetBrowserAccessibilityManager()-> | 3214 manager->GetRoot()->ToBrowserAccessibilityCocoa(); |
3240 GetRoot()->ToBrowserAccessibilityCocoa(); | |
3241 id obj = [root accessibilityHitTest:localPoint]; | 3215 id obj = [root accessibilityHitTest:localPoint]; |
3242 return obj; | 3216 return obj; |
3243 } | 3217 } |
3244 | 3218 |
3245 - (BOOL)accessibilityIsIgnored { | 3219 - (BOOL)accessibilityIsIgnored { |
3246 return !renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3220 BrowserAccessibilityManager* manager = |
| 3221 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3222 return !manager; |
3247 } | 3223 } |
3248 | 3224 |
3249 - (NSUInteger)accessibilityGetIndexOf:(id)child { | 3225 - (NSUInteger)accessibilityGetIndexOf:(id)child { |
3250 BrowserAccessibilityManager* manager = | 3226 BrowserAccessibilityManager* manager = |
3251 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3227 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3252 // Only child is root. | 3228 // Only child is root. |
3253 if (manager && | 3229 if (manager && |
3254 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { | 3230 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { |
3255 return 0; | 3231 return 0; |
3256 } else { | 3232 } else { |
3257 return NSNotFound; | 3233 return NSNotFound; |
3258 } | 3234 } |
3259 } | 3235 } |
3260 | 3236 |
3261 - (id)accessibilityFocusedUIElement { | 3237 - (id)accessibilityFocusedUIElement { |
3262 BrowserAccessibilityManager* manager = | 3238 BrowserAccessibilityManager* manager = |
3263 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3239 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3264 if (manager) { | 3240 if (manager) { |
3265 BrowserAccessibility* focused_item = manager->GetFocus(NULL); | 3241 BrowserAccessibility* focused_item = manager->GetFocus(NULL); |
3266 DCHECK(focused_item); | 3242 DCHECK(focused_item); |
3267 if (focused_item) { | 3243 if (focused_item) { |
3268 BrowserAccessibilityCocoa* focused_item_cocoa = | 3244 BrowserAccessibilityCocoa* focused_item_cocoa = |
3269 focused_item->ToBrowserAccessibilityCocoa(); | 3245 focused_item->ToBrowserAccessibilityCocoa(); |
3270 DCHECK(focused_item_cocoa); | 3246 DCHECK(focused_item_cocoa); |
3271 if (focused_item_cocoa) | 3247 if (focused_item_cocoa) |
3272 return focused_item_cocoa; | 3248 return focused_item_cocoa; |
3273 } | 3249 } |
(...skipping 736 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4010 | 3986 |
4011 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3987 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
4012 // regions that are not draggable. (See ControlRegionView in | 3988 // regions that are not draggable. (See ControlRegionView in |
4013 // native_app_window_cocoa.mm). This requires the render host view to be | 3989 // native_app_window_cocoa.mm). This requires the render host view to be |
4014 // draggable by default. | 3990 // draggable by default. |
4015 - (BOOL)mouseDownCanMoveWindow { | 3991 - (BOOL)mouseDownCanMoveWindow { |
4016 return YES; | 3992 return YES; |
4017 } | 3993 } |
4018 | 3994 |
4019 @end | 3995 @end |
OLD | NEW |