| OLD | NEW |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 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 "ui/message_center/cocoa/settings_controller.h" | 5 #import "ui/message_center/cocoa/settings_controller.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/mac/foundation_util.h" | 9 #include "base/mac/foundation_util.h" |
| 10 #import "base/mac/scoped_nsobject.h" | 10 #import "base/mac/scoped_nsobject.h" |
| 11 #include "base/stl_util.h" | 11 #include "base/stl_util.h" |
| 12 #include "base/strings/sys_string_conversions.h" | 12 #include "base/strings/sys_string_conversions.h" |
| 13 #include "grit/ui_strings.h" | 13 #include "grit/ui_strings.h" |
| 14 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
| 15 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
| 16 #import "ui/message_center/cocoa/opaque_views.h" |
| 16 #import "ui/message_center/cocoa/settings_entry_view.h" | 17 #import "ui/message_center/cocoa/settings_entry_view.h" |
| 17 #import "ui/message_center/cocoa/tray_view_controller.h" | 18 #import "ui/message_center/cocoa/tray_view_controller.h" |
| 18 #include "ui/message_center/message_center_style.h" | 19 #include "ui/message_center/message_center_style.h" |
| 19 | 20 |
| 20 using message_center::settings::kHorizontalMargin; | 21 using message_center::settings::kHorizontalMargin; |
| 21 using message_center::settings::kEntryHeight; | 22 using message_center::settings::kEntryHeight; |
| 22 | 23 |
| 23 // Intrinsic padding pixels out of our control. | 24 // Intrinsic padding pixels out of our control. |
| 24 const int kIntrinsicHeaderTextTopPadding = 3; | 25 const int kIntrinsicHeaderTextTopPadding = 3; |
| 25 const int kIntrinsicSubheaderTextTopPadding = 5; | 26 const int kIntrinsicSubheaderTextTopPadding = 5; |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 } | 98 } |
| 98 | 99 |
| 99 - (void)dealloc { | 100 - (void)dealloc { |
| 100 provider_->RemoveObserver(observer_.get()); | 101 provider_->RemoveObserver(observer_.get()); |
| 101 provider_->OnNotifierSettingsClosing(); | 102 provider_->OnNotifierSettingsClosing(); |
| 102 STLDeleteElements(¬ifiers_); | 103 STLDeleteElements(¬ifiers_); |
| 103 [super dealloc]; | 104 [super dealloc]; |
| 104 } | 105 } |
| 105 | 106 |
| 106 - (NSTextField*)newLabelWithFrame:(NSRect)frame { | 107 - (NSTextField*)newLabelWithFrame:(NSRect)frame { |
| 107 NSTextField* label = [[NSTextField alloc] initWithFrame:frame]; | 108 NSColor* color = gfx::SkColorToCalibratedNSColor( |
| 108 [label setDrawsBackground:NO]; | 109 message_center::kMessageCenterBackgroundColor); |
| 109 [label setBezeled:NO]; | 110 MCTextField* label = |
| 110 [label setEditable:NO]; | 111 [[MCTextField alloc] initWithFrame:frame backgroundColor:color]; |
| 111 [label setSelectable:NO]; | 112 |
| 112 [label setAutoresizingMask:NSViewMinYMargin]; | |
| 113 return label; | 113 return label; |
| 114 } | 114 } |
| 115 | 115 |
| 116 - (void)updateView { | 116 - (void)updateView { |
| 117 notifiers_.clear(); | 117 notifiers_.clear(); |
| 118 [trayViewController_ updateSettings]; | 118 [trayViewController_ updateSettings]; |
| 119 } | 119 } |
| 120 | 120 |
| 121 - (void)loadView { | 121 - (void)loadView { |
| 122 DCHECK(notifiers_.empty()); | 122 DCHECK(notifiers_.empty()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 134 message_center::kMessageCenterBackgroundColor)]; | 134 message_center::kMessageCenterBackgroundColor)]; |
| 135 [view setTitlePosition:NSNoTitle]; | 135 [view setTitlePosition:NSNoTitle]; |
| 136 [self setView:view]; | 136 [self setView:view]; |
| 137 | 137 |
| 138 // "Settings" text. | 138 // "Settings" text. |
| 139 NSRect headerFrame = NSMakeRect(kHorizontalMargin, | 139 NSRect headerFrame = NSMakeRect(kHorizontalMargin, |
| 140 kHorizontalMargin, | 140 kHorizontalMargin, |
| 141 NSWidth(fullFrame), | 141 NSWidth(fullFrame), |
| 142 NSHeight(fullFrame)); | 142 NSHeight(fullFrame)); |
| 143 settingsText_.reset([self newLabelWithFrame:headerFrame]); | 143 settingsText_.reset([self newLabelWithFrame:headerFrame]); |
| 144 [settingsText_ setAutoresizingMask:NSViewMinYMargin]; | |
| 145 [settingsText_ setTextColor: | 144 [settingsText_ setTextColor: |
| 146 gfx::SkColorToCalibratedNSColor(message_center::kRegularTextColor)]; | 145 gfx::SkColorToCalibratedNSColor(message_center::kRegularTextColor)]; |
| 147 [settingsText_ | 146 [settingsText_ |
| 148 setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]]; | 147 setFont:[NSFont messageFontOfSize:message_center::kTitleFontSize]]; |
| 149 | 148 |
| 150 [settingsText_ setStringValue: | 149 [settingsText_ setStringValue: |
| 151 l10n_util::GetNSString(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL)]; | 150 l10n_util::GetNSString(IDS_MESSAGE_CENTER_SETTINGS_BUTTON_LABEL)]; |
| 152 [settingsText_ sizeToFit]; | 151 [settingsText_ sizeToFit]; |
| 153 headerFrame = [settingsText_ frame]; | 152 headerFrame = [settingsText_ frame]; |
| 154 headerFrame.origin.y = NSMaxY(fullFrame) - kCorrectedHeaderTextTopPadding - | 153 headerFrame.origin.y = NSMaxY(fullFrame) - kCorrectedHeaderTextTopPadding - |
| 155 NSHeight(headerFrame); | 154 NSHeight(headerFrame); |
| 156 [[self view] addSubview:settingsText_]; | 155 [[self view] addSubview:settingsText_]; |
| 157 | 156 |
| 158 // Subheader. | 157 // Subheader. |
| 159 NSRect subheaderFrame = NSMakeRect(kHorizontalMargin, | 158 NSRect subheaderFrame = NSMakeRect(kHorizontalMargin, |
| 160 kHorizontalMargin, | 159 kHorizontalMargin, |
| 161 NSWidth(fullFrame), | 160 NSWidth(fullFrame), |
| 162 NSHeight(fullFrame)); | 161 NSHeight(fullFrame)); |
| 163 detailsText_.reset([self newLabelWithFrame:subheaderFrame]); | 162 detailsText_.reset([self newLabelWithFrame:subheaderFrame]); |
| 164 [detailsText_ setAutoresizingMask:NSViewMinYMargin]; | |
| 165 [detailsText_ setTextColor: | 163 [detailsText_ setTextColor: |
| 166 gfx::SkColorToCalibratedNSColor(message_center::kDimTextColor)]; | 164 gfx::SkColorToCalibratedNSColor(message_center::kDimTextColor)]; |
| 167 [detailsText_ | 165 [detailsText_ |
| 168 setFont:[NSFont messageFontOfSize:message_center::kMessageFontSize]]; | 166 setFont:[NSFont messageFontOfSize:message_center::kMessageFontSize]]; |
| 169 | 167 |
| 170 size_t groupCount = provider_->GetNotifierGroupCount(); | 168 size_t groupCount = provider_->GetNotifierGroupCount(); |
| 171 [detailsText_ setStringValue:l10n_util::GetNSString( | 169 [detailsText_ setStringValue:l10n_util::GetNSString( |
| 172 groupCount > 1 ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER | 170 groupCount > 1 ? IDS_MESSAGE_CENTER_SETTINGS_DESCRIPTION_MULTIUSER |
| 173 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)]; | 171 : IDS_MESSAGE_CENTER_SETTINGS_DIALOG_DESCRIPTION)]; |
| 174 [detailsText_ sizeToFit]; | 172 [detailsText_ sizeToFit]; |
| 175 subheaderFrame = [detailsText_ frame]; | 173 subheaderFrame = [detailsText_ frame]; |
| 176 subheaderFrame.origin.y = | 174 subheaderFrame.origin.y = |
| 177 NSMinY(headerFrame) - kCorrectedSubheaderTextTopPadding - | 175 NSMinY(headerFrame) - kCorrectedSubheaderTextTopPadding - |
| 178 NSHeight(subheaderFrame); | 176 NSHeight(subheaderFrame); |
| 179 [[self view] addSubview:detailsText_]; | 177 [[self view] addSubview:detailsText_]; |
| 180 | 178 |
| 181 // Profile switcher is only needed for more than one profile. | 179 // Profile switcher is only needed for more than one profile. |
| 182 NSRect dropDownButtonFrame = subheaderFrame; | 180 NSRect dropDownButtonFrame = subheaderFrame; |
| 183 if (groupCount > 1) { | 181 if (groupCount > 1) { |
| 184 dropDownButtonFrame = NSMakeRect(kCorrectedDropDownMargin, | 182 dropDownButtonFrame = NSMakeRect(kCorrectedDropDownMargin, |
| 185 kHorizontalMargin, | 183 kHorizontalMargin, |
| 186 NSWidth(fullFrame), | 184 NSWidth(fullFrame), |
| 187 NSHeight(fullFrame)); | 185 NSHeight(fullFrame)); |
| 188 groupDropDownButton_.reset( | 186 groupDropDownButton_.reset( |
| 189 [[NSPopUpButton alloc] initWithFrame:dropDownButtonFrame | 187 [[MCDropDown alloc] initWithFrame:dropDownButtonFrame pullsDown:YES]); |
| 190 pullsDown:YES]); | 188 [groupDropDownButton_ |
| 189 setBackgroundColor:gfx::SkColorToCalibratedNSColor( |
| 190 message_center::kMessageCenterBackgroundColor)]; |
| 191 [groupDropDownButton_ setAction:@selector(notifierGroupSelectionChanged:)]; | 191 [groupDropDownButton_ setAction:@selector(notifierGroupSelectionChanged:)]; |
| 192 [groupDropDownButton_ setTarget:self]; | 192 [groupDropDownButton_ setTarget:self]; |
| 193 // Add a dummy item for pull-down. | 193 // Add a dummy item for pull-down. |
| 194 [groupDropDownButton_ addItemWithTitle:@""]; | 194 [groupDropDownButton_ addItemWithTitle:@""]; |
| 195 base::string16 title; | 195 base::string16 title; |
| 196 for (size_t i = 0; i < groupCount; ++i) { | 196 for (size_t i = 0; i < groupCount; ++i) { |
| 197 const message_center::NotifierGroup& group = | 197 const message_center::NotifierGroup& group = |
| 198 provider_->GetNotifierGroupAt(i); | 198 provider_->GetNotifierGroupAt(i); |
| 199 base::string16 item = | 199 base::string16 item = |
| 200 group.login_info.empty() ? group.name : group.login_info; | 200 group.login_info.empty() ? group.name : group.login_info; |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); | 331 NSPopUpButton* button = static_cast<NSPopUpButton*>(sender); |
| 332 // The first item is a dummy item. | 332 // The first item is a dummy item. |
| 333 provider_->SwitchToNotifierGroup([button indexOfSelectedItem] - 1); | 333 provider_->SwitchToNotifierGroup([button indexOfSelectedItem] - 1); |
| 334 } | 334 } |
| 335 | 335 |
| 336 - (BOOL)notifierHasAdvancedSettings:(const message_center::NotifierId&)id { | 336 - (BOOL)notifierHasAdvancedSettings:(const message_center::NotifierId&)id { |
| 337 return provider_->NotifierHasAdvancedSettings(id); | 337 return provider_->NotifierHasAdvancedSettings(id); |
| 338 } | 338 } |
| 339 | 339 |
| 340 @end | 340 @end |
| OLD | NEW |