| 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 "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h" | 5 #import "chrome/browser/tab_contents/chrome_web_contents_view_delegate_mac.h" |
| 6 | 6 |
| 7 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat
e.h" | 7 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat
e.h" |
| 8 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 8 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
| 9 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" | 9 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" |
| 10 #import "chrome/browser/ui/cocoa/view_id_util.h" | 10 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 11 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 12 #include "content/public/browser/web_contents.h" | 12 #include "content/public/browser/web_contents.h" |
| 13 | 13 |
| 14 namespace chrome_web_contents_view_mac_delegate { | 14 namespace chrome_web_contents_view_delegate_mac { |
| 15 content::WebContentsViewMacDelegate* CreateWebContentsViewMacDelegate( | 15 content::WebContentsViewDelegate* CreateWebContentsViewDelegateMac( |
| 16 content::WebContents* web_contents) { | 16 content::WebContents* web_contents) { |
| 17 return new ChromeWebContentsViewMacDelegate(web_contents); | 17 return new ChromeWebContentsViewDelegateMac(web_contents); |
| 18 } | 18 } |
| 19 } | 19 } |
| 20 | 20 |
| 21 ChromeWebContentsViewMacDelegate::ChromeWebContentsViewMacDelegate( | 21 ChromeWebContentsViewDelegateMac::ChromeWebContentsViewDelegateMac( |
| 22 content::WebContents* web_contents) | 22 content::WebContents* web_contents) |
| 23 : bookmark_handler_(new WebDragBookmarkHandlerMac), | 23 : bookmark_handler_(new WebDragBookmarkHandlerMac), |
| 24 web_contents_(web_contents) { | 24 web_contents_(web_contents) { |
| 25 } | 25 } |
| 26 | 26 |
| 27 ChromeWebContentsViewMacDelegate::~ChromeWebContentsViewMacDelegate() { | 27 ChromeWebContentsViewDelegateMac::~ChromeWebContentsViewDelegateMac() { |
| 28 } | 28 } |
| 29 | 29 |
| 30 NSObject<RenderWidgetHostViewMacDelegate>* | 30 NSObject<RenderWidgetHostViewMacDelegate>* |
| 31 ChromeWebContentsViewMacDelegate::CreateRenderWidgetHostViewDelegate( | 31 ChromeWebContentsViewDelegateMac::CreateRenderWidgetHostViewDelegate( |
| 32 content::RenderWidgetHost* render_widget_host) { | 32 content::RenderWidgetHost* render_widget_host) { |
| 33 return [[ChromeRenderWidgetHostViewMacDelegate alloc] | 33 return [[ChromeRenderWidgetHostViewMacDelegate alloc] |
| 34 initWithRenderWidgetHost:render_widget_host]; | 34 initWithRenderWidgetHost:render_widget_host]; |
| 35 } | 35 } |
| 36 | 36 |
| 37 content::WebDragDestDelegate* ChromeWebContentsViewMacDelegate::DragDelegate() { | 37 content::WebDragDestDelegate* |
| 38 return static_cast<content::WebDragDestDelegate*>(bookmark_handler_.get()); | 38 ChromeWebContentsViewDelegateMac::GetDragDestDelegate() { |
| 39 return bookmark_handler_.get(); |
| 39 } | 40 } |
| 40 | 41 |
| 41 void ChromeWebContentsViewMacDelegate::ShowContextMenu( | 42 void ChromeWebContentsViewDelegateMac::ShowContextMenu( |
| 42 const content::ContextMenuParams& params) { | 43 const content::ContextMenuParams& params) { |
| 43 // The renderer may send the "show context menu" message multiple times, one | 44 // The renderer may send the "show context menu" message multiple times, one |
| 44 // for each right click mouse event it receives. Normally, this doesn't happen | 45 // for each right click mouse event it receives. Normally, this doesn't happen |
| 45 // because mouse events are not forwarded once the context menu is showing. | 46 // because mouse events are not forwarded once the context menu is showing. |
| 46 // However, there's a race - the context menu may not yet be showing when | 47 // However, there's a race - the context menu may not yet be showing when |
| 47 // the second mouse event arrives. In this case, |ShowContextMenu()| will | 48 // the second mouse event arrives. In this case, |ShowContextMenu()| will |
| 48 // get called multiple times - if so, don't create another context menu. | 49 // get called multiple times - if so, don't create another context menu. |
| 49 // TODO(asvitkine): Fix the renderer so that it doesn't do this. | 50 // TODO(asvitkine): Fix the renderer so that it doesn't do this. |
| 50 content::RenderWidgetHostView* widget_view = | 51 content::RenderWidgetHostView* widget_view = |
| 51 web_contents_->GetRenderWidgetHostView(); | 52 web_contents_->GetRenderWidgetHostView(); |
| 52 if (widget_view && widget_view->IsShowingContextMenu()) | 53 if (widget_view && widget_view->IsShowingContextMenu()) |
| 53 return; | 54 return; |
| 54 | 55 |
| 55 context_menu_.reset( | 56 context_menu_.reset( |
| 56 new RenderViewContextMenuMac(web_contents_, | 57 new RenderViewContextMenuMac(web_contents_, |
| 57 params, | 58 params, |
| 58 web_contents_->GetContentNativeView())); | 59 web_contents_->GetContentNativeView())); |
| 59 context_menu_->Init(); | 60 context_menu_->Init(); |
| 60 } | 61 } |
| 61 | 62 |
| 62 void ChromeWebContentsViewMacDelegate::NativeViewCreated(NSView* view) { | 63 void ChromeWebContentsViewDelegateMac::NativeViewCreated(NSView* view) { |
| 63 view_id_util::SetID(view, VIEW_ID_TAB_CONTAINER); | 64 view_id_util::SetID(view, VIEW_ID_TAB_CONTAINER); |
| 64 } | 65 } |
| 65 | 66 |
| 66 void ChromeWebContentsViewMacDelegate::NativeViewDestroyed(NSView* view) { | 67 void ChromeWebContentsViewDelegateMac::NativeViewDestroyed(NSView* view) { |
| 67 view_id_util::UnsetID(view); | 68 view_id_util::UnsetID(view); |
| 68 } | 69 } |
| OLD | NEW |