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 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 bool is_http_warning = | 153 int current_row_frontend_id = controller_->GetSuggestionAt(index).frontend_id; |
| 154 (controller_->GetSuggestionAt(index).frontend_id == | 154 const bool icon_in_front_of_text_row = |
|
vasilii
2017/07/06 15:15:21
icon_in_front_of_text?
melandory
2017/07/07 12:26:31
Done.
| |
| 155 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); | 155 (current_row_frontend_id == |
| 156 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE || | |
| 157 current_row_frontend_id == POPUP_ITEM_ID_ALL_SAVED_PASSWORDS_ENTRY); | |
| 156 const bool is_rtl = controller_->IsRTL(); | 158 const bool is_rtl = controller_->IsRTL(); |
| 157 const int text_align = | 159 const int text_align = |
| 158 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; | 160 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; |
| 159 gfx::Rect value_rect = entry_rect; | 161 gfx::Rect value_rect = entry_rect; |
| 160 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); | 162 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); |
| 161 | 163 |
| 162 // If the icon is on the right of the rect, no matter in RTL or LTR mode. | 164 // 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; | 165 bool icon_on_the_right = icon_in_front_of_text_row == is_rtl; |
| 164 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); | 166 int x_align_left = icon_on_the_right ? value_rect.right() : value_rect.x(); |
| 165 | 167 |
| 166 // Draw the Autofill icon, if one exists | 168 // Draw the Autofill icon, if one exists |
| 167 int row_height = controller_->layout_model().GetRowBounds(index).height(); | 169 int row_height = controller_->layout_model().GetRowBounds(index).height(); |
| 168 if (!controller_->GetSuggestionAt(index).icon.empty()) { | 170 if (!controller_->GetSuggestionAt(index).icon.empty()) { |
| 169 const gfx::ImageSkia image = | 171 const gfx::ImageSkia image = |
| 170 controller_->layout_model().GetIconImage(index); | 172 controller_->layout_model().GetIconImage(index); |
| 171 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; | 173 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; |
| 172 | 174 |
| 173 int icon_x_align_left = | 175 int icon_x_align_left = |
| 174 icon_on_the_right ? x_align_left - image.width() : x_align_left; | 176 icon_on_the_right ? x_align_left - image.width() : x_align_left; |
| 175 | 177 |
| 176 canvas->DrawImageInt(image, icon_x_align_left, icon_y); | 178 canvas->DrawImageInt(image, icon_x_align_left, icon_y); |
| 177 | 179 |
| 178 // An icon was drawn; adjust the |x_align_left| value for the next element. | 180 // An icon was drawn; adjust the |x_align_left| value for the next element. |
| 179 if (is_http_warning) { | 181 const int width_icon_padding = |
| 180 x_align_left = | 182 image.width() + |
| 181 icon_x_align_left + | 183 (icon_in_front_of_text_row |
| 182 (is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding | 184 ? AutofillPopupLayoutModel::kRightHandSideIconPapping |
|
vasilii
2017/07/06 15:15:21
Two questions:
- what is papping?
- Why "right han
melandory
2017/07/07 12:26:31
mistyped padding =)
vasilii
2017/07/07 12:51:27
But the icon is actually on the left side
| |
| 183 : image.width() + | 185 : AutofillPopupLayoutModel::kIconPadding); |
| 184 AutofillPopupLayoutModel::kHttpWarningIconPadding); | 186 x_align_left = x_align_left + (icon_on_the_right ? -width_icon_padding |
| 185 } else { | 187 : width_icon_padding); |
| 186 x_align_left = | |
| 187 icon_x_align_left + | |
| 188 (is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding | |
| 189 : -AutofillPopupLayoutModel::kIconPadding); | |
| 190 } | |
| 191 } | 188 } |
| 192 | 189 |
| 193 // Draw the value text | 190 // Draw the value text. |
| 194 const int value_width = gfx::GetStringWidth( | 191 const int value_width = gfx::GetStringWidth( |
| 195 controller_->GetElidedValueAt(index), | 192 controller_->GetElidedValueAt(index), |
| 196 controller_->layout_model().GetValueFontListForRow(index)); | 193 controller_->layout_model().GetValueFontListForRow(index)); |
| 197 int value_x_align_left = x_align_left; | 194 int value_x_align_left = x_align_left; |
| 198 | 195 |
| 199 if (is_http_warning) { | 196 if (icon_in_front_of_text_row) { |
| 200 value_x_align_left += is_rtl ? -value_width : 0; | 197 value_x_align_left += is_rtl ? -value_width : 0; |
| 201 } else { | 198 } else { |
| 202 value_x_align_left = | 199 value_x_align_left = |
| 203 is_rtl ? value_rect.right() - value_width : value_rect.x(); | 200 is_rtl ? value_rect.right() - value_width : value_rect.x(); |
|
vasilii
2017/07/06 15:15:21
The biggest question I have about all of this is
-
melandory
2017/07/07 12:26:31
It seems so to me for now, I'll get a break and lo
vasilii
2017/07/07 12:51:27
Then I think this block can be simplified.
melandory
2017/07/10 14:15:14
There is a view where icon is behind the text: htt
| |
| 204 } | 201 } |
| 205 | 202 |
| 206 canvas->DrawStringRectWithFlags( | 203 canvas->DrawStringRectWithFlags( |
| 207 controller_->GetElidedValueAt(index), | 204 controller_->GetElidedValueAt(index), |
| 208 controller_->layout_model().GetValueFontListForRow(index), | 205 controller_->layout_model().GetValueFontListForRow(index), |
| 209 GetNativeTheme()->GetSystemColor( | 206 GetNativeTheme()->GetSystemColor( |
| 210 controller_->layout_model().GetValueFontColorIDForRow(index)), | 207 controller_->layout_model().GetValueFontColorIDForRow(index)), |
| 211 gfx::Rect(value_x_align_left, value_rect.y(), value_width, | 208 gfx::Rect(value_x_align_left, value_rect.y(), value_width, |
| 212 value_rect.height()), | 209 value_rect.height()), |
| 213 text_align); | 210 text_align); |
| 214 | 211 |
| 215 // Draw the label text, if one exists. | 212 // Draw the label text, if one exists. |
| 216 if (!controller_->GetSuggestionAt(index).label.empty()) { | 213 if (!controller_->GetSuggestionAt(index).label.empty()) { |
| 217 const int label_width = gfx::GetStringWidth( | 214 const int label_width = gfx::GetStringWidth( |
| 218 controller_->GetElidedLabelAt(index), | 215 controller_->GetElidedLabelAt(index), |
| 219 controller_->layout_model().GetLabelFontListForRow(index)); | 216 controller_->layout_model().GetLabelFontListForRow(index)); |
| 220 int label_x_align_left = x_align_left; | 217 int label_x_align_left = x_align_left; |
| 221 | 218 |
| 222 if (is_http_warning) { | 219 if (icon_in_front_of_text_row) { |
| 223 label_x_align_left = | 220 label_x_align_left = |
| 224 is_rtl ? value_rect.x() : value_rect.right() - label_width; | 221 is_rtl ? value_rect.x() : value_rect.right() - label_width; |
| 225 } else { | 222 } else { |
| 226 label_x_align_left += is_rtl ? 0 : -label_width; | 223 label_x_align_left += is_rtl ? 0 : -label_width; |
| 227 } | 224 } |
| 228 | 225 |
| 229 // TODO(crbug.com/678033):Add a GetLabelFontColorForRow function similar to | 226 // TODO(crbug.com/678033): Add a GetLabelFontColorForRow function similar to |
| 230 // GetValueFontColorForRow so that the cocoa impl could use it too | 227 // GetValueFontColorForRow so that the cocoa impl could use it too. |
| 231 canvas->DrawStringRectWithFlags( | 228 canvas->DrawStringRectWithFlags( |
| 232 controller_->GetElidedLabelAt(index), | 229 controller_->GetElidedLabelAt(index), |
| 233 controller_->layout_model().GetLabelFontListForRow(index), | 230 controller_->layout_model().GetLabelFontListForRow(index), |
| 234 GetNativeTheme()->GetSystemColor( | 231 GetNativeTheme()->GetSystemColor( |
| 235 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), | 232 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), |
| 236 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, | 233 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, |
| 237 entry_rect.height()), | 234 entry_rect.height()), |
| 238 text_align); | 235 text_align); |
| 239 } | 236 } |
| 240 } | 237 } |
| (...skipping 20 matching lines...) Expand all Loading... | |
| 261 | 258 |
| 262 // If the top level widget can't be found, cancel the popup since we can't | 259 // If the top level widget can't be found, cancel the popup since we can't |
| 263 // fully set it up. | 260 // fully set it up. |
| 264 if (!observing_widget) | 261 if (!observing_widget) |
| 265 return NULL; | 262 return NULL; |
| 266 | 263 |
| 267 return new AutofillPopupViewViews(controller, observing_widget); | 264 return new AutofillPopupViewViews(controller, observing_widget); |
| 268 } | 265 } |
| 269 | 266 |
| 270 } // namespace autofill | 267 } // namespace autofill |
| OLD | NEW |