Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(31)

Side by Side Diff: chrome/browser/ui/views/autofill/autofill_popup_view_views.cc

Issue 2971783002: Skeleton for showing "Show all saved passwords row" for Linux/CrOs/Windows platforms (Closed)
Patch Set: . Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 =
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 == 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
180 const int width_icon_padding =
181 image.width() +
182 (icon_in_front_of_text
183 ? AutofillPopupLayoutModel::kRightSideIconTextPadding
184 : AutofillPopupLayoutModel::kIconPadding);
185
178 // An icon was drawn; adjust the |x_align_left| value for the next element. 186 // An icon was drawn; adjust the |x_align_left| value for the next element.
179 if (is_http_warning) { 187 x_align_left = x_align_left + (icon_on_the_right ? -width_icon_padding
180 x_align_left = 188 : 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 } 189 }
192 190
193 // Draw the value text 191 // Draw the value text.
194 const int value_width = gfx::GetStringWidth( 192 const int value_width = gfx::GetStringWidth(
195 controller_->GetElidedValueAt(index), 193 controller_->GetElidedValueAt(index),
196 controller_->layout_model().GetValueFontListForRow(index)); 194 controller_->layout_model().GetValueFontListForRow(index));
197 int value_x_align_left = x_align_left; 195 int value_x_align_left = x_align_left;
198 196
199 if (is_http_warning) { 197 if (icon_in_front_of_text) {
200 value_x_align_left += is_rtl ? -value_width : 0; 198 value_x_align_left += is_rtl ? -value_width : 0;
201 } else { 199 } else {
202 value_x_align_left = 200 value_x_align_left =
203 is_rtl ? value_rect.right() - value_width : value_rect.x(); 201 is_rtl ? value_rect.right() - value_width : value_rect.x();
204 } 202 }
205 203
206 canvas->DrawStringRectWithFlags( 204 canvas->DrawStringRectWithFlags(
207 controller_->GetElidedValueAt(index), 205 controller_->GetElidedValueAt(index),
208 controller_->layout_model().GetValueFontListForRow(index), 206 controller_->layout_model().GetValueFontListForRow(index),
209 GetNativeTheme()->GetSystemColor( 207 GetNativeTheme()->GetSystemColor(
210 controller_->layout_model().GetValueFontColorIDForRow(index)), 208 controller_->layout_model().GetValueFontColorIDForRow(index)),
211 gfx::Rect(value_x_align_left, value_rect.y(), value_width, 209 gfx::Rect(value_x_align_left, value_rect.y(), value_width,
212 value_rect.height()), 210 value_rect.height()),
213 text_align); 211 text_align);
214 212
215 // Draw the label text, if one exists. 213 // Draw the label text, if one exists.
216 if (!controller_->GetSuggestionAt(index).label.empty()) { 214 if (!controller_->GetSuggestionAt(index).label.empty()) {
217 const int label_width = gfx::GetStringWidth( 215 const int label_width = gfx::GetStringWidth(
218 controller_->GetElidedLabelAt(index), 216 controller_->GetElidedLabelAt(index),
219 controller_->layout_model().GetLabelFontListForRow(index)); 217 controller_->layout_model().GetLabelFontListForRow(index));
220 int label_x_align_left = x_align_left; 218 int label_x_align_left = x_align_left;
221 219
222 if (is_http_warning) { 220 if (icon_in_front_of_text) {
223 label_x_align_left = 221 label_x_align_left =
224 is_rtl ? value_rect.x() : value_rect.right() - label_width; 222 is_rtl ? value_rect.x() : value_rect.right() - label_width;
225 } else { 223 } else {
226 label_x_align_left += is_rtl ? 0 : -label_width; 224 label_x_align_left += is_rtl ? 0 : -label_width;
vasilii 2017/07/07 12:51:27 This block is also complicated
227 } 225 }
228 226
229 // TODO(crbug.com/678033):Add a GetLabelFontColorForRow function similar to 227 // TODO(crbug.com/678033): Add a GetLabelFontColorForRow function similar to
230 // GetValueFontColorForRow so that the cocoa impl could use it too 228 // GetValueFontColorForRow so that the cocoa impl could use it too.
231 canvas->DrawStringRectWithFlags( 229 canvas->DrawStringRectWithFlags(
232 controller_->GetElidedLabelAt(index), 230 controller_->GetElidedLabelAt(index),
233 controller_->layout_model().GetLabelFontListForRow(index), 231 controller_->layout_model().GetLabelFontListForRow(index),
234 GetNativeTheme()->GetSystemColor( 232 GetNativeTheme()->GetSystemColor(
235 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText), 233 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
236 gfx::Rect(label_x_align_left, entry_rect.y(), label_width, 234 gfx::Rect(label_x_align_left, entry_rect.y(), label_width,
237 entry_rect.height()), 235 entry_rect.height()),
238 text_align); 236 text_align);
239 } 237 }
240 } 238 }
(...skipping 20 matching lines...) Expand all
261 259
262 // If the top level widget can't be found, cancel the popup since we can't 260 // If the top level widget can't be found, cancel the popup since we can't
263 // fully set it up. 261 // fully set it up.
264 if (!observing_widget) 262 if (!observing_widget)
265 return NULL; 263 return NULL;
266 264
267 return new AutofillPopupViewViews(controller, observing_widget); 265 return new AutofillPopupViewViews(controller, observing_widget);
268 } 266 }
269 267
270 } // namespace autofill 268 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/autofill/chrome_autofill_client.cc ('k') | components/autofill/core/browser/autofill_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698