OLD | NEW |
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 "grit/ui_resources.h" | 8 #include "grit/ui_resources.h" |
9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" | 9 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h" |
10 #include "ui/base/keycodes/keyboard_codes.h" | 10 #include "ui/base/keycodes/keyboard_codes.h" |
11 #include "ui/base/resource/resource_bundle.h" | 11 #include "ui/base/resource/resource_bundle.h" |
12 #include "ui/gfx/canvas.h" | 12 #include "ui/gfx/canvas.h" |
13 #include "ui/gfx/display.h" | 13 #include "ui/gfx/display.h" |
14 #include "ui/gfx/image/image.h" | 14 #include "ui/gfx/image/image.h" |
15 #include "ui/gfx/point.h" | 15 #include "ui/gfx/point.h" |
16 #include "ui/gfx/rect.h" | 16 #include "ui/gfx/rect.h" |
17 #include "ui/gfx/screen.h" | 17 #include "ui/gfx/screen.h" |
18 #include "ui/views/border.h" | 18 #include "ui/views/border.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 using WebKit::WebAutofillClient; | 21 using WebKit::WebAutofillClient; |
22 | 22 |
23 namespace { | 23 namespace { |
24 | 24 |
25 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); | 25 const SkColor kBorderColor = SkColorSetARGB(0xFF, 0xC7, 0xCA, 0xCE); |
26 const SkColor kHoveredBackgroundColor = SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); | 26 const SkColor kHoveredBackgroundColor = SkColorSetARGB(0xFF, 0xCD, 0xCD, 0xCD); |
27 const SkColor kLabelTextColor = SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); | 27 const SkColor kItemTextColor = SkColorSetARGB(0xFF, 0x7F, 0x7F, 0x7F); |
28 const SkColor kPopupBackground = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); | 28 const SkColor kPopupBackground = SkColorSetARGB(0xFF, 0xFF, 0xFF, 0xFF); |
29 const SkColor kValueTextColor = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); | 29 const SkColor kValueTextColor = SkColorSetARGB(0xFF, 0x00, 0x00, 0x00); |
30 | 30 |
31 } // namespace | 31 } // namespace |
32 | 32 |
33 AutofillPopupViewViews::AutofillPopupViewViews( | 33 AutofillPopupViewViews::AutofillPopupViewViews( |
34 AutofillPopupController* controller) | 34 AutofillPopupController* controller) |
35 : controller_(controller), | 35 : controller_(controller), |
36 observing_widget_(NULL) {} | 36 observing_widget_(NULL) {} |
37 | 37 |
(...skipping 10 matching lines...) Expand all Loading... |
48 GetWidget()->Close(); | 48 GetWidget()->Close(); |
49 } else { | 49 } else { |
50 delete this; | 50 delete this; |
51 } | 51 } |
52 } | 52 } |
53 | 53 |
54 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { | 54 void AutofillPopupViewViews::OnPaint(gfx::Canvas* canvas) { |
55 canvas->DrawColor(kPopupBackground); | 55 canvas->DrawColor(kPopupBackground); |
56 OnPaintBorder(canvas); | 56 OnPaintBorder(canvas); |
57 | 57 |
58 for (size_t i = 0; i < controller_->autofill_values().size(); ++i) { | 58 for (size_t i = 0; i < controller_->names().size(); ++i) { |
59 gfx::Rect line_rect = controller_->GetRectForRow(i, width()); | 59 gfx::Rect line_rect = controller_->GetRowBounds(i); |
60 | 60 |
61 if (controller_->autofill_unique_ids()[i] == | 61 if (controller_->identifiers()[i] == |
62 WebAutofillClient::MenuItemIDSeparator) { | 62 WebAutofillClient::MenuItemIDSeparator) { |
63 canvas->DrawRect(line_rect, kLabelTextColor); | 63 canvas->DrawRect(line_rect, kItemTextColor); |
64 } else { | 64 } else { |
65 DrawAutofillEntry(canvas, i, line_rect); | 65 DrawAutofillEntry(canvas, i, line_rect); |
66 } | 66 } |
67 } | 67 } |
68 } | 68 } |
69 | 69 |
70 void AutofillPopupViewViews::OnMouseCaptureLost() { | 70 void AutofillPopupViewViews::OnMouseCaptureLost() { |
71 controller_->ClearSelectedLine(); | 71 controller_->MouseExitedPopup(); |
72 } | 72 } |
73 | 73 |
74 bool AutofillPopupViewViews::OnMouseDragged(const ui::MouseEvent& event) { | 74 bool AutofillPopupViewViews::OnMouseDragged(const ui::MouseEvent& event) { |
75 if (HitTestPoint(gfx::Point(event.x(), event.y()))) { | 75 if (HitTestPoint(gfx::Point(event.x(), event.y()))) { |
76 controller_->SetSelectedPosition(event.x(), event.y()); | 76 controller_->MouseHovered(event.x(), event.y()); |
77 | 77 |
78 // We must return true in order to get future OnMouseDragged and | 78 // We must return true in order to get future OnMouseDragged and |
79 // OnMouseReleased events. | 79 // OnMouseReleased events. |
80 return true; | 80 return true; |
81 } | 81 } |
82 | 82 |
83 // If we move off of the popup, we lose the selection. | 83 // If we move off of the popup, we lose the selection. |
84 controller_->ClearSelectedLine(); | 84 controller_->MouseExitedPopup(); |
85 return false; | 85 return false; |
86 } | 86 } |
87 | 87 |
88 void AutofillPopupViewViews::OnMouseExited(const ui::MouseEvent& event) { | 88 void AutofillPopupViewViews::OnMouseExited(const ui::MouseEvent& event) { |
89 controller_->ClearSelectedLine(); | 89 controller_->MouseExitedPopup(); |
90 } | 90 } |
91 | 91 |
92 void AutofillPopupViewViews::OnMouseMoved(const ui::MouseEvent& event) { | 92 void AutofillPopupViewViews::OnMouseMoved(const ui::MouseEvent& event) { |
93 controller_->SetSelectedPosition(event.x(), event.y()); | 93 controller_->MouseHovered(event.x(), event.y()); |
94 } | 94 } |
95 | 95 |
96 bool AutofillPopupViewViews::OnMousePressed(const ui::MouseEvent& event) { | 96 bool AutofillPopupViewViews::OnMousePressed(const ui::MouseEvent& event) { |
97 // We must return true in order to get the OnMouseReleased event later. | 97 // We must return true in order to get the OnMouseReleased event later. |
98 return true; | 98 return true; |
99 } | 99 } |
100 | 100 |
101 void AutofillPopupViewViews::OnMouseReleased(const ui::MouseEvent& event) { | 101 void AutofillPopupViewViews::OnMouseReleased(const ui::MouseEvent& event) { |
102 // We only care about the left click. | 102 // We only care about the left click. |
103 if (event.IsOnlyLeftMouseButton() && | 103 if (event.IsOnlyLeftMouseButton() && |
104 HitTestPoint(gfx::Point(event.x(), event.y()))) | 104 HitTestPoint(gfx::Point(event.x(), event.y()))) |
105 controller_->AcceptSelectedPosition(event.x(), event.y()); | 105 controller_->MouseClicked(event.x(), event.y()); |
106 } | 106 } |
107 | 107 |
108 void AutofillPopupViewViews::OnWidgetBoundsChanged( | 108 void AutofillPopupViewViews::OnWidgetBoundsChanged( |
109 views::Widget* widget, | 109 views::Widget* widget, |
110 const gfx::Rect& new_bounds) { | 110 const gfx::Rect& new_bounds) { |
111 Hide(); | 111 Hide(); |
112 } | 112 } |
113 | 113 |
114 void AutofillPopupViewViews::Show() { | 114 void AutofillPopupViewViews::Show() { |
115 if (!GetWidget()) { | 115 if (!GetWidget()) { |
(...skipping 23 matching lines...) Expand all Loading... |
139 observing_widget_->AddObserver(this); | 139 observing_widget_->AddObserver(this); |
140 } | 140 } |
141 | 141 |
142 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); | 142 set_border(views::Border::CreateSolidBorder(kBorderThickness, kBorderColor)); |
143 | 143 |
144 SetInitialBounds(); | 144 SetInitialBounds(); |
145 UpdateBoundsAndRedrawPopup(); | 145 UpdateBoundsAndRedrawPopup(); |
146 } | 146 } |
147 | 147 |
148 void AutofillPopupViewViews::InvalidateRow(size_t row) { | 148 void AutofillPopupViewViews::InvalidateRow(size_t row) { |
149 SchedulePaintInRect(controller_->GetRectForRow(row, width())); | 149 SchedulePaintInRect(controller_->GetRowBounds(row)); |
150 } | 150 } |
151 | 151 |
152 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { | 152 void AutofillPopupViewViews::UpdateBoundsAndRedrawPopup() { |
153 SetBoundsRect(controller_->popup_bounds()); | 153 SetBoundsRect(controller_->popup_bounds()); |
154 SchedulePaintInRect(controller_->popup_bounds()); | 154 SchedulePaintInRect(controller_->popup_bounds()); |
155 } | 155 } |
156 | 156 |
157 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, | 157 void AutofillPopupViewViews::DrawAutofillEntry(gfx::Canvas* canvas, |
158 int index, | 158 int index, |
159 const gfx::Rect& entry_rect) { | 159 const gfx::Rect& entry_rect) { |
160 // TODO(csharp): support RTL | 160 // TODO(csharp): support RTL |
161 | 161 |
162 if (controller_->selected_line() == index) | 162 if (controller_->selected_line() == index) |
163 canvas->FillRect(entry_rect, kHoveredBackgroundColor); | 163 canvas->FillRect(entry_rect, kHoveredBackgroundColor); |
164 | 164 |
165 canvas->DrawStringInt( | 165 canvas->DrawStringInt( |
166 controller_->autofill_values()[index], | 166 controller_->names()[index], |
167 controller_->value_font(), | 167 controller_->name_font(), |
168 kValueTextColor, | 168 kValueTextColor, |
169 kEndPadding, | 169 kEndPadding, |
170 entry_rect.y(), | 170 entry_rect.y(), |
171 canvas->GetStringWidth(controller_->autofill_values()[index], | 171 canvas->GetStringWidth(controller_->names()[index], |
172 controller_->value_font()), | 172 controller_->name_font()), |
173 entry_rect.height(), | 173 entry_rect.height(), |
174 gfx::Canvas::TEXT_ALIGN_CENTER); | 174 gfx::Canvas::TEXT_ALIGN_CENTER); |
175 | 175 |
176 // Use this to figure out where all the other Autofill items should be placed. | 176 // Use this to figure out where all the other Autofill items should be placed. |
177 int x_align_left = entry_rect.width() - kEndPadding; | 177 int x_align_left = entry_rect.width() - kEndPadding; |
178 | 178 |
179 // Draw the delete icon, if one is needed. | 179 // Draw the delete icon, if one is needed. |
180 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 180 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
181 int row_height = controller_->GetRowHeightFromId( | 181 int row_height = controller_->GetRowBounds(index).height(); |
182 controller_->autofill_unique_ids()[index]); | 182 if (controller_->CanDelete(index)) { |
183 if (controller_->CanDelete(controller_->autofill_unique_ids()[index])) { | |
184 x_align_left -= kDeleteIconWidth; | 183 x_align_left -= kDeleteIconWidth; |
185 | 184 |
186 // TODO(csharp): Create a custom resource for the delete icon. | 185 // TODO(csharp): Create a custom resource for the delete icon. |
187 // http://crbug.com/131801 | 186 // http://crbug.com/131801 |
188 canvas->DrawImageInt( | 187 canvas->DrawImageInt( |
189 *rb.GetImageSkiaNamed(IDR_CLOSE_BAR), | 188 *rb.GetImageSkiaNamed(IDR_CLOSE_BAR), |
190 x_align_left, | 189 x_align_left, |
191 entry_rect.y() + ((row_height - kDeleteIconHeight) / 2)); | 190 entry_rect.y() + (row_height - kDeleteIconHeight) / 2); |
192 | 191 |
193 x_align_left -= kIconPadding; | 192 x_align_left -= kIconPadding; |
194 } | 193 } |
195 | 194 |
196 // Draw the Autofill icon, if one exists | 195 // Draw the Autofill icon, if one exists |
197 if (!controller_->autofill_icons()[index].empty()) { | 196 if (!controller_->icons()[index].empty()) { |
198 int icon = | 197 int icon = controller_->GetIconResourceID(controller_->icons()[index]); |
199 controller_->GetIconResourceID(controller_->autofill_icons()[index]); | |
200 DCHECK_NE(-1, icon); | 198 DCHECK_NE(-1, icon); |
201 int icon_y = entry_rect.y() + (row_height - kAutofillIconHeight) / 2; | 199 int icon_y = entry_rect.y() + (row_height - kAutofillIconHeight) / 2; |
202 | 200 |
203 x_align_left -= kAutofillIconWidth; | 201 x_align_left -= kAutofillIconWidth; |
204 | 202 |
205 canvas->DrawImageInt(*rb.GetImageSkiaNamed(icon), x_align_left, icon_y); | 203 canvas->DrawImageInt(*rb.GetImageSkiaNamed(icon), x_align_left, icon_y); |
206 | 204 |
207 x_align_left -= kIconPadding; | 205 x_align_left -= kIconPadding; |
208 } | 206 } |
209 | 207 |
210 // Draw the label text. | 208 // Draw the name text. |
211 x_align_left -= canvas->GetStringWidth(controller_->autofill_labels()[index], | 209 x_align_left -= canvas->GetStringWidth(controller_->subtexts()[index], |
212 controller_->label_font()); | 210 controller_->subtext_font()); |
213 | 211 |
214 canvas->DrawStringInt( | 212 canvas->DrawStringInt( |
215 controller_->autofill_labels()[index], | 213 controller_->subtexts()[index], |
216 controller_->label_font(), | 214 controller_->subtext_font(), |
217 kLabelTextColor, | 215 kItemTextColor, |
218 x_align_left + kEndPadding, | 216 x_align_left + kEndPadding, |
219 entry_rect.y(), | 217 entry_rect.y(), |
220 canvas->GetStringWidth(controller_->autofill_labels()[index], | 218 canvas->GetStringWidth(controller_->subtexts()[index], |
221 controller_->label_font()), | 219 controller_->subtext_font()), |
222 entry_rect.height(), | 220 entry_rect.height(), |
223 gfx::Canvas::TEXT_ALIGN_CENTER); | 221 gfx::Canvas::TEXT_ALIGN_CENTER); |
224 } | 222 } |
225 | 223 |
226 void AutofillPopupViewViews::SetInitialBounds() { | 224 void AutofillPopupViewViews::SetInitialBounds() { |
227 int bottom_of_field = controller_->element_bounds().bottom(); | 225 int bottom_of_field = controller_->element_bounds().bottom(); |
228 int popup_height = controller_->GetPopupRequiredHeight(); | 226 int popup_height = controller_->GetPopupRequiredHeight(); |
229 | 227 |
230 // Find the correct top position of the popup so that it doesn't go off | 228 // Find the correct top position of the popup so that it doesn't go off |
231 // the screen. | 229 // the screen. |
(...skipping 19 matching lines...) Expand all Loading... |
251 gfx::Display display = | 249 gfx::Display display = |
252 screen->GetDisplayNearestPoint(controller_->element_bounds().origin()); | 250 screen->GetDisplayNearestPoint(controller_->element_bounds().origin()); |
253 | 251 |
254 return display.GetSizeInPixel(); | 252 return display.GetSizeInPixel(); |
255 } | 253 } |
256 | 254 |
257 AutofillPopupView* AutofillPopupView::Create( | 255 AutofillPopupView* AutofillPopupView::Create( |
258 AutofillPopupController* controller) { | 256 AutofillPopupController* controller) { |
259 return new AutofillPopupViewViews(controller); | 257 return new AutofillPopupViewViews(controller); |
260 } | 258 } |
OLD | NEW |