1 // Copyright 2014 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.
5 #import "ui/views/cocoa/views_nswindow_delegate.h"
7 #include "base/logging.h"
8 #import "ui/views/cocoa/bridged_content_view.h"
9 #import "ui/views/cocoa/bridged_native_widget.h"
10 #include "ui/views/widget/native_widget_mac.h"
12 @implementation ViewsNSWindowDelegate
14 - (id)initWithBridgedNativeWidget:(views::BridgedNativeWidget*)parent {
16 if ((self = [super init])) {
22 - (views::NativeWidgetMac*)nativeWidgetMac {
23 return parent_->native_widget_mac();
26 - (void)onWindowOrderWillChange:(NSWindowOrderingMode)orderingMode {
27 if (orderingMode != NSWindowOut)
28 [parent_->ns_view() setWillShow:YES];
31 - (void)onWindowOrderChanged {
32 [parent_->ns_view() setWillShow:NO];
35 // NSWindowDelegate implementation.
37 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
38 // Cocoa should already have sent an (unexpected) windowDidExitFullScreen:
39 // notification, and the attempt to get back into fullscreen should fail.
40 // Nothing to do except verify |parent_| is no longer trying to fullscreen.
41 DCHECK(!parent_->target_fullscreen_state());
44 - (void)windowDidFailToExitFullScreen:(NSWindow*)window {
45 // Unlike entering fullscreen, windowDidFailToExitFullScreen: is sent *before*
46 // windowDidExitFullScreen:. Also, failing to exit fullscreen just dumps the
47 // window out of fullscreen without an animation; still sending the expected,
48 // windowDidExitFullScreen: notification. So, again, nothing to do here.
49 DCHECK(!parent_->target_fullscreen_state());
52 - (void)windowDidBecomeKey:(NSNotification*)notification {
53 parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
57 - (void)windowDidResignKey:(NSNotification*)notification {
58 parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
62 - (void)windowWillClose:(NSNotification*)notification {
63 DCHECK([parent_->ns_window() isEqual:[notification object]]);
64 parent_->OnWindowWillClose();
67 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
68 parent_->OnFullscreenTransitionStart(true);
71 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
72 parent_->OnFullscreenTransitionComplete(true);
75 - (void)windowWillExitFullScreen:(NSNotification*)notification {
76 parent_->OnFullscreenTransitionStart(false);
79 - (void)windowDidExitFullScreen:(NSNotification*)notification {
80 parent_->OnFullscreenTransitionComplete(false);