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

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

Issue 2517843002: Http Bad: Put icon on the left of http warning message on Views (Closed)
Patch Set: add test Created 4 years, 1 month 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 "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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 51
52 canvas->DrawColor(kPopupBackground); 52 canvas->DrawColor(kPopupBackground);
53 OnPaintBorder(canvas); 53 OnPaintBorder(canvas);
54 54
55 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { 55 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
56 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); 56 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i);
57 57
58 if (controller_->GetSuggestionAt(i).frontend_id == 58 if (controller_->GetSuggestionAt(i).frontend_id ==
59 POPUP_ITEM_ID_SEPARATOR) { 59 POPUP_ITEM_ID_SEPARATOR) {
60 canvas->FillRect(line_rect, kLabelTextColor); 60 canvas->FillRect(line_rect, kLabelTextColor);
61 } else if (controller_->GetSuggestionAt(i).frontend_id ==
62 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE) {
63 DrawAutofillHttpWarningEntry(canvas, i, line_rect);
61 } else { 64 } else {
62 DrawAutofillEntry(canvas, i, line_rect); 65 DrawAutofillEntry(canvas, i, line_rect);
63 } 66 }
64 } 67 }
65 } 68 }
66 69
67 void AutofillPopupViewViews::InvalidateRow(size_t row) { 70 void AutofillPopupViewViews::InvalidateRow(size_t row) {
68 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); 71 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
69 } 72 }
70 73
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
102 x_align_left += is_rtl ? 0 : -image->width(); 105 x_align_left += is_rtl ? 0 : -image->width();
103 106
104 canvas->DrawImageInt(*image, x_align_left, icon_y); 107 canvas->DrawImageInt(*image, x_align_left, icon_y);
105 108
106 x_align_left += 109 x_align_left +=
107 is_rtl ? image->width() + AutofillPopupLayoutModel::kIconPadding 110 is_rtl ? image->width() + AutofillPopupLayoutModel::kIconPadding
108 : -AutofillPopupLayoutModel::kIconPadding; 111 : -AutofillPopupLayoutModel::kIconPadding;
109 } 112 }
110 113
111 // Draw the label text. 114 // Draw the label text.
112 const int label_width = 115 const int label_width = gfx::GetStringWidth(
113 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), 116 controller_->GetElidedLabelAt(index),
114 controller_->layout_model().GetLabelFontList()); 117 controller_->layout_model().GetLabelFontListForRow(index));
115 if (!is_rtl) 118 if (!is_rtl)
116 x_align_left -= label_width; 119 x_align_left -= label_width;
117
118 canvas->DrawStringRectWithFlags( 120 canvas->DrawStringRectWithFlags(
119 controller_->GetElidedLabelAt(index), 121 controller_->GetElidedLabelAt(index),
120 controller_->layout_model().GetLabelFontList(), kLabelTextColor, 122 controller_->layout_model().GetLabelFontListForRow(index),
123 kLabelTextColor,
121 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), 124 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()),
122 text_align); 125 text_align);
123 } 126 }
124 127
128 void AutofillPopupViewViews::DrawAutofillHttpWarningEntry(
Mathieu 2016/11/22 14:36:45 While I do like a clean separation and appreciate
lshang 2016/11/27 04:59:13 Done. Drawing the ASCII art is interesting.
129 gfx::Canvas* canvas,
130 int index,
131 const gfx::Rect& entry_rect) {
132 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index));
133
134 const bool is_rtl = controller_->IsRTL();
135 const int text_align =
136 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
137 gfx::Rect value_rect = entry_rect;
138 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0);
139
140 int x_align_left = is_rtl ? value_rect.right() : value_rect.x();
141
142 // Draw the Autofill icon, if one exists
143 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
144 int row_height = controller_->layout_model().GetRowBounds(index).height();
145 if (!controller_->GetSuggestionAt(index).icon.empty()) {
146 int icon = controller_->layout_model().GetIconResourceID(
147 controller_->GetSuggestionAt(index).icon);
148 DCHECK_NE(-1, icon);
149 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon);
150 int icon_y = entry_rect.y() + (row_height - image->height()) / 2;
151
152 x_align_left += is_rtl ? -image->width() : 0;
153
154 canvas->DrawImageInt(*image, value_rect.x(), icon_y);
155
156 // Use this to figure out where all the other Autofill items should be
157 // placed.
158 x_align_left += is_rtl
159 ? -AutofillPopupLayoutModel::kHttpWarningIconPadding
160 : image->width() +
161 AutofillPopupLayoutModel::kHttpWarningIconPadding;
162 }
163
164 // Draw the value text.
165 const int value_width = gfx::GetStringWidth(
166 controller_->GetElidedValueAt(index),
167 controller_->layout_model().GetValueFontListForRow(index));
168 if (is_rtl)
169 x_align_left -= value_width;
170 canvas->DrawStringRectWithFlags(
171 controller_->GetElidedValueAt(index),
172 controller_->layout_model().GetValueFontListForRow(index),
173 controller_->layout_model().GetValueFontColorForRow(index),
174 gfx::Rect(x_align_left, value_rect.y(), value_width, value_rect.height()),
175 text_align);
176
177 // Draw the label text, if one exists.
178 if (!controller_->GetSuggestionAt(index).label.empty()) {
Mathieu 2016/11/22 14:36:45 you can add this if condition in the main DrawAuto
lshang 2016/11/27 04:59:13 Done.
179 const int label_width = gfx::GetStringWidth(
180 controller_->GetElidedLabelAt(index),
181 controller_->layout_model().GetLabelFontListForRow(index));
182
183 x_align_left = is_rtl ? value_rect.x() : value_rect.right() - label_width;
184
185 canvas->DrawStringRectWithFlags(
186 controller_->GetElidedLabelAt(index),
187 controller_->layout_model().GetLabelFontListForRow(index),
188 kLabelTextColor, gfx::Rect(x_align_left, value_rect.y(), label_width,
189 value_rect.height()),
190 text_align);
191 }
192 }
193
125 AutofillPopupView* AutofillPopupView::Create( 194 AutofillPopupView* AutofillPopupView::Create(
126 AutofillPopupController* controller) { 195 AutofillPopupController* controller) {
127 views::Widget* observing_widget = 196 views::Widget* observing_widget =
128 views::Widget::GetTopLevelWidgetForNativeView( 197 views::Widget::GetTopLevelWidgetForNativeView(
129 controller->container_view()); 198 controller->container_view());
130 199
131 // If the top level widget can't be found, cancel the popup since we can't 200 // If the top level widget can't be found, cancel the popup since we can't
132 // fully set it up. 201 // fully set it up.
133 if (!observing_widget) 202 if (!observing_widget)
134 return NULL; 203 return NULL;
135 204
136 return new AutofillPopupViewViews(controller, observing_widget); 205 return new AutofillPopupViewViews(controller, observing_widget);
137 } 206 }
138 207
139 } // namespace autofill 208 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698