web_contents_view_mac.h revision c2e0dbddbe15c98d52c4786dac06cb8952a8ae6d
188c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall// Copyright (c) 2012 The Chromium Authors. All rights reserved.
288c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall// Use of this source code is governed by a BSD-style license that can be
388c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall// found in the LICENSE file.
488c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall
588c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall#ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
688c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall#define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
788c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall
888c1dfccf8c5d487408e3365c752ed24c867c7ceJohn McCall#import <Cocoa/Cocoa.h>
9
10#include <string>
11#include <vector>
12
13#include "base/memory/scoped_nsobject.h"
14#include "base/memory/scoped_ptr.h"
15#include "content/common/content_export.h"
16#include "content/common/drag_event_source_info.h"
17#include "content/port/browser/render_view_host_delegate_view.h"
18#include "content/port/browser/web_contents_view_port.h"
19#include "ui/base/cocoa/base_view.h"
20#include "ui/gfx/size.h"
21
22@class FocusTracker;
23class SkBitmap;
24@class WebDragDest;
25@class WebDragSource;
26
27namespace content {
28class WebContentsImpl;
29class WebContentsViewDelegate;
30class WebContentsViewMac;
31}
32
33namespace gfx {
34class Vector2d;
35}
36
37CONTENT_EXPORT
38@interface WebContentsViewCocoa : BaseView {
39 @private
40  content::WebContentsViewMac* webContentsView_;  // WEAK; owns us
41  scoped_nsobject<WebDragSource> dragSource_;
42  scoped_nsobject<WebDragDest> dragDest_;
43  BOOL mouseDownCanMoveWindow_;
44}
45
46- (void)setMouseDownCanMoveWindow:(BOOL)canMove;
47
48// Expose this, since sometimes one needs both the NSView and the
49// WebContentsImpl.
50- (content::WebContentsImpl*)webContents;
51@end
52
53namespace content {
54
55// Mac-specific implementation of the WebContentsView. It owns an NSView that
56// contains all of the contents of the tab and associated child views.
57class WebContentsViewMac : public WebContentsViewPort,
58                           public RenderViewHostDelegateView {
59 public:
60  // The corresponding WebContentsImpl is passed in the constructor, and manages
61  // our lifetime. This doesn't need to be the case, but is this way currently
62  // because that's what was easiest when they were split.
63  WebContentsViewMac(WebContentsImpl* web_contents,
64                     WebContentsViewDelegate* delegate);
65  virtual ~WebContentsViewMac();
66
67  // WebContentsView implementation --------------------------------------------
68  virtual gfx::NativeView GetNativeView() const OVERRIDE;
69  virtual gfx::NativeView GetContentNativeView() const OVERRIDE;
70  virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE;
71  virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE;
72  virtual void OnTabCrashed(base::TerminationStatus status,
73                            int error_code) OVERRIDE;
74  virtual void SizeContents(const gfx::Size& size) OVERRIDE;
75  virtual void Focus() OVERRIDE;
76  virtual void SetInitialFocus() OVERRIDE;
77  virtual void StoreFocus() OVERRIDE;
78  virtual void RestoreFocus() OVERRIDE;
79  virtual WebDropData* GetDropData() const OVERRIDE;
80  virtual gfx::Rect GetViewBounds() const OVERRIDE;
81  virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
82
83  // WebContentsViewPort implementation ----------------------------------------
84  virtual void CreateView(
85      const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
86  virtual RenderWidgetHostView* CreateViewForWidget(
87      RenderWidgetHost* render_widget_host) OVERRIDE;
88  virtual RenderWidgetHostView* CreateViewForPopupWidget(
89      RenderWidgetHost* render_widget_host) OVERRIDE;
90  virtual void SetPageTitle(const string16& title) OVERRIDE;
91  virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
92  virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
93  virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
94  virtual bool IsEventTracking() const OVERRIDE;
95  virtual void CloseTabAfterEventTracking() OVERRIDE;
96
97  // Backend implementation of RenderViewHostDelegateView.
98  virtual void ShowContextMenu(const ContextMenuParams& params,
99                               ContextMenuSourceType type) OVERRIDE;
100  virtual void ShowPopupMenu(const gfx::Rect& bounds,
101                             int item_height,
102                             double item_font_size,
103                             int selected_item,
104                             const std::vector<WebMenuItem>& items,
105                             bool right_aligned,
106                             bool allow_multiple_selection) OVERRIDE;
107  virtual void StartDragging(const WebDropData& drop_data,
108                             WebKit::WebDragOperationsMask allowed_operations,
109                             const gfx::ImageSkia& image,
110                             const gfx::Vector2d& image_offset,
111                             const DragEventSourceInfo& event_info) OVERRIDE;
112  virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE;
113  virtual void GotFocus() OVERRIDE;
114  virtual void TakeFocus(bool reverse) OVERRIDE;
115
116  // A helper method for closing the tab in the
117  // CloseTabAfterEventTracking() implementation.
118  void CloseTab();
119
120  WebContentsImpl* web_contents() { return web_contents_; }
121  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  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  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