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" |
11 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 11 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
12 #include "chrome/common/extensions/extension.h" | 12 #include "chrome/common/extensions/extension.h" |
13 #include "content/public/browser/render_widget_host_view.h" | 13 #include "content/public/browser/render_widget_host_view.h" |
14 #include "content/public/browser/web_contents.h" | 14 #include "content/public/browser/web_contents.h" |
15 #include "content/public/browser/web_contents_view.h" | 15 #include "content/public/browser/web_contents_view.h" |
16 #include "content/public/common/draggable_region.h" | |
16 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" | 17 #import "ui/base/cocoa/underlay_opengl_hosting_window.h" |
17 | 18 |
18 @interface NSWindow (NSPrivateApis) | 19 @interface NSWindow (NSPrivateApis) |
19 - (void)setBottomCornerRounded:(BOOL)rounded; | 20 - (void)setBottomCornerRounded:(BOOL)rounded; |
20 @end | 21 @end |
21 | 22 |
22 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 23 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
23 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 24 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
24 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 25 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
25 | 26 |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 if (base::mac::IsOSSnowLeopardOrEarlier() && | 133 if (base::mac::IsOSSnowLeopardOrEarlier() && |
133 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 134 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
134 [window setBottomCornerRounded:NO]; | 135 [window setBottomCornerRounded:NO]; |
135 | 136 |
136 window_controller_.reset( | 137 window_controller_.reset( |
137 [[ShellWindowController alloc] initWithWindow:window.release()]); | 138 [[ShellWindowController alloc] initWithWindow:window.release()]); |
138 | 139 |
139 NSView* view = web_contents()->GetView()->GetNativeView(); | 140 NSView* view = web_contents()->GetView()->GetNativeView(); |
140 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 141 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
141 | 142 |
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(); | 143 InstallView(); |
155 | 144 |
156 [[window_controller_ window] setDelegate:window_controller_]; | 145 [[window_controller_ window] setDelegate:window_controller_]; |
157 [window_controller_ setShellWindow:this]; | 146 [window_controller_ setShellWindow:this]; |
158 } | 147 } |
159 | 148 |
160 void ShellWindowCocoa::InstallView() { | 149 void ShellWindowCocoa::InstallView() { |
161 NSView* view = web_contents()->GetView()->GetNativeView(); | 150 NSView* view = web_contents()->GetView()->GetNativeView(); |
162 if (has_frame_) { | 151 if (has_frame_) { |
163 [view setFrame:[[window() contentView] bounds]]; | 152 [view setFrame:[[window() contentView] bounds]]; |
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
336 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 325 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
337 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); | 326 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); |
338 | 327 |
339 [window() setFrame:cocoa_bounds display:YES]; | 328 [window() setFrame:cocoa_bounds display:YES]; |
340 } | 329 } |
341 | 330 |
342 void ShellWindowCocoa::SetDraggableRegion(SkRegion* region) { | 331 void ShellWindowCocoa::SetDraggableRegion(SkRegion* region) { |
343 // TODO: implement | 332 // TODO: implement |
344 } | 333 } |
345 | 334 |
335 void ShellWindowCocoa::UpdateDraggableRegions( | |
336 const std::vector<content::DraggableRegion>& regions) { | |
337 // Draggable region is not supported for non-frameless window. | |
338 if (has_frame_) | |
339 return; | |
340 | |
341 NSView* frameView = [[window() contentView] superview]; | |
342 int frameHeight = NSHeight([frameView bounds]); | |
343 | |
344 // Remove all ControlRegionView that are added last time. | |
345 // Note that we need to copy subviews because [frameView subviews] returns the | |
346 // view's mutable internal array and we do not want to mutate the array while | |
347 // enumerating it. | |
348 NSArray* subviews = [[frameView subviews] copy]; | |
349 for (NSView* subview in subviews) { | |
350 if ([subview isKindOfClass:[ControlRegionView class]]) { | |
351 [subview setHidden:YES]; | |
352 [subview removeFromSuperview]; | |
353 } | |
354 } | |
355 [subviews release]; | |
356 | |
357 // Create and add ControlRegionView for each region that needs to be excluded | |
358 // from the dragging. | |
359 for (std::vector<content::DraggableRegion>::const_iterator iter = | |
360 regions.begin(); | |
361 iter != regions.end(); ++iter) { | |
362 const content::DraggableRegion& region = *iter; | |
363 NSView* controlRegion = [[ControlRegionView alloc] init]; | |
364 [controlRegion setFrame:NSMakeRect(region.bounds.x(), | |
365 frameHeight - region.bounds.bottom(), | |
366 region.bounds.width(), | |
367 region.bounds.height())]; | |
368 [frameView addSubview:controlRegion]; | |
jeremya
2012/08/07 00:38:53
We should add the ControlRegionViews as children o
jianli
2012/08/08 21:26:31
Done.
| |
369 [controlRegion release]; | |
370 } | |
371 } | |
372 | |
346 void ShellWindowCocoa::FlashFrame(bool flash) { | 373 void ShellWindowCocoa::FlashFrame(bool flash) { |
347 if (flash) { | 374 if (flash) { |
348 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; | 375 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
349 } else { | 376 } else { |
350 [NSApp cancelUserAttentionRequest:attention_request_id_]; | 377 [NSApp cancelUserAttentionRequest:attention_request_id_]; |
351 attention_request_id_ = 0; | 378 attention_request_id_ = 0; |
352 } | 379 } |
353 } | 380 } |
354 | 381 |
355 bool ShellWindowCocoa::IsAlwaysOnTop() const { | 382 bool ShellWindowCocoa::IsAlwaysOnTop() const { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
389 return [window_controller_ window]; | 416 return [window_controller_ window]; |
390 } | 417 } |
391 | 418 |
392 // static | 419 // static |
393 ShellWindow* ShellWindow::CreateImpl(Profile* profile, | 420 ShellWindow* ShellWindow::CreateImpl(Profile* profile, |
394 const extensions::Extension* extension, | 421 const extensions::Extension* extension, |
395 const GURL& url, | 422 const GURL& url, |
396 const ShellWindow::CreateParams& params) { | 423 const ShellWindow::CreateParams& params) { |
397 return new ShellWindowCocoa(profile, extension, url, params); | 424 return new ShellWindowCocoa(profile, extension, url, params); |
398 } | 425 } |
OLD | NEW |