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/omnibox/omnibox_popup_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/omnibox/omnibox_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 #include <string> | 10 #include <string> |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
329 // Stop listening to our signals before we destroy the model. I suspect that | 329 // Stop listening to our signals before we destroy the model. I suspect that |
330 // we can race window destruction, otherwise. | 330 // we can race window destruction, otherwise. |
331 signal_registrar_.reset(); | 331 signal_registrar_.reset(); |
332 | 332 |
333 // Explicitly destroy our model here, before we destroy our GTK widgets. | 333 // Explicitly destroy our model here, before we destroy our GTK widgets. |
334 // This is because the model destructor can call back into us, and we need | 334 // This is because the model destructor can call back into us, and we need |
335 // to make sure everything is still valid when it does. | 335 // to make sure everything is still valid when it does. |
336 model_.reset(); | 336 model_.reset(); |
337 g_object_unref(layout_); | 337 g_object_unref(layout_); |
338 gtk_widget_destroy(window_); | 338 gtk_widget_destroy(window_); |
339 | |
340 for (ImageMap::iterator it = images_.begin(); it != images_.end(); ++it) | |
341 delete it->second; | |
342 } | 339 } |
343 | 340 |
344 bool OmniboxPopupViewGtk::IsOpen() const { | 341 bool OmniboxPopupViewGtk::IsOpen() const { |
345 return opened_; | 342 return opened_; |
346 } | 343 } |
347 | 344 |
348 void OmniboxPopupViewGtk::InvalidateLine(size_t line) { | 345 void OmniboxPopupViewGtk::InvalidateLine(size_t line) { |
349 // TODO(deanm): Is it possible to use some constant for the width, instead | 346 // TODO(deanm): Is it possible to use some constant for the width, instead |
350 // of having to query the width of the window? | 347 // of having to query the width of the window? |
351 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); | 348 GdkWindow* gdk_window = gtk_widget_get_window(GTK_WIDGET(window_)); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
476 | 473 |
477 void OmniboxPopupViewGtk::AcceptLine(size_t line, | 474 void OmniboxPopupViewGtk::AcceptLine(size_t line, |
478 WindowOpenDisposition disposition) { | 475 WindowOpenDisposition disposition) { |
479 // OpenMatch() may close the popup, which will clear the result set and, by | 476 // OpenMatch() may close the popup, which will clear the result set and, by |
480 // extension, |match| and its contents. So copy the relevant match out to | 477 // extension, |match| and its contents. So copy the relevant match out to |
481 // make sure it stays alive until the call completes. | 478 // make sure it stays alive until the call completes. |
482 AutocompleteMatch match = model_->result().match_at(line); | 479 AutocompleteMatch match = model_->result().match_at(line); |
483 omnibox_view_->OpenMatch(match, disposition, GURL(), line); | 480 omnibox_view_->OpenMatch(match, disposition, GURL(), line); |
484 } | 481 } |
485 | 482 |
486 const gfx::Image* OmniboxPopupViewGtk::IconForMatch( | 483 gfx::Image OmniboxPopupViewGtk::IconForMatch( |
487 const AutocompleteMatch& match, | 484 const AutocompleteMatch& match, |
488 bool selected, | 485 bool selected, |
489 bool is_selected_keyword) { | 486 bool is_selected_keyword) { |
490 const SkBitmap* bitmap = model_->GetIconIfExtensionMatch(match); | 487 const gfx::Image image = model_->GetIconIfExtensionMatch(match); |
491 if (bitmap) { | 488 if (!image.IsEmpty()) |
492 if (!ContainsKey(images_, bitmap)) { | 489 return image; |
493 // gfx::Image wants ownership of bitmaps given to it, and we might as | |
494 // well make the bitmap copy a format that will be used. | |
495 images_[bitmap] = new gfx::Image(gfx::GdkPixbufFromSkBitmap(*bitmap)); | |
496 } | |
497 return images_[bitmap]; | |
498 } | |
499 | 490 |
500 int icon; | 491 int icon; |
501 if (is_selected_keyword) | 492 if (is_selected_keyword) |
502 icon = IDR_OMNIBOX_TTS; | 493 icon = IDR_OMNIBOX_TTS; |
503 else if (match.starred) | 494 else if (match.starred) |
504 icon = IDR_OMNIBOX_STAR; | 495 icon = IDR_OMNIBOX_STAR; |
505 else | 496 else |
506 icon = AutocompleteMatch::TypeToIcon(match.type); | 497 icon = AutocompleteMatch::TypeToIcon(match.type); |
507 | 498 |
508 if (selected) { | 499 if (selected) { |
(...skipping 12 matching lines...) Expand all Loading... |
521 break; | 512 break; |
522 case IDR_OMNIBOX_TTS: | 513 case IDR_OMNIBOX_TTS: |
523 icon = IDR_OMNIBOX_TTS_DARK; | 514 icon = IDR_OMNIBOX_TTS_DARK; |
524 break; | 515 break; |
525 default: | 516 default: |
526 NOTREACHED(); | 517 NOTREACHED(); |
527 break; | 518 break; |
528 } | 519 } |
529 } | 520 } |
530 | 521 |
531 return theme_service_->GetImageNamed(icon); | 522 return *theme_service_->GetImageNamed(icon); |
532 } | 523 } |
533 | 524 |
534 void OmniboxPopupViewGtk::GetVisibleMatchForInput( | 525 void OmniboxPopupViewGtk::GetVisibleMatchForInput( |
535 size_t index, | 526 size_t index, |
536 const AutocompleteMatch** match, | 527 const AutocompleteMatch** match, |
537 bool* is_selected_keyword) { | 528 bool* is_selected_keyword) { |
538 const AutocompleteResult& result = model_->result(); | 529 const AutocompleteResult& result = model_->result(); |
539 | 530 |
540 if (result.match_at(index).associated_keyword.get() && | 531 if (result.match_at(index).associated_keyword.get() && |
541 model_->selected_line() == index && | 532 model_->selected_line() == index && |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
720 cairo_restore(cr); | 711 cairo_restore(cr); |
721 } | 712 } |
722 | 713 |
723 if (match->associated_keyword.get()) { | 714 if (match->associated_keyword.get()) { |
724 // If this entry has an associated keyword, draw the arrow at the extreme | 715 // If this entry has an associated keyword, draw the arrow at the extreme |
725 // other side of the omnibox. | 716 // other side of the omnibox. |
726 icon_start_x = ltr ? (line_rect.width() - kIconLeftPadding - kIconWidth) : | 717 icon_start_x = ltr ? (line_rect.width() - kIconLeftPadding - kIconWidth) : |
727 kIconLeftPadding; | 718 kIconLeftPadding; |
728 // Draw the icon for this result. | 719 // Draw the icon for this result. |
729 gtk_util::DrawFullImage(cr, widget, | 720 gtk_util::DrawFullImage(cr, widget, |
730 theme_service_->GetImageNamed( | 721 *theme_service_->GetImageNamed( |
731 is_selected ? IDR_OMNIBOX_TTS_DARK : | 722 is_selected ? IDR_OMNIBOX_TTS_DARK : |
732 IDR_OMNIBOX_TTS), | 723 IDR_OMNIBOX_TTS), |
733 icon_start_x, line_rect.y() + kIconTopPadding); | 724 icon_start_x, line_rect.y() + kIconTopPadding); |
734 } | 725 } |
735 } | 726 } |
736 | 727 |
737 cairo_destroy(cr); | 728 cairo_destroy(cr); |
738 return TRUE; | 729 return TRUE; |
739 } | 730 } |
OLD | NEW |