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" |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
54 const CGFloat kSeparatorAlphaValue = 0.6f; | 54 const CGFloat kSeparatorAlphaValue = 0.6f; |
55 | 55 |
56 // Separator height. | 56 // Separator height. |
57 const CGFloat kSeparatorHeight = 1.0f; | 57 const CGFloat kSeparatorHeight = 1.0f; |
58 | 58 |
59 // Distance between two views inside the table row view. | 59 // Distance between two views inside the table row view. |
60 const CGFloat kTableRowViewHorizontalPadding = 5.0f; | 60 const CGFloat kTableRowViewHorizontalPadding = 5.0f; |
61 const CGFloat kTableRowViewVerticalPadding = 1.0f; | 61 const CGFloat kTableRowViewVerticalPadding = 1.0f; |
62 | 62 |
63 // The lookup table for signal strength level image. | 63 // The lookup table for signal strength level image. |
64 const int kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, | 64 const int kSignalStrengthLevelBlackImageIds[5] = { |
65 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, | 65 IDR_SIGNAL_0_BAR_BLACK, IDR_SIGNAL_1_BAR_BLACK, IDR_SIGNAL_2_BAR_BLACK, |
66 IDR_SIGNAL_4_BAR}; | 66 IDR_SIGNAL_3_BAR_BLACK, IDR_SIGNAL_4_BAR_BLACK}; |
| 67 const int kSignalStrengthLevelWhiteImageIds[5] = { |
| 68 IDR_SIGNAL_0_BAR_WHITE, IDR_SIGNAL_1_BAR_WHITE, IDR_SIGNAL_2_BAR_WHITE, |
| 69 IDR_SIGNAL_3_BAR_WHITE, IDR_SIGNAL_4_BAR_WHITE}; |
67 | 70 |
68 // Creates a label with |text|. | 71 // Creates a label with |text|. |
69 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { | 72 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { |
70 base::scoped_nsobject<NSTextField> label( | 73 base::scoped_nsobject<NSTextField> label( |
71 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 74 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
72 [label setDrawsBackground:NO]; | 75 [label setDrawsBackground:NO]; |
73 [label setBezeled:NO]; | 76 [label setBezeled:NO]; |
74 [label setEditable:NO]; | 77 [label setEditable:NO]; |
75 [label setSelectable:NO]; | 78 [label setSelectable:NO]; |
76 [label setStringValue:text]; | 79 [label setStringValue:text]; |
77 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 80 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
| 81 [label setTextColor:[NSColor blackColor]]; |
78 [label sizeToFit]; | 82 [label sizeToFit]; |
79 return label; | 83 return label; |
80 } | 84 } |
81 | 85 |
82 } // namespace | 86 } // namespace |
83 | 87 |
84 // A table row view that contains one line of text, and optionally contains an | 88 // A table row view that contains one line of text, and optionally contains an |
85 // image in front of the text. | 89 // image in front of the text. |
86 @interface ChooserContentTableRowView : NSView { | 90 @interface ChooserContentTableRowView : NSView { |
87 @private | 91 @private |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // Create the views. | 143 // Create the views. |
140 // Image. | 144 // Image. |
141 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 145 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
142 NSImage* image = nullptr; | 146 NSImage* image = nullptr; |
143 if (isConnected) { | 147 if (isConnected) { |
144 image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | 148 image = gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( |
145 gfx::VectorIconId::BLUETOOTH_CONNECTED, gfx::kChromeIconGrey)); | 149 gfx::VectorIconId::BLUETOOTH_CONNECTED, gfx::kChromeIconGrey)); |
146 } else if (level != -1) { | 150 } else if (level != -1) { |
147 DCHECK_GE(level, 0); | 151 DCHECK_GE(level, 0); |
148 DCHECK_LT(level, base::checked_cast<NSInteger>( | 152 DCHECK_LT(level, base::checked_cast<NSInteger>( |
149 arraysize(kSignalStrengthLevelImageIds))); | 153 arraysize(kSignalStrengthLevelBlackImageIds))); |
150 image = rb.GetNativeImageNamed(kSignalStrengthLevelImageIds[level]) | 154 image = rb.GetNativeImageNamed(kSignalStrengthLevelBlackImageIds[level]) |
151 .ToNSImage(); | 155 .ToNSImage(); |
152 } | 156 } |
153 | 157 |
154 CGFloat imageOriginX = kTableRowViewHorizontalPadding; | 158 CGFloat imageOriginX = kTableRowViewHorizontalPadding; |
155 CGFloat imageOriginY = (rowHeight - kRowViewImageSize) / 2; | 159 CGFloat imageOriginY = (rowHeight - kRowViewImageSize) / 2; |
156 if (image) { | 160 if (image) { |
157 image_.reset([[NSImageView alloc] | 161 image_.reset([[NSImageView alloc] |
158 initWithFrame:NSMakeRect(imageOriginX, imageOriginY, | 162 initWithFrame:NSMakeRect(imageOriginX, imageOriginY, |
159 kRowViewImageSize, kRowViewImageSize)]); | 163 kRowViewImageSize, kRowViewImageSize)]); |
160 [image_ setImage:image]; | 164 [image_ setImage:image]; |
(...skipping 637 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 } | 802 } |
799 | 803 |
800 - (void)onRescan:(id)sender { | 804 - (void)onRescan:(id)sender { |
801 chooserController_->RefreshOptions(); | 805 chooserController_->RefreshOptions(); |
802 } | 806 } |
803 | 807 |
804 - (void)onHelpPressed:(id)sender { | 808 - (void)onHelpPressed:(id)sender { |
805 chooserController_->OpenHelpCenterUrl(); | 809 chooserController_->OpenHelpCenterUrl(); |
806 } | 810 } |
807 | 811 |
| 812 - (void)updateContentRowColor { |
| 813 NSInteger selectedRow = [tableView_ selectedRow]; |
| 814 NSInteger numRows = [self numberOfOptions]; |
| 815 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 816 for (NSInteger rowIndex = 0; rowIndex < numRows; ++rowIndex) { |
| 817 // Update the color of the text. |
| 818 [[self tableRowViewText:rowIndex] |
| 819 setTextColor:(rowIndex == selectedRow ? [NSColor whiteColor] |
| 820 : [NSColor blackColor])]; |
| 821 |
| 822 // Update the color of the image. |
| 823 if (chooserController_->ShouldShowIconBeforeText()) { |
| 824 if (chooserController_->IsConnected(rowIndex)) { |
| 825 [[self tableRowViewImage:rowIndex] |
| 826 setImage:gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( |
| 827 gfx::VectorIconId::BLUETOOTH_CONNECTED, |
| 828 rowIndex == selectedRow ? SK_ColorWHITE |
| 829 : gfx::kChromeIconGrey))]; |
| 830 } else { |
| 831 int signalStrengthLevel = |
| 832 chooserController_->GetSignalStrengthLevel(rowIndex); |
| 833 if (signalStrengthLevel != -1) { |
| 834 int imageId = |
| 835 rowIndex == selectedRow |
| 836 ? kSignalStrengthLevelWhiteImageIds[signalStrengthLevel] |
| 837 : kSignalStrengthLevelBlackImageIds[signalStrengthLevel]; |
| 838 [[self tableRowViewImage:rowIndex] |
| 839 setImage:rb.GetNativeImageNamed(imageId).ToNSImage()]; |
| 840 } |
| 841 } |
| 842 } |
| 843 |
| 844 // Update the color of paired status. |
| 845 NSTextField* pairedStatusText = [self tableRowViewPairedStatus:rowIndex]; |
| 846 if (pairedStatusText) { |
| 847 [pairedStatusText |
| 848 setTextColor:(skia::SkColorToCalibratedNSColor( |
| 849 rowIndex == selectedRow ? gfx::kGoogleGreen300 |
| 850 : gfx::kGoogleGreen700))]; |
| 851 } |
| 852 } |
| 853 } |
| 854 |
808 - (NSImageView*)tableRowViewImage:(NSInteger)row { | 855 - (NSImageView*)tableRowViewImage:(NSInteger)row { |
809 ChooserContentTableRowView* tableRowView = | 856 ChooserContentTableRowView* tableRowView = |
810 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 857 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
811 return [tableRowView image]; | 858 return [tableRowView image]; |
812 } | 859 } |
813 | 860 |
814 - (NSTextField*)tableRowViewText:(NSInteger)row { | 861 - (NSTextField*)tableRowViewText:(NSInteger)row { |
815 ChooserContentTableRowView* tableRowView = | 862 ChooserContentTableRowView* tableRowView = |
816 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 863 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
817 return [tableRowView text]; | 864 return [tableRowView text]; |
818 } | 865 } |
819 | 866 |
820 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { | 867 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { |
821 ChooserContentTableRowView* tableRowView = | 868 ChooserContentTableRowView* tableRowView = |
822 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 869 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
823 return [tableRowView pairedStatus]; | 870 return [tableRowView pairedStatus]; |
824 } | 871 } |
825 | 872 |
826 @end | 873 @end |
OLD | NEW |