15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <string>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
13eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/mac/scoped_nsobject.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
15010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/renderer_host/render_view_host_delegate_view.h"
16010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)#include "content/browser/web_contents/web_contents_view.h"
17c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "content/common/content_export.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/common/drag_event_source_info.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/base/cocoa/base_view.h"
205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "ui/gfx/size.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class FocusTracker;
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class SkBitmap;
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class WebDragDest;
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@class WebDragSource;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
28effb81e5f8246d0db0270817048dc992db66e9fbBen Murdochclass PopupMenuHelper;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsImpl;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsViewDelegate;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsViewMac;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Vector2d;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
38c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)CONTENT_EXPORT
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@interface WebContentsViewCocoa : BaseView {
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::WebContentsViewMac* webContentsView_;  // WEAK; owns us
42eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<WebDragSource> dragSource_;
43eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<WebDragDest> dragDest_;
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BOOL mouseDownCanMoveWindow_;
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setMouseDownCanMoveWindow:(BOOL)canMove;
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Expose this, since sometimes one needs both the NSView and the
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// WebContentsImpl.
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (content::WebContentsImpl*)webContents;
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)@end
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Mac-specific implementation of the WebContentsView. It owns an NSView that
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// contains all of the contents of the tab and associated child views.
58010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)class WebContentsViewMac : public WebContentsView,
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                           public RenderViewHostDelegateView {
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The corresponding WebContentsImpl is passed in the constructor, and manages
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // our lifetime. This doesn't need to be the case, but is this way currently
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // because that's what was easiest when they were split.
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsViewMac(WebContentsImpl* web_contents,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                     WebContentsViewDelegate* delegate);
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual ~WebContentsViewMac();
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebContentsView implementation --------------------------------------------
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeView GetNativeView() const OVERRIDE;
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void Focus() OVERRIDE;
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetInitialFocus() OVERRIDE;
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void StoreFocus() OVERRIDE;
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RestoreFocus() OVERRIDE;
78eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual DropData* GetDropData() const OVERRIDE;
792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::Rect GetViewBounds() const OVERRIDE;
80116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual void SetAllowOtherViews(bool allow) OVERRIDE;
81116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  virtual bool GetAllowOtherViews() const OVERRIDE;
822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void CreateView(
832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
84010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual RenderWidgetHostViewBase* CreateViewForWidget(
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RenderWidgetHost* render_widget_host) OVERRIDE;
86010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual RenderWidgetHostViewBase* CreateViewForPopupWidget(
872a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RenderWidgetHost* render_widget_host) OVERRIDE;
88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetPageTitle(const base::string16& title) OVERRIDE;
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool IsEventTracking() const OVERRIDE;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void CloseTabAfterEventTracking() OVERRIDE;
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Backend implementation of RenderViewHostDelegateView.
961320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ShowContextMenu(RenderFrameHost* render_frame_host,
975d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)                               const ContextMenuParams& params) OVERRIDE;
981320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ShowPopupMenu(RenderFrameHost* render_frame_host,
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                             const gfx::Rect& bounds,
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             int item_height,
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             double item_font_size,
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             int selected_item,
1037dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                             const std::vector<MenuItem>& items,
1045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool right_aligned,
1055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             bool allow_multiple_selection) OVERRIDE;
106effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  virtual void HidePopupMenu() OVERRIDE;
107eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  virtual void StartDragging(const DropData& drop_data,
108f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)                             blink::WebDragOperationsMask allowed_operations,
1095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const gfx::ImageSkia& image,
1105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const gfx::Vector2d& image_offset,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const DragEventSourceInfo& event_info) OVERRIDE;
112f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE;
1135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void GotFocus() OVERRIDE;
1145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void TakeFocus(bool reverse) OVERRIDE;
1155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A helper method for closing the tab in the
1175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // CloseTabAfterEventTracking() implementation.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CloseTab();
1195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsImpl* web_contents() { return web_contents_; }
1215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsViewDelegate* delegate() { return delegate_.get(); }
1225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The WebContentsImpl whose contents we display.
1255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsImpl* web_contents_;
1265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // The Cocoa NSView that lives in the view hierarchy.
128eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_;
1295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Keeps track of which NSView has focus so we can restore the focus when
1315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // focus returns.
132eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  base::scoped_nsobject<FocusTracker> focus_tracker_;
1335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Our optional delegate.
1355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<WebContentsViewDelegate> delegate_;
1365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
137116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  // Whether to allow other views.
138116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch  bool allow_other_views_;
139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
140effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch  scoped_ptr<PopupMenuHelper> popup_menu_helper_;
141effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch
1425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace content
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
148