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

Side by Side Diff: chrome/browser/ui/cocoa/chrome_to_mobile_bubble_controller.mm

Issue 10885024: Integrate Chrome To Mobile with Action Box UI. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address cocoa comments. Created 8 years, 3 months 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 | Annotate | Revision Log
OLDNEW
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
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 if (controller != nil) {
sail 2012/08/29 23:15:03 you don't need this check, message calls to nil ar
msw 2012/08/29 23:26:19 Done.
95 // Restore the Action Box icon when the bubble closes.
96 [controller locationBarBridge]->SetActionBoxIcon(IDR_ACTION_BOX_BUTTON);
97 [controller chromeToMobileBubbleWindowWillClose];
98 }
99
91 // We caught a close so we don't need to observe further notifications. 100 // We caught a close so we don't need to observe further notifications.
92 bridge_.reset(NULL); 101 bridge_.reset(NULL);
93 [progressAnimation_ stopAnimation]; 102 [progressAnimation_ stopAnimation];
94 // Cancel any delayed requests that may still be pending (close, etc.). 103 // Cancel any delayed requests that may still be pending (close, etc.).
95 [NSObject cancelPreviousPerformRequestsWithTarget:self]; 104 [NSObject cancelPreviousPerformRequestsWithTarget:self];
96 [super windowWillClose:notification]; 105 [super windowWillClose:notification];
97 } 106 }
98 107
99 // Override -[BaseBubbleController showWindow:] to set up UI elements. 108 // Override -[BaseBubbleController showWindow:] to set up UI elements.
100 - (void)showWindow:(id)sender { 109 - (void)showWindow:(id)sender {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
134 [mobileRadioGroup_ setHidden:NO]; 143 [mobileRadioGroup_ setHidden:NO];
135 [mobileRadioGroup_ sizeToCells]; 144 [mobileRadioGroup_ sizeToCells];
136 145
137 // Adjust the window size to accommodate the radio group. 146 // Adjust the window size to accommodate the radio group.
138 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding; 147 CGFloat deltaY = [mobileRadioGroup_ frame].size.height + kVerticalPadding;
139 NSRect windowFrame = [window frame]; 148 NSRect windowFrame = [window frame];
140 windowFrame.size.height += deltaY; 149 windowFrame.size.height += deltaY;
141 [window setFrame:windowFrame display:YES animate:NO]; 150 [window setFrame:windowFrame display:YES animate:NO];
142 } 151 }
143 152
144 // Get the anchor point for the bubble in screen coordinates.
145 BrowserWindowController* controller = [BrowserWindowController 153 BrowserWindowController* controller = [BrowserWindowController
146 browserWindowControllerForWindow:self.parentWindow]; 154 browserWindowControllerForWindow:self.parentWindow];
147 if (controller != nil) { 155 if (controller != nil) {
156 // Get the anchor point for the bubble in screen coordinates.
148 LocationBarViewMac* locationBar = [controller locationBarBridge]; 157 LocationBarViewMac* locationBar = [controller locationBarBridge];
149 NSPoint bubblePoint; 158 NSPoint bubblePoint = locationBar->GetActionBoxAnchorPoint();
150 if (extensions::switch_utils::IsExtensionsInActionBoxEnabled()) { 159 bubblePoint = [self.parentWindow convertBaseToScreen:bubblePoint];
151 bubblePoint = locationBar->GetActionBoxAnchorPoint(); 160 // Without an arrow, the anchor point of a bubble is the top left corner,
152 bubblePoint = [self.parentWindow convertBaseToScreen:bubblePoint]; 161 // but GetActionBoxAnchorPoint returns the top right corner.
153 // Without an arrow, the anchor point of a bubble is the top left corner, 162 bubblePoint.x -= self.bubble.frame.size.width;
154 // but GetActionBoxAnchorPoint returns the top right corner. 163 [self.bubble setArrowLocation:info_bubble::kNoArrow];
155 bubblePoint.x -= self.bubble.frame.size.width; 164 [self.bubble setCornerFlags:info_bubble::kRoundedBottomCorners];
156 [self.bubble setArrowLocation:info_bubble::kNoArrow]; 165 [self.bubble setAlignment:info_bubble::kAlignEdgeToAnchorEdge];
157 [self.bubble setCornerFlags:info_bubble::kRoundedBottomCorners]; 166 [window setContentSize:self.bubble.frame.size];
158 [self.bubble setAlignment:info_bubble::kAlignEdgeToAnchorEdge]; 167 [window setContentView:self.bubble];
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
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)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698