cygprofile: increase timeouts to allow showing web contents
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / chrome_event_processing_window.mm
blob6c9e275d56264149f1f2445281f8c0a6e1a6a6d2
1 // Copyright (c) 2012 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 "chrome/browser/ui/cocoa/chrome_event_processing_window.h"
7 #include "base/logging.h"
8 #import "chrome/browser/ui/cocoa/chrome_command_dispatcher_delegate.h"
9 #import "ui/base/cocoa/user_interface_item_command_handler.h"
11 @implementation ChromeEventProcessingWindow {
12  @private
13   base::scoped_nsobject<CommandDispatcher> commandDispatcher_;
14   base::scoped_nsobject<ChromeCommandDispatcherDelegate>
15       commandDispatcherDelegate_;
16   base::scoped_nsprotocol<id<UserInterfaceItemCommandHandler>> commandHandler_;
19 - (instancetype)initWithContentRect:(NSRect)contentRect
20                           styleMask:(NSUInteger)windowStyle
21                             backing:(NSBackingStoreType)bufferingType
22                               defer:(BOOL)deferCreation {
23   if ((self = [super initWithContentRect:contentRect
24                                styleMask:windowStyle
25                                  backing:bufferingType
26                                    defer:deferCreation])) {
27     commandDispatcher_.reset([[CommandDispatcher alloc] initWithOwner:self]);
28     commandDispatcherDelegate_.reset(
29         [[ChromeCommandDispatcherDelegate alloc] init]);
30     [commandDispatcher_ setDelegate:commandDispatcherDelegate_];
31   }
32   return self;
35 - (BOOL)handleExtraKeyboardShortcut:(NSEvent*)event {
36   return [commandDispatcherDelegate_ handleExtraKeyboardShortcut:event
37                                                           window:self];
40 // CommandDispatchingWindow implementation.
42 - (void)setCommandHandler:(id<UserInterfaceItemCommandHandler>)commandHandler {
43   commandHandler_.reset([commandHandler retain]);
46 - (BOOL)redispatchKeyEvent:(NSEvent*)event {
47   return [commandDispatcher_ redispatchKeyEvent:event];
50 - (BOOL)defaultPerformKeyEquivalent:(NSEvent*)event {
51   return [super performKeyEquivalent:event];
54 - (void)commandDispatch:(id)sender {
55   [commandHandler_ commandDispatch:sender window:self];
58 - (void)commandDispatchUsingKeyModifiers:(id)sender {
59   [commandHandler_ commandDispatchUsingKeyModifiers:sender window:self];
62 // NSWindow overrides.
64 - (BOOL)performKeyEquivalent:(NSEvent*)event {
65   return [commandDispatcher_ performKeyEquivalent:event];
68 - (void)sendEvent:(NSEvent*)event {
69   if (![commandDispatcher_ preSendEvent:event])
70     [super sendEvent:event];
73 // NSWindow overrides (NSUserInterfaceValidations implementation).
75 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item {
76   // Since this class implements these selectors, |super| will always say they
77   // are enabled. Only use [super] to validate other selectors. If there is no
78   // command handler, defer to AppController.
79   if ([item action] == @selector(commandDispatch:) ||
80       [item action] == @selector(commandDispatchUsingKeyModifiers:)) {
81     return commandHandler_
82                ? [commandHandler_ validateUserInterfaceItem:item window:self]
83                : [[NSApp delegate] validateUserInterfaceItem:item];
84   }
86   return [super validateUserInterfaceItem:item];
89 @end  // ChromeEventProcessingWindow