Chromium Code Reviews| 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 #include "chrome/browser/renderer_host/backing_store.h" | 10 #include "chrome/browser/renderer_host/backing_store.h" |
| 11 #include "chrome/browser/renderer_host/render_process_host.h" | 11 #include "chrome/browser/renderer_host/render_process_host.h" |
| 12 #include "chrome/browser/renderer_host/render_widget_host.h" | 12 #include "chrome/browser/renderer_host/render_widget_host.h" |
| 13 #include "chrome/common/native_web_keyboard_event.h" | 13 #include "chrome/common/native_web_keyboard_event.h" |
| 14 #include "skia/ext/platform_canvas.h" | 14 #include "skia/ext/platform_canvas.h" |
| 15 #import "third_party/mozilla/include/ToolTip.h" | |
| 15 #include "webkit/api/public/mac/WebInputEventFactory.h" | 16 #include "webkit/api/public/mac/WebInputEventFactory.h" |
| 16 #include "webkit/api/public/WebInputEvent.h" | 17 #include "webkit/api/public/WebInputEvent.h" |
| 17 #include "webkit/glue/webmenurunner_mac.h" | 18 #include "webkit/glue/webmenurunner_mac.h" |
| 18 | 19 |
| 19 using WebKit::WebInputEventFactory; | 20 using WebKit::WebInputEventFactory; |
| 20 using WebKit::WebMouseEvent; | 21 using WebKit::WebMouseEvent; |
| 21 using WebKit::WebMouseWheelEvent; | 22 using WebKit::WebMouseWheelEvent; |
| 22 | 23 |
| 23 @interface RenderWidgetHostViewCocoa (Private) | 24 @interface RenderWidgetHostViewCocoa (Private) |
| 24 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 25 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 44 | 45 |
| 45 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 46 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
| 46 : render_widget_host_(widget), | 47 : render_widget_host_(widget), |
| 47 about_to_validate_and_paint_(false), | 48 about_to_validate_and_paint_(false), |
| 48 is_loading_(false), | 49 is_loading_(false), |
| 49 is_hidden_(false), | 50 is_hidden_(false), |
| 50 shutdown_factory_(this), | 51 shutdown_factory_(this), |
| 51 parent_view_(NULL) { | 52 parent_view_(NULL) { |
| 52 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 53 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 53 initWithRenderWidgetHostViewMac:this] autorelease]; | 54 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 55 tooltip_.reset([[ToolTip alloc] init]); | |
| 54 render_widget_host_->set_view(this); | 56 render_widget_host_->set_view(this); |
| 55 } | 57 } |
| 56 | 58 |
| 57 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 59 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 58 } | 60 } |
| 59 | 61 |
| 60 /////////////////////////////////////////////////////////////////////////////// | 62 /////////////////////////////////////////////////////////////////////////////// |
| 61 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 63 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| 62 | 64 |
| 63 void RenderWidgetHostViewMac::InitAsPopup( | 65 void RenderWidgetHostViewMac::InitAsPopup( |
| (...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 Destroy(); | 246 Destroy(); |
| 245 } | 247 } |
| 246 | 248 |
| 247 void RenderWidgetHostViewMac::Destroy() { | 249 void RenderWidgetHostViewMac::Destroy() { |
| 248 // We've been told to destroy. | 250 // We've been told to destroy. |
| 249 [cocoa_view_ retain]; | 251 [cocoa_view_ retain]; |
| 250 [cocoa_view_ removeFromSuperview]; | 252 [cocoa_view_ removeFromSuperview]; |
| 251 [cocoa_view_ autorelease]; | 253 [cocoa_view_ autorelease]; |
| 252 } | 254 } |
| 253 | 255 |
| 256 // Called from the renderer to tell us what the tooltip text should be. It | |
| 257 // calls us frequently so we need to cache the value to prevent doing a lot | |
| 258 // of repeat work. We cannot simply use [-NSView setToolTip:] because NSView | |
| 259 // can't handle the case where the tooltip text changes while the mouse is | |
| 260 // still inside the view. Since the page elements that get tooltips are all | |
|
stuartmorgan
2009/06/15 16:52:26
s/the view/a region/
| |
| 261 // contained within this view (and are unknown to the NSView system), we | |
| 262 // are forced to implement our own tooltips with child windows. | |
| 263 // TODO(pinkerton): Do we want these tooltips to time out after a certain time? | |
| 264 // Gecko does this automatically in the back-end, hence the ToolTip class not | |
| 265 // needing that functionality. We can either modify ToolTip or add this | |
| 266 // functionality here with a timer. | |
| 254 void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) { | 267 void RenderWidgetHostViewMac::SetTooltipText(const std::wstring& tooltip_text) { |
| 255 if (tooltip_text != tooltip_text_) { | 268 if (tooltip_text != tooltip_text_) { |
| 256 tooltip_text_ = tooltip_text; | 269 tooltip_text_ = tooltip_text; |
| 257 | 270 |
| 258 // Clamp the tooltip length to kMaxTooltipLength. It's a DOS issue on | 271 // Clamp the tooltip length to kMaxTooltipLength. It's a DOS issue on |
| 259 // Windows; we're just trying to be polite. | 272 // Windows; we're just trying to be polite. Don't persist the trimmed |
| 273 // string, as then the comparison above will always fail and we'll try to | |
| 274 // set it again every single time the mouse moves. | |
| 275 std::wstring display_text = tooltip_text_; | |
| 260 if (tooltip_text_.length() > kMaxTooltipLength) | 276 if (tooltip_text_.length() > kMaxTooltipLength) |
| 261 tooltip_text_ = tooltip_text_.substr(0, kMaxTooltipLength); | 277 display_text = tooltip_text_.substr(0, kMaxTooltipLength); |
| 262 | 278 |
| 263 NSString* tooltip_nsstring = base::SysWideToNSString(tooltip_text_); | 279 NSString* tooltip_nsstring = base::SysWideToNSString(display_text); |
| 264 [cocoa_view_ setToolTip:tooltip_nsstring]; | 280 if ([tooltip_nsstring length] == 0) { |
| 281 [tooltip_ closeToolTip]; | |
| 282 } else { | |
| 283 // Get the current mouse location in the window's coordinate system and | |
| 284 // use that as the point for displaying the tooltip. | |
| 285 NSPoint event_point = | |
| 286 [[cocoa_view_ window] mouseLocationOutsideOfEventStream]; | |
| 287 [tooltip_ showToolTipAtPoint:event_point | |
| 288 withString:tooltip_nsstring | |
| 289 overWindow:[cocoa_view_ window]]; | |
| 290 } | |
| 265 } | 291 } |
| 266 } | 292 } |
| 267 | 293 |
| 268 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 294 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
| 269 const gfx::Size& size) { | 295 const gfx::Size& size) { |
| 270 return new BackingStore(size); | 296 return new BackingStore(size); |
| 271 } | 297 } |
| 272 | 298 |
| 273 // Display a popup menu for WebKit using Cocoa widgets. | 299 // Display a popup menu for WebKit using Cocoa widgets. |
| 274 void RenderWidgetHostViewMac::ShowPopupWithItems( | 300 void RenderWidgetHostViewMac::ShowPopupWithItems( |
| (...skipping 177 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 452 | 478 |
| 453 - (BOOL)acceptsFirstResponder { | 479 - (BOOL)acceptsFirstResponder { |
| 454 return canBeKeyView_; | 480 return canBeKeyView_; |
| 455 } | 481 } |
| 456 | 482 |
| 457 - (BOOL)becomeFirstResponder { | 483 - (BOOL)becomeFirstResponder { |
| 458 if (![self superview]) { | 484 if (![self superview]) { |
| 459 // We're dead, so becoming first responder is probably a bad idea. | 485 // We're dead, so becoming first responder is probably a bad idea. |
| 460 return NO; | 486 return NO; |
| 461 } | 487 } |
| 462 | 488 |
| 463 renderWidgetHostView_->render_widget_host_->Focus(); | 489 renderWidgetHostView_->render_widget_host_->Focus(); |
| 464 return YES; | 490 return YES; |
| 465 } | 491 } |
| 466 | 492 |
| 467 - (BOOL)resignFirstResponder { | 493 - (BOOL)resignFirstResponder { |
| 468 if (![self superview]) { | 494 if (![self superview]) { |
| 469 // We're dead, so touching renderWidgetHostView_ is probably a bad | 495 // We're dead, so touching renderWidgetHostView_ is probably a bad |
| 470 // idea. | 496 // idea. |
| 471 return YES; | 497 return YES; |
| 472 } | 498 } |
| 473 | 499 |
| 474 if (closeOnDeactivate_) | 500 if (closeOnDeactivate_) |
| 475 renderWidgetHostView_->KillSelf(); | 501 renderWidgetHostView_->KillSelf(); |
| 476 | 502 |
| 477 renderWidgetHostView_->render_widget_host_->Blur(); | 503 renderWidgetHostView_->render_widget_host_->Blur(); |
| 478 | 504 |
| 479 return YES; | 505 return YES; |
| 480 } | 506 } |
| 481 | 507 |
| 482 @end | 508 @end |
| OLD | NEW |