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