| 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 2047 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2058 render_widget_host_->Send(new ViewMsg_SetBackground( | 2058 render_widget_host_->Send(new ViewMsg_SetBackground( |
| 2059 render_widget_host_->GetRoutingID(), background)); | 2059 render_widget_host_->GetRoutingID(), background)); |
| 2060 } | 2060 } |
| 2061 | 2061 |
| 2062 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { | 2062 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { |
| 2063 if (!GetBrowserAccessibilityManager()) { | 2063 if (!GetBrowserAccessibilityManager()) { |
| 2064 SetBrowserAccessibilityManager( | 2064 SetBrowserAccessibilityManager( |
| 2065 new BrowserAccessibilityManagerMac( | 2065 new BrowserAccessibilityManagerMac( |
| 2066 cocoa_view_, | 2066 cocoa_view_, |
| 2067 BrowserAccessibilityManagerMac::GetEmptyDocument(), | 2067 BrowserAccessibilityManagerMac::GetEmptyDocument(), |
| 2068 NULL)); | 2068 render_widget_host_)); |
| 2069 } | 2069 } |
| 2070 } | 2070 } |
| 2071 | 2071 |
| 2072 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
| 2073 const gfx::Rect& bounds) { |
| 2074 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
| 2075 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
| 2076 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
| 2077 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
| 2078 NSPoint originInScreen = |
| 2079 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
| 2080 originInScreen.y = originInScreen.y - size.height; |
| 2081 return gfx::Point(originInScreen.x, originInScreen.y); |
| 2082 } |
| 2083 |
| 2084 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { |
| 2085 // Immediately set the focused item even though we have not officially set |
| 2086 // focus on it as VoiceOver expects to get the focused item after this |
| 2087 // method returns. |
| 2088 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
| 2089 if (manager) |
| 2090 manager->SetFocus(manager->GetFromID(accObjId), false); |
| 2091 } |
| 2092 |
| 2093 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) { |
| 2094 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
| 2095 if (!manager) |
| 2096 return; |
| 2097 BrowserAccessibilityCocoa* obj = |
| 2098 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa(); |
| 2099 |
| 2100 // Performs a right click copying WebKit's |
| 2101 // accessibilityPerformShowMenuAction. |
| 2102 NSPoint objOrigin = [obj origin]; |
| 2103 NSSize size = [[obj size] sizeValue]; |
| 2104 gfx::Point origin = AccessibilityOriginInScreen( |
| 2105 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height)); |
| 2106 NSPoint location = NSMakePoint(origin.x(), origin.y()); |
| 2107 location = [[cocoa_view_ window] convertScreenToBase:location]; |
| 2108 location.x += size.width/2; |
| 2109 location.y += size.height/2; |
| 2110 |
| 2111 NSEvent* fakeRightClick = [NSEvent |
| 2112 mouseEventWithType:NSRightMouseDown |
| 2113 location:location |
| 2114 modifierFlags:0 |
| 2115 timestamp:0 |
| 2116 windowNumber:[[cocoa_view_ window] windowNumber] |
| 2117 context:[NSGraphicsContext currentContext] |
| 2118 eventNumber:0 |
| 2119 clickCount:1 |
| 2120 pressure:0]; |
| 2121 |
| 2122 [cocoa_view_ mouseEvent:fakeRightClick]; |
| 2123 } |
| 2124 |
| 2125 |
| 2126 |
| 2072 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 2127 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| 2073 if (active) { | 2128 if (active) { |
| 2074 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2129 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 2075 EnablePasswordInput(); | 2130 EnablePasswordInput(); |
| 2076 else | 2131 else |
| 2077 DisablePasswordInput(); | 2132 DisablePasswordInput(); |
| 2078 } else { | 2133 } else { |
| 2079 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2134 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 2080 DisablePasswordInput(); | 2135 DisablePasswordInput(); |
| 2081 } | 2136 } |
| (...skipping 1372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3454 BrowserAccessibilityCocoa* focused_item_cocoa = | 3509 BrowserAccessibilityCocoa* focused_item_cocoa = |
| 3455 focused_item->ToBrowserAccessibilityCocoa(); | 3510 focused_item->ToBrowserAccessibilityCocoa(); |
| 3456 DCHECK(focused_item_cocoa); | 3511 DCHECK(focused_item_cocoa); |
| 3457 if (focused_item_cocoa) | 3512 if (focused_item_cocoa) |
| 3458 return focused_item_cocoa; | 3513 return focused_item_cocoa; |
| 3459 } | 3514 } |
| 3460 } | 3515 } |
| 3461 return [super accessibilityFocusedUIElement]; | 3516 return [super accessibilityFocusedUIElement]; |
| 3462 } | 3517 } |
| 3463 | 3518 |
| 3464 - (void)doDefaultAction:(int32)accessibilityObjectId { | |
| 3465 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3466 rwh->Send(new AccessibilityMsg_DoDefaultAction( | |
| 3467 rwh->GetRoutingID(), accessibilityObjectId)); | |
| 3468 } | |
| 3469 | |
| 3470 // VoiceOver uses this method to move the caret to the beginning of the next | |
| 3471 // word in a text field. | |
| 3472 - (void)accessibilitySetTextSelection:(int32)accId | |
| 3473 startOffset:(int32)startOffset | |
| 3474 endOffset:(int32)endOffset { | |
| 3475 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3476 rwh->AccessibilitySetTextSelection(accId, startOffset, endOffset); | |
| 3477 } | |
| 3478 | |
| 3479 // Convert a web accessibility's location in web coordinates into a cocoa | |
| 3480 // screen coordinate. | |
| 3481 - (NSPoint)accessibilityPointInScreen:(NSPoint)origin | |
| 3482 size:(NSSize)size { | |
| 3483 origin.y = NSHeight([self bounds]) - origin.y; | |
| 3484 NSPoint originInWindow = [self convertPoint:origin toView:nil]; | |
| 3485 NSPoint originInScreen = [[self window] convertBaseToScreen:originInWindow]; | |
| 3486 originInScreen.y = originInScreen.y - size.height; | |
| 3487 return originInScreen; | |
| 3488 } | |
| 3489 | |
| 3490 - (void)setAccessibilityFocus:(BOOL)focus | |
| 3491 accessibilityId:(int32)accessibilityObjectId { | |
| 3492 if (focus) { | |
| 3493 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3494 rwh->Send(new AccessibilityMsg_SetFocus( | |
| 3495 rwh->GetRoutingID(), accessibilityObjectId)); | |
| 3496 | |
| 3497 // Immediately set the focused item even though we have not officially set | |
| 3498 // focus on it as VoiceOver expects to get the focused item after this | |
| 3499 // method returns. | |
| 3500 BrowserAccessibilityManager* manager = | |
| 3501 renderWidgetHostView_->GetBrowserAccessibilityManager(); | |
| 3502 manager->SetFocus(manager->GetFromID(accessibilityObjectId), false); | |
| 3503 } | |
| 3504 } | |
| 3505 | |
| 3506 - (void)performShowMenuAction:(BrowserAccessibilityCocoa*)accessibility { | |
| 3507 // Performs a right click copying WebKit's | |
| 3508 // accessibilityPerformShowMenuAction. | |
| 3509 NSPoint origin = [accessibility origin]; | |
| 3510 NSSize size = [[accessibility size] sizeValue]; | |
| 3511 NSPoint location = [self accessibilityPointInScreen:origin size:size]; | |
| 3512 location = [[self window] convertScreenToBase:location]; | |
| 3513 location.x += size.width/2; | |
| 3514 location.y += size.height/2; | |
| 3515 | |
| 3516 NSEvent* fakeRightClick = [NSEvent | |
| 3517 mouseEventWithType:NSRightMouseDown | |
| 3518 location:location | |
| 3519 modifierFlags:0 | |
| 3520 timestamp:0 | |
| 3521 windowNumber:[[self window] windowNumber] | |
| 3522 context:[NSGraphicsContext currentContext] | |
| 3523 eventNumber:0 | |
| 3524 clickCount:1 | |
| 3525 pressure:0]; | |
| 3526 | |
| 3527 [self mouseEvent:fakeRightClick]; | |
| 3528 } | |
| 3529 | |
| 3530 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm | 3519 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm |
| 3531 // with minor modifications for code style and commenting. | 3520 // with minor modifications for code style and commenting. |
| 3532 // | 3521 // |
| 3533 // The 'public' interface is -setToolTipAtMousePoint:. This differs from | 3522 // The 'public' interface is -setToolTipAtMousePoint:. This differs from |
| 3534 // -setToolTip: in that the updated tooltip takes effect immediately, | 3523 // -setToolTip: in that the updated tooltip takes effect immediately, |
| 3535 // without the user's having to move the mouse out of and back into the view. | 3524 // without the user's having to move the mouse out of and back into the view. |
| 3536 // | 3525 // |
| 3537 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to | 3526 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to |
| 3538 // the view, which in turn requires overriding some internal tracking-rect | 3527 // the view, which in turn requires overriding some internal tracking-rect |
| 3539 // methods (to keep track of its owner & userdata, which need to be filled out | 3528 // methods (to keep track of its owner & userdata, which need to be filled out |
| (...skipping 770 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4310 } | 4299 } |
| 4311 | 4300 |
| 4312 - (void)disableRendering { | 4301 - (void)disableRendering { |
| 4313 // Disable the fade-out animation as the layer is removed. | 4302 // Disable the fade-out animation as the layer is removed. |
| 4314 ScopedCAActionDisabler disabler; | 4303 ScopedCAActionDisabler disabler; |
| 4315 [self removeFromSuperlayer]; | 4304 [self removeFromSuperlayer]; |
| 4316 renderWidgetHostView_ = nil; | 4305 renderWidgetHostView_ = nil; |
| 4317 } | 4306 } |
| 4318 | 4307 |
| 4319 @end // implementation SoftwareLayer | 4308 @end // implementation SoftwareLayer |
| OLD | NEW |