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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
6 | 6 |
7 #include "content/browser/tab_contents/popup_menu_helper_mac.h" | 7 #include "content/browser/tab_contents/popup_menu_helper_mac.h" |
8 | 8 |
9 #import "base/mac/scoped_sending_event.h" | 9 #import "base/mac/scoped_sending_event.h" |
10 #include "base/memory/scoped_nsobject.h" | 10 #include "base/memory/scoped_nsobject.h" |
11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
12 #include "content/browser/renderer_host/render_view_host.h" | 12 #include "content/browser/renderer_host/render_view_host.h" |
13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 13 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
14 #include "content/public/browser/notification_source.h" | 14 #include "content/public/browser/notification_source.h" |
15 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
16 #import "ui/base/cocoa/base_view.h" | 16 #import "ui/base/cocoa/base_view.h" |
17 #include "webkit/glue/webmenurunner_mac.h" | 17 #include "webkit/glue/webmenurunner_mac.h" |
18 | 18 |
19 PopupMenuHelper::PopupMenuHelper(RenderViewHost* render_view_host) | 19 PopupMenuHelper::PopupMenuHelper(RenderViewHost* render_view_host) |
20 : render_view_host_(render_view_host) { | 20 : render_view_host_(static_cast<RenderViewHostImpl*>(render_view_host)) { |
21 notification_registrar_.Add( | 21 notification_registrar_.Add( |
22 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, | 22 this, content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED, |
23 content::Source<RenderWidgetHost>(render_view_host)); | 23 content::Source<RenderWidgetHost>(render_view_host)); |
24 } | 24 } |
25 | 25 |
26 void PopupMenuHelper::ShowPopupMenu( | 26 void PopupMenuHelper::ShowPopupMenu( |
27 const gfx::Rect& bounds, | 27 const gfx::Rect& bounds, |
28 int item_height, | 28 int item_height, |
29 double item_font_size, | 29 double item_font_size, |
30 int selected_item, | 30 int selected_item, |
31 const std::vector<WebMenuItem>& items, | 31 const std::vector<WebMenuItem>& items, |
32 bool right_aligned) { | 32 bool right_aligned) { |
33 // Retain the Cocoa view for the duration of the pop-up so that it can't be | 33 // Retain the Cocoa view for the duration of the pop-up so that it can't be |
34 // dealloced if my Destroy() method is called while the pop-up's up (which | 34 // dealloced if my Destroy() method is called while the pop-up's up (which |
35 // would in turn delete me, causing a crash once the -runMenuInView | 35 // would in turn delete me, causing a crash once the -runMenuInView |
36 // call returns. That's what was happening in <http://crbug.com/33250>). | 36 // call returns. That's what was happening in <http://crbug.com/33250>). |
37 RenderWidgetHostViewMac* rwhvm = | 37 RenderWidgetHostViewMac* rwhvm = |
38 static_cast<RenderWidgetHostViewMac*>(render_view_host_->view()); | 38 static_cast<RenderWidgetHostViewMac*>(render_view_host_->GetView()); |
39 scoped_nsobject<RenderWidgetHostViewCocoa> cocoa_view | 39 scoped_nsobject<RenderWidgetHostViewCocoa> cocoa_view |
40 ([rwhvm->cocoa_view() retain]); | 40 ([rwhvm->cocoa_view() retain]); |
41 | 41 |
42 // Display the menu. | 42 // Display the menu. |
43 scoped_nsobject<WebMenuRunner> menu_runner; | 43 scoped_nsobject<WebMenuRunner> menu_runner; |
44 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items | 44 menu_runner.reset([[WebMenuRunner alloc] initWithItems:items |
45 fontSize:item_font_size | 45 fontSize:item_font_size |
46 rightAligned:right_aligned]); | 46 rightAligned:right_aligned]); |
47 | 47 |
48 { | 48 { |
(...skipping 29 matching lines...) Expand all Loading... |
78 | 78 |
79 void PopupMenuHelper::Observe( | 79 void PopupMenuHelper::Observe( |
80 int type, | 80 int type, |
81 const content::NotificationSource& source, | 81 const content::NotificationSource& source, |
82 const content::NotificationDetails& details) { | 82 const content::NotificationDetails& details) { |
83 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); | 83 DCHECK(type == content::NOTIFICATION_RENDER_WIDGET_HOST_DESTROYED); |
84 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == render_view_host_); | 84 DCHECK(content::Source<RenderWidgetHost>(source).ptr() == render_view_host_); |
85 render_view_host_ = NULL; | 85 render_view_host_ = NULL; |
86 } | 86 } |
87 | 87 |
OLD | NEW |