Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(42)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm

Issue 10824004: [mac] Implement {frame: 'none'} app window on Mac. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: alternative approach Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h" 5 #include "chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h"
6 6
7 #include "base/mac/mac_util.h" 7 #include "base/mac/mac_util.h"
8 #include "base/sys_string_conversions.h" 8 #include "base/sys_string_conversions.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/ui/cocoa/browser_window_utils.h" 10 #include "chrome/browser/ui/cocoa/browser_window_utils.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 cornerRadius = [view roundedCornerRadius]; 75 cornerRadius = [view roundedCornerRadius];
76 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] 76 [[NSBezierPath bezierPathWithRoundedRect:[view bounds]
77 xRadius:cornerRadius 77 xRadius:cornerRadius
78 yRadius:cornerRadius] addClip]; 78 yRadius:cornerRadius] addClip];
79 [[NSColor whiteColor] set]; 79 [[NSColor whiteColor] set];
80 NSRectFill(rect); 80 NSRectFill(rect);
81 } 81 }
82 82
83 @end 83 @end
84 84
85 @interface ControlRegionView : NSView
86 @end
87 @implementation ControlRegionView
88 - (BOOL)mouseDownCanMoveWindow {
89 return NO;
90 }
91 - (NSView*)hitTest:(NSPoint)aPoint {
92 return nil;
93 }
94 @end
95
96 @interface NSView (WebContentsView)
97 - (void)setMouseDownCanMoveWindow:(BOOL)can_move;
98 @end
99
85 ShellWindowCocoa::ShellWindowCocoa(Profile* profile, 100 ShellWindowCocoa::ShellWindowCocoa(Profile* profile,
86 const extensions::Extension* extension, 101 const extensions::Extension* extension,
87 const GURL& url, 102 const GURL& url,
88 const ShellWindow::CreateParams& params) 103 const ShellWindow::CreateParams& params)
89 : ShellWindow(profile, extension, url), 104 : ShellWindow(profile, extension, url),
105 has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME),
90 attention_request_id_(0) { 106 attention_request_id_(0) {
91 // Flip coordinates based on the primary screen. 107 // Flip coordinates based on the primary screen.
92 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; 108 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
93 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), 109 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(),
94 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), 110 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(),
95 params.bounds.width(), params.bounds.height()); 111 params.bounds.width(), params.bounds.height());
96 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask | 112 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
97 NSMiniaturizableWindowMask | NSResizableWindowMask | 113 NSMiniaturizableWindowMask | NSResizableWindowMask |
98 NSTexturedBackgroundWindowMask; 114 NSTexturedBackgroundWindowMask;
99 scoped_nsobject<NSWindow> window([[ShellNSWindow alloc] 115 scoped_nsobject<NSWindow> window([[ShellNSWindow alloc]
(...skipping 10 matching lines...) Expand all
110 if (max_size.width() || max_size.height()) { 126 if (max_size.width() || max_size.height()) {
111 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; 127 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX;
112 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; 128 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX;
113 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; 129 [window setContentMaxSize:NSMakeSize(max_width, max_height)];
114 } 130 }
115 131
116 if (base::mac::IsOSSnowLeopardOrEarlier() && 132 if (base::mac::IsOSSnowLeopardOrEarlier() &&
117 [window respondsToSelector:@selector(setBottomCornerRounded:)]) 133 [window respondsToSelector:@selector(setBottomCornerRounded:)])
118 [window setBottomCornerRounded:NO]; 134 [window setBottomCornerRounded:NO];
119 135
120 NSView* view = web_contents()->GetView()->GetNativeView();
121 [view setFrame:[[window contentView] bounds]];
122 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
123 [[window contentView] addSubview:view];
124
125 window_controller_.reset( 136 window_controller_.reset(
126 [[ShellWindowController alloc] initWithWindow:window.release()]); 137 [[ShellWindowController alloc] initWithWindow:window.release()]);
138
139 NSView* view = web_contents()->GetView()->GetNativeView();
140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
141
142 if (!has_frame_) {
143 // TODO(jeremya): this is a temporary hack to allow moving the window while
144 // we still don't have proper draggable region support.
145 NSView* controlRegion = [[ControlRegionView alloc] init];
sail 2012/08/07 17:40:11 this should be scoped_nsobject
146 [controlRegion setFrame:NSMakeRect(0, 0, NSWidth([view bounds]),
147 NSHeight([view bounds]) - 20)];
148 [controlRegion setAutoresizingMask:
149 NSViewWidthSizable | NSViewHeightSizable];
150 [view addSubview:controlRegion];
151 [controlRegion release];
152 }
153
154 InstallView();
155
127 [[window_controller_ window] setDelegate:window_controller_]; 156 [[window_controller_ window] setDelegate:window_controller_];
128 [window_controller_ setShellWindow:this]; 157 [window_controller_ setShellWindow:this];
129 } 158 }
130 159
160 void ShellWindowCocoa::InstallView() {
161 NSView* view = web_contents()->GetView()->GetNativeView();
162 if (has_frame_) {
163 [view setFrame:[[window() contentView] bounds]];
164 [[window() contentView] addSubview:view];
165 } else {
166 // TODO(jeremya): find a cleaner way to send this information to the
167 // WebContentsViewCocoa view.
Avi (use Gerrit) 2012/08/03 05:19:49 Grrr. :(
jeremya 2012/08/05 22:52:42 I know :( :( I'm thinking that maybe the setMouse
168 DCHECK([view
169 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]);
170 [view setMouseDownCanMoveWindow:YES];
171
172 NSView* frameView = [[window() contentView] superview];
173 [view setFrame:[frameView bounds]];
174 [frameView addSubview:view];
175
176 [[window() standardWindowButton:NSWindowZoomButton] setHidden:YES];
177 [[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES];
178 [[window() standardWindowButton:NSWindowCloseButton] setHidden:YES];
179 }
180 }
181
182 void ShellWindowCocoa::UninstallView() {
183 NSView* view = web_contents()->GetView()->GetNativeView();
184 [view removeFromSuperview];
185 }
186
131 bool ShellWindowCocoa::IsActive() const { 187 bool ShellWindowCocoa::IsActive() const {
132 return [window() isKeyWindow]; 188 return [window() isKeyWindow];
133 } 189 }
134 190
135 bool ShellWindowCocoa::IsMaximized() const { 191 bool ShellWindowCocoa::IsMaximized() const {
136 return [window() isZoomed]; 192 return [window() isZoomed];
137 } 193 }
138 194
139 bool ShellWindowCocoa::IsMinimized() const { 195 bool ShellWindowCocoa::IsMinimized() const {
140 return [window() isMiniaturized]; 196 return [window() isMiniaturized];
(...skipping 19 matching lines...) Expand all
160 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6; 216 const CGDisplayReservationInterval kFadeDurationSeconds = 0.6;
161 bool did_fade_out = false; 217 bool did_fade_out = false;
162 CGDisplayFadeReservationToken token; 218 CGDisplayFadeReservationToken token;
163 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) == 219 if (CGAcquireDisplayFadeReservation(kFadeDurationSeconds, &token) ==
164 kCGErrorSuccess) { 220 kCGErrorSuccess) {
165 did_fade_out = true; 221 did_fade_out = true;
166 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal, 222 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendNormal,
167 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true); 223 kCGDisplayBlendSolidColor, 0.0, 0.0, 0.0, /*synchronous=*/true);
168 } 224 }
169 225
226 // Since frameless windows insert the WebContentsView into the NSThemeFrame
227 // ([[window contentView] superview]), and since that NSThemeFrame is
228 // destroyed and recreated when we change the styleMask of the window, we
229 // need to remove the view from the window when we change the style, and
230 // add it back afterwards.
231 UninstallView();
170 if (fullscreen) { 232 if (fullscreen) {
171 restored_bounds_ = [window() frame]; 233 restored_bounds_ = [window() frame];
172 [window() setStyleMask:NSBorderlessWindowMask]; 234 [window() setStyleMask:NSBorderlessWindowMask];
173 [window() setFrame:[window() 235 [window() setFrame:[window()
174 frameRectForContentRect:[[window() screen] frame]] 236 frameRectForContentRect:[[window() screen] frame]]
175 display:YES]; 237 display:YES];
176 base::mac::RequestFullScreen(base::mac::kFullScreenModeAutoHideAll); 238 base::mac::RequestFullScreen(base::mac::kFullScreenModeAutoHideAll);
177 } else { 239 } else {
178 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeAutoHideAll); 240 base::mac::ReleaseFullScreen(base::mac::kFullScreenModeAutoHideAll);
179 [window() setStyleMask:NSTitledWindowMask | NSClosableWindowMask | 241 NSUInteger style_mask = NSTitledWindowMask | NSClosableWindowMask |
180 NSMiniaturizableWindowMask | NSResizableWindowMask]; 242 NSMiniaturizableWindowMask | NSResizableWindowMask |
243 NSTexturedBackgroundWindowMask;
244 [window() setStyleMask:style_mask];
181 [window() setFrame:restored_bounds_ display:YES]; 245 [window() setFrame:restored_bounds_ display:YES];
182 } 246 }
247 InstallView();
183 248
184 // Fade back in. 249 // Fade back in.
185 if (did_fade_out) { 250 if (did_fade_out) {
186 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, 251 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor,
187 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); 252 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false);
188 CGReleaseDisplayFadeReservation(token); 253 CGReleaseDisplayFadeReservation(token);
189 } 254 }
190 } 255 }
191 256
192 bool ShellWindowCocoa::IsFullscreenOrPending() const { 257 bool ShellWindowCocoa::IsFullscreenOrPending() const {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 return [window_controller_ window]; 389 return [window_controller_ window];
325 } 390 }
326 391
327 // static 392 // static
328 ShellWindow* ShellWindow::CreateImpl(Profile* profile, 393 ShellWindow* ShellWindow::CreateImpl(Profile* profile,
329 const extensions::Extension* extension, 394 const extensions::Extension* extension,
330 const GURL& url, 395 const GURL& url,
331 const ShellWindow::CreateParams& params) { 396 const ShellWindow::CreateParams& params) {
332 return new ShellWindowCocoa(profile, extension, url, params); 397 return new ShellWindowCocoa(profile, extension, url, params);
333 } 398 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h ('k') | content/browser/web_contents/web_contents_view_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698