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

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 comments Created 4 years 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 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } else { 60 } else {
61 DrawAutofillEntry(canvas, i, line_rect); 61 DrawAutofillEntry(canvas, i, line_rect);
62 } 62 }
63 } 63 }
64 } 64 }
65 65
66 void AutofillPopupViewViews::InvalidateRow(size_t row) { 66 void AutofillPopupViewViews::InvalidateRow(size_t row) {
67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); 67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
68 } 68 }
69 69
70 /**
71 * Autofill entries in ltr.
72 *
73 * ............................................................................
74 * . ICON | HTTP WARNING MESSAGE VALUE | LABEL .
75 * ............................................................................
76 * . OTHER AUTOFILL ENTRY VALUE | LABEL | ICON .
77 * ............................................................................
78 *
79 * Autofill entries in rtl.
80 *
81 * ............................................................................
82 * . LABEL | HTTP WARNING MESSAGE VALUE | ICON .
83 * ............................................................................
84 * . ICON | LABEL | OTHER AUTOFILL ENTRY VALUE .
85 * ............................................................................
86 *
87 * Anyone who wants to modify the code below, remember to make sure that HTTP
88 * warning entry displays right. To trigger the warning message entry, enable
89 * #mark-non-secure-as flag as "display form warning", go to goo.gl/CEIjc6 with
90 * stored autofill info and check for credit card or password forms.
91 */
70 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, 92 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas,
71 int index, 93 int index,
72 const gfx::Rect& entry_rect) { 94 const gfx::Rect& entry_rect) {
73 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); 95 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index));
74 96
97 const bool is_http_warning =
98 (controller_->GetSuggestionAt(index).frontend_id ==
99 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
75 const bool is_rtl = controller_->IsRTL(); 100 const bool is_rtl = controller_->IsRTL();
76 const int text_align = 101 const int text_align =
77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; 102 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
78 gfx::Rect value_rect = entry_rect; 103 gfx::Rect value_rect = entry_rect;
79 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); 104 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0);
80 canvas->DrawStringRectWithFlags(
81 controller_->GetElidedValueAt(index),
82 controller_->layout_model().GetValueFontListForRow(index),
83 controller_->layout_model().GetValueFontColorForRow(index), value_rect,
84 text_align);
85 105
86 // Use this to figure out where all the other Autofill items should be placed. 106 int icon_x_align_left = 0;
87 int x_align_left = 107 if ((is_http_warning && !is_rtl) || (!is_http_warning && is_rtl))
Evan Stade 2016/11/29 15:43:17 nit: is_http_warning != is_rtl
lshang 2016/11/30 05:43:36 Done.
88 is_rtl ? AutofillPopupLayoutModel::kEndPadding 108 icon_x_align_left = value_rect.x();
89 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding; 109 else
110 icon_x_align_left = value_rect.right();
90 111
91 // Draw the Autofill icon, if one exists 112 // Draw the Autofill icon, if one exists
92 int row_height = controller_->layout_model().GetRowBounds(index).height(); 113 int row_height = controller_->layout_model().GetRowBounds(index).height();
93 if (!controller_->GetSuggestionAt(index).icon.empty()) { 114 if (!controller_->GetSuggestionAt(index).icon.empty()) {
94 const gfx::ImageSkia image = 115 const gfx::ImageSkia image =
95 controller_->layout_model().GetIconImage(index); 116 controller_->layout_model().GetIconImage(index);
96 int icon_y = entry_rect.y() + (row_height - image.height()) / 2; 117 int icon_y = entry_rect.y() + (row_height - image.height()) / 2;
97 118
98 x_align_left += is_rtl ? 0 : -image.width(); 119 if (icon_x_align_left == value_rect.right())
Evan Stade 2016/11/29 15:43:17 nit: can you save the result of the directionality
lshang 2016/11/30 05:43:36 Done.
120 icon_x_align_left -= image.width();
99 121
100 canvas->DrawImageInt(image, x_align_left, icon_y); 122 canvas->DrawImageInt(image, icon_x_align_left, icon_y);
101 123
102 x_align_left += is_rtl 124 // An icon was drawn; adjust the |icon_x_align_start| value for the next
103 ? image.width() + AutofillPopupLayoutModel::kIconPadding 125 // element.
104 : -AutofillPopupLayoutModel::kIconPadding; 126 if (is_http_warning) {
127 icon_x_align_left +=
Evan Stade 2016/11/29 15:43:17 after this statement, this variable no longer real
lshang 2016/11/30 05:43:36 Done.
128 is_rtl ? -AutofillPopupLayoutModel::kHttpWarningIconPadding
129 : image.width() +
130 AutofillPopupLayoutModel::kHttpWarningIconPadding;
131 } else {
132 icon_x_align_left +=
133 is_rtl ? image.width() + AutofillPopupLayoutModel::kIconPadding
134 : -AutofillPopupLayoutModel::kIconPadding;
135 }
105 } 136 }
106 137
107 // Draw the label text. 138 // Draw the value text
108 const int label_width = 139 const int value_width = gfx::GetStringWidth(
109 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), 140 controller_->GetElidedValueAt(index),
110 controller_->layout_model().GetLabelFontList()); 141 controller_->layout_model().GetValueFontListForRow(index));
111 if (!is_rtl) 142 int value_x_align_left = icon_x_align_left;
112 x_align_left -= label_width; 143
144 if (is_http_warning) {
145 value_x_align_left += is_rtl ? -value_width : 0;
146 } else {
147 value_x_align_left =
148 is_rtl ? value_rect.right() - value_width : value_rect.x();
149 }
113 150
114 canvas->DrawStringRectWithFlags( 151 canvas->DrawStringRectWithFlags(
115 controller_->GetElidedLabelAt(index), 152 controller_->GetElidedValueAt(index),
116 controller_->layout_model().GetLabelFontList(), kLabelTextColor, 153 controller_->layout_model().GetValueFontListForRow(index),
117 gfx::Rect(x_align_left, entry_rect.y(), label_width, entry_rect.height()), 154 controller_->layout_model().GetValueFontColorForRow(index),
155 gfx::Rect(value_x_align_left, value_rect.y(), value_width,
156 value_rect.height()),
118 text_align); 157 text_align);
158
159 // Draw the label text, if one exists.
160 if (!controller_->GetSuggestionAt(index).label.empty()) {
161 const int label_width = gfx::GetStringWidth(
162 controller_->GetElidedLabelAt(index),
163 controller_->layout_model().GetLabelFontListForRow(index));
164 int label_x_align_left = icon_x_align_left;
165
166 if (is_http_warning) {
167 label_x_align_left =
168 is_rtl ? value_rect.x() : value_rect.right() - label_width;
169 } else {
170 label_x_align_left += is_rtl ? 0 : -label_width;
171 }
172
173 canvas->DrawStringRectWithFlags(
174 controller_->GetElidedLabelAt(index),
175 controller_->layout_model().GetLabelFontListForRow(index),
176 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(),
177 label_width, entry_rect.height()),
178 text_align);
179 }
119 } 180 }
120 181
121 AutofillPopupView* AutofillPopupView::Create( 182 AutofillPopupView* AutofillPopupView::Create(
122 AutofillPopupController* controller) { 183 AutofillPopupController* controller) {
123 views::Widget* observing_widget = 184 views::Widget* observing_widget =
124 views::Widget::GetTopLevelWidgetForNativeView( 185 views::Widget::GetTopLevelWidgetForNativeView(
125 controller->container_view()); 186 controller->container_view());
126 187
127 // If the top level widget can't be found, cancel the popup since we can't 188 // If the top level widget can't be found, cancel the popup since we can't
128 // fully set it up. 189 // fully set it up.
129 if (!observing_widget) 190 if (!observing_widget)
130 return NULL; 191 return NULL;
131 192
132 return new AutofillPopupViewViews(controller, observing_widget); 193 return new AutofillPopupViewViews(controller, observing_widget);
133 } 194 }
134 195
135 } // namespace autofill 196 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698