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/gtk/autofill/autofill_popup_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/autofill/autofill_popup_view_gtk.h" |
6 | 6 |
7 #include <gdk/gdkkeysyms.h> | 7 #include <gdk/gdkkeysyms.h> |
8 | 8 |
9 #include "base/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 controller_->ViewDestroyed(); | 63 controller_->ViewDestroyed(); |
64 g_object_unref(layout_); | 64 g_object_unref(layout_); |
65 gtk_widget_destroy(window_); | 65 gtk_widget_destroy(window_); |
66 } | 66 } |
67 | 67 |
68 void AutofillPopupViewGtk::Hide() { | 68 void AutofillPopupViewGtk::Hide() { |
69 delete this; | 69 delete this; |
70 } | 70 } |
71 | 71 |
72 void AutofillPopupViewGtk::Show() { | 72 void AutofillPopupViewGtk::Show() { |
73 SetInitialBounds(); | |
74 UpdateBoundsAndRedrawPopup(); | 73 UpdateBoundsAndRedrawPopup(); |
75 | 74 |
76 gtk_widget_show(window_); | 75 gtk_widget_show(window_); |
77 | 76 |
78 GtkWidget* parent_window = | 77 GtkWidget* parent_window = |
79 gtk_widget_get_toplevel(controller_->container_view()); | 78 gtk_widget_get_toplevel(controller_->container_view()); |
80 ui::StackPopupWindow(window_, parent_window); | 79 ui::StackPopupWindow(window_, parent_window); |
81 } | 80 } |
82 | 81 |
83 void AutofillPopupViewGtk::InvalidateRow(size_t row) { | 82 void AutofillPopupViewGtk::InvalidateRow(size_t row) { |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 entry_rect.y(), | 298 entry_rect.y(), |
300 entry_rect.y() + | 299 entry_rect.y() + |
301 (row_height - controller_->subtext_font().GetHeight()) / 2); | 300 (row_height - controller_->subtext_font().GetHeight()) / 2); |
302 | 301 |
303 cairo_save(cairo_context); | 302 cairo_save(cairo_context); |
304 cairo_move_to(cairo_context, x_align_left, subtext_content_y); | 303 cairo_move_to(cairo_context, x_align_left, subtext_content_y); |
305 pango_cairo_show_layout(cairo_context, layout_); | 304 pango_cairo_show_layout(cairo_context, layout_); |
306 cairo_restore(cairo_context); | 305 cairo_restore(cairo_context); |
307 } | 306 } |
308 | 307 |
309 void AutofillPopupViewGtk::SetInitialBounds() { | |
310 GdkScreen* screen = | |
311 gtk_widget_get_screen(GTK_WIDGET(controller_->container_view())); | |
312 gint screen_height = gdk_screen_get_height(screen); | |
313 | |
314 int bottom_of_field = controller_->element_bounds().bottom(); | |
315 int popup_height = controller_->GetPopupRequiredHeight(); | |
316 | |
317 // Find the correct top position of the popup so that is doesn't go off | |
318 // the screen. | |
319 int top_of_popup = 0; | |
320 if (screen_height < bottom_of_field + popup_height) { | |
321 // The popup must appear above the field. | |
322 top_of_popup = controller_->element_bounds().y() - popup_height; | |
323 } else { | |
324 // The popup can appear below the field. | |
325 top_of_popup = bottom_of_field; | |
326 } | |
327 | |
328 controller_->SetPopupBounds(gfx::Rect( | |
329 controller_->element_bounds().x(), | |
330 top_of_popup, | |
331 controller_->GetPopupRequiredWidth(), | |
332 popup_height)); | |
333 } | |
334 | |
335 AutofillPopupView* AutofillPopupView::Create( | 308 AutofillPopupView* AutofillPopupView::Create( |
336 AutofillPopupController* controller) { | 309 AutofillPopupController* controller) { |
337 return new AutofillPopupViewGtk(controller); | 310 return new AutofillPopupViewGtk(controller); |
338 } | 311 } |
OLD | NEW |