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

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

Issue 1570783003: [Autofill] Move functions from the AutofillPopupController to AutofillPopupLayoutModel (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: addressed nit Created 4 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 "components/autofill/core/browser/popup_item_ids.h" 9 #include "components/autofill/core/browser/popup_item_ids.h"
9 #include "components/autofill/core/browser/suggestion.h" 10 #include "components/autofill/core/browser/suggestion.h"
10 #include "ui/base/resource/resource_bundle.h" 11 #include "ui/base/resource/resource_bundle.h"
11 #include "ui/events/keycodes/keyboard_codes.h" 12 #include "ui/events/keycodes/keyboard_codes.h"
12 #include "ui/gfx/canvas.h" 13 #include "ui/gfx/canvas.h"
13 #include "ui/gfx/geometry/point.h" 14 #include "ui/gfx/geometry/point.h"
14 #include "ui/gfx/geometry/rect.h" 15 #include "ui/gfx/geometry/rect.h"
15 #include "ui/gfx/image/image.h" 16 #include "ui/gfx/image/image.h"
16 #include "ui/gfx/native_widget_types.h" 17 #include "ui/gfx/native_widget_types.h"
17 #include "ui/gfx/text_utils.h" 18 #include "ui/gfx/text_utils.h"
(...skipping 26 matching lines...) Expand all
44 } 45 }
45 46
46 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { 47 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) {
47 if (!controller_) 48 if (!controller_)
48 return; 49 return;
49 50
50 canvas->DrawColor(kPopupBackground); 51 canvas->DrawColor(kPopupBackground);
51 OnPaintBorder(canvas); 52 OnPaintBorder(canvas);
52 53
53 for (size_t i = 0; i < controller_->GetLineCount(); ++i) { 54 for (size_t i = 0; i < controller_->GetLineCount(); ++i) {
54 gfx::Rect line_rect = controller_->GetRowBounds(i); 55 gfx::Rect line_rect = controller_->layout_model().GetRowBounds(i);
55 56
56 if (controller_->GetSuggestionAt(i).frontend_id == 57 if (controller_->GetSuggestionAt(i).frontend_id ==
57 POPUP_ITEM_ID_SEPARATOR) { 58 POPUP_ITEM_ID_SEPARATOR) {
58 canvas->FillRect(line_rect, kItemTextColor); 59 canvas->FillRect(line_rect, kItemTextColor);
59 } else { 60 } else {
60 DrawAutofillEntry(canvas, i, line_rect); 61 DrawAutofillEntry(canvas, i, line_rect);
61 } 62 }
62 } 63 }
63 } 64 }
64 65
65 void AutofillPopupViewViews::InvalidateRow(size_t row) { 66 void AutofillPopupViewViews::InvalidateRow(size_t row) {
66 SchedulePaintInRect(controller_->GetRowBounds(row)); 67 SchedulePaintInRect(controller_->layout_model().GetRowBounds(row));
67 } 68 }
68 69
69 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, 70 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas,
70 int index, 71 int index,
71 const gfx::Rect& entry_rect) { 72 const gfx::Rect& entry_rect) {
72 if (controller_->selected_line() == index) 73 if (controller_->selected_line() == index)
73 canvas->FillRect(entry_rect, kHoveredBackgroundColor); 74 canvas->FillRect(entry_rect, kHoveredBackgroundColor);
74 75
75 const bool is_rtl = controller_->IsRTL(); 76 const bool is_rtl = controller_->IsRTL();
76 const int text_align = 77 const int text_align =
77 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT; 78 is_rtl ? gfx::Canvas::TEXT_ALIGN_RIGHT : gfx::Canvas::TEXT_ALIGN_LEFT;
78 gfx::Rect value_rect = entry_rect; 79 gfx::Rect value_rect = entry_rect;
79 value_rect.Inset(kEndPadding, 0); 80 value_rect.Inset(AutofillPopupLayoutModel::kEndPadding, 0);
80 canvas->DrawStringRectWithFlags( 81 canvas->DrawStringRectWithFlags(
81 controller_->GetElidedValueAt(index), 82 controller_->GetElidedValueAt(index),
82 controller_->GetValueFontListForRow(index), 83 controller_->GetValueFontListForRow(index),
83 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor, 84 controller_->IsWarning(index) ? kWarningTextColor : kValueTextColor,
84 value_rect, text_align); 85 value_rect, text_align);
85 86
86 // Use this to figure out where all the other Autofill items should be placed. 87 // Use this to figure out where all the other Autofill items should be placed.
87 int x_align_left = is_rtl ? kEndPadding : entry_rect.right() - kEndPadding; 88 int x_align_left =
89 is_rtl ? AutofillPopupLayoutModel::kEndPadding
90 : entry_rect.right() - AutofillPopupLayoutModel::kEndPadding;
88 91
89 // Draw the Autofill icon, if one exists 92 // Draw the Autofill icon, if one exists
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 93 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
91 int row_height = controller_->GetRowBounds(index).height(); 94 int row_height = controller_->layout_model().GetRowBounds(index).height();
92 if (!controller_->GetSuggestionAt(index).icon.empty()) { 95 if (!controller_->GetSuggestionAt(index).icon.empty()) {
93 int icon = controller_->GetIconResourceID( 96 int icon = controller_->layout_model().GetIconResourceID(
94 controller_->GetSuggestionAt(index).icon); 97 controller_->GetSuggestionAt(index).icon);
95 DCHECK_NE(-1, icon); 98 DCHECK_NE(-1, icon);
96 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon); 99 const gfx::ImageSkia* image = rb.GetImageSkiaNamed(icon);
97 int icon_y = entry_rect.y() + (row_height - image->height()) / 2; 100 int icon_y = entry_rect.y() + (row_height - image->height()) / 2;
98 101
99 x_align_left += is_rtl ? 0 : -image->width(); 102 x_align_left += is_rtl ? 0 : -image->width();
100 103
101 canvas->DrawImageInt(*image, x_align_left, icon_y); 104 canvas->DrawImageInt(*image, x_align_left, icon_y);
102 105
103 x_align_left += is_rtl ? image->width() + kIconPadding : -kIconPadding; 106 x_align_left +=
107 is_rtl ? image->width() + AutofillPopupLayoutModel::kIconPadding
108 : -AutofillPopupLayoutModel::kIconPadding;
104 } 109 }
105 110
106 // Draw the label text. 111 // Draw the label text.
107 const int label_width = 112 const int label_width =
108 gfx::GetStringWidth(controller_->GetElidedLabelAt(index), 113 gfx::GetStringWidth(controller_->GetElidedLabelAt(index),
109 controller_->GetLabelFontList()); 114 controller_->GetLabelFontList());
110 if (!is_rtl) 115 if (!is_rtl)
111 x_align_left -= label_width; 116 x_align_left -= label_width;
112 117
113 canvas->DrawStringRectWithFlags( 118 canvas->DrawStringRectWithFlags(
(...skipping 11 matching lines...) Expand all
125 130
126 // If the top level widget can't be found, cancel the popup since we can't 131 // If the top level widget can't be found, cancel the popup since we can't
127 // fully set it up. 132 // fully set it up.
128 if (!observing_widget) 133 if (!observing_widget)
129 return NULL; 134 return NULL;
130 135
131 return new AutofillPopupViewViews(controller, observing_widget); 136 return new AutofillPopupViewViews(controller, observing_widget);
132 } 137 }
133 138
134 } // namespace autofill 139 } // namespace autofill
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/autofill/autofill_popup_view_views.h ('k') | chrome/chrome_browser_ui.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698