Chromium Code Reviews| Index: chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.mm |
| diff --git a/chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.mm b/chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..007db147740d0b0e619686e1584530956ff945a7 |
| --- /dev/null |
| +++ b/chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.mm |
| @@ -0,0 +1,68 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#import "chrome/browser/tab_contents/chrome_web_contents_view_mac_delegate.h" |
| + |
| +#import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegate.h" |
| +#include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
| +#include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" |
| +#import "chrome/browser/ui/cocoa/view_id_util.h" |
| +#include "content/browser/renderer_host/render_widget_host_view.h" |
| +#include "content/public/browser/web_contents.h" |
| + |
| +namespace chrome_web_contents_view_mac_delegate { |
| +content::WebContentsViewMacDelegate* CreateWebContentsViewMacDelegate( |
| + content::WebContents* web_contents) { |
| + return new ChromeWebContentsViewMacDelegate(web_contents); |
| +} |
| +} |
|
jochen (gone - plz use gerrit)
2012/02/03 00:13:33
} // namespace $fancy
Avi (use Gerrit)
2012/02/03 01:18:53
For a namespace that tightly wrapped around a shim
|
| + |
| +ChromeWebContentsViewMacDelegate::ChromeWebContentsViewMacDelegate( |
| + content::WebContents* web_contents) |
| + : bookmark_handler_(new WebDragBookmarkHandlerMac), |
| + web_contents_(web_contents) { |
| +} |
| + |
| +ChromeWebContentsViewMacDelegate::~ChromeWebContentsViewMacDelegate() { |
| +} |
| + |
| +NSObject<RenderWidgetHostViewMacDelegate>* |
| +ChromeWebContentsViewMacDelegate::CreateRenderWidgetHostViewDelegate( |
| + RenderWidgetHost* render_widget_host) { |
| + return [[ChromeRenderWidgetHostViewMacDelegate alloc] |
| + initWithRenderWidgetHost:render_widget_host]; |
| +} |
| + |
|
jochen (gone - plz use gerrit)
2012/02/03 00:13:33
only one empty line
Avi (use Gerrit)
2012/02/03 01:18:53
Done.
|
| + |
| +content::WebDragDestDelegate* ChromeWebContentsViewMacDelegate::DragDelegate() { |
| + return static_cast<content::WebDragDestDelegate*>(bookmark_handler_.get()); |
| +} |
| + |
| +void ChromeWebContentsViewMacDelegate::ShowContextMenu( |
| + const ContextMenuParams& params) { |
| + // The renderer may send the "show context menu" message multiple times, one |
| + // for each right click mouse event it receives. Normally, this doesn't happen |
| + // because mouse events are not forwarded once the context menu is showing. |
| + // However, there's a race - the context menu may not yet be showing when |
| + // the second mouse event arrives. In this case, |ShowContextMenu()| will |
| + // get called multiple times - if so, don't create another context menu. |
| + // TODO(asvitkine): Fix the renderer so that it doesn't do this. |
| + RenderWidgetHostView* widget_view = web_contents_->GetRenderWidgetHostView(); |
| + if (widget_view && widget_view->showing_context_menu()) |
| + return; |
| + |
| + context_menu_.reset( |
| + new RenderViewContextMenuMac(web_contents_, |
| + params, |
| + web_contents_->GetContentNativeView())); |
| + context_menu_->Init(); |
| +} |
| + |
| +void ChromeWebContentsViewMacDelegate::NativeViewCreated(NSView* view) { |
| + view_id_util::SetID(view, VIEW_ID_TAB_CONTAINER); |
| +} |
| + |
| +void ChromeWebContentsViewMacDelegate::NativeViewDestroyed(NSView* view) { |
| + view_id_util::UnsetID(view); |
| +} |