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