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 2163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2174 RenderWidgetHostViewMacDictionaryHelper helper(this); | 2174 RenderWidgetHostViewMacDictionaryHelper helper(this); |
2175 helper.ShowDefinitionForSelection(); | 2175 helper.ShowDefinitionForSelection(); |
2176 } | 2176 } |
2177 | 2177 |
2178 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { | 2178 void RenderWidgetHostViewMac::SetBackgroundOpaque(bool opaque) { |
2179 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); | 2179 RenderWidgetHostViewBase::SetBackgroundOpaque(opaque); |
2180 if (render_widget_host_) | 2180 if (render_widget_host_) |
2181 render_widget_host_->SetBackgroundOpaque(opaque); | 2181 render_widget_host_->SetBackgroundOpaque(opaque); |
2182 } | 2182 } |
2183 | 2183 |
2184 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { | 2184 BrowserAccessibilityManager* |
2185 if (!GetBrowserAccessibilityManager()) { | 2185 RenderWidgetHostViewMac::CreateBrowserAccessibilityManager( |
2186 SetBrowserAccessibilityManager( | 2186 BrowserAccessibilityDelegate* delegate) { |
2187 new BrowserAccessibilityManagerMac( | 2187 return new BrowserAccessibilityManagerMac( |
2188 cocoa_view_, | 2188 cocoa_view_, |
2189 BrowserAccessibilityManagerMac::GetEmptyDocument(), | 2189 BrowserAccessibilityManagerMac::GetEmptyDocument(), |
2190 render_widget_host_)); | 2190 delegate); |
2191 } | |
2192 } | 2191 } |
2193 | 2192 |
2194 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( | 2193 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
2195 const gfx::Rect& bounds) { | 2194 const gfx::Rect& bounds) { |
2196 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); | 2195 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
2197 NSSize size = NSMakeSize(bounds.width(), bounds.height()); | 2196 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
2198 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 2197 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
2199 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 2198 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
2200 NSPoint originInScreen = | 2199 NSPoint originInScreen = |
2201 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; | 2200 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
2202 originInScreen.y = originInScreen.y - size.height; | 2201 originInScreen.y = originInScreen.y - size.height; |
2203 return gfx::Point(originInScreen.x, originInScreen.y); | 2202 return gfx::Point(originInScreen.x, originInScreen.y); |
2204 } | 2203 } |
2205 | 2204 |
2206 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { | 2205 void RenderWidgetHostViewMac::AccessibilityShowMenu(const gfx::Point& point) { |
2207 // Immediately set the focused item even though we have not officially set | 2206 NSPoint location = NSMakePoint(point.x(), point.y()); |
2208 // focus on it as VoiceOver expects to get the focused item after this | |
2209 // method returns. | |
2210 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2211 if (manager) | |
2212 manager->SetFocus(manager->GetFromID(accObjId), false); | |
2213 } | |
2214 | |
2215 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) { | |
2216 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); | |
2217 if (!manager) | |
2218 return; | |
2219 BrowserAccessibilityCocoa* obj = | |
2220 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa(); | |
2221 | |
2222 // Performs a right click copying WebKit's | |
2223 // accessibilityPerformShowMenuAction. | |
2224 NSPoint objOrigin = [obj origin]; | |
2225 NSSize size = [[obj size] sizeValue]; | |
2226 gfx::Point origin = AccessibilityOriginInScreen( | |
2227 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height)); | |
2228 NSPoint location = NSMakePoint(origin.x(), origin.y()); | |
2229 location = [[cocoa_view_ window] convertScreenToBase:location]; | 2207 location = [[cocoa_view_ window] convertScreenToBase:location]; |
2230 location.x += size.width/2; | |
2231 location.y += size.height/2; | |
2232 | |
2233 NSEvent* fakeRightClick = [NSEvent | 2208 NSEvent* fakeRightClick = [NSEvent |
2234 mouseEventWithType:NSRightMouseDown | 2209 mouseEventWithType:NSRightMouseDown |
2235 location:location | 2210 location:location |
2236 modifierFlags:0 | 2211 modifierFlags:0 |
2237 timestamp:0 | 2212 timestamp:0 |
2238 windowNumber:[[cocoa_view_ window] windowNumber] | 2213 windowNumber:[[cocoa_view_ window] windowNumber] |
2239 context:[NSGraphicsContext currentContext] | 2214 context:[NSGraphicsContext currentContext] |
2240 eventNumber:0 | 2215 eventNumber:0 |
2241 clickCount:1 | 2216 clickCount:1 |
2242 pressure:0]; | 2217 pressure:0]; |
2243 | 2218 |
2244 [cocoa_view_ mouseEvent:fakeRightClick]; | 2219 [cocoa_view_ mouseEvent:fakeRightClick]; |
2245 } | 2220 } |
2246 | 2221 |
2247 | |
2248 | |
2249 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 2222 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
2250 if (active) { | 2223 if (active) { |
2251 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2224 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2252 EnablePasswordInput(); | 2225 EnablePasswordInput(); |
2253 else | 2226 else |
2254 DisablePasswordInput(); | 2227 DisablePasswordInput(); |
2255 } else { | 2228 } else { |
2256 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2229 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
2257 DisablePasswordInput(); | 2230 DisablePasswordInput(); |
2258 } | 2231 } |
(...skipping 1312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3571 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; | 3544 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; |
3572 } | 3545 } |
3573 | 3546 |
3574 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { | 3547 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { |
3575 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; | 3548 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; |
3576 return [fullArray count]; | 3549 return [fullArray count]; |
3577 } | 3550 } |
3578 | 3551 |
3579 - (id)accessibilityAttributeValue:(NSString *)attribute { | 3552 - (id)accessibilityAttributeValue:(NSString *)attribute { |
3580 BrowserAccessibilityManager* manager = | 3553 BrowserAccessibilityManager* manager = |
3581 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3554 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3582 | 3555 |
3583 // Contents specifies document view of RenderWidgetHostViewCocoa provided by | 3556 // Contents specifies document view of RenderWidgetHostViewCocoa provided by |
3584 // BrowserAccessibilityManager. Children includes all subviews in addition to | 3557 // BrowserAccessibilityManager. Children includes all subviews in addition to |
3585 // contents. Currently we do not have subviews besides the document view. | 3558 // contents. Currently we do not have subviews besides the document view. |
3586 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || | 3559 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || |
3587 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && | 3560 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && |
3588 manager) { | 3561 manager) { |
3589 return [NSArray arrayWithObjects:manager-> | 3562 return [NSArray arrayWithObjects:manager-> |
3590 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; | 3563 GetRoot()->ToBrowserAccessibilityCocoa(), nil]; |
3591 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { | 3564 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { |
3592 return NSAccessibilityScrollAreaRole; | 3565 return NSAccessibilityScrollAreaRole; |
3593 } | 3566 } |
3594 id ret = [super accessibilityAttributeValue:attribute]; | 3567 id ret = [super accessibilityAttributeValue:attribute]; |
3595 return ret; | 3568 return ret; |
3596 } | 3569 } |
3597 | 3570 |
3598 - (NSArray*)accessibilityAttributeNames { | 3571 - (NSArray*)accessibilityAttributeNames { |
3599 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 3572 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
3600 [ret addObject:NSAccessibilityContentsAttribute]; | 3573 [ret addObject:NSAccessibilityContentsAttribute]; |
3601 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; | 3574 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; |
3602 return ret; | 3575 return ret; |
3603 } | 3576 } |
3604 | 3577 |
3605 - (id)accessibilityHitTest:(NSPoint)point { | 3578 - (id)accessibilityHitTest:(NSPoint)point { |
3606 if (!renderWidgetHostView_->GetBrowserAccessibilityManager()) | 3579 BrowserAccessibilityManager* manager = |
| 3580 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3581 if (!manager) |
3607 return self; | 3582 return self; |
3608 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; | 3583 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; |
3609 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; | 3584 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; |
3610 localPoint.y = NSHeight([self bounds]) - localPoint.y; | 3585 localPoint.y = NSHeight([self bounds]) - localPoint.y; |
3611 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> | 3586 BrowserAccessibilityCocoa* root = |
3612 GetBrowserAccessibilityManager()-> | 3587 manager->GetRoot()->ToBrowserAccessibilityCocoa(); |
3613 GetRoot()->ToBrowserAccessibilityCocoa(); | |
3614 id obj = [root accessibilityHitTest:localPoint]; | 3588 id obj = [root accessibilityHitTest:localPoint]; |
3615 return obj; | 3589 return obj; |
3616 } | 3590 } |
3617 | 3591 |
3618 - (BOOL)accessibilityIsIgnored { | 3592 - (BOOL)accessibilityIsIgnored { |
3619 return !renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3593 BrowserAccessibilityManager* manager = |
| 3594 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
| 3595 return !manager; |
3620 } | 3596 } |
3621 | 3597 |
3622 - (NSUInteger)accessibilityGetIndexOf:(id)child { | 3598 - (NSUInteger)accessibilityGetIndexOf:(id)child { |
3623 BrowserAccessibilityManager* manager = | 3599 BrowserAccessibilityManager* manager = |
3624 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3600 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3625 // Only child is root. | 3601 // Only child is root. |
3626 if (manager && | 3602 if (manager && |
3627 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { | 3603 manager->GetRoot()->ToBrowserAccessibilityCocoa() == child) { |
3628 return 0; | 3604 return 0; |
3629 } else { | 3605 } else { |
3630 return NSNotFound; | 3606 return NSNotFound; |
3631 } | 3607 } |
3632 } | 3608 } |
3633 | 3609 |
3634 - (id)accessibilityFocusedUIElement { | 3610 - (id)accessibilityFocusedUIElement { |
3635 BrowserAccessibilityManager* manager = | 3611 BrowserAccessibilityManager* manager = |
3636 renderWidgetHostView_->GetBrowserAccessibilityManager(); | 3612 renderWidgetHostView_->GetHost()->GetRootBrowserAccessibilityManager(); |
3637 if (manager) { | 3613 if (manager) { |
3638 BrowserAccessibility* focused_item = manager->GetFocus(NULL); | 3614 BrowserAccessibility* focused_item = manager->GetFocus(NULL); |
3639 DCHECK(focused_item); | 3615 DCHECK(focused_item); |
3640 if (focused_item) { | 3616 if (focused_item) { |
3641 BrowserAccessibilityCocoa* focused_item_cocoa = | 3617 BrowserAccessibilityCocoa* focused_item_cocoa = |
3642 focused_item->ToBrowserAccessibilityCocoa(); | 3618 focused_item->ToBrowserAccessibilityCocoa(); |
3643 DCHECK(focused_item_cocoa); | 3619 DCHECK(focused_item_cocoa); |
3644 if (focused_item_cocoa) | 3620 if (focused_item_cocoa) |
3645 return focused_item_cocoa; | 3621 return focused_item_cocoa; |
3646 } | 3622 } |
(...skipping 738 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4385 | 4361 |
4386 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 4362 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
4387 // regions that are not draggable. (See ControlRegionView in | 4363 // regions that are not draggable. (See ControlRegionView in |
4388 // native_app_window_cocoa.mm). This requires the render host view to be | 4364 // native_app_window_cocoa.mm). This requires the render host view to be |
4389 // draggable by default. | 4365 // draggable by default. |
4390 - (BOOL)mouseDownCanMoveWindow { | 4366 - (BOOL)mouseDownCanMoveWindow { |
4391 return YES; | 4367 return YES; |
4392 } | 4368 } |
4393 | 4369 |
4394 @end | 4370 @end |
OLD | NEW |