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

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

Issue 2581513002: Replace hard-coded colors from ui::NativeTheme for consistency and accessibility. (Closed)
Patch Set: Delete unused popup_constants.h includes 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"
10 #include "components/autofill/core/browser/popup_item_ids.h" 9 #include "components/autofill/core/browser/popup_item_ids.h"
11 #include "components/autofill/core/browser/suggestion.h" 10 #include "components/autofill/core/browser/suggestion.h"
12 #include "ui/events/keycodes/keyboard_codes.h" 11 #include "ui/events/keycodes/keyboard_codes.h"
13 #include "ui/gfx/canvas.h" 12 #include "ui/gfx/canvas.h"
14 #include "ui/gfx/geometry/point.h" 13 #include "ui/gfx/geometry/point.h"
15 #include "ui/gfx/geometry/rect.h" 14 #include "ui/gfx/geometry/rect.h"
16 #include "ui/gfx/image/image.h" 15 #include "ui/gfx/image/image.h"
17 #include "ui/gfx/native_widget_types.h" 16 #include "ui/gfx/native_widget_types.h"
18 #include "ui/gfx/text_utils.h" 17 #include "ui/gfx/text_utils.h"
19 #include "ui/views/border.h" 18 #include "ui/views/border.h"
(...skipping 21 matching lines...) Expand all
41 } 40 }
42 41
43 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { 42 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() {
44 DoUpdateBoundsAndRedrawPopup(); 43 DoUpdateBoundsAndRedrawPopup();
45 } 44 }
46 45
47 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { 46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) {
48 if (!controller_) 47 if (!controller_)
49 return; 48 return;
50 49
51 canvas->DrawColor(kPopupBackground); 50 canvas->DrawColor(GetNativeTheme()->GetSystemColor(
51 ui::NativeTheme::kColorId_ResultsTableNormalBackground));
52 OnPaintBorder(canvas); 52 OnPaintBorder(canvas);
53 53
54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { 54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i); 55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i);
56 56
57 if (controller_->GetSuggestionAt(i).frontend_id == 57 if (controller_->GetSuggestionAt(i).frontend_id ==
58 POPUP_ITEM_ID_SEPARATOR) { 58 POPUP_ITEM_ID_SEPARATOR) {
59 canvas->FillRect(line_rect, kLabelTextColor); 59 canvas->FillRect(
60 line_rect,
61 GetNativeTheme()->GetSystemColor(
62 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText));
60 } else { 63 } else {
61 DrawAutofillEntry(canvas, i, line_rect); 64 DrawAutofillEntry(canvas, i, line_rect);
62 } 65 }
63 } 66 }
64 } 67 }
65 68
66 void AutofillPopupViewViews::InvalidateRow(size_t row) { 69 void AutofillPopupViewViews::InvalidateRow(size_t row) {
67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row)); 70 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
68 } 71 }
69 72
(...skipping 15 matching lines...) Expand all
85 * ............................................................................ 88 * ............................................................................
86 * 89 *
87 * Anyone who wants to modify the code below, remember to make sure that HTTP 90 * 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 91 * 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 92 * #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. 93 * stored autofill info and check for credit card or password forms.
91 */ 94 */
92 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, 95 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas,
93 int index, 96 int index,
94 const gfx::Rect& entry_rect) { 97 const gfx::Rect& entry_rect) {
95 canvas->FillRect(entry_rect, controller_->GetBackgroundColorForRow(index)); 98 canvas->FillRect(entry_rect,
99 GetNativeTheme()->GetSystemColor(
100 controller_->GetBackgroundColorForRow(index)));
96 101
97 const bool is_http_warning = 102 const bool is_http_warning =
98 (controller_->GetSuggestionAt(index).frontend_id == 103 (controller_->GetSuggestionAt(index).frontend_id ==
99 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); 104 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
100 const bool is_rtl = controller_->IsRTL(); 105 const bool is_rtl = controller_->IsRTL();
101 const int text_align = 106 const int text_align =
102 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; 107 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
103 gfx::Rect value_rect = entry_rect; 108 gfx::Rect value_rect = entry_rect;
104 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); 109 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0);
105 110
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (is_http_warning) { 148 if (is_http_warning) {
144 value_x_align_left += is_rtl ? -value_width : 0; 149 value_x_align_left += is_rtl ? -value_width : 0;
145 } else { 150 } else {
146 value_x_align_left = 151 value_x_align_left =
147 is_rtl ? value_rect.right() - value_width : value_rect.x(); 152 is_rtl ? value_rect.right() - value_width : value_rect.x();
148 } 153 }
149 154
150 canvas->DrawStringRectWithFlags( 155 canvas->DrawStringRectWithFlags(
151 controller_->GetElidedValueAt(index), 156 controller_->GetElidedValueAt(index),
152 controller_->layout_model().GetValueFontListForRow(index), 157 controller_->layout_model().GetValueFontListForRow(index),
153 controller_->layout_model().GetValueFontColorForRow(index), 158 GetNativeTheme()->GetSystemColor(
159 controller_->layout_model().GetValueFontColorForRow(index)),
154 gfx::Rect(value_x_align_left, value_rect.y(), value_width, 160 gfx::Rect(value_x_align_left, value_rect.y(), value_width,
155 value_rect.height()), 161 value_rect.height()),
156 text_align); 162 text_align);
157 163
158 // Draw the label text, if one exists. 164 // Draw the label text, if one exists.
159 if (!controller_->GetSuggestionAt(index).label.empty()) { 165 if (!controller_->GetSuggestionAt(index).label.empty()) {
160 const int label_width = gfx::GetStringWidth( 166 const int label_width = gfx::GetStringWidth(
161 controller_->GetElidedLabelAt(index), 167 controller_->GetElidedLabelAt(index),
162 controller_->layout_model().GetLabelFontListForRow(index)); 168 controller_->layout_model().GetLabelFontListForRow(index));
163 int label_x_align_left = x_align_left; 169 int label_x_align_left = x_align_left;
164 170
165 if (is_http_warning) { 171 if (is_http_warning) {
166 label_x_align_left = 172 label_x_align_left =
167 is_rtl ? value_rect.x() : value_rect.right() - label_width; 173 is_rtl ? value_rect.x() : value_rect.right() - label_width;
168 } else { 174 } else {
169 label_x_align_left += is_rtl ? 0 : -label_width; 175 label_x_align_left += is_rtl ? 0 : -label_width;
170 } 176 }
171 177
172 canvas->DrawStringRectWithFlags( 178 canvas->DrawStringRectWithFlags(
173 controller_->GetElidedLabelAt(index), 179 controller_->GetElidedLabelAt(index),
174 controller_->layout_model().GetLabelFontListForRow(index), 180 controller_->layout_model().GetLabelFontListForRow(index),
175 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), 181 GetNativeTheme()->GetSystemColor(
Mathieu 2016/12/20 20:36:40 Should we have a TODO to have a GetLabelFontColorF
jiahuiguo 2017/01/03 19:37:52 Done, added TODO in https://crbug.com/678033
Mathieu 2017/01/04 13:51:48 Please reference in code as // TODO(crbug.com/6780
jiahuiguo 2017/01/05 19:21:20 Done.
182 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
183 gfx::Rect(label_x_align_left, entry_rect.y(),
176 label_width, entry_rect.height()), 184 label_width, entry_rect.height()),
177 text_align); 185 text_align);
178 } 186 }
179 } 187 }
180 188
181 AutofillPopupView* AutofillPopupView::Create( 189 AutofillPopupView* AutofillPopupView::Create(
182 AutofillPopupController* controller) { 190 AutofillPopupController* controller) {
183 views::Widget* observing_widget = 191 views::Widget* observing_widget =
184 views::Widget::GetTopLevelWidgetForNativeView( 192 views::Widget::GetTopLevelWidgetForNativeView(
185 controller->container_view()); 193 controller->container_view());
186 194
187 // If the top level widget can't be found, cancel the popup since we can't 195 // If the top level widget can't be found, cancel the popup since we can't
188 // fully set it up. 196 // fully set it up.
189 if (!observing_widget) 197 if (!observing_widget)
190 return NULL; 198 return NULL;
191 199
192 return new AutofillPopupViewViews(controller, observing_widget); 200 return new AutofillPopupViewViews(controller, observing_widget);
193 } 201 }
194 202
195 } // namespace autofill 203 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698