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 |
| 86 @interface NSView (WebContentsView) |
| 87 - (void)setMouseDownCanMoveWindow:(BOOL)can_move; |
| 88 @end |
| 89 |
75 ShellWindowCocoa::ShellWindowCocoa(Profile* profile, | 90 ShellWindowCocoa::ShellWindowCocoa(Profile* profile, |
76 const extensions::Extension* extension, | 91 const extensions::Extension* extension, |
77 const GURL& url, | 92 const GURL& url, |
78 const ShellWindow::CreateParams& params) | 93 const ShellWindow::CreateParams& params) |
79 : ShellWindow(profile, extension, url), | 94 : ShellWindow(profile, extension, url), |
80 attention_request_id_(0) { | 95 attention_request_id_(0) { |
81 // Flip coordinates based on the primary screen. | 96 // Flip coordinates based on the primary screen. |
82 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; | 97 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; |
83 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), | 98 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), |
84 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), | 99 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; | 116 CGFloat max_width = max_size.width() ? max_size.width() : CGFLOAT_MAX; |
102 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; | 117 CGFloat max_height = max_size.height() ? max_size.height() : CGFLOAT_MAX; |
103 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 118 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
104 } | 119 } |
105 | 120 |
106 if (base::mac::IsOSSnowLeopardOrEarlier() && | 121 if (base::mac::IsOSSnowLeopardOrEarlier() && |
107 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 122 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
108 [window setBottomCornerRounded:NO]; | 123 [window setBottomCornerRounded:NO]; |
109 | 124 |
110 NSView* view = web_contents()->GetView()->GetNativeView(); | 125 NSView* view = web_contents()->GetView()->GetNativeView(); |
111 [view setFrame:[[window contentView] bounds]]; | |
112 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 126 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
113 [[window contentView] addSubview:view]; | 127 if (params.frame == ShellWindow::CreateParams::FRAME_CHROME) { |
| 128 [view setFrame:[[window contentView] bounds]]; |
| 129 [[window contentView] addSubview:view]; |
| 130 } else { |
| 131 NSView* web_contents_view = |
| 132 web_contents()->GetView()->GetNativeView(); |
| 133 DCHECK([web_contents_view |
| 134 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]); |
| 135 [web_contents_view setMouseDownCanMoveWindow:YES]; |
| 136 NSView* frameView = [[window contentView] superview]; |
| 137 [view setFrame:[frameView bounds]]; |
| 138 [frameView addSubview:view]; |
| 139 [[window standardWindowButton:NSWindowZoomButton] setHidden:YES]; |
| 140 [[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; |
| 141 [[window standardWindowButton:NSWindowCloseButton] setHidden:YES]; |
| 142 |
| 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]; |
| 146 [controlRegion setFrame:NSMakeRect(0, 0, NSWidth([frameView bounds]), |
| 147 NSHeight([frameView bounds]) - 20)]; |
| 148 [controlRegion setAutoresizingMask: |
| 149 NSViewWidthSizable | NSViewHeightSizable]; |
| 150 [frameView addSubview:controlRegion]; |
| 151 [controlRegion release]; |
| 152 } |
114 | 153 |
115 window_controller_.reset( | 154 window_controller_.reset( |
116 [[ShellWindowController alloc] initWithWindow:window.release()]); | 155 [[ShellWindowController alloc] initWithWindow:window.release()]); |
117 [[window_controller_ window] setDelegate:window_controller_]; | 156 [[window_controller_ window] setDelegate:window_controller_]; |
118 [window_controller_ setShellWindow:this]; | 157 [window_controller_ setShellWindow:this]; |
119 } | 158 } |
120 | 159 |
121 bool ShellWindowCocoa::IsActive() const { | 160 bool ShellWindowCocoa::IsActive() const { |
122 return [window() isKeyWindow]; | 161 return [window() isKeyWindow]; |
123 } | 162 } |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 return [window_controller_ window]; | 353 return [window_controller_ window]; |
315 } | 354 } |
316 | 355 |
317 // static | 356 // static |
318 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 357 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
319 const extensions::Extension* extension, | 358 const extensions::Extension* extension, |
320 const GURL& url, | 359 const GURL& url, |
321 const ShellWindow::CreateParams& params) { | 360 const ShellWindow::CreateParams& params) { |
322 return new ShellWindowCocoa(profile, extension, url, params); | 361 return new ShellWindowCocoa(profile, extension, url, params); |
323 } | 362 } |
OLD | NEW |