| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/autofill/autofill_popup_view_cocoa.h" | 5 #import "chrome/browser/ui/cocoa/autofill/autofill_popup_view_cocoa.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/sys_string_conversions.h" | 8 #include "base/strings/sys_string_conversions.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 10 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" | 10 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 11 #include "chrome/browser/ui/autofill/popup_constants.h" | |
| 12 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" | 11 #include "chrome/browser/ui/cocoa/autofill/autofill_popup_view_bridge.h" |
| 13 #include "components/autofill/core/browser/popup_item_ids.h" | 12 #include "components/autofill/core/browser/popup_item_ids.h" |
| 14 #include "components/autofill/core/browser/suggestion.h" | 13 #include "components/autofill/core/browser/suggestion.h" |
| 15 #include "skia/ext/skia_utils_mac.h" | 14 #include "skia/ext/skia_utils_mac.h" |
| 16 #include "third_party/skia/include/core/SkColor.h" | 15 #include "third_party/skia/include/core/SkColor.h" |
| 17 #include "ui/base/cocoa/window_size_constants.h" | 16 #include "ui/base/cocoa/window_size_constants.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/gfx/font_list.h" | 18 #include "ui/gfx/font_list.h" |
| 20 #include "ui/gfx/geometry/point.h" | 19 #include "ui/gfx/geometry/point.h" |
| 21 #include "ui/gfx/geometry/rect.h" | 20 #include "ui/gfx/geometry/rect.h" |
| 22 #include "ui/gfx/image/image.h" | 21 #include "ui/gfx/image/image.h" |
| 22 #include "ui/native_theme/native_theme.h" |
| 23 #include "ui/native_theme/native_theme_mac.h" |
| 23 | 24 |
| 24 using autofill::AutofillPopupView; | 25 using autofill::AutofillPopupView; |
| 25 using autofill::AutofillPopupLayoutModel; | 26 using autofill::AutofillPopupLayoutModel; |
| 26 | 27 |
| 27 @interface AutofillPopupViewCocoa () | 28 @interface AutofillPopupViewCocoa () |
| 28 | 29 |
| 29 #pragma mark - | 30 #pragma mark - |
| 30 #pragma mark Private methods | 31 #pragma mark Private methods |
| 31 | 32 |
| 32 // Draws an Autofill suggestion in the given |bounds|, labeled with the given | 33 // Draws an Autofill suggestion in the given |bounds|, labeled with the given |
| (...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 153 bounds:(NSRect)bounds | 154 bounds:(NSRect)bounds |
| 154 selected:(BOOL)isSelected | 155 selected:(BOOL)isSelected |
| 155 textYOffset:(CGFloat)textYOffset { | 156 textYOffset:(CGFloat)textYOffset { |
| 156 // If this row is selected, highlight it with this mac system color. | 157 // If this row is selected, highlight it with this mac system color. |
| 157 // Otherwise the controller may have a specific background color for this | 158 // Otherwise the controller may have a specific background color for this |
| 158 // entry. | 159 // entry. |
| 159 if (isSelected) { | 160 if (isSelected) { |
| 160 [[self highlightColor] set]; | 161 [[self highlightColor] set]; |
| 161 [NSBezierPath fillRect:bounds]; | 162 [NSBezierPath fillRect:bounds]; |
| 162 } else { | 163 } else { |
| 163 SkColor backgroundColor = controller_->GetBackgroundColorForRow(index); | 164 SkColor backgroundColor = |
| 165 ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor( |
| 166 controller_->GetBackgroundColorIDForRow(index)); |
| 164 [skia::SkColorToSRGBNSColor(backgroundColor) set]; | 167 [skia::SkColorToSRGBNSColor(backgroundColor) set]; |
| 165 [NSBezierPath fillRect:bounds]; | 168 [NSBezierPath fillRect:bounds]; |
| 166 } | 169 } |
| 167 | 170 |
| 168 BOOL isRTL = controller_->IsRTL(); | 171 BOOL isRTL = controller_->IsRTL(); |
| 169 | 172 |
| 170 // The X values of the left and right borders of the autofill widget. | 173 // The X values of the left and right borders of the autofill widget. |
| 171 CGFloat leftX = NSMinX(bounds) + AutofillPopupLayoutModel::kEndPadding; | 174 CGFloat leftX = NSMinX(bounds) + AutofillPopupLayoutModel::kEndPadding; |
| 172 CGFloat rightX = NSMaxX(bounds) - AutofillPopupLayoutModel::kEndPadding; | 175 CGFloat rightX = NSMaxX(bounds) - AutofillPopupLayoutModel::kEndPadding; |
| 173 | 176 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 191 textYOffset:textYOffset]; | 194 textYOffset:textYOffset]; |
| 192 } | 195 } |
| 193 | 196 |
| 194 - (CGFloat)drawName:(NSString*)name | 197 - (CGFloat)drawName:(NSString*)name |
| 195 atX:(CGFloat)x | 198 atX:(CGFloat)x |
| 196 index:(size_t)index | 199 index:(size_t)index |
| 197 rightAlign:(BOOL)rightAlign | 200 rightAlign:(BOOL)rightAlign |
| 198 bounds:(NSRect)bounds | 201 bounds:(NSRect)bounds |
| 199 textYOffset:(CGFloat)textYOffset { | 202 textYOffset:(CGFloat)textYOffset { |
| 200 NSColor* nameColor = skia::SkColorToSRGBNSColor( | 203 NSColor* nameColor = skia::SkColorToSRGBNSColor( |
| 201 controller_->layout_model().GetValueFontColorForRow(index)); | 204 ui::NativeTheme::GetInstanceForNativeUi()->GetSystemColor( |
| 205 controller_->layout_model().GetValueFontColorIDForRow(index))); |
| 202 NSDictionary* nameAttributes = [NSDictionary | 206 NSDictionary* nameAttributes = [NSDictionary |
| 203 dictionaryWithObjectsAndKeys:controller_->layout_model() | 207 dictionaryWithObjectsAndKeys:controller_->layout_model() |
| 204 .GetValueFontListForRow(index) | 208 .GetValueFontListForRow(index) |
| 205 .GetPrimaryFont() | 209 .GetPrimaryFont() |
| 206 .GetNativeFont(), | 210 .GetNativeFont(), |
| 207 NSFontAttributeName, nameColor, | 211 NSFontAttributeName, nameColor, |
| 208 NSForegroundColorAttributeName, nil]; | 212 NSForegroundColorAttributeName, nil]; |
| 209 NSSize nameSize = [name sizeWithAttributes:nameAttributes]; | 213 NSSize nameSize = [name sizeWithAttributes:nameAttributes]; |
| 210 x -= rightAlign ? nameSize.width : 0; | 214 x -= rightAlign ? nameSize.width : 0; |
| 211 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2; | 215 CGFloat y = bounds.origin.y + (bounds.size.height - nameSize.height) / 2; |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 268 return nil; | 272 return nil; |
| 269 | 273 |
| 270 int iconId = delegate_->GetIconResourceID(icon); | 274 int iconId = delegate_->GetIconResourceID(icon); |
| 271 DCHECK_NE(-1, iconId); | 275 DCHECK_NE(-1, iconId); |
| 272 | 276 |
| 273 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 277 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 274 return rb.GetNativeImageNamed(iconId).ToNSImage(); | 278 return rb.GetNativeImageNamed(iconId).ToNSImage(); |
| 275 } | 279 } |
| 276 | 280 |
| 277 @end | 281 @end |
| OLD | NEW |