| 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 <OpenGL/gl.h> | 8 #include <OpenGL/gl.h> |
| 9 #include <QuartzCore/QuartzCore.h> | 9 #include <QuartzCore/QuartzCore.h> |
| 10 #include <stdint.h> | 10 #include <stdint.h> |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 #include "content/public/browser/native_web_keyboard_event.h" | 64 #include "content/public/browser/native_web_keyboard_event.h" |
| 65 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" | 65 #include "content/public/browser/render_widget_host_view_frame_subscriber.h" |
| 66 #import "content/public/browser/render_widget_host_view_mac_delegate.h" | 66 #import "content/public/browser/render_widget_host_view_mac_delegate.h" |
| 67 #include "content/public/browser/web_contents.h" | 67 #include "content/public/browser/web_contents.h" |
| 68 #include "skia/ext/platform_canvas.h" | 68 #include "skia/ext/platform_canvas.h" |
| 69 #include "skia/ext/skia_utils_mac.h" | 69 #include "skia/ext/skia_utils_mac.h" |
| 70 #include "third_party/WebKit/public/platform/WebScreenInfo.h" | 70 #include "third_party/WebKit/public/platform/WebScreenInfo.h" |
| 71 #include "third_party/WebKit/public/web/WebInputEvent.h" | 71 #include "third_party/WebKit/public/web/WebInputEvent.h" |
| 72 #import "third_party/mozilla/ComplexTextInputPanel.h" | 72 #import "third_party/mozilla/ComplexTextInputPanel.h" |
| 73 #include "ui/base/cocoa/animation_utils.h" | 73 #include "ui/base/cocoa/animation_utils.h" |
| 74 #include "ui/base/cocoa/cocoa_base_utils.h" |
| 74 #import "ui/base/cocoa/fullscreen_window_manager.h" | 75 #import "ui/base/cocoa/fullscreen_window_manager.h" |
| 75 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 76 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
| 76 #include "ui/base/layout.h" | 77 #include "ui/base/layout.h" |
| 77 #include "ui/compositor/compositor.h" | 78 #include "ui/compositor/compositor.h" |
| 78 #include "ui/compositor/layer.h" | 79 #include "ui/compositor/layer.h" |
| 79 #include "ui/events/keycodes/keyboard_codes.h" | 80 #include "ui/events/keycodes/keyboard_codes.h" |
| 80 #include "ui/gfx/color_profile.h" | 81 #include "ui/gfx/color_profile.h" |
| 81 #include "ui/gfx/display.h" | 82 #include "ui/gfx/display.h" |
| 82 #include "ui/gfx/geometry/dip_util.h" | 83 #include "ui/gfx/geometry/dip_util.h" |
| 83 #include "ui/gfx/geometry/point.h" | 84 #include "ui/gfx/geometry/point.h" |
| (...skipping 910 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 994 gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const { | 995 gfx::Rect RenderWidgetHostViewMac::GetViewBounds() const { |
| 995 NSRect bounds = [cocoa_view_ bounds]; | 996 NSRect bounds = [cocoa_view_ bounds]; |
| 996 // TODO(shess): In case of !window, the view has been removed from | 997 // TODO(shess): In case of !window, the view has been removed from |
| 997 // the view hierarchy because the tab isn't main. Could retrieve | 998 // the view hierarchy because the tab isn't main. Could retrieve |
| 998 // the information from the main tab for our window. | 999 // the information from the main tab for our window. |
| 999 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); | 1000 NSWindow* enclosing_window = ApparentWindowForView(cocoa_view_); |
| 1000 if (!enclosing_window) | 1001 if (!enclosing_window) |
| 1001 return gfx::Rect(gfx::Size(NSWidth(bounds), NSHeight(bounds))); | 1002 return gfx::Rect(gfx::Size(NSWidth(bounds), NSHeight(bounds))); |
| 1002 | 1003 |
| 1003 bounds = [cocoa_view_ convertRect:bounds toView:nil]; | 1004 bounds = [cocoa_view_ convertRect:bounds toView:nil]; |
| 1004 bounds.origin = [enclosing_window convertBaseToScreen:bounds.origin]; | 1005 bounds = [enclosing_window convertRectToScreen:bounds]; |
| 1005 return FlipNSRectToRectScreen(bounds); | 1006 return FlipNSRectToRectScreen(bounds); |
| 1006 } | 1007 } |
| 1007 | 1008 |
| 1008 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { | 1009 void RenderWidgetHostViewMac::UpdateCursor(const WebCursor& cursor) { |
| 1009 WebCursor web_cursor = cursor; | 1010 WebCursor web_cursor = cursor; |
| 1010 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; | 1011 [cocoa_view_ updateCursor:web_cursor.GetNativeCursor()]; |
| 1011 } | 1012 } |
| 1012 | 1013 |
| 1013 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { | 1014 void RenderWidgetHostViewMac::SetIsLoading(bool is_loading) { |
| 1014 is_loading_ = is_loading; | 1015 is_loading_ = is_loading; |
| (...skipping 694 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1709 delegate); | 1710 delegate); |
| 1710 } | 1711 } |
| 1711 | 1712 |
| 1712 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( | 1713 gfx::Point RenderWidgetHostViewMac::AccessibilityOriginInScreen( |
| 1713 const gfx::Rect& bounds) { | 1714 const gfx::Rect& bounds) { |
| 1714 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); | 1715 NSPoint origin = NSMakePoint(bounds.x(), bounds.y()); |
| 1715 NSSize size = NSMakeSize(bounds.width(), bounds.height()); | 1716 NSSize size = NSMakeSize(bounds.width(), bounds.height()); |
| 1716 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; | 1717 origin.y = NSHeight([cocoa_view_ bounds]) - origin.y; |
| 1717 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; | 1718 NSPoint originInWindow = [cocoa_view_ convertPoint:origin toView:nil]; |
| 1718 NSPoint originInScreen = | 1719 NSPoint originInScreen = |
| 1719 [[cocoa_view_ window] convertBaseToScreen:originInWindow]; | 1720 ui::ConvertPointFromWindowToScreen([cocoa_view_ window], originInWindow); |
| 1720 originInScreen.y = originInScreen.y - size.height; | 1721 originInScreen.y = originInScreen.y - size.height; |
| 1721 return gfx::Point(originInScreen.x, originInScreen.y); | 1722 return gfx::Point(originInScreen.x, originInScreen.y); |
| 1722 } | 1723 } |
| 1723 | 1724 |
| 1724 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { | 1725 void RenderWidgetHostViewMac::SetTextInputActive(bool active) { |
| 1725 if (active) { | 1726 if (active) { |
| 1726 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) | 1727 if (text_input_type_ == ui::TEXT_INPUT_TYPE_PASSWORD) |
| 1727 EnablePasswordInput(); | 1728 EnablePasswordInput(); |
| 1728 else | 1729 else |
| 1729 DisablePasswordInput(); | 1730 DisablePasswordInput(); |
| (...skipping 1109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2839 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; | 2840 [ret addObjectsFromArray:[super accessibilityAttributeNames]]; |
| 2840 return ret; | 2841 return ret; |
| 2841 } | 2842 } |
| 2842 | 2843 |
| 2843 - (id)accessibilityHitTest:(NSPoint)point { | 2844 - (id)accessibilityHitTest:(NSPoint)point { |
| 2844 BrowserAccessibilityManager* manager = | 2845 BrowserAccessibilityManager* manager = |
| 2845 renderWidgetHostView_->render_widget_host_ | 2846 renderWidgetHostView_->render_widget_host_ |
| 2846 ->GetRootBrowserAccessibilityManager(); | 2847 ->GetRootBrowserAccessibilityManager(); |
| 2847 if (!manager) | 2848 if (!manager) |
| 2848 return self; | 2849 return self; |
| 2849 NSPoint pointInWindow = [[self window] convertScreenToBase:point]; | 2850 NSPoint pointInWindow = |
| 2851 ui::ConvertPointFromScreenToWindow([self window], point); |
| 2850 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; | 2852 NSPoint localPoint = [self convertPoint:pointInWindow fromView:nil]; |
| 2851 localPoint.y = NSHeight([self bounds]) - localPoint.y; | 2853 localPoint.y = NSHeight([self bounds]) - localPoint.y; |
| 2852 BrowserAccessibilityCocoa* root = | 2854 BrowserAccessibilityCocoa* root = |
| 2853 ToBrowserAccessibilityCocoa(manager->GetRoot()); | 2855 ToBrowserAccessibilityCocoa(manager->GetRoot()); |
| 2854 id obj = [root accessibilityHitTest:localPoint]; | 2856 id obj = [root accessibilityHitTest:localPoint]; |
| 2855 return obj; | 2857 return obj; |
| 2856 } | 2858 } |
| 2857 | 2859 |
| 2858 - (BOOL)accessibilityIsIgnored { | 2860 - (BOOL)accessibilityIsIgnored { |
| 2859 BrowserAccessibilityManager* manager = | 2861 BrowserAccessibilityManager* manager = |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2963 nil]); | 2965 nil]); |
| 2964 } | 2966 } |
| 2965 return validAttributesForMarkedText_.get(); | 2967 return validAttributesForMarkedText_.get(); |
| 2966 } | 2968 } |
| 2967 | 2969 |
| 2968 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { | 2970 - (NSUInteger)characterIndexForPoint:(NSPoint)thePoint { |
| 2969 DCHECK([self window]); | 2971 DCHECK([self window]); |
| 2970 // |thePoint| is in screen coordinates, but needs to be converted to WebKit | 2972 // |thePoint| is in screen coordinates, but needs to be converted to WebKit |
| 2971 // coordinates (upper left origin). Scroll offsets will be taken care of in | 2973 // coordinates (upper left origin). Scroll offsets will be taken care of in |
| 2972 // the renderer. | 2974 // the renderer. |
| 2973 thePoint = [[self window] convertScreenToBase:thePoint]; | 2975 thePoint = ui::ConvertPointFromScreenToWindow([self window], thePoint); |
| 2974 thePoint = [self convertPoint:thePoint fromView:nil]; | 2976 thePoint = [self convertPoint:thePoint fromView:nil]; |
| 2975 thePoint.y = NSHeight([self frame]) - thePoint.y; | 2977 thePoint.y = NSHeight([self frame]) - thePoint.y; |
| 2976 | 2978 |
| 2977 NSUInteger index = | 2979 NSUInteger index = |
| 2978 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( | 2980 TextInputClientMac::GetInstance()->GetCharacterIndexAtPoint( |
| 2979 renderWidgetHostView_->render_widget_host_, | 2981 renderWidgetHostView_->render_widget_host_, |
| 2980 gfx::Point(thePoint.x, thePoint.y)); | 2982 gfx::Point(thePoint.x, thePoint.y)); |
| 2981 return index; | 2983 return index; |
| 2982 } | 2984 } |
| 2983 | 2985 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3010 if (!renderWidgetHostView_->render_widget_host_) { | 3012 if (!renderWidgetHostView_->render_widget_host_) { |
| 3011 [self cancelComposition]; | 3013 [self cancelComposition]; |
| 3012 return NSZeroRect; | 3014 return NSZeroRect; |
| 3013 } | 3015 } |
| 3014 | 3016 |
| 3015 NSRect rect = [self firstViewRectForCharacterRange:theRange | 3017 NSRect rect = [self firstViewRectForCharacterRange:theRange |
| 3016 actualRange:actualRange]; | 3018 actualRange:actualRange]; |
| 3017 | 3019 |
| 3018 // Convert into screen coordinates for return. | 3020 // Convert into screen coordinates for return. |
| 3019 rect = [self convertRect:rect toView:nil]; | 3021 rect = [self convertRect:rect toView:nil]; |
| 3020 rect.origin = [[self window] convertBaseToScreen:rect.origin]; | 3022 rect = [[self window] convertRectToScreen:rect]; |
| 3021 return rect; | 3023 return rect; |
| 3022 } | 3024 } |
| 3023 | 3025 |
| 3024 - (NSRange)markedRange { | 3026 - (NSRange)markedRange { |
| 3025 // An input method calls this method to check if an application really has | 3027 // An input method calls this method to check if an application really has |
| 3026 // a text being composed when hasMarkedText call returns true. | 3028 // a text being composed when hasMarkedText call returns true. |
| 3027 // Returns the range saved in the setMarkedText method so the input method | 3029 // Returns the range saved in the setMarkedText method so the input method |
| 3028 // calls the setMarkedText method and we can update the composition node | 3030 // calls the setMarkedText method and we can update the composition node |
| 3029 // there. (When this method returns an empty range, the input method doesn't | 3031 // there. (When this method returns an empty range, the input method doesn't |
| 3030 // call the setMarkedText method.) | 3032 // call the setMarkedText method.) |
| (...skipping 451 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3482 | 3484 |
| 3483 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding | 3485 // "-webkit-app-region: drag | no-drag" is implemented on Mac by excluding |
| 3484 // regions that are not draggable. (See ControlRegionView in | 3486 // regions that are not draggable. (See ControlRegionView in |
| 3485 // native_app_window_cocoa.mm). This requires the render host view to be | 3487 // native_app_window_cocoa.mm). This requires the render host view to be |
| 3486 // draggable by default. | 3488 // draggable by default. |
| 3487 - (BOOL)mouseDownCanMoveWindow { | 3489 - (BOOL)mouseDownCanMoveWindow { |
| 3488 return YES; | 3490 return YES; |
| 3489 } | 3491 } |
| 3490 | 3492 |
| 3491 @end | 3493 @end |
| OLD | NEW |