OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #include "chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.h" | 5 #include "chrome/browser/ui/cocoa/screen_capture_notification_ui_cocoa.h" |
6 | 6 |
7 #import <Cocoa/Cocoa.h> | 7 #import <Cocoa/Cocoa.h> |
8 | 8 |
9 #include "base/compiler_specific.h" | 9 #include "base/compiler_specific.h" |
10 #include "base/i18n/rtl.h" | 10 #include "base/i18n/rtl.h" |
11 #include "base/mac/mac_util.h" | 11 #include "base/mac/mac_util.h" |
12 #include "base/mac/scoped_nsobject.h" | 12 #include "base/mac/scoped_nsobject.h" |
13 #include "base/strings/string_util.h" | 13 #include "base/strings/string_util.h" |
14 #include "base/strings/sys_string_conversions.h" | 14 #include "base/strings/sys_string_conversions.h" |
15 #include "grit/generated_resources.h" | 15 #include "grit/generated_resources.h" |
16 #include "grit/theme_resources.h" | 16 #include "grit/theme_resources.h" |
17 #include "skia/ext/skia_utils_mac.h" | 17 #include "skia/ext/skia_utils_mac.h" |
18 #import "ui/base/cocoa/controls/blue_label_button.h" | 18 #import "ui/base/cocoa/controls/blue_label_button.h" |
| 19 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
19 #include "ui/base/cocoa/window_size_constants.h" | 20 #include "ui/base/cocoa/window_size_constants.h" |
20 #include "ui/base/l10n/l10n_util.h" | 21 #include "ui/base/l10n/l10n_util.h" |
21 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
22 #include "ui/gfx/font_list.h" | 23 #include "ui/gfx/font_list.h" |
23 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
24 #include "ui/gfx/image/image_skia_util_mac.h" | 25 #include "ui/gfx/image/image_skia_util_mac.h" |
25 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
26 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
27 | 28 |
28 const CGFloat kMinimumWidth = 460; | 29 const CGFloat kMinimumWidth = 460; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 } | 106 } |
106 | 107 |
107 - (void)stopSharing:(id)sender { | 108 - (void)stopSharing:(id)sender { |
108 if (!stop_callback_.is_null()) { | 109 if (!stop_callback_.is_null()) { |
109 base::Closure callback = stop_callback_; | 110 base::Closure callback = stop_callback_; |
110 stop_callback_.Reset(); | 111 stop_callback_.Reset(); |
111 callback.Run(); // Deletes |self|. | 112 callback.Run(); // Deletes |self|. |
112 } | 113 } |
113 } | 114 } |
114 | 115 |
| 116 - (void)minimize:(id)sender { |
| 117 [[self window] miniaturize:sender]; |
| 118 } |
| 119 |
115 - (void)hide { | 120 - (void)hide { |
116 stop_callback_.Reset(); | 121 stop_callback_.Reset(); |
117 [self close]; | 122 [self close]; |
118 } | 123 } |
119 | 124 |
120 - (void)populateWithText:(const base::string16&)text { | 125 - (void)populateWithText:(const base::string16&)text { |
121 base::scoped_nsobject<ScreenCaptureNotificationView> content( | 126 base::scoped_nsobject<ScreenCaptureNotificationView> content( |
122 [[ScreenCaptureNotificationView alloc] | 127 [[ScreenCaptureNotificationView alloc] |
123 initWithFrame:ui::kWindowSizeDeterminedLater]); | 128 initWithFrame:ui::kWindowSizeDeterminedLater]); |
124 [[self window] setContentView:content]; | 129 [[self window] setContentView:content]; |
125 | 130 |
126 // Create button. | 131 // Create button. |
127 stopButton_.reset([[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | 132 stopButton_.reset([[BlueLabelButton alloc] initWithFrame:NSZeroRect]); |
128 [stopButton_ setTitle:l10n_util::GetNSString( | 133 [stopButton_ setTitle:l10n_util::GetNSString( |
129 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP)]; | 134 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP)]; |
130 [stopButton_ setTarget:self]; | 135 [stopButton_ setTarget:self]; |
131 [stopButton_ setAction:@selector(stopSharing:)]; | 136 [stopButton_ setAction:@selector(stopSharing:)]; |
132 [stopButton_ sizeToFit]; | 137 [stopButton_ sizeToFit]; |
133 [content addSubview:stopButton_]; | 138 [content addSubview:stopButton_]; |
134 | 139 |
135 CGFloat buttonWidth = NSWidth([stopButton_ frame]); | 140 minimizeButton_.reset( |
| 141 [[HyperlinkButtonCell buttonWithString:l10n_util::GetNSString( |
| 142 IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)] retain]); |
| 143 [minimizeButton_ sizeToFit]; |
| 144 [minimizeButton_ setTarget:self]; |
| 145 [minimizeButton_ setAction:@selector(minimize:)]; |
| 146 [content addSubview:minimizeButton_]; |
| 147 |
| 148 CGFloat buttonsWidth = NSWidth([stopButton_ frame]) + kHorizontalMargin + |
| 149 NSWidth([minimizeButton_ frame]); |
136 CGFloat totalHeight = kPadding + NSHeight([stopButton_ frame]) + kPadding; | 150 CGFloat totalHeight = kPadding + NSHeight([stopButton_ frame]) + kPadding; |
137 | 151 |
138 // Create grip icon. | 152 // Create grip icon. |
139 base::scoped_nsobject<WindowGripView> gripView([[WindowGripView alloc] init]); | 153 base::scoped_nsobject<WindowGripView> gripView([[WindowGripView alloc] init]); |
140 [content addSubview:gripView]; | 154 [content addSubview:gripView]; |
141 CGFloat gripWidth = NSWidth([gripView frame]); | 155 CGFloat gripWidth = NSWidth([gripView frame]); |
142 CGFloat gripHeight = NSHeight([gripView frame]); | 156 CGFloat gripHeight = NSHeight([gripView frame]); |
143 [gripView | 157 [gripView |
144 setFrameOrigin:NSMakePoint(kPaddingLeft, (totalHeight - gripHeight) / 2)]; | 158 setFrameOrigin:NSMakePoint(kPaddingLeft, (totalHeight - gripHeight) / 2)]; |
145 | 159 |
146 // Create text label. | 160 // Create text label. |
147 int maximumWidth = | 161 int maximumWidth = |
148 std::min(kMaximumWidth, NSWidth([[NSScreen mainScreen] visibleFrame])); | 162 std::min(kMaximumWidth, NSWidth([[NSScreen mainScreen] visibleFrame])); |
149 int maxLabelWidth = maximumWidth - kPaddingLeft - kPadding - | 163 int maxLabelWidth = maximumWidth - kPaddingLeft - kPadding - |
150 kHorizontalMargin * 2 - gripWidth - buttonWidth; | 164 kHorizontalMargin * 2 - gripWidth - buttonsWidth; |
151 gfx::FontList font_list; | 165 gfx::FontList font_list; |
152 base::string16 elidedText = | 166 base::string16 elidedText = |
153 ElideText(text, font_list, maxLabelWidth, gfx::ELIDE_IN_MIDDLE); | 167 ElideText(text, font_list, maxLabelWidth, gfx::ELIDE_IN_MIDDLE); |
154 NSString* statusText = base::SysUTF16ToNSString(elidedText); | 168 NSString* statusText = base::SysUTF16ToNSString(elidedText); |
155 base::scoped_nsobject<NSTextField> statusTextField( | 169 base::scoped_nsobject<NSTextField> statusTextField( |
156 [[NSTextField alloc] initWithFrame:ui::kWindowSizeDeterminedLater]); | 170 [[NSTextField alloc] initWithFrame:ui::kWindowSizeDeterminedLater]); |
157 [statusTextField setEditable:NO]; | 171 [statusTextField setEditable:NO]; |
158 [statusTextField setSelectable:NO]; | 172 [statusTextField setSelectable:NO]; |
159 [statusTextField setDrawsBackground:NO]; | 173 [statusTextField setDrawsBackground:NO]; |
160 [statusTextField setBezeled:NO]; | 174 [statusTextField setBezeled:NO]; |
161 [statusTextField setStringValue:statusText]; | 175 [statusTextField setStringValue:statusText]; |
162 [statusTextField setFont:font_list.GetPrimaryFont().GetNativeFont()]; | 176 [statusTextField setFont:font_list.GetPrimaryFont().GetNativeFont()]; |
163 [statusTextField sizeToFit]; | 177 [statusTextField sizeToFit]; |
164 [statusTextField setFrameOrigin:NSMakePoint( | 178 [statusTextField setFrameOrigin:NSMakePoint( |
165 kPaddingLeft + kHorizontalMargin + gripWidth, | 179 kPaddingLeft + kHorizontalMargin + gripWidth, |
166 (totalHeight - NSHeight([statusTextField frame])) / 2)]; | 180 (totalHeight - NSHeight([statusTextField frame])) / 2)]; |
167 [content addSubview:statusTextField]; | 181 [content addSubview:statusTextField]; |
168 | 182 |
169 // Resize content view to fit controls. | 183 // Resize content view to fit controls. |
170 CGFloat minimumLableWidth = kMinimumWidth - kPaddingLeft - kPadding - | 184 CGFloat minimumLableWidth = kMinimumWidth - kPaddingLeft - kPadding - |
171 kHorizontalMargin * 2 - gripWidth - buttonWidth; | 185 kHorizontalMargin * 2 - gripWidth - buttonsWidth; |
172 CGFloat lableWidth = | 186 CGFloat lableWidth = |
173 std::max(NSWidth([statusTextField frame]), minimumLableWidth); | 187 std::max(NSWidth([statusTextField frame]), minimumLableWidth); |
174 CGFloat totalWidth = kPaddingLeft + kPadding + kHorizontalMargin * 2 + | 188 CGFloat totalWidth = kPaddingLeft + kPadding + kHorizontalMargin * 2 + |
175 gripWidth + lableWidth + buttonWidth; | 189 gripWidth + lableWidth + buttonsWidth; |
176 [content setFrame:NSMakeRect(0, 0, totalWidth, totalHeight)]; | 190 [content setFrame:NSMakeRect(0, 0, totalWidth, totalHeight)]; |
177 | 191 |
178 // Move the button to the right place. | 192 // Move the buttons to the right place. |
179 NSPoint buttonOrigin = | 193 NSPoint buttonOrigin = |
180 NSMakePoint(totalWidth - kPadding - buttonWidth, kPadding); | 194 NSMakePoint(totalWidth - kPadding - buttonsWidth, kPadding); |
181 [stopButton_ setFrameOrigin:buttonOrigin]; | 195 [stopButton_ setFrameOrigin:buttonOrigin]; |
182 | 196 |
| 197 [minimizeButton_ setFrameOrigin:NSMakePoint( |
| 198 totalWidth - kPadding - NSWidth([minimizeButton_ frame]), |
| 199 (totalHeight - NSHeight([minimizeButton_ frame])) / 2)]; |
| 200 |
183 if (base::i18n::IsRTL()) { | 201 if (base::i18n::IsRTL()) { |
184 [stopButton_ | 202 [stopButton_ |
185 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([stopButton_ frame]), | 203 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([stopButton_ frame]), |
186 NSMinY([stopButton_ frame]))]; | 204 NSMinY([stopButton_ frame]))]; |
| 205 [minimizeButton_ |
| 206 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([minimizeButton_ frame]), |
| 207 NSMinY([minimizeButton_ frame]))]; |
187 [statusTextField | 208 [statusTextField |
188 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([statusTextField frame]), | 209 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([statusTextField frame]), |
189 NSMinY([statusTextField frame]))]; | 210 NSMinY([statusTextField frame]))]; |
190 [gripView setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([gripView frame]), | 211 [gripView setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([gripView frame]), |
191 NSMinY([gripView frame]))]; | 212 NSMinY([gripView frame]))]; |
192 } | 213 } |
193 } | 214 } |
194 | 215 |
195 - (void)windowWillClose:(NSNotification*)notification { | 216 - (void)windowWillClose:(NSNotification*)notification { |
196 [self stopSharing:nil]; | 217 [self stopSharing:nil]; |
(...skipping 22 matching lines...) Expand all Loading... |
219 self = [super | 240 self = [super |
220 initWithFrame:NSMakeRect(0, 0, gripImage.Width(), gripImage.Height())]; | 241 initWithFrame:NSMakeRect(0, 0, gripImage.Width(), gripImage.Height())]; |
221 [self setImage:gripImage.ToNSImage()]; | 242 [self setImage:gripImage.ToNSImage()]; |
222 return self; | 243 return self; |
223 } | 244 } |
224 | 245 |
225 - (BOOL)mouseDownCanMoveWindow { | 246 - (BOOL)mouseDownCanMoveWindow { |
226 return YES; | 247 return YES; |
227 } | 248 } |
228 @end | 249 @end |
OLD | NEW |