OLD | NEW |
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/autocomplete/autocomplete_popup_view_gtk.h" | 5 #include "chrome/browser/autocomplete/autocomplete_popup_view_gtk.h" |
6 | 6 |
7 #include <gtk/gtk.h> | 7 #include <gtk/gtk.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 422 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
433 | 433 |
434 // Draw the icon for this result time. | 434 // Draw the icon for this result time. |
435 DrawFullPixbuf(drawable, gc, IconForMatch(match, is_selected), | 435 DrawFullPixbuf(drawable, gc, IconForMatch(match, is_selected), |
436 kIconLeftPadding, line_rect.y() + kIconTopPadding); | 436 kIconLeftPadding, line_rect.y() + kIconTopPadding); |
437 | 437 |
438 // Draw the results text vertically centered in the results space. | 438 // Draw the results text vertically centered in the results space. |
439 // First draw the contents / url, but don't let it take up the whole width | 439 // First draw the contents / url, but don't let it take up the whole width |
440 // if there is also a description to be shown. | 440 // if there is also a description to be shown. |
441 bool has_description = !match.description.empty(); | 441 bool has_description = !match.description.empty(); |
442 int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding); | 442 int text_width = window_rect.width() - (kIconAreaWidth + kRightPadding); |
443 int content_width = has_description ? | 443 int allocated_content_width = has_description ? |
444 text_width * kContentWidthPercentage : text_width; | 444 text_width * kContentWidthPercentage : text_width; |
445 pango_layout_set_width(layout_, content_width * PANGO_SCALE); | 445 pango_layout_set_width(layout_, allocated_content_width * PANGO_SCALE); |
446 | 446 |
447 SetupLayoutForMatch(layout_, match.contents, match.contents_class, | 447 SetupLayoutForMatch(layout_, match.contents, match.contents_class, |
448 &kContentTextColor, std::string()); | 448 &kContentTextColor, std::string()); |
449 | 449 |
450 int actual_content_width, actual_content_height; | 450 int actual_content_width, actual_content_height; |
451 pango_layout_get_size(layout_, | 451 pango_layout_get_size(layout_, |
452 &actual_content_width, &actual_content_height); | 452 &actual_content_width, &actual_content_height); |
453 actual_content_width /= PANGO_SCALE; | 453 actual_content_width /= PANGO_SCALE; |
454 actual_content_height /= PANGO_SCALE; | 454 actual_content_height /= PANGO_SCALE; |
455 | 455 |
456 DCHECK_LT(actual_content_height, kHeightPerResult); // Font is too tall. | 456 DCHECK_LT(actual_content_height, kHeightPerResult); // Font is too tall. |
457 // Center the text within the line. | 457 // Center the text within the line. |
458 int content_y = std::max(line_rect.y(), | 458 int content_y = std::max(line_rect.y(), |
459 line_rect.y() + ((kHeightPerResult - actual_content_height) / 2)); | 459 line_rect.y() + ((kHeightPerResult - actual_content_height) / 2)); |
460 | 460 |
461 gdk_draw_layout(drawable, gc, | 461 gdk_draw_layout(drawable, gc, |
462 kIconAreaWidth, content_y, | 462 kIconAreaWidth, content_y, |
463 layout_); | 463 layout_); |
464 | 464 |
465 if (has_description) { | 465 if (has_description) { |
466 pango_layout_set_width(layout_, | 466 pango_layout_set_width(layout_, |
467 (text_width - content_width) * PANGO_SCALE); | 467 (text_width - actual_content_width) * PANGO_SCALE); |
468 SetupLayoutForMatch(layout_, match.description, match.description_class, | 468 SetupLayoutForMatch(layout_, match.description, match.description_class, |
469 is_selected ? &kDescriptionSelectedTextColor : | 469 is_selected ? &kDescriptionSelectedTextColor : |
470 &kDescriptionTextColor, | 470 &kDescriptionTextColor, |
471 std::string(" - ")); | 471 std::string(" - ")); |
472 | 472 |
473 gdk_draw_layout(drawable, gc, | 473 gdk_draw_layout(drawable, gc, |
474 kIconAreaWidth + actual_content_width, content_y, | 474 kIconAreaWidth + actual_content_width, content_y, |
475 layout_); | 475 layout_); |
476 } | 476 } |
477 } | 477 } |
478 | 478 |
479 g_object_unref(gc); | 479 g_object_unref(gc); |
480 | 480 |
481 return TRUE; | 481 return TRUE; |
482 } | 482 } |
OLD | NEW |