Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(358)

Side by Side Diff: chrome/browser/tab_contents/web_contents_view_mac.mm

Issue 49041: WebContentsView became more than just an interface with 48103 (r12483). If we... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 11 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/tab_contents/web_contents_view_mac.h" 5 #include "chrome/browser/tab_contents/web_contents_view_mac.h"
6 6
7 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. 7 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
8 #include "chrome/browser/cocoa/sad_tab_view.h" 8 #include "chrome/browser/cocoa/sad_tab_view.h"
9 #include "chrome/browser/renderer_host/render_widget_host.h" 9 #include "chrome/browser/renderer_host/render_widget_host.h"
10 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h" 10 #include "chrome/browser/renderer_host/render_widget_host_view_mac.h"
(...skipping 16 matching lines...) Expand all
27 : WebContentsView(web_contents) { 27 : WebContentsView(web_contents) {
28 registrar_.Add(this, NotificationType::WEB_CONTENTS_CONNECTED, 28 registrar_.Add(this, NotificationType::WEB_CONTENTS_CONNECTED,
29 Source<WebContents>(web_contents)); 29 Source<WebContents>(web_contents));
30 registrar_.Add(this, NotificationType::WEB_CONTENTS_DISCONNECTED, 30 registrar_.Add(this, NotificationType::WEB_CONTENTS_DISCONNECTED,
31 Source<WebContents>(web_contents)); 31 Source<WebContents>(web_contents));
32 } 32 }
33 33
34 WebContentsViewMac::~WebContentsViewMac() { 34 WebContentsViewMac::~WebContentsViewMac() {
35 } 35 }
36 36
37 WebContents* WebContentsViewMac::GetWebContents() {
38 return web_contents_;
39 }
40
41 void WebContentsViewMac::CreateView() { 37 void WebContentsViewMac::CreateView() {
42 WebContentsViewCocoa* view = 38 WebContentsViewCocoa* view =
43 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this]; 39 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this];
44 cocoa_view_.reset(view); 40 cocoa_view_.reset(view);
45 } 41 }
46 42
47 RenderWidgetHostView* WebContentsViewMac::CreateViewForWidget( 43 RenderWidgetHostView* WebContentsViewMac::CreateViewForWidget(
48 RenderWidgetHost* render_widget_host) { 44 RenderWidgetHost* render_widget_host) {
49 DCHECK(!render_widget_host->view()); 45 DCHECK(!render_widget_host->view());
50 RenderWidgetHostViewMac* view = 46 RenderWidgetHostViewMac* view =
51 new RenderWidgetHostViewMac(render_widget_host); 47 new RenderWidgetHostViewMac(render_widget_host);
52 48
53 // Fancy layout comes later; for now just make it our size and resize it 49 // Fancy layout comes later; for now just make it our size and resize it
54 // with us. 50 // with us.
55 NSView* view_view = view->native_view(); 51 NSView* view_view = view->native_view();
56 [cocoa_view_.get() addSubview:view_view]; 52 [cocoa_view_.get() addSubview:view_view];
57 [view_view setFrame:[cocoa_view_.get() bounds]]; 53 [view_view setFrame:[cocoa_view_.get() bounds]];
58 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; 54 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable];
59 55
60 return view; 56 return view;
61 } 57 }
62 58
63 gfx::NativeView WebContentsViewMac::GetNativeView() const { 59 gfx::NativeView WebContentsViewMac::GetNativeView() const {
64 return cocoa_view_.get(); 60 return cocoa_view_.get();
65 } 61 }
66 62
67 gfx::NativeView WebContentsViewMac::GetContentNativeView() const { 63 gfx::NativeView WebContentsViewMac::GetContentNativeView() const {
68 if (!web_contents_->render_widget_host_view()) 64 if (!web_contents()->render_widget_host_view())
69 return NULL; 65 return NULL;
70 return web_contents_->render_widget_host_view()->GetPluginNativeView(); 66 return web_contents()->render_widget_host_view()->GetPluginNativeView();
71 } 67 }
72 68
73 gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeWindow() const { 69 gfx::NativeWindow WebContentsViewMac::GetTopLevelNativeWindow() const {
74 return [cocoa_view_.get() window]; 70 return [cocoa_view_.get() window];
75 } 71 }
76 72
77 void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const { 73 void WebContentsViewMac::GetContainerBounds(gfx::Rect* out) const {
78 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]]; 74 *out = [cocoa_view_.get() NSRectToRect:[cocoa_view_.get() bounds]];
79 } 75 }
80 76
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 const gfx::Rect& selection_rect, 166 const gfx::Rect& selection_rect,
171 int active_match_ordinal, 167 int active_match_ordinal,
172 bool final_update) { 168 bool final_update) {
173 if (find_bar_.get()) { 169 if (find_bar_.get()) {
174 find_bar_->OnFindReply(request_id, number_of_matches, selection_rect, 170 find_bar_->OnFindReply(request_id, number_of_matches, selection_rect,
175 active_match_ordinal, final_update); 171 active_match_ordinal, final_update);
176 } 172 }
177 } 173 }
178 174
179 void WebContentsViewMac::ShowContextMenu(const ContextMenuParams& params) { 175 void WebContentsViewMac::ShowContextMenu(const ContextMenuParams& params) {
180 RenderViewContextMenuMac menu(web_contents_, 176 RenderViewContextMenuMac menu(web_contents(),
181 params, 177 params,
182 GetNativeView()); 178 GetNativeView());
183 } 179 }
184 180
185 WebContents* WebContentsViewMac::CreateNewWindowInternal( 181 WebContents* WebContentsViewMac::CreateNewWindowInternal(
186 int route_id, 182 int route_id,
187 base::WaitableEvent* modal_dialog_event) { 183 base::WaitableEvent* modal_dialog_event) {
188 // Create the new web contents. This will automatically create the new 184 // Create the new web contents. This will automatically create the new
189 // WebContentsView. In the future, we may want to create the view separately. 185 // WebContentsView. In the future, we may want to create the view separately.
190 WebContents* new_contents = 186 WebContents* new_contents =
191 new WebContents(web_contents_->profile(), 187 new WebContents(web_contents()->profile(),
192 web_contents_->GetSiteInstance(), 188 web_contents()->GetSiteInstance(),
193 web_contents_->render_view_factory_, 189 web_contents()->render_view_factory_,
194 route_id, 190 route_id,
195 modal_dialog_event); 191 modal_dialog_event);
196 new_contents->SetupController(web_contents_->profile()); 192 new_contents->SetupController(web_contents()->profile());
197 WebContentsView* new_view = new_contents->view(); 193 WebContentsView* new_view = new_contents->view();
198 194
199 new_view->CreateView(); 195 new_view->CreateView();
200 196
201 // TODO(brettw) it seems bogus that we have to call this function on the 197 // TODO(brettw) it seems bogus that we have to call this function on the
202 // newly created object and give it one of its own member variables. 198 // newly created object and give it one of its own member variables.
203 new_view->CreateViewForWidget(new_contents->render_view_host()); 199 new_view->CreateViewForWidget(new_contents->render_view_host());
204 return new_contents; 200 return new_contents;
205 } 201 }
206 202
207 void WebContentsViewMac::ShowCreatedWindowInternal( 203 void WebContentsViewMac::ShowCreatedWindowInternal(
208 WebContents* new_web_contents, 204 WebContents* new_web_contents,
209 WindowOpenDisposition disposition, 205 WindowOpenDisposition disposition,
210 const gfx::Rect& initial_pos, 206 const gfx::Rect& initial_pos,
211 bool user_gesture) { 207 bool user_gesture) {
212 if (!new_web_contents->render_widget_host_view() || 208 if (!new_web_contents->render_widget_host_view() ||
213 !new_web_contents->process()->channel()) { 209 !new_web_contents->process()->channel()) {
214 // The view has gone away or the renderer crashed. Nothing to do. 210 // The view has gone away or the renderer crashed. Nothing to do.
215 return; 211 return;
216 } 212 }
217 213
218 // TODO(brettw) this seems bogus to reach into here and initialize the host. 214 // TODO(brettw) this seems bogus to reach into here and initialize the host.
219 new_web_contents->render_view_host()->Init(); 215 new_web_contents->render_view_host()->Init();
220 web_contents_->AddNewContents(new_web_contents, disposition, initial_pos, 216 web_contents()->AddNewContents(new_web_contents, disposition, initial_pos,
221 user_gesture); 217 user_gesture);
222 } 218 }
223 219
224 void WebContentsViewMac::Observe(NotificationType type, 220 void WebContentsViewMac::Observe(NotificationType type,
225 const NotificationSource& source, 221 const NotificationSource& source,
226 const NotificationDetails& details) { 222 const NotificationDetails& details) {
227 switch (type.value) { 223 switch (type.value) {
228 case NotificationType::WEB_CONTENTS_CONNECTED: { 224 case NotificationType::WEB_CONTENTS_CONNECTED: {
229 if (sad_tab_.get()) { 225 if (sad_tab_.get()) {
230 [sad_tab_.get() removeFromSuperview]; 226 [sad_tab_.get() removeFromSuperview];
231 sad_tab_.reset(); 227 sad_tab_.reset();
(...skipping 26 matching lines...) Expand all
258 } 254 }
259 255
260 - (void)processKeyboardEvent:(NSEvent*)event { 256 - (void)processKeyboardEvent:(NSEvent*)event {
261 if ([event type] == NSKeyDown) 257 if ([event type] == NSKeyDown)
262 [super keyDown:event]; 258 [super keyDown:event];
263 else if ([event type] == NSKeyUp) 259 else if ([event type] == NSKeyUp)
264 [super keyUp:event]; 260 [super keyUp:event];
265 } 261 }
266 262
267 - (void)mouseEvent:(NSEvent *)theEvent { 263 - (void)mouseEvent:(NSEvent *)theEvent {
268 if (webContentsView_->GetWebContents()->delegate()) { 264 if (webContentsView_->web_contents()->delegate()) {
269 if ([theEvent type] == NSMouseMoved) 265 if ([theEvent type] == NSMouseMoved)
270 webContentsView_->GetWebContents()->delegate()-> 266 webContentsView_->web_contents()->delegate()->
271 ContentsMouseEvent(webContentsView_->GetWebContents(), true); 267 ContentsMouseEvent(webContentsView_->web_contents(), true);
272 if ([theEvent type] == NSMouseExited) 268 if ([theEvent type] == NSMouseExited)
273 webContentsView_->GetWebContents()->delegate()-> 269 webContentsView_->web_contents()->delegate()->
274 ContentsMouseEvent(webContentsView_->GetWebContents(), false); 270 ContentsMouseEvent(webContentsView_->web_contents(), false);
275 } 271 }
276 } 272 }
277 273
278 // In the Windows version, we always have cut/copy/paste enabled. This is sub- 274 // In the Windows version, we always have cut/copy/paste enabled. This is sub-
279 // optimal, but we do it too. TODO(avi): Plumb the "can*" methods up from 275 // optimal, but we do it too. TODO(avi): Plumb the "can*" methods up from
280 // WebCore. 276 // WebCore.
281 277
282 - (void)cut:(id)sender { 278 - (void)cut:(id)sender {
283 webContentsView_->GetWebContents()->Cut(); 279 webContentsView_->web_contents()->Cut();
284 } 280 }
285 281
286 - (void)copy:(id)sender { 282 - (void)copy:(id)sender {
287 webContentsView_->GetWebContents()->Copy(); 283 webContentsView_->web_contents()->Copy();
288 } 284 }
289 285
290 - (void)paste:(id)sender { 286 - (void)paste:(id)sender {
291 webContentsView_->GetWebContents()->Paste(); 287 webContentsView_->web_contents()->Paste();
292 } 288 }
293 289
294 // Tons of stuff goes here, where we grab events going on in Cocoaland and send 290 // Tons of stuff goes here, where we grab events going on in Cocoaland and send
295 // them into the C++ system. TODO(avi): all that jazz 291 // them into the C++ system. TODO(avi): all that jazz
296 292
297 @end 293 @end
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/web_contents_view_mac.h ('k') | chrome/browser/tab_contents/web_contents_view_win.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698