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
3 // found in the LICENSE file.
5 #ifndef CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
6 #define CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_
8 #import <Cocoa/Cocoa.h>
13 #include "base/mac/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"
28 class WebContentsImpl;
29 class WebContentsViewDelegate;
30 class WebContentsViewMac;
38 @interface WebContentsViewCocoa : BaseView {
40 content::WebContentsViewMac* webContentsView_; // WEAK; owns us
41 base::scoped_nsobject<WebDragSource> dragSource_;
42 base::scoped_nsobject<WebDragDest> dragDest_;
43 BOOL mouseDownCanMoveWindow_;
46 - (void)setMouseDownCanMoveWindow:(BOOL)canMove;
48 // Expose this, since sometimes one needs both the NSView and the
50 - (content::WebContentsImpl*)webContents;
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.
57 class WebContentsViewMac : public WebContentsViewPort,
58 public RenderViewHostDelegateView {
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();
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 DropData* GetDropData() const OVERRIDE;
80 virtual gfx::Rect GetViewBounds() const OVERRIDE;
81 virtual void SetAllowOverlappingViews(bool overlapping) OVERRIDE;
82 virtual bool GetAllowOverlappingViews() const OVERRIDE;
83 virtual void SetOverlayView(WebContentsView* overlay,
84 const gfx::Point& offset) OVERRIDE;
85 virtual void RemoveOverlayView() OVERRIDE;
87 // WebContentsViewPort implementation ----------------------------------------
88 virtual void CreateView(
89 const gfx::Size& initial_size, gfx::NativeView context) OVERRIDE;
90 virtual RenderWidgetHostView* CreateViewForWidget(
91 RenderWidgetHost* render_widget_host) OVERRIDE;
92 virtual RenderWidgetHostView* CreateViewForPopupWidget(
93 RenderWidgetHost* render_widget_host) OVERRIDE;
94 virtual void SetPageTitle(const base::string16& title) OVERRIDE;
95 virtual void RenderViewCreated(RenderViewHost* host) OVERRIDE;
96 virtual void RenderViewSwappedIn(RenderViewHost* host) OVERRIDE;
97 virtual void SetOverscrollControllerEnabled(bool enabled) OVERRIDE;
98 virtual bool IsEventTracking() const OVERRIDE;
99 virtual void CloseTabAfterEventTracking() OVERRIDE;
101 // Backend implementation of RenderViewHostDelegateView.
102 virtual void ShowContextMenu(const ContextMenuParams& params) OVERRIDE;
103 virtual void ShowPopupMenu(const gfx::Rect& bounds,
105 double item_font_size,
107 const std::vector<MenuItem>& items,
109 bool allow_multiple_selection) OVERRIDE;
110 virtual void StartDragging(const DropData& drop_data,
111 blink::WebDragOperationsMask allowed_operations,
112 const gfx::ImageSkia& image,
113 const gfx::Vector2d& image_offset,
114 const DragEventSourceInfo& event_info) OVERRIDE;
115 virtual void UpdateDragCursor(blink::WebDragOperation operation) OVERRIDE;
116 virtual void GotFocus() OVERRIDE;
117 virtual void TakeFocus(bool reverse) OVERRIDE;
119 // A helper method for closing the tab in the
120 // CloseTabAfterEventTracking() implementation.
123 WebContentsImpl* web_contents() { return web_contents_; }
124 WebContentsViewDelegate* delegate() { return delegate_.get(); }
127 // Updates overlay view on current RenderWidgetHostView.
128 void UpdateRenderWidgetHostViewOverlay();
130 // The WebContentsImpl whose contents we display.
131 WebContentsImpl* web_contents_;
133 // The Cocoa NSView that lives in the view hierarchy.
134 base::scoped_nsobject<WebContentsViewCocoa> cocoa_view_;
136 // Keeps track of which NSView has focus so we can restore the focus when
138 base::scoped_nsobject<FocusTracker> focus_tracker_;
140 // Our optional delegate.
141 scoped_ptr<WebContentsViewDelegate> delegate_;
143 // Whether to allow overlapping views.
144 bool allow_overlapping_views_;
146 // The overlay view which is rendered above this one.
147 // Overlay view has |underlay_view_| set to this view.
148 WebContentsViewMac* overlay_view_;
150 // The offset of overlay view relative to this view.
151 gfx::Point overlay_view_offset_;
153 // The underlay view which this view is rendered above.
154 // Underlay view has |overlay_view_| set to this view.
155 WebContentsViewMac* underlay_view_;
157 DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac);
160 } // namespace content
162 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_