| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" | 5 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" |
| 6 | 6 |
| 7 #include "ui/base/cocoa/animation_utils.h" | 7 #include "ui/base/cocoa/animation_utils.h" |
| 8 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" | 8 #include "ui/gfx/mac/scoped_cocoa_disable_screen_updates.h" |
| 9 | 9 |
| 10 namespace { | 10 namespace { |
| 11 | 11 |
| 12 // The number of frames we need to be in the WarmUp state before moving to the | 12 // The number of frames we need to be in the WarmUp state before moving to the |
| 13 // Enabled state. | 13 // Enabled state. |
| 14 const uint64_t kWarmUpFramesBeforeEnteringLowPowerMode = 30; | 14 const uint64_t kWarmUpFramesBeforeEnteringLowPowerMode = 30; |
| 15 | 15 |
| 16 } // namespace | 16 } // namespace |
| 17 | 17 |
| 18 @interface FullscreenLowPowerWindow : NSWindow { | 18 @interface FullscreenLowPowerWindow : NSWindow { |
| 19 base::scoped_nsobject<NSWindow> eventTargetWindow_; | 19 base::scoped_nsobject<NSWindow> eventTargetWindow_; |
| 20 } | 20 } |
| 21 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow | 21 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow |
| 22 withLayer:(CALayer*)layer; | 22 withLayer:(CALayer*)layer; |
| 23 @end | 23 @end |
| 24 | 24 |
| 25 @implementation FullscreenLowPowerWindow | 25 @implementation FullscreenLowPowerWindow |
| 26 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow | 26 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow |
| 27 withLayer:(CALayer*)layer { | 27 withLayer:(CALayer*)layer { |
| 28 // Resizing an NSWindow can be slow, so try to guess the right size at |
| 29 // creation. |
| 30 NSRect screenFrame = [[eventTargetWindow screen] frame]; |
| 31 NSRect initialRect = NSMakeRect( |
| 32 0, 0, NSWidth(screenFrame), NSHeight(screenFrame)); |
| 28 if (self = [super | 33 if (self = [super |
| 29 initWithContentRect:NSMakeRect(0, 0, 256, 256) | 34 initWithContentRect:initialRect |
| 30 styleMask:NSTitledWindowMask | NSResizableWindowMask | | 35 styleMask:NSTitledWindowMask | NSResizableWindowMask | |
| 31 NSFullSizeContentViewWindowMask | 36 NSFullSizeContentViewWindowMask |
| 32 backing:NSBackingStoreBuffered | 37 backing:NSBackingStoreBuffered |
| 33 defer:NO]) { | 38 defer:NO]) { |
| 34 eventTargetWindow_.reset(eventTargetWindow, base::scoped_policy::RETAIN); | 39 eventTargetWindow_.reset(eventTargetWindow, base::scoped_policy::RETAIN); |
| 35 [self setCollectionBehavior:NSWindowCollectionBehaviorIgnoresCycle]; | 40 [self setCollectionBehavior:NSWindowCollectionBehaviorIgnoresCycle]; |
| 36 [self setExcludedFromWindowsMenu:YES]; | 41 [self setExcludedFromWindowsMenu:YES]; |
| 37 [self setReleasedWhenClosed:NO]; | 42 [self setReleasedWhenClosed:NO]; |
| 38 [self setIgnoresMouseEvents:YES]; | 43 [self setIgnoresMouseEvents:YES]; |
| 39 | 44 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 178 widget_ && low_power_window_ && low_power_layer_valid_ && | 183 widget_ && low_power_window_ && low_power_layer_valid_ && |
| 179 allowed_by_fullscreen_transition_ && allowed_by_nsview_layout_ && | 184 allowed_by_fullscreen_transition_ && allowed_by_nsview_layout_ && |
| 180 allowed_by_child_windows_ && allowed_by_active_sheet_; | 185 allowed_by_child_windows_ && allowed_by_active_sheet_; |
| 181 | 186 |
| 182 switch (state_) { | 187 switch (state_) { |
| 183 case Disabled: | 188 case Disabled: |
| 184 if (can_use_low_power_window) { | 189 if (can_use_low_power_window) { |
| 185 // Ensure that the window's frame and style are set, and order it behind | 190 // Ensure that the window's frame and style are set, and order it behind |
| 186 // the main window, so that it's ready to be moved in front. | 191 // the main window, so that it's ready to be moved in front. |
| 187 state_ = WarmingUp; | 192 state_ = WarmingUp; |
| 193 |
| 194 // Changing the size of the Window will also change the size of the |
| 195 // views/layers. Disable implicit animations. |
| 196 ScopedCAActionDisabler disabler; |
| 188 [low_power_window_ setStyleMask:[low_power_window_ styleMask] | | 197 [low_power_window_ setStyleMask:[low_power_window_ styleMask] | |
| 189 NSFullScreenWindowMask]; | 198 NSFullScreenWindowMask]; |
| 190 [low_power_window_ setFrame:[content_window_ frame] | 199 [low_power_window_ setFrame:[content_window_ frame] |
| 191 display:YES | 200 display:YES |
| 192 animate:NO]; | 201 animate:NO]; |
| 193 [low_power_window_ orderWindow:NSWindowBelow | 202 [low_power_window_ orderWindow:NSWindowBelow |
| 194 relativeTo:[content_window_ windowNumber]]; | 203 relativeTo:[content_window_ windowNumber]]; |
| 195 } | 204 } |
| 196 break; | 205 break; |
| 197 case WarmingUp: | 206 case WarmingUp: |
| (...skipping 18 matching lines...) Expand all Loading... |
| 216 } | 225 } |
| 217 } else { | 226 } else { |
| 218 // Move behind the main window. | 227 // Move behind the main window. |
| 219 state_ = Disabled; | 228 state_ = Disabled; |
| 220 [low_power_window_ orderWindow:NSWindowBelow | 229 [low_power_window_ orderWindow:NSWindowBelow |
| 221 relativeTo:[content_window_ windowNumber]]; | 230 relativeTo:[content_window_ windowNumber]]; |
| 222 } | 231 } |
| 223 break; | 232 break; |
| 224 } | 233 } |
| 225 } | 234 } |
| OLD | NEW |