| // Copyright 2014 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| |
| #import "ui/views/cocoa/views_nswindow_delegate.h" |
| |
| #include "base/logging.h" |
| #import "ui/views/cocoa/bridged_content_view.h" |
| #import "ui/views/cocoa/bridged_native_widget.h" |
| #include "ui/views/widget/native_widget_mac.h" |
| |
| @implementation ViewsNSWindowDelegate |
| |
| - (id)initWithBridgedNativeWidget:(views::BridgedNativeWidget*)parent { |
| DCHECK(parent); |
| if ((self = [super init])) { |
| parent_ = parent; |
| } |
| return self; |
| } |
| |
| - (views::NativeWidgetMac*)nativeWidgetMac { |
| return parent_->native_widget_mac(); |
| } |
| |
| - (void)onWindowOrderWillChange:(NSWindowOrderingMode)orderingMode { |
| if (orderingMode != NSWindowOut) |
| [parent_->ns_view() setWillShow:YES]; |
| } |
| |
| - (void)onWindowOrderChanged { |
| [parent_->ns_view() setWillShow:NO]; |
| } |
| |
| // NSWindowDelegate implementation. |
| |
| - (void)windowDidFailToEnterFullScreen:(NSWindow*)window { |
| // Cocoa should already have sent an (unexpected) windowDidExitFullScreen: |
| // notification, and the attempt to get back into fullscreen should fail. |
| // Nothing to do except verify |parent_| is no longer trying to fullscreen. |
| DCHECK(!parent_->target_fullscreen_state()); |
| } |
| |
| - (void)windowDidFailToExitFullScreen:(NSWindow*)window { |
| // Unlike entering fullscreen, windowDidFailToExitFullScreen: is sent *before* |
| // windowDidExitFullScreen:. Also, failing to exit fullscreen just dumps the |
| // window out of fullscreen without an animation; still sending the expected, |
| // windowDidExitFullScreen: notification. So, again, nothing to do here. |
| DCHECK(!parent_->target_fullscreen_state()); |
| } |
| |
| - (void)windowDidResize:(NSNotification*)notification { |
| parent_->OnSizeChanged(); |
| } |
| |
| - (void)windowDidBecomeKey:(NSNotification*)notification { |
| parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged( |
| true); |
| } |
| |
| - (void)windowDidResignKey:(NSNotification*)notification { |
| parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged( |
| false); |
| } |
| |
| - (void)windowWillClose:(NSNotification*)notification { |
| DCHECK([parent_->ns_window() isEqual:[notification object]]); |
| parent_->OnWindowWillClose(); |
| } |
| |
| - (void)windowWillEnterFullScreen:(NSNotification*)notification { |
| parent_->OnFullscreenTransitionStart(true); |
| } |
| |
| - (void)windowDidEnterFullScreen:(NSNotification*)notification { |
| parent_->OnFullscreenTransitionComplete(true); |
| } |
| |
| - (void)windowWillExitFullScreen:(NSNotification*)notification { |
| parent_->OnFullscreenTransitionStart(false); |
| } |
| |
| - (void)windowDidExitFullScreen:(NSNotification*)notification { |
| parent_->OnFullscreenTransitionComplete(false); |
| } |
| |
| @end |