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

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

Issue 362013: [Mac] Delay TabContents::Close() when event-tracking. (Closed)
Patch Set: Oops, included file moved. Created 11 years, 1 month 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
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_mac.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #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 #import "base/chrome_application_mac.h"
11 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful. 12 #include "chrome/browser/browser.h" // TODO(beng): this dependency is awful.
12 #import "chrome/browser/cocoa/focus_tracker.h" 13 #import "chrome/browser/cocoa/focus_tracker.h"
13 #import "chrome/browser/cocoa/chrome_browser_window.h" 14 #import "chrome/browser/cocoa/chrome_browser_window.h"
14 #import "chrome/browser/cocoa/browser_window_controller.h" 15 #import "chrome/browser/cocoa/browser_window_controller.h"
15 #include "chrome/browser/global_keyboard_shortcuts_mac.h" 16 #include "chrome/browser/global_keyboard_shortcuts_mac.h"
16 #include "chrome/browser/cocoa/sad_tab_view.h" 17 #include "chrome/browser/cocoa/sad_tab_view.h"
17 #import "chrome/browser/cocoa/web_drag_source.h" 18 #import "chrome/browser/cocoa/web_drag_source.h"
18 #import "chrome/browser/cocoa/web_drop_target.h" 19 #import "chrome/browser/cocoa/web_drop_target.h"
19 #include "chrome/browser/renderer_host/render_view_host_factory.h" 20 #include "chrome/browser/renderer_host/render_view_host_factory.h"
20 #include "chrome/browser/renderer_host/render_widget_host.h" 21 #include "chrome/browser/renderer_host/render_widget_host.h"
(...skipping 23 matching lines...) Expand all
44 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete); 45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationDelete);
45 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery); 46 COMPILE_ASSERT_MATCHING_ENUM(DragOperationEvery);
46 47
47 @interface TabContentsViewCocoa (Private) 48 @interface TabContentsViewCocoa (Private)
48 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w; 49 - (id)initWithTabContentsViewMac:(TabContentsViewMac*)w;
49 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)event; 50 - (BOOL)processKeyboardEvent:(NativeWebKeyboardEvent*)event;
50 - (void)registerDragTypes; 51 - (void)registerDragTypes;
51 - (void)setCurrentDragOperation:(NSDragOperation)operation; 52 - (void)setCurrentDragOperation:(NSDragOperation)operation;
52 - (void)startDragWithDropData:(const WebDropData&)dropData 53 - (void)startDragWithDropData:(const WebDropData&)dropData
53 dragOperationMask:(NSDragOperation)operationMask; 54 dragOperationMask:(NSDragOperation)operationMask;
55 - (void)cancelDeferredClose;
56 - (void)closeTabAfterEvent;
54 @end 57 @end
55 58
56 // static 59 // static
57 TabContentsView* TabContentsView::Create(TabContents* tab_contents) { 60 TabContentsView* TabContentsView::Create(TabContents* tab_contents) {
58 return new TabContentsViewMac(tab_contents); 61 return new TabContentsViewMac(tab_contents);
59 } 62 }
60 63
61 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents) 64 TabContentsViewMac::TabContentsViewMac(TabContents* tab_contents)
62 : TabContentsView(tab_contents) { 65 : TabContentsView(tab_contents) {
63 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED, 66 registrar_.Add(this, NotificationType::TAB_CONTENTS_CONNECTED,
64 Source<TabContents>(tab_contents)); 67 Source<TabContents>(tab_contents));
65 } 68 }
66 69
70 TabContentsViewMac::~TabContentsViewMac() {
71 // This handles the case where a renderer close call was deferred
72 // while the user was operating a UI control which resulted in a
73 // close. In that case, the Cocoa view outlives the
74 // TabContentsViewMac instance due to Cocoa retain count.
75 [cocoa_view_ cancelDeferredClose];
76 }
77
67 void TabContentsViewMac::CreateView(const gfx::Size& initial_size) { 78 void TabContentsViewMac::CreateView(const gfx::Size& initial_size) {
68 TabContentsViewCocoa* view = 79 TabContentsViewCocoa* view =
69 [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this]; 80 [[TabContentsViewCocoa alloc] initWithTabContentsViewMac:this];
70 cocoa_view_.reset(view); 81 cocoa_view_.reset(view);
71 } 82 }
72 83
73 RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget( 84 RenderWidgetHostView* TabContentsViewMac::CreateViewForWidget(
74 RenderWidgetHost* render_widget_host) { 85 RenderWidgetHost* render_widget_host) {
75 if (render_widget_host->view()) { 86 if (render_widget_host->view()) {
76 // During testing, the view will already be set up in most cases to the 87 // During testing, the view will already be set up in most cases to the
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
248 TabContentsView::ShowCreatedWidgetInternal(widget_host_view, initial_pos); 259 TabContentsView::ShowCreatedWidgetInternal(widget_host_view, initial_pos);
249 260
250 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's 261 // A RenderWidgetHostViewMac has lifetime scoped to the view. Now that it's
251 // properly embedded (or purposefully ignored) we can release the retain we 262 // properly embedded (or purposefully ignored) we can release the retain we
252 // took in CreateNewWidgetInternal(). 263 // took in CreateNewWidgetInternal().
253 RenderWidgetHostViewMac* widget_view_mac = 264 RenderWidgetHostViewMac* widget_view_mac =
254 static_cast<RenderWidgetHostViewMac*>(widget_host_view); 265 static_cast<RenderWidgetHostViewMac*>(widget_host_view);
255 [widget_view_mac->native_view() release]; 266 [widget_view_mac->native_view() release];
256 } 267 }
257 268
269 bool TabContentsViewMac::IsEventTracking() const {
270 if ([NSApp isKindOfClass:[CrApplication class]] &&
271 [static_cast<CrApplication*>(NSApp) isHandlingSendEvent]) {
272 return true;
273 }
274 return false;
275 }
276
277 // Arrange to call CloseTab() after we're back to the main event loop.
278 // The obvious way to do this would be PostNonNestableTask(), but that
279 // will fire when the event-tracking loop polls for events. So we
280 // need to bounce the message via Cocoa, instead.
281 void TabContentsViewMac::CloseTabAfterEventTracking() {
282 [cocoa_view_ cancelDeferredClose];
283 [cocoa_view_ performSelector:@selector(closeTabAfterEvent)
284 withObject:nil
285 afterDelay:0.0];
286 }
287
288 void TabContentsViewMac::CloseTab() {
289 tab_contents()->Close(tab_contents()->render_view_host());
290 }
291
258 void TabContentsViewMac::Observe(NotificationType type, 292 void TabContentsViewMac::Observe(NotificationType type,
259 const NotificationSource& source, 293 const NotificationSource& source,
260 const NotificationDetails& details) { 294 const NotificationDetails& details) {
261 switch (type.value) { 295 switch (type.value) {
262 case NotificationType::TAB_CONTENTS_CONNECTED: { 296 case NotificationType::TAB_CONTENTS_CONNECTED: {
263 if (sad_tab_.get()) { 297 if (sad_tab_.get()) {
264 [sad_tab_.get() removeFromSuperview]; 298 [sad_tab_.get() removeFromSuperview];
265 sad_tab_.reset(); 299 sad_tab_.reset();
266 } 300 }
267 break; 301 break;
(...skipping 14 matching lines...) Expand all
282 if (self != nil) { 316 if (self != nil) {
283 tabContentsView_ = w; 317 tabContentsView_ = w;
284 dropTarget_.reset( 318 dropTarget_.reset(
285 [[WebDropTarget alloc] initWithTabContents:[self tabContents]]); 319 [[WebDropTarget alloc] initWithTabContents:[self tabContents]]);
286 [self registerDragTypes]; 320 [self registerDragTypes];
287 } 321 }
288 return self; 322 return self;
289 } 323 }
290 324
291 - (void)dealloc { 325 - (void)dealloc {
326 // Cancel any deferred tab closes, just in case.
327 [self cancelDeferredClose];
328
292 // This probably isn't strictly necessary, but can't hurt. 329 // This probably isn't strictly necessary, but can't hurt.
293 [self unregisterDraggedTypes]; 330 [self unregisterDraggedTypes];
294 [super dealloc]; 331 [super dealloc];
295 } 332 }
296 333
297 // Registers for the view for the appropriate drag types. 334 // Registers for the view for the appropriate drag types.
298 // TODO(pinkerton): register for file drags. 335 // TODO(pinkerton): register for file drags.
299 - (void)registerDragTypes { 336 - (void)registerDragTypes {
300 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType, 337 NSArray* types = [NSArray arrayWithObjects:NSStringPboardType,
301 NSHTMLPboardType, NSURLPboardType, nil]; 338 NSHTMLPboardType, NSURLPboardType, nil];
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 } 504 }
468 505
469 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender { 506 - (NSDragOperation)draggingUpdated:(id<NSDraggingInfo>)sender {
470 return [dropTarget_ draggingUpdated:sender view:self]; 507 return [dropTarget_ draggingUpdated:sender view:self];
471 } 508 }
472 509
473 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender { 510 - (BOOL)performDragOperation:(id<NSDraggingInfo>)sender {
474 return [dropTarget_ performDragOperation:sender view:self]; 511 return [dropTarget_ performDragOperation:sender view:self];
475 } 512 }
476 513
514 - (void)cancelDeferredClose {
515 SEL aSel = @selector(closeTabAfterEvent);
516 [NSObject cancelPreviousPerformRequestsWithTarget:self
517 selector:aSel
518 object:nil];
519 }
520
521 - (void)closeTabAfterEvent {
522 tabContentsView_->CloseTab();
523 }
524
477 // Tons of stuff goes here, where we grab events going on in Cocoaland and send 525 // Tons of stuff goes here, where we grab events going on in Cocoaland and send
478 // them into the C++ system. TODO(avi): all that jazz 526 // them into the C++ system. TODO(avi): all that jazz
479 527
480 @end 528 @end
OLDNEW
« no previous file with comments | « chrome/browser/tab_contents/tab_contents_view_mac.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698