| 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 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" | 5 #include "chrome/browser/ui/views/autofill/autofill_popup_view_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 7 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" | 8 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 9 #include "chrome/browser/ui/autofill/popup_constants.h" | 9 #include "chrome/browser/ui/autofill/popup_constants.h" |
| 10 #include "components/autofill/core/browser/popup_item_ids.h" | 10 #include "components/autofill/core/browser/popup_item_ids.h" |
| 11 #include "components/autofill/core/browser/suggestion.h" | 11 #include "components/autofill/core/browser/suggestion.h" |
| 12 #include "ui/base/resource/resource_bundle.h" | |
| 13 #include "ui/events/keycodes/keyboard_codes.h" | 12 #include "ui/events/keycodes/keyboard_codes.h" |
| 14 #include "ui/gfx/canvas.h" | 13 #include "ui/gfx/canvas.h" |
| 15 #include "ui/gfx/geometry/point.h" | 14 #include "ui/gfx/geometry/point.h" |
| 16 #include "ui/gfx/geometry/rect.h" | 15 #include "ui/gfx/geometry/rect.h" |
| 17 #include "ui/gfx/image/image.h" | 16 #include "ui/gfx/image/image.h" |
| 18 #include "ui/gfx/native_widget_types.h" | 17 #include "ui/gfx/native_widget_types.h" |
| 19 #include "ui/gfx/text_utils.h" | 18 #include "ui/gfx/text_utils.h" |
| 20 #include "ui/views/border.h" | 19 #include "ui/views/border.h" |
| 21 #include "ui/views/widget/widget.h" | 20 #include "ui/views/widget/widget.h" |
| 22 | 21 |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 83 controller_->layout_model().GetValueFontListForRow(index), | 82 controller_->layout_model().GetValueFontListForRow(index), |
| 84 controller_->layout_model().GetValueFontColorForRow(index), value_rect, | 83 controller_->layout_model().GetValueFontColorForRow(index), value_rect, |
| 85 text_align); | 84 text_align); |
| 86 | 85 |
| 87 // Use this to figure out where all the other Autofill items should be placed. | 86 // Use this to figure out where all the other Autofill items should be placed. |
| 88 int x_align_left = | 87 int x_align_left = |
| 89 is_rtl ? AutofillPopupLayoutModel::kEndPadding | 88 is_rtl ? AutofillPopupLayoutModel::kEndPadding |
| 90 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; | 89 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; |
| 91 | 90 |
| 92 // Draw the Autofill icon, if one exists | 91 // Draw the Autofill icon, if one exists |
| 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 94 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 92 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 95 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 93 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 96 int icon = controller_->layout_model().GetIconResourceID( | 94 const gfx::ImageSkia image = |
| 97 controller_->GetSuggestionAt(index).icon); | 95 controller_->layout_model().GetIconImage(index); |
| 98 DCHECK_NE(-1, icon); | 96 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 99 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); | |
| 100 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; | |
| 101 | 97 |
| 102 x_align_left += is_rtl ? 0 : -image->width(); | 98 x_align_left += is_rtl ? 0 : -image.width(); |
| 103 | 99 |
| 104 canvas->DrawImageInt(*image, x_align_left, icon_y); | 100 canvas->DrawImageInt(image, x_align_left, icon_y); |
| 105 | 101 |
| 106 x_align_left += | 102 x_align_left += is_rtl |
| 107 is_rtl ? image->width() + AutofillPopupLayoutModel::kIconPadding | 103 ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| 108 : -AutofillPopupLayoutModel::kIconPadding; | 104 : -AutofillPopupLayoutModel::kIconPadding; |
| 109 } | 105 } |
| 110 | 106 |
| 111 // Draw the label text. | 107 // Draw the label text. |
| 112 const int label_width = | 108 const int label_width = |
| 113 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), | 109 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), |
| 114 controller_->layout_model().GetLabelFontList()); | 110 controller_->layout_model().GetLabelFontList()); |
| 115 if (!is_rtl) | 111 if (!is_rtl) |
| 116 x_align_left -= label_width; | 112 x_align_left -= label_width; |
| 117 | 113 |
| 118 canvas->DrawStringRectWithFlags( | 114 canvas->DrawStringRectWithFlags( |
| (...skipping 11 matching lines...) Expand all Loading... |
| 130 | 126 |
| 131 // If the top level widget can't be found, cancel the popup since we can't | 127 // If the top level widget can't be found, cancel the popup since we can't |
| 132 // fully set it up. | 128 // fully set it up. |
| 133 if (!observing_widget) | 129 if (!observing_widget) |
| 134 return NULL; | 130 return NULL; |
| 135 | 131 |
| 136 return new AutofillPopupViewViews(controller, observing_widget); | 132 return new AutofillPopupViewViews(controller, observing_widget); |
| 137 } | 133 } |
| 138 | 134 |
| 139 } // namespace autofill | 135 } // namespace autofill |
| OLD | NEW |