| 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 "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/i18n/rtl.h" | 9 #include "base/i18n/rtl.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 | 54 |
| 55 // Height of the Autofill icons in pixels. | 55 // Height of the Autofill icons in pixels. |
| 56 const int kAutofillIconHeight = 16; | 56 const int kAutofillIconHeight = 16; |
| 57 | 57 |
| 58 // Width of the delete icon in pixels. | 58 // Width of the delete icon in pixels. |
| 59 const int kDeleteIconWidth = 16; | 59 const int kDeleteIconWidth = 16; |
| 60 | 60 |
| 61 // Height of the delete icon in pixels. | 61 // Height of the delete icon in pixels. |
| 62 const int kDeleteIconHeight = 16; | 62 const int kDeleteIconHeight = 16; |
| 63 | 63 |
| 64 // Size difference between value text and label text in pixels. | |
| 65 const int kLabelFontSizeDelta = -2; | |
| 66 | |
| 67 gfx::Rect GetWindowRect(GdkWindow* window) { | 64 gfx::Rect GetWindowRect(GdkWindow* window) { |
| 68 return gfx::Rect(gdk_window_get_width(window), | 65 return gfx::Rect(gdk_window_get_width(window), |
| 69 gdk_window_get_height(window)); | 66 gdk_window_get_height(window)); |
| 70 } | 67 } |
| 71 | 68 |
| 72 int GetRowHeight(int unique_id) { | 69 int GetRowHeight(int unique_id) { |
| 73 if (unique_id == WebAutofillClient::MenuItemIDSeparator) | 70 if (unique_id == WebAutofillClient::MenuItemIDSeparator) |
| 74 return kSeparatorHeight; | 71 return kSeparatorHeight; |
| 75 | 72 |
| 76 return kRowHeight; | 73 return kRowHeight; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 101 GDK_POINTER_MOTION_MASK); | 98 GDK_POINTER_MOTION_MASK); |
| 102 g_signal_connect(window_, "expose-event", | 99 g_signal_connect(window_, "expose-event", |
| 103 G_CALLBACK(HandleExposeThunk), this); | 100 G_CALLBACK(HandleExposeThunk), this); |
| 104 g_signal_connect(window_, "leave-notify-event", | 101 g_signal_connect(window_, "leave-notify-event", |
| 105 G_CALLBACK(HandleLeaveThunk), this); | 102 G_CALLBACK(HandleLeaveThunk), this); |
| 106 g_signal_connect(window_, "motion-notify-event", | 103 g_signal_connect(window_, "motion-notify-event", |
| 107 G_CALLBACK(HandleMotionThunk), this); | 104 G_CALLBACK(HandleMotionThunk), this); |
| 108 g_signal_connect(window_, "button-release-event", | 105 g_signal_connect(window_, "button-release-event", |
| 109 G_CALLBACK(HandleButtonReleaseThunk), this); | 106 G_CALLBACK(HandleButtonReleaseThunk), this); |
| 110 | 107 |
| 111 label_font_ = value_font_.DeriveFont(kLabelFontSizeDelta); | |
| 112 | |
| 113 // Cache the layout so we don't have to create it for every expose. | 108 // Cache the layout so we don't have to create it for every expose. |
| 114 layout_ = gtk_widget_create_pango_layout(window_, NULL); | 109 layout_ = gtk_widget_create_pango_layout(window_, NULL); |
| 115 } | 110 } |
| 116 | 111 |
| 117 AutofillPopupViewGtk::~AutofillPopupViewGtk() { | 112 AutofillPopupViewGtk::~AutofillPopupViewGtk() { |
| 118 g_object_unref(layout_); | 113 g_object_unref(layout_); |
| 119 gtk_widget_destroy(window_); | 114 gtk_widget_destroy(window_); |
| 120 } | 115 } |
| 121 | 116 |
| 122 void AutofillPopupViewGtk::ShowInternal() { | 117 void AutofillPopupViewGtk::ShowInternal() { |
| (...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 307 size_t index, | 302 size_t index, |
| 308 const gfx::Rect& entry_rect) { | 303 const gfx::Rect& entry_rect) { |
| 309 if (selected_line() == static_cast<int>(index)) { | 304 if (selected_line() == static_cast<int>(index)) { |
| 310 gdk_cairo_set_source_color(cairo_context, &kHoveredBackgroundColor); | 305 gdk_cairo_set_source_color(cairo_context, &kHoveredBackgroundColor); |
| 311 cairo_rectangle(cairo_context, entry_rect.x(), entry_rect.y(), | 306 cairo_rectangle(cairo_context, entry_rect.x(), entry_rect.y(), |
| 312 entry_rect.width(), entry_rect.height()); | 307 entry_rect.width(), entry_rect.height()); |
| 313 cairo_fill(cairo_context); | 308 cairo_fill(cairo_context); |
| 314 } | 309 } |
| 315 | 310 |
| 316 // Draw the value. | 311 // Draw the value. |
| 317 SetLayoutText(autofill_values()[index], value_font_, kValueTextColor); | 312 SetLayoutText(autofill_values()[index], value_font(), kValueTextColor); |
| 318 int value_text_width = value_font_.GetStringWidth(autofill_values()[index]); | 313 int value_text_width = value_font().GetStringWidth(autofill_values()[index]); |
| 319 | 314 |
| 320 // Center the text within the line. | 315 // Center the text within the line. |
| 321 int value_content_y = std::max( | 316 int value_content_y = std::max( |
| 322 entry_rect.y(), | 317 entry_rect.y(), |
| 323 entry_rect.y() + ((kRowHeight - value_font_.GetHeight()) / 2)); | 318 entry_rect.y() + ((kRowHeight - value_font().GetHeight()) / 2)); |
| 324 | 319 |
| 325 bool is_rtl = base::i18n::IsRTL(); | 320 bool is_rtl = base::i18n::IsRTL(); |
| 326 cairo_save(cairo_context); | 321 cairo_save(cairo_context); |
| 327 cairo_move_to(cairo_context, | 322 cairo_move_to(cairo_context, |
| 328 is_rtl ? entry_rect.width() - value_text_width - kEndPadding : | 323 is_rtl ? entry_rect.width() - value_text_width - kEndPadding : |
| 329 kEndPadding, | 324 kEndPadding, |
| 330 value_content_y); | 325 value_content_y); |
| 331 pango_cairo_show_layout(cairo_context, layout_); | 326 pango_cairo_show_layout(cairo_context, layout_); |
| 332 cairo_restore(cairo_context); | 327 cairo_restore(cairo_context); |
| 333 | 328 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 372 window_, | 367 window_, |
| 373 *theme_service_->GetImageNamed(icon), | 368 *theme_service_->GetImageNamed(icon), |
| 374 x_align_left, | 369 x_align_left, |
| 375 icon_y); | 370 icon_y); |
| 376 cairo_restore(cairo_context); | 371 cairo_restore(cairo_context); |
| 377 | 372 |
| 378 x_align_left += is_rtl ? kAutofillIconWidth + kIconPadding : -kIconPadding; | 373 x_align_left += is_rtl ? kAutofillIconWidth + kIconPadding : -kIconPadding; |
| 379 } | 374 } |
| 380 | 375 |
| 381 // Draw the label text. | 376 // Draw the label text. |
| 382 SetLayoutText(autofill_labels()[index], label_font_, kLabelTextColor); | 377 SetLayoutText(autofill_labels()[index], label_font(), kLabelTextColor); |
| 383 x_align_left += | 378 x_align_left += |
| 384 is_rtl ? 0 : -label_font_.GetStringWidth(autofill_labels()[index]); | 379 is_rtl ? 0 : -label_font().GetStringWidth(autofill_labels()[index]); |
| 385 | 380 |
| 386 // Center the text within the line. | 381 // Center the text within the line. |
| 387 int label_content_y = std::max( | 382 int label_content_y = std::max( |
| 388 entry_rect.y(), | 383 entry_rect.y(), |
| 389 entry_rect.y() + ((kRowHeight - label_font_.GetHeight()) / 2)); | 384 entry_rect.y() + ((kRowHeight - label_font().GetHeight()) / 2)); |
| 390 | 385 |
| 391 cairo_save(cairo_context); | 386 cairo_save(cairo_context); |
| 392 cairo_move_to(cairo_context, x_align_left, label_content_y); | 387 cairo_move_to(cairo_context, x_align_left, label_content_y); |
| 393 pango_cairo_show_layout(cairo_context, layout_); | 388 pango_cairo_show_layout(cairo_context, layout_); |
| 394 cairo_restore(cairo_context); | 389 cairo_restore(cairo_context); |
| 395 } | 390 } |
| 396 | 391 |
| 397 void AutofillPopupViewGtk::SetBounds() { | 392 void AutofillPopupViewGtk::SetBounds() { |
| 398 gint origin_x, origin_y; | 393 gint origin_x, origin_y; |
| 399 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y); | 394 gdk_window_get_origin(gtk_widget_get_window(parent_), &origin_x, &origin_y); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 421 top_of_popup, | 416 top_of_popup, |
| 422 GetPopupRequiredWidth(), | 417 GetPopupRequiredWidth(), |
| 423 popup_height); | 418 popup_height); |
| 424 } | 419 } |
| 425 | 420 |
| 426 int AutofillPopupViewGtk::GetPopupRequiredWidth() { | 421 int AutofillPopupViewGtk::GetPopupRequiredWidth() { |
| 427 int popup_width = element_bounds().width(); | 422 int popup_width = element_bounds().width(); |
| 428 DCHECK_EQ(autofill_values().size(), autofill_labels().size()); | 423 DCHECK_EQ(autofill_values().size(), autofill_labels().size()); |
| 429 for (size_t i = 0; i < autofill_values().size(); ++i) { | 424 for (size_t i = 0; i < autofill_values().size(); ++i) { |
| 430 int row_size = kEndPadding + | 425 int row_size = kEndPadding + |
| 431 value_font_.GetStringWidth(autofill_values()[i]) + | 426 value_font().GetStringWidth(autofill_values()[i]) + |
| 432 kLabelPadding + | 427 kLabelPadding + |
| 433 label_font_.GetStringWidth(autofill_labels()[i]); | 428 label_font().GetStringWidth(autofill_labels()[i]); |
| 434 | 429 |
| 435 // Add the Autofill icon size, if required. | 430 // Add the Autofill icon size, if required. |
| 436 if (!autofill_icons()[i].empty()) | 431 if (!autofill_icons()[i].empty()) |
| 437 row_size += kAutofillIconWidth + kIconPadding; | 432 row_size += kAutofillIconWidth + kIconPadding; |
| 438 | 433 |
| 439 // Add delete icon, if required. | 434 // Add delete icon, if required. |
| 440 if (CanDelete(autofill_unique_ids()[i])) | 435 if (CanDelete(autofill_unique_ids()[i])) |
| 441 row_size += kDeleteIconWidth + kIconPadding; | 436 row_size += kDeleteIconWidth + kIconPadding; |
| 442 | 437 |
| 443 // Add the padding at the end | 438 // Add the padding at the end |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 492 } | 487 } |
| 493 | 488 |
| 494 gfx::Rect delete_icon_bounds = gfx::Rect( | 489 gfx::Rect delete_icon_bounds = gfx::Rect( |
| 495 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding, | 490 GetPopupRequiredWidth() - kDeleteIconWidth - kIconPadding, |
| 496 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2), | 491 row_start_y + ((kRowHeight - kDeleteIconHeight) / 2), |
| 497 kDeleteIconWidth, | 492 kDeleteIconWidth, |
| 498 kDeleteIconHeight); | 493 kDeleteIconHeight); |
| 499 | 494 |
| 500 return delete_icon_bounds.Contains(x, y); | 495 return delete_icon_bounds.Contains(x, y); |
| 501 } | 496 } |
| OLD | NEW |