Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / ui / views / cocoa / views_nswindow_delegate.mm
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.
4
5 #import "ui/views/cocoa/views_nswindow_delegate.h"
6
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"
11
12 @implementation ViewsNSWindowDelegate
13
14 - (id)initWithBridgedNativeWidget:(views::BridgedNativeWidget*)parent {
15   DCHECK(parent);
16   if ((self = [super init])) {
17     parent_ = parent;
18   }
19   return self;
20 }
21
22 - (views::NativeWidgetMac*)nativeWidgetMac {
23   return parent_->native_widget_mac();
24 }
25
26 - (void)onWindowOrderWillChange:(NSWindowOrderingMode)orderingMode {
27   if (orderingMode != NSWindowOut)
28     [parent_->ns_view() setWillShow:YES];
29 }
30
31 - (void)onWindowOrderChanged {
32   [parent_->ns_view() setWillShow:NO];
33 }
34
35 // NSWindowDelegate implementation.
36
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());
42 }
43
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());
50 }
51
52 - (void)windowDidBecomeKey:(NSNotification*)notification {
53   parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
54       true);
55 }
56
57 - (void)windowDidResignKey:(NSNotification*)notification {
58   parent_->native_widget_mac()->GetWidget()->OnNativeWidgetActivationChanged(
59       false);
60 }
61
62 - (void)windowWillClose:(NSNotification*)notification {
63   DCHECK([parent_->ns_window() isEqual:[notification object]]);
64   parent_->OnWindowWillClose();
65 }
66
67 - (void)windowWillEnterFullScreen:(NSNotification*)notification {
68   parent_->OnFullscreenTransitionStart(true);
69 }
70
71 - (void)windowDidEnterFullScreen:(NSNotification*)notification {
72   parent_->OnFullscreenTransitionComplete(true);
73 }
74
75 - (void)windowWillExitFullScreen:(NSNotification*)notification {
76   parent_->OnFullscreenTransitionStart(false);
77 }
78
79 - (void)windowDidExitFullScreen:(NSNotification*)notification {
80   parent_->OnFullscreenTransitionComplete(false);
81 }
82
83 @end