diff options
author | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 00:11:45 +0000 |
---|---|---|
committer | estade@chromium.org <estade@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-26 00:11:45 +0000 |
commit | cb592c2a727cb7e9609a4b5dccf4e719ab120088 (patch) | |
tree | 634df95c265416d3b7c13012d76addcae7c49350 /chrome/browser/gtk | |
parent | b6d26b3107989c5300ffbf3a2e2f56d60bf6906e (diff) | |
download | chromium_src-cb592c2a727cb7e9609a4b5dccf4e719ab120088.zip chromium_src-cb592c2a727cb7e9609a4b5dccf4e719ab120088.tar.gz chromium_src-cb592c2a727cb7e9609a4b5dccf4e719ab120088.tar.bz2 |
[linux] instant search/browsing first cut
Implements the tab contents switching stuff (but not the suggestion text bit).
BUG=58937
TEST=manual (must be enabled in about:flags)
Review URL: http://codereview.chromium.org/4049002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@63815 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/gtk')
-rw-r--r-- | chrome/browser/gtk/browser_window_gtk.cc | 10 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.cc | 49 | ||||
-rw-r--r-- | chrome/browser/gtk/location_bar_view_gtk.h | 16 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.cc | 140 | ||||
-rw-r--r-- | chrome/browser/gtk/tab_contents_container_gtk.h | 28 |
5 files changed, 165 insertions, 78 deletions
diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index 1bbc883..1dfc8f3 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -1137,19 +1137,15 @@ void BrowserWindowGtk::Paste() { } void BrowserWindowGtk::ShowInstant(TabContents* preview_contents) { - // TODO: implement me - NOTIMPLEMENTED(); + contents_container_->SetPreviewContents(preview_contents); } void BrowserWindowGtk::HideInstant() { - // TODO: implement me - NOTIMPLEMENTED(); + contents_container_->PopPreviewContents(); } gfx::Rect BrowserWindowGtk::GetInstantBounds() { - // TODO: implement me - NOTIMPLEMENTED(); - return gfx::Rect(); + return gtk_util::GetWidgetScreenBounds(contents_container_->widget()); } void BrowserWindowGtk::ConfirmBrowserCloseWithPendingDownloads() { diff --git a/chrome/browser/gtk/location_bar_view_gtk.cc b/chrome/browser/gtk/location_bar_view_gtk.cc index 6f02d2c..9b10305 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.cc +++ b/chrome/browser/gtk/location_bar_view_gtk.cc @@ -18,6 +18,7 @@ #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,6 +432,31 @@ void LocationBarViewGtk::Update(const TabContents* contents) { } } +void LocationBarViewGtk::OnAutocompleteWillClosePopup() { + // TODO(estade): implement me. +} + +void LocationBarViewGtk::OnAutocompleteLosingFocus( + gfx::NativeView view_gaining_focus) { + // TODO(estade): implement me. +} + +void LocationBarViewGtk::OnAutocompleteWillAccept() { + // TODO(estade): implement me. +} + +bool LocationBarViewGtk::OnCommitSuggestedText( + const std::wstring& typed_text) { + // TODO(estade): implement me. + return false; +} + +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, @@ -479,6 +507,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 +589,7 @@ void LocationBarViewGtk::ShowFirstRunBubble(FirstRun::BubbleType bubble_type) { } void LocationBarViewGtk::SetSuggestedText(const string16& text) { - // TODO: implement me. - NOTIMPLEMENTED(); + // TODO(estade): implement me. } std::wstring LocationBarViewGtk::GetInputString() const { diff --git a/chrome/browser/gtk/location_bar_view_gtk.h b/chrome/browser/gtk/location_bar_view_gtk.h index a0a3484..c9045c1 100644 --- a/chrome/browser/gtk/location_bar_view_gtk.h +++ b/chrome/browser/gtk/location_bar_view_gtk.h @@ -88,13 +88,11 @@ class LocationBarViewGtk : public AutocompleteEditController, void SetStarred(bool starred); // Implement the AutocompleteEditController interface. - virtual void OnAutocompleteWillClosePopup() {} - virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus) {} - virtual void OnAutocompleteWillAccept() {} - virtual bool OnCommitSuggestedText(const std::wstring& typed_text) { - return false; - } - virtual void OnPopupBoundsChanged(const gfx::Rect& bounds) {} + virtual void OnAutocompleteWillClosePopup(); + virtual void OnAutocompleteLosingFocus(gfx::NativeView view_gaining_focus); + virtual void OnAutocompleteWillAccept(); + virtual bool OnCommitSuggestedText(const std::wstring& typed_text); + virtual void OnPopupBoundsChanged(const gfx::Rect& bounds); virtual void OnAutocompleteAccept(const GURL& url, WindowOpenDisposition disposition, PageTransition::Type transition, @@ -421,6 +419,10 @@ class LocationBarViewGtk : public AutocompleteEditController, // The last search keyword that was shown via the |tab_to_search_box_|. std::wstring last_keyword_; + // True if instant search should be updated. Copied from Views. For now, it + // is always true. + bool update_instant_; + DISALLOW_COPY_AND_ASSIGN(LocationBarViewGtk); }; diff --git a/chrome/browser/gtk/tab_contents_container_gtk.cc b/chrome/browser/gtk/tab_contents_container_gtk.cc index 1f4a3cc..48ca9e2 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/gtk/tab_contents_container_gtk.cc @@ -15,6 +15,7 @@ TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) : tab_contents_(NULL), + preview_contents_(NULL), status_bubble_(status_bubble) { Init(); } @@ -57,54 +58,101 @@ void TabContentsContainerGtk::Init() { } void TabContentsContainerGtk::SetTabContents(TabContents* tab_contents) { + HideTabContents(tab_contents_); if (tab_contents_) { - gfx::NativeView widget = tab_contents_->GetNativeView(); - if (widget) - gtk_widget_hide(widget); - - tab_contents_->WasHidden(); - - registrar_.Remove(this, NotificationType::RENDER_VIEW_HOST_CHANGED, - Source<NavigationController>(&tab_contents_->controller())); registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, Source<TabContents>(tab_contents_)); } tab_contents_ = tab_contents; - // When detaching the last tab of the browser SetTabContents is invoked - // with NULL. Don't attempt to do anything in that case. - if (tab_contents_) { - // TabContents can change their RenderViewHost and hence the GtkWidget that - // is shown. I'm not entirely sure that we need to observe this event under - // GTK, but am putting a stub implementation and a comment saying that if - // we crash after that NOTIMPLEMENTED(), we'll need it. - registrar_.Add(this, NotificationType::RENDER_VIEW_HOST_CHANGED, - Source<NavigationController>(&tab_contents_->controller())); + if (tab_contents_ == preview_contents_) { + // If the preview contents is becoming the new permanent tab contents, we + // just reassign some pointers. + preview_contents_ = NULL; + } else if (tab_contents_) { + // Otherwise we actually have to add it to the widget hierarchy. + PackTabContents(tab_contents); registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, Source<TabContents>(tab_contents_)); + } +} + +void TabContentsContainerGtk::SetPreviewContents(TabContents* preview) { + if (preview_contents_) + RemovePreviewContents(); + else + HideTabContents(tab_contents_); + + preview_contents_ = preview; + + PackTabContents(preview); + registrar_.Add(this, NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(preview_contents_)); +} + +void TabContentsContainerGtk::RemovePreviewContents() { + if (!preview_contents_) + return; + + HideTabContents(preview_contents_); + + GtkWidget* preview_widget = preview_contents_->GetNativeView(); + if (preview_widget) + gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); + + registrar_.Remove(this, NotificationType::TAB_CONTENTS_DESTROYED, + Source<TabContents>(preview_contents_)); + preview_contents_ = NULL; +} + +void TabContentsContainerGtk::PopPreviewContents() { + if (!preview_contents_) + return; + + RemovePreviewContents(); - gfx::NativeView widget = tab_contents_->GetNativeView(); - if (widget) { - if (widget->parent != expanded_) - gtk_container_add(GTK_CONTAINER(expanded_), widget); - gtk_widget_show(widget); - } - - // We need to make sure that we are below the findbar. - // Sometimes the content native view will be null. - // TODO(estade): will this case ever cause findbar occlusion problems? - if (tab_contents_->GetContentNativeView()) { - GdkWindow* content_gdk_window = - tab_contents_->GetContentNativeView()->window; - if (content_gdk_window) - gdk_window_lower(content_gdk_window); - } + PackTabContents(tab_contents_); +} + +void TabContentsContainerGtk::PackTabContents(TabContents* contents) { + if (!contents) + return; + + gfx::NativeView widget = contents->GetNativeView(); + if (widget) { + if (widget->parent != expanded_) + gtk_container_add(GTK_CONTAINER(expanded_), widget); + gtk_widget_show(widget); + } + + // We need to make sure that we are below the findbar. + // Sometimes the content native view will be null. + if (contents->GetContentNativeView()) { + GdkWindow* content_gdk_window = + contents->GetContentNativeView()->window; + if (content_gdk_window) + gdk_window_lower(content_gdk_window); } + + contents->ShowContents(); +} + +void TabContentsContainerGtk::HideTabContents(TabContents* contents) { + if (!contents) + return; + + gfx::NativeView widget = contents->GetNativeView(); + if (widget) + gtk_widget_hide(widget); + + contents->WasHidden(); + } void TabContentsContainerGtk::DetachTabContents(TabContents* tab_contents) { gfx::NativeView widget = tab_contents->GetNativeView(); + // It is possible to detach an unrealized, unparented TabContents if you // slow things down enough in valgrind. Might happen in the real world, too. if (widget && widget->parent) { @@ -116,30 +164,20 @@ void TabContentsContainerGtk::DetachTabContents(TabContents* tab_contents) { void TabContentsContainerGtk::Observe(NotificationType type, const NotificationSource& source, const NotificationDetails& details) { - if (type == NotificationType::RENDER_VIEW_HOST_CHANGED) { - RenderViewHostSwitchedDetails* switched_details = - Details<RenderViewHostSwitchedDetails>(details).ptr(); - RenderViewHostChanged(switched_details->old_host, - switched_details->new_host); - } else if (type == NotificationType::TAB_CONTENTS_DESTROYED) { - TabContentsDestroyed(Source<TabContents>(source).ptr()); - } else { - NOTREACHED(); - } -} + DCHECK(type == NotificationType::TAB_CONTENTS_DESTROYED); -void TabContentsContainerGtk::RenderViewHostChanged(RenderViewHost* old_host, - RenderViewHost* new_host) { - // TODO(port): Remove this method and the logic where we subscribe to the - // RENDER_VIEW_HOST_CHANGED notification. This was used on Windows for focus - // issues, and I'm not entirely convinced that this isn't necessary. + TabContentsDestroyed(Source<TabContents>(source).ptr()); } void TabContentsContainerGtk::TabContentsDestroyed(TabContents* contents) { // Sometimes, a TabContents is destroyed before we know about it. This allows // us to clean up our state in case this happens. - DCHECK(contents == tab_contents_); - SetTabContents(NULL); + if (contents == preview_contents_) + PopPreviewContents(); + else if (contents == tab_contents_) + SetTabContents(NULL); + else + NOTREACHED(); } // ----------------------------------------------------------------------------- diff --git a/chrome/browser/gtk/tab_contents_container_gtk.h b/chrome/browser/gtk/tab_contents_container_gtk.h index 0b3a959..ee28b0f 100644 --- a/chrome/browser/gtk/tab_contents_container_gtk.h +++ b/chrome/browser/gtk/tab_contents_container_gtk.h @@ -32,6 +32,9 @@ class TabContentsContainerGtk : public NotificationObserver, void SetTabContents(TabContents* tab_contents); TabContents* GetTabContents() const { return tab_contents_; } + void SetPreviewContents(TabContents* preview); + void PopPreviewContents(); + // Remove the tab from the hierarchy. void DetachTabContents(TabContents* tab_contents); @@ -46,15 +49,6 @@ class TabContentsContainerGtk : public NotificationObserver, virtual GtkWidget* GetWidgetForViewID(ViewID id); private: - // Add or remove observers for events that we care about. - void AddObservers(); - void RemoveObservers(); - - // Called when the RenderViewHost of the hosted TabContents has changed, e.g. - // to show an interstitial page. - void RenderViewHostChanged(RenderViewHost* old_host, - RenderViewHost* new_host); - // Called when a TabContents is destroyed. This gives us a chance to clean // up our internal state if the TabContents is somehow destroyed before we // get notified. @@ -66,11 +60,25 @@ class TabContentsContainerGtk : public NotificationObserver, GtkFloatingContainer* container, GtkAllocation* allocation, TabContentsContainerGtk* tab_contents_container); + // Add |contents| to the container and start showing it. + void PackTabContents(TabContents* contents); + + // Stop showing |contents|. + void HideTabContents(TabContents* contents); + + // Removes |preview_contents_|. + void RemovePreviewContents(); + NotificationRegistrar registrar_; - // The currently visible TabContents. + // The TabContents for the currently selected tab. This will be showing unless + // there is a preview contents. TabContents* tab_contents_; + // The current preview contents (for instant). If non-NULL, it will be + // visible. + TabContents* preview_contents_; + // The status bubble manager. Always non-NULL. StatusBubbleGtk* status_bubble_; |