| 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 2042 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2053 render_widget_host_->Send(new ViewMsg_SetBackground( | 2053 render_widget_host_->Send(new ViewMsg_SetBackground( |
| 2054 render_widget_host_->GetRoutingID(), background)); | 2054 render_widget_host_->GetRoutingID(), background)); |
| 2055 } | 2055 } |
| 2056 | 2056 |
| 2057 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { | 2057 void RenderWidgetHostViewMac::CreateBrowserAccessibilityManagerIfNeeded() { |
| 2058 if (!GetBrowserAccessibilityManager()) { | 2058 if (!GetBrowserAccessibilityManager()) { |
| 2059 SetBrowserAccessibilityManager( | 2059 SetBrowserAccessibilityManager( |
| 2060 new BrowserAccessibilityManagerMac( | 2060 new BrowserAccessibilityManagerMac( |
| 2061 cocoa_view_, | 2061 cocoa_view_, |
| 2062 BrowserAccessibilityManagerMac::GetEmptyDocument(), | 2062 BrowserAccessibilityManagerMac::GetEmptyDocument(), |
| 2063 NULL)); | 2063 render_widget_host_)); |
| 2064 } | 2064 } |
| 2065 } | 2065 } |
| 2066 | 2066 |
| 2067 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
| 2068 const gfx::Rect& bounds) { |
| 2069 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
| 2070 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
| 2071 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
| 2072 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
| 2073 NSPoint originInScreen = |
| 2074 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; |
| 2075 originInScreen.y = originInScreen.y - size.height; |
| 2076 return gfx::Point(originInScreen.x, originInScreen.y); |
| 2077 } |
| 2078 |
| 2079 void RenderWidgetHostViewMac::OnAccessibilitySetFocus(int accObjId) { |
| 2080 // Immediately set the focused item even though we have not officially set |
| 2081 // focus on it as VoiceOver expects to get the focused item after this |
| 2082 // method returns. |
| 2083 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
| 2084 if (manager) |
| 2085 manager->SetFocus(manager->GetFromID(accObjId), false); |
| 2086 } |
| 2087 |
| 2088 void RenderWidgetHostViewMac::AccessibilityShowMenu(int accObjId) { |
| 2089 BrowserAccessibilityManager* manager = GetBrowserAccessibilityManager(); |
| 2090 if (!manager) |
| 2091 return; |
| 2092 BrowserAccessibilityCocoa* obj = |
| 2093 manager->GetFromID(accObjId)->ToBrowserAccessibilityCocoa(); |
| 2094 |
| 2095 // Performs a right click copying WebKit's |
| 2096 // accessibilityPerformShowMenuAction. |
| 2097 NSPoint objOrigin = [obj origin]; |
| 2098 NSSize size = [[obj size] sizeValue]; |
| 2099 gfx::Point origin = AccessibilityOriginInScreen( |
| 2100 gfx::Rect(objOrigin.x, objOrigin.y, size.width, size.height)); |
| 2101 NSPoint location = NSMakePoint(origin.x(), origin.y()); |
| 2102 location = [[cocoa_view_ window] convertScreenToBase:location]; |
| 2103 location.x += size.width/2; |
| 2104 location.y += size.height/2; |
| 2105 |
| 2106 NSEvent* fakeRightClick = [NSEvent |
| 2107 mouseEventWithType:NSRightMouseDown |
| 2108 location:location |
| 2109 modifierFlags:0 |
| 2110 timestamp:0 |
| 2111 windowNumber:[[cocoa_view_ window] windowNumber] |
| 2112 context:[NSGraphicsContext currentContext] |
| 2113 eventNumber:0 |
| 2114 clickCount:1 |
| 2115 pressure:0]; |
| 2116 |
| 2117 [cocoa_view_ mouseEvent:fakeRightClick]; |
| 2118 } |
| 2119 |
| 2120 |
| 2121 |
| 2067 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 2122 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| 2068 if (active) { | 2123 if (active) { |
| 2069 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2124 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 2070 EnablePasswordInput(); | 2125 EnablePasswordInput(); |
| 2071 else | 2126 else |
| 2072 DisablePasswordInput(); | 2127 DisablePasswordInput(); |
| 2073 } else { | 2128 } else { |
| 2074 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 2129 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 2075 DisablePasswordInput(); | 2130 DisablePasswordInput(); |
| 2076 } | 2131 } |
| (...skipping 1345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3422 BrowserAccessibilityCocoa* focused_item_cocoa = | 3477 BrowserAccessibilityCocoa* focused_item_cocoa = |
| 3423 focused_item->ToBrowserAccessibilityCocoa(); | 3478 focused_item->ToBrowserAccessibilityCocoa(); |
| 3424 DCHECK(focused_item_cocoa); | 3479 DCHECK(focused_item_cocoa); |
| 3425 if (focused_item_cocoa) | 3480 if (focused_item_cocoa) |
| 3426 return focused_item_cocoa; | 3481 return focused_item_cocoa; |
| 3427 } | 3482 } |
| 3428 } | 3483 } |
| 3429 return [super accessibilityFocusedUIElement]; | 3484 return [super accessibilityFocusedUIElement]; |
| 3430 } | 3485 } |
| 3431 | 3486 |
| 3432 - (void)doDefaultAction:(int32)accessibilityObjectId { | |
| 3433 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3434 rwh->Send(new AccessibilityMsg_DoDefaultAction( | |
| 3435 rwh->GetRoutingID(), accessibilityObjectId)); | |
| 3436 } | |
| 3437 | |
| 3438 // VoiceOver uses this method to move the caret to the beginning of the next | |
| 3439 // word in a text field. | |
| 3440 - (void)accessibilitySetTextSelection:(int32)accId | |
| 3441 startOffset:(int32)startOffset | |
| 3442 endOffset:(int32)endOffset { | |
| 3443 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3444 rwh->AccessibilitySetTextSelection(accId, startOffset, endOffset); | |
| 3445 } | |
| 3446 | |
| 3447 // Convert a web accessibility's location in web coordinates into a cocoa | |
| 3448 // screen coordinate. | |
| 3449 - (NSPoint)accessibilityPointInScreen:(NSPoint)origin | |
| 3450 size:(NSSize)size { | |
| 3451 origin.y = NSHeight([self bounds]) - origin.y; | |
| 3452 NSPoint originInWindow = [self convertPoint:origin toView:nil]; | |
| 3453 NSPoint originInScreen = [[self window] convertBaseToScreen:originInWindow]; | |
| 3454 originInScreen.y = originInScreen.y - size.height; | |
| 3455 return originInScreen; | |
| 3456 } | |
| 3457 | |
| 3458 - (void)setAccessibilityFocus:(BOOL)focus | |
| 3459 accessibilityId:(int32)accessibilityObjectId { | |
| 3460 if (focus) { | |
| 3461 RenderWidgetHostImpl* rwh = renderWidgetHostView_->render_widget_host_; | |
| 3462 rwh->Send(new AccessibilityMsg_SetFocus( | |
| 3463 rwh->GetRoutingID(), accessibilityObjectId)); | |
| 3464 | |
| 3465 // Immediately set the focused item even though we have not officially set | |
| 3466 // focus on it as VoiceOver expects to get the focused item after this | |
| 3467 // method returns. | |
| 3468 BrowserAccessibilityManager* manager = | |
| 3469 renderWidgetHostView_->GetBrowserAccessibilityManager(); | |
| 3470 manager->SetFocus(manager->GetFromID(accessibilityObjectId), false); | |
| 3471 } | |
| 3472 } | |
| 3473 | |
| 3474 - (void)performShowMenuAction:(BrowserAccessibilityCocoa*)accessibility { | |
| 3475 // Performs a right click copying WebKit's | |
| 3476 // accessibilityPerformShowMenuAction. | |
| 3477 NSPoint origin = [accessibility origin]; | |
| 3478 NSSize size = [[accessibility size] sizeValue]; | |
| 3479 NSPoint location = [self accessibilityPointInScreen:origin size:size]; | |
| 3480 location = [[self window] convertScreenToBase:location]; | |
| 3481 location.x += size.width/2; | |
| 3482 location.y += size.height/2; | |
| 3483 | |
| 3484 NSEvent* fakeRightClick = [NSEvent | |
| 3485 mouseEventWithType:NSRightMouseDown | |
| 3486 location:location | |
| 3487 modifierFlags:0 | |
| 3488 timestamp:0 | |
| 3489 windowNumber:[[self window] windowNumber] | |
| 3490 context:[NSGraphicsContext currentContext] | |
| 3491 eventNumber:0 | |
| 3492 clickCount:1 | |
| 3493 pressure:0]; | |
| 3494 | |
| 3495 [self mouseEvent:fakeRightClick]; | |
| 3496 } | |
| 3497 | |
| 3498 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm | 3487 // Below is the nasty tooltip stuff -- copied from WebKit's WebHTMLView.mm |
| 3499 // with minor modifications for code style and commenting. | 3488 // with minor modifications for code style and commenting. |
| 3500 // | 3489 // |
| 3501 // The 'public' interface is -setToolTipAtMousePoint:. This differs from | 3490 // The 'public' interface is -setToolTipAtMousePoint:. This differs from |
| 3502 // -setToolTip: in that the updated tooltip takes effect immediately, | 3491 // -setToolTip: in that the updated tooltip takes effect immediately, |
| 3503 // without the user's having to move the mouse out of and back into the view. | 3492 // without the user's having to move the mouse out of and back into the view. |
| 3504 // | 3493 // |
| 3505 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to | 3494 // Unfortunately, doing this requires sending fake mouseEnter/Exit events to |
| 3506 // the view, which in turn requires overriding some internal tracking-rect | 3495 // the view, which in turn requires overriding some internal tracking-rect |
| 3507 // methods (to keep track of its owner & userdata, which need to be filled out | 3496 // 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... |
| 4278 } | 4267 } |
| 4279 | 4268 |
| 4280 - (void)disableRendering { | 4269 - (void)disableRendering { |
| 4281 // Disable the fade-out animation as the layer is removed. | 4270 // Disable the fade-out animation as the layer is removed. |
| 4282 ScopedCAActionDisabler disabler; | 4271 ScopedCAActionDisabler disabler; |
| 4283 [self removeFromSuperlayer]; | 4272 [self removeFromSuperlayer]; |
| 4284 renderWidgetHostView_ = nil; | 4273 renderWidgetHostView_ = nil; |
| 4285 } | 4274 } |
| 4286 | 4275 |
| 4287 @end // implementation SoftwareLayer | 4276 @end // implementation SoftwareLayer |
| OLD | NEW |