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

Side by Side Diff: chrome/browser/ui/gtk/autofill/autofill_popup_view_gtk.cc

Issue 10408070: Upgrade Seperator in New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 7 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 "autofill_popup_view_gtk.h" 5 #include "autofill_popup_view_gtk.h"
6 6
7 #include <gdk/gdkkeysyms.h> 7 #include <gdk/gdkkeysyms.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
11 #include "chrome/browser/autofill/autofill_external_delegate.h" 11 #include "chrome/browser/autofill/autofill_external_delegate.h"
12 #include "chrome/browser/ui/gtk/gtk_util.h" 12 #include "chrome/browser/ui/gtk/gtk_util.h"
13 #include "chrome/browser/ui/gtk/gtk_theme_service.h" 13 #include "chrome/browser/ui/gtk/gtk_theme_service.h"
14 #include "content/public/browser/render_view_host.h" 14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h" 15 #include "content/public/browser/web_contents.h"
16 #include "third_party/WebKit/Source/WebKit/chromium/public/WebAutofillClient.h"
16 #include "ui/base/gtk/gtk_compat.h" 17 #include "ui/base/gtk/gtk_compat.h"
17 #include "ui/base/gtk/gtk_hig_constants.h" 18 #include "ui/base/gtk/gtk_hig_constants.h"
18 #include "ui/base/gtk/gtk_windowing.h" 19 #include "ui/base/gtk/gtk_windowing.h"
19 #include "ui/gfx/native_widget_types.h" 20 #include "ui/gfx/native_widget_types.h"
20 #include "ui/gfx/rect.h" 21 #include "ui/gfx/rect.h"
21 22
23 using WebKit::WebAutofillClient;
24
22 namespace { 25 namespace {
23 const GdkColor kBorderColor = GDK_COLOR_RGB(0xc7, 0xca, 0xce); 26 const GdkColor kBorderColor = GDK_COLOR_RGB(0xc7, 0xca, 0xce);
24 const GdkColor kHoveredBackgroundColor = GDK_COLOR_RGB(0x0CD, 0xCD, 0xCD); 27 const GdkColor kHoveredBackgroundColor = GDK_COLOR_RGB(0x0CD, 0xCD, 0xCD);
25 const GdkColor kTextColor = GDK_COLOR_RGB(0x00, 0x00, 0x00); 28 const GdkColor kTextColor = GDK_COLOR_RGB(0x00, 0x00, 0x00);
26 29
27 // The vertical height of each row in pixels. 30 // The vertical height of each row in pixels.
28 const int kRowHeight = 24; 31 const int kRowHeight = 24;
29 32
30 // The amount of minimum padding between the Autofill value and label in pixels. 33 // The amount of minimum padding between the Autofill value and label in pixels.
31 const int kMiddlePadding = 10; 34 const int kMiddlePadding = 10;
32 35
33 // The amount of padding between the label and icon or edge and icon in pixels. 36 // The amount of padding between the label and icon or edge and icon in pixels.
34 const int kIconPadding = 5; 37 const int kIconPadding = 5;
35 38
36 // We have a 1 pixel border around the entire results popup. 39 // We have a 1 pixel border around the entire results popup.
37 const int kBorderThickness = 1; 40 const int kBorderThickness = 1;
38 41
39 // Width of the icons in pixels. 42 // Width of the icons in pixels.
40 const int kIconWidth = 25; 43 const int kIconWidth = 25;
41 44
42 // Height of the icons in pixels. 45 // Height of the icons in pixels.
43 const int kIconHeight = 16; 46 const int kIconHeight = 16;
44 47
45 gfx::Rect GetWindowRect(GdkWindow* window) { 48 gfx::Rect GetWindowRect(GdkWindow* window) {
46 return gfx::Rect(gdk_window_get_width(window), 49 return gfx::Rect(gdk_window_get_width(window),
47 gdk_window_get_height(window)); 50 gdk_window_get_height(window));
48 } 51 }
49 52
50 // Returns the rectangle containing the item at position |index| in the popup. 53 // Returns the rectangle containing the item at position |index| in the popup.
51 gfx::Rect GetRectForRow(size_t index, int width) { 54 gfx::Rect GetRectForRow(size_t row, int width) {
52 return gfx::Rect(0, (index * kRowHeight), width, kRowHeight); 55 return gfx::Rect(0, (row * kRowHeight), width, kRowHeight);
53 } 56 }
54 57
55 } // namespace 58 } // namespace
56 59
57 AutofillPopupViewGtk::AutofillPopupViewGtk( 60 AutofillPopupViewGtk::AutofillPopupViewGtk(
58 content::WebContents* web_contents, 61 content::WebContents* web_contents,
59 GtkThemeService* theme_service, 62 GtkThemeService* theme_service,
60 AutofillExternalDelegate* external_delegate, 63 AutofillExternalDelegate* external_delegate,
61 GtkWidget* parent) 64 GtkWidget* parent)
62 : AutofillPopupView(web_contents, external_delegate), 65 : AutofillPopupView(web_contents, external_delegate),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 void AutofillPopupViewGtk::InvalidateRow(size_t row) { 118 void AutofillPopupViewGtk::InvalidateRow(size_t row) {
116 GdkRectangle row_rect = GetRectForRow(row, bounds_.width()).ToGdkRectangle(); 119 GdkRectangle row_rect = GetRectForRow(row, bounds_.width()).ToGdkRectangle();
117 GdkWindow* gdk_window = gtk_widget_get_window(window_); 120 GdkWindow* gdk_window = gtk_widget_get_window(window_);
118 gdk_window_invalidate_rect(gdk_window, &row_rect, FALSE); 121 gdk_window_invalidate_rect(gdk_window, &row_rect, FALSE);
119 } 122 }
120 123
121 void AutofillPopupViewGtk::ResizePopup() { 124 void AutofillPopupViewGtk::ResizePopup() {
122 gtk_widget_set_size_request( 125 gtk_widget_set_size_request(
123 window_, 126 window_,
124 GetPopupRequiredWidth(), 127 GetPopupRequiredWidth(),
125 kRowHeight * autofill_values().size()); 128 kRowHeight * row_count());
126 } 129 }
127 130
128 gboolean AutofillPopupViewGtk::HandleButtonRelease(GtkWidget* widget, 131 gboolean AutofillPopupViewGtk::HandleButtonRelease(GtkWidget* widget,
129 GdkEventButton* event) { 132 GdkEventButton* event) {
130 // We only care about the left click. 133 // We only care about the left click.
131 if (event->button != 1) 134 if (event->button != 1)
132 return FALSE; 135 return FALSE;
133 136
134 DCHECK_EQ(selected_line(), LineFromY(event->y)); 137 DCHECK_EQ(selected_line(), LineFromY(event->y));
135 138
(...skipping 20 matching lines...) Expand all
156 cairo_rectangle(cr, 0, 0, window_rect.width(), window_rect.height()); 159 cairo_rectangle(cr, 0, 0, window_rect.width(), window_rect.height());
157 cairo_stroke(cr); 160 cairo_stroke(cr);
158 161
159 SetupLayout(window_rect, kTextColor); 162 SetupLayout(window_rect, kTextColor);
160 163
161 int actual_content_width, actual_content_height; 164 int actual_content_width, actual_content_height;
162 pango_layout_get_size(layout_, &actual_content_width, &actual_content_height); 165 pango_layout_get_size(layout_, &actual_content_width, &actual_content_height);
163 actual_content_width /= PANGO_SCALE; 166 actual_content_width /= PANGO_SCALE;
164 actual_content_height /= PANGO_SCALE; 167 actual_content_height /= PANGO_SCALE;
165 168
169 int current_row = 0;
166 for (size_t i = 0; i < autofill_values().size(); ++i) { 170 for (size_t i = 0; i < autofill_values().size(); ++i) {
167 gfx::Rect line_rect = GetRectForRow(i, window_rect.width()); 171 gfx::Rect line_rect = GetRectForRow(current_row, window_rect.width());
168 // Only repaint and layout damaged lines. 172 // Only repaint and layout damaged lines.
169 if (!line_rect.Intersects(damage_rect)) 173 if (!line_rect.Intersects(damage_rect)) {
174 if (autofill_unique_ids()[i] != WebAutofillClient::MenuItemIDSeparator)
175 ++current_row;
170 continue; 176 continue;
177 }
171 178
172 if (IsSeparatorIndex(i)) { 179 if (autofill_unique_ids()[i] == WebAutofillClient::MenuItemIDSeparator) {
173 int line_y = i * kRowHeight; 180 int line_y = current_row * kRowHeight;
174 181
175 cairo_save(cr); 182 cairo_save(cr);
176 cairo_move_to(cr, 0, line_y); 183 cairo_move_to(cr, 0, line_y);
177 cairo_line_to(cr, window_rect.width(), line_y); 184 cairo_line_to(cr, window_rect.width(), line_y);
178 cairo_stroke(cr); 185 cairo_stroke(cr);
179 cairo_restore(cr); 186 cairo_restore(cr);
187
188 // All the separator index should do is draw the line, move to the next
189 // element now.
190 continue;
180 } 191 }
181 192
182 if (selected_line() == static_cast<int>(i)) { 193 if (selected_line() == static_cast<int>(current_row)) {
183 gdk_cairo_set_source_color(cr, &kHoveredBackgroundColor); 194 gdk_cairo_set_source_color(cr, &kHoveredBackgroundColor);
184 cairo_rectangle(cr, line_rect.x(), line_rect.y(), 195 cairo_rectangle(cr, line_rect.x(), line_rect.y(),
185 line_rect.width(), line_rect.height()); 196 line_rect.width(), line_rect.height());
186 cairo_fill(cr); 197 cairo_fill(cr);
187 } 198 }
188 199
189 // Center the text within the line. 200 // Center the text within the line.
190 int content_y = std::max( 201 int content_y = std::max(
191 line_rect.y(), 202 line_rect.y(),
192 line_rect.y() + ((kRowHeight - actual_content_height) / 2)); 203 line_rect.y() + ((kRowHeight - actual_content_height) / 2));
(...skipping 28 matching lines...) Expand all
221 232
222 cairo_save(cr); 233 cairo_save(cr);
223 gtk_util::DrawFullImage(cr, 234 gtk_util::DrawFullImage(cr,
224 window_, 235 window_,
225 theme_service_->GetImageNamed(icon), 236 theme_service_->GetImageNamed(icon),
226 window_rect.width() - 237 window_rect.width() -
227 (kIconPadding + kIconWidth), 238 (kIconPadding + kIconWidth),
228 icon_y); 239 icon_y);
229 cairo_restore(cr); 240 cairo_restore(cr);
230 } 241 }
242
243 // Increase the current row.
244 ++current_row;
231 } 245 }
232 246
233 cairo_destroy(cr); 247 cairo_destroy(cr);
234 248
235 return TRUE; 249 return TRUE;
236 } 250 }
237 251
238 gboolean AutofillPopupViewGtk::HandleMotion(GtkWidget* widget, 252 gboolean AutofillPopupViewGtk::HandleMotion(GtkWidget* widget,
239 GdkEventMotion* event) { 253 GdkEventMotion* event) {
240 int line = LineFromY(event->y); 254 int line = LineFromY(event->y);
(...skipping 11 matching lines...) Expand all
252 case GDK_Up: 266 case GDK_Up:
253 SelectPreviousLine(); 267 SelectPreviousLine();
254 return true; 268 return true;
255 case GDK_Down: 269 case GDK_Down:
256 SelectNextLine(); 270 SelectNextLine();
257 return true; 271 return true;
258 case GDK_Page_Up: 272 case GDK_Page_Up:
259 SetSelectedLine(0); 273 SetSelectedLine(0);
260 return true; 274 return true;
261 case GDK_Page_Down: 275 case GDK_Page_Down:
262 SetSelectedLine(autofill_values().size() - 1); 276 SetSelectedLine(row_count() - 1);
263 return true; 277 return true;
264 case GDK_Escape: 278 case GDK_Escape:
265 Hide(); 279 Hide();
266 return true; 280 return true;
267 case GDK_Delete: 281 case GDK_Delete:
268 case GDK_KP_Delete: 282 case GDK_KP_Delete:
269 return (modifier == GDK_SHIFT_MASK) && RemoveSelectedLine(); 283 return (modifier == GDK_SHIFT_MASK) && RemoveSelectedLine();
270 case GDK_Return: 284 case GDK_Return:
271 case GDK_KP_Enter: 285 case GDK_KP_Enter:
272 return AcceptSelectedLine(); 286 return AcceptSelectedLine();
(...skipping 22 matching lines...) Expand all
295 309
296 void AutofillPopupViewGtk::SetBounds() { 310 void AutofillPopupViewGtk::SetBounds() {
297 gint origin_x, origin_y; 311 gint origin_x, origin_y;
298 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y); 312 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y);
299 313
300 GdkScreen* screen = gtk_widget_get_screen(parent_); 314 GdkScreen* screen = gtk_widget_get_screen(parent_);
301 gint screen_height = gdk_screen_get_height(screen); 315 gint screen_height = gdk_screen_get_height(screen);
302 316
303 int bottom_of_field = origin_y + element_bounds().y() + 317 int bottom_of_field = origin_y + element_bounds().y() +
304 element_bounds().height(); 318 element_bounds().height();
305 int popup_size = kRowHeight * autofill_values().size(); 319 int popup_size = kRowHeight * row_count();
306 320
307 // Find the correct top position of the popup so that is doesn't go off 321 // Find the correct top position of the popup so that is doesn't go off
308 // the screen. 322 // the screen.
309 int top_of_popup = 0; 323 int top_of_popup = 0;
310 if (screen_height < bottom_of_field + popup_size) { 324 if (screen_height < bottom_of_field + popup_size) {
311 // The popup must appear above the field. 325 // The popup must appear above the field.
312 top_of_popup = origin_y + element_bounds().y() - popup_size; 326 top_of_popup = origin_y + element_bounds().y() - popup_size;
313 } else { 327 } else {
314 // The popup can appear below the field. 328 // The popup can appear below the field.
315 top_of_popup = bottom_of_field; 329 top_of_popup = bottom_of_field;
(...skipping 20 matching lines...) Expand all
336 350
337 popup_width = std::max(popup_width, row_size); 351 popup_width = std::max(popup_width, row_size);
338 } 352 }
339 353
340 return popup_width; 354 return popup_width;
341 } 355 }
342 356
343 int AutofillPopupViewGtk::LineFromY(int y) { 357 int AutofillPopupViewGtk::LineFromY(int y) {
344 return y / kRowHeight; 358 return y / kRowHeight;
345 } 359 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698