diff options
author | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 20:14:27 +0000 |
---|---|---|
committer | sky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-10-05 20:14:27 +0000 |
commit | 6b723f8690dcdbdc4071a235aa67483dc18de329 (patch) | |
tree | c0d3b2f787bdef1927674687d9639cbea5dc3143 /chrome/browser | |
parent | 9929dbb542aa4a8531ea4d9eadbb43b99d13f846 (diff) | |
download | chromium_src-6b723f8690dcdbdc4071a235aa67483dc18de329.zip chromium_src-6b723f8690dcdbdc4071a235aa67483dc18de329.tar.gz chromium_src-6b723f8690dcdbdc4071a235aa67483dc18de329.tar.bz2 |
Renames and moves match preview classes to instant. This doesn't
contain any changes other than renaming/moving, as such I'm TBRing.
BUG=54833
TEST=none
TBR=jcivelli@chromium.org
Review URL: http://codereview.chromium.org/3602015
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@61553 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
29 files changed, 569 insertions, 572 deletions
diff --git a/chrome/browser/browser.cc b/chrome/browser/browser.cc index ad3c3e7..87a952f 100644 --- a/chrome/browser/browser.cc +++ b/chrome/browser/browser.cc @@ -56,6 +56,7 @@ #include "chrome/browser/google/google_url_tracker.h" #include "chrome/browser/google/google_util.h" #include "chrome/browser/host_zoom_map.h" +#include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/location_bar.h" #include "chrome/browser/metrics/user_metrics.h" #include "chrome/browser/net/browser_url_util.h" @@ -75,7 +76,6 @@ #include "chrome/browser/sync/sync_ui_util.h" #include "chrome/browser/tab_closeable_state_watcher.h" #include "chrome/browser/tab_contents/interstitial_page.h" -#include "chrome/browser/tab_contents/match_preview.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -247,9 +247,9 @@ Browser::Browser(Type type, Profile* profile) if (profile_->GetProfileSyncService()) profile_->GetProfileSyncService()->AddObserver(this); - if (type == TYPE_NORMAL && MatchPreview::IsEnabled() && + if (type == TYPE_NORMAL && InstantController::IsEnabled() && !profile->IsOffTheRecord()) { - match_preview_.reset(new MatchPreview(this)); + instant_.reset(new InstantController(this)); } PrefService *local_state = g_browser_process->local_state(); @@ -1255,7 +1255,7 @@ void Browser::OpenCurrentURL() { LocationBar* location_bar = window_->GetLocationBar(); WindowOpenDisposition open_disposition = location_bar->GetWindowOpenDisposition(); - if (OpenMatchPreview(open_disposition)) + if (OpenInstant(open_disposition)) return; GURL url(WideToUTF8(location_bar->GetInputString())); @@ -2549,8 +2549,8 @@ void Browser::TabDetachedAt(TabContents* contents, int index) { } void Browser::TabDeselectedAt(TabContents* contents, int index) { - if (match_preview()) - match_preview()->DestroyPreviewContents(); + if (instant()) + instant()->DestroyPreviewContents(); // Save what the user's currently typing, so it can be restored when we // switch back to this tab. @@ -3267,19 +3267,19 @@ void Browser::OnStateChanged() { } /////////////////////////////////////////////////////////////////////////////// -// Browser, MatchPreviewDelegate implementation: +// Browser, InstantDelegate implementation: -void Browser::ShowMatchPreview(TabContents* preview_contents) { - DCHECK(match_preview_->tab_contents() == GetSelectedTabContents()); - window_->ShowMatchPreview(preview_contents); +void Browser::ShowInstant(TabContents* preview_contents) { + DCHECK(instant_->tab_contents() == GetSelectedTabContents()); + window_->ShowInstant(preview_contents); } -void Browser::HideMatchPreview() { - window_->HideMatchPreview(); +void Browser::HideInstant() { + window_->HideInstant(); } -void Browser::CommitMatchPreview(TabContents* preview_contents) { - TabContents* tab_contents = match_preview_->tab_contents(); +void Browser::CommitInstant(TabContents* preview_contents) { + TabContents* tab_contents = instant_->tab_contents(); int index = tab_handler_->GetTabStripModel()->GetIndexOfTabContents( tab_contents); DCHECK_NE(-1, index); @@ -3294,8 +3294,8 @@ void Browser::SetSuggestedText(const string16& text) { window()->GetLocationBar()->SetSuggestedText(text); } -gfx::Rect Browser::GetMatchPreviewBounds() { - return window()->GetMatchPreviewBounds(); +gfx::Rect Browser::GetInstantBounds() { + return window()->GetInstantBounds(); } /////////////////////////////////////////////////////////////////////////////// @@ -4145,23 +4145,23 @@ void Browser::TabRestoreServiceDestroyed(TabRestoreService* service) { tab_restore_service_ = NULL; } -bool Browser::OpenMatchPreview(WindowOpenDisposition disposition) { - if (!match_preview() || !match_preview()->is_active()) +bool Browser::OpenInstant(WindowOpenDisposition disposition) { + if (!instant() || !instant()->is_active()) return false; if (disposition == CURRENT_TAB) { - match_preview()->CommitCurrentPreview(MATCH_PREVIEW_COMMIT_PRESSED_ENTER); + instant()->CommitCurrentPreview(INSTANT_COMMIT_PRESSED_ENTER); return true; } if (disposition == NEW_FOREGROUND_TAB || disposition == NEW_BACKGROUND_TAB) { - HideMatchPreview(); - TabContents* preview_contents = match_preview()->ReleasePreviewContents( - MATCH_PREVIEW_COMMIT_PRESSED_ENTER); + HideInstant(); + TabContents* preview_contents = instant()->ReleasePreviewContents( + INSTANT_COMMIT_PRESSED_ENTER); preview_contents->controller().PruneAllButActive(); tab_handler_->GetTabStripModel()->AddTabContents( preview_contents, -1, - match_preview()->last_transition_type(), + instant()->last_transition_type(), disposition == NEW_FOREGROUND_TAB ? TabStripModel::ADD_SELECTED : TabStripModel::ADD_NONE); return true; diff --git a/chrome/browser/browser.h b/chrome/browser/browser.h index 59049c5..d9e1591 100644 --- a/chrome/browser/browser.h +++ b/chrome/browser/browser.h @@ -18,6 +18,7 @@ #include "base/task.h" #include "chrome/browser/command_updater.h" #include "chrome/browser/debugger/devtools_toggle_action.h" +#include "chrome/browser/instant/instant_delegate.h" #include "chrome/browser/prefs/pref_member.h" #include "chrome/browser/sessions/session_id.h" #include "chrome/browser/sessions/tab_restore_service_observer.h" @@ -26,7 +27,6 @@ #include "chrome/browser/tabs/tab_handler.h" #include "chrome/browser/tabs/tab_strip_model_delegate.h" // TODO(beng): remove #include "chrome/browser/tabs/tab_strip_model_observer.h" // TODO(beng): remove -#include "chrome/browser/tab_contents/match_preview_delegate.h" #include "chrome/browser/tab_contents/page_navigator.h" #include "chrome/browser/tab_contents/tab_contents_delegate.h" #include "chrome/browser/toolbar_model.h" @@ -39,7 +39,7 @@ class BrowserWindow; class Extension; class FindBarController; -class MatchPreview; +class InstantController; class PrefService; class Profile; class SessionStorageNamespace; @@ -59,7 +59,7 @@ class Browser : public TabHandlerDelegate, public SelectFileDialog::Listener, public TabRestoreServiceObserver, public ProfileSyncServiceObserver, - public MatchPreviewDelegate { + public InstantDelegate { public: // If you change the values in this enum you'll need to update browser_proxy. // TODO(sky): move into a common place that is referenced by both ui_tests @@ -176,9 +176,9 @@ class Browser : public TabHandlerDelegate, Profile* profile() const { return profile_; } const std::vector<std::wstring>& user_data_dir_profiles() const; - // Returns the MatchPreview or NULL if there is no MatchPreview for this - // Browser. - MatchPreview* match_preview() const { return match_preview_.get(); } + // Returns the InstantController or NULL if there is no InstantController for + // this Browser. + InstantController* instant() const { return instant_.get(); } #if defined(UNIT_TEST) // Sets the BrowserWindow. This is intended for testing and generally not @@ -789,12 +789,12 @@ class Browser : public TabHandlerDelegate, // Overridden from ProfileSyncServiceObserver: virtual void OnStateChanged(); - // Overriden from MatchPreviewDelegate: - virtual void ShowMatchPreview(TabContents* preview_contents); - virtual void HideMatchPreview(); - virtual void CommitMatchPreview(TabContents* preview_contents); + // Overriden from InstantDelegate: + virtual void ShowInstant(TabContents* preview_contents); + virtual void HideInstant(); + virtual void CommitInstant(TabContents* preview_contents); virtual void SetSuggestedText(const string16& text); - virtual gfx::Rect GetMatchPreviewBounds(); + virtual gfx::Rect GetInstantBounds(); // Command and state updating /////////////////////////////////////////////// @@ -978,9 +978,9 @@ class Browser : public TabHandlerDelegate, // cancel closing of window. bool IsClosingPermitted(); - // Commits the current match preview, returning true on success. This is - // intended for use from OpenCurrentURL. - bool OpenMatchPreview(WindowOpenDisposition disposition); + // Commits the current instant, returning true on success. This is intended + // for use from OpenCurrentURL. + bool OpenInstant(WindowOpenDisposition disposition); // Data members ///////////////////////////////////////////////////////////// @@ -1110,7 +1110,7 @@ class Browser : public TabHandlerDelegate, // and we install ourselves as an observer. TabRestoreService* tab_restore_service_; - scoped_ptr<MatchPreview> match_preview_; + scoped_ptr<InstantController> instant_; DISALLOW_COPY_AND_ASSIGN(Browser); }; diff --git a/chrome/browser/browser_window.h b/chrome/browser/browser_window.h index aa109c5..f14d719 100644 --- a/chrome/browser/browser_window.h +++ b/chrome/browser/browser_window.h @@ -312,16 +312,16 @@ class BrowserWindow { virtual void OpenTabpose() = 0; #endif - // Invoked when the match preview's tab contents should be shown. - virtual void ShowMatchPreview(TabContents* preview_contents) = 0; + // Invoked when instant's tab contents should be shown. + virtual void ShowInstant(TabContents* preview_contents) = 0; - // Invoked when the match preview's tab contents should be hidden. - virtual void HideMatchPreview() = 0; + // Invoked when the instant's tab contents should be hidden. + virtual void HideInstant() = 0; - // Returns the desired bounds for match preview in screen coordinates. Note - // that if match preview isn't currently visible this returns the bounds the - // match preview would be placed at. - virtual gfx::Rect GetMatchPreviewBounds() = 0; + // Returns the desired bounds for instant in screen coordinates. Note that if + // instant isn't currently visible this returns the bounds instant would be + // placed at. + virtual gfx::Rect GetInstantBounds() = 0; // Construct a BrowserWindow implementation for the specified |browser|. static BrowserWindow* CreateBrowserWindow(Browser* browser); diff --git a/chrome/browser/cocoa/browser_window_cocoa.h b/chrome/browser/cocoa/browser_window_cocoa.h index a395397..9747178 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.h +++ b/chrome/browser/cocoa/browser_window_cocoa.h @@ -106,9 +106,9 @@ class BrowserWindowCocoa : public BrowserWindow, virtual void Paste(); virtual void ToggleTabStripMode(); virtual void OpenTabpose(); - virtual void ShowMatchPreview(TabContents* preview_contents); - virtual void HideMatchPreview(); - virtual gfx::Rect GetMatchPreviewBounds(); + virtual void ShowInstant(TabContents* preview_contents); + virtual void HideInstant(); + virtual gfx::Rect GetInstantBounds(); // Overridden from NotificationObserver virtual void Observe(NotificationType type, diff --git a/chrome/browser/cocoa/browser_window_cocoa.mm b/chrome/browser/cocoa/browser_window_cocoa.mm index 0c8d4e9..457c7a6 100644 --- a/chrome/browser/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/cocoa/browser_window_cocoa.mm @@ -564,17 +564,17 @@ void BrowserWindowCocoa::OpenTabpose() { [controller_ openTabpose]; } -void BrowserWindowCocoa::ShowMatchPreview(TabContents* preview_contents) { +void BrowserWindowCocoa::ShowInstant(TabContents* preview_contents) { // TODO: implement me NOTIMPLEMENTED(); } -void BrowserWindowCocoa::HideMatchPreview() { +void BrowserWindowCocoa::HideInstant() { // TODO: implement me NOTIMPLEMENTED(); } -gfx::Rect BrowserWindowCocoa::GetMatchPreviewBounds() { +gfx::Rect BrowserWindowCocoa::GetInstantBounds() { // TODO: implement me NOTIMPLEMENTED(); return gfx::Rect(); diff --git a/chrome/browser/gtk/browser_window_gtk.cc b/chrome/browser/gtk/browser_window_gtk.cc index d3146fa..7527b0f 100644 --- a/chrome/browser/gtk/browser_window_gtk.cc +++ b/chrome/browser/gtk/browser_window_gtk.cc @@ -1133,17 +1133,17 @@ void BrowserWindowGtk::Paste() { DoCutCopyPaste(this, &RenderViewHost::Paste, "paste-clipboard"); } -void BrowserWindowGtk::ShowMatchPreview(TabContents* preview_contents) { +void BrowserWindowGtk::ShowInstant(TabContents* preview_contents) { // TODO: implement me NOTIMPLEMENTED(); } -void BrowserWindowGtk::HideMatchPreview() { +void BrowserWindowGtk::HideInstant() { // TODO: implement me NOTIMPLEMENTED(); } -gfx::Rect BrowserWindowGtk::GetMatchPreviewBounds() { +gfx::Rect BrowserWindowGtk::GetInstantBounds() { // TODO: implement me NOTIMPLEMENTED(); return gfx::Rect(); diff --git a/chrome/browser/gtk/browser_window_gtk.h b/chrome/browser/gtk/browser_window_gtk.h index b5da791..2f0746f 100644 --- a/chrome/browser/gtk/browser_window_gtk.h +++ b/chrome/browser/gtk/browser_window_gtk.h @@ -123,9 +123,9 @@ class BrowserWindowGtk : public BrowserWindow, virtual void Copy(); virtual void Paste(); virtual void ToggleTabStripMode() {} - virtual void ShowMatchPreview(TabContents* preview_contents); - virtual void HideMatchPreview(); - virtual gfx::Rect GetMatchPreviewBounds(); + virtual void ShowInstant(TabContents* preview_contents); + virtual void HideInstant(); + virtual gfx::Rect GetInstantBounds(); // Overridden from NotificationObserver: virtual void Observe(NotificationType type, diff --git a/chrome/browser/instant/instant_commit_type.h b/chrome/browser/instant/instant_commit_type.h new file mode 100644 index 0000000..f73c08b --- /dev/null +++ b/chrome/browser/instant/instant_commit_type.h @@ -0,0 +1,22 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_INSTANT_INSTANT_COMMIT_TYPE_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_COMMIT_TYPE_H_ +#pragma once + +// Enum describing the ways instant can be committed. +enum InstantCommitType { + // The commit is the result of the user pressing enter. + INSTANT_COMMIT_PRESSED_ENTER, + + // The commit is the result of focus being lost. This typically corresponds + // to a mouse click event. + INSTANT_COMMIT_FOCUS_LOST, + + // Used internally by InstantController. + INSTANT_COMMIT_DESTROY +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_COMMIT_TYPE_H_ diff --git a/chrome/browser/tab_contents/match_preview.cc b/chrome/browser/instant/instant_controller.cc index ef8baf2..a095696 100644 --- a/chrome/browser/tab_contents/match_preview.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -2,22 +2,22 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/match_preview.h" +#include "chrome/browser/instant/instant_controller.h" #include "base/command_line.h" #include "chrome/browser/autocomplete/autocomplete.h" +#include "chrome/browser/instant/instant_delegate.h" +#include "chrome/browser/instant/instant_loader.h" +#include "chrome/browser/instant/instant_loader_manager.h" #include "chrome/browser/profile.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/tab_contents/loader_manager.h" -#include "chrome/browser/tab_contents/match_preview_delegate.h" -#include "chrome/browser/tab_contents/match_preview_loader.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/common/chrome_switches.h" #include "chrome/common/url_constants.h" // static -bool MatchPreview::IsEnabled() { +bool InstantController::IsEnabled() { static bool enabled = false; static bool checked = false; if (!checked) { @@ -28,7 +28,7 @@ bool MatchPreview::IsEnabled() { return enabled; } -MatchPreview::MatchPreview(MatchPreviewDelegate* delegate) +InstantController::InstantController(InstantDelegate* delegate) : delegate_(delegate), tab_contents_(NULL), is_active_(false), @@ -36,13 +36,13 @@ MatchPreview::MatchPreview(MatchPreviewDelegate* delegate) last_transition_type_(PageTransition::LINK) { } -MatchPreview::~MatchPreview() { +InstantController::~InstantController() { } -void MatchPreview::Update(TabContents* tab_contents, - const AutocompleteMatch& match, - const string16& user_text, - string16* suggested_text) { +void InstantController::Update(TabContents* tab_contents, + const AutocompleteMatch& match, + const string16& user_text, + string16* suggested_text) { if (tab_contents != tab_contents_) DestroyPreviewContents(); @@ -61,7 +61,7 @@ void MatchPreview::Update(TabContents* tab_contents, } if (!loader_manager_.get()) - loader_manager_.reset(new LoaderManager(this)); + loader_manager_.reset(new InstantLoaderManager(this)); const TemplateURL* template_url = match.template_url; if (match.type == AutocompleteMatch::SEARCH_WHAT_YOU_TYPED || @@ -79,19 +79,19 @@ void MatchPreview::Update(TabContents* tab_contents, } TemplateURLID template_url_id = template_url ? template_url->id() : 0; - MatchPreviewLoader* old_loader = loader_manager_->current_loader(); - scoped_ptr<MatchPreviewLoader> owned_loader; - MatchPreviewLoader* new_loader = + InstantLoader* old_loader = loader_manager_->current_loader(); + scoped_ptr<InstantLoader> owned_loader; + InstantLoader* new_loader = loader_manager_->UpdateLoader(template_url_id, &owned_loader); new_loader->SetOmniboxBounds(omnibox_bounds_); new_loader->Update(tab_contents, match, user_text, template_url, suggested_text); if (old_loader != new_loader && new_loader->ready()) - delegate_->ShowMatchPreview(new_loader->preview_contents()); + delegate_->ShowInstant(new_loader->preview_contents()); } -void MatchPreview::SetOmniboxBounds(const gfx::Rect& bounds) { +void InstantController::SetOmniboxBounds(const gfx::Rect& bounds) { if (omnibox_bounds_ == bounds) return; @@ -103,38 +103,37 @@ void MatchPreview::SetOmniboxBounds(const gfx::Rect& bounds) { } } -void MatchPreview::DestroyPreviewContents() { +void InstantController::DestroyPreviewContents() { if (!loader_manager_.get()) { // We're not showing anything, nothing to do. return; } - delegate_->HideMatchPreview(); - delete ReleasePreviewContents(MATCH_PREVIEW_COMMIT_DESTROY); + delegate_->HideInstant(); + delete ReleasePreviewContents(INSTANT_COMMIT_DESTROY); } -void MatchPreview::CommitCurrentPreview(MatchPreviewCommitType type) { +void InstantController::CommitCurrentPreview(InstantCommitType type) { DCHECK(loader_manager_.get()); DCHECK(loader_manager_->current_loader()); - delegate_->CommitMatchPreview(ReleasePreviewContents(type)); + delegate_->CommitInstant(ReleasePreviewContents(type)); } -void MatchPreview::SetCommitOnMouseUp() { +void InstantController::SetCommitOnMouseUp() { commit_on_mouse_up_ = true; } -bool MatchPreview::IsMouseDownFromActivate() { +bool InstantController::IsMouseDownFromActivate() { DCHECK(loader_manager_.get()); DCHECK(loader_manager_->current_loader()); return loader_manager_->current_loader()->IsMouseDownFromActivate(); } -TabContents* MatchPreview::ReleasePreviewContents(MatchPreviewCommitType type) { +TabContents* InstantController::ReleasePreviewContents(InstantCommitType type) { if (!loader_manager_.get()) return NULL; - scoped_ptr<MatchPreviewLoader> loader( - loader_manager_->ReleaseCurrentLoader()); + scoped_ptr<InstantLoader> loader(loader_manager_->ReleaseCurrentLoader()); TabContents* tab = loader->ReleasePreviewContents(type); is_active_ = false; @@ -144,47 +143,47 @@ TabContents* MatchPreview::ReleasePreviewContents(MatchPreviewCommitType type) { return tab; } -TabContents* MatchPreview::GetPreviewContents() { +TabContents* InstantController::GetPreviewContents() { return loader_manager_.get() ? loader_manager_->current_loader()->preview_contents() : NULL; } -bool MatchPreview::IsShowingInstant() { +bool InstantController::IsShowingInstant() { return loader_manager_.get() && loader_manager_->current_loader()->is_showing_instant(); } -void MatchPreview::ShowMatchPreviewLoader(MatchPreviewLoader* loader) { +void InstantController::ShowInstantLoader(InstantLoader* loader) { DCHECK(loader_manager_.get()); if (loader_manager_->current_loader() == loader) { is_active_ = true; - delegate_->ShowMatchPreview(loader->preview_contents()); + delegate_->ShowInstant(loader->preview_contents()); } else if (loader_manager_->pending_loader() == loader) { - scoped_ptr<MatchPreviewLoader> old_loader; + scoped_ptr<InstantLoader> old_loader; loader_manager_->MakePendingCurrent(&old_loader); - delegate_->ShowMatchPreview(loader->preview_contents()); + delegate_->ShowInstant(loader->preview_contents()); } else { NOTREACHED(); } } -void MatchPreview::SetSuggestedTextFor(MatchPreviewLoader* loader, - const string16& text) { +void InstantController::SetSuggestedTextFor(InstantLoader* loader, + const string16& text) { if (loader_manager_->current_loader() == loader) delegate_->SetSuggestedText(text); } -gfx::Rect MatchPreview::GetMatchPreviewBounds() { - return delegate_->GetMatchPreviewBounds(); +gfx::Rect InstantController::GetInstantBounds() { + return delegate_->GetInstantBounds(); } -bool MatchPreview::ShouldCommitPreviewOnMouseUp() { +bool InstantController::ShouldCommitInstantOnMouseUp() { return commit_on_mouse_up_; } -void MatchPreview::CommitPreview(MatchPreviewLoader* loader) { +void InstantController::CommitInstantLoader(InstantLoader* loader) { if (loader_manager_.get() && loader_manager_->current_loader() == loader) { - CommitCurrentPreview(MATCH_PREVIEW_COMMIT_FOCUS_LOST); + CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); } else { // This can happen if the mouse was down, we swapped out the preview and // the mouse was released. Generally this shouldn't happen, but if it does @@ -193,6 +192,6 @@ void MatchPreview::CommitPreview(MatchPreviewLoader* loader) { } } -bool MatchPreview::ShouldShowPreviewFor(const GURL& url) { +bool InstantController::ShouldShowPreviewFor(const GURL& url) { return !url.SchemeIs(chrome::kJavaScriptScheme); } diff --git a/chrome/browser/tab_contents/match_preview.h b/chrome/browser/instant/instant_controller.h index 7d2d7f0..678a9e1 100644 --- a/chrome/browser/tab_contents/match_preview.h +++ b/chrome/browser/instant/instant_controller.h @@ -2,39 +2,39 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_ -#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_ +#ifndef CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ #pragma once #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "base/string16.h" +#include "chrome/browser/instant/instant_commit_type.h" +#include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/search_engines/template_url_id.h" -#include "chrome/browser/tab_contents/match_preview_commit_type.h" -#include "chrome/browser/tab_contents/match_preview_loader_delegate.h" #include "chrome/common/page_transition_types.h" #include "gfx/rect.h" #include "googleurl/src/gurl.h" struct AutocompleteMatch; -class LoaderManager; -class MatchPreviewDelegate; +class InstantDelegate; +class InstantLoaderManager; class TabContents; -// MatchPreview maintains a TabContents that is intended to give a preview of -// a URL. MatchPreview is owned by Browser. +// InstantController maintains a TabContents that is intended to give a preview +// of a URL. InstantController is owned by Browser. // -// At any time the TabContents maintained by MatchPreview may be destroyed by -// way of |DestroyPreviewContents|, which results in |HideMatchPreview| being +// At any time the TabContents maintained by InstantController may be destroyed +// by way of |DestroyPreviewContents|, which results in |HideInstant| being // invoked on the delegate. Similarly the preview may be committed at any time -// by invoking |CommitCurrentPreview|, which results in |CommitMatchPreview| +// by invoking |CommitCurrentPreview|, which results in |CommitInstant| // being invoked on the delegate. -class MatchPreview : public MatchPreviewLoaderDelegate { +class InstantController : public InstantLoaderDelegate { public: - explicit MatchPreview(MatchPreviewDelegate* delegate); - ~MatchPreview(); + explicit InstantController(InstantDelegate* delegate); + ~InstantController(); - // Is MatchPreview enabled? + // Is InstantController enabled? static bool IsEnabled(); // Invoked as the user types in the omnibox with the url to navigate to. If @@ -57,9 +57,9 @@ class MatchPreview : public MatchPreviewLoaderDelegate { // Invoked when the user does some gesture that should trigger making the // current previewed page the permanent page. - void CommitCurrentPreview(MatchPreviewCommitType type); + void CommitCurrentPreview(InstantCommitType type); - // Sets MatchPreview so that when the mouse is released the preview is + // Sets InstantController so that when the mouse is released the preview is // committed. void SetCommitOnMouseUp(); @@ -72,7 +72,7 @@ class MatchPreview : public MatchPreviewLoaderDelegate { // Releases the preview TabContents passing ownership to the caller. This is // intended to be called when the preview TabContents is committed. This does // not notify the delegate. - TabContents* ReleasePreviewContents(MatchPreviewCommitType type); + TabContents* ReleasePreviewContents(InstantCommitType type); // TabContents the match is being shown for. TabContents* tab_contents() const { return tab_contents_; } @@ -92,13 +92,13 @@ class MatchPreview : public MatchPreviewLoaderDelegate { // Are we showing instant results? bool IsShowingInstant(); - // MatchPreviewLoaderDelegate - virtual void ShowMatchPreviewLoader(MatchPreviewLoader* loader); - virtual void SetSuggestedTextFor(MatchPreviewLoader* loader, + // InstantLoaderDelegate + virtual void ShowInstantLoader(InstantLoader* loader); + virtual void SetSuggestedTextFor(InstantLoader* loader, const string16& text); - virtual gfx::Rect GetMatchPreviewBounds(); - virtual bool ShouldCommitPreviewOnMouseUp(); - virtual void CommitPreview(MatchPreviewLoader* loader); + virtual gfx::Rect GetInstantBounds(); + virtual bool ShouldCommitInstantOnMouseUp(); + virtual void CommitInstantLoader(InstantLoader* loader); private: // Invoked when the page wants to update the suggested text. If |user_text_| @@ -117,7 +117,7 @@ class MatchPreview : public MatchPreviewLoaderDelegate { // Returns true if we should show preview for |url|. bool ShouldShowPreviewFor(const GURL& url); - MatchPreviewDelegate* delegate_; + InstantDelegate* delegate_; // The TabContents last passed to |Update|. TabContents* tab_contents_; @@ -135,9 +135,9 @@ class MatchPreview : public MatchPreviewLoaderDelegate { // See description above getter. PageTransition::Type last_transition_type_; - scoped_ptr<LoaderManager> loader_manager_; + scoped_ptr<InstantLoaderManager> loader_manager_; - DISALLOW_COPY_AND_ASSIGN(MatchPreview); + DISALLOW_COPY_AND_ASSIGN(InstantController); }; -#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_H_ +#endif // CHROME_BROWSER_INSTANT_INSTANT_CONTROLLER_H_ diff --git a/chrome/browser/instant/instant_delegate.h b/chrome/browser/instant/instant_delegate.h new file mode 100644 index 0000000..a5c9223 --- /dev/null +++ b/chrome/browser/instant/instant_delegate.h @@ -0,0 +1,42 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_INSTANT_INSTANT_DELEGATE_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_DELEGATE_H_ +#pragma once + +#include "base/string16.h" + +class TabContents; + +namespace gfx { +class Rect; +} + +// InstantController's delegate. Normally the Browser implements this. See +// InstantController for details. +class InstantDelegate { + public: + // Invoked when the instant TabContents should be shown. + virtual void ShowInstant(TabContents* preview_contents) = 0; + + // Invoked when the instant TabContents should be hidden. + virtual void HideInstant() = 0; + + // Invoked when the user does something that should result in the preview + // TabContents becoming the active TabContents. The delegate takes ownership + // of the supplied TabContents. + virtual void CommitInstant(TabContents* preview_contents) = 0; + + // Invoked when the suggested text is to change to |text|. + virtual void SetSuggestedText(const string16& text) = 0; + + // Returns the bounds instant will be placed at in screen coordinates. + virtual gfx::Rect GetInstantBounds() = 0; + + protected: + virtual ~InstantDelegate() {} +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/match_preview_loader.cc b/chrome/browser/instant/instant_loader.cc index f7ff7ed..adae0b8 100644 --- a/chrome/browser/tab_contents/match_preview_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -2,7 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/match_preview_loader.h" +#include "chrome/browser/instant/instant_loader.h" #include <algorithm> @@ -12,12 +12,12 @@ #include "chrome/browser/autocomplete/autocomplete.h" #include "chrome/browser/favicon_service.h" #include "chrome/browser/history/history_marshaling.h" +#include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_view_host.h" #include "chrome/browser/renderer_host/render_widget_host.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/search_engines/template_url.h" -#include "chrome/browser/tab_contents/match_preview_loader_delegate.h" #include "chrome/browser/tab_contents/navigation_controller.h" #include "chrome/browser/tab_contents/navigation_entry.h" #include "chrome/browser/tab_contents/tab_contents.h" @@ -114,11 +114,11 @@ void SendOmniboxBoundsScript(TabContents* tab_contents, // FrameLoadObserver is responsible for waiting for the TabContents to finish // loading and when done sending the necessary script down to the page. -class MatchPreviewLoader::FrameLoadObserver : public NotificationObserver { +class InstantLoader::FrameLoadObserver : public NotificationObserver { public: - FrameLoadObserver(MatchPreviewLoader* match_preview, const string16& text) - : match_preview_(match_preview), - tab_contents_(match_preview->preview_contents()), + FrameLoadObserver(InstantLoader* loader, const string16& text) + : loader_(loader), + tab_contents_(loader->preview_contents()), unique_id_(tab_contents_->controller().pending_entry()->unique_id()), text_(text), pressed_enter_(false) { @@ -131,10 +131,10 @@ class MatchPreviewLoader::FrameLoadObserver : public NotificationObserver { // Sets the text to send to the page. void set_text(const string16& text) { text_ = text; } - // Invoked when the MatchPreviewLoader releases ownership of the TabContents - // and the page hasn't finished loading. + // Invoked when the InstantLoader releases ownership of the TabContents and + // the page hasn't finished loading. void DetachFromPreview(bool pressed_enter) { - match_preview_ = NULL; + loader_ = NULL; pressed_enter_ = pressed_enter; } @@ -152,16 +152,16 @@ class MatchPreviewLoader::FrameLoadObserver : public NotificationObserver { return; } - if (match_preview_) { - gfx::Rect bounds = match_preview_->GetOmniboxBoundsInTermsOfPreview(); + if (loader_) { + gfx::Rect bounds = loader_->GetOmniboxBoundsInTermsOfPreview(); if (!bounds.IsEmpty()) SendOmniboxBoundsScript(tab_contents_, bounds); } SendUserInputScript(tab_contents_, text_); - if (match_preview_) - match_preview_->PageFinishedLoading(); + if (loader_) + loader_->PageFinishedLoading(); else SendDoneScript(tab_contents_, text_, pressed_enter_); @@ -180,8 +180,8 @@ class MatchPreviewLoader::FrameLoadObserver : public NotificationObserver { } private: - // MatchPreviewLoader that created us. - MatchPreviewLoader* match_preview_; + // InstantLoader that created us. + InstantLoader* loader_; // The TabContents we're listening for changes on. TabContents* tab_contents_; @@ -202,33 +202,32 @@ class MatchPreviewLoader::FrameLoadObserver : public NotificationObserver { }; // PaintObserver implementation. When the RenderWidgetHost paints itself this -// notifies MatchPreviewLoader, which makes the TabContents active. -class MatchPreviewLoader::PaintObserverImpl +// notifies InstantLoader, which makes the TabContents active. +class InstantLoader::PaintObserverImpl : public RenderWidgetHost::PaintObserver { public: - explicit PaintObserverImpl(MatchPreviewLoader* preview) - : match_preview_(preview) { + explicit PaintObserverImpl(InstantLoader* loader) : loader_(loader) { } virtual void RenderWidgetHostWillPaint(RenderWidgetHost* rwh) { } virtual void RenderWidgetHostDidPaint(RenderWidgetHost* rwh) { - match_preview_->PreviewPainted(); + loader_->PreviewPainted(); rwh->set_paint_observer(NULL); // WARNING: we've been deleted. } private: - MatchPreviewLoader* match_preview_; + InstantLoader* loader_; DISALLOW_COPY_AND_ASSIGN(PaintObserverImpl); }; -class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { +class InstantLoader::TabContentsDelegateImpl : public TabContentsDelegate { public: - explicit TabContentsDelegateImpl(MatchPreviewLoader* match_preview) - : match_preview_(match_preview), + explicit TabContentsDelegateImpl(InstantLoader* loader) + : loader_(loader), installed_paint_observer_(false), waiting_for_new_page_(true), is_mouse_down_from_activate_(false) { @@ -253,7 +252,7 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { // Commits the currently buffered history. void CommitHistory() { - TabContents* tab = match_preview_->preview_contents(); + TabContents* tab = loader_->preview_contents(); if (tab->profile()->IsOffTheRecord()) return; @@ -292,7 +291,7 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { // preview after the first paint we would end up with a white rect. installed_paint_observer_ = true; source->GetRenderWidgetHostView()->GetRenderWidgetHost()-> - set_paint_observer(new PaintObserverImpl(match_preview_)); + set_paint_observer(new PaintObserverImpl(loader_)); } } virtual void AddNewContents(TabContents* source, @@ -317,7 +316,7 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { return false; } virtual void WillShowConstrainedWindow(TabContents* source) { - if (!match_preview_->ready()) { + if (!loader_->ready()) { // A constrained window shown for an auth may not paint. Show the preview // contents. if (installed_paint_observer_) { @@ -325,7 +324,7 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { set_paint_observer(NULL); } installed_paint_observer_ = true; - match_preview_->ShowPreview(); + loader_->ShowPreview(); } } virtual TabContents* GetConstrainingContents(TabContents* source) { @@ -421,11 +420,11 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { virtual void ContentTypeChanged(TabContents* source) {} virtual void OnSetSuggestResult(int32 page_id, const std::string& result) { - TabContents* source = match_preview_->preview_contents(); + TabContents* source = loader_->preview_contents(); // TODO: only allow for default search provider. if (source->controller().GetActiveEntry() && page_id == source->controller().GetActiveEntry()->page_id()) { - match_preview_->SetCompleteSuggestedText(UTF8ToUTF16(result)); + loader_->SetCompleteSuggestedText(UTF8ToUTF16(result)); } } @@ -436,20 +435,20 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { void CommitFromMouseReleaseIfNecessary() { bool was_down = is_mouse_down_from_activate_; is_mouse_down_from_activate_ = false; - if (was_down && match_preview_->ShouldCommitPreviewOnMouseUp()) - match_preview_->CommitPreview(); + if (was_down && loader_->ShouldCommitInstantOnMouseUp()) + loader_->CommitInstantLoader(); } - MatchPreviewLoader* match_preview_; + InstantLoader* loader_; // Has the paint observer been installed? See comment in // NavigationStateChanged for details on this. bool installed_paint_observer_; // Used to cache data that needs to be added to history. Normally entries are - // added to history as the user types, but for match preview we only want to - // add the items to history if the user commits the match preview. So, we - // cache them here and if committed then add the items to history. + // added to history as the user types, but for instant we only want to add the + // items to history if the user commits instant. So, we cache them here and if + // committed then add the items to history. AddPageVector add_page_vector_; // Are we we waiting for a NavigationType of NEW_PAGE? If we're waiting for @@ -462,25 +461,24 @@ class MatchPreviewLoader::TabContentsDelegateImpl : public TabContentsDelegate { DISALLOW_COPY_AND_ASSIGN(TabContentsDelegateImpl); }; -MatchPreviewLoader::MatchPreviewLoader(MatchPreviewLoaderDelegate* delegate, - TemplateURLID id) +InstantLoader::InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id) : delegate_(delegate), template_url_id_(id), ready_(false) { preview_tab_contents_delegate_.reset(new TabContentsDelegateImpl(this)); } -MatchPreviewLoader::~MatchPreviewLoader() { +InstantLoader::~InstantLoader() { // Delete the TabContents before the delegate as the TabContents holds a // reference to the delegate. preview_contents_.reset(NULL); } -void MatchPreviewLoader::Update(TabContents* tab_contents, - const AutocompleteMatch& match, - const string16& user_text, - const TemplateURL* template_url, - string16* suggested_text) { +void InstantLoader::Update(TabContents* tab_contents, + const AutocompleteMatch& match, + const string16& user_text, + const TemplateURL* template_url, + string16* suggested_text) { DCHECK(url_ != match.destination_url); url_ = match.destination_url; @@ -543,7 +541,7 @@ void MatchPreviewLoader::Update(TabContents* tab_contents, } } -void MatchPreviewLoader::SetOmniboxBounds(const gfx::Rect& bounds) { +void InstantLoader::SetOmniboxBounds(const gfx::Rect& bounds) { if (omnibox_bounds_ == bounds) return; @@ -555,41 +553,40 @@ void MatchPreviewLoader::SetOmniboxBounds(const gfx::Rect& bounds) { } } -void MatchPreviewLoader::DestroyPreviewContents() { +void InstantLoader::DestroyPreviewContents() { if (!preview_contents_.get()) { // We're not showing anything, nothing to do. return; } - delete ReleasePreviewContents(MATCH_PREVIEW_COMMIT_DESTROY); + delete ReleasePreviewContents(INSTANT_COMMIT_DESTROY); } -bool MatchPreviewLoader::IsMouseDownFromActivate() { +bool InstantLoader::IsMouseDownFromActivate() { return preview_tab_contents_delegate_->is_mouse_down_from_activate(); } -TabContents* MatchPreviewLoader::ReleasePreviewContents( - MatchPreviewCommitType type) { +TabContents* InstantLoader::ReleasePreviewContents(InstantCommitType type) { if (!preview_contents_.get()) return NULL; if (frame_load_observer_.get()) { frame_load_observer_->DetachFromPreview( - type == MATCH_PREVIEW_COMMIT_PRESSED_ENTER); + type == INSTANT_COMMIT_PRESSED_ENTER); // FrameLoadObserver will delete itself either when the TabContents is // deleted, or when the page finishes loading. FrameLoadObserver* unused ALLOW_UNUSED = frame_load_observer_.release(); - } else if (type != MATCH_PREVIEW_COMMIT_DESTROY && is_showing_instant()) { + } else if (type != INSTANT_COMMIT_DESTROY && is_showing_instant()) { SendDoneScript(preview_contents_.get(), user_text_, - type == MATCH_PREVIEW_COMMIT_PRESSED_ENTER); + type == INSTANT_COMMIT_PRESSED_ENTER); } omnibox_bounds_ = gfx::Rect(); url_ = GURL(); user_text_.clear(); complete_suggested_text_.clear(); if (preview_contents_.get()) { - if (type != MATCH_PREVIEW_COMMIT_DESTROY) + if (type != INSTANT_COMMIT_DESTROY) preview_tab_contents_delegate_->CommitHistory(); // Destroy the paint observer. // RenderWidgetHostView may be null during shutdown. @@ -604,15 +601,15 @@ TabContents* MatchPreviewLoader::ReleasePreviewContents( return preview_contents_.release(); } -bool MatchPreviewLoader::ShouldCommitPreviewOnMouseUp() { - return delegate_->ShouldCommitPreviewOnMouseUp(); +bool InstantLoader::ShouldCommitInstantOnMouseUp() { + return delegate_->ShouldCommitInstantOnMouseUp(); } -void MatchPreviewLoader::CommitPreview() { - delegate_->CommitPreview(this); +void InstantLoader::CommitInstantLoader() { + delegate_->CommitInstantLoader(this); } -void MatchPreviewLoader::SetCompleteSuggestedText( +void InstantLoader::SetCompleteSuggestedText( const string16& complete_suggested_text) { if (complete_suggested_text == complete_suggested_text_) return; @@ -631,27 +628,27 @@ void MatchPreviewLoader::SetCompleteSuggestedText( complete_suggested_text_.substr(user_text_.size())); } -void MatchPreviewLoader::PreviewPainted() { +void InstantLoader::PreviewPainted() { ShowPreview(); } -void MatchPreviewLoader::ShowPreview() { +void InstantLoader::ShowPreview() { if (!ready_) { ready_ = true; - delegate_->ShowMatchPreviewLoader(this); + delegate_->ShowInstantLoader(this); } } -void MatchPreviewLoader::PageFinishedLoading() { +void InstantLoader::PageFinishedLoading() { // FrameLoadObserver deletes itself after this call. FrameLoadObserver* unused ALLOW_UNUSED = frame_load_observer_.release(); } -gfx::Rect MatchPreviewLoader::GetOmniboxBoundsInTermsOfPreview() { +gfx::Rect InstantLoader::GetOmniboxBoundsInTermsOfPreview() { if (omnibox_bounds_.IsEmpty()) return omnibox_bounds_; - gfx::Rect preview_bounds(delegate_->GetMatchPreviewBounds()); + gfx::Rect preview_bounds(delegate_->GetInstantBounds()); return gfx::Rect(omnibox_bounds_.x() - preview_bounds.x(), omnibox_bounds_.y() - preview_bounds.y(), omnibox_bounds_.width(), diff --git a/chrome/browser/tab_contents/match_preview_loader.h b/chrome/browser/instant/instant_loader.h index be96378..a5edb35 100644 --- a/chrome/browser/tab_contents/match_preview_loader.h +++ b/chrome/browser/instant/instant_loader.h @@ -2,32 +2,32 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_H_ -#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_H_ +#ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ #pragma once #include "base/basictypes.h" #include "base/scoped_ptr.h" #include "base/string16.h" +#include "chrome/browser/instant/instant_commit_type.h" #include "chrome/browser/search_engines/template_url_id.h" -#include "chrome/browser/tab_contents/match_preview_commit_type.h" #include "chrome/common/page_transition_types.h" #include "gfx/rect.h" #include "googleurl/src/gurl.h" struct AutocompleteMatch; -class LoaderManagerTest; -class MatchPreviewLoaderDelegate; +class InstantLoaderDelegate; +class InstantLoaderManagerTest; class TabContents; class TemplateURL; -// MatchPreviewLoader does the loading of a particular URL for MatchPreview. -// MatchPreviewLoader notifies its delegate, which is typically MatchPreview, -// of all interesting events. -class MatchPreviewLoader { +// InstantLoader does the loading of a particular URL for InstantController. +// InstantLoader notifies its delegate, which is typically InstantController, of +// all interesting events. +class InstantLoader { public: - MatchPreviewLoader(MatchPreviewLoaderDelegate* delegate, TemplateURLID id); - ~MatchPreviewLoader(); + InstantLoader(InstantLoaderDelegate* delegate, TemplateURLID id); + ~InstantLoader(); // Invoked to load a URL. |tab_contents| is the TabContents the preview is // going to be shown on top of and potentially replace. @@ -53,11 +53,11 @@ class MatchPreviewLoader { // Releases the preview TabContents passing ownership to the caller. This is // intended to be called when the preview TabContents is committed. This does // not notify the delegate. - TabContents* ReleasePreviewContents(MatchPreviewCommitType type); + TabContents* ReleasePreviewContents(InstantCommitType type); // Calls through to method of same name on delegate. - bool ShouldCommitPreviewOnMouseUp(); - void CommitPreview(); + bool ShouldCommitInstantOnMouseUp(); + void CommitInstantLoader(); // The preview TabContents; may be null. TabContents* preview_contents() const { return preview_contents_.get(); } @@ -74,7 +74,7 @@ class MatchPreviewLoader { TemplateURLID template_url_id() const { return template_url_id_; } private: - friend class LoaderManagerTest; + friend class InstantLoaderManagerTest; class FrameLoadObserver; class PaintObserverImpl; class TabContentsDelegateImpl; @@ -103,7 +103,7 @@ class MatchPreviewLoader { return frame_load_observer_.get() != NULL; } - MatchPreviewLoaderDelegate* delegate_; + InstantLoaderDelegate* delegate_; // If we're showing instant results this is the ID of the TemplateURL driving // the results. A value of 0 means there is no TemplateURL. @@ -133,7 +133,7 @@ class MatchPreviewLoader { scoped_ptr<FrameLoadObserver> frame_load_observer_; - DISALLOW_COPY_AND_ASSIGN(MatchPreviewLoader); + DISALLOW_COPY_AND_ASSIGN(InstantLoader); }; -#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_H_ +#endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_H_ diff --git a/chrome/browser/instant/instant_loader_delegate.h b/chrome/browser/instant/instant_loader_delegate.h new file mode 100644 index 0000000..b77742d --- /dev/null +++ b/chrome/browser/instant/instant_loader_delegate.h @@ -0,0 +1,40 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_DELEGATE_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_LOADER_DELEGATE_H_ +#pragma once + +#include "base/string16.h" + +namespace gfx { +class Rect; +} + +class InstantLoader; + +// InstantLoader's delegate. This interface is implemented by InstantController. +class InstantLoaderDelegate { + public: + // Invoked when the loader is ready to be shown. + virtual void ShowInstantLoader(InstantLoader* loader) = 0; + + // Invoked when the loader has suggested text. + virtual void SetSuggestedTextFor(InstantLoader* loader, + const string16& text) = 0; + + // Returns the bounds of instant. + virtual gfx::Rect GetInstantBounds() = 0; + + // Returns true if instant should be committed on mouse up. + virtual bool ShouldCommitInstantOnMouseUp() = 0; + + // Invoked when the the loader should be committed. + virtual void CommitInstantLoader(InstantLoader* loader) = 0; + + protected: + virtual ~InstantLoaderDelegate() {} +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/loader_manager.cc b/chrome/browser/instant/instant_loader_manager.cc index 962154f..e807bfc 100644 --- a/chrome/browser/tab_contents/loader_manager.cc +++ b/chrome/browser/instant/instant_loader_manager.cc @@ -2,20 +2,21 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -#include "chrome/browser/tab_contents/loader_manager.h" +#include "chrome/browser/instant/instant_loader_manager.h" #include "base/logging.h" -#include "chrome/browser/tab_contents/match_preview_loader.h" -#include "chrome/browser/tab_contents/match_preview_loader_delegate.h" +#include "chrome/browser/instant/instant_loader.h" +#include "chrome/browser/instant/instant_loader_delegate.h" #include "chrome/browser/tab_contents/tab_contents.h" -LoaderManager::LoaderManager(MatchPreviewLoaderDelegate* loader_delegate) +InstantLoaderManager::InstantLoaderManager( + InstantLoaderDelegate* loader_delegate) : loader_delegate_(loader_delegate), current_loader_(NULL), pending_loader_(NULL) { } -LoaderManager::~LoaderManager() { +InstantLoaderManager::~InstantLoaderManager() { for (Loaders::iterator i = instant_loaders_.begin(); i != instant_loaders_.end(); ++i) { if (i->second == current_loader_) @@ -32,14 +33,14 @@ LoaderManager::~LoaderManager() { delete pending_loader_; } -MatchPreviewLoader* LoaderManager::UpdateLoader( +InstantLoader* InstantLoaderManager::UpdateLoader( TemplateURLID instant_id, - scoped_ptr<MatchPreviewLoader>* old_loader) { - MatchPreviewLoader* old_current_loader = current_loader_; - MatchPreviewLoader* old_pending_loader = pending_loader_; + scoped_ptr<InstantLoader>* old_loader) { + InstantLoader* old_current_loader = current_loader_; + InstantLoader* old_pending_loader = pending_loader_; // Determine the new loader. - MatchPreviewLoader* loader = NULL; + InstantLoader* loader = NULL; if (instant_id) { loader = GetInstantLoader(instant_id); } else { @@ -85,8 +86,8 @@ MatchPreviewLoader* LoaderManager::UpdateLoader( return active_loader(); } -void LoaderManager::MakePendingCurrent( - scoped_ptr<MatchPreviewLoader>* old_loader) { +void InstantLoaderManager::MakePendingCurrent( + scoped_ptr<InstantLoader>* old_loader) { DCHECK(current_loader_); DCHECK(pending_loader_); @@ -97,9 +98,9 @@ void LoaderManager::MakePendingCurrent( pending_loader_ = NULL; } -MatchPreviewLoader* LoaderManager::ReleaseCurrentLoader() { +InstantLoader* InstantLoaderManager::ReleaseCurrentLoader() { DCHECK(current_loader_); - MatchPreviewLoader* loader = current_loader_; + InstantLoader* loader = current_loader_; if (current_loader_->template_url_id()) { Loaders::iterator i = instant_loaders_.find(current_loader_->template_url_id()); @@ -110,14 +111,14 @@ MatchPreviewLoader* LoaderManager::ReleaseCurrentLoader() { return loader; } -MatchPreviewLoader* LoaderManager::CreateLoader(TemplateURLID id) { - MatchPreviewLoader* loader = new MatchPreviewLoader(loader_delegate_, id); +InstantLoader* InstantLoaderManager::CreateLoader(TemplateURLID id) { + InstantLoader* loader = new InstantLoader(loader_delegate_, id); if (id) instant_loaders_[id] = loader; return loader; } -MatchPreviewLoader* LoaderManager::GetInstantLoader(TemplateURLID id) { +InstantLoader* InstantLoaderManager::GetInstantLoader(TemplateURLID id) { Loaders::iterator i = instant_loaders_.find(id); return i == instant_loaders_.end() ? CreateLoader(id) : i->second; } diff --git a/chrome/browser/instant/instant_loader_manager.h b/chrome/browser/instant/instant_loader_manager.h new file mode 100644 index 0000000..efcc6ac --- /dev/null +++ b/chrome/browser/instant/instant_loader_manager.h @@ -0,0 +1,97 @@ +// Copyright (c) 2010 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ +#pragma once + +#include <map> + +#include "base/scoped_ptr.h" +#include "chrome/browser/search_engines/template_url_id.h" + +class InstantLoader; +class InstantLoaderDelegate; + +// InstantLoaderManager is responsible for maintaining the InstantLoaders for +// InstantController. InstantLoaderManager keeps track of one loader for loading +// non-instant urls, and a loader per TemplateURLID for loading instant urls. A +// loader per TemplateURLID is necessitated due to not knowing in advance if a +// site really supports instant (for example, the user might have opted out even +// though it's supported). +// +// Users of InstantLoaderManager need only concern themselves with the current +// and pending loaders. The current loader is the loader that if ready is shown +// by InstantController. The pending loader is used if the current loader is +// ready and update is invoked with a different id. In this case the current +// loader is left as current (and it's preview contents stopped) and the newly +// created loader is set to pending. Once the pending loader is ready +// MakePendingCurrent should be invoked to make the pending the current loader. +// +// InstantLoader owns all the InstantLoaders returned. You can take +// ownership of the current loader by invoking ReleaseCurrentLoader. +class InstantLoaderManager { + public: + explicit InstantLoaderManager(InstantLoaderDelegate* loader_delegate); + ~InstantLoaderManager(); + + // Updates the current loader. If the current loader is replaced and should be + // deleted it is set in |old_loader|. This is done to allow the caller to + // notify delegates before the old loader is destroyed. This returns the + // active InstantLoader that should be used. + InstantLoader* UpdateLoader(TemplateURLID instant_id, + scoped_ptr<InstantLoader>* old_loader); + + // Makes the pending loader the current loader. If ownership of the old + // loader is to pass to the caller |old_loader| is set appropriately. + void MakePendingCurrent(scoped_ptr<InstantLoader>* old_loader); + + // Returns the current loader and clears internal references to it. This + // should be used prior to destroying the InstantLoaderManager when the owner + // of InstantLoaderManager wants to take ownership of the loader. + InstantLoader* ReleaseCurrentLoader(); + + // Returns the current loader, may be null. + InstantLoader* current_loader() const { return current_loader_; } + + // Returns the pending loader, may be null. + InstantLoader* pending_loader() const { return pending_loader_; } + + // The active loader is the loader that should be used for new loads. It is + // either the pending loader or the current loader. + InstantLoader* active_loader() const { + return pending_loader_ ? pending_loader_ : current_loader_; + } + + // Returns the number of instant loaders. + // This is exposed for tests. + size_t num_instant_loaders() const { return instant_loaders_.size(); } + + private: + typedef std::map<TemplateURLID, InstantLoader*> Loaders; + + // Creates a loader and if |id| is non-zero registers it in instant_loaders_. + InstantLoader* CreateLoader(TemplateURLID id); + + // Returns the loader for loading instant results with the specified id. If + // there is no loader for the specified id a new one is created. + InstantLoader* GetInstantLoader(TemplateURLID id); + + InstantLoaderDelegate* loader_delegate_; + + // The current loader. + InstantLoader* current_loader_; + + // Loader we want to use as soon as ready. This is only non-null if + // current_loader_ is ready and Update is invoked with a different template + // url id. + InstantLoader* pending_loader_; + + // Maps for template url id to loader used for that template url id. + Loaders instant_loaders_; + + DISALLOW_COPY_AND_ASSIGN(InstantLoaderManager); +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_LOADER_MANAGER_H_ diff --git a/chrome/browser/tab_contents/loader_manager_unittest.cc b/chrome/browser/instant/instant_loader_manager_unittest.cc index 4c9c5de..855bf59 100644 --- a/chrome/browser/tab_contents/loader_manager_unittest.cc +++ b/chrome/browser/instant/instant_loader_manager_unittest.cc @@ -3,56 +3,56 @@ // found in the LICENSE file. #include "base/scoped_ptr.h" -#include "chrome/browser/tab_contents/loader_manager.h" -#include "chrome/browser/tab_contents/match_preview_loader.h" -#include "chrome/browser/tab_contents/match_preview_loader_delegate.h" +#include "chrome/browser/instant/instant_loader.h" +#include "chrome/browser/instant/instant_loader_delegate.h" +#include "chrome/browser/instant/instant_loader_manager.h" #include "testing/gtest/include/gtest/gtest.h" namespace { -class MatchPreviewLoaderDelegateImpl : public MatchPreviewLoaderDelegate { +class InstantLoaderDelegateImpl : public InstantLoaderDelegate { public: - MatchPreviewLoaderDelegateImpl() {} + InstantLoaderDelegateImpl() {} - virtual void ShowMatchPreviewLoader(MatchPreviewLoader* loader) {} + virtual void ShowInstantLoader(InstantLoader* loader) {} - virtual void SetSuggestedTextFor(MatchPreviewLoader* loader, + virtual void SetSuggestedTextFor(InstantLoader* loader, const string16& text) {} - virtual gfx::Rect GetMatchPreviewBounds() { + virtual gfx::Rect GetInstantBounds() { return gfx::Rect(); } - virtual bool ShouldCommitPreviewOnMouseUp() { + virtual bool ShouldCommitInstantOnMouseUp() { return false; } - virtual void CommitPreview(MatchPreviewLoader* loader) { + virtual void CommitInstantLoader(InstantLoader* loader) { } private: - DISALLOW_COPY_AND_ASSIGN(MatchPreviewLoaderDelegateImpl); + DISALLOW_COPY_AND_ASSIGN(InstantLoaderDelegateImpl); }; } -class LoaderManagerTest : public testing::Test { +class InstantLoaderManagerTest : public testing::Test { public: - LoaderManagerTest() {} + InstantLoaderManagerTest() {} - void MarkReady(MatchPreviewLoader* loader) { + void MarkReady(InstantLoader* loader) { loader->ready_ = true; } private: - DISALLOW_COPY_AND_ASSIGN(LoaderManagerTest); + DISALLOW_COPY_AND_ASSIGN(InstantLoaderManagerTest); }; // Makes sure UpdateLoader works when invoked once. -TEST_F(LoaderManagerTest, Basic) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, Basic) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(0, &loader); EXPECT_EQ(NULL, loader.get()); EXPECT_TRUE(manager.current_loader()); @@ -62,12 +62,12 @@ TEST_F(LoaderManagerTest, Basic) { // Make sure invoking update twice for non-instant results keeps the same // loader. -TEST_F(LoaderManagerTest, UpdateTwice) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, UpdateTwice) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(0, &loader); - MatchPreviewLoader* current_loader = manager.current_loader(); + InstantLoader* current_loader = manager.current_loader(); manager.UpdateLoader(0, &loader); EXPECT_EQ(NULL, loader.get()); EXPECT_EQ(current_loader, manager.current_loader()); @@ -75,12 +75,12 @@ TEST_F(LoaderManagerTest, UpdateTwice) { } // Make sure invoking update twice for instant results keeps the same loader. -TEST_F(LoaderManagerTest, UpdateInstantTwice) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, UpdateInstantTwice) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(1, &loader); - MatchPreviewLoader* current_loader = manager.current_loader(); + InstantLoader* current_loader = manager.current_loader(); manager.UpdateLoader(1, &loader); EXPECT_EQ(NULL, loader.get()); EXPECT_EQ(current_loader, manager.current_loader()); @@ -89,12 +89,12 @@ TEST_F(LoaderManagerTest, UpdateInstantTwice) { } // Makes sure transitioning from non-instant to instant works. -TEST_F(LoaderManagerTest, NonInstantToInstant) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, NonInstantToInstant) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(0, &loader); - MatchPreviewLoader* current_loader = manager.current_loader(); + InstantLoader* current_loader = manager.current_loader(); manager.UpdateLoader(1, &loader); EXPECT_TRUE(loader.get() != NULL); EXPECT_NE(current_loader, manager.current_loader()); @@ -104,12 +104,12 @@ TEST_F(LoaderManagerTest, NonInstantToInstant) { // Makes sure instant loaders aren't deleted when invoking update with different // ids. -TEST_F(LoaderManagerTest, DontDeleteInstantLoaders) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, DontDeleteInstantLoaders) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(1, &loader); - MatchPreviewLoader* current_loader = manager.current_loader(); + InstantLoader* current_loader = manager.current_loader(); manager.UpdateLoader(2, &loader); EXPECT_EQ(NULL, loader.get()); EXPECT_NE(current_loader, manager.current_loader()); @@ -119,12 +119,12 @@ TEST_F(LoaderManagerTest, DontDeleteInstantLoaders) { // Makes sure a new loader is created and assigned to secondary when // transitioning from a ready non-instant to instant. -TEST_F(LoaderManagerTest, CreateSecondaryWhenReady) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, CreateSecondaryWhenReady) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(0, &loader); - MatchPreviewLoader* current_loader = manager.current_loader(); + InstantLoader* current_loader = manager.current_loader(); ASSERT_TRUE(current_loader); MarkReady(current_loader); @@ -136,7 +136,7 @@ TEST_F(LoaderManagerTest, CreateSecondaryWhenReady) { EXPECT_EQ(1u, manager.num_instant_loaders()); // Make the pending loader current. - MatchPreviewLoader* pending_loader = manager.pending_loader(); + InstantLoader* pending_loader = manager.pending_loader(); manager.MakePendingCurrent(&loader); EXPECT_TRUE(loader.get()); EXPECT_EQ(pending_loader, manager.current_loader()); @@ -145,12 +145,12 @@ TEST_F(LoaderManagerTest, CreateSecondaryWhenReady) { } // Makes sure releasing an instant updates maps currectly. -TEST_F(LoaderManagerTest, ReleaseInstant) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, ReleaseInstant) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(1, &loader); - scoped_ptr<MatchPreviewLoader> current_loader(manager.ReleaseCurrentLoader()); + scoped_ptr<InstantLoader> current_loader(manager.ReleaseCurrentLoader()); EXPECT_TRUE(current_loader.get()); EXPECT_EQ(NULL, manager.current_loader()); EXPECT_EQ(0u, manager.num_instant_loaders()); @@ -158,17 +158,17 @@ TEST_F(LoaderManagerTest, ReleaseInstant) { // Tests transitioning from a non-instant ready loader to an instant ready // loader is immediate. -TEST_F(LoaderManagerTest, NonInstantToInstantWhenReady) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, NonInstantToInstantWhenReady) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(1, &loader); ASSERT_TRUE(manager.current_loader()); EXPECT_EQ(1, manager.current_loader()->template_url_id()); - MatchPreviewLoader* instant_loader = manager.current_loader(); + InstantLoader* instant_loader = manager.current_loader(); manager.UpdateLoader(0, &loader); - MatchPreviewLoader* non_instant_loader = manager.current_loader(); + InstantLoader* non_instant_loader = manager.current_loader(); ASSERT_TRUE(non_instant_loader); MarkReady(non_instant_loader); EXPECT_NE(non_instant_loader, instant_loader); @@ -182,25 +182,25 @@ TEST_F(LoaderManagerTest, NonInstantToInstantWhenReady) { } // Tests transitioning between 3 instant loaders, all ready. -TEST_F(LoaderManagerTest, ThreeInstant) { - MatchPreviewLoaderDelegateImpl delegate; - LoaderManager manager(&delegate); - scoped_ptr<MatchPreviewLoader> loader; +TEST_F(InstantLoaderManagerTest, ThreeInstant) { + InstantLoaderDelegateImpl delegate; + InstantLoaderManager manager(&delegate); + scoped_ptr<InstantLoader> loader; manager.UpdateLoader(1, &loader); ASSERT_TRUE(manager.current_loader()); EXPECT_EQ(1, manager.current_loader()->template_url_id()); - MatchPreviewLoader* instant_loader1 = manager.current_loader(); + InstantLoader* instant_loader1 = manager.current_loader(); MarkReady(instant_loader1); manager.UpdateLoader(2, &loader); - MatchPreviewLoader* instant_loader2 = manager.pending_loader(); + InstantLoader* instant_loader2 = manager.pending_loader(); ASSERT_TRUE(instant_loader2); EXPECT_EQ(2, instant_loader2->template_url_id()); EXPECT_NE(instant_loader1, instant_loader2); EXPECT_EQ(instant_loader1, manager.current_loader()); manager.UpdateLoader(3, &loader); - MatchPreviewLoader* instant_loader3 = manager.pending_loader(); + InstantLoader* instant_loader3 = manager.pending_loader(); ASSERT_TRUE(instant_loader3); EXPECT_EQ(3, instant_loader3->template_url_id()); EXPECT_NE(instant_loader1, instant_loader3); diff --git a/chrome/browser/tab_contents/loader_manager.h b/chrome/browser/tab_contents/loader_manager.h deleted file mode 100644 index a72defc..0000000 --- a/chrome/browser/tab_contents/loader_manager.h +++ /dev/null @@ -1,97 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_LOADER_MANAGER_H_ -#define CHROME_BROWSER_TAB_CONTENTS_LOADER_MANAGER_H_ -#pragma once - -#include <map> - -#include "base/scoped_ptr.h" -#include "chrome/browser/search_engines/template_url_id.h" - -class MatchPreviewLoader; -class MatchPreviewLoaderDelegate; - -// LoaderManager is responsible for maintaining the MatchPreviewLoaders for -// MatchPreview. LoaderManager keeps track of one loader for loading non-instant -// urls, and a loader per TemplateURLID for loading instant urls. A loader per -// TemplateURLID is necessitated due to not knowing in advance if a site -// really supports instant (for example, the user might have opted out even -// though it's supported). -// -// Users of LoaderManager need only concern themselves with the current and -// pending loaders. The current loader is the loader that if ready is shown by -// MatchPreview. The pending loader is used if the current loader is ready and -// update is invoked with a different id. In this case the current loader is -// left as current (and it's preview contents stopped) and the newly created -// loader is set to pending. Once the pending loader is ready -// MakePendingCurrent should be invoked to make the pending the current loader. -// -// MatchPreviewLoader owns all the MatchPreviewLoaders returned. You can take -// ownership of the current loader by invoking ReleaseCurrentLoader. -class LoaderManager { - public: - explicit LoaderManager(MatchPreviewLoaderDelegate* loader_delegate); - ~LoaderManager(); - - // Updates the current loader. If the current loader is replaced and should be - // deleted it is set in |old_loader|. This is done to allow the caller to - // notify delegates before the old loader is destroyed. This returns the - // active MatchPreviewLoader that should be used. - MatchPreviewLoader* UpdateLoader(TemplateURLID instant_id, - scoped_ptr<MatchPreviewLoader>* old_loader); - - // Makes the pending loader the current loader. If ownership of the old - // loader is to pass to the caller |old_loader| is set appropriately. - void MakePendingCurrent(scoped_ptr<MatchPreviewLoader>* old_loader); - - // Returns the current loader and clears internal references to it. This - // should be used prior to destroying the LoaderManager when the owner of - // LoaderManager wants to take ownership of the loader. - MatchPreviewLoader* ReleaseCurrentLoader(); - - // Returns the current loader, may be null. - MatchPreviewLoader* current_loader() const { return current_loader_; } - - // Returns the pending loader, may be null. - MatchPreviewLoader* pending_loader() const { return pending_loader_; } - - // The active loader is the loader that should be used for new loads. It is - // either the pending loader or the current loader. - MatchPreviewLoader* active_loader() const { - return pending_loader_ ? pending_loader_ : current_loader_; - } - - // Returns the number of instant loaders. - // This is exposed for tests. - size_t num_instant_loaders() const { return instant_loaders_.size(); } - - private: - typedef std::map<TemplateURLID, MatchPreviewLoader*> Loaders; - - // Creates a loader and if |id| is non-zero registers it in instant_loaders_. - MatchPreviewLoader* CreateLoader(TemplateURLID id); - - // Returns the loader for loading instant results with the specified id. If - // there is no loader for the specified id a new one is created. - MatchPreviewLoader* GetInstantLoader(TemplateURLID id); - - MatchPreviewLoaderDelegate* loader_delegate_; - - // The current loader. - MatchPreviewLoader* current_loader_; - - // Loader we want to use as soon as ready. This is only non-null if - // current_loader_ is ready and Update is invoked with a different template - // url id. - MatchPreviewLoader* pending_loader_; - - // Maps for template url id to loader used for that template url id. - Loaders instant_loaders_; - - DISALLOW_COPY_AND_ASSIGN(LoaderManager); -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_LOADER_MANAGER_H_ diff --git a/chrome/browser/tab_contents/match_preview_commit_type.h b/chrome/browser/tab_contents/match_preview_commit_type.h deleted file mode 100644 index a4bbd3f..0000000 --- a/chrome/browser/tab_contents/match_preview_commit_type.h +++ /dev/null @@ -1,22 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_COMMIT_TYPE_H_ -#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_COMMIT_TYPE_H_ -#pragma once - -// Enum describing the ways the MatchPreview can be committed. -enum MatchPreviewCommitType { - // The commit is the result of the user pressing enter. - MATCH_PREVIEW_COMMIT_PRESSED_ENTER, - - // The commit is the result of focus being lost. This typically corresponds - // to a mouse click event. - MATCH_PREVIEW_COMMIT_FOCUS_LOST, - - // Used internally by MatchPreview. - MATCH_PREVIEW_COMMIT_DESTROY -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_COMMIT_TYPE_H_ diff --git a/chrome/browser/tab_contents/match_preview_delegate.h b/chrome/browser/tab_contents/match_preview_delegate.h deleted file mode 100644 index fed4d89..0000000 --- a/chrome/browser/tab_contents/match_preview_delegate.h +++ /dev/null @@ -1,43 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_DELEGATE_H_ -#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_DELEGATE_H_ -#pragma once - -#include "base/string16.h" - -class TabContents; - -namespace gfx { -class Rect; -} - -// MatchPreview's delegate. Normally the Browser implements this. See -// MatchPreview for details. -class MatchPreviewDelegate { - public: - // Invoked when the preview TabContents should be shown. - virtual void ShowMatchPreview(TabContents* preview_contents) = 0; - - // Invoked when the preview TabContents should be hidden. - virtual void HideMatchPreview() = 0; - - // Invoked when the user does something that should result in the preview - // TabContents becoming the active TabContents. The delegate takes ownership - // of the supplied TabContents. - virtual void CommitMatchPreview(TabContents* preview_contents) = 0; - - // Invoked when the suggested text is to change to |text|. - virtual void SetSuggestedText(const string16& text) = 0; - - // Returns the bounds the match preview will be placed in, in screen - // coordinates. - virtual gfx::Rect GetMatchPreviewBounds() = 0; - - protected: - virtual ~MatchPreviewDelegate() {} -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_DELEGATE_H_ diff --git a/chrome/browser/tab_contents/match_preview_loader_delegate.h b/chrome/browser/tab_contents/match_preview_loader_delegate.h deleted file mode 100644 index 3384b0c..0000000 --- a/chrome/browser/tab_contents/match_preview_loader_delegate.h +++ /dev/null @@ -1,38 +0,0 @@ -// Copyright (c) 2010 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_DELEGATE_H_ -#define CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_DELEGATE_H_ -#pragma once - -#include "base/string16.h" - -namespace gfx { -class Rect; -} - -class MatchPreviewLoader; - -// MatchPreviewLoader's delegate. This interface is implemented by -// MatchPreview. -class MatchPreviewLoaderDelegate { - public: - // Invoked when the loader is ready to be shown. - virtual void ShowMatchPreviewLoader(MatchPreviewLoader* loader) = 0; - - // Invoked when the renderer has suggested text. - virtual void SetSuggestedTextFor(MatchPreviewLoader* loader, - const string16& text) = 0; - - // Returns the bounds of the match preview. - virtual gfx::Rect GetMatchPreviewBounds() = 0; - - // Returns true if preview should be committed on mouse up. - virtual bool ShouldCommitPreviewOnMouseUp() = 0; - - // Invoked when the preview should be committed. - virtual void CommitPreview(MatchPreviewLoader* loader) = 0; -}; - -#endif // CHROME_BROWSER_TAB_CONTENTS_MATCH_PREVIEW_LOADER_DELEGATE_H_ diff --git a/chrome/browser/views/app_launcher.cc b/chrome/browser/views/app_launcher.cc index 6c5a635..fb2bf50 100644 --- a/chrome/browser/views/app_launcher.cc +++ b/chrome/browser/views/app_launcher.cc @@ -86,7 +86,7 @@ class InfoBubbleContentsView : public views::View, // WARNING: this is not the TabContents of the bubble! Use // GetBubbleTabContents() to get the bubble's TabContents. virtual TabContents* GetTabContents(); - virtual MatchPreview* GetMatchPreview() { return NULL; } + virtual InstantController* GetInstant() { return NULL; } virtual void OnInputInProgress(bool in_progress) {} // CommandUpdater::CommandUpdaterDelegate implementation: diff --git a/chrome/browser/views/frame/browser_view.cc b/chrome/browser/views/frame/browser_view.cc index a2bacef..8c2eea6 100644 --- a/chrome/browser/views/frame/browser_view.cc +++ b/chrome/browser/views/frame/browser_view.cc @@ -26,6 +26,7 @@ #include "chrome/browser/debugger/devtools_window.h" #include "chrome/browser/dom_ui/bug_report_ui.h" #include "chrome/browser/download/download_manager.h" +#include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/ntp_background_util.h" #include "chrome/browser/page_info_window.h" #include "chrome/browser/prefs/pref_service.h" @@ -33,7 +34,6 @@ #include "chrome/browser/sessions/tab_restore_service.h" #include "chrome/browser/sidebar/sidebar_container.h" #include "chrome/browser/sidebar/sidebar_manager.h" -#include "chrome/browser/tab_contents/match_preview.h" #include "chrome/browser/tab_contents/tab_contents.h" #include "chrome/browser/tab_contents/tab_contents_view.h" #include "chrome/browser/tabs/tab_strip_model.h" @@ -1355,14 +1355,14 @@ void BrowserView::ToggleTabStripMode() { frame_->TabStripDisplayModeChanged(); } -void BrowserView::ShowMatchPreview(TabContents* preview_contents) { +void BrowserView::ShowInstant(TabContents* preview_contents) { if (!preview_container_) preview_container_ = new TabContentsContainer(); contents_->SetPreview(preview_container_, preview_contents); preview_container_->ChangeTabContents(preview_contents); } -void BrowserView::HideMatchPreview() { +void BrowserView::HideInstant() { if (!preview_container_) return; @@ -1373,7 +1373,7 @@ void BrowserView::HideMatchPreview() { preview_container_ = NULL; } -gfx::Rect BrowserView::GetMatchPreviewBounds() { +gfx::Rect BrowserView::GetInstantBounds() { return contents_->GetPreviewBounds(); } diff --git a/chrome/browser/views/frame/browser_view.h b/chrome/browser/views/frame/browser_view.h index ec9111d..71e99e3 100644 --- a/chrome/browser/views/frame/browser_view.h +++ b/chrome/browser/views/frame/browser_view.h @@ -321,9 +321,9 @@ class BrowserView : public BrowserBubbleHost, virtual void Copy(); virtual void Paste(); virtual void ToggleTabStripMode(); - virtual void ShowMatchPreview(TabContents* preview_contents); - virtual void HideMatchPreview(); - virtual gfx::Rect GetMatchPreviewBounds(); + virtual void ShowInstant(TabContents* preview_contents); + virtual void HideInstant(); + virtual gfx::Rect GetInstantBounds(); // Overridden from BrowserWindowTesting: virtual BookmarkBarView* GetBookmarkBarView() const; @@ -496,7 +496,7 @@ class BrowserView : public BrowserBubbleHost, // Initialize the hung plugin detector. void InitHangMonitor(); - // Invoked from TabSelectedAt or when the match preview is made active. Is + // Invoked from TabSelectedAt or when instant is made active. Is // |change_tab_contents| is true, |new_contents| is added to the view // hierarchy, if |change_tab_contents| is false, it's assumed |new_contents| // has already been added to the view hierarchy. @@ -584,7 +584,7 @@ class BrowserView : public BrowserBubbleHost, // The view that contains devtools window for the selected TabContents. TabContentsContainer* devtools_container_; - // The view that contains the match preview TabContents. + // The view that contains instant's TabContents. TabContentsContainer* preview_container_; // The view managing both the contents_container_ and preview_container_. diff --git a/chrome/browser/views/frame/contents_container.h b/chrome/browser/views/frame/contents_container.h index 9a03c38..fe22d47 100644 --- a/chrome/browser/views/frame/contents_container.h +++ b/chrome/browser/views/frame/contents_container.h @@ -17,7 +17,7 @@ class Widget; // ContentsContainer is responsible for managing the TabContents views. // ContentsContainer has up to two children: one for the currently active -// TabContents and one for the match preview TabContents. +// TabContents and one for instant's TabContents. class ContentsContainer : public views::View { public: ContentsContainer(BrowserView* browser_view, views::View* active); diff --git a/chrome/browser/views/location_bar/location_bar_view.cc b/chrome/browser/views/location_bar/location_bar_view.cc index 5af0fe5..8235e03 100644 --- a/chrome/browser/views/location_bar/location_bar_view.cc +++ b/chrome/browser/views/location_bar/location_bar_view.cc @@ -20,11 +20,11 @@ #include "chrome/browser/defaults.h" #include "chrome/browser/extensions/extension_browser_event_router.h" #include "chrome/browser/extensions/extensions_service.h" +#include "chrome/browser/instant/instant_controller.h" #include "chrome/browser/profile.h" #include "chrome/browser/renderer_host/render_widget_host_view.h" #include "chrome/browser/search_engines/template_url.h" #include "chrome/browser/search_engines/template_url_model.h" -#include "chrome/browser/tab_contents/match_preview.h" #include "chrome/browser/view_ids.h" #include "chrome/browser/views/browser_dialogs.h" #include "chrome/browser/views/location_bar/content_setting_image_view.h" @@ -101,7 +101,7 @@ LocationBarView::LocationBarView(Profile* profile, show_focus_rect_(false), bubble_type_(FirstRun::MINIMAL_BUBBLE), template_url_model_(NULL), - update_match_preview_(true) { + update_instant_(true) { DCHECK(profile_); SetID(VIEW_ID_LOCATION_BAR); SetFocusable(true); @@ -717,34 +717,34 @@ void LocationBarView::OnMouseReleased(const views::MouseEvent& event, #endif void LocationBarView::OnAutocompleteWillClosePopup() { - if (!update_match_preview_) + if (!update_instant_) return; - MatchPreview* match_preview = delegate_->GetMatchPreview(); - if (match_preview && !match_preview->commit_on_mouse_up()) - match_preview->DestroyPreviewContents(); + InstantController* instant = delegate_->GetInstant(); + if (instant && !instant->commit_on_mouse_up()) + instant->DestroyPreviewContents(); } void LocationBarView::OnAutocompleteLosingFocus( gfx::NativeView view_gaining_focus) { SetSuggestedText(string16()); - MatchPreview* match_preview = delegate_->GetMatchPreview(); - if (!match_preview) + InstantController* instant = delegate_->GetInstant(); + if (!instant) return; - if (!match_preview->is_active() || !match_preview->GetPreviewContents()) + if (!instant->is_active() || !instant->GetPreviewContents()) return; switch (GetCommitType(view_gaining_focus)) { - case COMMIT_MATCH_PREVIEW_IMMEDIATELY: - match_preview->CommitCurrentPreview(MATCH_PREVIEW_COMMIT_FOCUS_LOST); + case COMMIT_INSTANT_IMMEDIATELY: + instant->CommitCurrentPreview(INSTANT_COMMIT_FOCUS_LOST); break; - case COMMIT_MATCH_PREVIEW_ON_MOUSE_UP: - match_preview->SetCommitOnMouseUp(); + case COMMIT_INSTANT_ON_MOUSE_UP: + instant->SetCommitOnMouseUp(); break; - case REVERT_MATCH_PREVIEW: - match_preview->DestroyPreviewContents(); + case REVERT_INSTANT: + instant->DestroyPreviewContents(); break; default: NOTREACHED(); @@ -752,26 +752,26 @@ void LocationBarView::OnAutocompleteLosingFocus( } void LocationBarView::OnAutocompleteWillAccept() { - update_match_preview_ = false; + update_instant_ = false; } bool LocationBarView::OnCommitSuggestedText(const std::wstring& typed_text) { - MatchPreview* match_preview = delegate_->GetMatchPreview(); - if (!match_preview || !suggested_text_view_ || + InstantController* instant = delegate_->GetInstant(); + if (!instant || !suggested_text_view_ || suggested_text_view_->size().IsEmpty() || suggested_text_view_->GetText().empty()) { return false; } - // TODO(sky): I may need to route this through MatchPreview so that we don't + // TODO(sky): I may need to route this through InstantController so that we don't // fetch suggestions for the new combined text. location_entry_->SetUserText(typed_text + suggested_text_view_->GetText()); return true; } void LocationBarView::OnPopupBoundsChanged(const gfx::Rect& bounds) { - MatchPreview* match_preview = delegate_->GetMatchPreview(); - if (match_preview) - match_preview->SetOmniboxBounds(bounds); + InstantController* instant = delegate_->GetInstant(); + if (instant) + instant->SetOmniboxBounds(bounds); } void LocationBarView::OnAutocompleteAccept( @@ -808,10 +808,10 @@ void LocationBarView::OnAutocompleteAccept( } } - if (delegate_->GetMatchPreview()) - delegate_->GetMatchPreview()->DestroyPreviewContents(); + if (delegate_->GetInstant()) + delegate_->GetInstant()->DestroyPreviewContents(); - update_match_preview_ = true; + update_instant_ = true; } void LocationBarView::OnChanged() { @@ -821,17 +821,17 @@ void LocationBarView::OnChanged() { Layout(); SchedulePaint(); - MatchPreview* match_preview = delegate_->GetMatchPreview(); + InstantController* instant = delegate_->GetInstant(); string16 suggested_text; - if (update_match_preview_ && match_preview && GetTabContents()) { + if (update_instant_ && instant && GetTabContents()) { if (location_entry_->model()->user_input_in_progress() && location_entry_->model()->popup_model()->IsOpen()) { - match_preview->Update(GetTabContents(), - location_entry_->model()->CurrentMatch(), - WideToUTF16(location_entry_->GetText()), - &suggested_text); + instant->Update(GetTabContents(), + location_entry_->model()->CurrentMatch(), + WideToUTF16(location_entry_->GetText()), + &suggested_text); } else { - match_preview->DestroyPreviewContents(); + instant->DestroyPreviewContents(); } } @@ -1201,34 +1201,33 @@ void LocationBarView::OnTemplateURLModelChanged() { ShowFirstRunBubble(bubble_type_); } -LocationBarView::MatchPreviewCommitType LocationBarView::GetCommitType( +LocationBarView::InstantCommitType LocationBarView::GetCommitType( gfx::NativeView view_gaining_focus) { - // The MatchPreview is active. Destroy it if the user didn't click on the + // The InstantController is active. Destroy it if the user didn't click on the // TabContents (or one of its children). #if defined(OS_WIN) - MatchPreview* match_preview = delegate_->GetMatchPreview(); + InstantController* instant = delegate_->GetInstant(); RenderWidgetHostView* rwhv = - match_preview->GetPreviewContents()->GetRenderWidgetHostView(); + instant->GetPreviewContents()->GetRenderWidgetHostView(); if (!view_gaining_focus || !rwhv) - return REVERT_MATCH_PREVIEW; + return REVERT_INSTANT; - gfx::NativeView tab_view = - match_preview->GetPreviewContents()->GetNativeView(); + gfx::NativeView tab_view = instant->GetPreviewContents()->GetNativeView(); if (rwhv->GetNativeView() == view_gaining_focus || tab_view == view_gaining_focus) { - // Focus is going to the renderer. Only commit the match preview if the - // mouse is down. If the mouse isn't down it means someone else moved focus - // and we shouldn't commit. - if (match_preview->IsMouseDownFromActivate()) { - if (match_preview->IsShowingInstant()) { + // Focus is going to the renderer. Only commit instant if the mouse is + // down. If the mouse isn't down it means someone else moved focus and we + // shouldn't commit. + if (instant->IsMouseDownFromActivate()) { + if (instant->IsShowingInstant()) { // We're showing instant results. As instant results may shift when // committing we commit on the mouse up. This way a slow click still // works fine. - return COMMIT_MATCH_PREVIEW_ON_MOUSE_UP; + return COMMIT_INSTANT_ON_MOUSE_UP; } - return COMMIT_MATCH_PREVIEW_IMMEDIATELY; + return COMMIT_INSTANT_IMMEDIATELY; } - return REVERT_MATCH_PREVIEW; + return REVERT_INSTANT; } gfx::NativeView view_gaining_focus_ancestor = view_gaining_focus; while (view_gaining_focus_ancestor && @@ -1236,10 +1235,10 @@ LocationBarView::MatchPreviewCommitType LocationBarView::GetCommitType( view_gaining_focus_ancestor = ::GetParent(view_gaining_focus_ancestor); } return view_gaining_focus_ancestor != NULL ? - COMMIT_MATCH_PREVIEW_IMMEDIATELY : REVERT_MATCH_PREVIEW; + COMMIT_INSTANT_IMMEDIATELY : REVERT_INSTANT; #else // TODO: implement me. NOTIMPLEMENTED(); - return REVERT_MATCH_PREVIEW; + return REVERT_INSTANT; #endif } diff --git a/chrome/browser/views/location_bar/location_bar_view.h b/chrome/browser/views/location_bar/location_bar_view.h index 1b8762d..15c785d 100644 --- a/chrome/browser/views/location_bar/location_bar_view.h +++ b/chrome/browser/views/location_bar/location_bar_view.h @@ -36,9 +36,9 @@ class ContentSettingImageView; class EVBubbleView; class ExtensionAction; class GURL; +class InstantController; class KeywordHintView; class LocationIconView; -class MatchPreview; class PageActionWithBadgeView; class Profile; class SelectedKeywordView; @@ -73,8 +73,8 @@ class LocationBarView : public LocationBar, // Should return the current tab contents. virtual TabContents* GetTabContents() = 0; - // Returns the MatchPreview, or NULL if there isn't one. - virtual MatchPreview* GetMatchPreview() = 0; + // Returns the InstantController, or NULL if there isn't one. + virtual InstantController* GetInstant() = 0; // Called by the location bar view when the user starts typing in the edit. // This forces our security style to be UNKNOWN for the duration of the @@ -257,16 +257,16 @@ class LocationBarView : public LocationBar, private: typedef std::vector<ContentSettingImageView*> ContentSettingViews; - // Enumeration of what should happen to the match preview on focus lost. - enum MatchPreviewCommitType { - // The match preview should be committed immediately. - COMMIT_MATCH_PREVIEW_IMMEDIATELY, + // Enumeration of what should happen to instant on focus lost. + enum InstantCommitType { + // The instant preview should be committed immediately. + COMMIT_INSTANT_IMMEDIATELY, - // The match preview should be committed on mouse up. - COMMIT_MATCH_PREVIEW_ON_MOUSE_UP, + // The instant preview should be committed on mouse up. + COMMIT_INSTANT_ON_MOUSE_UP, - // The match preview should be reverted. - REVERT_MATCH_PREVIEW + // The instant preview should be reverted. + REVERT_INSTANT }; friend class PageActionImageView; @@ -311,9 +311,9 @@ class LocationBarView : public LocationBar, // Helper to show the first run info bubble. void ShowFirstRunBubbleInternal(FirstRun::BubbleType bubble_type); - // Returns what should happen to the MatchPreview as a result of focus being - // lost. - MatchPreviewCommitType GetCommitType(gfx::NativeView view_gaining_focus); + // Returns what should happen to the InstantController as a result of focus + // being lost. + InstantCommitType GetCommitType(gfx::NativeView view_gaining_focus); // Current profile. Not owned by us. Profile* profile_; @@ -403,11 +403,11 @@ class LocationBarView : public LocationBar, scoped_ptr<AccessibleWidgetHelper> accessible_widget_helper_; #endif - // Should the match preview be updated? This is set to false in - // OnAutocompleteWillAccept and true in OnAutocompleteAccept. This is needed - // as prior to accepting an autocomplete suggestion the model is reverted - // which triggers resetting the match preview. - bool update_match_preview_; + // Should instant be updated? This is set to false in OnAutocompleteWillAccept + // and true in OnAutocompleteAccept. This is needed as prior to accepting an + // autocomplete suggestion the model is reverted which triggers resetting + // instant. + bool update_instant_; DISALLOW_IMPLICIT_CONSTRUCTORS(LocationBarView); }; diff --git a/chrome/browser/views/toolbar_view.cc b/chrome/browser/views/toolbar_view.cc index d2cc229..0bd1e1e 100644 --- a/chrome/browser/views/toolbar_view.cc +++ b/chrome/browser/views/toolbar_view.cc @@ -274,8 +274,8 @@ TabContents* ToolbarView::GetTabContents() { return browser_->GetSelectedTabContents(); } -MatchPreview* ToolbarView::GetMatchPreview() { - return browser_->match_preview(); +InstantController* ToolbarView::GetInstant() { + return browser_->instant(); } void ToolbarView::OnInputInProgress(bool in_progress) { diff --git a/chrome/browser/views/toolbar_view.h b/chrome/browser/views/toolbar_view.h index 84ad2b0..1cb8fd0 100644 --- a/chrome/browser/views/toolbar_view.h +++ b/chrome/browser/views/toolbar_view.h @@ -89,7 +89,7 @@ class ToolbarView : public AccessibleToolbarView, // Overridden from LocationBarView::Delegate: virtual TabContents* GetTabContents(); - virtual MatchPreview* GetMatchPreview(); + virtual InstantController* GetInstant(); virtual void OnInputInProgress(bool in_progress); // Overridden from AnimationDelegate: |