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/browser/renderer_host/render_view_host_delegate_view.h"
16 #include "content/browser/web_contents/web_contents_view.h"
17 #include "content/common/content_export.h"
18 #include "content/common/drag_event_source_info.h"
19 #include "ui/base/cocoa/base_view.h"
20 #include "ui/gfx/geometry/size.h"
28 class PopupMenuHelper
;
29 class WebContentsImpl
;
30 class WebContentsViewDelegate
;
31 class WebContentsViewMac
;
39 @interface WebContentsViewCocoa
: BaseView
{
41 content::WebContentsViewMac
* webContentsView_
; // WEAK; owns us
42 base::scoped_nsobject
<WebDragSource
> dragSource_
;
43 base::scoped_nsobject
<WebDragDest
> dragDest_
;
44 BOOL mouseDownCanMoveWindow_
;
47 - (void)setMouseDownCanMoveWindow
:(BOOL
)canMove
;
48 - (void)setOpaque
:(BOOL
)opaque
;
50 // Expose this, since sometimes one needs both the NSView and the
52 - (content::WebContentsImpl
*)webContents
;
57 // Mac-specific implementation of the WebContentsView. It owns an NSView that
58 // contains all of the contents of the tab and associated child views.
59 class WebContentsViewMac
: public WebContentsView
,
60 public RenderViewHostDelegateView
{
62 // The corresponding WebContentsImpl is passed in the constructor, and manages
63 // our lifetime. This doesn't need to be the case, but is this way currently
64 // because that's what was easiest when they were split.
65 WebContentsViewMac(WebContentsImpl
* web_contents
,
66 WebContentsViewDelegate
* delegate
);
67 ~WebContentsViewMac() override
;
69 // WebContentsView implementation --------------------------------------------
70 gfx::NativeView
GetNativeView() const override
;
71 gfx::NativeView
GetContentNativeView() const override
;
72 gfx::NativeWindow
GetTopLevelNativeWindow() const override
;
73 void GetContainerBounds(gfx::Rect
* out
) const override
;
74 void SizeContents(const gfx::Size
& size
) override
;
75 void Focus() override
;
76 void SetInitialFocus() override
;
77 void StoreFocus() override
;
78 void RestoreFocus() override
;
79 DropData
* GetDropData() const override
;
80 gfx::Rect
GetViewBounds() const override
;
81 void SetAllowOtherViews(bool allow
) override
;
82 bool GetAllowOtherViews() const override
;
83 void CreateView(const gfx::Size
& initial_size
,
84 gfx::NativeView context
) override
;
85 RenderWidgetHostViewBase
* CreateViewForWidget(
86 RenderWidgetHost
* render_widget_host
,
87 bool is_guest_view_hack
) override
;
88 RenderWidgetHostViewBase
* CreateViewForPopupWidget(
89 RenderWidgetHost
* render_widget_host
) override
;
90 void SetPageTitle(const base::string16
& title
) override
;
91 void RenderViewCreated(RenderViewHost
* host
) override
;
92 void RenderViewSwappedIn(RenderViewHost
* host
) override
;
93 void SetOverscrollControllerEnabled(bool enabled
) override
;
94 bool IsEventTracking() const override
;
95 void CloseTabAfterEventTracking() override
;
97 // Backend implementation of RenderViewHostDelegateView.
98 void ShowContextMenu(RenderFrameHost
* render_frame_host
,
99 const ContextMenuParams
& params
) override
;
100 void ShowPopupMenu(RenderFrameHost
* render_frame_host
,
101 const gfx::Rect
& bounds
,
103 double item_font_size
,
105 const std::vector
<MenuItem
>& items
,
107 bool allow_multiple_selection
) override
;
108 void HidePopupMenu() override
;
109 void StartDragging(const DropData
& drop_data
,
110 blink::WebDragOperationsMask allowed_operations
,
111 const gfx::ImageSkia
& image
,
112 const gfx::Vector2d
& image_offset
,
113 const DragEventSourceInfo
& event_info
) override
;
114 void UpdateDragCursor(blink::WebDragOperation operation
) override
;
115 void GotFocus() override
;
116 void TakeFocus(bool reverse
) override
;
118 // A helper method for closing the tab in the
119 // CloseTabAfterEventTracking() implementation.
122 WebContentsImpl
* web_contents() { return web_contents_
; }
123 WebContentsViewDelegate
* delegate() { return delegate_
.get(); }
126 // Returns the fullscreen view, if one exists; otherwise, returns the content
127 // native view. This ensures that the view currently attached to a NSWindow is
128 // being used to query or set first responder state.
129 gfx::NativeView
GetNativeViewForFocus() const;
131 // The WebContentsImpl whose contents we display.
132 WebContentsImpl
* web_contents_
;
134 // The Cocoa NSView that lives in the view hierarchy.
135 base::scoped_nsobject
<WebContentsViewCocoa
> cocoa_view_
;
137 // Keeps track of which NSView has focus so we can restore the focus when
139 base::scoped_nsobject
<FocusTracker
> focus_tracker_
;
141 // Our optional delegate.
142 scoped_ptr
<WebContentsViewDelegate
> delegate_
;
144 // Whether to allow other views.
145 bool allow_other_views_
;
147 scoped_ptr
<PopupMenuHelper
> popup_menu_helper_
;
149 DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac
);
152 } // namespace content
154 #endif // CONTENT_BROWSER_WEB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_