| 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 "base/optional.h" | 7 #include "base/optional.h" |
| 8 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" | 8 #include "chrome/browser/ui/autofill/autofill_popup_controller.h" |
| 9 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" | 9 #include "chrome/browser/ui/autofill/autofill_popup_layout_model.h" |
| 10 #include "chrome/grit/generated_resources.h" | 10 #include "chrome/grit/generated_resources.h" |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 * stored autofill info and check for credit card or password forms. | 143 * stored autofill info and check for credit card or password forms. |
| 144 */ | 144 */ |
| 145 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 145 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
| 146 int index, | 146 int index, |
| 147 const gfx::Rect& entry_rect) { | 147 const gfx::Rect& entry_rect) { |
| 148 canvas->FillRect( | 148 canvas->FillRect( |
| 149 entry_rect, | 149 entry_rect, |
| 150 GetNativeTheme()->GetSystemColor( | 150 GetNativeTheme()->GetSystemColor( |
| 151 controller_->GetBackgroundColorIDForRow(index))); | 151 controller_->GetBackgroundColorIDForRow(index))); |
| 152 | 152 |
| 153 const int frontend_id = controller_->GetSuggestionAt(index).frontend_id; |
| 153 const bool is_http_warning = | 154 const bool is_http_warning = |
| 154 (controller_->GetSuggestionAt(index).frontend_id == | 155 (frontend_id == POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); |
| 155 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | 156 const bool icon_in_front_of_text = |
| 157 (is_http_warning || |
| 158 frontend_id == POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY); |
| 156 const bool is_rtl = controller_->IsRTL(); | 159 const bool is_rtl = controller_->IsRTL(); |
| 157 const int text_align = | 160 const int text_align = |
| 158 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 161 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 159 gfx::Rect value_rect = entry_rect; | 162 gfx::Rect value_rect = entry_rect; |
| 160 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); | 163 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); |
| 161 | 164 |
| 162 // If the icon is on the right of the rect, no matter in RTL or LTR mode. | 165 // If the icon is on the right of the rect, no matter in RTL or LTR mode. |
| 163 bool icon_on_the_right = is_http_warning == is_rtl; | 166 bool icon_on_the_right = icon_in_front_of_text == is_rtl; |
| 164 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); | 167 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); |
| 165 | 168 |
| 166 // Draw the Autofill icon, if one exists | 169 // Draw the Autofill icon, if one exists |
| 167 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 170 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 168 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 171 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 169 const gfx::ImageSkia image = | 172 const gfx::ImageSkia image = |
| 170 controller_->layout_model().GetIconImage(index); | 173 controller_->layout_model().GetIconImage(index); |
| 171 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; | 174 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 172 | 175 |
| 173 int icon_x_align_left = | 176 int icon_x_align_left = |
| 174 icon_on_the_right ? x_align_left - image.width() : x_align_left; | 177 icon_on_the_right ? x_align_left - image.width() : x_align_left; |
| 175 | 178 |
| 176 canvas->DrawImageInt(image, icon_x_align_left, icon_y); | 179 canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| 177 | 180 |
| 178 // An icon was drawn; adjust the |x_align_left| value for the next element. | 181 // An icon was drawn; adjust the |x_align_left| value for the next element. |
| 179 if (is_http_warning) { | 182 if (icon_in_front_of_text) { |
| 180 x_align_left = | 183 x_align_left = |
| 181 icon_x_align_left + | 184 icon_x_align_left + |
| 182 (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding | 185 (is_rtl ? -AutofillPopupLayoutModel::kPaddingAfterLeadingIcon |
| 183 : image.width() + | 186 : image.width() + |
| 184 AutofillPopupLayoutModel::kHttpWarningIconPadding); | 187 AutofillPopupLayoutModel::kPaddingAfterLeadingIcon); |
| 185 } else { | 188 } else { |
| 186 x_align_left = | 189 x_align_left = |
| 187 icon_x_align_left + | 190 icon_x_align_left + |
| 188 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding | 191 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding |
| 189 : -AutofillPopupLayoutModel::kIconPadding); | 192 : -AutofillPopupLayoutModel::kIconPadding); |
| 190 } | 193 } |
| 191 } | 194 } |
| 192 | 195 |
| 193 // Draw the value text | 196 // Draw the value text |
| 194 const int value_width = gfx::GetStringWidth( | 197 const int value_width = gfx::GetStringWidth( |
| 195 controller_->GetElidedValueAt(index), | 198 controller_->GetElidedValueAt(index), |
| 196 controller_->layout_model().GetValueFontListForRow(index)); | 199 controller_->layout_model().GetValueFontListForRow(index)); |
| 197 int value_x_align_left = x_align_left; | 200 int value_x_align_left = x_align_left; |
| 198 | 201 |
| 199 if (is_http_warning) { | 202 if (icon_in_front_of_text) { |
| 200 value_x_align_left += is_rtl ? -value_width : 0; | 203 value_x_align_left += is_rtl ? -value_width : 0; |
| 201 } else { | 204 } else { |
| 202 value_x_align_left = | 205 value_x_align_left = |
| 203 is_rtl ? value_rect.right() - value_width : value_rect.x(); | 206 is_rtl ? value_rect.right() - value_width : value_rect.x(); |
| 204 } | 207 } |
| 205 | 208 |
| 206 canvas->DrawStringRectWithFlags( | 209 canvas->DrawStringRectWithFlags( |
| 207 controller_->GetElidedValueAt(index), | 210 controller_->GetElidedValueAt(index), |
| 208 controller_->layout_model().GetValueFontListForRow(index), | 211 controller_->layout_model().GetValueFontListForRow(index), |
| 209 GetNativeTheme()->GetSystemColor( | 212 GetNativeTheme()->GetSystemColor( |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 261 | 264 |
| 262 // If the top level widget can't be found, cancel the popup since we can't | 265 // If the top level widget can't be found, cancel the popup since we can't |
| 263 // fully set it up. | 266 // fully set it up. |
| 264 if (!observing_widget) | 267 if (!observing_widget) |
| 265 return NULL; | 268 return NULL; |
| 266 | 269 |
| 267 return new AutofillPopupViewViews(controller, observing_widget); | 270 return new AutofillPopupViewViews(controller, observing_widget); |
| 268 } | 271 } |
| 269 | 272 |
| 270 } // namespace autofill | 273 } // namespace autofill |
| OLD | NEW |