| 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" |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 #include "ui/base/resource/resource_bundle.h" | 22 #include "ui/base/resource/resource_bundle.h" |
| 23 #include "ui/gfx/font_list.h" | 23 #include "ui/gfx/font_list.h" |
| 24 #include "ui/gfx/image/image_skia.h" | 24 #include "ui/gfx/image/image_skia.h" |
| 25 #include "ui/gfx/image/image_skia_util_mac.h" | 25 #include "ui/gfx/image/image_skia_util_mac.h" |
| 26 #include "ui/gfx/text_elider.h" | 26 #include "ui/gfx/text_elider.h" |
| 27 #include "ui/native_theme/native_theme.h" | 27 #include "ui/native_theme/native_theme.h" |
| 28 | 28 |
| 29 const CGFloat kMinimumWidth = 460; | 29 const CGFloat kMinimumWidth = 460; |
| 30 const CGFloat kMaximumWidth = 1000; | 30 const CGFloat kMaximumWidth = 1000; |
| 31 const CGFloat kHorizontalMargin = 10; | 31 const CGFloat kHorizontalMargin = 10; |
| 32 const CGFloat kPadding = 5; | 32 const CGFloat kPaddingVertical = 5; |
| 33 const CGFloat kPaddingLeft = 10; | 33 const CGFloat kPaddingHorizontal = 10; |
| 34 const CGFloat kWindowCornerRadius = 2; | 34 const CGFloat kWindowCornerRadius = 2; |
| 35 const CGFloat kWindowAlphaValue = 0.85; | 35 const CGFloat kWindowAlphaValue = 0.85; |
| 36 | 36 |
| 37 @interface ScreenCaptureNotificationController() | 37 @interface ScreenCaptureNotificationController() |
| 38 - (void)hide; | 38 - (void)hide; |
| 39 - (void)populateWithText:(const base::string16&)text; | 39 - (void)populateWithText:(const base::string16&)text; |
| 40 @end | 40 @end |
| 41 | 41 |
| 42 @interface ScreenCaptureNotificationView : NSView | 42 @interface ScreenCaptureNotificationView : NSView |
| 43 @end | 43 @end |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 | 133 |
| 134 // Create button. | 134 // Create button. |
| 135 stopButton_.reset([[BlueLabelButton alloc] initWithFrame:NSZeroRect]); | 135 stopButton_.reset([[BlueLabelButton alloc] initWithFrame:NSZeroRect]); |
| 136 [stopButton_ setTitle:l10n_util::GetNSString( | 136 [stopButton_ setTitle:l10n_util::GetNSString( |
| 137 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP)]; | 137 IDS_MEDIA_SCREEN_CAPTURE_NOTIFICATION_STOP)]; |
| 138 [stopButton_ setTarget:self]; | 138 [stopButton_ setTarget:self]; |
| 139 [stopButton_ setAction:@selector(stopSharing:)]; | 139 [stopButton_ setAction:@selector(stopSharing:)]; |
| 140 [stopButton_ sizeToFit]; | 140 [stopButton_ sizeToFit]; |
| 141 [content addSubview:stopButton_]; | 141 [content addSubview:stopButton_]; |
| 142 | 142 |
| 143 minimizeButton_.reset( | 143 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 144 [[HyperlinkButtonCell buttonWithString:l10n_util::GetNSString( | 144 [[HyperlinkButtonCell alloc] |
| 145 IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)] retain]); | 145 initTextCell:l10n_util::GetNSString( |
| 146 IDS_PASSWORDS_PAGE_VIEW_HIDE_BUTTON)]); |
| 147 [cell setShouldUnderline:NO]; |
| 148 |
| 149 minimizeButton_.reset([[NSButton alloc] initWithFrame:NSZeroRect]); |
| 150 [minimizeButton_ setCell:cell.get()]; |
| 146 [minimizeButton_ sizeToFit]; | 151 [minimizeButton_ sizeToFit]; |
| 147 [minimizeButton_ setTarget:self]; | 152 [minimizeButton_ setTarget:self]; |
| 148 [minimizeButton_ setAction:@selector(minimize:)]; | 153 [minimizeButton_ setAction:@selector(minimize:)]; |
| 149 [content addSubview:minimizeButton_]; | 154 [content addSubview:minimizeButton_]; |
| 150 | 155 |
| 151 CGFloat buttonsWidth = NSWidth([stopButton_ frame]) + kHorizontalMargin + | 156 CGFloat buttonsWidth = NSWidth([stopButton_ frame]) + kHorizontalMargin + |
| 152 NSWidth([minimizeButton_ frame]); | 157 NSWidth([minimizeButton_ frame]); |
| 153 CGFloat totalHeight = kPadding + NSHeight([stopButton_ frame]) + kPadding; | 158 CGFloat totalHeight = |
| 159 kPaddingVertical + NSHeight([stopButton_ frame]) + kPaddingVertical; |
| 154 | 160 |
| 155 // Create grip icon. | 161 // Create grip icon. |
| 156 base::scoped_nsobject<WindowGripView> gripView([[WindowGripView alloc] init]); | 162 base::scoped_nsobject<WindowGripView> gripView([[WindowGripView alloc] init]); |
| 157 [content addSubview:gripView]; | 163 [content addSubview:gripView]; |
| 158 CGFloat gripWidth = NSWidth([gripView frame]); | 164 CGFloat gripWidth = NSWidth([gripView frame]); |
| 159 CGFloat gripHeight = NSHeight([gripView frame]); | 165 CGFloat gripHeight = NSHeight([gripView frame]); |
| 160 [gripView | 166 [gripView setFrameOrigin:NSMakePoint(kPaddingHorizontal, |
| 161 setFrameOrigin:NSMakePoint(kPaddingLeft, (totalHeight - gripHeight) / 2)]; | 167 (totalHeight - gripHeight) / 2)]; |
| 162 | 168 |
| 163 // Create text label. | 169 // Create text label. |
| 164 int maximumWidth = | 170 int maximumWidth = |
| 165 std::min(kMaximumWidth, NSWidth([[NSScreen mainScreen] visibleFrame])); | 171 std::min(kMaximumWidth, NSWidth([[NSScreen mainScreen] visibleFrame])); |
| 166 int maxLabelWidth = maximumWidth - kPaddingLeft - kPadding - | 172 int maxLabelWidth = maximumWidth - kPaddingHorizontal * 2 - |
| 167 kHorizontalMargin * 2 - gripWidth - buttonsWidth; | 173 kHorizontalMargin * 2 - gripWidth - buttonsWidth; |
| 168 gfx::FontList font_list; | 174 gfx::FontList font_list; |
| 169 base::string16 elidedText = | 175 base::string16 elidedText = |
| 170 ElideText(text, font_list, maxLabelWidth, gfx::ELIDE_IN_MIDDLE); | 176 ElideText(text, font_list, maxLabelWidth, gfx::ELIDE_IN_MIDDLE); |
| 171 NSString* statusText = base::SysUTF16ToNSString(elidedText); | 177 NSString* statusText = base::SysUTF16ToNSString(elidedText); |
| 172 base::scoped_nsobject<NSTextField> statusTextField( | 178 base::scoped_nsobject<NSTextField> statusTextField( |
| 173 [[NSTextField alloc] initWithFrame:ui::kWindowSizeDeterminedLater]); | 179 [[NSTextField alloc] initWithFrame:ui::kWindowSizeDeterminedLater]); |
| 174 [statusTextField setEditable:NO]; | 180 [statusTextField setEditable:NO]; |
| 175 [statusTextField setSelectable:NO]; | 181 [statusTextField setSelectable:NO]; |
| 176 [statusTextField setDrawsBackground:NO]; | 182 [statusTextField setDrawsBackground:NO]; |
| 177 [statusTextField setBezeled:NO]; | 183 [statusTextField setBezeled:NO]; |
| 178 [statusTextField setStringValue:statusText]; | 184 [statusTextField setStringValue:statusText]; |
| 179 [statusTextField setFont:font_list.GetPrimaryFont().GetNativeFont()]; | 185 [statusTextField setFont:font_list.GetPrimaryFont().GetNativeFont()]; |
| 180 [statusTextField sizeToFit]; | 186 [statusTextField sizeToFit]; |
| 181 [statusTextField setFrameOrigin:NSMakePoint( | 187 [statusTextField setFrameOrigin:NSMakePoint( |
| 182 kPaddingLeft + kHorizontalMargin + gripWidth, | 188 kPaddingHorizontal + kHorizontalMargin + gripWidth, |
| 183 (totalHeight - NSHeight([statusTextField frame])) / 2)]; | 189 (totalHeight - NSHeight([statusTextField frame])) / 2)]; |
| 184 [content addSubview:statusTextField]; | 190 [content addSubview:statusTextField]; |
| 185 | 191 |
| 186 // Resize content view to fit controls. | 192 // Resize content view to fit controls. |
| 187 CGFloat minimumLableWidth = kMinimumWidth - kPaddingLeft - kPadding - | 193 CGFloat minimumLableWidth = kMinimumWidth - kPaddingHorizontal * 2 - |
| 188 kHorizontalMargin * 2 - gripWidth - buttonsWidth; | 194 kHorizontalMargin * 2 - gripWidth - buttonsWidth; |
| 189 CGFloat lableWidth = | 195 CGFloat lableWidth = |
| 190 std::max(NSWidth([statusTextField frame]), minimumLableWidth); | 196 std::max(NSWidth([statusTextField frame]), minimumLableWidth); |
| 191 CGFloat totalWidth = kPaddingLeft + kPadding + kHorizontalMargin * 2 + | 197 CGFloat totalWidth = kPaddingHorizontal * 2 + kHorizontalMargin * 2 + |
| 192 gripWidth + lableWidth + buttonsWidth; | 198 gripWidth + lableWidth + buttonsWidth; |
| 193 [content setFrame:NSMakeRect(0, 0, totalWidth, totalHeight)]; | 199 [content setFrame:NSMakeRect(0, 0, totalWidth, totalHeight)]; |
| 194 | 200 |
| 195 // Move the buttons to the right place. | 201 // Move the buttons to the right place. |
| 196 NSPoint buttonOrigin = | 202 NSPoint buttonOrigin = NSMakePoint( |
| 197 NSMakePoint(totalWidth - kPadding - buttonsWidth, kPadding); | 203 totalWidth - kPaddingHorizontal - buttonsWidth, kPaddingVertical); |
| 198 [stopButton_ setFrameOrigin:buttonOrigin]; | 204 [stopButton_ setFrameOrigin:buttonOrigin]; |
| 199 | 205 |
| 200 [minimizeButton_ setFrameOrigin:NSMakePoint( | 206 [minimizeButton_ setFrameOrigin:NSMakePoint( |
| 201 totalWidth - kPadding - NSWidth([minimizeButton_ frame]), | 207 totalWidth - kPaddingHorizontal - NSWidth([minimizeButton_ frame]), |
| 202 (totalHeight - NSHeight([minimizeButton_ frame])) / 2)]; | 208 (totalHeight - NSHeight([minimizeButton_ frame])) / 2)]; |
| 203 | 209 |
| 204 if (base::i18n::IsRTL()) { | 210 if (base::i18n::IsRTL()) { |
| 205 [stopButton_ | 211 [stopButton_ |
| 206 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([stopButton_ frame]), | 212 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([stopButton_ frame]), |
| 207 NSMinY([stopButton_ frame]))]; | 213 NSMinY([stopButton_ frame]))]; |
| 208 [minimizeButton_ | 214 [minimizeButton_ |
| 209 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([minimizeButton_ frame]), | 215 setFrameOrigin:NSMakePoint(totalWidth - NSMaxX([minimizeButton_ frame]), |
| 210 NSMinY([minimizeButton_ frame]))]; | 216 NSMinY([minimizeButton_ frame]))]; |
| 211 [statusTextField | 217 [statusTextField |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 self = [super | 249 self = [super |
| 244 initWithFrame:NSMakeRect(0, 0, gripImage.Width(), gripImage.Height())]; | 250 initWithFrame:NSMakeRect(0, 0, gripImage.Width(), gripImage.Height())]; |
| 245 [self setImage:gripImage.ToNSImage()]; | 251 [self setImage:gripImage.ToNSImage()]; |
| 246 return self; | 252 return self; |
| 247 } | 253 } |
| 248 | 254 |
| 249 - (BOOL)mouseDownCanMoveWindow { | 255 - (BOOL)mouseDownCanMoveWindow { |
| 250 return YES; | 256 return YES; |
| 251 } | 257 } |
| 252 @end | 258 @end |
| OLD | NEW |