Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / full_size_content_window.mm
blob1dea52a7000bd65d1d62417433394e089eb08e28
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 "chrome/browser/ui/cocoa/full_size_content_window.h"
7 #include "base/logging.h"
9 @interface FullSizeContentWindow ()
11 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle;
13 @end
15 // This view always takes the size of its superview. It is intended to be used
16 // as a NSWindow's contentView.  It is needed because NSWindow's implementation
17 // explicitly resizes the contentView at inopportune times.
18 @interface FullSizeContentView : NSView
19 @end
21 @implementation FullSizeContentView
23 // This method is directly called by AppKit during a live window resize.
24 // Override it to prevent the content view from shrinking.
25 - (void)setFrameSize:(NSSize)size {
26   if ([self superview])
27     size = [[self superview] bounds].size;
28   [super setFrameSize:size];
31 @end
33 @implementation FullSizeContentWindow
35 #pragma mark - Lifecycle
37 - (instancetype)init {
38   NOTREACHED();
39   return nil;
42 - (instancetype)initWithContentRect:(NSRect)contentRect
43                           styleMask:(NSUInteger)windowStyle
44                             backing:(NSBackingStoreType)bufferingType
45                               defer:(BOOL)deferCreation {
46   return [self initWithContentRect:contentRect
47                          styleMask:windowStyle
48                            backing:bufferingType
49                              defer:deferCreation
50             wantsViewsOverTitlebar:NO];
53 - (instancetype)initWithContentRect:(NSRect)contentRect
54                           styleMask:(NSUInteger)windowStyle
55                             backing:(NSBackingStoreType)bufferingType
56                               defer:(BOOL)deferCreation
57              wantsViewsOverTitlebar:(BOOL)wantsViewsOverTitlebar {
58   self = [super initWithContentRect:contentRect
59                           styleMask:windowStyle
60                             backing:bufferingType
61                               defer:deferCreation];
62   if (self) {
63     if (wantsViewsOverTitlebar &&
64         [FullSizeContentWindow
65             shouldUseFullSizeContentViewForStyle:windowStyle]) {
66       chromeWindowView_.reset([[FullSizeContentView alloc] init]);
67       [chromeWindowView_
68           setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
69       [self setContentView:chromeWindowView_];
70       [chromeWindowView_ setFrame:[[chromeWindowView_ superview] bounds]];
72       // Our content view overlaps the window control buttons, so we must ensure
73       // it is positioned below the buttons.
74       NSView* superview = [chromeWindowView_ superview];
75       [chromeWindowView_ removeFromSuperview];
76       [superview addSubview:chromeWindowView_
77                  positioned:NSWindowBelow
78                  relativeTo:nil];
79     }
80   }
81   return self;
84 #pragma mark - Private Methods
86 + (BOOL)shouldUseFullSizeContentViewForStyle:(NSUInteger)windowStyle {
87   return windowStyle & NSTitledWindowMask;
90 #pragma mark - NSWindow Overrides
92 + (NSRect)frameRectForContentRect:(NSRect)cRect styleMask:(NSUInteger)aStyle {
93   if ([self shouldUseFullSizeContentViewForStyle:aStyle])
94     return cRect;
95   return [super frameRectForContentRect:cRect styleMask:aStyle];
98 - (NSRect)frameRectForContentRect:(NSRect)contentRect {
99   if (chromeWindowView_)
100     return contentRect;
101   return [super frameRectForContentRect:contentRect];
104 + (NSRect)contentRectForFrameRect:(NSRect)fRect styleMask:(NSUInteger)aStyle {
105   if ([self shouldUseFullSizeContentViewForStyle:aStyle])
106     return fRect;
107   return [super contentRectForFrameRect:fRect styleMask:aStyle];
110 - (NSRect)contentRectForFrameRect:(NSRect)frameRect {
111   if (chromeWindowView_)
112     return frameRect;
113   return [super contentRectForFrameRect:frameRect];
116 @end