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