Chromium Code Reviews| 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 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 if (base::mac::IsOSSnowLeopardOrEarlier() && | 132 if (base::mac::IsOSSnowLeopardOrEarlier() && |
| 133 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 133 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 134 [window setBottomCornerRounded:NO]; | 134 [window setBottomCornerRounded:NO]; |
| 135 | 135 |
| 136 window_controller_.reset( | 136 window_controller_.reset( |
| 137 [[ShellWindowController alloc] initWithWindow:window.release()]); | 137 [[ShellWindowController alloc] initWithWindow:window.release()]); |
| 138 | 138 |
| 139 NSView* view = web_contents()->GetView()->GetNativeView(); | 139 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 141 | 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]; | |
| 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(); | 142 InstallView(); |
| 155 | 143 |
| 156 [[window_controller_ window] setDelegate:window_controller_]; | 144 [[window_controller_ window] setDelegate:window_controller_]; |
| 157 [window_controller_ setShellWindow:this]; | 145 [window_controller_ setShellWindow:this]; |
| 158 } | 146 } |
| 159 | 147 |
| 160 void ShellWindowCocoa::InstallView() { | 148 void ShellWindowCocoa::InstallView() { |
| 161 NSView* view = web_contents()->GetView()->GetNativeView(); | 149 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 162 if (has_frame_) { | 150 if (has_frame_) { |
| 163 [view setFrame:[[window() contentView] bounds]]; | 151 [view setFrame:[[window() contentView] bounds]]; |
| 164 [[window() contentView] addSubview:view]; | 152 [[window() contentView] addSubview:view]; |
| 165 } else { | 153 } else { |
| 166 // TODO(jeremya): find a cleaner way to send this information to the | 154 // TODO(jeremya): find a cleaner way to send this information to the |
| 167 // WebContentsViewCocoa view. | 155 // WebContentsViewCocoa view. |
| 168 DCHECK([view | 156 DCHECK([view |
| 169 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]); | 157 respondsToSelector:@selector(setMouseDownCanMoveWindow:)]); |
| 170 [view setMouseDownCanMoveWindow:YES]; | 158 [view setMouseDownCanMoveWindow:YES]; |
| 171 | 159 |
| 172 NSView* frameView = [[window() contentView] superview]; | 160 NSView* frameView = [[window() contentView] superview]; |
| 173 [view setFrame:[frameView bounds]]; | 161 [view setFrame:[frameView bounds]]; |
| 174 [frameView addSubview:view]; | 162 [frameView addSubview:view]; |
| 175 | 163 |
| 176 [[window() standardWindowButton:NSWindowZoomButton] setHidden:YES]; | 164 [[window() standardWindowButton:NSWindowZoomButton] setHidden:YES]; |
| 177 [[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; | 165 [[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; |
| 178 [[window() standardWindowButton:NSWindowCloseButton] setHidden:YES]; | 166 [[window() standardWindowButton:NSWindowCloseButton] setHidden:YES]; |
| 167 | |
| 168 InstallDraggableRegionViews(); | |
| 179 } | 169 } |
| 180 } | 170 } |
| 181 | 171 |
| 182 void ShellWindowCocoa::UninstallView() { | 172 void ShellWindowCocoa::UninstallView() { |
| 183 NSView* view = web_contents()->GetView()->GetNativeView(); | 173 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 184 [view removeFromSuperview]; | 174 [view removeFromSuperview]; |
| 185 } | 175 } |
| 186 | 176 |
| 187 bool ShellWindowCocoa::IsActive() const { | 177 bool ShellWindowCocoa::IsActive() const { |
| 188 return [window() isKeyWindow]; | 178 return [window() isKeyWindow]; |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 332 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, | 322 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, |
| 333 checked_bounds.width(), | 323 checked_bounds.width(), |
| 334 checked_bounds.height()); | 324 checked_bounds.height()); |
| 335 // Flip coordinates based on the primary screen. | 325 // Flip coordinates based on the primary screen. |
| 336 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 326 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 337 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); | 327 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); |
| 338 | 328 |
| 339 [window() setFrame:cocoa_bounds display:YES]; | 329 [window() setFrame:cocoa_bounds display:YES]; |
| 340 } | 330 } |
| 341 | 331 |
| 332 void ShellWindowCocoa::UpdateDraggableRegions( | |
| 333 const std::vector<extensions::DraggableRegion>& regions) { | |
| 334 // Draggable region is not supported for non-frameless window. | |
| 335 if (has_frame_) | |
| 336 return; | |
| 337 | |
| 338 draggable_regions_ = regions; | |
| 339 InstallDraggableRegionViews(); | |
| 340 } | |
| 341 | |
| 342 void ShellWindowCocoa::InstallDraggableRegionViews() { | |
| 343 DCHECK(!has_frame_); | |
| 344 | |
| 345 // All ControlRegionViews should be added as children of the WebContentsView, | |
| 346 // because WebContentsView will be removed and re-added when entering and | |
| 347 // leaving fullscreen mode. | |
| 348 NSView* webView = web_contents()->GetView()->GetNativeView(); | |
| 349 int webViewHeight = NSHeight([webView bounds]); | |
|
Robert Sesek
2012/08/09 14:52:44
NSHeight returns a CGFloat. If you want to truncat
| |
| 350 | |
| 351 // Remove all ControlRegionViews that are added last time. | |
| 352 // Note that we need to copy subviews because [webView subviews] returns | |
|
Robert Sesek
2012/08/09 14:52:44
Avoid "we" in comments. Third person is preferred.
| |
| 353 // the view's mutable internal array and we do not want to mutate the array | |
| 354 // while enumerating it. | |
| 355 NSArray* subviews = [[webView subviews] copy]; | |
|
Robert Sesek
2012/08/09 14:52:44
scoped_nsobject<T>
| |
| 356 for (NSView* subview in subviews) | |
| 357 if ([subview isKindOfClass:[ControlRegionView class]]) | |
| 358 [subview removeFromSuperview]; | |
| 359 [subviews release]; | |
| 360 | |
| 361 // Create and add ControlRegionView for each region that needs to be excluded | |
| 362 // from the dragging. | |
| 363 for (std::vector<extensions::DraggableRegion>::const_iterator iter = | |
| 364 draggable_regions_.begin(); | |
| 365 iter != draggable_regions_.end(); ++iter) { | |
|
Robert Sesek
2012/08/09 14:52:44
GO ahead and move ++iter to its own line, too
| |
| 366 const extensions::DraggableRegion& region = *iter; | |
| 367 scoped_nsobject<NSView> controlRegion([[ControlRegionView alloc] init]); | |
| 368 [controlRegion setFrame:NSMakeRect(region.bounds.x(), | |
| 369 webViewHeight - region.bounds.bottom(), | |
| 370 region.bounds.width(), | |
| 371 region.bounds.height())]; | |
| 372 [webView addSubview:controlRegion]; | |
| 373 } | |
| 374 } | |
| 375 | |
| 342 void ShellWindowCocoa::FlashFrame(bool flash) { | 376 void ShellWindowCocoa::FlashFrame(bool flash) { |
| 343 if (flash) { | 377 if (flash) { |
| 344 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; | 378 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
| 345 } else { | 379 } else { |
| 346 [NSApp cancelUserAttentionRequest:attention_request_id_]; | 380 [NSApp cancelUserAttentionRequest:attention_request_id_]; |
| 347 attention_request_id_ = 0; | 381 attention_request_id_ = 0; |
| 348 } | 382 } |
| 349 } | 383 } |
| 350 | 384 |
| 351 bool ShellWindowCocoa::IsAlwaysOnTop() const { | 385 bool ShellWindowCocoa::IsAlwaysOnTop() const { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 385 return [window_controller_ window]; | 419 return [window_controller_ window]; |
| 386 } | 420 } |
| 387 | 421 |
| 388 // static | 422 // static |
| 389 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 423 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
| 390 const extensions::Extension* extension, | 424 const extensions::Extension* extension, |
| 391 const GURL& url, | 425 const GURL& url, |
| 392 const ShellWindow::CreateParams& params) { | 426 const ShellWindow::CreateParams& params) { |
| 393 return new ShellWindowCocoa(profile, extension, url, params); | 427 return new ShellWindowCocoa(profile, extension, url, params); |
| 394 } | 428 } |
| OLD | NEW |