Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(221)

Side by Side Diff: chrome/browser/ui/cocoa/chooser_content_view_cocoa.mm

Issue 2342723002: Reland: Update image and text color when row is selected in the chooser on Mac (Closed)
Patch Set: address comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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};
67 71
68 // Creates a label with |text|. 72 // Creates a label with |text|.
69 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) { 73 base::scoped_nsobject<NSTextField> CreateLabel(NSString* text) {
70 base::scoped_nsobject<NSTextField> label( 74 base::scoped_nsobject<NSTextField> label(
71 [[NSTextField alloc] initWithFrame:NSZeroRect]); 75 [[NSTextField alloc] initWithFrame:NSZeroRect]);
72 [label setDrawsBackground:NO]; 76 [label setDrawsBackground:NO];
73 [label setBezeled:NO]; 77 [label setBezeled:NO];
74 [label setEditable:NO]; 78 [label setEditable:NO];
75 [label setSelectable:NO]; 79 [label setSelectable:NO];
76 [label setStringValue:text]; 80 [label setStringValue:text];
77 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]]; 81 [label setFont:[NSFont systemFontOfSize:[NSFont systemFontSize]]];
82 [label setTextColor:[NSColor blackColor]];
78 [label sizeToFit]; 83 [label sizeToFit];
79 return label; 84 return label;
80 } 85 }
81 86
82 } // namespace 87 } // namespace
83 88
84 // A table row view that contains one line of text, and optionally contains an 89 // A table row view that contains one line of text, and optionally contains an
85 // image in front of the text. 90 // image in front of the text.
86 @interface ChooserContentTableRowView : NSView { 91 @interface ChooserContentTableRowView : NSView {
87 @private 92 @private
(...skipping 710 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 } 803 }
799 804
800 - (void)onRescan:(id)sender { 805 - (void)onRescan:(id)sender {
801 chooserController_->RefreshOptions(); 806 chooserController_->RefreshOptions();
802 } 807 }
803 808
804 - (void)onHelpPressed:(id)sender { 809 - (void)onHelpPressed:(id)sender {
805 chooserController_->OpenHelpCenterUrl(); 810 chooserController_->OpenHelpCenterUrl();
806 } 811 }
807 812
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
808 - (NSImageView*)tableRowViewImage:(NSInteger)row { 856 - (NSImageView*)tableRowViewImage:(NSInteger)row {
809 ChooserContentTableRowView* tableRowView = 857 ChooserContentTableRowView* tableRowView =
810 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; 858 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES];
811 return [tableRowView image]; 859 return [tableRowView image];
812 } 860 }
813 861
814 - (NSTextField*)tableRowViewText:(NSInteger)row { 862 - (NSTextField*)tableRowViewText:(NSInteger)row {
815 ChooserContentTableRowView* tableRowView = 863 ChooserContentTableRowView* tableRowView =
816 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; 864 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES];
817 return [tableRowView text]; 865 return [tableRowView text];
818 } 866 }
819 867
820 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row { 868 - (NSTextField*)tableRowViewPairedStatus:(NSInteger)row {
821 ChooserContentTableRowView* tableRowView = 869 ChooserContentTableRowView* tableRowView =
822 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES]; 870 [tableView_ viewAtColumn:0 row:row makeIfNecessary:YES];
823 return [tableRowView pairedStatus]; 871 return [tableRowView pairedStatus];
824 } 872 }
825 873
826 @end 874 @end
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698