Commit 51e76634 authored by Leonard Grey's avatar Leonard Grey Committed by Commit Bot

Mac: De-Cocoa ShareMenuController

We managed to miss the fact that ShareMenuController's transition animation
data was dependent on Cocoa browser windows. This change uses Views APIs
to get the content area's rect and screengrab instead.

Bug: 890355
Change-Id: Ifa86782902e24985228a423510b65b5a58ef37b5
Reviewed-on: https://chromium-review.googlesource.com/1252245Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Commit-Queue: Leonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#595469}
parent 41e5acad
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "base/mac/foundation_util.h" #include "base/mac/foundation_util.h"
#include "base/mac/mac_util.h" #include "base/mac/mac_util.h"
#include "base/mac/scoped_nsobject.h"
#include "base/mac/sdk_forward_declarations.h" #include "base/mac/sdk_forward_declarations.h"
#include "base/metrics/histogram_macros.h" #include "base/metrics/histogram_macros.h"
#include "base/strings/sys_string_conversions.h" #include "base/strings/sys_string_conversions.h"
...@@ -13,19 +14,19 @@ ...@@ -13,19 +14,19 @@
#include "chrome/browser/global_keyboard_shortcuts_mac.h" #include "chrome/browser/global_keyboard_shortcuts_mac.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/accelerators_cocoa.h" #import "chrome/browser/ui/cocoa/accelerators_cocoa.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #include "chrome/browser/ui/views/frame/browser_view.h"
#import "chrome/browser/ui/cocoa/browser_window_views_mac.h"
#import "chrome/browser/ui/cocoa/fast_resize_view.h"
#import "chrome/browser/ui/cocoa/last_active_browser_cocoa.h"
#include "chrome/grit/generated_resources.h" #include "chrome/grit/generated_resources.h"
#include "net/base/mac/url_conversions.h" #include "net/base/mac/url_conversions.h"
#include "ui/base/accelerators/platform_accelerator_cocoa.h" #include "ui/base/accelerators/platform_accelerator_cocoa.h"
#include "ui/base/l10n/l10n_util_mac.h" #include "ui/base/l10n/l10n_util_mac.h"
#include "ui/gfx/geometry/rect.h" #include "ui/gfx/geometry/rect.h"
#include "ui/gfx/image/image.h" #include "ui/gfx/image/image.h"
#include "ui/gfx/mac/coordinate_conversion.h"
#include "ui/snapshot/snapshot.h" #include "ui/snapshot/snapshot.h"
#include "ui/views/view.h"
// Private method, used to identify instantiated services. // Private method, used to identify instantiated services.
@interface NSSharingService (ExposeName) @interface NSSharingService (ExposeName)
...@@ -86,12 +87,12 @@ NSString* const kRemindersSharingServiceName = ...@@ -86,12 +87,12 @@ NSString* const kRemindersSharingServiceName =
[menu removeAllItems]; [menu removeAllItems];
[menu setAutoenablesItems:NO]; [menu setAutoenablesItems:NO];
Browser* lastActiveBrowser = chrome::GetLastActiveBrowser(); Browser* lastActiveBrowser = chrome::FindLastActive();
BOOL canShare = BOOL canShare =
lastActiveBrowser != nullptr && lastActiveBrowser != nullptr &&
// Avoid |CanEmailPageLocation| segfault in interactive UI tests // Avoid |CanEmailPageLocation| segfault in interactive UI tests
lastActiveBrowser->tab_strip_model()->GetActiveWebContents() != nullptr && lastActiveBrowser->tab_strip_model()->GetActiveWebContents() != nullptr &&
chrome::CanEmailPageLocation(chrome::GetLastActiveBrowser()); chrome::CanEmailPageLocation(lastActiveBrowser);
// Using a real URL instead of empty string to avoid system log about relative // Using a real URL instead of empty string to avoid system log about relative
// URLs in the pasteboard. This URL will not actually be shared to, just used // URLs in the pasteboard. This URL will not actually be shared to, just used
// to fetch sharing services that can handle the NSURL type. // to fetch sharing services that can handle the NSURL type.
...@@ -156,17 +157,23 @@ NSString* const kRemindersSharingServiceName = ...@@ -156,17 +157,23 @@ NSString* const kRemindersSharingServiceName =
// Saves details required by delegate methods for the transition animation. // Saves details required by delegate methods for the transition animation.
- (void)saveTransitionDataFromBrowser:(Browser*)browser { - (void)saveTransitionDataFromBrowser:(Browser*)browser {
windowForShare_ = browser->window()->GetNativeWindow(); windowForShare_ = browser->window()->GetNativeWindow();
BrowserView* browserView = BrowserView::GetBrowserViewForBrowser(browser);
if (!browserView)
return;
views::View* contentsView = browserView->contents_container();
if (!contentsView)
return;
gfx::Rect screenRect = contentsView->bounds();
views::View::ConvertRectToScreen(browserView, &screenRect);
TabWindowController* tabWindowController = rectForShare_ = ScreenRectToNSRect(screenRect);
TabWindowControllerForWindow(windowForShare_);
NSView* contentsView = [tabWindowController tabContentArea];
NSRect rectInWindow =
[[contentsView superview] convertRect:[contentsView frame] toView:nil];
rectForShare_ = [windowForShare_ convertRectToScreen:rectInWindow];
gfx::Rect rectInWidget =
browserView->ConvertRectToWidget(contentsView->bounds());
gfx::Image image; gfx::Image image;
gfx::Rect rect = gfx::Rect(NSRectToCGRect([contentsView bounds])); if (ui::GrabWindowSnapshot(windowForShare_, rectInWidget, &image)) {
if (ui::GrabViewSnapshot(contentsView, rect, &image)) {
snapshotForShare_.reset(image.CopyNSImage()); snapshotForShare_.reset(image.CopyNSImage());
} }
} }
...@@ -183,7 +190,7 @@ NSString* const kRemindersSharingServiceName = ...@@ -183,7 +190,7 @@ NSString* const kRemindersSharingServiceName =
// Performs the share action using the sharing service represented by |sender|. // Performs the share action using the sharing service represented by |sender|.
- (void)performShare:(NSMenuItem*)sender { - (void)performShare:(NSMenuItem*)sender {
Browser* browser = chrome::GetLastActiveBrowser(); Browser* browser = chrome::FindLastActive();
DCHECK(browser); DCHECK(browser);
[self saveTransitionDataFromBrowser:browser]; [self saveTransitionDataFromBrowser:browser];
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment