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

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: Using NativeTheme::GetInstanceForNativeUi() to get NativeThemeMac instance Created 3 years, 11 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 "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(
99 entry_rect,
100 GetNativeTheme()->GetSystemColor(
101 controller_->GetBackgroundColorIDForRow(index)));
96 102
97 const bool is_http_warning = 103 const bool is_http_warning =
98 (controller_->GetSuggestionAt(index).frontend_id == 104 (controller_->GetSuggestionAt(index).frontend_id ==
99 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE); 105 POPUP_ITEM_ID_HTTP_NOT_SECURE_WARNING_MESSAGE);
100 const bool is_rtl = controller_->IsRTL(); 106 const bool is_rtl = controller_->IsRTL();
101 const int text_align = 107 const int text_align =
102 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; 108 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
103 gfx::Rect value_rect = entry_rect; 109 gfx::Rect value_rect = entry_rect;
104 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0); 110 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0);
105 111
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
143 if (is_http_warning) { 149 if (is_http_warning) {
144 value_x_align_left += is_rtl ? -value_width : 0; 150 value_x_align_left += is_rtl ? -value_width : 0;
145 } else { 151 } else {
146 value_x_align_left = 152 value_x_align_left =
147 is_rtl ? value_rect.right() - value_width : value_rect.x(); 153 is_rtl ? value_rect.right() - value_width : value_rect.x();
148 } 154 }
149 155
150 canvas->DrawStringRectWithFlags( 156 canvas->DrawStringRectWithFlags(
151 controller_->GetElidedValueAt(index), 157 controller_->GetElidedValueAt(index),
152 controller_->layout_model().GetValueFontListForRow(index), 158 controller_->layout_model().GetValueFontListForRow(index),
153 controller_->layout_model().GetValueFontColorForRow(index), 159 GetNativeTheme()->GetSystemColor(
160 controller_->layout_model().GetValueFontColorIDForRow(index)),
154 gfx::Rect(value_x_align_left, value_rect.y(), value_width, 161 gfx::Rect(value_x_align_left, value_rect.y(), value_width,
155 value_rect.height()), 162 value_rect.height()),
156 text_align); 163 text_align);
157 164
158 // Draw the label text, if one exists. 165 // Draw the label text, if one exists.
159 if (!controller_->GetSuggestionAt(index).label.empty()) { 166 if (!controller_->GetSuggestionAt(index).label.empty()) {
160 const int label_width = gfx::GetStringWidth( 167 const int label_width = gfx::GetStringWidth(
161 controller_->GetElidedLabelAt(index), 168 controller_->GetElidedLabelAt(index),
162 controller_->layout_model().GetLabelFontListForRow(index)); 169 controller_->layout_model().GetLabelFontListForRow(index));
163 int label_x_align_left = x_align_left; 170 int label_x_align_left = x_align_left;
164 171
165 if (is_http_warning) { 172 if (is_http_warning) {
166 label_x_align_left = 173 label_x_align_left =
167 is_rtl ? value_rect.x() : value_rect.right() - label_width; 174 is_rtl ? value_rect.x() : value_rect.right() - label_width;
168 } else { 175 } else {
169 label_x_align_left += is_rtl ? 0 : -label_width; 176 label_x_align_left += is_rtl ? 0 : -label_width;
170 } 177 }
171 178
172 canvas->DrawStringRectWithFlags( 179 canvas->DrawStringRectWithFlags(
173 controller_->GetElidedLabelAt(index), 180 controller_->GetElidedLabelAt(index),
174 controller_->layout_model().GetLabelFontListForRow(index), 181 controller_->layout_model().GetLabelFontListForRow(index),
175 kLabelTextColor, gfx::Rect(label_x_align_left, entry_rect.y(), 182 GetNativeTheme()->GetSystemColor(
183 ui::NativeTheme::kColorId_ResultsTableNormalDimmedText),
184 gfx::Rect(label_x_align_left, entry_rect.y(),
176 label_width, entry_rect.height()), 185 label_width, entry_rect.height()),
177 text_align); 186 text_align);
178 } 187 }
179 } 188 }
180 189
181 AutofillPopupView* AutofillPopupView::Create( 190 AutofillPopupView* AutofillPopupView::Create(
182 AutofillPopupController* controller) { 191 AutofillPopupController* controller) {
183 views::Widget* observing_widget = 192 views::Widget* observing_widget =
184 views::Widget::GetTopLevelWidgetForNativeView( 193 views::Widget::GetTopLevelWidgetForNativeView(
185 controller->container_view()); 194 controller->container_view());
186 195
187 // If the top level widget can't be found, cancel the popup since we can't 196 // If the top level widget can't be found, cancel the popup since we can't
188 // fully set it up. 197 // fully set it up.
189 if (!observing_widget) 198 if (!observing_widget)
190 return NULL; 199 return NULL;
191 200
192 return new AutofillPopupViewViews(controller, observing_widget); 201 return new AutofillPopupViewViews(controller, observing_widget);
193 } 202 }
194 203
195 } // namespace autofill 204 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698