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 #include <QuartzCore/QuartzCore.h> | 7 #include <QuartzCore/QuartzCore.h> |
8 | 8 |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/bind_helpers.h" | 10 #include "base/bind_helpers.h" |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
88 #endif // 10.6 | 88 #endif // 10.6 |
89 | 89 |
90 // Declare things that are part of the 10.7 SDK. | 90 // Declare things that are part of the 10.7 SDK. |
91 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 91 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
92 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 92 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
93 @interface NSEvent (LionAPI) | 93 @interface NSEvent (LionAPI) |
94 + (id)addLocalMonitorForEventsMatchingMask:(NSEventMask)mask | 94 + (id)addLocalMonitorForEventsMatchingMask:(NSEventMask)mask |
95 handler:(NSEvent* (^)(NSEvent*))block; | 95 handler:(NSEvent* (^)(NSEvent*))block; |
96 + (void)removeMonitor:(id)eventMonitor; | 96 + (void)removeMonitor:(id)eventMonitor; |
97 @end | 97 @end |
| 98 |
| 99 @interface NSScreen (LionAPI) |
| 100 - (CGFloat)backingScaleFactor; |
| 101 @end |
| 102 |
| 103 @interface NSWindow (LionAPI) |
| 104 - (CGFloat)backingScaleFactor; |
| 105 @end |
| 106 |
98 #endif // 10.7 | 107 #endif // 10.7 |
99 | 108 |
| 109 |
100 static inline int ToWebKitModifiers(NSUInteger flags) { | 110 static inline int ToWebKitModifiers(NSUInteger flags) { |
101 int modifiers = 0; | 111 int modifiers = 0; |
102 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; | 112 if (flags & NSControlKeyMask) modifiers |= WebInputEvent::ControlKey; |
103 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; | 113 if (flags & NSShiftKeyMask) modifiers |= WebInputEvent::ShiftKey; |
104 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; | 114 if (flags & NSAlternateKeyMask) modifiers |= WebInputEvent::AltKey; |
105 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; | 115 if (flags & NSCommandKeyMask) modifiers |= WebInputEvent::MetaKey; |
106 return modifiers; | 116 return modifiers; |
107 } | 117 } |
108 | 118 |
109 // Private methods: | 119 // Private methods: |
(...skipping 663 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 web_event.type = WebInputEvent::MouseLeave; | 783 web_event.type = WebInputEvent::MouseLeave; |
774 ForwardMouseEvent(web_event); | 784 ForwardMouseEvent(web_event); |
775 } | 785 } |
776 | 786 |
777 bool RenderWidgetHostViewMac::IsPopup() const { | 787 bool RenderWidgetHostViewMac::IsPopup() const { |
778 return popup_type_ != WebKit::WebPopupTypeNone; | 788 return popup_type_ != WebKit::WebPopupTypeNone; |
779 } | 789 } |
780 | 790 |
781 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 791 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
782 const gfx::Size& size) { | 792 const gfx::Size& size) { |
783 // TODO(thakis): Pass correct scale factor. | 793 // TODO(thakis): Register for backing scale factor change events and pass |
784 return new BackingStoreMac(render_widget_host_, size, 1.0); | 794 // that on. |
| 795 float scale = 1; |
| 796 if (NSWindow* window = [cocoa_view_ window]) { |
| 797 if ([window respondsToSelector:@selector(backingScaleFactor)]) |
| 798 scale = [window backingScaleFactor]; |
| 799 else |
| 800 scale = [window userSpaceScaleFactor]; |
| 801 } else if (NSScreen* screen = [NSScreen mainScreen]) { |
| 802 if ([screen respondsToSelector:@selector(backingScaleFactor)]) |
| 803 scale = [screen backingScaleFactor]; |
| 804 else |
| 805 scale = [screen userSpaceScaleFactor]; |
| 806 } |
| 807 return new BackingStoreMac(render_widget_host_, size, scale); |
785 } | 808 } |
786 | 809 |
787 void RenderWidgetHostViewMac::CopyFromCompositingSurface( | 810 void RenderWidgetHostViewMac::CopyFromCompositingSurface( |
788 const gfx::Size& size, | 811 const gfx::Size& size, |
789 skia::PlatformCanvas* output, | 812 skia::PlatformCanvas* output, |
790 base::Callback<void(bool)> callback) { | 813 base::Callback<void(bool)> callback) { |
791 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); | 814 base::ScopedClosureRunner scoped_callback_runner(base::Bind(callback, false)); |
792 if (!compositing_iosurface_.get() || | 815 if (!compositing_iosurface_.get() || |
793 !compositing_iosurface_->HasIOSurface()) | 816 !compositing_iosurface_->HasIOSurface()) |
794 return; | 817 return; |
(...skipping 1146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1941 [[NSColor clearColor] set]; | 1964 [[NSColor clearColor] set]; |
1942 NSRectFill(dirtyRect); | 1965 NSRectFill(dirtyRect); |
1943 } | 1966 } |
1944 | 1967 |
1945 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(self); | 1968 renderWidgetHostView_->compositing_iosurface_->DrawIOSurface(self); |
1946 renderWidgetHostView_->AckPendingSwapBuffers(); | 1969 renderWidgetHostView_->AckPendingSwapBuffers(); |
1947 return; | 1970 return; |
1948 } | 1971 } |
1949 | 1972 |
1950 if (backingStore) { | 1973 if (backingStore) { |
| 1974 // Note: All coordinates are in view units, not pixels. |
1951 gfx::Rect bitmapRect(0, 0, | 1975 gfx::Rect bitmapRect(0, 0, |
1952 backingStore->size().width(), | 1976 backingStore->size().width(), |
1953 backingStore->size().height()); | 1977 backingStore->size().height()); |
1954 | 1978 |
1955 // Specify the proper y offset to ensure that the view is rooted to the | 1979 // Specify the proper y offset to ensure that the view is rooted to the |
1956 // upper left corner. This can be negative, if the window was resized | 1980 // upper left corner. This can be negative, if the window was resized |
1957 // smaller and the renderer hasn't yet repainted. | 1981 // smaller and the renderer hasn't yet repainted. |
1958 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); | 1982 int yOffset = NSHeight([self bounds]) - backingStore->size().height(); |
1959 | 1983 |
1960 gfx::Rect paintRect = bitmapRect.Intersect(damagedRect); | 1984 gfx::Rect paintRect = bitmapRect.Intersect(damagedRect); |
(...skipping 992 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2953 if (!string) return NO; | 2977 if (!string) return NO; |
2954 | 2978 |
2955 // If the user is currently using an IME, confirm the IME input, | 2979 // If the user is currently using an IME, confirm the IME input, |
2956 // and then insert the text from the service, the same as TextEdit and Safari. | 2980 // and then insert the text from the service, the same as TextEdit and Safari. |
2957 [self confirmComposition]; | 2981 [self confirmComposition]; |
2958 [self insertText:string]; | 2982 [self insertText:string]; |
2959 return YES; | 2983 return YES; |
2960 } | 2984 } |
2961 | 2985 |
2962 @end | 2986 @end |
OLD | NEW |