| 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 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" | 15 #include "third_party/WebKit/WebKit/chromium/public/mac/WebInputEventFactory.h" |
| 16 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" | 16 #include "third_party/WebKit/WebKit/chromium/public/WebInputEvent.h" |
| 17 #include "webkit/glue/webmenurunner_mac.h" |
| 17 | 18 |
| 18 using WebKit::WebInputEventFactory; | 19 using WebKit::WebInputEventFactory; |
| 19 using WebKit::WebMouseEvent; | 20 using WebKit::WebMouseEvent; |
| 20 using WebKit::WebMouseWheelEvent; | 21 using WebKit::WebMouseWheelEvent; |
| 21 | 22 |
| 22 @interface RenderWidgetHostViewCocoa (Private) | 23 @interface RenderWidgetHostViewCocoa (Private) |
| 23 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; | 24 - (id)initWithRenderWidgetHostViewMac:(RenderWidgetHostViewMac*)r; |
| 24 @end | 25 @end |
| 25 | 26 |
| 26 namespace { | 27 namespace { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 39 } | 40 } |
| 40 | 41 |
| 41 /////////////////////////////////////////////////////////////////////////////// | 42 /////////////////////////////////////////////////////////////////////////////// |
| 42 // RenderWidgetHostViewMac, public: | 43 // RenderWidgetHostViewMac, public: |
| 43 | 44 |
| 44 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) | 45 RenderWidgetHostViewMac::RenderWidgetHostViewMac(RenderWidgetHost* widget) |
| 45 : render_widget_host_(widget), | 46 : render_widget_host_(widget), |
| 46 about_to_validate_and_paint_(false), | 47 about_to_validate_and_paint_(false), |
| 47 is_loading_(false), | 48 is_loading_(false), |
| 48 is_hidden_(false), | 49 is_hidden_(false), |
| 49 shutdown_factory_(this) { | 50 shutdown_factory_(this), |
| 51 parent_view_(NULL) { |
| 50 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] | 52 cocoa_view_ = [[[RenderWidgetHostViewCocoa alloc] |
| 51 initWithRenderWidgetHostViewMac:this] autorelease]; | 53 initWithRenderWidgetHostViewMac:this] autorelease]; |
| 52 render_widget_host_->set_view(this); | 54 render_widget_host_->set_view(this); |
| 53 } | 55 } |
| 54 | 56 |
| 55 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { | 57 RenderWidgetHostViewMac::~RenderWidgetHostViewMac() { |
| 56 } | 58 } |
| 57 | 59 |
| 58 /////////////////////////////////////////////////////////////////////////////// | 60 /////////////////////////////////////////////////////////////////////////////// |
| 59 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: | 61 // RenderWidgetHostViewMac, RenderWidgetHostView implementation: |
| (...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 260 NSString* tooltip_nsstring = base::SysWideToNSString(tooltip_text_); | 262 NSString* tooltip_nsstring = base::SysWideToNSString(tooltip_text_); |
| 261 [cocoa_view_ setToolTip:tooltip_nsstring]; | 263 [cocoa_view_ setToolTip:tooltip_nsstring]; |
| 262 } | 264 } |
| 263 } | 265 } |
| 264 | 266 |
| 265 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( | 267 BackingStore* RenderWidgetHostViewMac::AllocBackingStore( |
| 266 const gfx::Size& size) { | 268 const gfx::Size& size) { |
| 267 return new BackingStore(size); | 269 return new BackingStore(size); |
| 268 } | 270 } |
| 269 | 271 |
| 272 // Display a popup menu for WebKit using Cocoa widgets. |
| 273 void RenderWidgetHostViewMac::ShowPopupWithItems( |
| 274 gfx::Rect bounds, |
| 275 int item_height, |
| 276 int selected_item, |
| 277 const std::vector<WebMenuItem>& items) { |
| 278 NSRect view_rect = [cocoa_view_ bounds]; |
| 279 NSRect position = NSMakeRect(bounds.x(), bounds.y() - bounds.height(), |
| 280 bounds.width(), bounds.height()); |
| 281 |
| 282 // Display the menu. |
| 283 WebMenuRunner* menu_runner = |
| 284 [[[WebMenuRunner alloc] initWithItems:items] autorelease]; |
| 285 |
| 286 [menu_runner runMenuInView:parent_view_ |
| 287 withBounds:position |
| 288 initialIndex:selected_item]; |
| 289 |
| 290 int window_num = [[parent_view_ window] windowNumber]; |
| 291 NSEvent* event = CreateEventForMenuAction([menu_runner menuItemWasChosen], |
| 292 window_num, item_height, |
| 293 [menu_runner indexOfSelectedItem], |
| 294 position, view_rect); |
| 295 |
| 296 if ([menu_runner menuItemWasChosen]) { |
| 297 // Simulate a menu selection event. |
| 298 const WebMouseEvent& mouse_event = |
| 299 WebInputEventFactory::mouseEvent(event, cocoa_view_); |
| 300 render_widget_host_->ForwardMouseEvent(mouse_event); |
| 301 } else { |
| 302 // Simulate a menu dismiss event. |
| 303 NativeWebKeyboardEvent keyboard_event(event); |
| 304 render_widget_host_->ForwardKeyboardEvent(keyboard_event); |
| 305 } |
| 306 } |
| 307 |
| 270 void RenderWidgetHostViewMac::KillSelf() { | 308 void RenderWidgetHostViewMac::KillSelf() { |
| 271 if (shutdown_factory_.empty()) { | 309 if (shutdown_factory_.empty()) { |
| 272 [cocoa_view_ setHidden:YES]; | 310 [cocoa_view_ setHidden:YES]; |
| 273 MessageLoop::current()->PostTask(FROM_HERE, | 311 MessageLoop::current()->PostTask(FROM_HERE, |
| 274 shutdown_factory_.NewRunnableMethod( | 312 shutdown_factory_.NewRunnableMethod( |
| 275 &RenderWidgetHostViewMac::ShutdownHost)); | 313 &RenderWidgetHostViewMac::ShutdownHost)); |
| 276 } | 314 } |
| 277 } | 315 } |
| 278 | 316 |
| 279 void RenderWidgetHostViewMac::ShutdownHost() { | 317 void RenderWidgetHostViewMac::ShutdownHost() { |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 421 - (BOOL)resignFirstResponder { | 459 - (BOOL)resignFirstResponder { |
| 422 if (closeOnDeactivate_) | 460 if (closeOnDeactivate_) |
| 423 renderWidgetHostView_->KillSelf(); | 461 renderWidgetHostView_->KillSelf(); |
| 424 | 462 |
| 425 renderWidgetHostView_->render_widget_host_->Blur(); | 463 renderWidgetHostView_->render_widget_host_->Blur(); |
| 426 | 464 |
| 427 return YES; | 465 return YES; |
| 428 } | 466 } |
| 429 | 467 |
| 430 @end | 468 @end |
| OLD | NEW |