OLD | NEW |
| (Empty) |
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. | |
4 | |
5 #ifndef CONTENT_BROWSER_TAB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_ | |
6 #define CONTENT_BROWSER_TAB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_ | |
7 #pragma once | |
8 | |
9 #if defined(__OBJC__) | |
10 | |
11 #import <Cocoa/Cocoa.h> | |
12 | |
13 #include <string> | |
14 #include <vector> | |
15 | |
16 #include "base/memory/scoped_nsobject.h" | |
17 #include "base/memory/scoped_ptr.h" | |
18 #include "content/browser/tab_contents/tab_contents_view_helper.h" | |
19 #include "content/public/browser/web_contents_view.h" | |
20 #include "ui/base/cocoa/base_view.h" | |
21 #include "ui/gfx/size.h" | |
22 | |
23 @class FocusTracker; | |
24 class SkBitmap; | |
25 class WebContentsViewMac; | |
26 @class WebDragDest; | |
27 @class WebDragSource; | |
28 | |
29 namespace content { | |
30 class WebContentsViewDelegate; | |
31 } | |
32 | |
33 namespace gfx { | |
34 class Point; | |
35 } | |
36 | |
37 @interface WebContentsViewCocoa : BaseView { | |
38 @private | |
39 WebContentsViewMac* webContentsView_; // WEAK; owns us | |
40 scoped_nsobject<WebDragSource> dragSource_; | |
41 scoped_nsobject<WebDragDest> dragDest_; | |
42 } | |
43 | |
44 // Expose this, since sometimes one needs both the NSView and the | |
45 // WebContentsImpl. | |
46 - (WebContentsImpl*)webContents; | |
47 @end | |
48 | |
49 // Mac-specific implementation of the WebContentsView. It owns an NSView that | |
50 // contains all of the contents of the tab and associated child views. | |
51 class WebContentsViewMac : public content::WebContentsView { | |
52 public: | |
53 // The corresponding WebContentsImpl is passed in the constructor, and manages | |
54 // our lifetime. This doesn't need to be the case, but is this way currently | |
55 // because that's what was easiest when they were split. | |
56 WebContentsViewMac(WebContentsImpl* web_contents, | |
57 content::WebContentsViewDelegate* delegate); | |
58 virtual ~WebContentsViewMac(); | |
59 | |
60 // WebContentsView implementation -------------------------------------------- | |
61 | |
62 virtual void CreateView(const gfx::Size& initial_size) OVERRIDE; | |
63 virtual content::RenderWidgetHostView* CreateViewForWidget( | |
64 content::RenderWidgetHost* render_widget_host) OVERRIDE; | |
65 virtual gfx::NativeView GetNativeView() const OVERRIDE; | |
66 virtual gfx::NativeView GetContentNativeView() const OVERRIDE; | |
67 virtual gfx::NativeWindow GetTopLevelNativeWindow() const OVERRIDE; | |
68 virtual void GetContainerBounds(gfx::Rect* out) const OVERRIDE; | |
69 virtual void RenderViewCreated(content::RenderViewHost* host) OVERRIDE; | |
70 virtual void SetPageTitle(const string16& title) OVERRIDE; | |
71 virtual void OnTabCrashed(base::TerminationStatus status, | |
72 int error_code) OVERRIDE; | |
73 virtual void SizeContents(const gfx::Size& size) OVERRIDE; | |
74 virtual void Focus() OVERRIDE; | |
75 virtual void SetInitialFocus() OVERRIDE; | |
76 virtual void StoreFocus() OVERRIDE; | |
77 virtual void RestoreFocus() OVERRIDE; | |
78 virtual bool IsDoingDrag() const OVERRIDE; | |
79 virtual void CancelDragAndCloseTab() OVERRIDE; | |
80 virtual bool IsEventTracking() const OVERRIDE; | |
81 virtual void CloseTabAfterEventTracking() OVERRIDE; | |
82 virtual void GetViewBounds(gfx::Rect* out) const OVERRIDE; | |
83 | |
84 // Backend implementation of RenderViewHostDelegate::View. | |
85 virtual void CreateNewWindow( | |
86 int route_id, | |
87 const ViewHostMsg_CreateWindow_Params& params) OVERRIDE; | |
88 virtual void CreateNewWidget(int route_id, | |
89 WebKit::WebPopupType popup_type) OVERRIDE; | |
90 virtual void CreateNewFullscreenWidget(int route_id) OVERRIDE; | |
91 virtual void ShowCreatedWindow(int route_id, | |
92 WindowOpenDisposition disposition, | |
93 const gfx::Rect& initial_pos, | |
94 bool user_gesture) OVERRIDE; | |
95 virtual void ShowCreatedWidget(int route_id, | |
96 const gfx::Rect& initial_pos) OVERRIDE; | |
97 virtual void ShowCreatedFullscreenWidget(int route_id) OVERRIDE; | |
98 virtual void ShowContextMenu( | |
99 const content::ContextMenuParams& params) 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) OVERRIDE; | |
106 virtual void StartDragging(const WebDropData& drop_data, | |
107 WebKit::WebDragOperationsMask allowed_operations, | |
108 const SkBitmap& image, | |
109 const gfx::Point& image_offset) OVERRIDE; | |
110 virtual void UpdateDragCursor(WebKit::WebDragOperation operation) OVERRIDE; | |
111 virtual void GotFocus() OVERRIDE; | |
112 virtual void TakeFocus(bool reverse) OVERRIDE; | |
113 | |
114 // A helper method for closing the tab in the | |
115 // CloseTabAfterEventTracking() implementation. | |
116 void CloseTab(); | |
117 | |
118 WebContentsImpl* web_contents() { return web_contents_; } | |
119 content::WebContentsViewDelegate* delegate() { return delegate_.get(); } | |
120 | |
121 private: | |
122 // The WebContentsImpl whose contents we display. | |
123 WebContentsImpl* web_contents_; | |
124 | |
125 // Common implementations of some WebContentsView methods. | |
126 TabContentsViewHelper tab_contents_view_helper_; | |
127 | |
128 // The Cocoa NSView that lives in the view hierarchy. | |
129 scoped_nsobject<WebContentsViewCocoa> cocoa_view_; | |
130 | |
131 // Keeps track of which NSView has focus so we can restore the focus when | |
132 // focus returns. | |
133 scoped_nsobject<FocusTracker> focus_tracker_; | |
134 | |
135 // Our optional delegate. | |
136 scoped_ptr<content::WebContentsViewDelegate> delegate_; | |
137 | |
138 DISALLOW_COPY_AND_ASSIGN(WebContentsViewMac); | |
139 }; | |
140 | |
141 #endif // __OBJC__ | |
142 | |
143 // Functions that may be accessed from non-Objective-C C/C++ code. | |
144 namespace content { | |
145 class WebContents; | |
146 class WebContentsView; | |
147 class WebContentsViewDelegate; | |
148 } | |
149 | |
150 namespace web_contents_view_mac { | |
151 // Creates a WebContentsViewMac. Takes ownership of |delegate|. | |
152 CONTENT_EXPORT content::WebContentsView* CreateWebContentsView( | |
153 WebContentsImpl* web_contents, | |
154 content::WebContentsViewDelegate* delegate); | |
155 } | |
156 | |
157 #endif // CONTENT_BROWSER_TAB_CONTENTS_WEB_CONTENTS_VIEW_MAC_H_ | |
OLD | NEW |