| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" |
| 6 | 6 |
| 7 #include "base/histogram.h" | 7 #include "base/histogram.h" |
| 8 #include "base/sys_string_conversions.h" | 8 #include "base/sys_string_conversions.h" |
| 9 #include "chrome/browser/browser_trial.h" | 9 #include "chrome/browser/browser_trial.h" |
| 10 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" | 10 #import "chrome/browser/cocoa/rwhvm_editcommand_helper.h" |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 249 // TODO(darin): keep this around, and draw sad-tab into it. | 249 // TODO(darin): keep this around, and draw sad-tab into it. |
| 250 UpdateCursorIfOverSelf(); | 250 UpdateCursorIfOverSelf(); |
| 251 Destroy(); | 251 Destroy(); |
| 252 } | 252 } |
| 253 | 253 |
| 254 void RenderWidgetHostViewMac::Destroy() { | 254 void RenderWidgetHostViewMac::Destroy() { |
| 255 // We've been told to destroy. | 255 // We've been told to destroy. |
| 256 [cocoa_view_ retain]; | 256 [cocoa_view_ retain]; |
| 257 [cocoa_view_ removeFromSuperview]; | 257 [cocoa_view_ removeFromSuperview]; |
| 258 [cocoa_view_ autorelease]; | 258 [cocoa_view_ autorelease]; |
| 259 |
| 260 // We get this call just before |render_widget_host_| deletes |
| 261 // itself. But we are owned by |cocoa_view_|, which may be retained |
| 262 // by some other code. Examples are TabContentsViewMac's |
| 263 // |latent_focus_view_| and TabWindowController's |
| 264 // |cachedContentView_|. |
| 265 render_widget_host_ = NULL; |
| 259 } | 266 } |
| 260 | 267 |
| 261 // Called from the renderer to tell us what the tooltip text should be. It | 268 // Called from the renderer to tell us what the tooltip text should be. It |
| 262 // calls us frequently so we need to cache the value to prevent doing a lot | 269 // calls us frequently so we need to cache the value to prevent doing a lot |
| 263 // of repeat work. We cannot simply use [-NSView setToolTip:] because NSView | 270 // of repeat work. We cannot simply use [-NSView setToolTip:] because NSView |
| 264 // can't handle the case where the tooltip text changes while the mouse is | 271 // can't handle the case where the tooltip text changes while the mouse is |
| 265 // still inside the view. Since the page elements that get tooltips are all | 272 // still inside the view. Since the page elements that get tooltips are all |
| 266 // contained within this view (and are unknown to the NSView system), we | 273 // contained within this view (and are unknown to the NSView system), we |
| 267 // are forced to implement our own tooltips with child windows. | 274 // are forced to implement our own tooltips with child windows. |
| 268 // TODO(pinkerton): Do we want these tooltips to time out after a certain time? | 275 // TODO(pinkerton): Do we want these tooltips to time out after a certain time? |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 388 canBeKeyView_ = can; | 395 canBeKeyView_ = can; |
| 389 } | 396 } |
| 390 | 397 |
| 391 - (void)setCloseOnDeactivate:(BOOL)b { | 398 - (void)setCloseOnDeactivate:(BOOL)b { |
| 392 closeOnDeactivate_ = b; | 399 closeOnDeactivate_ = b; |
| 393 } | 400 } |
| 394 | 401 |
| 395 - (void)mouseEvent:(NSEvent *)theEvent { | 402 - (void)mouseEvent:(NSEvent *)theEvent { |
| 396 const WebMouseEvent& event = | 403 const WebMouseEvent& event = |
| 397 WebInputEventFactory::mouseEvent(theEvent, self); | 404 WebInputEventFactory::mouseEvent(theEvent, self); |
| 398 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); | 405 if (renderWidgetHostView_->render_widget_host_) |
| 406 renderWidgetHostView_->render_widget_host_->ForwardMouseEvent(event); |
| 399 } | 407 } |
| 400 | 408 |
| 401 - (void)keyEvent:(NSEvent *)theEvent { | 409 - (void)keyEvent:(NSEvent *)theEvent { |
| 402 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and | 410 // TODO(avi): Possibly kill self? See RenderWidgetHostViewWin::OnKeyEvent and |
| 403 // http://b/issue?id=1192881 . | 411 // http://b/issue?id=1192881 . |
| 404 | 412 |
| 405 NativeWebKeyboardEvent event(theEvent); | 413 NativeWebKeyboardEvent event(theEvent); |
| 406 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); | 414 if (renderWidgetHostView_->render_widget_host_) |
| 415 renderWidgetHostView_->render_widget_host_->ForwardKeyboardEvent(event); |
| 407 } | 416 } |
| 408 | 417 |
| 409 - (void)scrollWheel:(NSEvent *)theEvent { | 418 - (void)scrollWheel:(NSEvent *)theEvent { |
| 410 const WebMouseWheelEvent& event = | 419 const WebMouseWheelEvent& event = |
| 411 WebInputEventFactory::mouseWheelEvent(theEvent, self); | 420 WebInputEventFactory::mouseWheelEvent(theEvent, self); |
| 412 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(event); | 421 if (renderWidgetHostView_->render_widget_host_) |
| 422 renderWidgetHostView_->render_widget_host_->ForwardWheelEvent(event); |
| 413 } | 423 } |
| 414 | 424 |
| 415 - (void)setFrame:(NSRect)frameRect { | 425 - (void)setFrame:(NSRect)frameRect { |
| 416 [super setFrame:frameRect]; | 426 [super setFrame:frameRect]; |
| 417 renderWidgetHostView_->render_widget_host_->WasResized(); | 427 if (renderWidgetHostView_->render_widget_host_) |
| 428 renderWidgetHostView_->render_widget_host_->WasResized(); |
| 418 } | 429 } |
| 419 | 430 |
| 420 - (void)drawRect:(NSRect)dirtyRect { | 431 - (void)drawRect:(NSRect)dirtyRect { |
| 432 if (!renderWidgetHostView_->render_widget_host_) { |
| 433 // TODO(shess): Consider using something more noticable? |
| 434 [[NSColor whiteColor] set]; |
| 435 NSRectFill(dirtyRect); |
| 436 return; |
| 437 } |
| 438 |
| 421 DCHECK(renderWidgetHostView_->render_widget_host_->process()->HasConnection())
; | 439 DCHECK(renderWidgetHostView_->render_widget_host_->process()->HasConnection())
; |
| 422 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); | 440 DCHECK(!renderWidgetHostView_->about_to_validate_and_paint_); |
| 423 | 441 |
| 424 renderWidgetHostView_->invalid_rect_ = dirtyRect; | 442 renderWidgetHostView_->invalid_rect_ = dirtyRect; |
| 425 renderWidgetHostView_->about_to_validate_and_paint_ = true; | 443 renderWidgetHostView_->about_to_validate_and_paint_ = true; |
| 426 BackingStore* backing_store = | 444 BackingStore* backing_store = |
| 427 renderWidgetHostView_->render_widget_host_->GetBackingStore(true); | 445 renderWidgetHostView_->render_widget_host_->GetBackingStore(true); |
| 428 skia::PlatformCanvas* canvas = backing_store->canvas(); | 446 skia::PlatformCanvas* canvas = backing_store->canvas(); |
| 429 renderWidgetHostView_->about_to_validate_and_paint_ = false; | 447 renderWidgetHostView_->about_to_validate_and_paint_ = false; |
| 430 dirtyRect = renderWidgetHostView_->invalid_rect_; | 448 dirtyRect = renderWidgetHostView_->invalid_rect_; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 502 } | 520 } |
| 503 } else { | 521 } else { |
| 504 [[NSColor whiteColor] set]; | 522 [[NSColor whiteColor] set]; |
| 505 NSRectFill(dirtyRect); | 523 NSRectFill(dirtyRect); |
| 506 if (renderWidgetHostView_->whiteout_start_time_.is_null()) | 524 if (renderWidgetHostView_->whiteout_start_time_.is_null()) |
| 507 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); | 525 renderWidgetHostView_->whiteout_start_time_ = base::TimeTicks::Now(); |
| 508 } | 526 } |
| 509 } | 527 } |
| 510 | 528 |
| 511 - (BOOL)canBecomeKeyView { | 529 - (BOOL)canBecomeKeyView { |
| 530 if (!renderWidgetHostView_->render_widget_host_) |
| 531 return NO; |
| 532 |
| 512 return canBeKeyView_; | 533 return canBeKeyView_; |
| 513 } | 534 } |
| 514 | 535 |
| 515 - (BOOL)acceptsFirstResponder { | 536 - (BOOL)acceptsFirstResponder { |
| 537 if (!renderWidgetHostView_->render_widget_host_) |
| 538 return NO; |
| 539 |
| 516 return canBeKeyView_; | 540 return canBeKeyView_; |
| 517 } | 541 } |
| 518 | 542 |
| 519 - (BOOL)becomeFirstResponder { | 543 - (BOOL)becomeFirstResponder { |
| 520 if (![self superview]) { | 544 if (!renderWidgetHostView_->render_widget_host_) |
| 521 // We're dead, so becoming first responder is probably a bad idea. | |
| 522 return NO; | 545 return NO; |
| 523 } | |
| 524 | 546 |
| 525 renderWidgetHostView_->render_widget_host_->Focus(); | 547 renderWidgetHostView_->render_widget_host_->Focus(); |
| 526 return YES; | 548 return YES; |
| 527 } | 549 } |
| 528 | 550 |
| 529 - (BOOL)resignFirstResponder { | 551 - (BOOL)resignFirstResponder { |
| 530 if (![self superview]) { | 552 if (!renderWidgetHostView_->render_widget_host_) |
| 531 // We're dead, so touching renderWidgetHostView_ is probably a bad | |
| 532 // idea. | |
| 533 return YES; | 553 return YES; |
| 534 } | |
| 535 | 554 |
| 536 if (closeOnDeactivate_) | 555 if (closeOnDeactivate_) |
| 537 renderWidgetHostView_->KillSelf(); | 556 renderWidgetHostView_->KillSelf(); |
| 538 | 557 |
| 539 renderWidgetHostView_->render_widget_host_->Blur(); | 558 renderWidgetHostView_->render_widget_host_->Blur(); |
| 540 | 559 |
| 541 return YES; | 560 return YES; |
| 542 } | 561 } |
| 543 | 562 |
| 544 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { | 563 - (BOOL)validateUserInterfaceItem:(id<NSValidatedUserInterfaceItem>)item { |
| 545 SEL action = [item action]; | 564 SEL action = [item action]; |
| 546 | 565 |
| 547 return editCommand_helper_->IsMenuItemEnabled(action, self); | 566 return editCommand_helper_->IsMenuItemEnabled(action, self); |
| 548 } | 567 } |
| 549 | 568 |
| 550 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { | 569 - (RenderWidgetHostViewMac*)renderWidgetHostViewMac { |
| 551 return renderWidgetHostView_; | 570 return renderWidgetHostView_; |
| 552 } | 571 } |
| 553 | 572 |
| 554 @end | 573 @end |
| 555 | 574 |
| OLD | NEW |