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 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
361 } | 361 } |
362 | 362 |
363 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { | 363 RenderWidgetHost* RenderWidgetHostViewMac::GetRenderWidgetHost() const { |
364 return render_widget_host_; | 364 return render_widget_host_; |
365 } | 365 } |
366 | 366 |
367 void RenderWidgetHostViewMac::WasShown() { | 367 void RenderWidgetHostViewMac::WasShown() { |
368 if (!is_hidden_) | 368 if (!is_hidden_) |
369 return; | 369 return; |
370 | 370 |
371 // Check if the backing scale factor changed while the tab was in the | |
372 // background. | |
373 [cocoa_view_ updateTabBackingStoreScaleFactor]; | |
374 | |
375 if (web_contents_switch_paint_time_.is_null()) | 371 if (web_contents_switch_paint_time_.is_null()) |
376 web_contents_switch_paint_time_ = base::TimeTicks::Now(); | 372 web_contents_switch_paint_time_ = base::TimeTicks::Now(); |
377 is_hidden_ = false; | 373 is_hidden_ = false; |
378 render_widget_host_->WasShown(); | 374 render_widget_host_->WasShown(); |
379 | 375 |
380 // We're messing with the window, so do this to ensure no flashes. | 376 // We're messing with the window, so do this to ensure no flashes. |
381 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; | 377 [[cocoa_view_ window] disableScreenUpdatesUntilFlush]; |
382 } | 378 } |
383 | 379 |
384 void RenderWidgetHostViewMac::WasHidden() { | 380 void RenderWidgetHostViewMac::WasHidden() { |
(...skipping 1044 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1429 | 1425 |
1430 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { | 1426 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r { |
1431 self = [super initWithFrame:NSZeroRect]; | 1427 self = [super initWithFrame:NSZeroRect]; |
1432 if (self) { | 1428 if (self) { |
1433 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); | 1429 editCommand_helper_.reset(new RenderWidgetHostViewMacEditCommandHelper); |
1434 editCommand_helper_->AddEditingSelectorsToClass([self class]); | 1430 editCommand_helper_->AddEditingSelectorsToClass([self class]); |
1435 | 1431 |
1436 renderWidgetHostView_.reset(r); | 1432 renderWidgetHostView_.reset(r); |
1437 canBeKeyView_ = YES; | 1433 canBeKeyView_ = YES; |
1438 focusedPluginIdentifier_ = -1; | 1434 focusedPluginIdentifier_ = -1; |
| 1435 deviceScaleFactor_ = ScaleFactor(self); |
1439 | 1436 |
1440 // OpenGL support: | 1437 // OpenGL support: |
1441 if ([self respondsToSelector: | 1438 if ([self respondsToSelector: |
1442 @selector(setWantsBestResolutionOpenGLSurface:)]) { | 1439 @selector(setWantsBestResolutionOpenGLSurface:)]) { |
1443 [self setWantsBestResolutionOpenGLSurface:YES]; | 1440 [self setWantsBestResolutionOpenGLSurface:YES]; |
1444 } | 1441 } |
1445 handlingGlobalFrameDidChange_ = NO; | 1442 handlingGlobalFrameDidChange_ = NO; |
1446 [[NSNotificationCenter defaultCenter] | 1443 [[NSNotificationCenter defaultCenter] |
1447 addObserver:self | 1444 addObserver:self |
1448 selector:@selector(globalFrameDidChange:) | 1445 selector:@selector(globalFrameDidChange:) |
(...skipping 573 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2022 name:NSWindowDidChangeScreenNotification | 2019 name:NSWindowDidChangeScreenNotification |
2023 object:newWindow]; | 2020 object:newWindow]; |
2024 } | 2021 } |
2025 } | 2022 } |
2026 | 2023 |
2027 - (void)updateTabBackingStoreScaleFactor { | 2024 - (void)updateTabBackingStoreScaleFactor { |
2028 if (!renderWidgetHostView_->render_widget_host_) | 2025 if (!renderWidgetHostView_->render_widget_host_) |
2029 return; | 2026 return; |
2030 | 2027 |
2031 float scaleFactor = ScaleFactor(self); | 2028 float scaleFactor = ScaleFactor(self); |
| 2029 if (scaleFactor == deviceScaleFactor_) |
| 2030 return; |
| 2031 deviceScaleFactor_ = scaleFactor; |
| 2032 |
2032 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( | 2033 BackingStoreMac* backingStore = static_cast<BackingStoreMac*>( |
2033 renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); | 2034 renderWidgetHostView_->render_widget_host_->GetBackingStore(false)); |
2034 if (backingStore) // NULL in hardware path. | 2035 if (backingStore) // NULL in hardware path. |
2035 backingStore->ScaleFactorChanged(scaleFactor); | 2036 backingStore->ScaleFactorChanged(scaleFactor); |
2036 | 2037 |
2037 renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( | 2038 renderWidgetHostView_->render_widget_host_->SetDeviceScaleFactor( |
2038 scaleFactor); | 2039 scaleFactor); |
2039 } | 2040 } |
2040 | 2041 |
2041 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce
ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a
pple_ref/doc/uid/TP40012302-CH10-SW4 | 2042 // http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conce
ptual/HighResolutionOSX/CapturingScreenContents/CapturingScreenContents.html#//a
pple_ref/doc/uid/TP40012302-CH10-SW4 |
2042 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { | 2043 - (void)windowDidChangeBackingProperties:(NSNotification*)notification { |
2043 NSWindow* window = (NSWindow*)[notification object]; | 2044 NSWindow* window = (NSWindow*)[notification object]; |
2044 | 2045 |
2045 CGFloat newBackingScaleFactor = [window backingScaleFactor]; | 2046 CGFloat newBackingScaleFactor = [window backingScaleFactor]; |
2046 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( | 2047 CGFloat oldBackingScaleFactor = [base::mac::ObjCCast<NSNumber>( |
2047 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) | 2048 [[notification userInfo] objectForKey:NSBackingPropertyOldScaleFactorKey]) |
2048 doubleValue]; | 2049 doubleValue]; |
2049 if (newBackingScaleFactor != oldBackingScaleFactor) { | 2050 if (newBackingScaleFactor != oldBackingScaleFactor) { |
2050 // Background tabs check if their scale factor changed when they become | 2051 // Background tabs check if their scale factor changed when they are added |
2051 // active, in WasShown(). | 2052 // to a window. |
2052 | 2053 |
2053 // Allocating a CGLayerRef with the current scale factor immediately from | 2054 // Allocating a CGLayerRef with the current scale factor immediately from |
2054 // this handler doesn't work. Schedule the backing store update on the | 2055 // this handler doesn't work. Schedule the backing store update on the |
2055 // next runloop cycle, then things are read for CGLayerRef allocations to | 2056 // next runloop cycle, then things are read for CGLayerRef allocations to |
2056 // work. | 2057 // work. |
2057 [self performSelector:@selector(updateTabBackingStoreScaleFactor) | 2058 [self performSelector:@selector(updateTabBackingStoreScaleFactor) |
2058 withObject:nil | 2059 withObject:nil |
2059 afterDelay:0]; | 2060 afterDelay:0]; |
2060 } | 2061 } |
2061 } | 2062 } |
(...skipping 911 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2973 hasMarkedText_ = NO; | 2974 hasMarkedText_ = NO; |
2974 } | 2975 } |
2975 | 2976 |
2976 - (void)insertText:(id)string { | 2977 - (void)insertText:(id)string { |
2977 // This is a method on NSTextInput, not NSTextInputClient. But on 10.5, this | 2978 // This is a method on NSTextInput, not NSTextInputClient. But on 10.5, this |
2978 // gets called anyway. Forward to the right method. http://crbug.com/47890 | 2979 // gets called anyway. Forward to the right method. http://crbug.com/47890 |
2979 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; | 2980 [self insertText:string replacementRange:NSMakeRange(NSNotFound, 0)]; |
2980 } | 2981 } |
2981 | 2982 |
2982 - (void)viewDidMoveToWindow { | 2983 - (void)viewDidMoveToWindow { |
| 2984 if ([self window]) |
| 2985 [self updateTabBackingStoreScaleFactor]; |
| 2986 |
2983 if (canBeKeyView_) { | 2987 if (canBeKeyView_) { |
2984 NSWindow* newWindow = [self window]; | 2988 NSWindow* newWindow = [self window]; |
2985 // Pointer comparison only, since we don't know if lastWindow_ is still | 2989 // Pointer comparison only, since we don't know if lastWindow_ is still |
2986 // valid. | 2990 // valid. |
2987 if (newWindow) { | 2991 if (newWindow) { |
2988 // If we move into a new window, refresh the frame information. We | 2992 // If we move into a new window, refresh the frame information. We |
2989 // don't need to do it if it was the same window as it used to be in, | 2993 // don't need to do it if it was the same window as it used to be in, |
2990 // since that case is covered by WasShown(). We only want to do this for | 2994 // since that case is covered by WasShown(). We only want to do this for |
2991 // real browser views, not popups. | 2995 // real browser views, not popups. |
2992 if (newWindow != lastWindow_) { | 2996 if (newWindow != lastWindow_) { |
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3202 if (!string) return NO; | 3206 if (!string) return NO; |
3203 | 3207 |
3204 // If the user is currently using an IME, confirm the IME input, | 3208 // If the user is currently using an IME, confirm the IME input, |
3205 // and then insert the text from the service, the same as TextEdit and Safari. | 3209 // and then insert the text from the service, the same as TextEdit and Safari. |
3206 [self confirmComposition]; | 3210 [self confirmComposition]; |
3207 [self insertText:string]; | 3211 [self insertText:string]; |
3208 return YES; | 3212 return YES; |
3209 } | 3213 } |
3210 | 3214 |
3211 @end | 3215 @end |
OLD | NEW |