From 6880d990a84271934522d8be73faf33792477316 Mon Sep 17 00:00:00 2001 From: Marshall Greenblatt Date: Sun, 14 Aug 2011 21:54:18 +0000 Subject: [PATCH] Mac: - Don't show the "drop" icon outside of valid drop regions. - Fix a crash if the WebViewHost is destroyed before the BrowserWebView. - Remove unused/unnecessary code. git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@276 5089003a-bbd8-11dd-ad1f-f1f9622dbc98 --- libcef/browser_webview_mac.mm | 7 +++--- libcef/web_drag_source_mac.mm | 4 ---- libcef/web_drop_target_mac.h | 9 -------- libcef/web_drop_target_mac.mm | 32 +++++++++++----------------- libcef/webview_host.cc | 2 ++ libcef/webview_host_mac.mm | 5 +++++ libcef/webwidget_host.h | 4 ---- libcef/webwidget_host_mac.mm | 40 ----------------------------------- 8 files changed, 23 insertions(+), 80 deletions(-) diff --git a/libcef/browser_webview_mac.mm b/libcef/browser_webview_mac.mm index fce87db9d..5fc13f344 100644 --- a/libcef/browser_webview_mac.mm +++ b/libcef/browser_webview_mac.mm @@ -38,7 +38,8 @@ } - (void) dealloc { - browser_->UIT_DestroyBrowser(); + if (browser) + browser_->UIT_DestroyBrowser(); [self removeTrackingArea:trackingArea_]; [trackingArea_ release]; @@ -156,7 +157,7 @@ - (BOOL)becomeFirstResponder { if (browser_ && browser_->UIT_GetWebView()) { browser_->UIT_GetWebViewHost()->SetFocus(YES); - return YES; + return [super becomeFirstResponder]; } return NO; @@ -165,7 +166,7 @@ - (BOOL)resignFirstResponder { if (browser_ && browser_->UIT_GetWebView()) { browser_->UIT_GetWebViewHost()->SetFocus(NO); - return YES; + return [super resignFirstResponder]; } return NO; diff --git a/libcef/web_drag_source_mac.mm b/libcef/web_drag_source_mac.mm index 913fc1de8..69e40a302 100644 --- a/libcef/web_drag_source_mac.mm +++ b/libcef/web_drag_source_mac.mm @@ -288,10 +288,6 @@ void PromiseWriterTask::Run() { if (operation == (NSDragOperationMove | NSDragOperationCopy)) operation &= ~NSDragOperationMove; - // TODO: Figure out why |operation| is always NSDragOperationNone. - if (operation == NSDragOperationNone) - operation = NSDragOperationCopy; - WebView* webview = view_.browser->UIT_GetWebView(); gfx::Point client(localPoint.x, localPoint.y); diff --git a/libcef/web_drop_target_mac.h b/libcef/web_drop_target_mac.h index 17708182e..cc94f4472 100644 --- a/libcef/web_drop_target_mac.h +++ b/libcef/web_drop_target_mac.h @@ -21,10 +21,6 @@ class WebViewHost; // Our associated WebView. Weak reference. BrowserWebView* view_; - // Updated asynchronously during a drag to tell us whether or not we should - // allow the drop. - NSDragOperation current_operation_; - // Keep track of the WebViewHost we're dragging over. If it changes during a // drag, we need to re-send the DragEnter message. WebViewHost* current_wvh_; @@ -35,11 +31,6 @@ class WebViewHost; // (if necessary). - (id)initWithWebView:(BrowserWebView*)view; -// Sets the current operation negotiated by the source and destination, -// which determines whether or not we should allow the drop. Takes effect the -// next time |-draggingUpdated:| is called. -- (void)setCurrentOperation: (NSDragOperation)operation; - // Messages to send during the tracking of a drag, ususally upon receiving // calls from the view system. Communicates the drag messages to WebCore. - (NSDragOperation)draggingEntered:(id)info diff --git a/libcef/web_drop_target_mac.mm b/libcef/web_drop_target_mac.mm index 69048206f..80432f1fa 100644 --- a/libcef/web_drop_target_mac.mm +++ b/libcef/web_drop_target_mac.mm @@ -19,6 +19,7 @@ #include "webkit/glue/webdropdata.h" #include "webkit/glue/window_open_disposition.h" +using WebKit::WebDragOperation; using WebKit::WebDragOperationsMask; using WebKit::WebPoint; using WebKit::WebView; @@ -34,12 +35,6 @@ using WebKit::WebView; return self; } -// Call to set whether or not we should allow the drop. Takes effect the -// next time |-draggingUpdated:| is called. -- (void)setCurrentOperation: (NSDragOperation)operation { - current_operation_ = operation; -} - // Given a point in window coordinates and a view in that window, return a // flipped point in the coordinate system of |view|. - (NSPoint)flipWindowPointToView:(const NSPoint&)windowPoint @@ -100,15 +95,12 @@ using WebKit::WebView; NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; NSDragOperation mask = [info draggingSourceOperationMask]; - webview->dragTargetDragEnter(data.ToDragData(), - WebPoint(viewPoint.x, viewPoint.y), - WebPoint(screenPoint.x, screenPoint.y), - static_cast(mask)); - - // We won't know the true operation (whether the drag is allowed) until we - // hear back from the renderer. For now, be optimistic: - current_operation_ = NSDragOperationCopy; - return current_operation_; + WebDragOperation op = + webview->dragTargetDragEnter(data.ToDragData(), + WebPoint(viewPoint.x, viewPoint.y), + WebPoint(screenPoint.x, screenPoint.y), + static_cast(mask)); + return static_cast(op); } - (void)draggingExited:(id)info { @@ -143,11 +135,11 @@ using WebKit::WebView; NSPoint viewPoint = [self flipWindowPointToView:windowPoint view:view]; NSPoint screenPoint = [self flipWindowPointToScreen:windowPoint view:view]; NSDragOperation mask = [info draggingSourceOperationMask]; - webview->dragTargetDragOver(WebPoint(viewPoint.x, viewPoint.y), - WebPoint(screenPoint.x, screenPoint.y), - static_cast(mask)); - - return current_operation_; + WebDragOperation op = + webview->dragTargetDragOver(WebPoint(viewPoint.x, viewPoint.y), + WebPoint(screenPoint.x, screenPoint.y), + static_cast(mask)); + return static_cast(op); } - (BOOL)performDragOperation:(id)info diff --git a/libcef/webview_host.cc b/libcef/webview_host.cc index 965bbecb5..e43d81d23 100644 --- a/libcef/webview_host.cc +++ b/libcef/webview_host.cc @@ -8,6 +8,8 @@ WebViewHost::WebViewHost() { } +#if !defined(OS_MACOSX) WebViewHost::~WebViewHost() { } +#endif diff --git a/libcef/webview_host_mac.mm b/libcef/webview_host_mac.mm index b1804d954..bb70902a5 100644 --- a/libcef/webview_host_mac.mm +++ b/libcef/webview_host_mac.mm @@ -50,6 +50,11 @@ WebViewHost* WebViewHost::Create(NSView* parent_view, return host; } +WebViewHost::~WebViewHost() { + BrowserWebView* webView = static_cast(view_); + webView.browser = NULL; +} + WebView* WebViewHost::webview() const { return static_cast(webwidget_); } diff --git a/libcef/webwidget_host.h b/libcef/webwidget_host.h index a01a4543f..2135ec36c 100644 --- a/libcef/webwidget_host.h +++ b/libcef/webwidget_host.h @@ -61,10 +61,6 @@ class WebWidgetHost { virtual ~WebWidgetHost(); -#if defined(OS_MACOSX) - static void HandleEvent(gfx::NativeView view, NSEvent* event); -#endif - gfx::NativeView view_handle() const { return view_; } WebKit::WebWidget* webwidget() const { return webwidget_; } diff --git a/libcef/webwidget_host_mac.mm b/libcef/webwidget_host_mac.mm index 685c5de00..45f0b6e74 100644 --- a/libcef/webwidget_host_mac.mm +++ b/libcef/webwidget_host_mac.mm @@ -45,46 +45,6 @@ WebWidgetHost* WebWidgetHost::Create(NSView* parent_view, return host; } -/*static*/ -void WebWidgetHost::HandleEvent(NSView* view, NSEvent* event) { - /* TODO(port): rig up a way to get to the host */ - WebWidgetHost* host = NULL; - if (host) { - switch ([event type]) { - case NSLeftMouseDown: - case NSLeftMouseUp: - case NSRightMouseDown: - case NSRightMouseUp: - case NSOtherMouseDown: - case NSOtherMouseUp: - case NSMouseEntered: - case NSMouseExited: - host->MouseEvent(event); - break; - - case NSScrollWheel: - host->WheelEvent(event); - break; - - case NSKeyDown: - case NSKeyUp: - host->KeyEvent(event); - break; - - case NSAppKitDefined: - switch ([event subtype]) { - case NSApplicationActivatedEventType: - host->SetFocus(true); - break; - case NSApplicationDeactivatedEventType: - host->SetFocus(false); - break; - } - break; - } - } -} - void WebWidgetHost::DidInvalidateRect(const gfx::Rect& damaged_rect) { #ifndef NDEBUG DLOG_IF(WARNING, painting_) << "unexpected invalidation while painting";