Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/browser/ui/cocoa/fullscreen_low_power_coordinator.h" | |
| 6 | |
| 7 @interface FullscreenLowPowerWindow : NSWindow { | |
| 8 NSWindow* eventTargetWindow_; | |
|
erikchen
2016/05/05 17:47:38
I prefer to never use raw pointers for NSObjects,
ccameron
2016/05/05 19:27:18
Oh, I'd prefer scoped_nsobject.
| |
| 9 } | |
| 10 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow | |
| 11 withLayer:(CALayer*)layer; | |
| 12 @end | |
| 13 | |
| 14 @implementation FullscreenLowPowerWindow | |
| 15 - (id)initWithEventTargetWindow:(NSWindow*)eventTargetWindow | |
| 16 withLayer:(CALayer*)layer { | |
| 17 if (self = [super | |
| 18 initWithContentRect:NSMakeRect(0, 0, 256, 256) | |
| 19 styleMask:NSTitledWindowMask | NSResizableWindowMask | | |
| 20 NSFullSizeContentViewWindowMask | |
| 21 backing:NSBackingStoreBuffered | |
| 22 defer:NO]) { | |
| 23 eventTargetWindow_ = eventTargetWindow; | |
| 24 [self setReleasedWhenClosed:NO]; | |
| 25 [self setIgnoresMouseEvents:YES]; | |
| 26 | |
| 27 base::scoped_nsobject<CALayer> content_layer([[CALayer alloc] init]); | |
| 28 [content_layer setBackgroundColor:CGColorGetConstantColor(kCGColorBlack)]; | |
| 29 | |
| 30 NSView* content_view = [self contentView]; | |
| 31 [content_view setLayer:content_layer]; | |
| 32 [content_view setWantsLayer:YES]; | |
| 33 | |
| 34 [content_layer addSublayer:layer]; | |
| 35 } | |
| 36 return self; | |
| 37 } | |
| 38 | |
| 39 - (void)sendEvent:(NSEvent*)event { | |
| 40 [eventTargetWindow_ sendEvent:event]; | |
| 41 } | |
| 42 @end | |
| 43 | |
| 44 FullscreenLowPowerCoordinatorCocoa::FullscreenLowPowerCoordinatorCocoa( | |
| 45 NSWindow* content_window, | |
| 46 ui::AcceleratedWidgetMac* widget) | |
| 47 : content_window_(content_window, base::scoped_policy::RETAIN), | |
| 48 widget_(widget) { | |
| 49 if (widget_) { | |
| 50 widget_->SetFullscreenLowPowerCoordinator(this); | |
| 51 CALayer* fullscreen_low_power_layer = widget_->GetFullscreenLowPowerLayer(); | |
| 52 if (fullscreen_low_power_layer) { | |
| 53 low_power_window_.reset([[FullscreenLowPowerWindow alloc] | |
| 54 initWithEventTargetWindow:content_window_ | |
| 55 withLayer:fullscreen_low_power_layer]); | |
| 56 } | |
| 57 } | |
| 58 } | |
| 59 | |
| 60 FullscreenLowPowerCoordinatorCocoa::~FullscreenLowPowerCoordinatorCocoa() { | |
| 61 if (widget_) | |
| 62 widget_->ResetFullscreenLowPowerCoordinator(); | |
| 63 EnterOrExitLowPowerModeIfNeeded(); | |
| 64 [low_power_window_ close]; | |
| 65 } | |
| 66 | |
| 67 NSWindow* FullscreenLowPowerCoordinatorCocoa::GetFullscreenLowPowerWindow() { | |
| 68 return low_power_window_.get(); | |
| 69 } | |
| 70 | |
| 71 void FullscreenLowPowerCoordinatorCocoa::AddLowPowerModeSuppression() { | |
| 72 suppression_count_ += 1; | |
| 73 EnterOrExitLowPowerModeIfNeeded(); | |
| 74 } | |
| 75 | |
| 76 void FullscreenLowPowerCoordinatorCocoa::RemoveLowPowerModeSuppression() { | |
| 77 DCHECK(suppression_count_ > 0); | |
| 78 suppression_count_ -= 1; | |
| 79 EnterOrExitLowPowerModeIfNeeded(); | |
| 80 } | |
| 81 | |
| 82 void FullscreenLowPowerCoordinatorCocoa::SetLowPowerLayerValid(bool valid) { | |
| 83 low_power_layer_valid_ = valid; | |
| 84 EnterOrExitLowPowerModeIfNeeded(); | |
| 85 } | |
| 86 | |
| 87 void FullscreenLowPowerCoordinatorCocoa::WillLoseAcceleratedWidget() { | |
| 88 DCHECK(widget_); | |
| 89 widget_->ResetFullscreenLowPowerCoordinator(); | |
| 90 widget_ = nullptr; | |
| 91 EnterOrExitLowPowerModeIfNeeded(); | |
| 92 } | |
| 93 | |
| 94 void FullscreenLowPowerCoordinatorCocoa::EnterOrExitLowPowerModeIfNeeded() { | |
| 95 bool new_in_low_power_mode = widget_ && low_power_window_ && | |
| 96 !suppression_count_ && low_power_layer_valid_; | |
| 97 if (new_in_low_power_mode) { | |
| 98 if (!in_low_power_mode_) { | |
| 99 [low_power_window_ setFrame:[content_window_ frame] display:YES]; | |
| 100 [low_power_window_ | |
| 101 setStyleMask:[low_power_window_ styleMask] | NSFullScreenWindowMask]; | |
|
erikchen
2016/05/05 17:47:38
We don't unset this mask when exiting low power mo
ccameron
2016/05/05 19:27:18
Setting it at creation time results in us not hitt
| |
| 102 [low_power_window_ orderWindow:NSWindowAbove | |
| 103 relativeTo:[content_window_ windowNumber]]; | |
| 104 in_low_power_mode_ = true; | |
| 105 } | |
| 106 } else { | |
| 107 if (in_low_power_mode_) { | |
| 108 [low_power_window_ orderWindow:NSWindowBelow | |
| 109 relativeTo:[content_window_ windowNumber]]; | |
| 110 in_low_power_mode_ = false; | |
| 111 } | |
| 112 } | |
| 113 } | |
| OLD | NEW |