Index: chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm |
diff --git a/chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm b/chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm |
index b76391fa12801da1d4cf4989258b1813e6878007..63868b7f549bfd510624ebba007d3ad0dc3ebd73 100644 |
--- a/chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm |
+++ b/chrome/browser/ui/cocoa/extensions/shell_window_cocoa.mm |
@@ -139,18 +139,6 @@ ShellWindowCocoa::ShellWindowCocoa(Profile* profile, |
NSView* view = web_contents()->GetView()->GetNativeView(); |
[view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
- if (!has_frame_) { |
- // TODO(jeremya): this is a temporary hack to allow moving the window while |
- // we still don't have proper draggable region support. |
- NSView* controlRegion = [[ControlRegionView alloc] init]; |
- [controlRegion setFrame:NSMakeRect(0, 0, NSWidth([view bounds]), |
- NSHeight([view bounds]) - 20)]; |
- [controlRegion setAutoresizingMask: |
- NSViewWidthSizable | NSViewHeightSizable]; |
- [view addSubview:controlRegion]; |
- [controlRegion release]; |
- } |
- |
InstallView(); |
[[window_controller_ window] setDelegate:window_controller_]; |
@@ -176,6 +164,8 @@ void ShellWindowCocoa::InstallView() { |
[[window() standardWindowButton:NSWindowZoomButton] setHidden:YES]; |
[[window() standardWindowButton:NSWindowMiniaturizeButton] setHidden:YES]; |
[[window() standardWindowButton:NSWindowCloseButton] setHidden:YES]; |
+ |
+ InstallDraggableRegionViews(); |
} |
} |
@@ -339,6 +329,50 @@ void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
[window() setFrame:cocoa_bounds display:YES]; |
} |
+void ShellWindowCocoa::UpdateDraggableRegions( |
+ const std::vector<extensions::DraggableRegion>& regions) { |
+ // Draggable region is not supported for non-frameless window. |
+ if (has_frame_) |
+ return; |
+ |
+ draggable_regions_ = regions; |
+ InstallDraggableRegionViews(); |
+} |
+ |
+void ShellWindowCocoa::InstallDraggableRegionViews() { |
+ DCHECK(!has_frame_); |
+ |
+ // All ControlRegionViews should be added as children of the WebContentsView, |
+ // because WebContentsView will be removed and re-added when entering and |
+ // leaving fullscreen mode. |
+ NSView* webView = web_contents()->GetView()->GetNativeView(); |
+ int webViewHeight = NSHeight([webView bounds]); |
Robert Sesek
2012/08/09 14:52:44
NSHeight returns a CGFloat. If you want to truncat
|
+ |
+ // Remove all ControlRegionViews that are added last time. |
+ // 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.
|
+ // the view's mutable internal array and we do not want to mutate the array |
+ // while enumerating it. |
+ NSArray* subviews = [[webView subviews] copy]; |
Robert Sesek
2012/08/09 14:52:44
scoped_nsobject<T>
|
+ for (NSView* subview in subviews) |
+ if ([subview isKindOfClass:[ControlRegionView class]]) |
+ [subview removeFromSuperview]; |
+ [subviews release]; |
+ |
+ // Create and add ControlRegionView for each region that needs to be excluded |
+ // from the dragging. |
+ for (std::vector<extensions::DraggableRegion>::const_iterator iter = |
+ draggable_regions_.begin(); |
+ iter != draggable_regions_.end(); ++iter) { |
Robert Sesek
2012/08/09 14:52:44
GO ahead and move ++iter to its own line, too
|
+ const extensions::DraggableRegion& region = *iter; |
+ scoped_nsobject<NSView> controlRegion([[ControlRegionView alloc] init]); |
+ [controlRegion setFrame:NSMakeRect(region.bounds.x(), |
+ webViewHeight - region.bounds.bottom(), |
+ region.bounds.width(), |
+ region.bounds.height())]; |
+ [webView addSubview:controlRegion]; |
+ } |
+} |
+ |
void ShellWindowCocoa::FlashFrame(bool flash) { |
if (flash) { |
attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |