| 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 string16& typed_text) { | 462 const std::wstring& 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 string16 keyword(location_entry_->model()->keyword()); | 516 const std::wstring 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 location_entry_->GetText(), | 537 WideToUTF16(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(string16(), | 541 location_entry_->model()->FinalizeInstantQuery(std::wstring(), |
| 542 string16()); | 542 std::wstring()); |
| 543 } | 543 } |
| 544 } else { | 544 } else { |
| 545 instant->DestroyPreviewContents(); | 545 instant->DestroyPreviewContents(); |
| 546 location_entry_->model()->FinalizeInstantQuery(string16(), | 546 location_entry_->model()->FinalizeInstantQuery(std::wstring(), |
| 547 string16()); | 547 std::wstring()); |
| 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 string16 LocationBarViewGtk::GetTitle() const { | 609 std::wstring LocationBarViewGtk::GetTitle() const { |
| 610 return GetTabContents()->GetTitle(); | 610 return UTF16ToWideHack(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(), text); | 630 location_entry_->GetText(), |
| 631 UTF16ToWide(text)); |
| 631 } | 632 } |
| 632 } else { | 633 } else { |
| 633 location_entry_->SetInstantSuggestion(text); | 634 location_entry_->SetInstantSuggestion(text); |
| 634 } | 635 } |
| 635 } | 636 } |
| 636 | 637 |
| 637 std::wstring LocationBarViewGtk::GetInputString() const { | 638 std::wstring LocationBarViewGtk::GetInputString() const { |
| 638 return location_input_; | 639 return location_input_; |
| 639 } | 640 } |
| 640 | 641 |
| (...skipping 322 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 int max_chars = static_cast<int>(static_cast<float>(text_area) / | 964 int max_chars = static_cast<int>(static_cast<float>(text_area) / |
| 964 static_cast<float>(char_width) / 2.75); | 965 static_cast<float>(char_width) / 2.75); |
| 965 // Don't let the label be smaller than 10 characters so that the country | 966 // Don't let the label be smaller than 10 characters so that the country |
| 966 // code is always visible. | 967 // code is always visible. |
| 967 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), | 968 gtk_label_set_max_width_chars(GTK_LABEL(security_info_label_), |
| 968 std::max(10, max_chars)); | 969 std::max(10, max_chars)); |
| 969 | 970 |
| 970 pango_font_metrics_unref(metrics); | 971 pango_font_metrics_unref(metrics); |
| 971 } | 972 } |
| 972 | 973 |
| 973 void LocationBarViewGtk::SetKeywordLabel(const string16& keyword) { | 974 void LocationBarViewGtk::SetKeywordLabel(const std::wstring& keyword) { |
| 974 if (keyword.empty()) | 975 if (keyword.empty()) |
| 975 return; | 976 return; |
| 976 | 977 |
| 977 DCHECK(profile_); | 978 DCHECK(profile_); |
| 978 if (!profile_->GetTemplateURLModel()) | 979 if (!profile_->GetTemplateURLModel()) |
| 979 return; | 980 return; |
| 980 | 981 |
| 981 bool is_extension_keyword; | 982 bool is_extension_keyword; |
| 982 const string16 short_name = profile_->GetTemplateURLModel()-> | 983 const string16 short_name = profile_->GetTemplateURLModel()-> |
| 983 GetKeywordShortName(keyword, &is_extension_keyword); | 984 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); |
| 984 int message_id = is_extension_keyword ? | 985 int message_id = is_extension_keyword ? |
| 985 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; | 986 IDS_OMNIBOX_EXTENSION_KEYWORD_TEXT : IDS_OMNIBOX_KEYWORD_TEXT; |
| 986 string16 full_name = l10n_util::GetStringFUTF16(message_id, | 987 string16 full_name = l10n_util::GetStringFUTF16(message_id, |
| 987 short_name); | 988 short_name); |
| 988 string16 partial_name = l10n_util::GetStringFUTF16( | 989 string16 partial_name = l10n_util::GetStringFUTF16( |
| 989 message_id, | 990 message_id, |
| 990 WideToUTF16Hack( | 991 WideToUTF16Hack( |
| 991 location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); | 992 location_bar_util::CalculateMinString(UTF16ToWideHack(short_name)))); |
| 992 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), | 993 gtk_label_set_text(GTK_LABEL(tab_to_search_full_label_), |
| 993 UTF16ToUTF8(full_name).c_str()); | 994 UTF16ToUTF8(full_name).c_str()); |
| 994 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), | 995 gtk_label_set_text(GTK_LABEL(tab_to_search_partial_label_), |
| 995 UTF16ToUTF8(partial_name).c_str()); | 996 UTF16ToUTF8(partial_name).c_str()); |
| 996 | 997 |
| 997 if (last_keyword_ != keyword) { | 998 if (last_keyword_ != keyword) { |
| 998 last_keyword_ = keyword; | 999 last_keyword_ = keyword; |
| 999 | 1000 |
| 1000 if (is_extension_keyword) { | 1001 if (is_extension_keyword) { |
| 1001 const TemplateURL* template_url = | 1002 const TemplateURL* template_url = |
| 1002 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword(keyword); | 1003 profile_->GetTemplateURLModel()->GetTemplateURLForKeyword( |
| 1004 WideToUTF16Hack(keyword)); |
| 1003 const SkBitmap& bitmap = profile_->GetExtensionService()-> | 1005 const SkBitmap& bitmap = profile_->GetExtensionService()-> |
| 1004 GetOmniboxIcon(template_url->GetExtensionId()); | 1006 GetOmniboxIcon(template_url->GetExtensionId()); |
| 1005 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); | 1007 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&bitmap); |
| 1006 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), pixbuf); | 1008 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), pixbuf); |
| 1007 g_object_unref(pixbuf); | 1009 g_object_unref(pixbuf); |
| 1008 } else { | 1010 } else { |
| 1009 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); | 1011 ResourceBundle& rb = ResourceBundle::GetSharedInstance(); |
| 1010 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), | 1012 gtk_image_set_from_pixbuf(GTK_IMAGE(tab_to_search_magnifier_), |
| 1011 rb.GetPixbufNamed(IDR_OMNIBOX_SEARCH)); | 1013 rb.GetPixbufNamed(IDR_OMNIBOX_SEARCH)); |
| 1012 } | 1014 } |
| 1013 } | 1015 } |
| 1014 } | 1016 } |
| 1015 | 1017 |
| 1016 void LocationBarViewGtk::SetKeywordHintLabel(const string16& keyword) { | 1018 void LocationBarViewGtk::SetKeywordHintLabel(const std::wstring& keyword) { |
| 1017 if (keyword.empty()) | 1019 if (keyword.empty()) |
| 1018 return; | 1020 return; |
| 1019 | 1021 |
| 1020 DCHECK(profile_); | 1022 DCHECK(profile_); |
| 1021 if (!profile_->GetTemplateURLModel()) | 1023 if (!profile_->GetTemplateURLModel()) |
| 1022 return; | 1024 return; |
| 1023 | 1025 |
| 1024 bool is_extension_keyword; | 1026 bool is_extension_keyword; |
| 1025 const string16 short_name = profile_->GetTemplateURLModel()-> | 1027 const string16 short_name = profile_->GetTemplateURLModel()-> |
| 1026 GetKeywordShortName(keyword, &is_extension_keyword); | 1028 GetKeywordShortName(WideToUTF16Hack(keyword), &is_extension_keyword); |
| 1027 int message_id = is_extension_keyword ? | 1029 int message_id = is_extension_keyword ? |
| 1028 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; | 1030 IDS_OMNIBOX_EXTENSION_KEYWORD_HINT : IDS_OMNIBOX_KEYWORD_HINT; |
| 1029 std::vector<size_t> content_param_offsets; | 1031 std::vector<size_t> content_param_offsets; |
| 1030 const string16 keyword_hint = l10n_util::GetStringFUTF16( | 1032 const string16 keyword_hint = l10n_util::GetStringFUTF16( |
| 1031 message_id, | 1033 message_id, |
| 1032 string16(), | 1034 string16(), |
| 1033 short_name, | 1035 short_name, |
| 1034 &content_param_offsets); | 1036 &content_param_offsets); |
| 1035 if (content_param_offsets.size() != 2) { | 1037 if (content_param_offsets.size() != 2) { |
| 1036 // See comments on an identical NOTREACHED() in search_provider.cc. | 1038 // See comments on an identical NOTREACHED() in search_provider.cc. |
| (...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1120 ui::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); | 1122 ui::WriteURLWithName(data, tab->GetURL(), tab->GetTitle(), info); |
| 1121 } | 1123 } |
| 1122 | 1124 |
| 1123 void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, | 1125 void LocationBarViewGtk::OnIconDragBegin(GtkWidget* sender, |
| 1124 GdkDragContext* context) { | 1126 GdkDragContext* context) { |
| 1125 SkBitmap favicon = GetFavIcon(); | 1127 SkBitmap favicon = GetFavIcon(); |
| 1126 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&favicon); | 1128 GdkPixbuf* pixbuf = gfx::GdkPixbufFromSkBitmap(&favicon); |
| 1127 if (!pixbuf) | 1129 if (!pixbuf) |
| 1128 return; | 1130 return; |
| 1129 drag_icon_ = bookmark_utils::GetDragRepresentation(pixbuf, | 1131 drag_icon_ = bookmark_utils::GetDragRepresentation(pixbuf, |
| 1130 GetTitle(), theme_provider_); | 1132 WideToUTF16(GetTitle()), theme_provider_); |
| 1131 g_object_unref(pixbuf); | 1133 g_object_unref(pixbuf); |
| 1132 gtk_drag_set_icon_widget(context, drag_icon_, 0, 0); | 1134 gtk_drag_set_icon_widget(context, drag_icon_, 0, 0); |
| 1133 } | 1135 } |
| 1134 | 1136 |
| 1135 void LocationBarViewGtk::OnIconDragEnd(GtkWidget* sender, | 1137 void LocationBarViewGtk::OnIconDragEnd(GtkWidget* sender, |
| 1136 GdkDragContext* context) { | 1138 GdkDragContext* context) { |
| 1137 DCHECK(drag_icon_); | 1139 DCHECK(drag_icon_); |
| 1138 gtk_widget_destroy(drag_icon_); | 1140 gtk_widget_destroy(drag_icon_); |
| 1139 drag_icon_ = NULL; | 1141 drag_icon_ = NULL; |
| 1140 } | 1142 } |
| (...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1541 | 1543 |
| 1542 std::string badge_text = page_action_->GetBadgeText(tab_id); | 1544 std::string badge_text = page_action_->GetBadgeText(tab_id); |
| 1543 if (badge_text.empty()) | 1545 if (badge_text.empty()) |
| 1544 return FALSE; | 1546 return FALSE; |
| 1545 | 1547 |
| 1546 gfx::CanvasSkiaPaint canvas(event, false); | 1548 gfx::CanvasSkiaPaint canvas(event, false); |
| 1547 gfx::Rect bounding_rect(widget->allocation); | 1549 gfx::Rect bounding_rect(widget->allocation); |
| 1548 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); | 1550 page_action_->PaintBadge(&canvas, bounding_rect, tab_id); |
| 1549 return FALSE; | 1551 return FALSE; |
| 1550 } | 1552 } |
| OLD | NEW |