| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" | 7 #include "chrome/browser/tab_contents/tab_contents_view_mac.h" |
| 8 | 8 |
| 9 #include <string> | 9 #include <string> |
| 10 | 10 |
| 11 #include "chrome/browser/browser_shutdown.h" | |
| 12 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat
e.h" | 11 #import "chrome/browser/renderer_host/chrome_render_widget_host_view_mac_delegat
e.h" |
| 13 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" | 12 #include "chrome/browser/tab_contents/render_view_context_menu_mac.h" |
| 14 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" | 13 #include "chrome/browser/tab_contents/web_drag_bookmark_handler_mac.h" |
| 15 #import "chrome/browser/ui/cocoa/focus_tracker.h" | 14 #import "chrome/browser/ui/cocoa/focus_tracker.h" |
| 16 #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" | |
| 17 #import "chrome/browser/ui/cocoa/view_id_util.h" | 15 #import "chrome/browser/ui/cocoa/view_id_util.h" |
| 18 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
| 19 #include "content/browser/renderer_host/render_view_host_factory.h" | 17 #include "content/browser/renderer_host/render_view_host_factory.h" |
| 20 #include "content/browser/renderer_host/render_widget_host.h" | 18 #include "content/browser/renderer_host/render_widget_host.h" |
| 21 #include "content/browser/renderer_host/render_widget_host_view_mac.h" | 19 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
| 22 #include "content/browser/tab_contents/popup_menu_helper_mac.h" | 20 #include "content/browser/tab_contents/popup_menu_helper_mac.h" |
| 23 #include "content/browser/tab_contents/tab_contents.h" | 21 #include "content/browser/tab_contents/tab_contents.h" |
| 24 #include "content/browser/tab_contents/tab_contents_delegate.h" | 22 #include "content/browser/tab_contents/tab_contents_delegate.h" |
| 25 #import "content/browser/tab_contents/web_drag_dest_mac.h" | 23 #import "content/browser/tab_contents/web_drag_dest_mac.h" |
| 26 #import "content/browser/tab_contents/web_drag_source_mac.h" | 24 #import "content/browser/tab_contents/web_drag_source_mac.h" |
| 27 #import "content/common/chrome_application_mac.h" | 25 #import "content/common/chrome_application_mac.h" |
| 28 #import "content/common/mac/scoped_sending_event.h" | 26 #import "content/common/mac/scoped_sending_event.h" |
| 29 #include "content/common/view_messages.h" | 27 #include "content/common/view_messages.h" |
| 30 #include "content/public/browser/notification_details.h" | |
| 31 #include "content/public/browser/notification_source.h" | |
| 32 #include "content/public/browser/notification_types.h" | |
| 33 #include "skia/ext/skia_utils_mac.h" | 28 #include "skia/ext/skia_utils_mac.h" |
| 34 #import "third_party/mozilla/NSPasteboard+Utils.h" | 29 #import "third_party/mozilla/NSPasteboard+Utils.h" |
| 35 | 30 |
| 36 using WebKit::WebDragOperation; | 31 using WebKit::WebDragOperation; |
| 37 using WebKit::WebDragOperationsMask; | 32 using WebKit::WebDragOperationsMask; |
| 38 | 33 |
| 39 // Ensure that the WebKit::WebDragOperation enum values stay in sync with | 34 // Ensure that the WebKit::WebDragOperation enum values stay in sync with |
| 40 // NSDragOperation constants, since the code below static_casts between 'em. | 35 // NSDragOperation constants, since the code below static_casts between 'em. |
| 41 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ | 36 #define COMPILE_ASSERT_MATCHING_ENUM(name) \ |
| 42 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) | 37 COMPILE_ASSERT(int(NS##name) == int(WebKit::Web##name), enum_mismatch_##name) |
| (...skipping 21 matching lines...) Expand all Loading... |
| 64 @end | 59 @end |
| 65 | 60 |
| 66 namespace tab_contents_view_mac { | 61 namespace tab_contents_view_mac { |
| 67 TabContentsView* CreateTabContentsView(TabContents* tab_contents) { | 62 TabContentsView* CreateTabContentsView(TabContents* tab_contents) { |
| 68 return new TabContentsViewMac(tab_contents); | 63 return new TabContentsViewMac(tab_contents); |
| 69 } | 64 } |
| 70 } | 65 } |
| 71 | 66 |
| 72 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) | 67 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) |
| 73 : tab_contents_(tab_contents), | 68 : tab_contents_(tab_contents), |
| 74 preferred_width_(0) { | 69 preferred_width_(0), |
| 75 registrar_.Add(this, content::NOTIFICATION_TAB_CONTENTS_CONNECTED, | 70 overlaid_view_(nil) { |
| 76 content::Source<TabContents>(tab_contents)); | |
| 77 } | 71 } |
| 78 | 72 |
| 79 TabContentsViewMac::~TabContentsViewMac() { | 73 TabContentsViewMac::~TabContentsViewMac() { |
| 80 // This handles the case where a renderer close call was deferred | 74 // This handles the case where a renderer close call was deferred |
| 81 // while the user was operating a UI control which resulted in a | 75 // while the user was operating a UI control which resulted in a |
| 82 // close. In that case, the Cocoa view outlives the | 76 // close. In that case, the Cocoa view outlives the |
| 83 // TabContentsViewMac instance due to Cocoa retain count. | 77 // TabContentsViewMac instance due to Cocoa retain count. |
| 84 [cocoa_view_ cancelDeferredClose]; | 78 [cocoa_view_ cancelDeferredClose]; |
| 85 [cocoa_view_ clearTabContentsView]; | 79 [cocoa_view_ clearTabContentsView]; |
| 86 } | 80 } |
| (...skipping 26 matching lines...) Expand all Loading... |
| 113 initWithRenderWidgetHost:render_widget_host]; | 107 initWithRenderWidgetHost:render_widget_host]; |
| 114 view->SetDelegate((RenderWidgetHostViewMacDelegate*)rw_delegate); | 108 view->SetDelegate((RenderWidgetHostViewMacDelegate*)rw_delegate); |
| 115 | 109 |
| 116 // Fancy layout comes later; for now just make it our size and resize it | 110 // Fancy layout comes later; for now just make it our size and resize it |
| 117 // with us. In case there are other siblings of the content area, we want | 111 // with us. In case there are other siblings of the content area, we want |
| 118 // to make sure the content area is on the bottom so other things draw over | 112 // to make sure the content area is on the bottom so other things draw over |
| 119 // it. | 113 // it. |
| 120 NSView* view_view = view->native_view(); | 114 NSView* view_view = view->native_view(); |
| 121 [view_view setFrame:[cocoa_view_.get() bounds]]; | 115 [view_view setFrame:[cocoa_view_.get() bounds]]; |
| 122 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; | 116 [view_view setAutoresizingMask:NSViewWidthSizable | NSViewHeightSizable]; |
| 117 // Add the new view below all other views; this also keeps it below any |
| 118 // overlay view installed. |
| 123 [cocoa_view_.get() addSubview:view_view | 119 [cocoa_view_.get() addSubview:view_view |
| 124 positioned:NSWindowBelow | 120 positioned:NSWindowBelow |
| 125 relativeTo:nil]; | 121 relativeTo:nil]; |
| 126 // For some reason known only to Cocoa, the autorecalculation of the key view | 122 // For some reason known only to Cocoa, the autorecalculation of the key view |
| 127 // loop set on the window doesn't set the next key view when the subview is | 123 // loop set on the window doesn't set the next key view when the subview is |
| 128 // added. On 10.6 things magically work fine; on 10.5 they fail | 124 // added. On 10.6 things magically work fine; on 10.5 they fail |
| 129 // <http://crbug.com/61493>. Digging into Cocoa key view loop code yielded | 125 // <http://crbug.com/61493>. Digging into Cocoa key view loop code yielded |
| 130 // madness; TODO(avi,rohit): look at this again and figure out what's really | 126 // madness; TODO(avi,rohit): look at this again and figure out what's really |
| 131 // going on. | 127 // going on. |
| 132 [cocoa_view_.get() setNextKeyView:view_view]; | 128 [cocoa_view_.get() setNextKeyView:view_view]; |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 // when the "zoom" button in the browser window is clicked. | 177 // when the "zoom" button in the browser window is clicked. |
| 182 host->EnablePreferredSizeMode(kPreferredSizeWidth); | 178 host->EnablePreferredSizeMode(kPreferredSizeWidth); |
| 183 } | 179 } |
| 184 | 180 |
| 185 void TabContentsViewMac::SetPageTitle(const string16& title) { | 181 void TabContentsViewMac::SetPageTitle(const string16& title) { |
| 186 // Meaningless on the Mac; widgets don't have a "title" attribute | 182 // Meaningless on the Mac; widgets don't have a "title" attribute |
| 187 } | 183 } |
| 188 | 184 |
| 189 void TabContentsViewMac::OnTabCrashed(base::TerminationStatus /* status */, | 185 void TabContentsViewMac::OnTabCrashed(base::TerminationStatus /* status */, |
| 190 int /* error_code */) { | 186 int /* error_code */) { |
| 191 // Only show the sad tab if we're not in browser shutdown, so that TabContents | |
| 192 // objects that are not in a browser (e.g., HTML dialogs) and thus are | |
| 193 // visible do not flash a sad tab page. | |
| 194 if (browser_shutdown::GetShutdownType() != browser_shutdown::NOT_VALID) | |
| 195 return; | |
| 196 | |
| 197 if (!sad_tab_.get()) { | |
| 198 DCHECK(tab_contents_); | |
| 199 if (tab_contents_) { | |
| 200 SadTabController* sad_tab = | |
| 201 [[SadTabController alloc] initWithTabContents:tab_contents_ | |
| 202 superview:cocoa_view_]; | |
| 203 sad_tab_.reset(sad_tab); | |
| 204 } | |
| 205 } | |
| 206 } | 187 } |
| 207 | 188 |
| 208 void TabContentsViewMac::SizeContents(const gfx::Size& size) { | 189 void TabContentsViewMac::SizeContents(const gfx::Size& size) { |
| 209 // TODO(brettw | japhet) This is a hack and should be removed. | 190 // TODO(brettw | japhet) This is a hack and should be removed. |
| 210 // See tab_contents_view.h. | 191 // See tab_contents_view.h. |
| 211 gfx::Rect rect(gfx::Point(), size); | 192 gfx::Rect rect(gfx::Point(), size); |
| 212 TabContentsViewCocoa* view = cocoa_view_.get(); | 193 TabContentsViewCocoa* view = cocoa_view_.get(); |
| 213 [view setFrame:[view flipRectToNSRect:rect]]; | 194 [view setFrame:[view flipRectToNSRect:rect]]; |
| 214 } | 195 } |
| 215 | 196 |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 390 [cocoa_view_ performSelector:@selector(closeTabAfterEvent) | 371 [cocoa_view_ performSelector:@selector(closeTabAfterEvent) |
| 391 withObject:nil | 372 withObject:nil |
| 392 afterDelay:0.0]; | 373 afterDelay:0.0]; |
| 393 } | 374 } |
| 394 | 375 |
| 395 void TabContentsViewMac::GetViewBounds(gfx::Rect* out) const { | 376 void TabContentsViewMac::GetViewBounds(gfx::Rect* out) const { |
| 396 // This method is not currently used on mac. | 377 // This method is not currently used on mac. |
| 397 NOTIMPLEMENTED(); | 378 NOTIMPLEMENTED(); |
| 398 } | 379 } |
| 399 | 380 |
| 381 void TabContentsViewMac::InstallOverlayView(gfx::NativeView view) { |
| 382 DCHECK(!overlaid_view_); |
| 383 overlaid_view_ = view; |
| 384 [view setAutoresizingMask:(NSViewWidthSizable | NSViewHeightSizable)]; |
| 385 [cocoa_view_.get() addSubview:view]; |
| 386 [view setFrame:[cocoa_view_.get() bounds]]; |
| 387 } |
| 388 |
| 389 void TabContentsViewMac::RemoveOverlayView() { |
| 390 DCHECK(overlaid_view_); |
| 391 [overlaid_view_ removeFromSuperview]; |
| 392 overlaid_view_ = nil; |
| 393 } |
| 394 |
| 400 void TabContentsViewMac::CloseTab() { | 395 void TabContentsViewMac::CloseTab() { |
| 401 tab_contents_->Close(tab_contents_->render_view_host()); | 396 tab_contents_->Close(tab_contents_->render_view_host()); |
| 402 } | 397 } |
| 403 | 398 |
| 404 void TabContentsViewMac::Observe(int type, | |
| 405 const content::NotificationSource& source, | |
| 406 const content::NotificationDetails& details) { | |
| 407 switch (type) { | |
| 408 case content::NOTIFICATION_TAB_CONTENTS_CONNECTED: { | |
| 409 sad_tab_.reset(); | |
| 410 break; | |
| 411 } | |
| 412 default: | |
| 413 NOTREACHED() << "Got a notification we didn't register for."; | |
| 414 } | |
| 415 } | |
| 416 | |
| 417 @implementation TabContentsViewCocoa | 399 @implementation TabContentsViewCocoa |
| 418 | 400 |
| 419 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w { | 401 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w { |
| 420 self = [super initWithFrame:NSZeroRect]; | 402 self = [super initWithFrame:NSZeroRect]; |
| 421 if (self != nil) { | 403 if (self != nil) { |
| 422 tabContentsView_ = w; | 404 tabContentsView_ = w; |
| 423 dragDest_.reset( | 405 dragDest_.reset( |
| 424 [[WebDragDest alloc] initWithTabContents:[self tabContents]]); | 406 [[WebDragDest alloc] initWithTabContents:[self tabContents]]); |
| 425 bookmarkHandler_.reset(new WebDragBookmarkHandlerMac); | 407 bookmarkHandler_.reset(new WebDragBookmarkHandlerMac); |
| 426 [dragDest_ setDragDelegate: | 408 [dragDest_ setDragDelegate: |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 597 [[[notification userInfo] objectForKey:kSelectionDirection] | 579 [[[notification userInfo] objectForKey:kSelectionDirection] |
| 598 unsignedIntegerValue]; | 580 unsignedIntegerValue]; |
| 599 if (direction == NSDirectSelection) | 581 if (direction == NSDirectSelection) |
| 600 return; | 582 return; |
| 601 | 583 |
| 602 [self tabContents]-> | 584 [self tabContents]-> |
| 603 FocusThroughTabTraversal(direction == NSSelectingPrevious); | 585 FocusThroughTabTraversal(direction == NSSelectingPrevious); |
| 604 } | 586 } |
| 605 | 587 |
| 606 @end | 588 @end |
| OLD | NEW |