web_contents_view_mac.h revision eb525c5499e34cc9c4b825d6d9e75bb07cc06ace
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)
51320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
61320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
85821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#import <Cocoa/Cocoa.h>
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include <string>
115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include <vector>
127dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/mac/scoped_nsobject.h"
14ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "base/memory/scoped_ptr.h"
15ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/common/content_export.h"
16ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/common/drag_event_source_info.h"
17ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch#include "content/port/browser/render_view_host_delegate_view.h"
182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/port/browser/web_contents_view_port.h"
192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "ui/base/cocoa/base_view.h"
205d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "ui/gfx/size.h"
215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
221320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@class FocusTracker;
231320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass SkBitmap;
241320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@class WebDragDest;
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@class WebDragSource;
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace content {
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsImpl;
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsViewDelegate;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class WebContentsViewMac;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace gfx {
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class Vector2d;
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
362a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
372a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)CONTENT_EXPORT
382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)@interface WebContentsViewCocoa : BaseView {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) @private
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  content::WebContentsViewMac* webContentsView_;  // WEAK; owns us
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  base::scoped_nsobject<WebDragSource> dragSource_;
42ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  base::scoped_nsobject<WebDragDest> dragDest_;
43ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  BOOL mouseDownCanMoveWindow_;
44ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch}
450529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)- (void)setMouseDownCanMoveWindow:(BOOL)canMove;
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Expose this, since sometimes one needs both the NSView and the
491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// WebContentsImpl.
501320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci- (content::WebContentsImpl*)webContents;
511320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci@end
521320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)namespace content {
542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci// Mac-specific implementation of the WebContentsView. It owns an NSView that
562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// contains all of the contents of the tab and associated child views.
571320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucciclass WebContentsViewMac : public WebContentsViewPort,
582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                           public RenderViewHostDelegateView {
591320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci public:
602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // The corresponding WebContentsImpl is passed in the constructor, and manages
612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // our lifetime. This doesn't need to be the case, but is this way currently
622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // because that's what was easiest when they were split.
632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  WebContentsViewMac(WebContentsImpl* web_contents,
641320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci                     WebContentsViewDelegate* delegate);
652a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual ~WebContentsViewMac();
662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // WebContentsView implementation --------------------------------------------
681320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual gfx::NativeView GetNativeView() const OVERRIDE;
692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
702a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
712a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
721320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void OnTabCrashed(base::TerminationStatus status,
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            int error_code) OVERRIDE;
742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
751320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void Focus() OVERRIDE;
762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetInitialFocus() OVERRIDE;
771320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void StoreFocus() OVERRIDE;
78ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void RestoreFocus() OVERRIDE;
79ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual DropData* GetDropData() const OVERRIDE;
80ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual gfx::Rect GetViewBounds() const OVERRIDE;
81ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch  virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
821320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual bool GetAllowOverlappingViews() const OVERRIDE;
830529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch
845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // WebContentsViewPort implementation ----------------------------------------
852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void CreateView(
862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual RenderWidgetHostView* CreateViewForWidget(
882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)      RenderWidgetHost* render_widget_host) OVERRIDE;
892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual RenderWidgetHostView* CreateViewForPopupWidget(
905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)      RenderWidgetHost* render_widget_host) OVERRIDE;
912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetPageTitle(const string16& title) OVERRIDE;
922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual bool IsEventTracking() const OVERRIDE;
962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void CloseTabAfterEventTracking() OVERRIDE;
972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
982a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  // Backend implementation of RenderViewHostDelegateView.
991320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
1002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void ShowPopupMenu(const gfx::Rect& bounds,
1012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             int item_height,
1022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             double item_font_size,
1032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             int selected_item,
1042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const std::vector<WebMenuItem>& items,
1052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             bool right_aligned,
1062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             bool allow_multiple_selection) OVERRIDE;
1072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void StartDragging(const DropData& drop_data,
1082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             WebKit::WebDragOperationsMask allowed_operations,
1092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const gfx::ImageSkia& image,
1102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                             const gfx::Vector2d& image_offset,
1115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                             const DragEventSourceInfo& event_info) OVERRIDE;
1121320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
1131320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void GotFocus() OVERRIDE;
1142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void TakeFocus(bool reverse) OVERRIDE;
1151320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci
1165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // A helper method for closing the tab in the
1171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  // CloseTabAfterEventTracking() implementation.
1185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void CloseTab();
1192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
1205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  WebContentsImpl* web_contents() { return web_contents_; }
1211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  WebContentsViewDelegate* delegate() { return delegate_.get(); }
122
123 private:
124  // The WebContentsImpl whose contents we display.
125  WebContentsImpl* web_contents_;
126
127  // The Cocoa NSView that lives in the view hierarchy.
128  base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_;
129
130  // Keeps track of which NSView has focus so we can restore the focus when
131  // focus returns.
132  base::scoped_nsobject<FocusTracker> focus_tracker_;
133
134  // Our optional delegate.
135  scoped_ptr<WebContentsViewDelegate> delegate_;
136
137  // Whether to allow overlapping views.
138  bool allow_overlapping_views_;
139
140  DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
141};
142
143}  // namespace content
144
145#endif  // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
146