| OLD | NEW |
| 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 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 65 const CGFloat kWindowBorderRadius = 3.0; | 65 const CGFloat kWindowBorderRadius = 3.0; |
| 66 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] | 66 [[NSBezierPath bezierPathWithRoundedRect:[view bounds] |
| 67 xRadius:kWindowBorderRadius | 67 xRadius:kWindowBorderRadius |
| 68 yRadius:kWindowBorderRadius] addClip]; | 68 yRadius:kWindowBorderRadius] addClip]; |
| 69 [[NSColor whiteColor] set]; | 69 [[NSColor whiteColor] set]; |
| 70 NSRectFill(rect); | 70 NSRectFill(rect); |
| 71 } | 71 } |
| 72 | 72 |
| 73 @end | 73 @end |
| 74 | 74 |
| 75 @interface ControlRegionView : NSView |
| 76 @end |
| 77 @implementation ControlRegionView |
| 78 - (BOOL)mouseDownCanMoveWindow { |
| 79 return NO; |
| 80 } |
| 81 - (NSView*)hitTest:(NSPoint)aPoint { |
| 82 return nil; |
| 83 } |
| 84 @end |
| 85 |
| 75 ShellWindowCocoa::ShellWindowCocoa(Profile* profile, | 86 ShellWindowCocoa::ShellWindowCocoa(Profile* profile, |
| 76 const extensions::Extension* extension, | 87 const extensions::Extension* extension, |
| 77 const GURL& url, | 88 const GURL& url, |
| 78 const ShellWindow::CreateParams& params) | 89 const ShellWindow::CreateParams& params) |
| 79 : ShellWindow(profile, extension, url), | 90 : ShellWindow(profile, extension, url), |
| 80 attention_request_id_(0) { | 91 attention_request_id_(0) { |
| 81 // Flip coordinates based on the primary screen. | 92 // Flip coordinates based on the primary screen. |
| 82 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; | 93 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; |
| 83 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), | 94 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), |
| 84 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), | 95 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), |
| (...skipping 16 matching lines...) Expand all Loading... |
| 101 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; | 112 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; |
| 102 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; | 113 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; |
| 103 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 114 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| 104 } | 115 } |
| 105 | 116 |
| 106 if (base::mac::IsOSSnowLeopardOrEarlier() && | 117 if (base::mac::IsOSSnowLeopardOrEarlier() && |
| 107 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 118 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 108 [window setBottomCornerRounded:NO]; | 119 [window setBottomCornerRounded:NO]; |
| 109 | 120 |
| 110 NSView* view = web_contents()->GetView()->GetNativeView(); | 121 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 111 [view setFrame:[[window contentView] bounds]]; | |
| 112 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 122 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 113 [[window contentView] addSubview:view]; | 123 if (params.frame == ShellWindow::CreateParams::FRAME_CHROME) { |
| 124 [view setFrame:[[window contentView] bounds]]; |
| 125 [[window contentView] addSubview:view]; |
| 126 } else { |
| 127 web_contents()->GetView()->SetMouseDownCanMoveWindow(true); |
| 128 NSView* frameView = [[window contentView] superview]; |
| 129 [view setFrame:[frameView bounds]]; |
| 130 [frameView addSubview:view]; |
| 131 [[window standardWindowButton:NSWindowZoomButton] setHidden:YES]; |
| 132 [[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; |
| 133 [[window standardWindowButton:NSWindowCloseButton] setHidden:YES]; |
| 134 |
| 135 // TODO(jeremya): this is a temporary hack to allow moving the window while |
| 136 // we still don't have proper draggable region support. |
| 137 NSView* controlRegion = [[ControlRegionView alloc] init]; |
| 138 [controlRegion setFrame:NSMakeRect(0, 0, NSWidth([frameView bounds]), |
| 139 NSHeight([frameView bounds]) - 20)]; |
| 140 [controlRegion setAutoresizingMask: |
| 141 NSViewWidthSizable | NSViewHeightSizable]; |
| 142 [frameView addSubview:controlRegion]; |
| 143 [controlRegion release]; |
| 144 } |
| 114 | 145 |
| 115 window_controller_.reset( | 146 window_controller_.reset( |
| 116 [[ShellWindowController alloc] initWithWindow:window.release()]); | 147 [[ShellWindowController alloc] initWithWindow:window.release()]); |
| 117 [[window_controller_ window] setDelegate:window_controller_]; | 148 [[window_controller_ window] setDelegate:window_controller_]; |
| 118 [window_controller_ setShellWindow:this]; | 149 [window_controller_ setShellWindow:this]; |
| 119 } | 150 } |
| 120 | 151 |
| 121 bool ShellWindowCocoa::IsActive() const { | 152 bool ShellWindowCocoa::IsActive() const { |
| 122 return [window() isKeyWindow]; | 153 return [window() isKeyWindow]; |
| 123 } | 154 } |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 return [window_controller_ window]; | 345 return [window_controller_ window]; |
| 315 } | 346 } |
| 316 | 347 |
| 317 // static | 348 // static |
| 318 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 349 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| 319 const extensions::Extension* extension, | 350 const extensions::Extension* extension, |
| 320 const GURL& url, | 351 const GURL& url, |
| 321 const ShellWindow::CreateParams& params) { | 352 const ShellWindow::CreateParams& params) { |
| 322 return new ShellWindowCocoa(profile, extension, url, params); | 353 return new ShellWindowCocoa(profile, extension, url, params); |
| 323 } | 354 } |
| OLD | NEW |