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 <QuartzCore/QuartzCore.h> | 8 #include <QuartzCore/QuartzCore.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 2154 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2165 RenderWidgetHostViewMacDictionaryHelper helper(this); | 2165 RenderWidgetHostViewMacDictionaryHelper helper(this); |
2166 helper.ShowDefinitionForSelection(); | 2166 helper.ShowDefinitionForSelection(); |
2167 } | 2167 } |
2168 | 2168 |
2169 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { | 2169 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { |
2170 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); | 2170 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); |
2171 if (render_widget_host_) | 2171 if (render_widget_host_) |
2172 render_widget_host_->SetBackgroundOpaque(opaque); | 2172 render_widget_host_->SetBackgroundOpaque(opaque); |
2173 } | 2173 } |
2174 | 2174 |
2175 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { | 2175 BrowserAccessibilityManager* |
2176 if (!GetBrowserAccessibilityManager()) { | 2176 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( |
2177 SetBrowserAccessibilityManager( | 2177 BrowserAccessibilityDelegate* delegate) { |
2178 new BrowserAccessibilityManagerMac( | 2178 return new BrowserAccessibilityManagerMac( |
2179 cocoa_view_, | 2179 cocoa_view_, |
2180 BrowserAccessibilityManagerMac::GetEmptyDocument(), | 2180 BrowserAccessibilityManagerMac::GetEmptyDocument(), |
2181 render_widget_host_)); | 2181 delegate); |
2182 } | |
2183 } | 2182 } |
2184 | 2183 |
2185 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( | 2184 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
2186 const gfx::Rect& bounds) { | 2185 const gfx::Rect& bounds) { |
2187 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); | 2186 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
2188 NSSize size = NSMakeSize(bounds.width(), bounds.height()); | 2187 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
2189 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 2188 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
2190 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 2189 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
2191 NSPoint originInScreen = | 2190 NSPoint originInScreen = |
2192 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; | 2191 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
2193 originInScreen.y = originInScreen.y - size.height; | 2192 originInScreen.y = originInScreen.y - size.height; |
2194 return gfx::Point(originInScreen.x, originInScreen.y); | 2193 return gfx::Point(originInScreen.x, originInScreen.y); |
2195 } | 2194 } |
2196 | 2195 |
2197 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { | 2196 void RenderWidgetHostViewMac::AccessibilityShowMenu(const gfx::Point& point) { |
2198 // Immediately set the focused item even though we have not officially set | 2197 NSPoint location = NSMakePoint(point.x(), point.y()); |
2199 // focus on it as VoiceOver expects to get the focused item after this | |
2200 // method returns. | |
2201 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2202 if (manager) | |
2203 manager->SetFocus(manager->GetFromID(accObjId), false); | |
2204 } | |
2205 | |
2206 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) { | |
2207 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2208 if (!manager) | |
2209 return; | |
2210 BrowserAccessibilityCocoa* obj = | |
2211 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa(); | |
2212 | |
2213 // Performs a right click copying WebKit's | |
2214 // accessibilityPerformShowMenuAction. | |
2215 NSPoint objOrigin = [obj origin]; | |
2216 NSSize size = [[obj size] sizeValue]; | |
2217 gfx::Point origin = AccessibilityOriginInScreen( | |
2218 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height)); | |
2219 NSPoint location = NSMakePoint(origin.x(), origin.y()); | |
2220 location = [[cocoa_view_ window] convertScreenToBase:location]; | 2198 location = [[cocoa_view_ window] convertScreenToBase:location]; |
2221 location.x += size.width/2; | |
2222 location.y += size.height/2; | |
2223 | |
2224 NSEvent* fakeRightClick = [NSEvent | 2199 NSEvent* fakeRightClick = [NSEvent |
2225 mouseEventWithType:NSRightMouseDown | 2200 mouseEventWithType:NSRightMouseDown |
2226 location:location | 2201 location:location |
2227 modifierFlags:0 | 2202 modifierFlags:0 |
2228 timestamp:0 | 2203 timestamp:0 |
2229 windowNumber:[[cocoa_view_ window] windowNumber] | 2204 windowNumber:[[cocoa_view_ window] windowNumber] |
2230 context:[NSGraphicsContext currentContext] | 2205 context:[NSGraphicsContext currentContext] |
2231 eventNumber:0 | 2206 eventNumber:0 |
2232 clickCount:1 | 2207 clickCount:1 |
2233 pressure:0]; | 2208 pressure:0]; |
2234 | 2209 |
2235 [cocoa_view_ mouseEvent:fakeRightClick]; | 2210 [cocoa_view_ mouseEvent:fakeRightClick]; |
2236 } | 2211 } |
2237 | 2212 |
2238 | |
2239 | |
2240 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 2213 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
2241 if (active) { | 2214 if (active) { |
2242 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2215 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2243 EnablePasswordInput(); | 2216 EnablePasswordInput(); |
2244 else | 2217 else |
2245 DisablePasswordInput(); | 2218 DisablePasswordInput(); |
2246 } else { | 2219 } else { |
2247 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2220 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2248 DisablePasswordInput(); | 2221 DisablePasswordInput(); |
2249 } | 2222 } |
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3569 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; | 3542 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; |
3570 } | 3543 } |
3571 | 3544 |
3572 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { | 3545 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { |
3573 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; | 3546 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; |
3574 return [fullArray count]; | 3547 return [fullArray count]; |
3575 } | 3548 } |
3576 | 3549 |
3577 - (id)accessibilityAttributeValue:(NSString *)attribute { | 3550 - (id)accessibilityAttributeValue:(NSString *)attribute { |
3578 BrowserAccessibilityManager* manager = | 3551 BrowserAccessibilityManager* manager = |
3579 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3552 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3580 | 3553 |
3581 // Contents specifies document view of RenderWidgetHostViewCocoa provided by | 3554 // Contents specifies document view of RenderWidgetHostViewCocoa provided by |
3582 // BrowserAccessibilityManager. Children includes all subviews in addition to | 3555 // BrowserAccessibilityManager. Children includes all subviews in addition to |
3583 // contents. Currently we do not have subviews besides the document view. | 3556 // contents. Currently we do not have subviews besides the document view. |
3584 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || | 3557 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || |
3585 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && | 3558 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && |
3586 manager) { | 3559 manager) { |
3587 return [NSArray arrayWithObjects:manager-> | 3560 return [NSArray arrayWithObjects:manager-> |
3588 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; | 3561 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; |
3589 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { | 3562 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { |
3590 return NSAccessibilityScrollAreaRole; | 3563 return NSAccessibilityScrollAreaRole; |
3591 } | 3564 } |
3592 id ret = [super accessibilityAttributeValue:attribute]; | 3565 id ret = [super accessibilityAttributeValue:attribute]; |
3593 return ret; | 3566 return ret; |
3594 } | 3567 } |
3595 | 3568 |
3596 - (NSArray*)accessibilityAttributeNames { | 3569 - (NSArray*)accessibilityAttributeNames { |
3597 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 3570 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
3598 [ret addObject:NSAccessibilityContentsAttribute]; | 3571 [ret addObject:NSAccessibilityContentsAttribute]; |
3599 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; | 3572 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; |
3600 return ret; | 3573 return ret; |
3601 } | 3574 } |
3602 | 3575 |
3603 - (id)accessibilityHitTest:(NSPoint)point { | 3576 - (id)accessibilityHitTest:(NSPoint)point { |
3604 if (!renderWidgetHostView_->GetBrowserAccessibilityManager()) | 3577 BrowserAccessibilityManager* manager = |
| 3578 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3579 if (!manager) |
3605 return self; | 3580 return self; |
3606 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; | 3581 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; |
3607 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; | 3582 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; |
3608 localPoint.y = NSHeight([self bounds]) - localPoint.y; | 3583 localPoint.y = NSHeight([self bounds]) - localPoint.y; |
3609 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> | 3584 BrowserAccessibilityCocoa* root = |
3610 GetBrowserAccessibilityManager()-> | 3585 manager->GetRoot()->ToBrowserAccessibilityCocoa(); |
3611 GetRoot()->ToBrowserAccessibilityCocoa(); | |
3612 id obj = [root accessibilityHitTest:localPoint]; | 3586 id obj = [root accessibilityHitTest:localPoint]; |
3613 return obj; | 3587 return obj; |
3614 } | 3588 } |
3615 | 3589 |
3616 - (BOOL)accessibilityIsIgnored { | 3590 - (BOOL)accessibilityIsIgnored { |
3617 return !renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3591 BrowserAccessibilityManager* manager = |
| 3592 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3593 return !manager; |
3618 } | 3594 } |
3619 | 3595 |
3620 - (NSUInteger)accessibilityGetIndexOf:(id)child { | 3596 - (NSUInteger)accessibilityGetIndexOf:(id)child { |
3621 BrowserAccessibilityManager* manager = | 3597 BrowserAccessibilityManager* manager = |
3622 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3598 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3623 // Only child is root. | 3599 // Only child is root. |
3624 if (manager && | 3600 if (manager && |
3625 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { | 3601 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { |
3626 return 0; | 3602 return 0; |
3627 } else { | 3603 } else { |
3628 return NSNotFound; | 3604 return NSNotFound; |
3629 } | 3605 } |
3630 } | 3606 } |
3631 | 3607 |
3632 - (id)accessibilityFocusedUIElement { | 3608 - (id)accessibilityFocusedUIElement { |
3633 BrowserAccessibilityManager* manager = | 3609 BrowserAccessibilityManager* manager = |
3634 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3610 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3635 if (manager) { | 3611 if (manager) { |
3636 BrowserAccessibility* focused_item = manager->GetFocus(NULL); | 3612 BrowserAccessibility* focused_item = manager->GetFocus(NULL); |
3637 DCHECK(focused_item); | 3613 DCHECK(focused_item); |
3638 if (focused_item) { | 3614 if (focused_item) { |
3639 BrowserAccessibilityCocoa* focused_item_cocoa = | 3615 BrowserAccessibilityCocoa* focused_item_cocoa = |
3640 focused_item->ToBrowserAccessibilityCocoa(); | 3616 focused_item->ToBrowserAccessibilityCocoa(); |
3641 DCHECK(focused_item_cocoa); | 3617 DCHECK(focused_item_cocoa); |
3642 if (focused_item_cocoa) | 3618 if (focused_item_cocoa) |
3643 return focused_item_cocoa; | 3619 return focused_item_cocoa; |
3644 } | 3620 } |
(...skipping 784 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4429 } | 4405 } |
4430 | 4406 |
4431 - (void)disableRendering { | 4407 - (void)disableRendering { |
4432 // Disable the fade-out animation as the layer is removed. | 4408 // Disable the fade-out animation as the layer is removed. |
4433 ScopedCAActionDisabler disabler; | 4409 ScopedCAActionDisabler disabler; |
4434 [self removeFromSuperlayer]; | 4410 [self removeFromSuperlayer]; |
4435 renderWidgetHostView_ = nil; | 4411 renderWidgetHostView_ = nil; |
4436 } | 4412 } |
4437 | 4413 |
4438 @end // implementation SoftwareLayer | 4414 @end // implementation SoftwareLayer |
OLD | NEW |