| 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/app_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 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" | 11 #import "chrome/browser/ui/cocoa/chrome_event_processing_window.h" |
| 12 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" | 12 #include "chrome/browser/ui/cocoa/extensions/extension_keybinding_registry_cocoa
.h" |
| 13 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" | 13 #include "chrome/browser/ui/cocoa/extensions/extension_view_mac.h" |
| 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" | 14 #include "chrome/browser/ui/tab_contents/tab_contents.h" |
| 15 #include "chrome/common/extensions/extension.h" | 15 #include "chrome/common/extensions/extension.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 26 // Replicate specific 10.7 SDK declarations for building with prior SDKs. | 26 // Replicate specific 10.7 SDK declarations for building with prior SDKs. |
| 27 #if !defined(MAC_OS_X_VERSION_10_7) || \ | 27 #if !defined(MAC_OS_X_VERSION_10_7) || \ |
| 28 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 | 28 MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_7 |
| 29 | 29 |
| 30 @interface NSWindow (LionSDKDeclarations) | 30 @interface NSWindow (LionSDKDeclarations) |
| 31 - (void)toggleFullScreen:(id)sender; | 31 - (void)toggleFullScreen:(id)sender; |
| 32 @end | 32 @end |
| 33 | 33 |
| 34 #endif // MAC_OS_X_VERSION_10_7 | 34 #endif // MAC_OS_X_VERSION_10_7 |
| 35 | 35 |
| 36 @implementation ShellWindowController | 36 @implementation AppWindowController |
| 37 | 37 |
| 38 @synthesize shellWindow = shellWindow_; | 38 @synthesize appWindow = appWindow_; |
| 39 | 39 |
| 40 - (void)windowWillClose:(NSNotification*)notification { | 40 - (void)windowWillClose:(NSNotification*)notification { |
| 41 if (shellWindow_) | 41 if (appWindow_) |
| 42 shellWindow_->WindowWillClose(); | 42 appWindow_->WindowWillClose(); |
| 43 } | 43 } |
| 44 | 44 |
| 45 - (void)windowDidBecomeKey:(NSNotification*)notification { | 45 - (void)windowDidBecomeKey:(NSNotification*)notification { |
| 46 if (shellWindow_) | 46 if (appWindow_) |
| 47 shellWindow_->WindowDidBecomeKey(); | 47 appWindow_->WindowDidBecomeKey(); |
| 48 } | 48 } |
| 49 | 49 |
| 50 - (void)windowDidResignKey:(NSNotification*)notification { | 50 - (void)windowDidResignKey:(NSNotification*)notification { |
| 51 if (shellWindow_) | 51 if (appWindow_) |
| 52 shellWindow_->WindowDidResignKey(); | 52 appWindow_->WindowDidResignKey(); |
| 53 } | 53 } |
| 54 | 54 |
| 55 - (void)windowDidResize:(NSNotification*)notification { | 55 - (void)windowDidResize:(NSNotification*)notification { |
| 56 if (shellWindow_) | 56 if (appWindow_) |
| 57 shellWindow_->WindowDidResize(); | 57 appWindow_->WindowDidResize(); |
| 58 } | 58 } |
| 59 | 59 |
| 60 - (void)windowDidMove:(NSNotification*)notification { | 60 - (void)windowDidMove:(NSNotification*)notification { |
| 61 if (shellWindow_) | 61 if (appWindow_) |
| 62 shellWindow_->WindowDidMove(); | 62 appWindow_->WindowDidMove(); |
| 63 } | 63 } |
| 64 | 64 |
| 65 - (void)gtm_systemRequestsVisibilityForView:(NSView*)view { | 65 - (void)gtm_systemRequestsVisibilityForView:(NSView*)view { |
| 66 [[self window] makeKeyAndOrderFront:self]; | 66 [[self window] makeKeyAndOrderFront:self]; |
| 67 } | 67 } |
| 68 | 68 |
| 69 - (GTMWindowSheetController*)sheetController { | 69 - (GTMWindowSheetController*)sheetController { |
| 70 if (!sheetController_.get()) { | 70 if (!sheetController_.get()) { |
| 71 sheetController_.reset([[GTMWindowSheetController alloc] | 71 sheetController_.reset([[GTMWindowSheetController alloc] |
| 72 initWithWindow:[self window] | 72 initWithWindow:[self window] |
| 73 delegate:self]); | 73 delegate:self]); |
| 74 } | 74 } |
| 75 return sheetController_; | 75 return sheetController_; |
| 76 } | 76 } |
| 77 | 77 |
| 78 - (void)executeCommand:(int)command { | 78 - (void)executeCommand:(int)command { |
| 79 // No-op, swallow the event. | 79 // No-op, swallow the event. |
| 80 } | 80 } |
| 81 | 81 |
| 82 - (BOOL)handledByExtensionCommand:(NSEvent*)event { | 82 - (BOOL)handledByExtensionCommand:(NSEvent*)event { |
| 83 if (shellWindow_) | 83 if (appWindow_) |
| 84 return shellWindow_->HandledByExtensionCommand(event); | 84 return appWindow_->HandledByExtensionCommand(event); |
| 85 return NO; | 85 return NO; |
| 86 } | 86 } |
| 87 | 87 |
| 88 @end | 88 @end |
| 89 | 89 |
| 90 // This is really a method on NSGrayFrame, so it should only be called on the | 90 // This is really a method on NSGrayFrame, so it should only be called on the |
| 91 // view passed into -[NSWindow drawCustomFrameRect:forView:]. | 91 // view passed into -[NSWindow drawCustomFrameRect:forView:]. |
| 92 @interface NSView (PrivateMethods) | 92 @interface NSView (PrivateMethods) |
| 93 - (CGFloat)roundedCornerRadius; | 93 - (CGFloat)roundedCornerRadius; |
| 94 @end | 94 @end |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 140 } | 140 } |
| 141 | 141 |
| 142 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { | 142 - (NSRect)contentRectForFrameRect:(NSRect)frameRect { |
| 143 return frameRect; | 143 return frameRect; |
| 144 } | 144 } |
| 145 | 145 |
| 146 @end | 146 @end |
| 147 | 147 |
| 148 @interface ControlRegionView : NSView { | 148 @interface ControlRegionView : NSView { |
| 149 @private | 149 @private |
| 150 ShellWindowCocoa* shellWindow_; // Weak; owns self. | 150 AppWindowCocoa* appWindow_; // Weak; owns self. |
| 151 } | 151 } |
| 152 | 152 |
| 153 @end | 153 @end |
| 154 | 154 |
| 155 @implementation ControlRegionView | 155 @implementation ControlRegionView |
| 156 | 156 |
| 157 - (id)initWithShellWindow:(ShellWindowCocoa*)shellWindow { | 157 - (id)initWithAppWindow:(AppWindowCocoa*)appWindow { |
| 158 if ((self = [super init])) | 158 if ((self = [super init])) |
| 159 shellWindow_ = shellWindow; | 159 appWindow_ = appWindow; |
| 160 return self; | 160 return self; |
| 161 } | 161 } |
| 162 | 162 |
| 163 - (BOOL)mouseDownCanMoveWindow { | 163 - (BOOL)mouseDownCanMoveWindow { |
| 164 return NO; | 164 return NO; |
| 165 } | 165 } |
| 166 | 166 |
| 167 - (NSView*)hitTest:(NSPoint)aPoint { | 167 - (NSView*)hitTest:(NSPoint)aPoint { |
| 168 if (shellWindow_->use_system_drag() || | 168 if (appWindow_->use_system_drag() || |
| 169 !shellWindow_->IsWithinDraggableRegion(aPoint)) { | 169 !appWindow_->IsWithinDraggableRegion(aPoint)) { |
| 170 return nil; | 170 return nil; |
| 171 } | 171 } |
| 172 return self; | 172 return self; |
| 173 } | 173 } |
| 174 | 174 |
| 175 - (void)mouseDown:(NSEvent*)event { | 175 - (void)mouseDown:(NSEvent*)event { |
| 176 shellWindow_->HandleMouseEvent(event); | 176 appWindow_->HandleMouseEvent(event); |
| 177 } | 177 } |
| 178 | 178 |
| 179 - (void)mouseDragged:(NSEvent*)event { | 179 - (void)mouseDragged:(NSEvent*)event { |
| 180 shellWindow_->HandleMouseEvent(event); | 180 appWindow_->HandleMouseEvent(event); |
| 181 } | 181 } |
| 182 | 182 |
| 183 @end | 183 @end |
| 184 | 184 |
| 185 @interface NSView (WebContentsView) | 185 @interface NSView (WebContentsView) |
| 186 - (void)setMouseDownCanMoveWindow:(BOOL)can_move; | 186 - (void)setMouseDownCanMoveWindow:(BOOL)can_move; |
| 187 @end | 187 @end |
| 188 | 188 |
| 189 ShellWindowCocoa::ShellWindowCocoa(ShellWindow* shell_window, | 189 AppWindowCocoa::AppWindowCocoa(ShellWindow* shell_window, |
| 190 const ShellWindow::CreateParams& params) | 190 const ShellWindow::CreateParams& params) |
| 191 : shell_window_(shell_window), | 191 : shell_window_(shell_window), |
| 192 has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME), | 192 has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME), |
| 193 attention_request_id_(0), | 193 attention_request_id_(0), |
| 194 use_system_drag_(true) { | 194 use_system_drag_(true) { |
| 195 // Flip coordinates based on the primary screen. | 195 // Flip coordinates based on the primary screen. |
| 196 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; | 196 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; |
| 197 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), | 197 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), |
| 198 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), | 198 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), |
| 199 params.bounds.width(), params.bounds.height()); | 199 params.bounds.width(), params.bounds.height()); |
| 200 | 200 |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 CGFloat max_width = max_size_.width() ? max_size_.width() : CGFLOAT_MAX; | 236 CGFloat max_width = max_size_.width() ? max_size_.width() : CGFLOAT_MAX; |
| 237 CGFloat max_height = max_size_.height() ? max_size_.height() : CGFLOAT_MAX; | 237 CGFloat max_height = max_size_.height() ? max_size_.height() : CGFLOAT_MAX; |
| 238 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; | 238 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; |
| 239 } | 239 } |
| 240 | 240 |
| 241 if (base::mac::IsOSSnowLeopard() && | 241 if (base::mac::IsOSSnowLeopard() && |
| 242 [window respondsToSelector:@selector(setBottomCornerRounded:)]) | 242 [window respondsToSelector:@selector(setBottomCornerRounded:)]) |
| 243 [window setBottomCornerRounded:NO]; | 243 [window setBottomCornerRounded:NO]; |
| 244 | 244 |
| 245 window_controller_.reset( | 245 window_controller_.reset( |
| 246 [[ShellWindowController alloc] initWithWindow:window.release()]); | 246 [[AppWindowController alloc] initWithWindow:window.release()]); |
| 247 | 247 |
| 248 NSView* view = web_contents()->GetView()->GetNativeView(); | 248 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 249 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 249 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 250 | 250 |
| 251 // By default, the whole frameless window is not draggable. | 251 // By default, the whole frameless window is not draggable. |
| 252 if (!has_frame_) { | 252 if (!has_frame_) { |
| 253 gfx::Rect window_bounds( | 253 gfx::Rect window_bounds( |
| 254 0, 0, NSWidth(cocoa_bounds), NSHeight(cocoa_bounds)); | 254 0, 0, NSWidth(cocoa_bounds), NSHeight(cocoa_bounds)); |
| 255 system_drag_exclude_areas_.push_back(window_bounds); | 255 system_drag_exclude_areas_.push_back(window_bounds); |
| 256 } | 256 } |
| 257 | 257 |
| 258 InstallView(); | 258 InstallView(); |
| 259 | 259 |
| 260 [[window_controller_ window] setDelegate:window_controller_]; | 260 [[window_controller_ window] setDelegate:window_controller_]; |
| 261 [window_controller_ setShellWindow:this]; | 261 [window_controller_ setAppWindow:this]; |
| 262 | 262 |
| 263 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( | 263 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( |
| 264 shell_window_->profile(), | 264 shell_window_->profile(), |
| 265 window, | 265 window, |
| 266 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, | 266 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, |
| 267 shell_window)); | 267 shell_window)); |
| 268 } | 268 } |
| 269 | 269 |
| 270 void ShellWindowCocoa::InstallView() { | 270 void AppWindowCocoa::InstallView() { |
| 271 NSView* view = web_contents()->GetView()->GetNativeView(); | 271 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 272 if (has_frame_) { | 272 if (has_frame_) { |
| 273 [view setFrame:[[window() contentView] bounds]]; | 273 [view setFrame:[[window() contentView] bounds]]; |
| 274 [[window() contentView] addSubview:view]; | 274 [[window() contentView] addSubview:view]; |
| 275 if (!max_size_.IsEmpty() && min_size_ == max_size_) { | 275 if (!max_size_.IsEmpty() && min_size_ == max_size_) { |
| 276 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; | 276 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; |
| 277 [window() setShowsResizeIndicator:NO]; | 277 [window() setShowsResizeIndicator:NO]; |
| 278 } | 278 } |
| 279 } else { | 279 } else { |
| 280 // TODO(jeremya): find a cleaner way to send this information to the | 280 // TODO(jeremya): find a cleaner way to send this information to the |
| (...skipping 12 matching lines...) Expand all Loading... |
| 293 | 293 |
| 294 // Some third-party OS X utilities check the zoom button's enabled state to | 294 // Some third-party OS X utilities check the zoom button's enabled state to |
| 295 // determine whether to show custom UI on hover, so we disable it here to | 295 // determine whether to show custom UI on hover, so we disable it here to |
| 296 // prevent them from doing so in a frameless app window. | 296 // prevent them from doing so in a frameless app window. |
| 297 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; | 297 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; |
| 298 | 298 |
| 299 InstallDraggableRegionViews(); | 299 InstallDraggableRegionViews(); |
| 300 } | 300 } |
| 301 } | 301 } |
| 302 | 302 |
| 303 void ShellWindowCocoa::UninstallView() { | 303 void AppWindowCocoa::UninstallView() { |
| 304 NSView* view = web_contents()->GetView()->GetNativeView(); | 304 NSView* view = web_contents()->GetView()->GetNativeView(); |
| 305 [view removeFromSuperview]; | 305 [view removeFromSuperview]; |
| 306 } | 306 } |
| 307 | 307 |
| 308 bool ShellWindowCocoa::IsActive() const { | 308 bool AppWindowCocoa::IsActive() const { |
| 309 return [window() isKeyWindow]; | 309 return [window() isKeyWindow]; |
| 310 } | 310 } |
| 311 | 311 |
| 312 bool ShellWindowCocoa::IsMaximized() const { | 312 bool AppWindowCocoa::IsMaximized() const { |
| 313 return [window() isZoomed]; | 313 return [window() isZoomed]; |
| 314 } | 314 } |
| 315 | 315 |
| 316 bool ShellWindowCocoa::IsMinimized() const { | 316 bool AppWindowCocoa::IsMinimized() const { |
| 317 return [window() isMiniaturized]; | 317 return [window() isMiniaturized]; |
| 318 } | 318 } |
| 319 | 319 |
| 320 bool ShellWindowCocoa::IsFullscreen() const { | 320 bool AppWindowCocoa::IsFullscreen() const { |
| 321 return is_fullscreen_; | 321 return is_fullscreen_; |
| 322 } | 322 } |
| 323 | 323 |
| 324 void ShellWindowCocoa::SetFullscreen(bool fullscreen) { | 324 void AppWindowCocoa::SetFullscreen(bool fullscreen) { |
| 325 if (fullscreen == is_fullscreen_) | 325 if (fullscreen == is_fullscreen_) |
| 326 return; | 326 return; |
| 327 is_fullscreen_ = fullscreen; | 327 is_fullscreen_ = fullscreen; |
| 328 | 328 |
| 329 if (base::mac::IsOSLionOrLater()) { | 329 if (base::mac::IsOSLionOrLater()) { |
| 330 [window() toggleFullScreen:nil]; | 330 [window() toggleFullScreen:nil]; |
| 331 return; | 331 return; |
| 332 } | 332 } |
| 333 | 333 |
| 334 DCHECK(base::mac::IsOSSnowLeopard()); | 334 DCHECK(base::mac::IsOSSnowLeopard()); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 InstallView(); | 368 InstallView(); |
| 369 | 369 |
| 370 // Fade back in. | 370 // Fade back in. |
| 371 if (did_fade_out) { | 371 if (did_fade_out) { |
| 372 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, | 372 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, |
| 373 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); | 373 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); |
| 374 CGReleaseDisplayFadeReservation(token); | 374 CGReleaseDisplayFadeReservation(token); |
| 375 } | 375 } |
| 376 } | 376 } |
| 377 | 377 |
| 378 bool ShellWindowCocoa::IsFullscreenOrPending() const { | 378 bool AppWindowCocoa::IsFullscreenOrPending() const { |
| 379 return is_fullscreen_; | 379 return is_fullscreen_; |
| 380 } | 380 } |
| 381 | 381 |
| 382 gfx::NativeWindow ShellWindowCocoa::GetNativeWindow() { | 382 gfx::NativeWindow AppWindowCocoa::GetNativeWindow() { |
| 383 return window(); | 383 return window(); |
| 384 } | 384 } |
| 385 | 385 |
| 386 gfx::Rect ShellWindowCocoa::GetRestoredBounds() const { | 386 gfx::Rect AppWindowCocoa::GetRestoredBounds() const { |
| 387 // Flip coordinates based on the primary screen. | 387 // Flip coordinates based on the primary screen. |
| 388 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 388 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 389 NSRect frame = [window() frame]; | 389 NSRect frame = [window() frame]; |
| 390 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); | 390 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); |
| 391 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); | 391 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); |
| 392 return bounds; | 392 return bounds; |
| 393 } | 393 } |
| 394 | 394 |
| 395 gfx::Rect ShellWindowCocoa::GetBounds() const { | 395 gfx::Rect AppWindowCocoa::GetBounds() const { |
| 396 return GetRestoredBounds(); | 396 return GetRestoredBounds(); |
| 397 } | 397 } |
| 398 | 398 |
| 399 void ShellWindowCocoa::Show() { | 399 void AppWindowCocoa::Show() { |
| 400 [window_controller_ showWindow:nil]; | 400 [window_controller_ showWindow:nil]; |
| 401 [window() makeKeyAndOrderFront:window_controller_]; | 401 [window() makeKeyAndOrderFront:window_controller_]; |
| 402 } | 402 } |
| 403 | 403 |
| 404 void ShellWindowCocoa::ShowInactive() { | 404 void AppWindowCocoa::ShowInactive() { |
| 405 [window() orderFront:window_controller_]; | 405 [window() orderFront:window_controller_]; |
| 406 } | 406 } |
| 407 | 407 |
| 408 void ShellWindowCocoa::Hide() { | 408 void AppWindowCocoa::Hide() { |
| 409 [window() orderOut:window_controller_]; | 409 [window() orderOut:window_controller_]; |
| 410 } | 410 } |
| 411 | 411 |
| 412 void ShellWindowCocoa::Close() { | 412 void AppWindowCocoa::Close() { |
| 413 [window() performClose:nil]; | 413 [window() performClose:nil]; |
| 414 } | 414 } |
| 415 | 415 |
| 416 void ShellWindowCocoa::Activate() { | 416 void AppWindowCocoa::Activate() { |
| 417 [BrowserWindowUtils activateWindowForController:window_controller_]; | 417 [BrowserWindowUtils activateWindowForController:window_controller_]; |
| 418 } | 418 } |
| 419 | 419 |
| 420 void ShellWindowCocoa::Deactivate() { | 420 void AppWindowCocoa::Deactivate() { |
| 421 // TODO(jcivelli): http://crbug.com/51364 Implement me. | 421 // TODO(jcivelli): http://crbug.com/51364 Implement me. |
| 422 NOTIMPLEMENTED(); | 422 NOTIMPLEMENTED(); |
| 423 } | 423 } |
| 424 | 424 |
| 425 void ShellWindowCocoa::Maximize() { | 425 void AppWindowCocoa::Maximize() { |
| 426 // Zoom toggles so only call if not already maximized. | 426 // Zoom toggles so only call if not already maximized. |
| 427 if (!IsMaximized()) | 427 if (!IsMaximized()) |
| 428 [window() zoom:window_controller_]; | 428 [window() zoom:window_controller_]; |
| 429 } | 429 } |
| 430 | 430 |
| 431 void ShellWindowCocoa::Minimize() { | 431 void AppWindowCocoa::Minimize() { |
| 432 [window() miniaturize:window_controller_]; | 432 [window() miniaturize:window_controller_]; |
| 433 } | 433 } |
| 434 | 434 |
| 435 void ShellWindowCocoa::Restore() { | 435 void AppWindowCocoa::Restore() { |
| 436 if (IsMaximized()) | 436 if (IsMaximized()) |
| 437 [window() zoom:window_controller_]; // Toggles zoom mode. | 437 [window() zoom:window_controller_]; // Toggles zoom mode. |
| 438 else if (IsMinimized()) | 438 else if (IsMinimized()) |
| 439 [window() deminiaturize:window_controller_]; | 439 [window() deminiaturize:window_controller_]; |
| 440 } | 440 } |
| 441 | 441 |
| 442 void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) { | 442 void AppWindowCocoa::SetBounds(const gfx::Rect& bounds) { |
| 443 // Enforce minimum/maximum bounds. | 443 // Enforce minimum/maximum bounds. |
| 444 gfx::Rect checked_bounds = bounds; | 444 gfx::Rect checked_bounds = bounds; |
| 445 | 445 |
| 446 NSSize min_size = [window() minSize]; | 446 NSSize min_size = [window() minSize]; |
| 447 if (bounds.width() < min_size.width) | 447 if (bounds.width() < min_size.width) |
| 448 checked_bounds.set_width(min_size.width); | 448 checked_bounds.set_width(min_size.width); |
| 449 if (bounds.height() < min_size.height) | 449 if (bounds.height() < min_size.height) |
| 450 checked_bounds.set_height(min_size.height); | 450 checked_bounds.set_height(min_size.height); |
| 451 NSSize max_size = [window() maxSize]; | 451 NSSize max_size = [window() maxSize]; |
| 452 if (checked_bounds.width() > max_size.width) | 452 if (checked_bounds.width() > max_size.width) |
| 453 checked_bounds.set_width(max_size.width); | 453 checked_bounds.set_width(max_size.width); |
| 454 if (checked_bounds.height() > max_size.height) | 454 if (checked_bounds.height() > max_size.height) |
| 455 checked_bounds.set_height(max_size.height); | 455 checked_bounds.set_height(max_size.height); |
| 456 | 456 |
| 457 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, | 457 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, |
| 458 checked_bounds.width(), | 458 checked_bounds.width(), |
| 459 checked_bounds.height()); | 459 checked_bounds.height()); |
| 460 // Flip coordinates based on the primary screen. | 460 // Flip coordinates based on the primary screen. |
| 461 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; | 461 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; |
| 462 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); | 462 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); |
| 463 | 463 |
| 464 [window() setFrame:cocoa_bounds display:YES]; | 464 [window() setFrame:cocoa_bounds display:YES]; |
| 465 } | 465 } |
| 466 | 466 |
| 467 void ShellWindowCocoa::UpdateWindowIcon() { | 467 void AppWindowCocoa::UpdateWindowIcon() { |
| 468 // TODO(junmin): implement. | 468 // TODO(junmin): implement. |
| 469 } | 469 } |
| 470 | 470 |
| 471 void ShellWindowCocoa::UpdateWindowTitle() { | 471 void AppWindowCocoa::UpdateWindowTitle() { |
| 472 string16 title = shell_window_->GetTitle(); | 472 string16 title = shell_window_->GetTitle(); |
| 473 [window() setTitle:base::SysUTF16ToNSString(title)]; | 473 [window() setTitle:base::SysUTF16ToNSString(title)]; |
| 474 } | 474 } |
| 475 | 475 |
| 476 void ShellWindowCocoa::UpdateDraggableRegions( | 476 void AppWindowCocoa::UpdateDraggableRegions( |
| 477 const std::vector<extensions::DraggableRegion>& regions) { | 477 const std::vector<extensions::DraggableRegion>& regions) { |
| 478 // Draggable region is not supported for non-frameless window. | 478 // Draggable region is not supported for non-frameless window. |
| 479 if (has_frame_) | 479 if (has_frame_) |
| 480 return; | 480 return; |
| 481 | 481 |
| 482 // To use system drag, the window has to be marked as draggable with | 482 // To use system drag, the window has to be marked as draggable with |
| 483 // non-draggable areas being excluded via overlapping views. | 483 // non-draggable areas being excluded via overlapping views. |
| 484 // 1) If no draggable area is provided, the window is not draggable at all. | 484 // 1) If no draggable area is provided, the window is not draggable at all. |
| 485 // 2) If only one draggable area is given, as this is the most common | 485 // 2) If only one draggable area is given, as this is the most common |
| 486 // case, use the system drag. The non-draggable areas that are opposite of | 486 // case, use the system drag. The non-draggable areas that are opposite of |
| (...skipping 20 matching lines...) Expand all Loading... |
| 507 } | 507 } |
| 508 | 508 |
| 509 if (use_system_drag_) | 509 if (use_system_drag_) |
| 510 UpdateDraggableRegionsForSystemDrag(regions, draggable_area); | 510 UpdateDraggableRegionsForSystemDrag(regions, draggable_area); |
| 511 else | 511 else |
| 512 UpdateDraggableRegionsForCustomDrag(regions); | 512 UpdateDraggableRegionsForCustomDrag(regions); |
| 513 | 513 |
| 514 InstallDraggableRegionViews(); | 514 InstallDraggableRegionViews(); |
| 515 } | 515 } |
| 516 | 516 |
| 517 void ShellWindowCocoa::UpdateDraggableRegionsForSystemDrag( | 517 void AppWindowCocoa::UpdateDraggableRegionsForSystemDrag( |
| 518 const std::vector<extensions::DraggableRegion>& regions, | 518 const std::vector<extensions::DraggableRegion>& regions, |
| 519 const extensions::DraggableRegion* draggable_area) { | 519 const extensions::DraggableRegion* draggable_area) { |
| 520 NSView* web_view = web_contents()->GetView()->GetNativeView(); | 520 NSView* web_view = web_contents()->GetView()->GetNativeView(); |
| 521 NSInteger web_view_width = NSWidth([web_view bounds]); | 521 NSInteger web_view_width = NSWidth([web_view bounds]); |
| 522 NSInteger web_view_height = NSHeight([web_view bounds]); | 522 NSInteger web_view_height = NSHeight([web_view bounds]); |
| 523 | 523 |
| 524 system_drag_exclude_areas_.clear(); | 524 system_drag_exclude_areas_.clear(); |
| 525 | 525 |
| 526 // The whole window is not draggable if no draggable area is given. | 526 // The whole window is not draggable if no draggable area is given. |
| 527 if (!draggable_area) { | 527 if (!draggable_area) { |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 576 // Add the non-draggable area to the right of the given draggable area. | 576 // Add the non-draggable area to the right of the given draggable area. |
| 577 if (draggable_bounds.right() < web_view_width) { | 577 if (draggable_bounds.right() < web_view_width) { |
| 578 non_draggable_bounds.SetRect(draggable_bounds.right() + 1, | 578 non_draggable_bounds.SetRect(draggable_bounds.right() + 1, |
| 579 draggable_bounds.y(), | 579 draggable_bounds.y(), |
| 580 web_view_width - draggable_bounds.right(), | 580 web_view_width - draggable_bounds.right(), |
| 581 draggable_bounds.height()); | 581 draggable_bounds.height()); |
| 582 system_drag_exclude_areas_.push_back(non_draggable_bounds); | 582 system_drag_exclude_areas_.push_back(non_draggable_bounds); |
| 583 } | 583 } |
| 584 } | 584 } |
| 585 | 585 |
| 586 void ShellWindowCocoa::UpdateDraggableRegionsForCustomDrag( | 586 void AppWindowCocoa::UpdateDraggableRegionsForCustomDrag( |
| 587 const std::vector<extensions::DraggableRegion>& regions) { | 587 const std::vector<extensions::DraggableRegion>& regions) { |
| 588 // We still need one ControlRegionView to cover the whole window such that | 588 // We still need one ControlRegionView to cover the whole window such that |
| 589 // mouse events could be captured. | 589 // mouse events could be captured. |
| 590 NSView* web_view = web_contents()->GetView()->GetNativeView(); | 590 NSView* web_view = web_contents()->GetView()->GetNativeView(); |
| 591 gfx::Rect window_bounds( | 591 gfx::Rect window_bounds( |
| 592 0, 0, NSWidth([web_view bounds]), NSHeight([web_view bounds])); | 592 0, 0, NSWidth([web_view bounds]), NSHeight([web_view bounds])); |
| 593 system_drag_exclude_areas_.clear(); | 593 system_drag_exclude_areas_.clear(); |
| 594 system_drag_exclude_areas_.push_back(window_bounds); | 594 system_drag_exclude_areas_.push_back(window_bounds); |
| 595 | 595 |
| 596 // Aggregate the draggable areas and non-draggable areas such that hit test | 596 // Aggregate the draggable areas and non-draggable areas such that hit test |
| 597 // could be performed easily. | 597 // could be performed easily. |
| 598 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); | 598 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); |
| 599 } | 599 } |
| 600 | 600 |
| 601 void ShellWindowCocoa::HandleKeyboardEvent( | 601 void AppWindowCocoa::HandleKeyboardEvent( |
| 602 const content::NativeWebKeyboardEvent& event) { | 602 const content::NativeWebKeyboardEvent& event) { |
| 603 if (event.skip_in_browser || | 603 if (event.skip_in_browser || |
| 604 event.type == content::NativeWebKeyboardEvent::Char) { | 604 event.type == content::NativeWebKeyboardEvent::Char) { |
| 605 return; | 605 return; |
| 606 } | 606 } |
| 607 [window() redispatchKeyEvent:event.os_event]; | 607 [window() redispatchKeyEvent:event.os_event]; |
| 608 } | 608 } |
| 609 | 609 |
| 610 void ShellWindowCocoa::InstallDraggableRegionViews() { | 610 void AppWindowCocoa::InstallDraggableRegionViews() { |
| 611 DCHECK(!has_frame_); | 611 DCHECK(!has_frame_); |
| 612 | 612 |
| 613 // All ControlRegionViews should be added as children of the WebContentsView, | 613 // All ControlRegionViews should be added as children of the WebContentsView, |
| 614 // because WebContentsView will be removed and re-added when entering and | 614 // because WebContentsView will be removed and re-added when entering and |
| 615 // leaving fullscreen mode. | 615 // leaving fullscreen mode. |
| 616 NSView* webView = web_contents()->GetView()->GetNativeView(); | 616 NSView* webView = web_contents()->GetView()->GetNativeView(); |
| 617 NSInteger webViewHeight = NSHeight([webView bounds]); | 617 NSInteger webViewHeight = NSHeight([webView bounds]); |
| 618 | 618 |
| 619 // Remove all ControlRegionViews that are added last time. | 619 // Remove all ControlRegionViews that are added last time. |
| 620 // Note that [webView subviews] returns the view's mutable internal array and | 620 // Note that [webView subviews] returns the view's mutable internal array and |
| 621 // it should be copied to avoid mutating the original array while enumerating | 621 // it should be copied to avoid mutating the original array while enumerating |
| 622 // it. | 622 // it. |
| 623 scoped_nsobject<NSArray> subviews([[webView subviews] copy]); | 623 scoped_nsobject<NSArray> subviews([[webView subviews] copy]); |
| 624 for (NSView* subview in subviews.get()) | 624 for (NSView* subview in subviews.get()) |
| 625 if ([subview isKindOfClass:[ControlRegionView class]]) | 625 if ([subview isKindOfClass:[ControlRegionView class]]) |
| 626 [subview removeFromSuperview]; | 626 [subview removeFromSuperview]; |
| 627 | 627 |
| 628 // Create and add ControlRegionView for each region that needs to be excluded | 628 // Create and add ControlRegionView for each region that needs to be excluded |
| 629 // from the dragging. | 629 // from the dragging. |
| 630 for (std::vector<gfx::Rect>::const_iterator iter = | 630 for (std::vector<gfx::Rect>::const_iterator iter = |
| 631 system_drag_exclude_areas_.begin(); | 631 system_drag_exclude_areas_.begin(); |
| 632 iter != system_drag_exclude_areas_.end(); | 632 iter != system_drag_exclude_areas_.end(); |
| 633 ++iter) { | 633 ++iter) { |
| 634 scoped_nsobject<NSView> controlRegion( | 634 scoped_nsobject<NSView> controlRegion( |
| 635 [[ControlRegionView alloc] initWithShellWindow:this]); | 635 [[ControlRegionView alloc] initWithAppWindow:this]); |
| 636 [controlRegion setFrame:NSMakeRect(iter->x(), | 636 [controlRegion setFrame:NSMakeRect(iter->x(), |
| 637 webViewHeight - iter->bottom(), | 637 webViewHeight - iter->bottom(), |
| 638 iter->width(), | 638 iter->width(), |
| 639 iter->height())]; | 639 iter->height())]; |
| 640 [webView addSubview:controlRegion]; | 640 [webView addSubview:controlRegion]; |
| 641 } | 641 } |
| 642 } | 642 } |
| 643 | 643 |
| 644 void ShellWindowCocoa::FlashFrame(bool flash) { | 644 void AppWindowCocoa::FlashFrame(bool flash) { |
| 645 if (flash) { | 645 if (flash) { |
| 646 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; | 646 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; |
| 647 } else { | 647 } else { |
| 648 [NSApp cancelUserAttentionRequest:attention_request_id_]; | 648 [NSApp cancelUserAttentionRequest:attention_request_id_]; |
| 649 attention_request_id_ = 0; | 649 attention_request_id_ = 0; |
| 650 } | 650 } |
| 651 } | 651 } |
| 652 | 652 |
| 653 bool ShellWindowCocoa::IsAlwaysOnTop() const { | 653 bool AppWindowCocoa::IsAlwaysOnTop() const { |
| 654 return false; | 654 return false; |
| 655 } | 655 } |
| 656 | 656 |
| 657 void ShellWindowCocoa::WindowWillClose() { | 657 void AppWindowCocoa::WindowWillClose() { |
| 658 [window_controller_ setShellWindow:NULL]; | 658 [window_controller_ setAppWindow:NULL]; |
| 659 shell_window_->SaveWindowPosition(); | 659 shell_window_->SaveWindowPosition(); |
| 660 shell_window_->OnNativeClose(); | 660 shell_window_->OnNativeClose(); |
| 661 } | 661 } |
| 662 | 662 |
| 663 void ShellWindowCocoa::WindowDidBecomeKey() { | 663 void AppWindowCocoa::WindowDidBecomeKey() { |
| 664 content::RenderWidgetHostView* rwhv = | 664 content::RenderWidgetHostView* rwhv = |
| 665 web_contents()->GetRenderWidgetHostView(); | 665 web_contents()->GetRenderWidgetHostView(); |
| 666 if (rwhv) | 666 if (rwhv) |
| 667 rwhv->SetActive(true); | 667 rwhv->SetActive(true); |
| 668 } | 668 } |
| 669 | 669 |
| 670 void ShellWindowCocoa::WindowDidResignKey() { | 670 void AppWindowCocoa::WindowDidResignKey() { |
| 671 // If our app is still active and we're still the key window, ignore this | 671 // If our app is still active and we're still the key window, ignore this |
| 672 // message, since it just means that a menu extra (on the "system status bar") | 672 // message, since it just means that a menu extra (on the "system status bar") |
| 673 // was activated; we'll get another |-windowDidResignKey| if we ever really | 673 // was activated; we'll get another |-windowDidResignKey| if we ever really |
| 674 // lose key window status. | 674 // lose key window status. |
| 675 if ([NSApp isActive] && ([NSApp keyWindow] == window())) | 675 if ([NSApp isActive] && ([NSApp keyWindow] == window())) |
| 676 return; | 676 return; |
| 677 | 677 |
| 678 content::RenderWidgetHostView* rwhv = | 678 content::RenderWidgetHostView* rwhv = |
| 679 web_contents()->GetRenderWidgetHostView(); | 679 web_contents()->GetRenderWidgetHostView(); |
| 680 if (rwhv) | 680 if (rwhv) |
| 681 rwhv->SetActive(false); | 681 rwhv->SetActive(false); |
| 682 } | 682 } |
| 683 | 683 |
| 684 void ShellWindowCocoa::WindowDidResize() { | 684 void AppWindowCocoa::WindowDidResize() { |
| 685 shell_window_->SaveWindowPosition(); | 685 shell_window_->SaveWindowPosition(); |
| 686 } | 686 } |
| 687 | 687 |
| 688 void ShellWindowCocoa::WindowDidMove() { | 688 void AppWindowCocoa::WindowDidMove() { |
| 689 shell_window_->SaveWindowPosition(); | 689 shell_window_->SaveWindowPosition(); |
| 690 } | 690 } |
| 691 | 691 |
| 692 bool ShellWindowCocoa::HandledByExtensionCommand(NSEvent* event) { | 692 bool AppWindowCocoa::HandledByExtensionCommand(NSEvent* event) { |
| 693 return extension_keybinding_registry_->ProcessKeyEvent( | 693 return extension_keybinding_registry_->ProcessKeyEvent( |
| 694 content::NativeWebKeyboardEvent(event)); | 694 content::NativeWebKeyboardEvent(event)); |
| 695 } | 695 } |
| 696 | 696 |
| 697 void ShellWindowCocoa::HandleMouseEvent(NSEvent* event) { | 697 void AppWindowCocoa::HandleMouseEvent(NSEvent* event) { |
| 698 if ([event type] == NSLeftMouseDown) { | 698 if ([event type] == NSLeftMouseDown) { |
| 699 last_mouse_location_ = | 699 last_mouse_location_ = |
| 700 [window() convertBaseToScreen:[event locationInWindow]]; | 700 [window() convertBaseToScreen:[event locationInWindow]]; |
| 701 } else if ([event type] == NSLeftMouseDragged) { | 701 } else if ([event type] == NSLeftMouseDragged) { |
| 702 NSPoint current_mouse_location = | 702 NSPoint current_mouse_location = |
| 703 [window() convertBaseToScreen:[event locationInWindow]]; | 703 [window() convertBaseToScreen:[event locationInWindow]]; |
| 704 NSPoint frame_origin = [window() frame].origin; | 704 NSPoint frame_origin = [window() frame].origin; |
| 705 frame_origin.x += current_mouse_location.x - last_mouse_location_.x; | 705 frame_origin.x += current_mouse_location.x - last_mouse_location_.x; |
| 706 frame_origin.y += current_mouse_location.y - last_mouse_location_.y; | 706 frame_origin.y += current_mouse_location.y - last_mouse_location_.y; |
| 707 [window() setFrameOrigin:frame_origin]; | 707 [window() setFrameOrigin:frame_origin]; |
| 708 last_mouse_location_ = current_mouse_location; | 708 last_mouse_location_ = current_mouse_location; |
| 709 } | 709 } |
| 710 } | 710 } |
| 711 | 711 |
| 712 bool ShellWindowCocoa::IsWithinDraggableRegion(NSPoint point) const { | 712 bool AppWindowCocoa::IsWithinDraggableRegion(NSPoint point) const { |
| 713 if (!draggable_region_) | 713 if (!draggable_region_) |
| 714 return false; | 714 return false; |
| 715 NSView* webView = web_contents()->GetView()->GetNativeView(); | 715 NSView* webView = web_contents()->GetView()->GetNativeView(); |
| 716 NSInteger webViewHeight = NSHeight([webView bounds]); | 716 NSInteger webViewHeight = NSHeight([webView bounds]); |
| 717 // |draggable_region_| is stored in local platform-indepdent coordiate system | 717 // |draggable_region_| is stored in local platform-indepdent coordiate system |
| 718 // while |point| is in local Cocoa coordinate system. Do the conversion | 718 // while |point| is in local Cocoa coordinate system. Do the conversion |
| 719 // to match these two. | 719 // to match these two. |
| 720 return draggable_region_->contains(point.x, webViewHeight - point.y); | 720 return draggable_region_->contains(point.x, webViewHeight - point.y); |
| 721 } | 721 } |
| 722 | 722 |
| 723 ShellWindowCocoa::~ShellWindowCocoa() { | 723 AppWindowCocoa::~AppWindowCocoa() { |
| 724 } | 724 } |
| 725 | 725 |
| 726 ShellNSWindow* ShellWindowCocoa::window() const { | 726 ShellNSWindow* AppWindowCocoa::window() const { |
| 727 NSWindow* window = [window_controller_ window]; | 727 NSWindow* window = [window_controller_ window]; |
| 728 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); | 728 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); |
| 729 return static_cast<ShellNSWindow*>(window); | 729 return static_cast<ShellNSWindow*>(window); |
| 730 } | 730 } |
| 731 | 731 |
| 732 // static | 732 // static |
| 733 NativeShellWindow* NativeShellWindow::Create( | 733 AppBaseWindow* AppBaseWindow::Create( |
| 734 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { | 734 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { |
| 735 return new ShellWindowCocoa(shell_window, params); | 735 return new AppWindowCocoa(shell_window, params); |
| 736 } | 736 } |
| OLD | NEW |