| 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 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 142 windowDelegateProtocol, | 142 windowDelegateProtocol, |
| 143 @selector(windowDidChangeBackingProperties:), | 143 @selector(windowDidChangeBackingProperties:), |
| 144 NO, | 144 NO, |
| 145 YES); | 145 YES); |
| 146 | 146 |
| 147 // If the protocol does not contain the method, the returned method | 147 // If the protocol does not contain the method, the returned method |
| 148 // description is {NULL, NULL} | 148 // description is {NULL, NULL} |
| 149 return methodDescription.name != NULL || methodDescription.types != NULL; | 149 return methodDescription.name != NULL || methodDescription.types != NULL; |
| 150 } | 150 } |
| 151 | 151 |
| 152 static float ScaleFactorForView(NSView* view) { | |
| 153 return ui::GetImageScale(ui::GetScaleFactorForNativeView(view)); | |
| 154 } | |
| 155 | |
| 156 // Private methods: | 152 // Private methods: |
| 157 @interface RenderWidgetHostViewCocoa () | 153 @interface RenderWidgetHostViewCocoa () |
| 158 @property(nonatomic, assign) NSRange selectedRange; | 154 @property(nonatomic, assign) NSRange selectedRange; |
| 159 @property(nonatomic, assign) NSRange markedRange; | 155 @property(nonatomic, assign) NSRange markedRange; |
| 160 | 156 |
| 161 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; | 157 + (BOOL)shouldAutohideCursorForEvent:(NSEvent*)event; |
| 162 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 158 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 163 - (void)gotUnhandledWheelEvent; | 159 - (void)gotUnhandledWheelEvent; |
| 164 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; | 160 - (void)scrollOffsetPinnedToLeft:(BOOL)left toRight:(BOOL)right; |
| 165 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; | 161 - (void)setHasHorizontalScrollbar:(BOOL)has_horizontal_scrollbar; |
| (...skipping 636 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 802 } | 798 } |
| 803 | 799 |
| 804 int RenderWidgetHostViewMac::window_number() const { | 800 int RenderWidgetHostViewMac::window_number() const { |
| 805 NSWindow* window = [cocoa_view_ window]; | 801 NSWindow* window = [cocoa_view_ window]; |
| 806 if (!window) | 802 if (!window) |
| 807 return -1; | 803 return -1; |
| 808 return [window windowNumber]; | 804 return [window windowNumber]; |
| 809 } | 805 } |
| 810 | 806 |
| 811 float RenderWidgetHostViewMac::ViewScaleFactor() const { | 807 float RenderWidgetHostViewMac::ViewScaleFactor() const { |
| 812 return ScaleFactorForView(cocoa_view_); | 808 return ui::GetScaleFactorForNativeView(cocoa_view_); |
| 813 } | 809 } |
| 814 | 810 |
| 815 void RenderWidgetHostViewMac::UpdateDisplayLink() { | 811 void RenderWidgetHostViewMac::UpdateDisplayLink() { |
| 816 static bool is_vsync_disabled = | 812 static bool is_vsync_disabled = |
| 817 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync); | 813 CommandLine::ForCurrentProcess()->HasSwitch(switches::kDisableGpuVsync); |
| 818 if (is_vsync_disabled) | 814 if (is_vsync_disabled) |
| 819 return; | 815 return; |
| 820 | 816 |
| 821 NSScreen* screen = [[cocoa_view_ window] screen]; | 817 NSScreen* screen = [[cocoa_view_ window] screen]; |
| 822 NSDictionary* screen_description = [screen deviceDescription]; | 818 NSDictionary* screen_description = [screen deviceDescription]; |
| (...skipping 17 matching lines...) Expand all Loading... |
| 840 if (!display_link_->GetVSyncParameters(&timebase, &interval)) | 836 if (!display_link_->GetVSyncParameters(&timebase, &interval)) |
| 841 return; | 837 return; |
| 842 | 838 |
| 843 render_widget_host_->UpdateVSyncParameters(timebase, interval); | 839 render_widget_host_->UpdateVSyncParameters(timebase, interval); |
| 844 } | 840 } |
| 845 | 841 |
| 846 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() { | 842 void RenderWidgetHostViewMac::UpdateBackingStoreScaleFactor() { |
| 847 if (!render_widget_host_) | 843 if (!render_widget_host_) |
| 848 return; | 844 return; |
| 849 | 845 |
| 850 float new_scale_factor = ScaleFactorForView(cocoa_view_); | 846 float new_scale_factor = ui::GetScaleFactorForNativeView(cocoa_view_); |
| 851 if (new_scale_factor == backing_store_scale_factor_) | 847 if (new_scale_factor == backing_store_scale_factor_) |
| 852 return; | 848 return; |
| 853 backing_store_scale_factor_ = new_scale_factor; | 849 backing_store_scale_factor_ = new_scale_factor; |
| 854 | 850 |
| 855 render_widget_host_->NotifyScreenInfoChanged(); | 851 render_widget_host_->NotifyScreenInfoChanged(); |
| 856 } | 852 } |
| 857 | 853 |
| 858 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 854 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
| 859 return render_widget_host_; | 855 return render_widget_host_; |
| 860 } | 856 } |
| (...skipping 383 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1244 src_subrect, dst_size, callback, config); | 1240 src_subrect, dst_size, callback, config); |
| 1245 return; | 1241 return; |
| 1246 } | 1242 } |
| 1247 | 1243 |
| 1248 if (config != SkBitmap::kARGB_8888_Config) { | 1244 if (config != SkBitmap::kARGB_8888_Config) { |
| 1249 NOTIMPLEMENTED(); | 1245 NOTIMPLEMENTED(); |
| 1250 callback.Run(false, SkBitmap()); | 1246 callback.Run(false, SkBitmap()); |
| 1251 } | 1247 } |
| 1252 base::ScopedClosureRunner scoped_callback_runner( | 1248 base::ScopedClosureRunner scoped_callback_runner( |
| 1253 base::Bind(callback, false, SkBitmap())); | 1249 base::Bind(callback, false, SkBitmap())); |
| 1254 float scale = ScaleFactorForView(cocoa_view_); | 1250 float scale = ui::GetScaleFactorForNativeView(cocoa_view_); |
| 1255 gfx::Size dst_pixel_size = gfx::ToFlooredSize( | 1251 gfx::Size dst_pixel_size = gfx::ToFlooredSize( |
| 1256 gfx::ScaleSize(dst_size, scale)); | 1252 gfx::ScaleSize(dst_size, scale)); |
| 1257 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { | 1253 if (compositing_iosurface_ && compositing_iosurface_->HasIOSurface()) { |
| 1258 ignore_result(scoped_callback_runner.Release()); | 1254 ignore_result(scoped_callback_runner.Release()); |
| 1259 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), | 1255 compositing_iosurface_->CopyTo(GetScaledOpenGLPixelRect(src_subrect), |
| 1260 dst_pixel_size, | 1256 dst_pixel_size, |
| 1261 callback); | 1257 callback); |
| 1262 } else if (software_frame_manager_->HasCurrentFrame()) { | 1258 } else if (software_frame_manager_->HasCurrentFrame()) { |
| 1263 gfx::Rect src_pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect( | 1259 gfx::Rect src_pixel_rect = gfx::ToEnclosingRect(gfx::ScaleRect( |
| 1264 src_subrect, | 1260 src_subrect, |
| (...skipping 1223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2488 self = [super initWithFrame:NSZeroRect]; | 2484 self = [super initWithFrame:NSZeroRect]; |
| 2489 if (self) { | 2485 if (self) { |
| 2490 self.acceptsTouchEvents = YES; | 2486 self.acceptsTouchEvents = YES; |
| 2491 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 2487 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
| 2492 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 2488 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
| 2493 | 2489 |
| 2494 renderWidgetHostView_.reset(r); | 2490 renderWidgetHostView_.reset(r); |
| 2495 canBeKeyView_ = YES; | 2491 canBeKeyView_ = YES; |
| 2496 focusedPluginIdentifier_ = -1; | 2492 focusedPluginIdentifier_ = -1; |
| 2497 renderWidgetHostView_->backing_store_scale_factor_ = | 2493 renderWidgetHostView_->backing_store_scale_factor_ = |
| 2498 ScaleFactorForView(self); | 2494 ui::GetScaleFactorForNativeView(self); |
| 2499 | 2495 |
| 2500 // OpenGL support: | 2496 // OpenGL support: |
| 2501 if ([self respondsToSelector: | 2497 if ([self respondsToSelector: |
| 2502 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 2498 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
| 2503 [self setWantsBestResolutionOpenGLSurface:YES]; | 2499 [self setWantsBestResolutionOpenGLSurface:YES]; |
| 2504 } | 2500 } |
| 2505 handlingGlobalFrameDidChange_ = NO; | 2501 handlingGlobalFrameDidChange_ = NO; |
| 2506 [[NSNotificationCenter defaultCenter] | 2502 [[NSNotificationCenter defaultCenter] |
| 2507 addObserver:self | 2503 addObserver:self |
| 2508 selector:@selector(globalFrameDidChange:) | 2504 selector:@selector(globalFrameDidChange:) |
| (...skipping 1916 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4425 } | 4421 } |
| 4426 | 4422 |
| 4427 - (void)disableRendering { | 4423 - (void)disableRendering { |
| 4428 // Disable the fade-out animation as the layer is removed. | 4424 // Disable the fade-out animation as the layer is removed. |
| 4429 ScopedCAActionDisabler disabler; | 4425 ScopedCAActionDisabler disabler; |
| 4430 [self removeFromSuperlayer]; | 4426 [self removeFromSuperlayer]; |
| 4431 renderWidgetHostView_ = nil; | 4427 renderWidgetHostView_ = nil; |
| 4432 } | 4428 } |
| 4433 | 4429 |
| 4434 @end // implementation SoftwareLayer | 4430 @end // implementation SoftwareLayer |
| OLD | NEW |