OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/location_bar_view_gtk.h" | 5 #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 InstantController* instant = browser_->instant(); | 452 InstantController* instant = browser_->instant(); |
453 if (instant) | 453 if (instant) |
454 instant->OnAutocompleteLostFocus(view_gaining_focus); | 454 instant->OnAutocompleteLostFocus(view_gaining_focus); |
455 } | 455 } |
456 | 456 |
457 void LocationBarViewGtk::OnAutocompleteWillAccept() { | 457 void LocationBarViewGtk::OnAutocompleteWillAccept() { |
458 update_instant_ = false; | 458 update_instant_ = false; |
459 } | 459 } |
460 | 460 |
461 bool LocationBarViewGtk::OnCommitSuggestedText( | 461 bool LocationBarViewGtk::OnCommitSuggestedText( |
462 const std::wstring& typed_text) { | 462 const string16& typed_text) { |
463 return browser_->instant() && location_entry_->CommitInstantSuggestion(); | 463 return browser_->instant() && location_entry_->CommitInstantSuggestion(); |
464 } | 464 } |
465 | 465 |
466 bool LocationBarViewGtk::AcceptCurrentInstantPreview() { | 466 bool LocationBarViewGtk::AcceptCurrentInstantPreview() { |
467 return InstantController::CommitIfCurrent(browser_->instant()); | 467 return InstantController::CommitIfCurrent(browser_->instant()); |
468 } | 468 } |
469 | 469 |
470 void LocationBarViewGtk::OnPopupBoundsChanged(const gfx::Rect& bounds) { | 470 void LocationBarViewGtk::OnPopupBoundsChanged(const gfx::Rect& bounds) { |
471 InstantController* instant = browser_->instant(); | 471 InstantController* instant = browser_->instant(); |
472 if (instant) | 472 if (instant) |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
506 | 506 |
507 if (browser_->instant() && !location_entry_->model()->popup_model()->IsOpen()) | 507 if (browser_->instant() && !location_entry_->model()->popup_model()->IsOpen()) |
508 browser_->instant()->DestroyPreviewContents(); | 508 browser_->instant()->DestroyPreviewContents(); |
509 | 509 |
510 update_instant_ = true; | 510 update_instant_ = true; |
511 } | 511 } |
512 | 512 |
513 void LocationBarViewGtk::OnChanged() { | 513 void LocationBarViewGtk::OnChanged() { |
514 UpdateSiteTypeArea(); | 514 UpdateSiteTypeArea(); |
515 | 515 |
516 const std::wstring keyword(location_entry_->model()->keyword()); | 516 const string16 keyword(location_entry_->model()->keyword()); |
517 const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); | 517 const bool is_keyword_hint = location_entry_->model()->is_keyword_hint(); |
518 show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; | 518 show_selected_keyword_ = !keyword.empty() && !is_keyword_hint; |
519 show_keyword_hint_ = !keyword.empty() && is_keyword_hint; | 519 show_keyword_hint_ = !keyword.empty() && is_keyword_hint; |
520 | 520 |
521 if (show_selected_keyword_) | 521 if (show_selected_keyword_) |
522 SetKeywordLabel(keyword); | 522 SetKeywordLabel(keyword); |
523 | 523 |
524 if (show_keyword_hint_) | 524 if (show_keyword_hint_) |
525 SetKeywordHintLabel(keyword); | 525 SetKeywordHintLabel(keyword); |
526 | 526 |
527 AdjustChildrenVisibility(); | 527 AdjustChildrenVisibility(); |
528 | 528 |
529 InstantController* instant = browser_->instant(); | 529 InstantController* instant = browser_->instant(); |
530 string16 suggested_text; | 530 string16 suggested_text; |
531 if (update_instant_ && instant && GetTabContents()) { | 531 if (update_instant_ && instant && GetTabContents()) { |
532 if (location_entry_->model()->user_input_in_progress() && | 532 if (location_entry_->model()->user_input_in_progress() && |
533 location_entry_->model()->popup_model()->IsOpen()) { | 533 location_entry_->model()->popup_model()->IsOpen()) { |
534 instant->Update( | 534 instant->Update( |
535 browser_->GetSelectedTabContentsWrapper(), | 535 browser_->GetSelectedTabContentsWrapper(), |
536 location_entry_->model()->CurrentMatch(), | 536 location_entry_->model()->CurrentMatch(), |
537 WideToUTF16(location_entry_->GetText()), | 537 location_entry_->GetText(), |
538 location_entry_->model()->UseVerbatimInstant(), | 538 location_entry_->model()->UseVerbatimInstant(), |
539 &suggested_text); | 539 &suggested_text); |
540 if (!instant->MightSupportInstant()) { | 540 if (!instant->MightSupportInstant()) { |
541 location_entry_->model()->FinalizeInstantQuery(std::wstring(), | 541 location_entry_->model()->FinalizeInstantQuery(string16(), |
542 std::wstring()); | 542 string16()); |
543 } | 543 } |
544 } else { | 544 } else { |
545 instant->DestroyPreviewContents(); | 545 instant->DestroyPreviewContents(); |
546 location_entry_->model()->FinalizeInstantQuery(std::wstring(), | 546 location_entry_->model()->FinalizeInstantQuery(string16(), |
547 std::wstring()); | 547 string16()); |
548 } | 548 } |
549 } | 549 } |
550 | 550 |
551 SetSuggestedText(suggested_text); | 551 SetSuggestedText(suggested_text); |
552 } | 552 } |
553 | 553 |
554 void LocationBarViewGtk::OnSelectionBoundsChanged() { | 554 void LocationBarViewGtk::OnSelectionBoundsChanged() { |
555 NOTIMPLEMENTED(); | 555 NOTIMPLEMENTED(); |
556 } | 556 } |
557 | 557 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
599 Details<AccessibilityTextBoxInfo>(&info)); | 599 Details<AccessibilityTextBoxInfo>(&info)); |
600 | 600 |
601 // Update the keyword and search hint states. | 601 // Update the keyword and search hint states. |
602 OnChanged(); | 602 OnChanged(); |
603 } | 603 } |
604 | 604 |
605 SkBitmap LocationBarViewGtk::GetFavIcon() const { | 605 SkBitmap LocationBarViewGtk::GetFavIcon() const { |
606 return GetTabContents()->GetFavIcon(); | 606 return GetTabContents()->GetFavIcon(); |
607 } | 607 } |
608 | 608 |
609 std::wstring LocationBarViewGtk::GetTitle() const { | 609 string16 LocationBarViewGtk::GetTitle() const { |
610 return UTF16ToWideHack(GetTabContents()->GetTitle()); | 610 return GetTabContents()->GetTitle(); |
611 } | 611 } |
612 | 612 |
613 void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { | 613 void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { |
614 // We need the browser window to be shown before we can show the bubble, but | 614 // We need the browser window to be shown before we can show the bubble, but |
615 // we get called before that's happened. | 615 // we get called before that's happened. |
616 Task* task = first_run_bubble_.NewRunnableMethod( | 616 Task* task = first_run_bubble_.NewRunnableMethod( |
617 &LocationBarViewGtk::ShowFirstRunBubbleInternal, bubble_type); | 617 &LocationBarViewGtk::ShowFirstRunBubbleInternal, bubble_type); |
618 MessageLoop::current()->PostTask(FROM_HERE, task); | 618 MessageLoop::current()->PostTask(FROM_HERE, task); |
619 } | 619 } |
620 | 620 |
621 void LocationBarViewGtk::SetSuggestedText(const string16& text) { | 621 void LocationBarViewGtk::SetSuggestedText(const string16& text) { |
622 if (CommandLine::ForCurrentProcess()->HasSwitch( | 622 if (CommandLine::ForCurrentProcess()->HasSwitch( |
623 switches::kInstantAutocompleteImmediately)) { | 623 switches::kInstantAutocompleteImmediately)) { |
624 // This method is internally invoked to reset suggest text, so we only do | 624 // This method is internally invoked to reset suggest text, so we only do |
625 // anything if the text isn't empty. | 625 // anything if the text isn't empty. |
626 // TODO: if we keep autocomplete, make it so this isn't invoked with empty | 626 // TODO: if we keep autocomplete, make it so this isn't invoked with empty |
627 // text. | 627 // text. |
628 if (!text.empty()) { | 628 if (!text.empty()) { |
629 location_entry_->model()->FinalizeInstantQuery( | 629 location_entry_->model()->FinalizeInstantQuery( |
630 location_entry_->GetText(), | 630 location_entry_->GetText(), text); |
631 UTF16ToWide(text)); | |
632 } | 631 } |
633 } else { | 632 } else { |
634 location_entry_->SetInstantSuggestion(text); | 633 location_entry_->SetInstantSuggestion(text); |
635 } | 634 } |
636 } | 635 } |
637 | 636 |
638 std::wstring LocationBarViewGtk::GetInputString() const { | 637 std::wstring LocationBarViewGtk::GetInputString() const { |
639 return location_input_; | 638 return location_input_; |
640 } | 639 } |
641 | 640 |
(...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
964 int max_chars = static_cast<int>(static_cast<float>(text_area) / | 963 int max_chars = static_cast<int>(static_cast<float>(text_area) / |
965 static_cast<float>(char_width) / 2.75); | 964 static_cast<float>(char_width) / 2.75); |
966 // Don't let the label be smaller than 10 characters so that the country | 965 // Don't let the label be smaller than 10 characters so that the country |
967 // code is always visible. | 966 // code is always visible. |
968 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), | 967 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), |
969 std::max(10, max_chars)); | 968 std::max(10, max_chars)); |
970 | 969 |
971 pango_font_metrics_unref(metrics); | 970 pango_font_metrics_unref(metrics); |
972 } | 971 } |
973 | 972 |
974 void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { | 973 void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { |
975 if (keyword.empty()) | 974 if (keyword.empty()) |
976 return; | 975 return; |
977 | 976 |
978 DCHECK(profile_); | 977 DCHECK(profile_); |
979 if (!profile_->GetTemplateURLModel()) | 978 if (!profile_->GetTemplateURLModel()) |
980 return; | 979 return; |
981 | 980 |
982 bool is_extension_keyword; | 981 bool is_extension_keyword; |
983 const string16 short_name = profile_->GetTemplateURLModel()-> | 982 const string16 short_name = profile_->GetTemplateURLModel()-> |
984 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); | 983 GetKeywordShortName(keyword, &is_extension_keyword); |
985 int message_id = is_extension_keyword ? | 984 int message_id = is_extension_keyword ? |
986 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; | 985 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; |
987 string16 full_name = l10n_util::GetStringFUTF16(message_id, | 986 string16 full_name = l10n_util::GetStringFUTF16(message_id, |
988 short_name); | 987 short_name); |
989 string16 partial_name = l10n_util::GetStringFUTF16( | 988 string16 partial_name = l10n_util::GetStringFUTF16( |
990 message_id, | 989 message_id, |
991 WideToUTF16Hack( | 990 WideToUTF16Hack( |
992 location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); | 991 location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); |
993 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), | 992 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), |
994 UTF16ToUTF8(full_name).c_str()); | 993 UTF16ToUTF8(full_name).c_str()); |
995 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), | 994 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), |
996 UTF16ToUTF8(partial_name).c_str()); | 995 UTF16ToUTF8(partial_name).c_str()); |
997 | 996 |
998 if (last_keyword_ != keyword) { | 997 if (last_keyword_ != keyword) { |
999 last_keyword_ = keyword; | 998 last_keyword_ = keyword; |
1000 | 999 |
1001 if (is_extension_keyword) { | 1000 if (is_extension_keyword) { |
1002 const TemplateURL* template_url = | 1001 const TemplateURL* template_url = |
1003 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( | 1002 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); |
1004 WideToUTF16Hack(keyword)); | |
1005 const SkBitmap& bitmap = profile_->GetExtensionService()-> | 1003 const SkBitmap& bitmap = profile_->GetExtensionService()-> |
1006 GetOmniboxIcon(template_url->GetExtensionId()); | 1004 GetOmniboxIcon(template_url->GetExtensionId()); |
1007 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); | 1005 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); |
1008 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), pixbuf); | 1006 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), pixbuf); |
1009 g_object_unref(pixbuf); | 1007 g_object_unref(pixbuf); |
1010 } else { | 1008 } else { |
1011 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1009 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
1012 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), | 1010 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), |
1013 rb.GetPixbufNamed(IDR_OMNIBOX_SEARCH)); | 1011 rb.GetPixbufNamed(IDR_OMNIBOX_SEARCH)); |
1014 } | 1012 } |
1015 } | 1013 } |
1016 } | 1014 } |
1017 | 1015 |
1018 void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) { | 1016 void LocationBarViewGtk::SetKeywordHintLabel(const string16& keyword) { |
1019 if (keyword.empty()) | 1017 if (keyword.empty()) |
1020 return; | 1018 return; |
1021 | 1019 |
1022 DCHECK(profile_); | 1020 DCHECK(profile_); |
1023 if (!profile_->GetTemplateURLModel()) | 1021 if (!profile_->GetTemplateURLModel()) |
1024 return; | 1022 return; |
1025 | 1023 |
1026 bool is_extension_keyword; | 1024 bool is_extension_keyword; |
1027 const string16 short_name = profile_->GetTemplateURLModel()-> | 1025 const string16 short_name = profile_->GetTemplateURLModel()-> |
1028 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); | 1026 GetKeywordShortName(keyword, &is_extension_keyword); |
1029 int message_id = is_extension_keyword ? | 1027 int message_id = is_extension_keyword ? |
1030 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; | 1028 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; |
1031 std::vector<size_t> content_param_offsets; | 1029 std::vector<size_t> content_param_offsets; |
1032 const string16 keyword_hint = l10n_util::GetStringFUTF16( | 1030 const string16 keyword_hint = l10n_util::GetStringFUTF16( |
1033 message_id, | 1031 message_id, |
1034 string16(), | 1032 string16(), |
1035 short_name, | 1033 short_name, |
1036 &content_param_offsets); | 1034 &content_param_offsets); |
1037 if (content_param_offsets.size() != 2) { | 1035 if (content_param_offsets.size() != 2) { |
1038 // See comments on an identical NOTREACHED() in search_provider.cc. | 1036 // See comments on an identical NOTREACHED() in search_provider.cc. |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1122 ui::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); | 1120 ui::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); |
1123 } | 1121 } |
1124 | 1122 |
1125 void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, | 1123 void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, |
1126 GdkDragContext* context) { | 1124 GdkDragContext* context) { |
1127 SkBitmap favicon = GetFavIcon(); | 1125 SkBitmap favicon = GetFavIcon(); |
1128 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&favicon); | 1126 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&favicon); |
1129 if (!pixbuf) | 1127 if (!pixbuf) |
1130 return; | 1128 return; |
1131 drag_icon_ = bookmark_utils::GetDragRepresentation(pixbuf, | 1129 drag_icon_ = bookmark_utils::GetDragRepresentation(pixbuf, |
1132 WideToUTF16(GetTitle()), theme_provider_); | 1130 GetTitle(), theme_provider_); |
1133 g_object_unref(pixbuf); | 1131 g_object_unref(pixbuf); |
1134 gtk_drag_set_icon_widget(context, drag_icon_, 0, 0); | 1132 gtk_drag_set_icon_widget(context, drag_icon_, 0, 0); |
1135 } | 1133 } |
1136 | 1134 |
1137 void LocationBarViewGtk::OnIconDragEnd(GtkWidget* sender, | 1135 void LocationBarViewGtk::OnIconDragEnd(GtkWidget* sender, |
1138 GdkDragContext* context) { | 1136 GdkDragContext* context) { |
1139 DCHECK(drag_icon_); | 1137 DCHECK(drag_icon_); |
1140 gtk_widget_destroy(drag_icon_); | 1138 gtk_widget_destroy(drag_icon_); |
1141 drag_icon_ = NULL; | 1139 drag_icon_ = NULL; |
1142 } | 1140 } |
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1543 | 1541 |
1544 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1542 std::string badge_text = page_action_->GetBadgeText(tab_id); |
1545 if (badge_text.empty()) | 1543 if (badge_text.empty()) |
1546 return FALSE; | 1544 return FALSE; |
1547 | 1545 |
1548 gfx::CanvasSkiaPaint canvas(event, false); | 1546 gfx::CanvasSkiaPaint canvas(event, false); |
1549 gfx::Rect bounding_rect(widget->allocation); | 1547 gfx::Rect bounding_rect(widget->allocation); |
1550 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1548 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
1551 return FALSE; | 1549 return FALSE; |
1552 } | 1550 } |
OLD | NEW |