Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.mm

Issue 11280173: Rename ShellWindow* classes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Merge fix Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/native_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
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 NativeAppWindowController
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
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 NativeAppWindowCocoa* 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:(NativeAppWindowCocoa*)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 NativeAppWindowCocoa::NativeAppWindowCocoa(
190 const ShellWindow::CreateParams& params) 190 ShellWindow* shell_window,
191 const ShellWindow::CreateParams& params)
191 : shell_window_(shell_window), 192 : shell_window_(shell_window),
192 has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME), 193 has_frame_(params.frame == ShellWindow::CreateParams::FRAME_CHROME),
193 attention_request_id_(0), 194 attention_request_id_(0),
194 use_system_drag_(true) { 195 use_system_drag_(true) {
195 // Flip coordinates based on the primary screen. 196 // Flip coordinates based on the primary screen.
196 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame]; 197 NSRect main_screen_rect = [[[NSScreen screens] objectAtIndex:0] frame];
197 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(), 198 NSRect cocoa_bounds = NSMakeRect(params.bounds.x(),
198 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(), 199 NSHeight(main_screen_rect) - params.bounds.y() - params.bounds.height(),
199 params.bounds.width(), params.bounds.height()); 200 params.bounds.width(), params.bounds.height());
200 201
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 CGFloat max_width = max_size_.width() ? max_size_.width() : CGFLOAT_MAX; 237 CGFloat max_width = max_size_.width() ? max_size_.width() : CGFLOAT_MAX;
237 CGFloat max_height = max_size_.height() ? max_size_.height() : CGFLOAT_MAX; 238 CGFloat max_height = max_size_.height() ? max_size_.height() : CGFLOAT_MAX;
238 [window setContentMaxSize:NSMakeSize(max_width, max_height)]; 239 [window setContentMaxSize:NSMakeSize(max_width, max_height)];
239 } 240 }
240 241
241 if (base::mac::IsOSSnowLeopard() && 242 if (base::mac::IsOSSnowLeopard() &&
242 [window respondsToSelector:@selector(setBottomCornerRounded:)]) 243 [window respondsToSelector:@selector(setBottomCornerRounded:)])
243 [window setBottomCornerRounded:NO]; 244 [window setBottomCornerRounded:NO];
244 245
245 window_controller_.reset( 246 window_controller_.reset(
246 [[ShellWindowController alloc] initWithWindow:window.release()]); 247 [[NativeAppWindowController alloc] initWithWindow:window.release()]);
247 248
248 NSView* view = web_contents()->GetView()->GetNativeView(); 249 NSView* view = web_contents()->GetView()->GetNativeView();
249 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 250 [view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
250 251
251 // By default, the whole frameless window is not draggable. 252 // By default, the whole frameless window is not draggable.
252 if (!has_frame_) { 253 if (!has_frame_) {
253 gfx::Rect window_bounds( 254 gfx::Rect window_bounds(
254 0, 0, NSWidth(cocoa_bounds), NSHeight(cocoa_bounds)); 255 0, 0, NSWidth(cocoa_bounds), NSHeight(cocoa_bounds));
255 system_drag_exclude_areas_.push_back(window_bounds); 256 system_drag_exclude_areas_.push_back(window_bounds);
256 } 257 }
257 258
258 InstallView(); 259 InstallView();
259 260
260 [[window_controller_ window] setDelegate:window_controller_]; 261 [[window_controller_ window] setDelegate:window_controller_];
261 [window_controller_ setShellWindow:this]; 262 [window_controller_ setAppWindow:this];
262 263
263 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa( 264 extension_keybinding_registry_.reset(new ExtensionKeybindingRegistryCocoa(
264 shell_window_->profile(), 265 shell_window_->profile(),
265 window, 266 window,
266 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY, 267 extensions::ExtensionKeybindingRegistry::PLATFORM_APPS_ONLY,
267 shell_window)); 268 shell_window));
268 } 269 }
269 270
270 void ShellWindowCocoa::InstallView() { 271 void NativeAppWindowCocoa::InstallView() {
271 NSView* view = web_contents()->GetView()->GetNativeView(); 272 NSView* view = web_contents()->GetView()->GetNativeView();
272 if (has_frame_) { 273 if (has_frame_) {
273 [view setFrame:[[window() contentView] bounds]]; 274 [view setFrame:[[window() contentView] bounds]];
274 [[window() contentView] addSubview:view]; 275 [[window() contentView] addSubview:view];
275 if (!max_size_.IsEmpty() && min_size_ == max_size_) { 276 if (!max_size_.IsEmpty() && min_size_ == max_size_) {
276 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; 277 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO];
277 [window() setShowsResizeIndicator:NO]; 278 [window() setShowsResizeIndicator:NO];
278 } 279 }
279 } else { 280 } else {
280 // TODO(jeremya): find a cleaner way to send this information to the 281 // TODO(jeremya): find a cleaner way to send this information to the
(...skipping 12 matching lines...) Expand all
293 294
294 // Some third-party OS X utilities check the zoom button's enabled state to 295 // 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 296 // 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. 297 // prevent them from doing so in a frameless app window.
297 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO]; 298 [[window() standardWindowButton:NSWindowZoomButton] setEnabled:NO];
298 299
299 InstallDraggableRegionViews(); 300 InstallDraggableRegionViews();
300 } 301 }
301 } 302 }
302 303
303 void ShellWindowCocoa::UninstallView() { 304 void NativeAppWindowCocoa::UninstallView() {
304 NSView* view = web_contents()->GetView()->GetNativeView(); 305 NSView* view = web_contents()->GetView()->GetNativeView();
305 [view removeFromSuperview]; 306 [view removeFromSuperview];
306 } 307 }
307 308
308 bool ShellWindowCocoa::IsActive() const { 309 bool NativeAppWindowCocoa::IsActive() const {
309 return [window() isKeyWindow]; 310 return [window() isKeyWindow];
310 } 311 }
311 312
312 bool ShellWindowCocoa::IsMaximized() const { 313 bool NativeAppWindowCocoa::IsMaximized() const {
313 return [window() isZoomed]; 314 return [window() isZoomed];
314 } 315 }
315 316
316 bool ShellWindowCocoa::IsMinimized() const { 317 bool NativeAppWindowCocoa::IsMinimized() const {
317 return [window() isMiniaturized]; 318 return [window() isMiniaturized];
318 } 319 }
319 320
320 bool ShellWindowCocoa::IsFullscreen() const { 321 bool NativeAppWindowCocoa::IsFullscreen() const {
321 return is_fullscreen_; 322 return is_fullscreen_;
322 } 323 }
323 324
324 void ShellWindowCocoa::SetFullscreen(bool fullscreen) { 325 void NativeAppWindowCocoa::SetFullscreen(bool fullscreen) {
325 if (fullscreen == is_fullscreen_) 326 if (fullscreen == is_fullscreen_)
326 return; 327 return;
327 is_fullscreen_ = fullscreen; 328 is_fullscreen_ = fullscreen;
328 329
329 if (base::mac::IsOSLionOrLater()) { 330 if (base::mac::IsOSLionOrLater()) {
330 [window() toggleFullScreen:nil]; 331 [window() toggleFullScreen:nil];
331 return; 332 return;
332 } 333 }
333 334
334 DCHECK(base::mac::IsOSSnowLeopard()); 335 DCHECK(base::mac::IsOSSnowLeopard());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
368 InstallView(); 369 InstallView();
369 370
370 // Fade back in. 371 // Fade back in.
371 if (did_fade_out) { 372 if (did_fade_out) {
372 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor, 373 CGDisplayFade(token, kFadeDurationSeconds / 2, kCGDisplayBlendSolidColor,
373 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false); 374 kCGDisplayBlendNormal, 0.0, 0.0, 0.0, /*synchronous=*/false);
374 CGReleaseDisplayFadeReservation(token); 375 CGReleaseDisplayFadeReservation(token);
375 } 376 }
376 } 377 }
377 378
378 bool ShellWindowCocoa::IsFullscreenOrPending() const { 379 bool NativeAppWindowCocoa::IsFullscreenOrPending() const {
379 return is_fullscreen_; 380 return is_fullscreen_;
380 } 381 }
381 382
382 gfx::NativeWindow ShellWindowCocoa::GetNativeWindow() { 383 gfx::NativeWindow NativeAppWindowCocoa::GetNativeWindow() {
383 return window(); 384 return window();
384 } 385 }
385 386
386 gfx::Rect ShellWindowCocoa::GetRestoredBounds() const { 387 gfx::Rect NativeAppWindowCocoa::GetRestoredBounds() const {
387 // Flip coordinates based on the primary screen. 388 // Flip coordinates based on the primary screen.
388 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 389 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
389 NSRect frame = [window() frame]; 390 NSRect frame = [window() frame];
390 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame)); 391 gfx::Rect bounds(frame.origin.x, 0, NSWidth(frame), NSHeight(frame));
391 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame)); 392 bounds.set_y(NSHeight([screen frame]) - NSMaxY(frame));
392 return bounds; 393 return bounds;
393 } 394 }
394 395
395 gfx::Rect ShellWindowCocoa::GetBounds() const { 396 gfx::Rect NativeAppWindowCocoa::GetBounds() const {
396 return GetRestoredBounds(); 397 return GetRestoredBounds();
397 } 398 }
398 399
399 void ShellWindowCocoa::Show() { 400 void NativeAppWindowCocoa::Show() {
400 [window_controller_ showWindow:nil]; 401 [window_controller_ showWindow:nil];
401 [window() makeKeyAndOrderFront:window_controller_]; 402 [window() makeKeyAndOrderFront:window_controller_];
402 } 403 }
403 404
404 void ShellWindowCocoa::ShowInactive() { 405 void NativeAppWindowCocoa::ShowInactive() {
405 [window() orderFront:window_controller_]; 406 [window() orderFront:window_controller_];
406 } 407 }
407 408
408 void ShellWindowCocoa::Hide() { 409 void NativeAppWindowCocoa::Hide() {
409 [window() orderOut:window_controller_]; 410 [window() orderOut:window_controller_];
410 } 411 }
411 412
412 void ShellWindowCocoa::Close() { 413 void NativeAppWindowCocoa::Close() {
413 [window() performClose:nil]; 414 [window() performClose:nil];
414 } 415 }
415 416
416 void ShellWindowCocoa::Activate() { 417 void NativeAppWindowCocoa::Activate() {
417 [BrowserWindowUtils activateWindowForController:window_controller_]; 418 [BrowserWindowUtils activateWindowForController:window_controller_];
418 } 419 }
419 420
420 void ShellWindowCocoa::Deactivate() { 421 void NativeAppWindowCocoa::Deactivate() {
421 // TODO(jcivelli): http://crbug.com/51364 Implement me. 422 // TODO(jcivelli): http://crbug.com/51364 Implement me.
422 NOTIMPLEMENTED(); 423 NOTIMPLEMENTED();
423 } 424 }
424 425
425 void ShellWindowCocoa::Maximize() { 426 void NativeAppWindowCocoa::Maximize() {
426 // Zoom toggles so only call if not already maximized. 427 // Zoom toggles so only call if not already maximized.
427 if (!IsMaximized()) 428 if (!IsMaximized())
428 [window() zoom:window_controller_]; 429 [window() zoom:window_controller_];
429 } 430 }
430 431
431 void ShellWindowCocoa::Minimize() { 432 void NativeAppWindowCocoa::Minimize() {
432 [window() miniaturize:window_controller_]; 433 [window() miniaturize:window_controller_];
433 } 434 }
434 435
435 void ShellWindowCocoa::Restore() { 436 void NativeAppWindowCocoa::Restore() {
436 if (IsMaximized()) 437 if (IsMaximized())
437 [window() zoom:window_controller_]; // Toggles zoom mode. 438 [window() zoom:window_controller_]; // Toggles zoom mode.
438 else if (IsMinimized()) 439 else if (IsMinimized())
439 [window() deminiaturize:window_controller_]; 440 [window() deminiaturize:window_controller_];
440 } 441 }
441 442
442 void ShellWindowCocoa::SetBounds(const gfx::Rect& bounds) { 443 void NativeAppWindowCocoa::SetBounds(const gfx::Rect& bounds) {
443 // Enforce minimum/maximum bounds. 444 // Enforce minimum/maximum bounds.
444 gfx::Rect checked_bounds = bounds; 445 gfx::Rect checked_bounds = bounds;
445 446
446 NSSize min_size = [window() minSize]; 447 NSSize min_size = [window() minSize];
447 if (bounds.width() < min_size.width) 448 if (bounds.width() < min_size.width)
448 checked_bounds.set_width(min_size.width); 449 checked_bounds.set_width(min_size.width);
449 if (bounds.height() < min_size.height) 450 if (bounds.height() < min_size.height)
450 checked_bounds.set_height(min_size.height); 451 checked_bounds.set_height(min_size.height);
451 NSSize max_size = [window() maxSize]; 452 NSSize max_size = [window() maxSize];
452 if (checked_bounds.width() > max_size.width) 453 if (checked_bounds.width() > max_size.width)
453 checked_bounds.set_width(max_size.width); 454 checked_bounds.set_width(max_size.width);
454 if (checked_bounds.height() > max_size.height) 455 if (checked_bounds.height() > max_size.height)
455 checked_bounds.set_height(max_size.height); 456 checked_bounds.set_height(max_size.height);
456 457
457 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0, 458 NSRect cocoa_bounds = NSMakeRect(checked_bounds.x(), 0,
458 checked_bounds.width(), 459 checked_bounds.width(),
459 checked_bounds.height()); 460 checked_bounds.height());
460 // Flip coordinates based on the primary screen. 461 // Flip coordinates based on the primary screen.
461 NSScreen* screen = [[NSScreen screens] objectAtIndex:0]; 462 NSScreen* screen = [[NSScreen screens] objectAtIndex:0];
462 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom(); 463 cocoa_bounds.origin.y = NSHeight([screen frame]) - checked_bounds.bottom();
463 464
464 [window() setFrame:cocoa_bounds display:YES]; 465 [window() setFrame:cocoa_bounds display:YES];
465 } 466 }
466 467
467 void ShellWindowCocoa::UpdateWindowIcon() { 468 void NativeAppWindowCocoa::UpdateWindowIcon() {
468 // TODO(junmin): implement. 469 // TODO(junmin): implement.
469 } 470 }
470 471
471 void ShellWindowCocoa::UpdateWindowTitle() { 472 void NativeAppWindowCocoa::UpdateWindowTitle() {
472 string16 title = shell_window_->GetTitle(); 473 string16 title = shell_window_->GetTitle();
473 [window() setTitle:base::SysUTF16ToNSString(title)]; 474 [window() setTitle:base::SysUTF16ToNSString(title)];
474 } 475 }
475 476
476 void ShellWindowCocoa::UpdateDraggableRegions( 477 void NativeAppWindowCocoa::UpdateDraggableRegions(
477 const std::vector<extensions::DraggableRegion>& regions) { 478 const std::vector<extensions::DraggableRegion>& regions) {
478 // Draggable region is not supported for non-frameless window. 479 // Draggable region is not supported for non-frameless window.
479 if (has_frame_) 480 if (has_frame_)
480 return; 481 return;
481 482
482 // To use system drag, the window has to be marked as draggable with 483 // To use system drag, the window has to be marked as draggable with
483 // non-draggable areas being excluded via overlapping views. 484 // non-draggable areas being excluded via overlapping views.
484 // 1) If no draggable area is provided, the window is not draggable at all. 485 // 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 486 // 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 487 // case, use the system drag. The non-draggable areas that are opposite of
(...skipping 20 matching lines...) Expand all
507 } 508 }
508 509
509 if (use_system_drag_) 510 if (use_system_drag_)
510 UpdateDraggableRegionsForSystemDrag(regions, draggable_area); 511 UpdateDraggableRegionsForSystemDrag(regions, draggable_area);
511 else 512 else
512 UpdateDraggableRegionsForCustomDrag(regions); 513 UpdateDraggableRegionsForCustomDrag(regions);
513 514
514 InstallDraggableRegionViews(); 515 InstallDraggableRegionViews();
515 } 516 }
516 517
517 void ShellWindowCocoa::UpdateDraggableRegionsForSystemDrag( 518 void NativeAppWindowCocoa::UpdateDraggableRegionsForSystemDrag(
518 const std::vector<extensions::DraggableRegion>& regions, 519 const std::vector<extensions::DraggableRegion>& regions,
519 const extensions::DraggableRegion* draggable_area) { 520 const extensions::DraggableRegion* draggable_area) {
520 NSView* web_view = web_contents()->GetView()->GetNativeView(); 521 NSView* web_view = web_contents()->GetView()->GetNativeView();
521 NSInteger web_view_width = NSWidth([web_view bounds]); 522 NSInteger web_view_width = NSWidth([web_view bounds]);
522 NSInteger web_view_height = NSHeight([web_view bounds]); 523 NSInteger web_view_height = NSHeight([web_view bounds]);
523 524
524 system_drag_exclude_areas_.clear(); 525 system_drag_exclude_areas_.clear();
525 526
526 // The whole window is not draggable if no draggable area is given. 527 // The whole window is not draggable if no draggable area is given.
527 if (!draggable_area) { 528 if (!draggable_area) {
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 // Add the non-draggable area to the right of the given draggable area. 577 // Add the non-draggable area to the right of the given draggable area.
577 if (draggable_bounds.right() < web_view_width) { 578 if (draggable_bounds.right() < web_view_width) {
578 non_draggable_bounds.SetRect(draggable_bounds.right() + 1, 579 non_draggable_bounds.SetRect(draggable_bounds.right() + 1,
579 draggable_bounds.y(), 580 draggable_bounds.y(),
580 web_view_width - draggable_bounds.right(), 581 web_view_width - draggable_bounds.right(),
581 draggable_bounds.height()); 582 draggable_bounds.height());
582 system_drag_exclude_areas_.push_back(non_draggable_bounds); 583 system_drag_exclude_areas_.push_back(non_draggable_bounds);
583 } 584 }
584 } 585 }
585 586
586 void ShellWindowCocoa::UpdateDraggableRegionsForCustomDrag( 587 void NativeAppWindowCocoa::UpdateDraggableRegionsForCustomDrag(
587 const std::vector<extensions::DraggableRegion>& regions) { 588 const std::vector<extensions::DraggableRegion>& regions) {
588 // We still need one ControlRegionView to cover the whole window such that 589 // We still need one ControlRegionView to cover the whole window such that
589 // mouse events could be captured. 590 // mouse events could be captured.
590 NSView* web_view = web_contents()->GetView()->GetNativeView(); 591 NSView* web_view = web_contents()->GetView()->GetNativeView();
591 gfx::Rect window_bounds( 592 gfx::Rect window_bounds(
592 0, 0, NSWidth([web_view bounds]), NSHeight([web_view bounds])); 593 0, 0, NSWidth([web_view bounds]), NSHeight([web_view bounds]));
593 system_drag_exclude_areas_.clear(); 594 system_drag_exclude_areas_.clear();
594 system_drag_exclude_areas_.push_back(window_bounds); 595 system_drag_exclude_areas_.push_back(window_bounds);
595 596
596 // Aggregate the draggable areas and non-draggable areas such that hit test 597 // Aggregate the draggable areas and non-draggable areas such that hit test
597 // could be performed easily. 598 // could be performed easily.
598 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions)); 599 draggable_region_.reset(ShellWindow::RawDraggableRegionsToSkRegion(regions));
599 } 600 }
600 601
601 void ShellWindowCocoa::HandleKeyboardEvent( 602 void NativeAppWindowCocoa::HandleKeyboardEvent(
602 const content::NativeWebKeyboardEvent& event) { 603 const content::NativeWebKeyboardEvent& event) {
603 if (event.skip_in_browser || 604 if (event.skip_in_browser ||
604 event.type == content::NativeWebKeyboardEvent::Char) { 605 event.type == content::NativeWebKeyboardEvent::Char) {
605 return; 606 return;
606 } 607 }
607 [window() redispatchKeyEvent:event.os_event]; 608 [window() redispatchKeyEvent:event.os_event];
608 } 609 }
609 610
610 void ShellWindowCocoa::InstallDraggableRegionViews() { 611 void NativeAppWindowCocoa::InstallDraggableRegionViews() {
611 DCHECK(!has_frame_); 612 DCHECK(!has_frame_);
612 613
613 // All ControlRegionViews should be added as children of the WebContentsView, 614 // All ControlRegionViews should be added as children of the WebContentsView,
614 // because WebContentsView will be removed and re-added when entering and 615 // because WebContentsView will be removed and re-added when entering and
615 // leaving fullscreen mode. 616 // leaving fullscreen mode.
616 NSView* webView = web_contents()->GetView()->GetNativeView(); 617 NSView* webView = web_contents()->GetView()->GetNativeView();
617 NSInteger webViewHeight = NSHeight([webView bounds]); 618 NSInteger webViewHeight = NSHeight([webView bounds]);
618 619
619 // Remove all ControlRegionViews that are added last time. 620 // Remove all ControlRegionViews that are added last time.
620 // Note that [webView subviews] returns the view's mutable internal array and 621 // 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 622 // it should be copied to avoid mutating the original array while enumerating
622 // it. 623 // it.
623 scoped_nsobject<NSArray> subviews([[webView subviews] copy]); 624 scoped_nsobject<NSArray> subviews([[webView subviews] copy]);
624 for (NSView* subview in subviews.get()) 625 for (NSView* subview in subviews.get())
625 if ([subview isKindOfClass:[ControlRegionView class]]) 626 if ([subview isKindOfClass:[ControlRegionView class]])
626 [subview removeFromSuperview]; 627 [subview removeFromSuperview];
627 628
628 // Create and add ControlRegionView for each region that needs to be excluded 629 // Create and add ControlRegionView for each region that needs to be excluded
629 // from the dragging. 630 // from the dragging.
630 for (std::vector<gfx::Rect>::const_iterator iter = 631 for (std::vector<gfx::Rect>::const_iterator iter =
631 system_drag_exclude_areas_.begin(); 632 system_drag_exclude_areas_.begin();
632 iter != system_drag_exclude_areas_.end(); 633 iter != system_drag_exclude_areas_.end();
633 ++iter) { 634 ++iter) {
634 scoped_nsobject<NSView> controlRegion( 635 scoped_nsobject<NSView> controlRegion(
635 [[ControlRegionView alloc] initWithShellWindow:this]); 636 [[ControlRegionView alloc] initWithAppWindow:this]);
636 [controlRegion setFrame:NSMakeRect(iter->x(), 637 [controlRegion setFrame:NSMakeRect(iter->x(),
637 webViewHeight - iter->bottom(), 638 webViewHeight - iter->bottom(),
638 iter->width(), 639 iter->width(),
639 iter->height())]; 640 iter->height())];
640 [webView addSubview:controlRegion]; 641 [webView addSubview:controlRegion];
641 } 642 }
642 } 643 }
643 644
644 void ShellWindowCocoa::FlashFrame(bool flash) { 645 void NativeAppWindowCocoa::FlashFrame(bool flash) {
645 if (flash) { 646 if (flash) {
646 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest]; 647 attention_request_id_ = [NSApp requestUserAttention:NSInformationalRequest];
647 } else { 648 } else {
648 [NSApp cancelUserAttentionRequest:attention_request_id_]; 649 [NSApp cancelUserAttentionRequest:attention_request_id_];
649 attention_request_id_ = 0; 650 attention_request_id_ = 0;
650 } 651 }
651 } 652 }
652 653
653 bool ShellWindowCocoa::IsAlwaysOnTop() const { 654 bool NativeAppWindowCocoa::IsAlwaysOnTop() const {
654 return false; 655 return false;
655 } 656 }
656 657
657 void ShellWindowCocoa::WindowWillClose() { 658 void NativeAppWindowCocoa::WindowWillClose() {
658 [window_controller_ setShellWindow:NULL]; 659 [window_controller_ setAppWindow:NULL];
659 shell_window_->OnNativeWindowChanged(); 660 shell_window_->OnNativeWindowChanged();
660 shell_window_->OnNativeClose(); 661 shell_window_->OnNativeClose();
661 } 662 }
662 663
663 void ShellWindowCocoa::WindowDidBecomeKey() { 664 void NativeAppWindowCocoa::WindowDidBecomeKey() {
664 content::RenderWidgetHostView* rwhv = 665 content::RenderWidgetHostView* rwhv =
665 web_contents()->GetRenderWidgetHostView(); 666 web_contents()->GetRenderWidgetHostView();
666 if (rwhv) 667 if (rwhv)
667 rwhv->SetActive(true); 668 rwhv->SetActive(true);
668 } 669 }
669 670
670 void ShellWindowCocoa::WindowDidResignKey() { 671 void NativeAppWindowCocoa::WindowDidResignKey() {
671 // If our app is still active and we're still the key window, ignore this 672 // 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") 673 // 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 674 // was activated; we'll get another |-windowDidResignKey| if we ever really
674 // lose key window status. 675 // lose key window status.
675 if ([NSApp isActive] && ([NSApp keyWindow] == window())) 676 if ([NSApp isActive] && ([NSApp keyWindow] == window()))
676 return; 677 return;
677 678
678 content::RenderWidgetHostView* rwhv = 679 content::RenderWidgetHostView* rwhv =
679 web_contents()->GetRenderWidgetHostView(); 680 web_contents()->GetRenderWidgetHostView();
680 if (rwhv) 681 if (rwhv)
681 rwhv->SetActive(false); 682 rwhv->SetActive(false);
682 } 683 }
683 684
684 void ShellWindowCocoa::WindowDidResize() { 685 void NativeAppWindowCocoa::WindowDidResize() {
685 shell_window_->OnNativeWindowChanged(); 686 shell_window_->OnNativeWindowChanged();
686 } 687 }
687 688
688 void ShellWindowCocoa::WindowDidMove() { 689 void NativeAppWindowCocoa::WindowDidMove() {
689 shell_window_->OnNativeWindowChanged(); 690 shell_window_->OnNativeWindowChanged();
690 } 691 }
691 692
692 bool ShellWindowCocoa::HandledByExtensionCommand(NSEvent* event) { 693 bool NativeAppWindowCocoa::HandledByExtensionCommand(NSEvent* event) {
693 return extension_keybinding_registry_->ProcessKeyEvent( 694 return extension_keybinding_registry_->ProcessKeyEvent(
694 content::NativeWebKeyboardEvent(event)); 695 content::NativeWebKeyboardEvent(event));
695 } 696 }
696 697
697 void ShellWindowCocoa::HandleMouseEvent(NSEvent* event) { 698 void NativeAppWindowCocoa::HandleMouseEvent(NSEvent* event) {
698 if ([event type] == NSLeftMouseDown) { 699 if ([event type] == NSLeftMouseDown) {
699 last_mouse_location_ = 700 last_mouse_location_ =
700 [window() convertBaseToScreen:[event locationInWindow]]; 701 [window() convertBaseToScreen:[event locationInWindow]];
701 } else if ([event type] == NSLeftMouseDragged) { 702 } else if ([event type] == NSLeftMouseDragged) {
702 NSPoint current_mouse_location = 703 NSPoint current_mouse_location =
703 [window() convertBaseToScreen:[event locationInWindow]]; 704 [window() convertBaseToScreen:[event locationInWindow]];
704 NSPoint frame_origin = [window() frame].origin; 705 NSPoint frame_origin = [window() frame].origin;
705 frame_origin.x += current_mouse_location.x - last_mouse_location_.x; 706 frame_origin.x += current_mouse_location.x - last_mouse_location_.x;
706 frame_origin.y += current_mouse_location.y - last_mouse_location_.y; 707 frame_origin.y += current_mouse_location.y - last_mouse_location_.y;
707 [window() setFrameOrigin:frame_origin]; 708 [window() setFrameOrigin:frame_origin];
708 last_mouse_location_ = current_mouse_location; 709 last_mouse_location_ = current_mouse_location;
709 } 710 }
710 } 711 }
711 712
712 bool ShellWindowCocoa::IsWithinDraggableRegion(NSPoint point) const { 713 bool NativeAppWindowCocoa::IsWithinDraggableRegion(NSPoint point) const {
713 if (!draggable_region_) 714 if (!draggable_region_)
714 return false; 715 return false;
715 NSView* webView = web_contents()->GetView()->GetNativeView(); 716 NSView* webView = web_contents()->GetView()->GetNativeView();
716 NSInteger webViewHeight = NSHeight([webView bounds]); 717 NSInteger webViewHeight = NSHeight([webView bounds]);
717 // |draggable_region_| is stored in local platform-indepdent coordiate system 718 // |draggable_region_| is stored in local platform-indepdent coordiate system
718 // while |point| is in local Cocoa coordinate system. Do the conversion 719 // while |point| is in local Cocoa coordinate system. Do the conversion
719 // to match these two. 720 // to match these two.
720 return draggable_region_->contains(point.x, webViewHeight - point.y); 721 return draggable_region_->contains(point.x, webViewHeight - point.y);
721 } 722 }
722 723
723 ShellWindowCocoa::~ShellWindowCocoa() { 724 NativeAppWindowCocoa::~NativeAppWindowCocoa() {
724 } 725 }
725 726
726 ShellNSWindow* ShellWindowCocoa::window() const { 727 ShellNSWindow* NativeAppWindowCocoa::window() const {
727 NSWindow* window = [window_controller_ window]; 728 NSWindow* window = [window_controller_ window];
728 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]); 729 CHECK(!window || [window isKindOfClass:[ShellNSWindow class]]);
729 return static_cast<ShellNSWindow*>(window); 730 return static_cast<ShellNSWindow*>(window);
730 } 731 }
731 732
732 // static 733 // static
733 NativeShellWindow* NativeShellWindow::Create( 734 NativeAppWindow* NativeAppWindow::Create(
734 ShellWindow* shell_window, const ShellWindow::CreateParams& params) { 735 ShellWindow* shell_window,
735 return new ShellWindowCocoa(shell_window, params); 736 const ShellWindow::CreateParams& params) {
737 return new NativeAppWindowCocoa(shell_window, params);
736 } 738 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/cocoa/extensions/native_app_window_cocoa.h ('k') | chrome/browser/ui/cocoa/extensions/shell_window_cocoa.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698