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 text field with |text|. | |
|
Jeffrey Yasskin
2016/09/07 02:01:47
I think this is a label, rather than a general tex
juncai
2016/09/09 20:06:15
Done.
| |
| 69 base::scoped_nsobject<NSTextField> CreateTextField(NSString* text) { | |
| 70 base::scoped_nsobject<NSTextField> text_field( | |
| 71 [[NSTextField alloc] initWithFrame:NSZeroRect]); | |
| 72 [text_field setDrawsBackground:NO]; | |
|
Jeffrey Yasskin
2016/09/07 02:01:47
I hate that we need this long list of setters in o
juncai
2016/09/09 20:06:15
Acknowledged.
| |
| 73 [text_field setBezeled:NO]; | |
| 74 [text_field setEditable:NO]; | |
| 75 [text_field setSelectable:NO]; | |
| 76 [text_field setStringValue:text]; | |
| 77 [text_field setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | |
| 78 [text_field sizeToFit]; | |
| 79 return text_field; | |
| 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 // |horizontalPaddingOffset| is used to adjust the origin x of |text_| | |
| 95 // when the chooser needs to show no devices found message. | |
| 69 - (instancetype)initWithText:(NSString*)text | 96 - (instancetype)initWithText:(NSString*)text |
| 70 signalStrengthLevel:(NSInteger)level; | 97 signalStrengthLevel:(NSInteger)level |
| 98 isConnected:(bool)isConnected | |
| 99 isPaired:(bool)isPaired | |
| 100 rowHeight:(CGFloat)rowHeight | |
| 101 horizontalPaddingOffset:(CGFloat)horizontalPaddingOffset; | |
| 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 { | 117 signalStrengthLevel:(NSInteger)level |
| 118 isConnected:(bool)isConnected | |
| 119 isPaired:(bool)isPaired | |
| 120 rowHeight:(CGFloat)rowHeight | |
| 121 horizontalPaddingOffset:(CGFloat)horizontalPaddingOffset { | |
| 84 if ((self = [super initWithFrame:NSZeroRect])) { | 122 if ((self = [super initWithFrame:NSZeroRect])) { |
| 85 if (level != -1) { | 123 // Create the views. |
| 124 // Image. | |
| 125 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 126 NSImage* image = nullptr; | |
| 127 if (isConnected) { | |
| 128 image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | |
| 129 gfx::VectorIconId::BLUETOOTH_CONNECTED, SK_ColorBLACK)); | |
|
Evan Stade
2016/09/07 16:41:42
are you sure you want black and not kChromeIconGre
juncai
2016/09/09 20:06:15
Done.
| |
| 130 } else if (level != -1) { | |
| 86 DCHECK_GE(level, 0); | 131 DCHECK_GE(level, 0); |
| 87 DCHECK_LT(level, base::checked_cast<NSInteger>( | 132 DCHECK_LT(level, base::checked_cast<NSInteger>( |
| 88 arraysize(kSignalStrengthLevelImageIds))); | 133 arraysize(kSignalStrengthLevelImageIds))); |
| 89 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 134 image = rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) |
| 90 NSImage* signalStrengthLevelImage = | 135 .ToNSImage(); |
| 91 rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) | 136 } |
| 92 .ToNSImage(); | |
| 93 | 137 |
| 138 CGFloat imageOriginX = kTableRowViewHorizontalPadding; | |
| 139 CGFloat imageOriginY = (rowHeight - kRowViewImageSize) / 2; | |
| 140 if (image) { | |
| 94 image_.reset([[NSImageView alloc] | 141 image_.reset([[NSImageView alloc] |
| 95 initWithFrame:NSMakeRect(0, (kTableRowViewHeight - | 142 initWithFrame:NSMakeRect(imageOriginX, imageOriginY, |
| 96 kSignalStrengthLevelImageSize) / | 143 kRowViewImageSize, kRowViewImageSize)]); |
| 97 2, | 144 [image_ setImage:image]; |
| 98 kSignalStrengthLevelImageSize, | |
| 99 kSignalStrengthLevelImageSize)]); | |
| 100 [image_ setImage:signalStrengthLevelImage]; | |
| 101 [self addSubview:image_]; | 145 [self addSubview:image_]; |
| 102 } | 146 } |
| 103 | 147 |
| 104 text_.reset([[NSTextField alloc] initWithFrame:NSZeroRect]); | 148 // Text. |
| 105 [text_ setDrawsBackground:NO]; | 149 text_ = CreateTextField(text); |
| 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]); | 150 CGFloat textHeight = NSHeight([text_ frame]); |
| 113 [text_ setFrameOrigin:NSMakePoint( | 151 |
| 114 level == -1 ? 0 : kSignalStrengthLevelImageSize + | 152 // Paired status. |
| 115 kHorizontalPadding, | 153 CGFloat pairedStatusHeight = 0.0f; |
| 116 (kTableRowViewHeight - textHeight) / 2)]; | 154 if (isPaired) { |
| 155 pairedStatus_ = CreateTextField( | |
| 156 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_PAIRED_STATUS_TEXT)); | |
| 157 [pairedStatus_ | |
| 158 setTextColor:skia::SkColorToCalibratedNSColor(gfx::kGoogleGreen700)]; | |
| 159 pairedStatusHeight = NSHeight([pairedStatus_ frame]); | |
| 160 } | |
| 161 | |
| 162 // Lay out the views. | |
| 163 // Text. | |
| 164 CGFloat textOriginX = imageOriginX + kRowViewImageSize + | |
| 165 kTableRowViewHorizontalPadding + | |
| 166 horizontalPaddingOffset; | |
| 167 CGFloat textOriginY; | |
| 168 if (isPaired) { | |
| 169 textOriginY = pairedStatusHeight + | |
| 170 (rowHeight - textHeight - pairedStatusHeight - | |
| 171 kTableRowViewVerticalPadding) / | |
| 172 2 + | |
| 173 kTableRowViewVerticalPadding; | |
| 174 } else { | |
| 175 textOriginY = (rowHeight - textHeight) / 2; | |
| 176 } | |
| 177 | |
| 178 [text_ setFrameOrigin:NSMakePoint(textOriginX, textOriginY)]; | |
| 117 [self addSubview:text_]; | 179 [self addSubview:text_]; |
| 180 | |
| 181 // Paired status. | |
| 182 if (isPaired) { | |
| 183 CGFloat pairedStatusOriginX = textOriginX; | |
| 184 CGFloat pairedStatusOriginY = | |
| 185 (rowHeight - textHeight - pairedStatusHeight - | |
| 186 kTableRowViewVerticalPadding) / | |
| 187 2; | |
| 188 [pairedStatus_ | |
| 189 setFrameOrigin:NSMakePoint(pairedStatusOriginX, pairedStatusOriginY)]; | |
| 190 [self addSubview:pairedStatus_]; | |
| 191 } | |
| 118 } | 192 } |
| 119 | 193 |
| 120 return self; | 194 return self; |
| 121 } | 195 } |
| 122 | 196 |
| 123 - (NSImageView*)image { | 197 - (NSImageView*)image { |
| 124 return image_.get(); | 198 return image_.get(); |
| 125 } | 199 } |
| 126 | 200 |
| 127 - (NSTextField*)text { | 201 - (NSTextField*)text { |
| 128 return text_.get(); | 202 return text_.get(); |
| 129 } | 203 } |
| 130 | 204 |
| 205 - (NSTextField*)pairedStatus { | |
| 206 return pairedStatus_.get(); | |
| 207 } | |
| 208 | |
| 131 @end | 209 @end |
| 132 | 210 |
| 133 class ChooserContentViewController : public ChooserController::View { | 211 class ChooserContentViewController : public ChooserController::View { |
| 134 public: | 212 public: |
| 135 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, | 213 ChooserContentViewController(ChooserContentViewCocoa* chooser_content_view, |
| 136 ChooserController* chooser_controller, | 214 ChooserController* chooser_controller, |
| 137 NSTableView* table_view, | 215 NSTableView* table_view, |
| 138 SpinnerView* spinner, | 216 SpinnerView* spinner, |
| 139 NSTextField* status, | 217 NSTextField* status, |
| 140 NSButton* rescan_button); | 218 NSButton* rescan_button); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 303 | 381 |
| 304 if ((self = [super initWithFrame:chooserFrame])) { | 382 if ((self = [super initWithFrame:chooserFrame])) { |
| 305 chooserController_ = std::move(chooserController); | 383 chooserController_ = std::move(chooserController); |
| 306 | 384 |
| 307 // Create the views. | 385 // Create the views. |
| 308 // Title. | 386 // Title. |
| 309 titleView_ = [self createChooserTitle:chooserTitle]; | 387 titleView_ = [self createChooserTitle:chooserTitle]; |
| 310 titleHeight_ = NSHeight([titleView_ frame]); | 388 titleHeight_ = NSHeight([titleView_ frame]); |
| 311 | 389 |
| 312 // Status. | 390 // Status. |
| 313 status_ = [self createTextField:l10n_util::GetNSString( | 391 status_ = CreateTextField( |
| 314 IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)]; | 392 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_SCANNING)); |
| 315 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; | 393 CGFloat statusWidth = kChooserWidth / 2 - kMarginX; |
| 316 // The height is arbitrary as it will be adjusted later. | 394 // The height is arbitrary as it will be adjusted later. |
| 317 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; | 395 [status_ setFrameSize:NSMakeSize(statusWidth, 0.0f)]; |
| 318 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; | 396 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:status_]; |
| 319 statusHeight_ = NSHeight([status_ frame]); | 397 statusHeight_ = NSHeight([status_ frame]); |
| 320 | 398 |
| 321 // Re-scan button. | 399 // Re-scan button. |
| 322 rescanButton_ = | 400 rescanButton_ = |
| 323 [self createHyperlinkButtonWithText: | 401 [self createHyperlinkButtonWithText: |
| 324 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; | 402 l10n_util::GetNSString(IDS_BLUETOOTH_DEVICE_CHOOSER_RE_SCAN)]; |
| 325 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); | 403 rescanButtonHeight_ = NSHeight([rescanButton_ frame]); |
| 326 | 404 |
| 327 // Connect button. | 405 // Connect button. |
| 328 connectButton_ = [self createConnectButton]; | 406 connectButton_ = [self createConnectButton]; |
| 329 connectButtonWidth_ = NSWidth([connectButton_ frame]); | 407 connectButtonWidth_ = NSWidth([connectButton_ frame]); |
| 330 connectButtonHeight_ = NSHeight([connectButton_ frame]); | 408 connectButtonHeight_ = NSHeight([connectButton_ frame]); |
| 331 | 409 |
| 332 // Cancel button. | 410 // Cancel button. |
| 333 cancelButton_ = [self createCancelButton]; | 411 cancelButton_ = [self createCancelButton]; |
| 334 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); | 412 cancelButtonWidth_ = NSWidth([cancelButton_ frame]); |
| 335 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); | 413 cancelButtonHeight_ = NSHeight([cancelButton_ frame]); |
| 336 | 414 |
| 337 CGFloat buttonRowHeight = | 415 CGFloat buttonRowHeight = |
| 338 std::max(connectButtonHeight_, cancelButtonHeight_); | 416 std::max(connectButtonHeight_, cancelButtonHeight_); |
| 339 | 417 |
| 340 // Separator. | 418 // Separator. |
| 341 separator_ = [self createSeparator]; | 419 separator_ = [self createSeparator]; |
| 342 | 420 |
| 343 // Message. | 421 // Message. |
| 344 message_ = [self createTextField:l10n_util::GetNSStringF( | 422 message_ = CreateTextField(l10n_util::GetNSStringF( |
| 345 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, | 423 IDS_DEVICE_CHOOSER_FOOTNOTE_TEXT, base::string16())); |
| 346 base::string16())]; | |
| 347 CGFloat messageWidth = NSWidth([message_ frame]); | 424 CGFloat messageWidth = NSWidth([message_ frame]); |
| 348 messageHeight_ = NSHeight([message_ frame]); | 425 messageHeight_ = NSHeight([message_ frame]); |
| 349 | 426 |
| 350 // Help button. | 427 // Help button. |
| 351 helpButton_ = [self | 428 helpButton_ = [self |
| 352 createHyperlinkButtonWithText: | 429 createHyperlinkButtonWithText: |
| 353 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; | 430 l10n_util::GetNSString(IDS_DEVICE_CHOOSER_GET_HELP_LINK_TEXT)]; |
| 354 | 431 |
| 355 // ScollView embedding with TableView. | 432 // ScollView embedding with TableView. |
| 356 noStatusOrRescanButtonShown_.scroll_view_frame = | 433 noStatusOrRescanButtonShown_.scroll_view_frame = |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 482 [titleView setEditable:NO]; | 559 [titleView setEditable:NO]; |
| 483 [titleView setSelectable:NO]; | 560 [titleView setSelectable:NO]; |
| 484 [titleView setStringValue:title]; | 561 [titleView setStringValue:title]; |
| 485 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 562 [titleView setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 486 // The height is arbitrary as it will be adjusted later. | 563 // The height is arbitrary as it will be adjusted later. |
| 487 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; | 564 [titleView setFrameSize:NSMakeSize(kChooserWidth - 2 * kMarginX, 0.0f)]; |
| 488 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; | 565 [GTMUILocalizerAndLayoutTweaker sizeToFitFixedWidthTextField:titleView]; |
| 489 return titleView; | 566 return titleView; |
| 490 } | 567 } |
| 491 | 568 |
| 492 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)rowIndex { | 569 - (base::scoped_nsobject<NSView>)createTableRowView:(NSInteger)row { |
| 493 NSInteger level = -1; | 570 NSInteger level = -1; |
| 571 bool isConnected = false; | |
| 572 bool isPaired = false; | |
| 573 CGFloat horizontalPaddingOffset = 0.0f; | |
| 494 size_t numOptions = chooserController_->NumOptions(); | 574 size_t numOptions = chooserController_->NumOptions(); |
| 495 if (chooserController_->ShouldShowIconBeforeText() && numOptions > 0) { | 575 if (numOptions == 0) { |
|
Jeffrey Yasskin
2016/09/07 02:01:47
There are enough special cases for numOptions==0 h
juncai
2016/09/09 20:06:15
If using a different view, it will make the test c
| |
| 496 DCHECK_GE(rowIndex, 0); | 576 DCHECK_EQ(0, row); |
| 497 DCHECK_LT(rowIndex, base::checked_cast<NSInteger>(numOptions)); | 577 // Here since the chooser needs to show no devices found message, |
| 498 level = base::checked_cast<NSInteger>( | 578 // the text's origin x needs to be adjusted. |
| 499 chooserController_->GetSignalStrengthLevel( | 579 horizontalPaddingOffset = |
| 500 base::checked_cast<size_t>(rowIndex))); | 580 -(kRowViewImageSize + kTableRowViewHorizontalPadding); |
| 581 } else { | |
| 582 DCHECK_GE(row, 0); | |
| 583 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); | |
| 584 size_t rowIndex = base::checked_cast<size_t>(row); | |
| 585 if (chooserController_->ShouldShowIconBeforeText()) { | |
| 586 level = base::checked_cast<NSInteger>( | |
| 587 chooserController_->GetSignalStrengthLevel(rowIndex)); | |
| 588 } | |
| 589 isConnected = chooserController_->IsConnected(rowIndex); | |
| 590 isPaired = chooserController_->IsPaired(rowIndex); | |
| 501 } | 591 } |
| 502 | 592 |
| 503 base::scoped_nsobject<NSView> tableRowView([[ChooserContentTableRowView alloc] | 593 base::scoped_nsobject<NSView> tableRowView([[ChooserContentTableRowView alloc] |
| 504 initWithText:[self optionAtIndex:rowIndex] | 594 initWithText:[self optionAtIndex:row] |
| 505 signalStrengthLevel:level]); | 595 signalStrengthLevel:level |
| 596 isConnected:isConnected | |
| 597 isPaired:isPaired | |
| 598 rowHeight:[self tableRowViewHeight:row] | |
| 599 horizontalPaddingOffset:horizontalPaddingOffset]); | |
| 506 return tableRowView; | 600 return tableRowView; |
| 507 } | 601 } |
| 508 | 602 |
| 509 - (CGFloat)tableRowViewHeight:(NSInteger)row { | 603 - (CGFloat)tableRowViewHeight:(NSInteger)row { |
| 510 return kTableRowViewHeight; | 604 size_t numOptions = chooserController_->NumOptions(); |
| 605 if (numOptions == 0) { | |
| 606 DCHECK_EQ(0, row); | |
| 607 return kTableRowViewOneLineHeight; | |
| 608 } | |
| 609 | |
| 610 DCHECK_GE(row, 0); | |
| 611 DCHECK_LT(row, base::checked_cast<NSInteger>(numOptions)); | |
| 612 size_t rowIndex = base::checked_cast<size_t>(row); | |
| 613 if (chooserController_->IsPaired(rowIndex)) | |
|
Jeffrey Yasskin
2016/09/07 02:01:47
This part of the calculation should be done inside
juncai
2016/09/09 20:06:15
Since
https://cs.chromium.org/chromium/src/chrome/
Jeffrey Yasskin
2016/09/14 20:08:36
Yep, oh well.
| |
| 614 return kTableRowViewTwoLinesHeight; | |
| 615 else | |
| 616 return kTableRowViewOneLineHeight; | |
| 511 } | 617 } |
| 512 | 618 |
| 513 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { | 619 - (base::scoped_nsobject<NSButton>)createButtonWithTitle:(NSString*)title { |
| 514 base::scoped_nsobject<NSButton> button( | 620 base::scoped_nsobject<NSButton> button( |
| 515 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); | 621 [[ConstrainedWindowButton alloc] initWithFrame:NSZeroRect]); |
| 516 [button setButtonType:NSMomentaryPushInButton]; | 622 [button setButtonType:NSMomentaryPushInButton]; |
| 517 [button setTitle:title]; | 623 [button setTitle:title]; |
| 518 [button sizeToFit]; | 624 [button sizeToFit]; |
| 519 return button; | 625 return button; |
| 520 } | 626 } |
| (...skipping 12 matching lines...) Expand all Loading... | |
| 533 | 639 |
| 534 - (base::scoped_nsobject<NSBox>)createSeparator { | 640 - (base::scoped_nsobject<NSBox>)createSeparator { |
| 535 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); | 641 base::scoped_nsobject<NSBox> spacer([[NSBox alloc] initWithFrame:NSZeroRect]); |
| 536 [spacer setBoxType:NSBoxSeparator]; | 642 [spacer setBoxType:NSBoxSeparator]; |
| 537 [spacer setBorderType:NSLineBorder]; | 643 [spacer setBorderType:NSLineBorder]; |
| 538 [spacer setAlphaValue:kSeparatorAlphaValue]; | 644 [spacer setAlphaValue:kSeparatorAlphaValue]; |
| 539 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; | 645 [spacer setFrameSize:NSMakeSize(kChooserWidth, kSeparatorHeight)]; |
| 540 return spacer; | 646 return spacer; |
| 541 } | 647 } |
| 542 | 648 |
| 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: | 649 - (base::scoped_nsobject<NSButton>)createHyperlinkButtonWithText: |
| 557 (NSString*)text { | 650 (NSString*)text { |
| 558 base::scoped_nsobject<NSButton> button( | 651 base::scoped_nsobject<NSButton> button( |
| 559 [[NSButton alloc] initWithFrame:NSZeroRect]); | 652 [[NSButton alloc] initWithFrame:NSZeroRect]); |
| 560 base::scoped_nsobject<HyperlinkButtonCell> cell( | 653 base::scoped_nsobject<HyperlinkButtonCell> cell( |
| 561 [[HyperlinkButtonCell alloc] initTextCell:text]); | 654 [[HyperlinkButtonCell alloc] initTextCell:text]); |
| 562 [button setCell:cell.get()]; | 655 [button setCell:cell.get()]; |
| 563 [button sizeToFit]; | 656 [button sizeToFit]; |
| 564 return button; | 657 return button; |
| 565 } | 658 } |
| (...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 697 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 790 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
| 698 return [tableRowView image]; | 791 return [tableRowView image]; |
| 699 } | 792 } |
| 700 | 793 |
| 701 - (NSTextField*)tableRowViewText:(NSInteger)row { | 794 - (NSTextField*)tableRowViewText:(NSInteger)row { |
| 702 ChooserContentTableRowView* tableRowView = | 795 ChooserContentTableRowView* tableRowView = |
| 703 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 796 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
| 704 return [tableRowView text]; | 797 return [tableRowView text]; |
| 705 } | 798 } |
| 706 | 799 |
| 800 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { | |
| 801 ChooserContentTableRowView* tableRowView = | |
| 802 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | |
| 803 return [tableRowView pairedStatus]; | |
| 804 } | |
| 805 | |
| 707 @end | 806 @end |
| OLD | NEW |