summaryrefslogtreecommitdiffstats
path: root/chrome/browser/gtk/location_bar_view_gtk.cc
diff options
context:
space:
mode:
Diffstat (limited to 'chrome/browser/gtk/location_bar_view_gtk.cc')
-rw-r--r--chrome/browser/gtk/location_bar_view_gtk.cc140
1 files changed, 103 insertions, 37 deletions
diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc
index 6f02d2c..b207665 100644
--- a/chrome/browser/gtk/location_bar_view_gtk.cc
+++ b/chrome/browser/gtk/location_bar_view_gtk.cc
@@ -14,10 +14,11 @@
#include "base/logging.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
-#include "chrome/app/chrome_dll_resource.h"
+#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/accessibility_events.h"
#include "chrome/browser/alternate_nav_url_fetcher.h"
#include "chrome/browser/autocomplete/autocomplete_edit_view_gtk.h"
+#include "chrome/browser/autocomplete/autocomplete_popup_model.h"
#include "chrome/browser/browser.h"
#include "chrome/browser/browser_list.h"
#include "chrome/browser/command_updater.h"
@@ -38,6 +39,7 @@
#include "chrome/browser/gtk/nine_box.h"
#include "chrome/browser/gtk/rounded_window.h"
#include "chrome/browser/gtk/view_id_util.h"
+#include "chrome/browser/instant/instant_controller.h"
#include "chrome/browser/location_bar_util.h"
#include "chrome/browser/profile.h"
#include "chrome/browser/search_engines/template_url.h"
@@ -143,7 +145,8 @@ LocationBarViewGtk::LocationBarViewGtk(Browser* browser)
hbox_width_(0),
entry_box_width_(0),
show_selected_keyword_(false),
- show_keyword_hint_(false) {
+ show_keyword_hint_(false),
+ update_instant_(true) {
}
LocationBarViewGtk::~LocationBarViewGtk() {
@@ -429,39 +432,87 @@ void LocationBarViewGtk::Update(const TabContents* contents) {
}
}
-void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
- WindowOpenDisposition disposition,
- PageTransition::Type transition,
- const GURL& alternate_nav_url) {
- if (!url.is_valid())
+void LocationBarViewGtk::OnAutocompleteWillClosePopup() {
+ if (!update_instant_)
return;
- location_input_ = UTF8ToWide(url.spec());
- disposition_ = disposition;
- transition_ = transition;
+ InstantController* instant = browser_->instant();
+ if (instant && !instant->commit_on_mouse_up())
+ instant->DestroyPreviewContents();
+}
- if (!command_updater_)
- return;
+void LocationBarViewGtk::OnAutocompleteLosingFocus(
+ gfx::NativeView view_gaining_focus) {
+ SetSuggestedText(string16());
- if (!alternate_nav_url.is_valid()) {
- command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
- return;
- }
+ InstantController* instant = browser_->instant();
+ if (instant)
+ instant->OnAutocompleteLostFocus(view_gaining_focus);
+}
- AlternateNavURLFetcher* fetcher =
- new AlternateNavURLFetcher(alternate_nav_url);
- // The AlternateNavURLFetcher will listen for the pending navigation
- // notification that will be issued as a result of the "open URL." It
- // will automatically install itself into that navigation controller.
- command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
- if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
- // I'm not sure this should be reachable, but I'm not also sure enough
- // that it shouldn't to stick in a NOTREACHED(). In any case, this is
- // harmless.
- delete fetcher;
- } else {
- // The navigation controller will delete the fetcher.
+void LocationBarViewGtk::OnAutocompleteWillAccept() {
+ update_instant_ = false;
+}
+
+bool LocationBarViewGtk::OnCommitSuggestedText(
+ const std::wstring& typed_text) {
+ InstantController* instant = browser_->instant();
+ if (!instant)
+ return false;
+
+ bool updating_instant = update_instant_;
+ update_instant_ = false;
+ bool rv = location_entry_->CommitInstantSuggestion();
+ update_instant_ = updating_instant;
+ return rv;
+}
+
+void LocationBarViewGtk::OnSetSuggestedSearchText(
+ const string16& suggested_text) {
+ SetSuggestedText(suggested_text);
+}
+
+void LocationBarViewGtk::OnPopupBoundsChanged(const gfx::Rect& bounds) {
+ InstantController* instant = browser_->instant();
+ if (instant)
+ instant->SetOmniboxBounds(bounds);
+}
+
+void LocationBarViewGtk::OnAutocompleteAccept(const GURL& url,
+ WindowOpenDisposition disposition,
+ PageTransition::Type transition,
+ const GURL& alternate_nav_url) {
+ if (url.is_valid()) {
+ location_input_ = UTF8ToWide(url.spec());
+ disposition_ = disposition;
+ transition_ = transition;
+
+ if (command_updater_) {
+ if (!alternate_nav_url.is_valid()) {
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ } else {
+ AlternateNavURLFetcher* fetcher =
+ new AlternateNavURLFetcher(alternate_nav_url);
+ // The AlternateNavURLFetcher will listen for the pending navigation
+ // notification that will be issued as a result of the "open URL." It
+ // will automatically install itself into that navigation controller.
+ command_updater_->ExecuteCommand(IDC_OPEN_CURRENT_URL);
+ if (fetcher->state() == AlternateNavURLFetcher::NOT_STARTED) {
+ // I'm not sure this should be reachable, but I'm not also sure enough
+ // that it shouldn't to stick in a NOTREACHED(). In any case, this is
+ // harmless.
+ delete fetcher;
+ } else {
+ // The navigation controller will delete the fetcher.
+ }
+ }
+ }
}
+
+ if (browser_->instant())
+ browser_->instant()->DestroyPreviewContents();
+
+ update_instant_ = true;
}
void LocationBarViewGtk::OnChanged() {
@@ -479,6 +530,22 @@ void LocationBarViewGtk::OnChanged() {
SetKeywordHintLabel(keyword);
AdjustChildrenVisibility();
+
+ InstantController* instant = browser_->instant();
+ string16 suggested_text;
+ if (update_instant_ && instant && GetTabContents()) {
+ if (location_entry_->model()->user_input_in_progress() &&
+ location_entry_->model()->popup_model()->IsOpen()) {
+ instant->Update(GetTabContents(),
+ location_entry_->model()->CurrentMatch(),
+ WideToUTF16(location_entry_->GetText()),
+ &suggested_text);
+ } else {
+ instant->DestroyPreviewContents();
+ }
+ }
+
+ SetSuggestedText(suggested_text);
}
void LocationBarViewGtk::CreateStarButton() {
@@ -545,8 +612,7 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) {
}
void LocationBarViewGtk::SetSuggestedText(const string16& text) {
- // TODO: implement me.
- NOTIMPLEMENTED();
+ location_entry_->SetInstantSuggestion(UTF16ToUTF8(text));
}
std::wstring LocationBarViewGtk::GetInputString() const {
@@ -742,8 +808,8 @@ void LocationBarViewGtk::Observe(NotificationType type,
gtk_util::SetRoundedWindowBorderColor(tab_to_search_box_,
kKeywordBorderColor);
- gtk_util::SetLabelColor(tab_to_search_full_label_, &gfx::kGdkBlack);
- gtk_util::SetLabelColor(tab_to_search_partial_label_, &gfx::kGdkBlack);
+ gtk_util::SetLabelColor(tab_to_search_full_label_, &gtk_util::kGdkBlack);
+ gtk_util::SetLabelColor(tab_to_search_partial_label_, &gtk_util::kGdkBlack);
gtk_util::SetLabelColor(tab_to_search_hint_leading_label_,
&kHintTextColor);
gtk_util::SetLabelColor(tab_to_search_hint_trailing_label_,
@@ -1261,8 +1327,8 @@ LocationBarViewGtk::PageActionViewGtk::PageActionViewGtk(
image_.Own(gtk_image_new());
gtk_container_add(GTK_CONTAINER(event_box_.get()), image_.get());
- Extension* extension = profile->GetExtensionsService()->GetExtensionById(
- page_action->extension_id(), false);
+ const Extension* extension = profile->GetExtensionsService()->
+ GetExtensionById(page_action->extension_id(), false);
DCHECK(extension);
// Load all the icons declared in the manifest. This is the contents of the
@@ -1425,8 +1491,8 @@ gboolean LocationBarViewGtk::PageActionViewGtk::OnButtonPressed(
event->button.button);
}
} else {
- Extension* extension = profile_->GetExtensionsService()->GetExtensionById(
- page_action()->extension_id(), false);
+ const Extension* extension = profile_->GetExtensionsService()->
+ GetExtensionById(page_action()->extension_id(), false);
context_menu_model_ =
new ExtensionContextMenuModel(extension, owner_->browser_, this);