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 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 kSignalStrengthLevelImageIds[5] = {IDR_SIGNAL_0_BAR, IDR_SIGNAL_1_BAR, |
65 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, | 65 IDR_SIGNAL_2_BAR, IDR_SIGNAL_3_BAR, |
66 IDR_SIGNAL_4_BAR}; | 66 IDR_SIGNAL_4_BAR}; |
67 const int kSignalStrengthLevelImageSelectedIds[5] = { | |
68 IDR_SIGNAL_0_BAR_SELECTED, IDR_SIGNAL_1_BAR_SELECTED, | |
69 IDR_SIGNAL_2_BAR_SELECTED, IDR_SIGNAL_3_BAR_SELECTED, | |
70 IDR_SIGNAL_4_BAR_SELECTED}; | |
71 | 67 |
72 // Creates a label with |text|. | 68 // Creates a label with |text|. |
73 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { | 69 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { |
74 base::scoped_nsobject<NSTextField> label( | 70 base::scoped_nsobject<NSTextField> label( |
75 [[NSTextField alloc] initWithFrame:NSZeroRect]); | 71 [[NSTextField alloc] initWithFrame:NSZeroRect]); |
76 [label setDrawsBackground:NO]; | 72 [label setDrawsBackground:NO]; |
77 [label setBezeled:NO]; | 73 [label setBezeled:NO]; |
78 [label setEditable:NO]; | 74 [label setEditable:NO]; |
79 [label setSelectable:NO]; | 75 [label setSelectable:NO]; |
80 [label setStringValue:text]; | 76 [label setStringValue:text]; |
81 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; | 77 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; |
82 [label setTextColor:[NSColor blackColor]]; | |
83 [label sizeToFit]; | 78 [label sizeToFit]; |
84 return label; | 79 return label; |
85 } | 80 } |
86 | 81 |
87 } // namespace | 82 } // namespace |
88 | 83 |
89 // 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 |
90 // image in front of the text. | 85 // image in front of the text. |
91 @interface ChooserContentTableRowView : NSView { | 86 @interface ChooserContentTableRowView : NSView { |
92 @private | 87 @private |
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
803 } | 798 } |
804 | 799 |
805 - (void)onRescan:(id)sender { | 800 - (void)onRescan:(id)sender { |
806 chooserController_->RefreshOptions(); | 801 chooserController_->RefreshOptions(); |
807 } | 802 } |
808 | 803 |
809 - (void)onHelpPressed:(id)sender { | 804 - (void)onHelpPressed:(id)sender { |
810 chooserController_->OpenHelpCenterUrl(); | 805 chooserController_->OpenHelpCenterUrl(); |
811 } | 806 } |
812 | 807 |
813 - (void)updateContentRowColor { | |
814 NSInteger selectedRow = [tableView_ selectedRow]; | |
815 NSInteger numRows = [self numberOfOptions]; | |
816 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
817 for (NSInteger rowIndex = 0; rowIndex < numRows; ++rowIndex) { | |
818 // Update the color of the text. | |
819 [[self tableRowViewText:rowIndex] | |
820 setTextColor:(rowIndex == selectedRow ? [NSColor whiteColor] | |
821 : [NSColor blackColor])]; | |
822 | |
823 // Update the color of the image. | |
824 if (chooserController_->ShouldShowIconBeforeText()) { | |
825 if (chooserController_->IsConnected(rowIndex)) { | |
826 [[self tableRowViewImage:rowIndex] | |
827 setImage:gfx::NSImageFromImageSkia(gfx::CreateVectorIcon( | |
828 gfx::VectorIconId::BLUETOOTH_CONNECTED, | |
829 rowIndex == selectedRow ? SK_ColorWHITE | |
830 : gfx::kChromeIconGrey))]; | |
831 } else { | |
832 int signalStrengthLevel = | |
833 chooserController_->GetSignalStrengthLevel(rowIndex); | |
834 if (signalStrengthLevel != -1) { | |
835 int imageId = | |
836 rowIndex == selectedRow | |
837 ? kSignalStrengthLevelImageSelectedIds[signalStrengthLevel] | |
838 : kSignalStrengthLevelImageIds[signalStrengthLevel]; | |
839 [[self tableRowViewImage:rowIndex] | |
840 setImage:rb.GetNativeImageNamed(imageId).ToNSImage()]; | |
841 } | |
842 } | |
843 } | |
844 | |
845 // Update the color of paired status. | |
846 NSTextField* pairedStatusText = [self tableRowViewPairedStatus:rowIndex]; | |
847 if (pairedStatusText) { | |
848 [pairedStatusText | |
849 setTextColor:(skia::SkColorToCalibratedNSColor( | |
850 rowIndex == selectedRow ? gfx::kGoogleGreen300 | |
851 : gfx::kGoogleGreen700))]; | |
852 } | |
853 } | |
854 } | |
855 | |
856 - (NSImageView*)tableRowViewImage:(NSInteger)row { | 808 - (NSImageView*)tableRowViewImage:(NSInteger)row { |
857 ChooserContentTableRowView* tableRowView = | 809 ChooserContentTableRowView* tableRowView = |
858 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 810 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
859 return [tableRowView image]; | 811 return [tableRowView image]; |
860 } | 812 } |
861 | 813 |
862 - (NSTextField*)tableRowViewText:(NSInteger)row { | 814 - (NSTextField*)tableRowViewText:(NSInteger)row { |
863 ChooserContentTableRowView* tableRowView = | 815 ChooserContentTableRowView* tableRowView = |
864 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 816 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
865 return [tableRowView text]; | 817 return [tableRowView text]; |
866 } | 818 } |
867 | 819 |
868 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { | 820 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { |
869 ChooserContentTableRowView* tableRowView = | 821 ChooserContentTableRowView* tableRowView = |
870 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; | 822 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; |
871 return [tableRowView pairedStatus]; | 823 return [tableRowView pairedStatus]; |
872 } | 824 } |
873 | 825 |
874 @end | 826 @end |
OLD | NEW |