Workaround for xkbcommon dead keys.
[chromium-blink-merge.git] / ui / views / cocoa / native_widget_mac_nswindow.mm
blob2bc9c4f6e59412c9b0c04b897aa4bcaa63d0c131
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/native_widget_mac_nswindow.h"
7 #include "base/mac/foundation_util.h"
8 #import "ui/views/cocoa/views_nswindow_delegate.h"
10 @interface NativeWidgetMacNSWindow ()
11 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate;
12 @end
14 @implementation NativeWidgetMacNSWindow
16 - (ViewsNSWindowDelegate*)viewsNSWindowDelegate {
17   return base::mac::ObjCCastStrict<ViewsNSWindowDelegate>([self delegate]);
20 // Override canBecome{Key,Main}Window to always return YES, otherwise Windows
21 // with a styleMask of NSBorderlessWindowMask default to NO.
22 - (BOOL)canBecomeKeyWindow {
23   return YES;
26 - (BOOL)canBecomeMainWindow {
27   return YES;
30 // Override display, since this is the first opportunity Cocoa gives to detect
31 // a visibility change in some cases. For example, restoring from the dock first
32 // calls -[NSWindow display] before any NSWindowDelegate functions and before
33 // ordering the window (and without actually calling -[NSWindow deminiaturize]).
34 // By notifying the delegate that a display is about to occur, it can apply a
35 // correct visibility state, before [super display] requests a draw of the
36 // contentView. -[NSWindow isVisible] can still report NO at this point, so this
37 // gives the delegate time to apply correct visibility before the draw occurs.
38 - (void)display {
39   [[self viewsNSWindowDelegate] onWindowWillDisplay];
40   [super display];
43 // Override window order functions to intercept other visibility changes. This
44 // is needed in addition to the -[NSWindow display] override because Cocoa
45 // hardly ever calls display, and reports -[NSWindow isVisible] incorrectly
46 // when ordering in a window for the first time.
47 - (void)orderWindow:(NSWindowOrderingMode)orderingMode
48          relativeTo:(NSInteger)otherWindowNumber {
49   [[self viewsNSWindowDelegate] onWindowOrderWillChange:orderingMode];
50   [super orderWindow:orderingMode relativeTo:otherWindowNumber];
51   [[self viewsNSWindowDelegate] onWindowOrderChanged:nil];
54 @end