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 parent_->OnVisibilityChangedTo(orderingMode != NSWindowOut);
30 - (void)onWindowOrderChanged:(NSNotification*)notification {
31 parent_->OnVisibilityChanged();
34 - (void)onWindowWillDisplay {
35 parent_->OnVisibilityChangedTo(true);
38 // NSWindowDelegate implementation.
40 - (void)windowDidFailToEnterFullScreen:(NSWindow*)window {
41 // Cocoa should already have sent an (unexpected) windowDidExitFullScreen:
42 // notification, and the attempt to get back into fullscreen should fail.
43 // Nothing to do except verify |parent_| is no longer trying to fullscreen.
44 DCHECK(!parent_->target_fullscreen_state());
47 - (void)windowDidFailToExitFullScreen:(NSWindow*)window {
48 // Unlike entering fullscreen, windowDidFailToExitFullScreen: is sent *before*
49 // windowDidExitFullScreen:. Also, failing to exit fullscreen just dumps the
50 // window out of fullscreen without an animation; still sending the expected,
51 // windowDidExitFullScreen: notification. So, again, nothing to do here.
52 DCHECK(!parent_->target_fullscreen_state());
55 - (void)windowDidResize:(NSNotification*)notification {
56 parent_->OnSizeChanged();
59 - (void)windowDidBecomeKey:(NSNotification*)notification {
60 parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
64 - (void)windowDidResignKey:(NSNotification*)notification {
65 parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
69 - (void)windowWillClose:(NSNotification*)notification {
70 DCHECK([parent_->ns_window() isEqual:[notification object]]);
71 parent_->OnWindowWillClose();
74 - (void)windowDidMiniaturize:(NSNotification*)notification {
75 parent_->OnVisibilityChanged();
78 - (void)windowDidDeminiaturize:(NSNotification*)notification {
79 parent_->OnVisibilityChanged();
82 - (void)windowDidChangeBackingProperties:(NSNotification*)notification {
83 parent_->OnBackingPropertiesChanged();
86 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
87 parent_->OnFullscreenTransitionStart(true);
90 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
91 parent_->OnFullscreenTransitionComplete(true);
94 - (void)windowWillExitFullScreen:(NSNotification*)notification {
95 parent_->OnFullscreenTransitionStart(false);
98 - (void)windowDidExitFullScreen:(NSNotification*)notification {
99 parent_->OnFullscreenTransitionComplete(false);