| 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 "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h" | 5 #import "chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.h" |
| 6 | 6 |
| 7 #include "base/mac/mac_util.h" | 7 #include "base/mac/mac_util.h" |
| 8 #include "base/memory/weak_ptr.h" | 8 #include "base/memory/weak_ptr.h" |
| 9 #include "base/sys_string_conversions.h" | 9 #include "base/sys_string_conversions.h" |
| 10 #include "chrome/browser/chrome_to_mobile_service_factory.h" | 10 #include "chrome/browser/chrome_to_mobile_service_factory.h" |
| 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" | 11 #import "chrome/browser/ui/cocoa/browser_window_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/info_bubble_view.h" | 12 #import "chrome/browser/ui/cocoa/info_bubble_view.h" |
| 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" | 13 #import "chrome/browser/ui/cocoa/location_bar/location_bar_view_mac.h" |
| 14 #include "chrome/common/extensions/extension_switch_utils.h" | 14 #include "chrome/common/extensions/extension_switch_utils.h" |
| 15 #include "content/public/browser/notification_service.h" | 15 #include "content/public/browser/notification_service.h" |
| 16 #include "content/public/browser/notification_types.h" | 16 #include "content/public/browser/notification_types.h" |
| 17 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
| 18 #include "grit/theme_resources.h" |
| 18 #include "ui/base/l10n/l10n_util.h" | 19 #include "ui/base/l10n/l10n_util.h" |
| 19 #include "ui/base/l10n/l10n_util_mac.h" | 20 #include "ui/base/l10n/l10n_util_mac.h" |
| 20 #include "ui/base/text/bytes_formatting.h" | 21 #include "ui/base/text/bytes_formatting.h" |
| 21 | 22 |
| 22 namespace { | 23 namespace { |
| 23 | 24 |
| 24 // The verical padding between the radio group and the send copy checkbox. | 25 // The verical padding between the radio group and the send copy checkbox. |
| 25 const CGFloat kVerticalPadding = 10; | 26 const CGFloat kVerticalPadding = 10; |
| 26 | 27 |
| 27 // The duration of the "Sending..." progress throb animation in seconds. | 28 // The duration of the "Sending..." progress throb animation in seconds. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 81 browser_ = browser; | 82 browser_ = browser; |
| 82 service_ = ChromeToMobileServiceFactory::GetForProfile(browser->profile()); | 83 service_ = ChromeToMobileServiceFactory::GetForProfile(browser->profile()); |
| 83 } | 84 } |
| 84 return self; | 85 return self; |
| 85 } | 86 } |
| 86 | 87 |
| 87 - (void)windowWillClose:(NSNotification*)notification { | 88 - (void)windowWillClose:(NSNotification*)notification { |
| 88 // Instruct the service to delete the snapshot file. | 89 // Instruct the service to delete the snapshot file. |
| 89 service_->DeleteSnapshot(snapshotPath_); | 90 service_->DeleteSnapshot(snapshotPath_); |
| 90 | 91 |
| 92 BrowserWindowController* controller = [BrowserWindowController |
| 93 browserWindowControllerForWindow:self.parentWindow]; |
| 94 [controller chromeToMobileBubbleWindowWillClose]; |
| 95 |
| 96 // Restore the Action Box icon when the bubble closes. |
| 97 LocationBarViewMac* locationBar = [controller locationBarBridge]; |
| 98 if (locationBar) |
| 99 locationBar->SetActionBoxIcon(IDR_ACTION_BOX_BUTTON); |
| 100 |
| 91 // We caught a close so we don't need to observe further notifications. | 101 // We caught a close so we don't need to observe further notifications. |
| 92 bridge_.reset(NULL); | 102 bridge_.reset(NULL); |
| 93 [progressAnimation_ stopAnimation]; | 103 [progressAnimation_ stopAnimation]; |
| 94 // Cancel any delayed requests that may still be pending (close, etc.). | 104 // Cancel any delayed requests that may still be pending (close, etc.). |
| 95 [NSObject cancelPreviousPerformRequestsWithTarget:self]; | 105 [NSObject cancelPreviousPerformRequestsWithTarget:self]; |
| 96 [super windowWillClose:notification]; | 106 [super windowWillClose:notification]; |
| 97 } | 107 } |
| 98 | 108 |
| 99 // Override -[BaseBubbleController showWindow:] to set up UI elements. | 109 // Override -[BaseBubbleController showWindow:] to set up UI elements. |
| 100 - (void)showWindow:(id)sender { | 110 - (void)showWindow:(id)sender { |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 134 [mobileRadioGroup_ setHidden:NO]; | 144 [mobileRadioGroup_ setHidden:NO]; |
| 135 [mobileRadioGroup_ sizeToCells]; | 145 [mobileRadioGroup_ sizeToCells]; |
| 136 | 146 |
| 137 // Adjust the window size to accommodate the radio group. | 147 // Adjust the window size to accommodate the radio group. |
| 138 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding; | 148 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding; |
| 139 NSRect windowFrame = [window frame]; | 149 NSRect windowFrame = [window frame]; |
| 140 windowFrame.size.height += deltaY; | 150 windowFrame.size.height += deltaY; |
| 141 [window setFrame:windowFrame display:YES animate:NO]; | 151 [window setFrame:windowFrame display:YES animate:NO]; |
| 142 } | 152 } |
| 143 | 153 |
| 144 // Get the anchor point for the bubble in screen coordinates. | 154 LocationBarViewMac* locationBar = [[BrowserWindowController |
| 145 BrowserWindowController* controller = [BrowserWindowController | 155 browserWindowControllerForWindow:self.parentWindow] locationBarBridge]; |
| 146 browserWindowControllerForWindow:self.parentWindow]; | 156 if (locationBar) { |
| 147 if (controller != nil) { | 157 // Get the anchor point for the bubble in screen coordinates. |
| 148 LocationBarViewMac* locationBar = [controller locationBarBridge]; | 158 NSPoint bubblePoint = locationBar->GetActionBoxAnchorPoint(); |
| 149 NSPoint bubblePoint; | 159 bubblePoint = [self.parentWindow convertBaseToScreen:bubblePoint]; |
| 150 if (extensions::switch_utils::IsExtensionsInActionBoxEnabled()) { | 160 // Without an arrow, the anchor point of a bubble is the top left corner, |
| 151 bubblePoint = locationBar->GetActionBoxAnchorPoint(); | 161 // but GetActionBoxAnchorPoint returns the top right corner. |
| 152 bubblePoint = [self.parentWindow convertBaseToScreen:bubblePoint]; | 162 bubblePoint.x -= self.bubble.frame.size.width; |
| 153 // Without an arrow, the anchor point of a bubble is the top left corner, | 163 [self.bubble setArrowLocation:info_bubble::kNoArrow]; |
| 154 // but GetActionBoxAnchorPoint returns the top right corner. | 164 [self.bubble setCornerFlags:info_bubble::kRoundedBottomCorners]; |
| 155 bubblePoint.x -= self.bubble.frame.size.width; | 165 [self.bubble setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; |
| 156 [self.bubble setArrowLocation:info_bubble::kNoArrow]; | 166 [window setContentSize:self.bubble.frame.size]; |
| 157 [self.bubble setCornerFlags:info_bubble::kRoundedBottomCorners]; | 167 [window setContentView:self.bubble]; |
| 158 [self.bubble setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; | |
| 159 [window setContentSize:self.bubble.frame.size]; | |
| 160 [window setContentView:self.bubble]; | |
| 161 } else { | |
| 162 bubblePoint = locationBar->GetChromeToMobileBubblePoint(); | |
| 163 bubblePoint = [self.parentWindow convertBaseToScreen:bubblePoint]; | |
| 164 [self.bubble setArrowLocation:info_bubble::kTopRight]; | |
| 165 } | |
| 166 [self setAnchorPoint:bubblePoint]; | 168 [self setAnchorPoint:bubblePoint]; |
| 169 |
| 170 // Show the lit Chrome To Mobile icon while the bubble is open. |
| 171 locationBar->SetActionBoxIcon(IDR_MOBILE_LIT); |
| 167 } | 172 } |
| 168 | 173 |
| 169 // Initialize the checkbox to send an offline copy. | 174 // Initialize the checkbox to send an offline copy. |
| 170 NSString* sendCopyString = | 175 NSString* sendCopyString = |
| 171 l10n_util::GetNSStringF(IDS_CHROME_TO_MOBILE_BUBBLE_SEND_COPY, | 176 l10n_util::GetNSStringF(IDS_CHROME_TO_MOBILE_BUBBLE_SEND_COPY, |
| 172 l10n_util::GetStringUTF16( | 177 l10n_util::GetStringUTF16( |
| 173 IDS_CHROME_TO_MOBILE_BUBBLE_SEND_COPY_GENERATING)); | 178 IDS_CHROME_TO_MOBILE_BUBBLE_SEND_COPY_GENERATING)); |
| 174 [sendCopy_ setTitle:sendCopyString]; | 179 [sendCopy_ setTitle:sendCopyString]; |
| 175 [sendCopy_ setState:NSOffState]; | 180 [sendCopy_ setState:NSOffState]; |
| 176 | 181 |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 300 | 305 |
| 301 - (void)setSendCopy:(bool)sendCopy { | 306 - (void)setSendCopy:(bool)sendCopy { |
| 302 [sendCopy_ setState:(sendCopy ? NSOnState : NSOffState)]; | 307 [sendCopy_ setState:(sendCopy ? NSOnState : NSOffState)]; |
| 303 } | 308 } |
| 304 | 309 |
| 305 - (ChromeToMobileBubbleNotificationBridge*)bridge { | 310 - (ChromeToMobileBubbleNotificationBridge*)bridge { |
| 306 return bridge_.get(); | 311 return bridge_.get(); |
| 307 } | 312 } |
| 308 | 313 |
| 309 @end // ChromeToMobileBubbleController (JustForTesting) | 314 @end // ChromeToMobileBubbleController (JustForTesting) |
| OLD | NEW |