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 // Designated initializer. |
| 94 // This initializer is used when the chooser needs to show the no-devices-found |
| 95 // message. |
| 96 - (instancetype)initWithText:(NSString*)text; |
| 97 |
| 98 // Designated initializer. |
69 - (instancetype)initWithText:(NSString*)text | 99 - (instancetype)initWithText:(NSString*)text |
70 signalStrengthLevel:(NSInteger)level; | 100 signalStrengthLevel:(NSInteger)level |
| 101 isConnected:(bool)isConnected |
| 102 isPaired:(bool)isPaired |
| 103 rowHeight:(CGFloat)rowHeight |
| 104 textNeedIndentation:(bool)textNeedIndentation; |
71 | 105 |
72 // Gets the image in front of the text. | 106 // Gets the image in front of the text. |
73 - (NSImageView*)image; | 107 - (NSImageView*)image; |
74 | 108 |
75 // Gets the text. | 109 // Gets the text. |
76 - (NSTextField*)text; | 110 - (NSTextField*)text; |
77 | 111 |
| 112 // Gets the paired status. |
| 113 - (NSTextField*)pairedStatus; |
| 114 |
78 @end | 115 @end |
79 | 116 |
80 @implementation ChooserContentTableRowView | 117 @implementation ChooserContentTableRowView |
81 | 118 |
82 - (instancetype)initWithText:(NSString*)text | 119 - (instancetype)initWithText:(NSString*)text { |
83 signalStrengthLevel:(NSInteger)level { | |
84 if ((self = [super initWithFrame:NSZeroRect])) { | 120 if ((self = [super initWithFrame:NSZeroRect])) { |
85 if (level != -1) { | 121 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]); | 122 CGFloat textHeight = NSHeight([text_ frame]); |
113 [text_ setFrameOrigin:NSMakePoint( | 123 CGFloat textOriginX = kTableRowViewHorizontalPadding; |
114 level == -1 ? 0 : kSignalStrengthLevelImageSize + | 124 CGFloat textOriginY = (kTableRowViewOneLineHeight - textHeight) / 2; |
115 kHorizontalPadding, | 125 [text_ setFrameOrigin:NSMakePoint(textOriginX, textOriginY)]; |
116 (kTableRowViewHeight - textHeight) / 2)]; | |
117 [self addSubview:text_]; | 126 [self addSubview:text_]; |
118 } | 127 } |
119 | 128 |
120 return self; | 129 return self; |
| 130 } |
| 131 |
| 132 - (instancetype)initWithText:(NSString*)text |
| 133 signalStrengthLevel:(NSInteger)level |
| 134 isConnected:(bool)isConnected |
| 135 isPaired:(bool)isPaired |
| 136 rowHeight:(CGFloat)rowHeight |
| 137 textNeedIndentation:(bool)textNeedIndentation { |
| 138 if ((self = [super initWithFrame:NSZeroRect])) { |
| 139 // Create the views. |
| 140 // Image. |
| 141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 142 NSImage* image = nullptr; |
| 143 if (isConnected) { |
| 144 image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 145 gfx::VectorIconId::BLUETOOTH_CONNECTED, gfx::kChromeIconGrey)); |
| 146 } else if (level != -1) { |
| 147 DCHECK_GE(level, 0); |
| 148 DCHECK_LT(level, base::checked_cast<NSInteger>( |
| 149 arraysize(kSignalStrengthLevelImageIds))); |
| 150 image = rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) |
| 151 .ToNSImage(); |
| 152 } |
| 153 |
| 154 CGFloat imageOriginX = kTableRowViewHorizontalPadding; |
| 155 CGFloat imageOriginY = (rowHeight - kRowViewImageSize) / 2; |
| 156 if (image) { |
| 157 image_.reset([[NSImageView alloc] |
| 158 initWithFrame:NSMakeRect(imageOriginX, imageOriginY, |
| 159 kRowViewImageSize, kRowViewImageSize)]); |
| 160 [image_ setImage:image]; |
| 161 [self addSubview:image_]; |
| 162 } |
| 163 |
| 164 // Text. |
| 165 text_ = CreateLabel(text); |
| 166 CGFloat textHeight = NSHeight([text_ frame]); |
| 167 |
| 168 // Paired status. |
| 169 CGFloat pairedStatusHeight = 0.0f; |
| 170 if (isPaired) { |
| 171 pairedStatus_ = CreateLabel( |
| 172 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT)); |
| 173 [pairedStatus_ |
| 174 setTextColor:skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700)]; |
| 175 pairedStatusHeight = NSHeight([pairedStatus_ frame]); |
| 176 } |
| 177 |
| 178 // Lay out the views. |
| 179 // Text. |
| 180 CGFloat textOriginX = kTableRowViewHorizontalPadding; |
| 181 if (textNeedIndentation) |
| 182 textOriginX += imageOriginX + kRowViewImageSize; |
| 183 CGFloat textOriginY; |
| 184 if (isPaired) { |
| 185 textOriginY = pairedStatusHeight + |
| 186 (rowHeight - textHeight - pairedStatusHeight - |
| 187 kTableRowViewVerticalPadding) / |
| 188 2 + |
| 189 kTableRowViewVerticalPadding; |
| 190 } else { |
| 191 textOriginY = (rowHeight - textHeight) / 2; |
| 192 } |
| 193 |
| 194 [text_ setFrameOrigin:NSMakePoint(textOriginX, textOriginY)]; |
| 195 [self addSubview:text_]; |
| 196 |
| 197 // Paired status. |
| 198 if (isPaired) { |
| 199 CGFloat pairedStatusOriginX = textOriginX; |
| 200 CGFloat pairedStatusOriginY = |
| 201 (rowHeight - textHeight - pairedStatusHeight - |
| 202 kTableRowViewVerticalPadding) / |
| 203 2; |
| 204 [pairedStatus_ |
| 205 setFrameOrigin:NSMakePoint(pairedStatusOriginX, pairedStatusOriginY)]; |
| 206 [self addSubview:pairedStatus_]; |
| 207 } |
| 208 } |
| 209 |
| 210 return self; |
121 } | 211 } |
122 | 212 |
123 - (NSImageView*)image { | 213 - (NSImageView*)image { |
124 return image_.get(); | 214 return image_.get(); |
125 } | 215 } |
126 | 216 |
127 - (NSTextField*)text { | 217 - (NSTextField*)text { |
128 return text_.get(); | 218 return text_.get(); |
129 } | 219 } |
130 | 220 |
| 221 - (NSTextField*)pairedStatus { |
| 222 return pairedStatus_.get(); |
| 223 } |
| 224 |
131 @end | 225 @end |
132 | 226 |
133 class ChooserContentViewController : public ChooserController::View { | 227 class ChooserContentViewController : public ChooserController::View { |
134 public: | 228 public: |
135 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, | 229 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, |
136 ChooserController* chooser_controller, | 230 ChooserController* chooser_controller, |
137 NSTableView* table_view, | 231 NSTableView* table_view, |
138 SpinnerView* spinner, | 232 SpinnerView* spinner, |
139 NSTextField* status, | 233 NSTextField* status, |
140 NSButton* rescan_button); | 234 NSButton* rescan_button); |
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
303 | 397 |
304 if ((self = [super initWithFrame:chooserFrame])) { | 398 if ((self = [super initWithFrame:chooserFrame])) { |
305 chooserController_ = std::move(chooserController); | 399 chooserController_ = std::move(chooserController); |
306 | 400 |
307 // Create the views. | 401 // Create the views. |
308 // Title. | 402 // Title. |
309 titleView_ = [self createChooserTitle:chooserTitle]; | 403 titleView_ = [self createChooserTitle:chooserTitle]; |
310 titleHeight_ = NSHeight([titleView_ frame]); | 404 titleHeight_ = NSHeight([titleView_ frame]); |
311 | 405 |
312 // Status. | 406 // Status. |
313 status_ = [self createTextField:l10n_util::GetNSString( | 407 status_ = CreateLabel( |
314 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)]; | 408 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)); |
315 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; | 409 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; |
316 // The height is arbitrary as it will be adjusted later. | 410 // The height is arbitrary as it will be adjusted later. |
317 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; | 411 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; |
318 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; | 412 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; |
319 statusHeight_ = NSHeight([status_ frame]); | 413 statusHeight_ = NSHeight([status_ frame]); |
320 | 414 |
321 // Re-scan button. | 415 // Re-scan button. |
322 rescanButton_ = | 416 rescanButton_ = |
323 [self createHyperlinkButtonWithText: | 417 [self createHyperlinkButtonWithText: |
324 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; | 418 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; |
325 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); | 419 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); |
326 | 420 |
327 // Connect button. | 421 // Connect button. |
328 connectButton_ = [self createConnectButton]; | 422 connectButton_ = [self createConnectButton]; |
329 connectButtonWidth_ = NSWidth([connectButton_ frame]); | 423 connectButtonWidth_ = NSWidth([connectButton_ frame]); |
330 connectButtonHeight_ = NSHeight([connectButton_ frame]); | 424 connectButtonHeight_ = NSHeight([connectButton_ frame]); |
331 | 425 |
332 // Cancel button. | 426 // Cancel button. |
333 cancelButton_ = [self createCancelButton]; | 427 cancelButton_ = [self createCancelButton]; |
334 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); | 428 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); |
335 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); | 429 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); |
336 | 430 |
337 CGFloat buttonRowHeight = | 431 CGFloat buttonRowHeight = |
338 std::max(connectButtonHeight_, cancelButtonHeight_); | 432 std::max(connectButtonHeight_, cancelButtonHeight_); |
339 | 433 |
340 // Separator. | 434 // Separator. |
341 separator_ = [self createSeparator]; | 435 separator_ = [self createSeparator]; |
342 | 436 |
343 // Message. | 437 // Message. |
344 message_ = [self createTextField:l10n_util::GetNSStringF( | 438 message_ = CreateLabel(l10n_util::GetNSStringF( |
345 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, | 439 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, base::string16())); |
346 base::string16())]; | |
347 CGFloat messageWidth = NSWidth([message_ frame]); | 440 CGFloat messageWidth = NSWidth([message_ frame]); |
348 messageHeight_ = NSHeight([message_ frame]); | 441 messageHeight_ = NSHeight([message_ frame]); |
349 | 442 |
350 // Help button. | 443 // Help button. |
351 helpButton_ = [self | 444 helpButton_ = [self |
352 createHyperlinkButtonWithText: | 445 createHyperlinkButtonWithText: |
353 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; | 446 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; |
354 | 447 |
355 // ScollView embedding with TableView. | 448 // ScollView embedding with TableView. |
356 noStatusOrRescanButtonShown_.scroll_view_frame = | 449 noStatusOrRescanButtonShown_.scroll_view_frame = |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
482 [titleView setEditable:NO]; | 575 [titleView setEditable:NO]; |
483 [titleView setSelectable:NO]; | 576 [titleView setSelectable:NO]; |
484 [titleView setStringValue:title]; | 577 [titleView setStringValue:title]; |
485 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 578 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
486 // The height is arbitrary as it will be adjusted later. | 579 // The height is arbitrary as it will be adjusted later. |
487 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; | 580 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; |
488 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | 581 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; |
489 return titleView; | 582 return titleView; |
490 } | 583 } |
491 | 584 |
492 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)rowIndex { | 585 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)row { |
493 NSInteger level = -1; | 586 NSInteger level = -1; |
| 587 bool isConnected = false; |
| 588 bool isPaired = false; |
494 size_t numOptions = chooserController_->NumOptions(); | 589 size_t numOptions = chooserController_->NumOptions(); |
495 if (chooserController_->ShouldShowIconBeforeText() && numOptions > 0) { | 590 base::scoped_nsobject<NSView> tableRowView; |
496 DCHECK_GE(rowIndex, 0); | 591 if (numOptions == 0) { |
497 DCHECK_LT(rowIndex, base::checked_cast<NSInteger>(numOptions)); | 592 DCHECK_EQ(0, row); |
498 level = base::checked_cast<NSInteger>( | 593 tableRowView.reset([[ChooserContentTableRowView alloc] |
499 chooserController_->GetSignalStrengthLevel( | 594 initWithText:[self optionAtIndex:row]]); |
500 base::checked_cast<size_t>(rowIndex))); | 595 } else { |
| 596 DCHECK_GE(row, 0); |
| 597 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); |
| 598 size_t rowIndex = base::checked_cast<size_t>(row); |
| 599 if (chooserController_->ShouldShowIconBeforeText()) { |
| 600 level = base::checked_cast<NSInteger>( |
| 601 chooserController_->GetSignalStrengthLevel(rowIndex)); |
| 602 } |
| 603 isConnected = chooserController_->IsConnected(rowIndex); |
| 604 isPaired = chooserController_->IsPaired(rowIndex); |
| 605 bool textNeedIndentation = false; |
| 606 for (size_t i = 0; i < numOptions; ++i) { |
| 607 if (chooserController_->GetSignalStrengthLevel(i) != -1 || |
| 608 chooserController_->IsConnected(i)) { |
| 609 textNeedIndentation = true; |
| 610 break; |
| 611 } |
| 612 } |
| 613 tableRowView.reset([[ChooserContentTableRowView alloc] |
| 614 initWithText:[self optionAtIndex:row] |
| 615 signalStrengthLevel:level |
| 616 isConnected:isConnected |
| 617 isPaired:isPaired |
| 618 rowHeight:[self tableRowViewHeight:row] |
| 619 textNeedIndentation:textNeedIndentation]); |
501 } | 620 } |
502 | 621 |
503 base::scoped_nsobject<NSView> tableRowView([[ChooserContentTableRowView alloc] | |
504 initWithText:[self optionAtIndex:rowIndex] | |
505 signalStrengthLevel:level]); | |
506 return tableRowView; | 622 return tableRowView; |
507 } | 623 } |
508 | 624 |
509 - (CGFloat)tableRowViewHeight:(NSInteger)row { | 625 - (CGFloat)tableRowViewHeight:(NSInteger)row { |
510 return kTableRowViewHeight; | 626 size_t numOptions = chooserController_->NumOptions(); |
| 627 if (numOptions == 0) { |
| 628 DCHECK_EQ(0, row); |
| 629 return kTableRowViewOneLineHeight; |
| 630 } |
| 631 |
| 632 DCHECK_GE(row, 0); |
| 633 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); |
| 634 size_t rowIndex = base::checked_cast<size_t>(row); |
| 635 return chooserController_->IsPaired(rowIndex) ? kTableRowViewTwoLinesHeight |
| 636 : kTableRowViewOneLineHeight; |
511 } | 637 } |
512 | 638 |
513 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { | 639 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { |
514 base::scoped_nsobject<NSButton> button( | 640 base::scoped_nsobject<NSButton> button( |
515 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 641 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
516 [button setButtonType:NSMomentaryPushInButton]; | 642 [button setButtonType:NSMomentaryPushInButton]; |
517 [button setTitle:title]; | 643 [button setTitle:title]; |
518 [button sizeToFit]; | 644 [button sizeToFit]; |
519 return button; | 645 return button; |
520 } | 646 } |
(...skipping 12 matching lines...) Expand all Loading... |
533 | 659 |
534 - (base::scoped_nsobject<NSBox>)createSeparator { | 660 - (base::scoped_nsobject<NSBox>)createSeparator { |
535 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); | 661 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); |
536 [spacer setBoxType:NSBoxSeparator]; | 662 [spacer setBoxType:NSBoxSeparator]; |
537 [spacer setBorderType:NSLineBorder]; | 663 [spacer setBorderType:NSLineBorder]; |
538 [spacer setAlphaValue:kSeparatorAlphaValue]; | 664 [spacer setAlphaValue:kSeparatorAlphaValue]; |
539 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; | 665 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; |
540 return spacer; | 666 return spacer; |
541 } | 667 } |
542 | 668 |
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: | 669 - (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText: |
557 (NSString*)text { | 670 (NSString*)text { |
558 base::scoped_nsobject<NSButton> button( | 671 base::scoped_nsobject<NSButton> button( |
559 [[NSButton alloc] initWithFrame:NSZeroRect]); | 672 [[NSButton alloc] initWithFrame:NSZeroRect]); |
560 base::scoped_nsobject<HyperlinkButtonCell> cell( | 673 base::scoped_nsobject<HyperlinkButtonCell> cell( |
561 [[HyperlinkButtonCell alloc] initTextCell:text]); | 674 [[HyperlinkButtonCell alloc] initTextCell:text]); |
562 [button setCell:cell.get()]; | 675 [button setCell:cell.get()]; |
563 [button sizeToFit]; | 676 [button sizeToFit]; |
564 return button; | 677 return button; |
565 } | 678 } |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
697 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 810 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
698 return [tableRowView image]; | 811 return [tableRowView image]; |
699 } | 812 } |
700 | 813 |
701 - (NSTextField*)tableRowViewText:(NSInteger)row { | 814 - (NSTextField*)tableRowViewText:(NSInteger)row { |
702 ChooserContentTableRowView* tableRowView = | 815 ChooserContentTableRowView* tableRowView = |
703 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 816 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
704 return [tableRowView text]; | 817 return [tableRowView text]; |
705 } | 818 } |
706 | 819 |
| 820 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { |
| 821 ChooserContentTableRowView* tableRowView = |
| 822 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
| 823 return [tableRowView pairedStatus]; |
| 824 } |
| 825 |
707 @end | 826 @end |
OLD | NEW |