Chromium Code Reviews| 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 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 135 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON . | 135 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON . |
| 136 * ............................................................................ | 136 * ............................................................................ |
| 137 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . | 137 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE . |
| 138 * ............................................................................ | 138 * ............................................................................ |
| 139 * | 139 * |
| 140 * Anyone who wants to modify the code below, remember to make sure that HTTP | 140 * Anyone who wants to modify the code below, remember to make sure that HTTP |
| 141 * warning entry displays right. To trigger the warning message entry, enable | 141 * warning entry displays right. To trigger the warning message entry, enable |
| 142 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with | 142 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with |
| 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, |
|
Evan Stade
2017/07/12 17:53:52
This entire function with all its directionality c
melandory
2017/07/12 23:13:47
The initial change to this function was more strai
Mathieu
2017/07/13 14:16:04
I agree with Evan, we need to rework this function
| |
| 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 bool is_http_warning = | 153 int current_row_frontend_id = controller_->GetSuggestionAt(index).frontend_id; |
|
Evan Stade
2017/07/12 17:53:52
nit: const
also, to shorten the variable name I t
| |
| 154 (controller_->GetSuggestionAt(index).frontend_id == | |
| 155 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | |
| 156 const bool is_rtl = controller_->IsRTL(); | 154 const bool is_rtl = controller_->IsRTL(); |
| 157 const int text_align = | 155 const int text_align = |
| 158 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 156 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 159 gfx::Rect value_rect = entry_rect; | 157 gfx::Rect value_rect = entry_rect; |
| 160 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); | 158 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); |
| 159 const bool icon_in_front_of_text = | |
| 160 (current_row_frontend_id == | |
| 161 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || | |
| 162 current_row_frontend_id == POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY); | |
| 161 | 163 |
| 162 // If the icon is on the right of the rect, no matter in RTL or LTR mode. | 164 int x_align_left = is_rtl ? value_rect.x() : value_rect.right(); |
| 163 bool icon_on_the_right = is_http_warning == is_rtl; | 165 // Draw the Autofill icon, if one exists |
| 164 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); | 166 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 167 int row_height = controller_->layout_model().GetRowBounds(index).height(); | |
| 168 // If the icon is on the right of the rect, no matter in RTL or LTR mode. | |
| 169 bool icon_on_the_right = icon_in_front_of_text == is_rtl; | |
|
Evan Stade
2017/07/12 17:53:52
nit: const
| |
| 170 x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); | |
| 165 | 171 |
| 166 // Draw the Autofill icon, if one exists | |
| 167 int row_height = controller_->layout_model().GetRowBounds(index).height(); | |
| 168 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 |
| 181 const int width_icon_padding = | |
| 182 image.width() + | |
| 183 (icon_in_front_of_text | |
| 184 ? AutofillPopupLayoutModel::kPaddingBetweenLeftSideIconAndText | |
| 185 : AutofillPopupLayoutModel::kIconPadding); | |
| 186 | |
| 178 // An icon was drawn; adjust the |x_align_left| value for the next element. | 187 // An icon was drawn; adjust the |x_align_left| value for the next element. |
| 179 if (is_http_warning) { | 188 x_align_left = x_align_left + (icon_on_the_right ? -width_icon_padding |
| 180 x_align_left = | 189 : width_icon_padding); |
| 181 icon_x_align_left + | |
| 182 (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding | |
| 183 : image.width() + | |
| 184 AutofillPopupLayoutModel::kHttpWarningIconPadding); | |
| 185 } else { | |
| 186 x_align_left = | |
| 187 icon_x_align_left + | |
| 188 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding | |
| 189 : -AutofillPopupLayoutModel::kIconPadding); | |
| 190 } | |
| 191 } | 190 } |
| 192 | 191 |
| 193 // Draw the value text | 192 // Draw the value text. |
| 194 const int value_width = gfx::GetStringWidth( | 193 const int value_width = gfx::GetStringWidth( |
| 195 controller_->GetElidedValueAt(index), | 194 controller_->GetElidedValueAt(index), |
| 196 controller_->layout_model().GetValueFontListForRow(index)); | 195 controller_->layout_model().GetValueFontListForRow(index)); |
| 197 int value_x_align_left = x_align_left; | 196 int value_x_align_left = x_align_left; |
| 198 | 197 |
| 199 if (is_http_warning) { | 198 if (icon_in_front_of_text) { |
| 200 value_x_align_left += is_rtl ? -value_width : 0; | 199 value_x_align_left += is_rtl ? -value_width : 0; |
| 201 } else { | 200 } else { |
| 202 value_x_align_left = | 201 value_x_align_left = |
| 203 is_rtl ? value_rect.right() - value_width : value_rect.x(); | 202 is_rtl ? value_rect.right() - value_width : value_rect.x(); |
| 204 } | 203 } |
| 205 | 204 |
| 206 canvas->DrawStringRectWithFlags( | 205 canvas->DrawStringRectWithFlags( |
| 207 controller_->GetElidedValueAt(index), | 206 controller_->GetElidedValueAt(index), |
| 208 controller_->layout_model().GetValueFontListForRow(index), | 207 controller_->layout_model().GetValueFontListForRow(index), |
| 209 GetNativeTheme()->GetSystemColor( | 208 GetNativeTheme()->GetSystemColor( |
| 210 controller_->layout_model().GetValueFontColorIDForRow(index)), | 209 controller_->layout_model().GetValueFontColorIDForRow(index)), |
| 211 gfx::Rect(value_x_align_left, value_rect.y(), value_width, | 210 gfx::Rect(value_x_align_left, value_rect.y(), value_width, |
| 212 value_rect.height()), | 211 value_rect.height()), |
| 213 text_align); | 212 text_align); |
| 214 | 213 |
| 215 // Draw the label text, if one exists. | 214 // Draw the label text, if one exists. |
| 216 if (!controller_->GetSuggestionAt(index).label.empty()) { | 215 if (!controller_->GetSuggestionAt(index).label.empty()) { |
| 217 const int label_width = gfx::GetStringWidth( | 216 const int label_width = gfx::GetStringWidth( |
| 218 controller_->GetElidedLabelAt(index), | 217 controller_->GetElidedLabelAt(index), |
| 219 controller_->layout_model().GetLabelFontListForRow(index)); | 218 controller_->layout_model().GetLabelFontListForRow(index)); |
| 220 int label_x_align_left = x_align_left; | 219 int label_x_align_left = x_align_left; |
| 221 | 220 |
| 222 if (is_http_warning) { | 221 if (icon_in_front_of_text) { |
| 223 label_x_align_left = | 222 label_x_align_left = |
| 224 is_rtl ? value_rect.x() : value_rect.right() - label_width; | 223 is_rtl ? value_rect.x() : value_rect.right() - label_width; |
| 225 } else { | 224 } else { |
| 226 label_x_align_left += is_rtl ? 0 : -label_width; | 225 label_x_align_left += is_rtl ? 0 : -label_width; |
| 227 } | 226 } |
| 228 | 227 |
| 229 // TODO(crbug.com/678033):Add a GetLabelFontColorForRow function similar to | 228 // TODO(crbug.com/678033): Add a GetLabelFontColorForRow function similar to |
| 230 // GetValueFontColorForRow so that the cocoa impl could use it too | 229 // GetValueFontColorForRow so that the cocoa impl could use it too. |
| 231 canvas->DrawStringRectWithFlags( | 230 canvas->DrawStringRectWithFlags( |
| 232 controller_->GetElidedLabelAt(index), | 231 controller_->GetElidedLabelAt(index), |
| 233 controller_->layout_model().GetLabelFontListForRow(index), | 232 controller_->layout_model().GetLabelFontListForRow(index), |
| 234 GetNativeTheme()->GetSystemColor( | 233 GetNativeTheme()->GetSystemColor( |
| 235 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 234 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
| 236 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 235 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
| 237 entry_rect.height()), | 236 entry_rect.height()), |
| 238 text_align); | 237 text_align); |
| 239 } | 238 } |
| 240 } | 239 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 261 | 260 |
| 262 // If the top level widget can't be found, cancel the popup since we can't | 261 // If the top level widget can't be found, cancel the popup since we can't |
| 263 // fully set it up. | 262 // fully set it up. |
| 264 if (!observing_widget) | 263 if (!observing_widget) |
| 265 return NULL; | 264 return NULL; |
| 266 | 265 |
| 267 return new AutofillPopupViewViews(controller, observing_widget); | 266 return new AutofillPopupViewViews(controller, observing_widget); |
| 268 } | 267 } |
| 269 | 268 |
| 270 } // namespace autofill | 269 } // namespace autofill |
| OLD | NEW |