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

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

Issue 10073018: Add Delete Support to New Autofill UI (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Rebase 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
« no previous file with comments | « chrome/browser/ui/gtk/autofill/autofill_popup_view_gtk.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 75
76 AutofillPopupViewGtk::~AutofillPopupViewGtk() { 76 AutofillPopupViewGtk::~AutofillPopupViewGtk() {
77 g_object_unref(layout_); 77 g_object_unref(layout_);
78 gtk_widget_destroy(window_); 78 gtk_widget_destroy(window_);
79 } 79 }
80 80
81 void AutofillPopupViewGtk::ShowInternal() { 81 void AutofillPopupViewGtk::ShowInternal() {
82 gint origin_x, origin_y; 82 gint origin_x, origin_y;
83 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y); 83 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y);
84 84
85 int popup_width = GetPopupRequiredWidth();
86
87 // Move the popup to appear right below the text field it is using. 85 // Move the popup to appear right below the text field it is using.
88 bounds_.SetRect( 86 bounds_.SetRect(
89 origin_x + element_bounds().x(), 87 origin_x + element_bounds().x(),
90 origin_y + element_bounds().y() + element_bounds().height(), 88 origin_y + element_bounds().y() + element_bounds().height(),
91 popup_width, 89 GetPopupRequiredWidth(),
92 row_height_ * autofill_values().size()); 90 row_height_ * autofill_values().size());
93 91
94 gtk_window_move(GTK_WINDOW(window_), bounds_.x(), bounds_.y()); 92 gtk_window_move(GTK_WINDOW(window_), bounds_.x(), bounds_.y());
95 93
96 gtk_widget_set_size_request( 94 ResizePopup();
97 window_,
98 popup_width,
99 row_height_ * autofill_values().size());
100 95
101 render_view_host_->AddKeyboardListener(this); 96 render_view_host_->AddKeyboardListener(this);
102 97
103 gtk_widget_show(window_); 98 gtk_widget_show(window_);
104 99
105 GtkWidget* toplevel = gtk_widget_get_toplevel(parent_); 100 GtkWidget* toplevel = gtk_widget_get_toplevel(parent_);
106 CHECK(gtk_widget_is_toplevel(toplevel)); 101 CHECK(gtk_widget_is_toplevel(toplevel));
107 ui::StackPopupWindow(window_, toplevel); 102 ui::StackPopupWindow(window_, toplevel);
108 } 103 }
109 104
110 void AutofillPopupViewGtk::HideInternal() { 105 void AutofillPopupViewGtk::HideInternal() {
111 render_view_host_->RemoveKeyboardListener(this); 106 render_view_host_->RemoveKeyboardListener(this);
112 107
113 gtk_widget_hide(window_); 108 gtk_widget_hide(window_);
114 } 109 }
115 110
116 void AutofillPopupViewGtk::InvalidateRow(size_t row) { 111 void AutofillPopupViewGtk::InvalidateRow(size_t row) {
117 GdkRectangle row_rect = GetRectForRow( 112 GdkRectangle row_rect = GetRectForRow(
118 row, bounds_.width(), row_height_).ToGdkRectangle(); 113 row, bounds_.width(), row_height_).ToGdkRectangle();
119 GdkWindow* gdk_window = gtk_widget_get_window(window_); 114 GdkWindow* gdk_window = gtk_widget_get_window(window_);
120 gdk_window_invalidate_rect(gdk_window, &row_rect, FALSE); 115 gdk_window_invalidate_rect(gdk_window, &row_rect, FALSE);
121 } 116 }
122 117
118 void AutofillPopupViewGtk::ResizePopup() {
119 gtk_widget_set_size_request(
120 window_,
121 GetPopupRequiredWidth(),
122 row_height_ * autofill_values().size());
123 }
124
123 gboolean AutofillPopupViewGtk::HandleButtonRelease(GtkWidget* widget, 125 gboolean AutofillPopupViewGtk::HandleButtonRelease(GtkWidget* widget,
124 GdkEventButton* event) { 126 GdkEventButton* event) {
125 // We only care about the left click. 127 // We only care about the left click.
126 if (event->button != 1) 128 if (event->button != 1)
127 return FALSE; 129 return FALSE;
128 130
129 DCHECK_EQ(selected_line(), LineFromY(event->y)); 131 DCHECK_EQ(selected_line(), LineFromY(event->y));
130 132
131 AcceptSelectedLine(); 133 AcceptSelectedLine();
132 134
(...skipping 24 matching lines...) Expand all
157 pango_layout_get_size(layout_, &actual_content_width, &actual_content_height); 159 pango_layout_get_size(layout_, &actual_content_width, &actual_content_height);
158 actual_content_width /= PANGO_SCALE; 160 actual_content_width /= PANGO_SCALE;
159 actual_content_height /= PANGO_SCALE; 161 actual_content_height /= PANGO_SCALE;
160 162
161 for (size_t i = 0; i < autofill_values().size(); ++i) { 163 for (size_t i = 0; i < autofill_values().size(); ++i) {
162 gfx::Rect line_rect = GetRectForRow(i, window_rect.width(), row_height_); 164 gfx::Rect line_rect = GetRectForRow(i, window_rect.width(), row_height_);
163 // Only repaint and layout damaged lines. 165 // Only repaint and layout damaged lines.
164 if (!line_rect.Intersects(damage_rect)) 166 if (!line_rect.Intersects(damage_rect))
165 continue; 167 continue;
166 168
167 if (separator_index() == static_cast<int>(i)) { 169 if (IsSeparatorIndex(i)) {
168 int line_y = i * row_height_; 170 int line_y = i * row_height_;
169 171
170 cairo_save(cr); 172 cairo_save(cr);
171 cairo_move_to(cr, 0, line_y); 173 cairo_move_to(cr, 0, line_y);
172 cairo_line_to(cr, window_rect.width(), line_y); 174 cairo_line_to(cr, window_rect.width(), line_y);
173 cairo_stroke(cr); 175 cairo_stroke(cr);
174 cairo_restore(cr); 176 cairo_restore(cr);
175 } 177 }
176 178
177 if (selected_line() == static_cast<int>(i)) { 179 if (selected_line() == static_cast<int>(i)) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
213 gboolean AutofillPopupViewGtk::HandleMotion(GtkWidget* widget, 215 gboolean AutofillPopupViewGtk::HandleMotion(GtkWidget* widget,
214 GdkEventMotion* event) { 216 GdkEventMotion* event) {
215 int line = LineFromY(event->y); 217 int line = LineFromY(event->y);
216 218
217 SetSelectedLine(line); 219 SetSelectedLine(line);
218 220
219 return TRUE; 221 return TRUE;
220 } 222 }
221 223
222 bool AutofillPopupViewGtk::HandleKeyPressEvent(GdkEventKey* event) { 224 bool AutofillPopupViewGtk::HandleKeyPressEvent(GdkEventKey* event) {
225 // Filter modifier to only include accelerator modifiers.
226 guint modifier = event->state & gtk_accelerator_get_default_mod_mask();
227
223 switch (event->keyval) { 228 switch (event->keyval) {
224 case GDK_Up: 229 case GDK_Up:
225 SelectPreviousLine(); 230 SelectPreviousLine();
226 return true; 231 return true;
227 case GDK_Down: 232 case GDK_Down:
228 SelectNextLine(); 233 SelectNextLine();
229 return true; 234 return true;
230 case GDK_Page_Up: 235 case GDK_Page_Up:
231 SetSelectedLine(0); 236 SetSelectedLine(0);
232 return true; 237 return true;
233 case GDK_Page_Down: 238 case GDK_Page_Down:
234 SetSelectedLine(autofill_values().size() - 1); 239 SetSelectedLine(autofill_values().size() - 1);
235 return true; 240 return true;
236 case GDK_Escape: 241 case GDK_Escape:
237 Hide(); 242 Hide();
238 return true; 243 return true;
239 case GDK_Delete: 244 case GDK_Delete:
240 case GDK_KP_Delete: 245 case GDK_KP_Delete:
241 return (event->state == GDK_SHIFT_MASK) && RemoveSelectedLine(); 246 return (modifier == GDK_SHIFT_MASK) && RemoveSelectedLine();
242 case GDK_Return: 247 case GDK_Return:
243 case GDK_KP_Enter: 248 case GDK_KP_Enter:
244 return AcceptSelectedLine(); 249 return AcceptSelectedLine();
245 } 250 }
246 251
247 return false; 252 return false;
248 } 253 }
249 254
250 void AutofillPopupViewGtk::SetupLayout(const gfx::Rect& window_rect, 255 void AutofillPopupViewGtk::SetupLayout(const gfx::Rect& window_rect,
251 const GdkColor& text_color) { 256 const GdkColor& text_color) {
(...skipping 24 matching lines...) Expand all
276 kMiddlePadding + 281 kMiddlePadding +
277 font_.GetStringWidth(autofill_labels()[i])); 282 font_.GetStringWidth(autofill_labels()[i]));
278 } 283 }
279 284
280 return popup_width; 285 return popup_width;
281 } 286 }
282 287
283 int AutofillPopupViewGtk::LineFromY(int y) { 288 int AutofillPopupViewGtk::LineFromY(int y) {
284 return y / row_height_; 289 return y / row_height_;
285 } 290 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/gtk/autofill/autofill_popup_view_gtk.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698