| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 #import <Carbon/Carbon.h> | 5 #import <Carbon/Carbon.h> |
| 6 | 6 |
| 7 #import "content/browser/web_contents/web_contents_view_mac.h" | 7 #import "content/browser/web_contents/web_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "ui/gfx/image/image_skia_util_mac.h" | 29 #include "ui/gfx/image/image_skia_util_mac.h" |
| 30 | 30 |
| 31 using WebKit::WebDragOperation; | 31 using WebKit::WebDragOperation; |
| 32 using WebKit::WebDragOperationsMask; | 32 using WebKit::WebDragOperationsMask; |
| 33 using content::PopupMenuHelper; | 33 using content::PopupMenuHelper; |
| 34 using content::RenderViewHostFactory; | 34 using content::RenderViewHostFactory; |
| 35 using content::RenderWidgetHostView; | 35 using content::RenderWidgetHostView; |
| 36 using content::RenderWidgetHostViewMac; | 36 using content::RenderWidgetHostViewMac; |
| 37 using content::WebContents; | 37 using content::WebContents; |
| 38 using content::WebContentsImpl; | 38 using content::WebContentsImpl; |
| 39 using content::WebContentsViewMac; |
| 39 | 40 |
| 40 // Ensure that the WebKit::WebDragOperation enum values stay in sync with | 41 // Ensure that the WebKit::WebDragOperation enum values stay in sync with |
| 41 // NSDragOperation constants, since the code below static_casts between 'em. | 42 // NSDragOperation constants, since the code below static_casts between 'em. |
| 42 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 43 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 43 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) | 44 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) |
| 44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); | 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationNone); |
| 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); | 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationCopy); |
| 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); | 47 COMPILE_ASSERT_MATCHING_ENUM(DragOperationLink); |
| 47 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); | 48 COMPILE_ASSERT_MATCHING_ENUM(DragOperationGeneric); |
| 48 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); | 49 COMPILE_ASSERT_MATCHING_ENUM(DragOperationPrivate); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 67 | 68 |
| 68 namespace content { | 69 namespace content { |
| 69 WebContentsView* CreateWebContentsView( | 70 WebContentsView* CreateWebContentsView( |
| 70 WebContentsImpl* web_contents, | 71 WebContentsImpl* web_contents, |
| 71 WebContentsViewDelegate* delegate, | 72 WebContentsViewDelegate* delegate, |
| 72 RenderViewHostDelegateView** render_view_host_delegate_view) { | 73 RenderViewHostDelegateView** render_view_host_delegate_view) { |
| 73 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); | 74 WebContentsViewMac* rv = new WebContentsViewMac(web_contents, delegate); |
| 74 *render_view_host_delegate_view = rv; | 75 *render_view_host_delegate_view = rv; |
| 75 return rv; | 76 return rv; |
| 76 } | 77 } |
| 77 } | |
| 78 | 78 |
| 79 WebContentsViewMac::WebContentsViewMac( | 79 WebContentsViewMac::WebContentsViewMac(WebContentsImpl* web_contents, |
| 80 WebContentsImpl* web_contents, | 80 WebContentsViewDelegate* delegate) |
| 81 content::WebContentsViewDelegate* delegate) | |
| 82 : web_contents_(web_contents), | 81 : web_contents_(web_contents), |
| 83 delegate_(delegate) { | 82 delegate_(delegate) { |
| 84 } | 83 } |
| 85 | 84 |
| 86 WebContentsViewMac::~WebContentsViewMac() { | 85 WebContentsViewMac::~WebContentsViewMac() { |
| 87 // This handles the case where a renderer close call was deferred | 86 // This handles the case where a renderer close call was deferred |
| 88 // while the user was operating a UI control which resulted in a | 87 // while the user was operating a UI control which resulted in a |
| 89 // close. In that case, the Cocoa view outlives the | 88 // close. In that case, the Cocoa view outlives the |
| 90 // WebContentsViewMac instance due to Cocoa retain count. | 89 // WebContentsViewMac instance due to Cocoa retain count. |
| 91 [cocoa_view_ cancelDeferredClose]; | 90 [cocoa_view_ cancelDeferredClose]; |
| 92 [cocoa_view_ clearWebContentsView]; | 91 [cocoa_view_ clearWebContentsView]; |
| 93 } | 92 } |
| 94 | 93 |
| 95 void WebContentsViewMac::CreateView(const gfx::Size& initial_size) { | 94 void WebContentsViewMac::CreateView(const gfx::Size& initial_size) { |
| 96 WebContentsViewCocoa* view = | 95 WebContentsViewCocoa* view = |
| 97 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this]; | 96 [[WebContentsViewCocoa alloc] initWithWebContentsViewMac:this]; |
| 98 cocoa_view_.reset(view); | 97 cocoa_view_.reset(view); |
| 99 } | 98 } |
| 100 | 99 |
| 101 RenderWidgetHostView* WebContentsViewMac::CreateViewForWidget( | 100 RenderWidgetHostView* WebContentsViewMac::CreateViewForWidget( |
| 102 content::RenderWidgetHost* render_widget_host) { | 101 RenderWidgetHost* render_widget_host) { |
| 103 if (render_widget_host->GetView()) { | 102 if (render_widget_host->GetView()) { |
| 104 // During testing, the view will already be set up in most cases to the | 103 // During testing, the view will already be set up in most cases to the |
| 105 // test view, so we don't want to clobber it with a real one. To verify that | 104 // test view, so we don't want to clobber it with a real one. To verify that |
| 106 // this actually is happening (and somebody isn't accidentally creating the | 105 // this actually is happening (and somebody isn't accidentally creating the |
| 107 // view twice), we check for the RVH Factory, which will be set when we're | 106 // view twice), we check for the RVH Factory, which will be set when we're |
| 108 // making special ones (which go along with the special views). | 107 // making special ones (which go along with the special views). |
| 109 DCHECK(RenderViewHostFactory::has_factory()); | 108 DCHECK(RenderViewHostFactory::has_factory()); |
| 110 return render_widget_host->GetView(); | 109 return render_widget_host->GetView(); |
| 111 } | 110 } |
| 112 | 111 |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 187 // processing events. | 186 // processing events. |
| 188 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); | 187 MessageLoop::ScopedNestableTaskAllower allow(MessageLoop::current()); |
| 189 NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); | 188 NSDragOperation mask = static_cast<NSDragOperation>(allowed_operations); |
| 190 NSPoint offset = NSPointFromCGPoint(image_offset.ToCGPoint()); | 189 NSPoint offset = NSPointFromCGPoint(image_offset.ToCGPoint()); |
| 191 [cocoa_view_ startDragWithDropData:drop_data | 190 [cocoa_view_ startDragWithDropData:drop_data |
| 192 dragOperationMask:mask | 191 dragOperationMask:mask |
| 193 image:gfx::NSImageFromImageSkia(image) | 192 image:gfx::NSImageFromImageSkia(image) |
| 194 offset:offset]; | 193 offset:offset]; |
| 195 } | 194 } |
| 196 | 195 |
| 197 void WebContentsViewMac::RenderViewCreated(content::RenderViewHost* host) { | 196 void WebContentsViewMac::RenderViewCreated(RenderViewHost* host) { |
| 198 // We want updates whenever the intrinsic width of the webpage changes. | 197 // We want updates whenever the intrinsic width of the webpage changes. |
| 199 // Put the RenderView into that mode. The preferred width is used for example | 198 // Put the RenderView into that mode. The preferred width is used for example |
| 200 // when the "zoom" button in the browser window is clicked. | 199 // when the "zoom" button in the browser window is clicked. |
| 201 host->EnablePreferredSizeMode(); | 200 host->EnablePreferredSizeMode(); |
| 202 } | 201 } |
| 203 | 202 |
| 204 void WebContentsViewMac::SetPageTitle(const string16& title) { | 203 void WebContentsViewMac::SetPageTitle(const string16& title) { |
| 205 // Meaningless on the Mac; widgets don't have a "title" attribute | 204 // Meaningless on the Mac; widgets don't have a "title" attribute |
| 206 } | 205 } |
| 207 | 206 |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 273 // This is called when the renderer asks us to take focus back (i.e., it has | 272 // This is called when the renderer asks us to take focus back (i.e., it has |
| 274 // iterated past the last focusable element on the page). | 273 // iterated past the last focusable element on the page). |
| 275 void WebContentsViewMac::TakeFocus(bool reverse) { | 274 void WebContentsViewMac::TakeFocus(bool reverse) { |
| 276 if (reverse) { | 275 if (reverse) { |
| 277 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; | 276 [[cocoa_view_ window] selectPreviousKeyView:cocoa_view_.get()]; |
| 278 } else { | 277 } else { |
| 279 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; | 278 [[cocoa_view_ window] selectNextKeyView:cocoa_view_.get()]; |
| 280 } | 279 } |
| 281 } | 280 } |
| 282 | 281 |
| 283 void WebContentsViewMac::ShowContextMenu( | 282 void WebContentsViewMac::ShowContextMenu(const ContextMenuParams& params, |
| 284 const content::ContextMenuParams& params, | 283 ContextMenuSourceType type) { |
| 285 content::ContextMenuSourceType type) { | |
| 286 // Allow delegates to handle the context menu operation first. | 284 // Allow delegates to handle the context menu operation first. |
| 287 if (web_contents_->GetDelegate() && | 285 if (web_contents_->GetDelegate() && |
| 288 web_contents_->GetDelegate()->HandleContextMenu(params)) { | 286 web_contents_->GetDelegate()->HandleContextMenu(params)) { |
| 289 return; | 287 return; |
| 290 } | 288 } |
| 291 | 289 |
| 292 if (delegate()) | 290 if (delegate()) |
| 293 delegate()->ShowContextMenu(params, type); | 291 delegate()->ShowContextMenu(params, type); |
| 294 else | 292 else |
| 295 DLOG(ERROR) << "Cannot show context menus without a delegate."; | 293 DLOG(ERROR) << "Cannot show context menus without a delegate."; |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 328 gfx::Rect WebContentsViewMac::GetViewBounds() const { | 326 gfx::Rect WebContentsViewMac::GetViewBounds() const { |
| 329 // This method is not currently used on mac. | 327 // This method is not currently used on mac. |
| 330 NOTIMPLEMENTED(); | 328 NOTIMPLEMENTED(); |
| 331 return gfx::Rect(); | 329 return gfx::Rect(); |
| 332 } | 330 } |
| 333 | 331 |
| 334 void WebContentsViewMac::CloseTab() { | 332 void WebContentsViewMac::CloseTab() { |
| 335 web_contents_->Close(web_contents_->GetRenderViewHost()); | 333 web_contents_->Close(web_contents_->GetRenderViewHost()); |
| 336 } | 334 } |
| 337 | 335 |
| 336 } // namespace content |
| 337 |
| 338 @implementation WebContentsViewCocoa | 338 @implementation WebContentsViewCocoa |
| 339 | 339 |
| 340 - (id)initWithWebContentsViewMac:(WebContentsViewMac*)w { | 340 - (id)initWithWebContentsViewMac:(WebContentsViewMac*)w { |
| 341 self = [super initWithFrame:NSZeroRect]; | 341 self = [super initWithFrame:NSZeroRect]; |
| 342 if (self != nil) { | 342 if (self != nil) { |
| 343 webContentsView_ = w; | 343 webContentsView_ = w; |
| 344 dragDest_.reset( | 344 dragDest_.reset( |
| 345 [[WebDragDest alloc] initWithWebContentsImpl:[self webContents]]); | 345 [[WebDragDest alloc] initWithWebContentsImpl:[self webContents]]); |
| 346 [self registerDragTypes]; | 346 [self registerDragTypes]; |
| 347 | 347 |
| (...skipping 183 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 531 [[[notification userInfo] objectForKey:kSelectionDirection] | 531 [[[notification userInfo] objectForKey:kSelectionDirection] |
| 532 unsignedIntegerValue]; | 532 unsignedIntegerValue]; |
| 533 if (direction == NSDirectSelection) | 533 if (direction == NSDirectSelection) |
| 534 return; | 534 return; |
| 535 | 535 |
| 536 [self webContents]-> | 536 [self webContents]-> |
| 537 FocusThroughTabTraversal(direction == NSSelectingPrevious); | 537 FocusThroughTabTraversal(direction == NSSelectingPrevious); |
| 538 } | 538 } |
| 539 | 539 |
| 540 @end | 540 @end |
| OLD | NEW |