Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/chooser_content_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/chooser_content_view_cocoa.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "base/strings/sys_string_conversions.h" | 10 #include "base/strings/sys_string_conversions.h" |
| 11 #include "chrome/browser/chooser_controller/chooser_controller.h" | 11 #include "chrome/browser/chooser_controller/chooser_controller.h" |
| 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" | 12 #import "chrome/browser/ui/cocoa/constrained_window/constrained_window_button.h" |
| 13 #include "chrome/browser/ui/cocoa/spinner_view.h" | 13 #include "chrome/browser/ui/cocoa/spinner_view.h" |
| 14 #include "chrome/grit/generated_resources.h" | 14 #include "chrome/grit/generated_resources.h" |
| 15 #include "skia/ext/skia_utils_mac.h" | |
| 15 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" | 16 #import "third_party/google_toolbox_for_mac/src/AppKit/GTMUILocalizerAndLayoutTw eaker.h" |
| 16 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" | 17 #import "ui/base/cocoa/controls/hyperlink_button_cell.h" |
| 17 #include "ui/base/l10n/l10n_util_mac.h" | 18 #include "ui/base/l10n/l10n_util_mac.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
| 20 #include "ui/gfx/color_palette.h" | |
| 21 #include "ui/gfx/image/image_skia_util_mac.h" | |
| 22 #include "ui/gfx/paint_vector_icon.h" | |
| 23 #include "ui/gfx/vector_icons_public.h" | |
| 19 #include "ui/resources/grit/ui_resources.h" | 24 #include "ui/resources/grit/ui_resources.h" |
| 20 | 25 |
| 21 namespace { | 26 namespace { |
| 22 | 27 |
| 23 // Chooser width. | 28 // Chooser width. |
| 24 const CGFloat kChooserWidth = 350.0f; | 29 const CGFloat kChooserWidth = 350.0f; |
| 25 | 30 |
| 26 // Chooser height. | 31 // Chooser height. |
| 27 const CGFloat kChooserHeight = 300.0f; | 32 const CGFloat kChooserHeight = 300.0f; |
| 28 | 33 |
| 29 // Signal strength level image size. | 34 // Row view image size. |
| 30 const CGFloat kSignalStrengthLevelImageSize = 20.0f; | 35 const CGFloat kRowViewImageSize = 20.0f; |
| 31 | 36 |
| 32 // Table row view height. | 37 // Table row view height. |
| 33 const CGFloat kTableRowViewHeight = 23.0f; | 38 const CGFloat kTableRowViewOneLineHeight = 23.0f; |
| 39 const CGFloat kTableRowViewTwoLinesHeight = 39.0f; | |
| 34 | 40 |
| 35 // Spinner size. | 41 // Spinner size. |
| 36 const CGFloat kSpinnerSize = 24.0f; | 42 const CGFloat kSpinnerSize = 24.0f; |
| 37 | 43 |
| 38 // Distance between the chooser border and the view that is closest to the | 44 // Distance between the chooser border and the view that is closest to the |
| 39 // border. | 45 // border. |
| 40 const CGFloat kMarginX = 20.0f; | 46 const CGFloat kMarginX = 20.0f; |
| 41 const CGFloat kMarginY = 20.0f; | 47 const CGFloat kMarginY = 20.0f; |
| 42 | 48 |
| 43 // Distance between two views inside the chooser. | 49 // Distance between two views inside the chooser. |
| 44 const CGFloat kHorizontalPadding = 10.0f; | 50 const CGFloat kHorizontalPadding = 10.0f; |
| 45 const CGFloat kVerticalPadding = 10.0f; | 51 const CGFloat kVerticalPadding = 10.0f; |
| 46 | 52 |
| 47 // Separator alpha value. | 53 // Separator alpha value. |
| 48 const CGFloat kSeparatorAlphaValue = 0.6f; | 54 const CGFloat kSeparatorAlphaValue = 0.6f; |
| 49 | 55 |
| 50 // Separator height. | 56 // Separator height. |
| 51 const CGFloat kSeparatorHeight = 1.0f; | 57 const CGFloat kSeparatorHeight = 1.0f; |
| 52 | 58 |
| 59 // Distance between two views inside the table row view. | |
| 60 const CGFloat kTableRowViewHorizontalPadding = 5.0f; | |
| 61 const CGFloat kTableRowViewVerticalPadding = 1.0f; | |
| 62 | |
| 53 // The lookup table for signal strength level image. | 63 // The lookup table for signal strength level image. |
| 54 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, | 64 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, |
| 55 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, | 65 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, |
| 56 IDR_SIGNAL_4_BAR}; | 66 IDR_SIGNAL_4_BAR}; |
| 57 | 67 |
| 68 // Creates a label with |text|. | |
| 69 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { | |
| 70 base::scoped_nsobject<NSTextField> label( | |
| 71 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 72 [label setDrawsBackground:NO]; | |
| 73 [label setBezeled:NO]; | |
| 74 [label setEditable:NO]; | |
| 75 [label setSelectable:NO]; | |
| 76 [label setStringValue:text]; | |
| 77 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 78 [label sizeToFit]; | |
| 79 return label; | |
| 80 } | |
| 81 | |
| 58 } // namespace | 82 } // namespace |
| 59 | 83 |
| 60 // A table row view that contains one line of text, and optionally contains an | 84 // A table row view that contains one line of text, and optionally contains an |
| 61 // image in front of the text. | 85 // image in front of the text. |
| 62 @interface ChooserContentTableRowView : NSView { | 86 @interface ChooserContentTableRowView : NSView { |
| 63 @private | 87 @private |
| 64 base::scoped_nsobject<NSImageView> image_; | 88 base::scoped_nsobject<NSImageView> image_; |
| 65 base::scoped_nsobject<NSTextField> text_; | 89 base::scoped_nsobject<NSTextField> text_; |
| 90 base::scoped_nsobject<NSTextField> pairedStatus_; | |
| 66 } | 91 } |
| 67 | 92 |
| 68 // Designated initializer. | 93 // This initializer is used when the chooser needs to show no devices found |
|
Jeffrey Yasskin
2016/09/14 20:08:36
"show the no-devices-found message"
juncai
2016/09/14 23:13:07
Done.
| |
| 94 // message. | |
| 95 - (instancetype)initWithText:(NSString*)text; | |
|
Jeffrey Yasskin
2016/09/14 20:08:36
https://google.github.io/styleguide/objcguide.xml?
juncai
2016/09/14 23:13:07
Done.
| |
| 96 | |
| 69 - (instancetype)initWithText:(NSString*)text | 97 - (instancetype)initWithText:(NSString*)text |
| 70 signalStrengthLevel:(NSInteger)level; | 98 signalStrengthLevel:(NSInteger)level |
| 99 isConnected:(bool)isConnected | |
| 100 isPaired:(bool)isPaired | |
| 101 rowHeight:(CGFloat)rowHeight | |
| 102 textNeedIndentation:(bool)textNeedIndentation; | |
| 71 | 103 |
| 72 // Gets the image in front of the text. | 104 // Gets the image in front of the text. |
| 73 - (NSImageView*)image; | 105 - (NSImageView*)image; |
| 74 | 106 |
| 75 // Gets the text. | 107 // Gets the text. |
| 76 - (NSTextField*)text; | 108 - (NSTextField*)text; |
| 77 | 109 |
| 110 // Gets the paired status. | |
| 111 - (NSTextField*)pairedStatus; | |
| 112 | |
| 78 @end | 113 @end |
| 79 | 114 |
| 80 @implementation ChooserContentTableRowView | 115 @implementation ChooserContentTableRowView |
| 81 | 116 |
| 82 - (instancetype)initWithText:(NSString*)text | 117 - (instancetype)initWithText:(NSString*)text { |
| 83 signalStrengthLevel:(NSInteger)level { | |
| 84 if ((self = [super initWithFrame:NSZeroRect])) { | 118 if ((self = [super initWithFrame:NSZeroRect])) { |
| 85 if (level != -1) { | 119 text_ = CreateLabel(text); |
| 86 DCHECK_GE(level, 0); | |
| 87 DCHECK_LT(level, base::checked_cast<NSInteger>( | |
| 88 arraysize(kSignalStrengthLevelImageIds))); | |
| 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 90 NSImage* signalStrengthLevelImage = | |
| 91 rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) | |
| 92 .ToNSImage(); | |
| 93 | |
| 94 image_.reset([[NSImageView alloc] | |
| 95 initWithFrame:NSMakeRect(0, (kTableRowViewHeight - | |
| 96 kSignalStrengthLevelImageSize) / | |
| 97 2, | |
| 98 kSignalStrengthLevelImageSize, | |
| 99 kSignalStrengthLevelImageSize)]); | |
| 100 [image_ setImage:signalStrengthLevelImage]; | |
| 101 [self addSubview:image_]; | |
| 102 } | |
| 103 | |
| 104 text_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 105 [text_ setDrawsBackground:NO]; | |
| 106 [text_ setBezeled:NO]; | |
| 107 [text_ setEditable:NO]; | |
| 108 [text_ setSelectable:NO]; | |
| 109 [text_ setStringValue:text]; | |
| 110 [text_ setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 111 [text_ sizeToFit]; | |
| 112 CGFloat textHeight = NSHeight([text_ frame]); | 120 CGFloat textHeight = NSHeight([text_ frame]); |
| 113 [text_ setFrameOrigin:NSMakePoint( | 121 CGFloat textOriginX = kTableRowViewHorizontalPadding; |
| 114 level == -1 ? 0 : kSignalStrengthLevelImageSize + | 122 CGFloat textOriginY = (kTableRowViewOneLineHeight - textHeight) / 2; |
| 115 kHorizontalPadding, | 123 [text_ setFrameOrigin:NSMakePoint(textOriginX, textOriginY)]; |
| 116 (kTableRowViewHeight - textHeight) / 2)]; | |
| 117 [self addSubview:text_]; | 124 [self addSubview:text_]; |
| 118 } | 125 } |
| 119 | 126 |
| 120 return self; | 127 return self; |
| 128 } | |
| 129 | |
| 130 - (instancetype)initWithText:(NSString*)text | |
| 131 signalStrengthLevel:(NSInteger)level | |
| 132 isConnected:(bool)isConnected | |
| 133 isPaired:(bool)isPaired | |
| 134 rowHeight:(CGFloat)rowHeight | |
| 135 textNeedIndentation:(bool)textNeedIndentation { | |
| 136 if ((self = [super initWithFrame:NSZeroRect])) { | |
| 137 // Create the views. | |
| 138 // Image. | |
| 139 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 140 NSImage* image = nullptr; | |
| 141 if (isConnected) { | |
| 142 image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 143 gfx::VectorIconId::BLUETOOTH_CONNECTED, gfx::kChromeIconGrey)); | |
| 144 } else if (level != -1) { | |
| 145 DCHECK_GE(level, 0); | |
| 146 DCHECK_LT(level, base::checked_cast<NSInteger>( | |
| 147 arraysize(kSignalStrengthLevelImageIds))); | |
| 148 image = rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) | |
| 149 .ToNSImage(); | |
| 150 } | |
| 151 | |
| 152 CGFloat imageOriginX = kTableRowViewHorizontalPadding; | |
| 153 CGFloat imageOriginY = (rowHeight - kRowViewImageSize) / 2; | |
| 154 if (image) { | |
| 155 image_.reset([[NSImageView alloc] | |
| 156 initWithFrame:NSMakeRect(imageOriginX, imageOriginY, | |
| 157 kRowViewImageSize, kRowViewImageSize)]); | |
| 158 [image_ setImage:image]; | |
| 159 [self addSubview:image_]; | |
| 160 } | |
| 161 | |
| 162 // Text. | |
| 163 text_ = CreateLabel(text); | |
| 164 CGFloat textHeight = NSHeight([text_ frame]); | |
| 165 | |
| 166 // Paired status. | |
| 167 CGFloat pairedStatusHeight = 0.0f; | |
| 168 if (isPaired) { | |
| 169 pairedStatus_ = CreateLabel( | |
| 170 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT)); | |
| 171 [pairedStatus_ | |
| 172 setTextColor:skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700)]; | |
| 173 pairedStatusHeight = NSHeight([pairedStatus_ frame]); | |
| 174 } | |
| 175 | |
| 176 // Lay out the views. | |
| 177 // Text. | |
| 178 CGFloat textOriginX = kTableRowViewHorizontalPadding; | |
| 179 if (textNeedIndentation) | |
| 180 textOriginX += imageOriginX + kRowViewImageSize; | |
| 181 CGFloat textOriginY; | |
| 182 if (isPaired) { | |
| 183 textOriginY = pairedStatusHeight + | |
| 184 (rowHeight - textHeight - pairedStatusHeight - | |
| 185 kTableRowViewVerticalPadding) / | |
| 186 2 + | |
| 187 kTableRowViewVerticalPadding; | |
| 188 } else { | |
| 189 textOriginY = (rowHeight - textHeight) / 2; | |
| 190 } | |
| 191 | |
| 192 [text_ setFrameOrigin:NSMakePoint(textOriginX, textOriginY)]; | |
| 193 [self addSubview:text_]; | |
| 194 | |
| 195 // Paired status. | |
| 196 if (isPaired) { | |
| 197 CGFloat pairedStatusOriginX = textOriginX; | |
| 198 CGFloat pairedStatusOriginY = | |
| 199 (rowHeight - textHeight - pairedStatusHeight - | |
| 200 kTableRowViewVerticalPadding) / | |
| 201 2; | |
| 202 [pairedStatus_ | |
| 203 setFrameOrigin:NSMakePoint(pairedStatusOriginX, pairedStatusOriginY)]; | |
| 204 [self addSubview:pairedStatus_]; | |
| 205 } | |
| 206 } | |
| 207 | |
| 208 return self; | |
| 121 } | 209 } |
| 122 | 210 |
| 123 - (NSImageView*)image { | 211 - (NSImageView*)image { |
| 124 return image_.get(); | 212 return image_.get(); |
| 125 } | 213 } |
| 126 | 214 |
| 127 - (NSTextField*)text { | 215 - (NSTextField*)text { |
| 128 return text_.get(); | 216 return text_.get(); |
| 129 } | 217 } |
| 130 | 218 |
| 219 - (NSTextField*)pairedStatus { | |
| 220 return pairedStatus_.get(); | |
| 221 } | |
| 222 | |
| 131 @end | 223 @end |
| 132 | 224 |
| 133 class ChooserContentViewController : public ChooserController::View { | 225 class ChooserContentViewController : public ChooserController::View { |
| 134 public: | 226 public: |
| 135 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, | 227 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, |
| 136 ChooserController* chooser_controller, | 228 ChooserController* chooser_controller, |
| 137 NSTableView* table_view, | 229 NSTableView* table_view, |
| 138 SpinnerView* spinner, | 230 SpinnerView* spinner, |
| 139 NSTextField* status, | 231 NSTextField* status, |
| 140 NSButton* rescan_button); | 232 NSButton* rescan_button); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 395 |
| 304 if ((self = [super initWithFrame:chooserFrame])) { | 396 if ((self = [super initWithFrame:chooserFrame])) { |
| 305 chooserController_ = std::move(chooserController); | 397 chooserController_ = std::move(chooserController); |
| 306 | 398 |
| 307 // Create the views. | 399 // Create the views. |
| 308 // Title. | 400 // Title. |
| 309 titleView_ = [self createChooserTitle:chooserTitle]; | 401 titleView_ = [self createChooserTitle:chooserTitle]; |
| 310 titleHeight_ = NSHeight([titleView_ frame]); | 402 titleHeight_ = NSHeight([titleView_ frame]); |
| 311 | 403 |
| 312 // Status. | 404 // Status. |
| 313 status_ = [self createTextField:l10n_util::GetNSString( | 405 status_ = CreateLabel( |
| 314 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)]; | 406 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)); |
| 315 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; | 407 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; |
| 316 // The height is arbitrary as it will be adjusted later. | 408 // The height is arbitrary as it will be adjusted later. |
| 317 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; | 409 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; |
| 318 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; | 410 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; |
| 319 statusHeight_ = NSHeight([status_ frame]); | 411 statusHeight_ = NSHeight([status_ frame]); |
| 320 | 412 |
| 321 // Re-scan button. | 413 // Re-scan button. |
| 322 rescanButton_ = | 414 rescanButton_ = |
| 323 [self createHyperlinkButtonWithText: | 415 [self createHyperlinkButtonWithText: |
| 324 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; | 416 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; |
| 325 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); | 417 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); |
| 326 | 418 |
| 327 // Connect button. | 419 // Connect button. |
| 328 connectButton_ = [self createConnectButton]; | 420 connectButton_ = [self createConnectButton]; |
| 329 connectButtonWidth_ = NSWidth([connectButton_ frame]); | 421 connectButtonWidth_ = NSWidth([connectButton_ frame]); |
| 330 connectButtonHeight_ = NSHeight([connectButton_ frame]); | 422 connectButtonHeight_ = NSHeight([connectButton_ frame]); |
| 331 | 423 |
| 332 // Cancel button. | 424 // Cancel button. |
| 333 cancelButton_ = [self createCancelButton]; | 425 cancelButton_ = [self createCancelButton]; |
| 334 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); | 426 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); |
| 335 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); | 427 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); |
| 336 | 428 |
| 337 CGFloat buttonRowHeight = | 429 CGFloat buttonRowHeight = |
| 338 std::max(connectButtonHeight_, cancelButtonHeight_); | 430 std::max(connectButtonHeight_, cancelButtonHeight_); |
| 339 | 431 |
| 340 // Separator. | 432 // Separator. |
| 341 separator_ = [self createSeparator]; | 433 separator_ = [self createSeparator]; |
| 342 | 434 |
| 343 // Message. | 435 // Message. |
| 344 message_ = [self createTextField:l10n_util::GetNSStringF( | 436 message_ = CreateLabel(l10n_util::GetNSStringF( |
| 345 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, | 437 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, base::string16())); |
| 346 base::string16())]; | |
| 347 CGFloat messageWidth = NSWidth([message_ frame]); | 438 CGFloat messageWidth = NSWidth([message_ frame]); |
| 348 messageHeight_ = NSHeight([message_ frame]); | 439 messageHeight_ = NSHeight([message_ frame]); |
| 349 | 440 |
| 350 // Help button. | 441 // Help button. |
| 351 helpButton_ = [self | 442 helpButton_ = [self |
| 352 createHyperlinkButtonWithText: | 443 createHyperlinkButtonWithText: |
| 353 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; | 444 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; |
| 354 | 445 |
| 355 // ScollView embedding with TableView. | 446 // ScollView embedding with TableView. |
| 356 noStatusOrRescanButtonShown_.scroll_view_frame = | 447 noStatusOrRescanButtonShown_.scroll_view_frame = |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 [titleView setEditable:NO]; | 573 [titleView setEditable:NO]; |
| 483 [titleView setSelectable:NO]; | 574 [titleView setSelectable:NO]; |
| 484 [titleView setStringValue:title]; | 575 [titleView setStringValue:title]; |
| 485 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 576 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 486 // The height is arbitrary as it will be adjusted later. | 577 // The height is arbitrary as it will be adjusted later. |
| 487 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; | 578 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; |
| 488 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | 579 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; |
| 489 return titleView; | 580 return titleView; |
| 490 } | 581 } |
| 491 | 582 |
| 492 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)rowIndex { | 583 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)row { |
| 493 NSInteger level = -1; | 584 NSInteger level = -1; |
| 585 bool isConnected = false; | |
| 586 bool isPaired = false; | |
| 494 size_t numOptions = chooserController_->NumOptions(); | 587 size_t numOptions = chooserController_->NumOptions(); |
| 495 if (chooserController_->ShouldShowIconBeforeText() && numOptions > 0) { | 588 base::scoped_nsobject<NSView> tableRowView; |
| 496 DCHECK_GE(rowIndex, 0); | 589 if (numOptions == 0) { |
| 497 DCHECK_LT(rowIndex, base::checked_cast<NSInteger>(numOptions)); | 590 DCHECK_EQ(0, row); |
| 498 level = base::checked_cast<NSInteger>( | 591 tableRowView.reset([[ChooserContentTableRowView alloc] |
| 499 chooserController_->GetSignalStrengthLevel( | 592 initWithText:[self optionAtIndex:row]]); |
| 500 base::checked_cast<size_t>(rowIndex))); | 593 } else { |
| 594 DCHECK_GE(row, 0); | |
| 595 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); | |
| 596 size_t rowIndex = base::checked_cast<size_t>(row); | |
| 597 if (chooserController_->ShouldShowIconBeforeText()) { | |
| 598 level = base::checked_cast<NSInteger>( | |
| 599 chooserController_->GetSignalStrengthLevel(rowIndex)); | |
| 600 } | |
| 601 isConnected = chooserController_->IsConnected(rowIndex); | |
| 602 isPaired = chooserController_->IsPaired(rowIndex); | |
| 603 bool textNeedIndentation = false; | |
| 604 for (size_t i = 0; i < numOptions; ++i) { | |
| 605 if (chooserController_->GetSignalStrengthLevel(i) != -1 || | |
|
Jeffrey Yasskin
2016/09/14 20:08:36
I think we want to indent rows that have neither a
juncai
2016/09/14 23:13:07
I uploaded a screenshot from Mac showing the text
Jeffrey Yasskin
2016/09/14 23:52:03
Thanks, I missed the loop somehow. :-/ If the firs
juncai
2016/09/15 01:00:02
Yes, it will keep all the text aligned. It was sug
| |
| 606 chooserController_->IsConnected(i)) { | |
| 607 textNeedIndentation = true; | |
| 608 break; | |
| 609 } | |
| 610 } | |
| 611 tableRowView.reset([[ChooserContentTableRowView alloc] | |
| 612 initWithText:[self optionAtIndex:row] | |
| 613 signalStrengthLevel:level | |
| 614 isConnected:isConnected | |
| 615 isPaired:isPaired | |
| 616 rowHeight:[self tableRowViewHeight:row] | |
| 617 textNeedIndentation:textNeedIndentation]); | |
| 501 } | 618 } |
| 502 | 619 |
| 503 base::scoped_nsobject<NSView> tableRowView([[ChooserContentTableRowView alloc] | |
| 504 initWithText:[self optionAtIndex:rowIndex] | |
| 505 signalStrengthLevel:level]); | |
| 506 return tableRowView; | 620 return tableRowView; |
| 507 } | 621 } |
| 508 | 622 |
| 509 - (CGFloat)tableRowViewHeight:(NSInteger)row { | 623 - (CGFloat)tableRowViewHeight:(NSInteger)row { |
| 510 return kTableRowViewHeight; | 624 size_t numOptions = chooserController_->NumOptions(); |
| 625 if (numOptions == 0) { | |
| 626 DCHECK_EQ(0, row); | |
| 627 return kTableRowViewOneLineHeight; | |
| 628 } | |
| 629 | |
| 630 DCHECK_GE(row, 0); | |
| 631 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); | |
| 632 size_t rowIndex = base::checked_cast<size_t>(row); | |
| 633 return chooserController_->IsPaired(rowIndex) ? kTableRowViewTwoLinesHeight | |
| 634 : kTableRowViewOneLineHeight; | |
| 511 } | 635 } |
| 512 | 636 |
| 513 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { | 637 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { |
| 514 base::scoped_nsobject<NSButton> button( | 638 base::scoped_nsobject<NSButton> button( |
| 515 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 639 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 516 [button setButtonType:NSMomentaryPushInButton]; | 640 [button setButtonType:NSMomentaryPushInButton]; |
| 517 [button setTitle:title]; | 641 [button setTitle:title]; |
| 518 [button sizeToFit]; | 642 [button sizeToFit]; |
| 519 return button; | 643 return button; |
| 520 } | 644 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 533 | 657 |
| 534 - (base::scoped_nsobject<NSBox>)createSeparator { | 658 - (base::scoped_nsobject<NSBox>)createSeparator { |
| 535 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); | 659 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); |
| 536 [spacer setBoxType:NSBoxSeparator]; | 660 [spacer setBoxType:NSBoxSeparator]; |
| 537 [spacer setBorderType:NSLineBorder]; | 661 [spacer setBorderType:NSLineBorder]; |
| 538 [spacer setAlphaValue:kSeparatorAlphaValue]; | 662 [spacer setAlphaValue:kSeparatorAlphaValue]; |
| 539 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; | 663 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; |
| 540 return spacer; | 664 return spacer; |
| 541 } | 665 } |
| 542 | 666 |
| 543 - (base::scoped_nsobject<NSTextField>)createTextField:(NSString*)text { | |
| 544 base::scoped_nsobject<NSTextField> textField( | |
| 545 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 546 [textField setDrawsBackground:NO]; | |
| 547 [textField setBezeled:NO]; | |
| 548 [textField setEditable:NO]; | |
| 549 [textField setSelectable:NO]; | |
| 550 [textField setStringValue:text]; | |
| 551 [textField setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 552 [textField sizeToFit]; | |
| 553 return textField; | |
| 554 } | |
| 555 | |
| 556 - (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText: | 667 - (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText: |
| 557 (NSString*)text { | 668 (NSString*)text { |
| 558 base::scoped_nsobject<NSButton> button( | 669 base::scoped_nsobject<NSButton> button( |
| 559 [[NSButton alloc] initWithFrame:NSZeroRect]); | 670 [[NSButton alloc] initWithFrame:NSZeroRect]); |
| 560 base::scoped_nsobject<HyperlinkButtonCell> cell( | 671 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 561 [[HyperlinkButtonCell alloc] initTextCell:text]); | 672 [[HyperlinkButtonCell alloc] initTextCell:text]); |
| 562 [button setCell:cell.get()]; | 673 [button setCell:cell.get()]; |
| 563 [button sizeToFit]; | 674 [button sizeToFit]; |
| 564 return button; | 675 return button; |
| 565 } | 676 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 808 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
| 698 return [tableRowView image]; | 809 return [tableRowView image]; |
| 699 } | 810 } |
| 700 | 811 |
| 701 - (NSTextField*)tableRowViewText:(NSInteger)row { | 812 - (NSTextField*)tableRowViewText:(NSInteger)row { |
| 702 ChooserContentTableRowView* tableRowView = | 813 ChooserContentTableRowView* tableRowView = |
| 703 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 814 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
| 704 return [tableRowView text]; | 815 return [tableRowView text]; |
| 705 } | 816 } |
| 706 | 817 |
| 818 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { | |
| 819 ChooserContentTableRowView* tableRowView = | |
| 820 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | |
| 821 return [tableRowView pairedStatus]; | |
| 822 } | |
| 823 | |
| 707 @end | 824 @end |
| OLD | NEW |