| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
| 11 #include "base/logging.h" | 11 #include "base/logging.h" |
| 12 #include "base/mac/mac_util.h" | 12 #include "base/mac/mac_util.h" |
| 13 #include "base/mac/scoped_cftyperef.h" | 13 #include "base/mac/scoped_cftyperef.h" |
| 14 #import "base/mac/scoped_nsautorelease_pool.h" | 14 #import "base/mac/scoped_nsautorelease_pool.h" |
| 15 #import "base/memory/scoped_nsobject.h" | 15 #import "base/memory/scoped_nsobject.h" |
| 16 #include "base/metrics/histogram.h" | 16 #include "base/metrics/histogram.h" |
| 17 #include "base/string_util.h" | 17 #include "base/string_util.h" |
| 18 #include "base/sys_info.h" | 18 #include "base/sys_info.h" |
| 19 #include "base/sys_string_conversions.h" | 19 #include "base/sys_string_conversions.h" |
| 20 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
| 21 #import "content/browser/accessibility/browser_accessibility_cocoa.h" | 21 #import "content/browser/accessibility/browser_accessibility_cocoa.h" |
| 22 #include "content/browser/mac/closure_blocks_leopard_compat.h" | 22 #include "content/browser/mac/closure_blocks_leopard_compat.h" |
| 23 #include "content/browser/plugin_process_host.h" | 23 #include "content/browser/plugin_process_host.h" |
| 24 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" | 24 #import "content/browser/renderer_host/accelerated_plugin_view_mac.h" |
| 25 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| 25 #include "content/browser/renderer_host/backing_store_mac.h" | 26 #include "content/browser/renderer_host/backing_store_mac.h" |
| 26 #include "content/browser/renderer_host/render_process_host_impl.h" | 27 #include "content/browser/renderer_host/render_process_host_impl.h" |
| 27 #include "content/browser/renderer_host/render_view_host.h" | 28 #include "content/browser/renderer_host/render_view_host.h" |
| 28 #import "content/browser/renderer_host/render_widget_host_view_mac_delegate.h" | 29 #import "content/browser/renderer_host/render_widget_host_view_mac_delegate.h" |
| 29 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" | 30 #import "content/browser/renderer_host/render_widget_host_view_mac_editcommand_h
elper.h" |
| 30 #import "content/browser/renderer_host/text_input_client_mac.h" | 31 #import "content/browser/renderer_host/text_input_client_mac.h" |
| 31 #include "content/common/edit_command.h" | 32 #include "content/common/edit_command.h" |
| 32 #include "content/common/gpu/gpu_messages.h" | 33 #include "content/common/gpu/gpu_messages.h" |
| 33 #include "content/common/plugin_messages.h" | 34 #include "content/common/plugin_messages.h" |
| 34 #include "content/common/view_messages.h" | 35 #include "content/common/view_messages.h" |
| (...skipping 1056 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 | 1092 |
| 1092 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { | 1093 void RenderWidgetHostViewMac::SetBackground(const SkBitmap& background) { |
| 1093 RenderWidgetHostView::SetBackground(background); | 1094 RenderWidgetHostView::SetBackground(background); |
| 1094 if (render_widget_host_) | 1095 if (render_widget_host_) |
| 1095 render_widget_host_->Send(new ViewMsg_SetBackground( | 1096 render_widget_host_->Send(new ViewMsg_SetBackground( |
| 1096 render_widget_host_->routing_id(), background)); | 1097 render_widget_host_->routing_id(), background)); |
| 1097 } | 1098 } |
| 1098 | 1099 |
| 1099 void RenderWidgetHostViewMac::OnAccessibilityNotifications( | 1100 void RenderWidgetHostViewMac::OnAccessibilityNotifications( |
| 1100 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { | 1101 const std::vector<ViewHostMsg_AccessibilityNotification_Params>& params) { |
| 1101 if (!browser_accessibility_manager_.get()) { | 1102 if (!browser_accessibility_manager()) { |
| 1102 browser_accessibility_manager_.reset( | 1103 browser_accessibility_manager( |
| 1103 BrowserAccessibilityManager::CreateEmptyDocument( | 1104 BrowserAccessibilityManager::CreateEmptyDocument( |
| 1104 cocoa_view_, static_cast<WebAccessibility::State>(0), NULL)); | 1105 cocoa_view_, static_cast<WebAccessibility::State>(0), NULL)); |
| 1105 } | 1106 } |
| 1106 browser_accessibility_manager_->OnAccessibilityNotifications(params); | 1107 browser_accessibility_manager()->OnAccessibilityNotifications(params); |
| 1107 } | 1108 } |
| 1108 | 1109 |
| 1109 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 1110 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| 1110 if (active) { | 1111 if (active) { |
| 1111 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1112 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 1112 EnablePasswordInput(); | 1113 EnablePasswordInput(); |
| 1113 else | 1114 else |
| 1114 DisablePasswordInput(); | 1115 DisablePasswordInput(); |
| 1115 } else { | 1116 } else { |
| 1116 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1117 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1921 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; | 1922 return [fullArray subarrayWithRange:NSMakeRange(index, length)]; |
| 1922 } | 1923 } |
| 1923 | 1924 |
| 1924 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { | 1925 - (NSUInteger)accessibilityArrayAttributeCount:(NSString *)attribute { |
| 1925 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; | 1926 NSArray* fullArray = [self accessibilityAttributeValue:attribute]; |
| 1926 return [fullArray count]; | 1927 return [fullArray count]; |
| 1927 } | 1928 } |
| 1928 | 1929 |
| 1929 - (id)accessibilityAttributeValue:(NSString *)attribute { | 1930 - (id)accessibilityAttributeValue:(NSString *)attribute { |
| 1930 BrowserAccessibilityManager* manager = | 1931 BrowserAccessibilityManager* manager = |
| 1931 renderWidgetHostView_->browser_accessibility_manager_.get(); | 1932 renderWidgetHostView_->browser_accessibility_manager(); |
| 1932 | 1933 |
| 1933 // Contents specifies document view of RenderWidgetHostViewCocoa provided by | 1934 // Contents specifies document view of RenderWidgetHostViewCocoa provided by |
| 1934 // BrowserAccessibilityManager. Children includes all subviews in addition to | 1935 // BrowserAccessibilityManager. Children includes all subviews in addition to |
| 1935 // contents. Currently we do not have subviews besides the document view. | 1936 // contents. Currently we do not have subviews besides the document view. |
| 1936 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || | 1937 if (([attribute isEqualToString:NSAccessibilityChildrenAttribute] || |
| 1937 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && | 1938 [attribute isEqualToString:NSAccessibilityContentsAttribute]) && |
| 1938 manager) { | 1939 manager) { |
| 1939 return [NSArray arrayWithObjects:manager-> | 1940 return [NSArray arrayWithObjects:manager-> |
| 1940 GetRoot()->toBrowserAccessibilityCocoa(), nil]; | 1941 GetRoot()->toBrowserAccessibilityCocoa(), nil]; |
| 1941 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { | 1942 } else if ([attribute isEqualToString:NSAccessibilityRoleAttribute]) { |
| 1942 return NSAccessibilityScrollAreaRole; | 1943 return NSAccessibilityScrollAreaRole; |
| 1943 } | 1944 } |
| 1944 id ret = [super accessibilityAttributeValue:attribute]; | 1945 id ret = [super accessibilityAttributeValue:attribute]; |
| 1945 return ret; | 1946 return ret; |
| 1946 } | 1947 } |
| 1947 | 1948 |
| 1948 - (NSArray*)accessibilityAttributeNames { | 1949 - (NSArray*)accessibilityAttributeNames { |
| 1949 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; | 1950 NSMutableArray* ret = [[[NSMutableArray alloc] init] autorelease]; |
| 1950 [ret addObject:NSAccessibilityContentsAttribute]; | 1951 [ret addObject:NSAccessibilityContentsAttribute]; |
| 1951 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; | 1952 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; |
| 1952 return ret; | 1953 return ret; |
| 1953 } | 1954 } |
| 1954 | 1955 |
| 1955 - (id)accessibilityHitTest:(NSPoint)point { | 1956 - (id)accessibilityHitTest:(NSPoint)point { |
| 1956 if (!renderWidgetHostView_->browser_accessibility_manager_.get()) | 1957 if (!renderWidgetHostView_->browser_accessibility_manager()) |
| 1957 return self; | 1958 return self; |
| 1958 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; | 1959 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; |
| 1959 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; | 1960 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; |
| 1960 localPoint.y = NSHeight([self bounds]) - localPoint.y; | 1961 localPoint.y = NSHeight([self bounds]) - localPoint.y; |
| 1961 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> | 1962 BrowserAccessibilityCocoa* root = renderWidgetHostView_-> |
| 1962 browser_accessibility_manager_-> | 1963 browser_accessibility_manager()-> |
| 1963 GetRoot()->toBrowserAccessibilityCocoa(); | 1964 GetRoot()->toBrowserAccessibilityCocoa(); |
| 1964 id obj = [root accessibilityHitTest:localPoint]; | 1965 id obj = [root accessibilityHitTest:localPoint]; |
| 1965 return obj; | 1966 return obj; |
| 1966 } | 1967 } |
| 1967 | 1968 |
| 1968 - (BOOL)accessibilityIsIgnored { | 1969 - (BOOL)accessibilityIsIgnored { |
| 1969 return !renderWidgetHostView_->browser_accessibility_manager_.get(); | 1970 return !renderWidgetHostView_->browser_accessibility_manager(); |
| 1970 } | 1971 } |
| 1971 | 1972 |
| 1972 - (NSUInteger)accessibilityGetIndexOf:(id)child { | 1973 - (NSUInteger)accessibilityGetIndexOf:(id)child { |
| 1973 BrowserAccessibilityManager* manager = | 1974 BrowserAccessibilityManager* manager = |
| 1974 renderWidgetHostView_->browser_accessibility_manager_.get(); | 1975 renderWidgetHostView_->browser_accessibility_manager(); |
| 1975 // Only child is root. | 1976 // Only child is root. |
| 1976 if (manager && | 1977 if (manager && |
| 1977 manager->GetRoot()->toBrowserAccessibilityCocoa() == child) { | 1978 manager->GetRoot()->toBrowserAccessibilityCocoa() == child) { |
| 1978 return 0; | 1979 return 0; |
| 1979 } else { | 1980 } else { |
| 1980 return NSNotFound; | 1981 return NSNotFound; |
| 1981 } | 1982 } |
| 1982 } | 1983 } |
| 1983 | 1984 |
| 1984 - (id)accessibilityFocusedUIElement { | 1985 - (id)accessibilityFocusedUIElement { |
| 1985 BrowserAccessibilityManager* manager = | 1986 BrowserAccessibilityManager* manager = |
| 1986 renderWidgetHostView_->browser_accessibility_manager_.get(); | 1987 renderWidgetHostView_->browser_accessibility_manager(); |
| 1987 if (manager) { | 1988 if (manager) { |
| 1988 BrowserAccessibility* focused_item = manager->GetFocus(NULL); | 1989 BrowserAccessibility* focused_item = manager->GetFocus(NULL); |
| 1989 DCHECK(focused_item); | 1990 DCHECK(focused_item); |
| 1990 if (focused_item) { | 1991 if (focused_item) { |
| 1991 BrowserAccessibilityCocoa* focused_item_cocoa = | 1992 BrowserAccessibilityCocoa* focused_item_cocoa = |
| 1992 focused_item->toBrowserAccessibilityCocoa(); | 1993 focused_item->toBrowserAccessibilityCocoa(); |
| 1993 DCHECK(focused_item_cocoa); | 1994 DCHECK(focused_item_cocoa); |
| 1994 if (focused_item_cocoa) | 1995 if (focused_item_cocoa) |
| 1995 return focused_item_cocoa; | 1996 return focused_item_cocoa; |
| 1996 } | 1997 } |
| (...skipping 732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2729 if (!string) return NO; | 2730 if (!string) return NO; |
| 2730 | 2731 |
| 2731 // If the user is currently using an IME, confirm the IME input, | 2732 // If the user is currently using an IME, confirm the IME input, |
| 2732 // and then insert the text from the service, the same as TextEdit and Safari. | 2733 // and then insert the text from the service, the same as TextEdit and Safari. |
| 2733 [self confirmComposition]; | 2734 [self confirmComposition]; |
| 2734 [self insertText:string]; | 2735 [self insertText:string]; |
| 2735 return YES; | 2736 return YES; |
| 2736 } | 2737 } |
| 2737 | 2738 |
| 2738 @end | 2739 @end |
| OLD | NEW |