From ddd28ae31cb3fbfc2a06fc0b9469e27712645434 Mon Sep 17 00:00:00 2001 From: "sreeram@chromium.org" Date: Mon, 4 Mar 2013 21:11:54 +0000 Subject: Instant: Rename 'preview' to 'overlay' This CL has only cosmetic changes. It's in service of a larger refactor. Also: + Renames InstantModel* to InstantOverlayModel* to make it clear that the model is meant only for the overlay, and not committed tabs that Instant works with. BUG=none R=sky@chromium.org TEST=none Review URL: https://chromiumcodereview.appspot.com/12381078 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@185971 0039d316-1c4b-4281-b951-d872f2087c98 --- chrome/browser/infobars/infobar_container.cc | 10 +- chrome/browser/infobars/infobar_container.h | 10 +- chrome/browser/instant/instant_browsertest.cc | 322 ++++++++++----------- chrome/browser/instant/instant_controller.cc | 162 +++++------ chrome/browser/instant/instant_controller.h | 63 ++-- .../instant/instant_extended_browsertest.cc | 136 ++++----- chrome/browser/instant/instant_loader.cc | 2 +- chrome/browser/instant/instant_model.cc | 64 ---- chrome/browser/instant/instant_model.h | 64 ---- chrome/browser/instant/instant_model_observer.h | 21 -- chrome/browser/instant/instant_ntp.h | 2 +- chrome/browser/instant/instant_overlay.cc | 4 +- chrome/browser/instant/instant_overlay.h | 10 +- .../browser/instant/instant_overlay_controller.cc | 19 ++ .../browser/instant/instant_overlay_controller.h | 28 ++ chrome/browser/instant/instant_overlay_model.cc | 66 +++++ chrome/browser/instant/instant_overlay_model.h | 64 ++++ .../instant/instant_overlay_model_observer.h | 21 ++ .../browser/instant/instant_preview_controller.cc | 19 -- .../browser/instant/instant_preview_controller.h | 27 -- chrome/browser/instant/instant_test_utils.cc | 15 +- chrome/browser/instant/instant_test_utils.h | 16 +- chrome/browser/resources/instant/instant.css | 2 +- chrome/browser/resources/instant/instant.html | 2 +- chrome/browser/resources/instant/instant.js | 9 +- .../task_manager_resource_providers.cc | 26 +- .../task_manager/task_manager_resource_providers.h | 9 +- chrome/browser/ui/browser.cc | 11 +- chrome/browser/ui/browser.h | 6 +- chrome/browser/ui/browser_instant_controller.cc | 20 +- chrome/browser/ui/browser_instant_controller.h | 16 +- chrome/browser/ui/cocoa/browser_window_cocoa.mm | 3 +- .../browser/ui/cocoa/browser_window_controller.h | 12 +- .../browser/ui/cocoa/browser_window_controller.mm | 26 +- .../cocoa/browser_window_controller_browsertest.mm | 72 ++--- .../ui/cocoa/browser_window_controller_private.h | 5 +- .../ui/cocoa/browser_window_controller_private.mm | 24 +- .../tab_contents/instant_overlay_controller_mac.h | 33 +++ .../tab_contents/instant_overlay_controller_mac.mm | 43 +++ .../tab_contents/instant_preview_controller_mac.h | 33 --- .../tab_contents/instant_preview_controller_mac.mm | 44 --- .../cocoa/tab_contents/overlay_drop_shadow_view.h | 13 + .../cocoa/tab_contents/overlay_drop_shadow_view.mm | 32 ++ .../overlay_drop_shadow_view_unittest.mm | 27 ++ .../tab_contents/overlayable_contents_controller.h | 92 ++++++ .../overlayable_contents_controller.mm | 180 ++++++++++++ .../overlayable_contents_controller_browsertest.mm | 144 +++++++++ .../cocoa/tab_contents/preview_drop_shadow_view.h | 13 - .../cocoa/tab_contents/preview_drop_shadow_view.mm | 32 -- .../preview_drop_shadow_view_unittest.mm | 27 -- .../tab_contents/previewable_contents_controller.h | 92 ------ .../previewable_contents_controller.mm | 180 ------------ .../previewable_contents_controller_browsertest.mm | 143 --------- chrome/browser/ui/gtk/browser_window_gtk.cc | 8 +- chrome/browser/ui/gtk/browser_window_gtk.h | 6 +- .../ui/gtk/instant_overlay_controller_gtk.cc | 31 ++ .../ui/gtk/instant_overlay_controller_gtk.h | 31 ++ .../ui/gtk/instant_preview_controller_gtk.cc | 31 -- .../ui/gtk/instant_preview_controller_gtk.h | 31 -- .../browser/ui/gtk/tab_contents_container_gtk.cc | 38 +-- chrome/browser/ui/gtk/tab_contents_container_gtk.h | 14 +- chrome/browser/ui/views/frame/browser_view.cc | 28 +- chrome/browser/ui/views/frame/browser_view.h | 10 +- .../browser/ui/views/frame/browser_view_layout.cc | 6 +- .../browser/ui/views/frame/contents_container.cc | 134 ++++----- chrome/browser/ui/views/frame/contents_container.h | 46 +-- .../frame/instant_overlay_controller_views.cc | 63 ++++ .../views/frame/instant_overlay_controller_views.h | 46 +++ .../frame/instant_preview_controller_views.cc | 63 ---- .../views/frame/instant_preview_controller_views.h | 46 --- 70 files changed, 1571 insertions(+), 1577 deletions(-) delete mode 100644 chrome/browser/instant/instant_model.cc delete mode 100644 chrome/browser/instant/instant_model.h delete mode 100644 chrome/browser/instant/instant_model_observer.h create mode 100644 chrome/browser/instant/instant_overlay_controller.cc create mode 100644 chrome/browser/instant/instant_overlay_controller.h create mode 100644 chrome/browser/instant/instant_overlay_model.cc create mode 100644 chrome/browser/instant/instant_overlay_model.h create mode 100644 chrome/browser/instant/instant_overlay_model_observer.h delete mode 100644 chrome/browser/instant/instant_preview_controller.cc delete mode 100644 chrome/browser/instant/instant_preview_controller.h create mode 100644 chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h create mode 100644 chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.mm delete mode 100644 chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h delete mode 100644 chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.mm create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view_unittest.mm create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm create mode 100644 chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm delete mode 100644 chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h delete mode 100644 chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.mm delete mode 100644 chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view_unittest.mm delete mode 100644 chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h delete mode 100644 chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm delete mode 100644 chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller_browsertest.mm create mode 100644 chrome/browser/ui/gtk/instant_overlay_controller_gtk.cc create mode 100644 chrome/browser/ui/gtk/instant_overlay_controller_gtk.h delete mode 100644 chrome/browser/ui/gtk/instant_preview_controller_gtk.cc delete mode 100644 chrome/browser/ui/gtk/instant_preview_controller_gtk.h create mode 100644 chrome/browser/ui/views/frame/instant_overlay_controller_views.cc create mode 100644 chrome/browser/ui/views/frame/instant_overlay_controller_views.h delete mode 100644 chrome/browser/ui/views/frame/instant_preview_controller_views.cc delete mode 100644 chrome/browser/ui/views/frame/instant_preview_controller_views.h (limited to 'chrome/browser') diff --git a/chrome/browser/infobars/infobar_container.cc b/chrome/browser/infobars/infobar_container.cc index 3da8c0f..b601744 100644 --- a/chrome/browser/infobars/infobar_container.cc +++ b/chrome/browser/infobars/infobar_container.cc @@ -15,7 +15,7 @@ #include "chrome/browser/api/infobars/infobar_delegate.h" #include "chrome/browser/api/infobars/infobar_service.h" #include "chrome/browser/infobars/infobar.h" -#include "chrome/browser/instant/instant_model.h" +#include "chrome/browser/instant/instant_overlay_model.h" #include "chrome/browser/ui/search/search_model.h" #include "chrome/common/chrome_notification_types.h" #include "content/public/browser/notification_details.h" @@ -48,7 +48,7 @@ void InfoBarContainer::ChangeInfoBarService(InfoBarService* infobar_service) { registrar_.RemoveAll(); // Note that HideAllInfoBars() sets |infobars_shown_| to false, because that's - // what the other, instant-related callers want; but here we actually + // what the other, Instant-related callers want; but here we actually // explicitly want to reset this variable to true. So do that after calling // the function. HideAllInfoBars(); @@ -179,8 +179,8 @@ void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, // Hide infobars when showing Instant Extended suggestions. if (new_mode.is_search_suggestions()) { // If suggestions are being shown on a |DEFAULT| page, delay the hiding - // until notification that instant preview is ready is received via - // PreviewStateChanged(); this prevents jankiness caused by infobars hiding + // until notification that Instant overlay is ready is received via + // OverlayStateChanged(); this prevents jankiness caused by infobars hiding // followed by suggestions appearing. if (new_mode.is_origin_default()) return; @@ -192,7 +192,7 @@ void InfoBarContainer::ModeChanged(const chrome::search::Mode& old_mode, } } -void InfoBarContainer::PreviewStateChanged(const InstantModel& model) { +void InfoBarContainer::OverlayStateChanged(const InstantOverlayModel& model) { // If suggestions are being shown on a |DEFAULT| page, hide the infobars now. // See comments for ModeChanged() for explanation. if (model.mode().is_search_suggestions() && diff --git a/chrome/browser/infobars/infobar_container.h b/chrome/browser/infobars/infobar_container.h index c1b6633..3808fb3 100644 --- a/chrome/browser/infobars/infobar_container.h +++ b/chrome/browser/infobars/infobar_container.h @@ -9,7 +9,7 @@ #include "base/compiler_specific.h" #include "base/time.h" -#include "chrome/browser/instant/instant_model_observer.h" +#include "chrome/browser/instant/instant_overlay_model_observer.h" #include "chrome/browser/ui/search/search_model_observer.h" #include "chrome/common/search_types.h" #include "content/public/browser/notification_observer.h" @@ -38,7 +38,7 @@ class SearchModel; // temporarily if the user changes into |SEARCH_SUGGESTIONS| mode (refer to // chrome::search::Mode in chrome/common/search_types.h for all search modes) // when on a : -// - |DEFAULT| page: when instant preview is ready; +// - |DEFAULT| page: when Instant overlay is ready; // - |NTP| or |SEARCH_RESULTS| page: immediately; // TODO(kuan): this scenario requires more complex synchronization with // renderer SearchBoxAPI and will be implemented as the next step; @@ -51,7 +51,7 @@ class SearchModel; // to re-hide infobars without animation is canceled if a tab change occurs. class InfoBarContainer : public content::NotificationObserver, public chrome::search::SearchModelObserver, - public InstantModelObserver { + public InstantOverlayModelObserver { public: class Delegate { public: @@ -110,8 +110,8 @@ class InfoBarContainer : public content::NotificationObserver, const Delegate* delegate() const { return delegate_; } - // InstantModelObserver: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; + // InstantOverlayModelObserver: + virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; protected: // Subclasses must call this during destruction, so that we can remove diff --git a/chrome/browser/instant/instant_browsertest.cc b/chrome/browser/instant/instant_browsertest.cc index c149544..893712e 100644 --- a/chrome/browser/instant/instant_browsertest.cc +++ b/chrome/browser/instant/instant_browsertest.cc @@ -75,9 +75,9 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_FALSE(omnibox()->model()->has_focus()); - // Delete any existing preview. + // Delete any existing overlay. instant()->overlay_.reset(); - EXPECT_FALSE(instant()->GetPreviewContents()); + EXPECT_FALSE(instant()->GetOverlayContents()); // Refocus the omnibox. The InstantController should've preloaded Instant. FocusOmniboxAndWaitForInstantSupport(); @@ -85,32 +85,32 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OmniboxFocusLoadsInstant) { EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(omnibox()->model()->has_focus()); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // Check that the page supports Instant, but it isn't showing. EXPECT_TRUE(instant()->overlay_->supports_instant()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); - // Adding a new tab shouldn't delete or recreate the preview; otherwise, + // Adding a new tab shouldn't delete or recreate the overlay; otherwise, // what's the point of preloading? AddBlankTabAndShow(browser()); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); - // Unfocusing and refocusing the omnibox should also preserve the preview. + // Unfocusing and refocusing the omnibox should also preserve the overlay. ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); FocusOmnibox(); EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); // Doing a search should also use the same preloaded page. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); } // Flakes on Windows and Mac: http://crbug.com/170677 @@ -138,11 +138,11 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { // Typing "query" into the omnibox causes one or more onchange events. The // page suggested "query suggestion" is inline autocompleted into the omnibox, // causing another onchange event. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); int min_onchangecalls = 2; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); EXPECT_LE(min_onchangecalls, onchangecalls_); min_onchangecalls = onchangecalls_; @@ -150,10 +150,10 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { SetOmniboxText("search"); ++min_onchangecalls; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); EXPECT_LE(min_onchangecalls, onchangecalls_); - // The preview was shown once, and the active tab was never hidden. + // The overlay was shown once, and the active tab was never hidden. EXPECT_EQ(1, onvisibilitycalls_); active_tab_onvisibilitycalls = -1; EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", @@ -165,14 +165,14 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_OnChangeEvent) { IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); - // Stash a reference to the preview, so we can refer to it after commit. - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + // Stash a reference to the overlay, so we can refer to it after commit. + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // The state of the searchbox before the commit. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_FALSE(verbatim_); EXPECT_EQ(0, onsubmitcalls_); @@ -181,7 +181,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { // Before the commit, the active tab is the NTP (i.e., not Instant). content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_NE(preview_tab, active_tab); + EXPECT_NE(overlay, active_tab); EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); EXPECT_EQ(std::string(chrome::kAboutBlankURL), omnibox()->model()->PermanentURL().spec()); @@ -190,50 +190,50 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnSubmitEvent) { browser()->window()->GetLocationBar()->AcceptInput(); // After the commit, Instant should not be showing. - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // The old overlay is deleted and a new one is created. - EXPECT_TRUE(instant()->GetPreviewContents()); - EXPECT_NE(instant()->GetPreviewContents(), preview_tab); + EXPECT_TRUE(instant()->GetOverlayContents()); + EXPECT_NE(instant()->GetOverlayContents(), overlay); - // Check that the current active tab is indeed what was once the preview. - EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); + // Check that the current active tab is indeed what was once the overlay. + EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); // We should have two navigation entries, one for the NTP, and one for the // Instant search that was committed. - EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); + EXPECT_EQ(2, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; - EXPECT_TRUE(GetStringFromJS(preview_tab, + EXPECT_TRUE(GetStringFromJS(overlay, "chrome.embeddedSearch.searchBox.value", &value)); EXPECT_EQ("", value); // However, the page should've correctly received the committed query. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_TRUE(verbatim_); EXPECT_EQ(1, onsubmitcalls_); EXPECT_EQ(1, onvisibilitycalls_); } -// Test that the oncancel event is dispatched upon clicking on the preview. +// Test that the oncancel event is dispatched upon clicking on the overlay. IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); - // Stash a reference to the preview, so we can refer to it after commit. - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + // Stash a reference to the overlay, so we can refer to it after commit. + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // The state of the searchbox before the commit. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_FALSE(verbatim_); EXPECT_EQ(0, oncancelcalls_); @@ -242,40 +242,40 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnCancelEvent) { // Before the commit, the active tab is the NTP (i.e., not Instant). content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_NE(preview_tab, active_tab); + EXPECT_NE(overlay, active_tab); EXPECT_EQ(1, active_tab->GetController().GetEntryCount()); EXPECT_EQ(std::string(chrome::kAboutBlankURL), omnibox()->model()->PermanentURL().spec()); - // Commit the search by clicking on the preview. + // Commit the search by clicking on the overlay. ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); // After the commit, Instant should not be showing. - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // The old overlay is deleted and a new one is created. - EXPECT_TRUE(instant()->GetPreviewContents()); - EXPECT_NE(instant()->GetPreviewContents(), preview_tab); + EXPECT_TRUE(instant()->GetOverlayContents()); + EXPECT_NE(instant()->GetOverlayContents(), overlay); - // Check that the current active tab is indeed what was once the preview. - EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); + // Check that the current active tab is indeed what was once the overlay. + EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); // We should have two navigation entries, one for the NTP, and one for the // Instant search that was committed. - EXPECT_EQ(2, preview_tab->GetController().GetEntryCount()); + EXPECT_EQ(2, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; - EXPECT_TRUE(GetStringFromJS(preview_tab, + EXPECT_TRUE(GetStringFromJS(overlay, "chrome.embeddedSearch.searchBox.value", &value)); EXPECT_EQ("", value); // However, the page should've correctly received the committed query. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_TRUE(verbatim_); EXPECT_EQ(1, oncancelcalls_); @@ -288,15 +288,15 @@ IN_PROC_BROWSER_TEST_F(InstantTest, OnResizeEvent) { FocusOmniboxAndWaitForInstantSupport(); - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); EXPECT_EQ(0, onresizecalls_); EXPECT_EQ(0, height_); // Type a query into the omnibox. This should cause an onresize() event, with // a valid (non-zero) height. - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); EXPECT_EQ(1, onresizecalls_); EXPECT_LT(0, height_); } @@ -310,7 +310,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNow) { EXPECT_TRUE(ExecuteScript("behavior = 'now'")); // Type a query, causing the hardcoded "query suggestion" to be returned. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); // Get what's showing in the omnibox, and what's highlighted. string16 text = omnibox()->GetText(); @@ -333,7 +333,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsCompletedNever) { EXPECT_TRUE(ExecuteScript("behavior = 'never'")); // Type a query, causing the hardcoded "query suggestion" to be returned. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); // Get what's showing in the omnibox, and what's highlighted. string16 text = omnibox()->GetText(); @@ -356,7 +356,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsValidObject) { EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'query completion' } ]")); // Type a query, causing "query completion" to be returned as the suggestion. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_EQ(ASCIIToUTF16("query completion"), omnibox()->GetText()); } @@ -369,7 +369,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsInvalidObject) { EXPECT_TRUE(ExecuteScript("suggestion = { value: 'query completion' }")); // Type a query, but expect no suggestion. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); } @@ -379,19 +379,19 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionIsEmpty) { FocusOmniboxAndWaitForInstantSupport(); EXPECT_TRUE(ExecuteScript("suggestion = {}")); - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); omnibox()->RevertAll(); EXPECT_TRUE(ExecuteScript("suggestion = []")); - SetOmniboxTextAndWaitForInstantToShow("query sugg"); + SetOmniboxTextAndWaitForOverlayToShow("query sugg"); EXPECT_EQ(ASCIIToUTF16("query sugg"), omnibox()->GetText()); omnibox()->RevertAll(); EXPECT_TRUE(ExecuteScript("suggestion = [{}]")); - SetOmniboxTextAndWaitForInstantToShow("query suggest"); + SetOmniboxTextAndWaitForOverlayToShow("query suggest"); EXPECT_EQ(ASCIIToUTF16("query suggest"), omnibox()->GetText()); } @@ -404,19 +404,19 @@ IN_PROC_BROWSER_TEST_F(InstantTest, RejectsURLs) { // typing them into the omnibox (without pressing Enter) and checking that // Instant doesn't try to process them. SetOmniboxText(content::kChromeUICrashURL); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); SetOmniboxText(content::kChromeUIHangURL); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); SetOmniboxText(content::kChromeUIKillURL); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); - // Make sure that the URLs were never sent to the preview page. - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); + // Make sure that the URLs were never sent to the overlay page. + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); EXPECT_EQ("", value_); } @@ -431,8 +431,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, IntranetPathLooksLikeSearch) { ui_test_utils::NavigateToURL(browser(), GURL("http://baby/beluga")); EXPECT_EQ(ASCIIToUTF16("baby/beluga"), omnibox()->GetText()); - EXPECT_TRUE(instant()->GetPreviewContents()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(instant()->GetOverlayContents()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); } @@ -449,41 +449,41 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { SetOmniboxText("http://monstrous/nightmare"); int min_onchangecalls = 2; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); EXPECT_EQ("", value_); EXPECT_LE(min_onchangecalls, onchangecalls_); min_onchangecalls = onchangecalls_; // Type a search. Instant should show. - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); ++min_onchangecalls; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); - EXPECT_TRUE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); + EXPECT_TRUE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); EXPECT_EQ("search", value_); EXPECT_LE(min_onchangecalls, onchangecalls_); min_onchangecalls = onchangecalls_; - // Type another URL. The preview should be hidden. + // Type another URL. The overlay should be hidden. SetOmniboxText("http://terrible/terror"); ++min_onchangecalls; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); EXPECT_EQ("", value_); EXPECT_LE(min_onchangecalls, onchangecalls_); min_onchangecalls = onchangecalls_; // Type the same search as before. - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); min_onchangecalls++; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); - EXPECT_TRUE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); + EXPECT_TRUE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); EXPECT_EQ("search", value_); EXPECT_LE(min_onchangecalls, onchangecalls_); @@ -493,8 +493,8 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TransitionsBetweenSearchAndURL) { omnibox()->RevertAll(); min_onchangecalls++; - EXPECT_TRUE(UpdateSearchState(instant()->GetPreviewContents())); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(UpdateSearchState(instant()->GetOverlayContents())); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); EXPECT_EQ("", value_); EXPECT_LE(min_onchangecalls, onchangecalls_); @@ -505,9 +505,9 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); - // Type a URL. The Instant preview shouldn't be showing. + // Type a URL. The Instant overlay shouldn't be showing. SetOmniboxText("http://deadly/nadder"); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // Unfocus and refocus the omnibox. @@ -515,24 +515,24 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsOne) { EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); FocusOmnibox(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // The omnibox text hasn't changed, so Instant still shouldn't be showing. EXPECT_EQ(ASCIIToUTF16("http://deadly/nadder"), omnibox()->GetText()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // Commit the URL. The omnibox should reflect the URL minus the scheme. browser()->window()->GetLocationBar()->AcceptInput(); content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_NE(preview_tab, active_tab); + EXPECT_NE(overlay, active_tab); EXPECT_EQ(ASCIIToUTF16("deadly/nadder"), omnibox()->GetText()); // Instant shouldn't have done anything. - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); } @@ -541,15 +541,15 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - // Type a query. This causes the preview to be shown. - SetOmniboxTextAndWaitForInstantToShow("query"); + // Type a query. This causes the overlay to be shown. + SetOmniboxTextAndWaitForOverlayToShow("query"); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); - // Type a URL. This causes the preview to be hidden. + // Type a URL. This causes the overlay to be hidden. SetOmniboxText("http://hideous/zippleback"); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // Pretend the omnibox got focus. It already had focus, so we are just trying @@ -561,16 +561,16 @@ IN_PROC_BROWSER_TEST_F(InstantTest, DoesNotCommitURLsTwo) { browser()->window()->GetLocationBar()->AcceptInput(); content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_NE(preview_tab, active_tab); + EXPECT_NE(overlay, active_tab); EXPECT_EQ(ASCIIToUTF16("hideous/zippleback"), omnibox()->GetText()); // As before, Instant shouldn't have done anything. - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); } -// Test that a non-Instant search provider shows no previews. +// Test that a non-Instant search provider shows no overlays. IN_PROC_BROWSER_TEST_F(InstantTest, NonInstantSearchProvider) { instant_url_ = test_server()->GetURL("files/empty.html"); ASSERT_NO_FATAL_FAILURE(SetupInstant()); @@ -594,41 +594,41 @@ IN_PROC_BROWSER_TEST_F(InstantTest, NoCrashOnBlockedJS) { FocusOmniboxAndWaitForInstantSupport(); } -// Test that the preview and active tab's visibility states are set correctly. +// Test that the overlay and active tab's visibility states are set correctly. IN_PROC_BROWSER_TEST_F(InstantTest, PageVisibility) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); + content::WebContents* overlay = instant()->GetOverlayContents(); - // Inititally, the active tab is showing; the preview is not. + // Inititally, the active tab is showing; the overlay is not. EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); - EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); + EXPECT_TRUE(CheckVisibilityIs(overlay, false)); // Type a query and wait for Instant to show. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); - EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); + EXPECT_TRUE(CheckVisibilityIs(overlay, true)); - // Deleting the omnibox text should hide the preview. + // Deleting the omnibox text should hide the overlay. SetOmniboxText(""); EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); - EXPECT_TRUE(CheckVisibilityIs(preview_tab, false)); + EXPECT_TRUE(CheckVisibilityIs(overlay, false)); - // Typing a query should show the preview again. - SetOmniboxTextAndWaitForInstantToShow("query"); + // Typing a query should show the overlay again. + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_TRUE(CheckVisibilityIs(active_tab, true)); - EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); + EXPECT_TRUE(CheckVisibilityIs(overlay, true)); - // Commit the preview. + // Commit the overlay. browser()->window()->GetLocationBar()->AcceptInput(); - EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); - EXPECT_TRUE(CheckVisibilityIs(preview_tab, true)); + EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); + EXPECT_TRUE(CheckVisibilityIs(overlay, true)); } -// Test that the task manager identifies Instant's preview tab correctly. +// Test that the task manager identifies Instant's overlay correctly. IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { // The browser starts with a new tab, so there's just one renderer initially. TaskManagerModel* task_manager = TaskManager::GetInstance()->model(); @@ -636,9 +636,9 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { TaskManagerBrowserTestUtil::WaitForWebResourceChange(1); string16 prefix = l10n_util::GetStringFUTF16( - IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX, string16()); + IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX, string16()); - // There should be no Instant preview yet. + // There should be no Instant overlay yet. for (int i = 0; i < task_manager->ResourceCount(); ++i) { string16 title = task_manager->GetResourceTitle(i); EXPECT_FALSE(StartsWith(title, prefix, true)) << title << " vs " << prefix; @@ -647,16 +647,16 @@ IN_PROC_BROWSER_TEST_F(InstantTest, TaskManagerPrefix) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmnibox(); - // Now there should be two renderers, the second being the Instant preview. + // Now there should be two renderers, the second being the Instant overlay. TaskManagerBrowserTestUtil::WaitForWebResourceChange(2); - int instant_previews = 0; + int instant_overlays = 0; for (int i = 0; i < task_manager->ResourceCount(); ++i) { string16 title = task_manager->GetResourceTitle(i); if (StartsWith(title, prefix, true)) - ++instant_previews; + ++instant_overlays; } - EXPECT_EQ(1, instant_previews); + EXPECT_EQ(1, instant_overlays); } void HistoryQueryDone(base::RunLoop* run_loop, @@ -696,7 +696,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { ui_test_utils::WaitForHistoryToLoad(history); // Perform a search. - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); // Commit the search. browser()->window()->GetLocationBar()->AcceptInput(); @@ -736,40 +736,40 @@ IN_PROC_BROWSER_TEST_F(InstantTest, History) { #else #define MAYBE_NewWindowDismissesInstant NewWindowDismissesInstant #endif -// Test that creating a new window hides any currently showing Instant preview. +// Test that creating a new window hides any currently showing Instant overlay. IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_NewWindowDismissesInstant) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); EXPECT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); Browser* previous_window = browser(); - EXPECT_TRUE(instant()->IsPreviewingSearchResults()); + EXPECT_TRUE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); InstantTestModelObserver observer(instant()->model(), chrome::search::Mode::MODE_DEFAULT); chrome::NewEmptyWindow(browser()->profile(), chrome::HOST_DESKTOP_TYPE_NATIVE); - observer.WaitUntilDesiredPreviewState(); + observer.WaitForDesiredOverlayState(); // Even though we just created a new Browser object (for the new window), the // browser() accessor should still give us the first window's Browser object. EXPECT_EQ(previous_window, browser()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); } // Test that the Instant overlay is recreated when all these conditions are met: // - The stale overlay timer has fired. -// - The preview is not showing. +// - The overlay is not showing. // - The omnibox doesn't have focus. IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - // The preview is refreshed only after all three conditions above are met. - SetOmniboxTextAndWaitForInstantToShow("query"); + // The overlay is refreshed only after all three conditions above are met. + SetOmniboxTextAndWaitForOverlayToShow("query"); instant()->overlay_->is_stale_ = true; instant()->ReloadOverlayIfStale(); EXPECT_TRUE(instant()->overlay_->supports_instant()); @@ -780,14 +780,14 @@ IN_PROC_BROWSER_TEST_F(InstantTest, InstantOverlayRefresh) { EXPECT_FALSE(instant()->overlay_->supports_instant()); // Try with a different ordering. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); instant()->overlay_->is_stale_ = true; instant()->ReloadOverlayIfStale(); EXPECT_TRUE(instant()->overlay_->supports_instant()); instant()->OmniboxFocusChanged(OMNIBOX_FOCUS_NONE, OMNIBOX_FOCUS_CHANGE_EXPLICIT, NULL); // TODO(sreeram): Currently, OmniboxLostFocus() calls HideOverlay(). When it - // stops hiding the preview eventually, uncomment these two lines: + // stops hiding the overlay eventually, uncomment these two lines: // EXPECT_TRUE(instant()->overlay_->supports_instant()); // instant()->HideOverlay(); EXPECT_FALSE(instant()->overlay_->supports_instant()); @@ -800,42 +800,42 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'INSTANT' } ]")); - SetOmniboxTextAndWaitForInstantToShow("in"); + SetOmniboxTextAndWaitForOverlayToShow("in"); EXPECT_EQ(ASCIIToUTF16("instant"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow("IN"); + SetOmniboxTextAndWaitForOverlayToShow("IN"); EXPECT_EQ(ASCIIToUTF16("INSTANT"), omnibox()->GetText()); // U+0130 == LATIN CAPITAL LETTER I WITH DOT ABOVE EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u0130NSTANT' } ]")); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow("i"); + SetOmniboxTextAndWaitForOverlayToShow("i"); EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow("I"); + SetOmniboxTextAndWaitForOverlayToShow("I"); EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"i\u0307")); + SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"i\u0307")); EXPECT_EQ(WideToUTF16(L"i\u0307nstant"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"I\u0307")); + SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"I\u0307")); EXPECT_EQ(WideToUTF16(L"I\u0307nstant"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u0130")); + SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u0130")); EXPECT_EQ(WideToUTF16(L"\u0130NSTANT"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow("in"); + SetOmniboxTextAndWaitForOverlayToShow("in"); EXPECT_EQ(ASCIIToUTF16("in"), omnibox()->GetText()); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow("IN"); + SetOmniboxTextAndWaitForOverlayToShow("IN"); EXPECT_EQ(ASCIIToUTF16("IN"), omnibox()->GetText()); // Check that a d with a dot above and below it is completed regardless of @@ -845,7 +845,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { EXPECT_TRUE(ExecuteScript("suggestion = [ { value: '\\u1e0d\\u0307oh' } ]")); omnibox()->RevertAll(); - SetOmniboxTextAndWaitForInstantToShow(WideToUTF8(L"\u1e0b\u0323")); + SetOmniboxTextAndWaitForOverlayToShow(WideToUTF8(L"\u1e0b\u0323")); EXPECT_EQ(WideToUTF16(L"\u1e0b\u0323oh"), omnibox()->GetText()); } @@ -855,7 +855,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreCaseInsensitive) { #else #define MAYBE_CommitInNewTab CommitInNewTab #endif -// Test that the preview can be committed onto a new tab. +// Test that the overlay can be committed onto a new tab. IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); @@ -871,21 +871,21 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { &active_tab_onvisibilitycalls)); EXPECT_EQ(0, active_tab_onvisibilitycalls); - SetOmniboxTextAndWaitForInstantToShow("search"); + SetOmniboxTextAndWaitForOverlayToShow("search"); - // Stash a reference to the preview, so we can refer to it after commit. - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + // Stash a reference to the overlay, so we can refer to it after commit. + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // The state of the searchbox before the commit. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_FALSE(verbatim_); EXPECT_EQ(0, onsubmitcalls_); EXPECT_EQ(1, onvisibilitycalls_); // The state of the active tab before the commit. - EXPECT_NE(preview_tab, active_tab); + EXPECT_NE(overlay, active_tab); EXPECT_EQ(2, active_tab->GetController().GetEntryCount()); EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); active_tab_onvisibilitycalls = -1; @@ -897,38 +897,38 @@ IN_PROC_BROWSER_TEST_F(InstantTest, MAYBE_CommitInNewTab) { omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); // After the commit, Instant should not be showing. - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // The old overlay is deleted and a new one is created. - EXPECT_TRUE(instant()->GetPreviewContents()); - EXPECT_NE(instant()->GetPreviewContents(), preview_tab); + EXPECT_TRUE(instant()->GetOverlayContents()); + EXPECT_NE(instant()->GetOverlayContents(), overlay); // Check that we have two tabs and that the new active tab is indeed what was - // once the preview. The preview tab should have just one navigation entry, - // for the Instant search that was committed. + // once the overlay. The overlay should have just one navigation entry, for + // the Instant search that was committed. EXPECT_EQ(2, browser()->tab_strip_model()->count()); - EXPECT_EQ(preview_tab, browser()->tab_strip_model()->GetActiveWebContents()); - EXPECT_EQ(1, preview_tab->GetController().GetEntryCount()); + EXPECT_EQ(overlay, browser()->tab_strip_model()->GetActiveWebContents()); + EXPECT_EQ(1, overlay->GetController().GetEntryCount()); // Check that the omnibox contains the Instant URL we loaded. EXPECT_EQ(instant_url_, omnibox()->model()->PermanentURL()); // Check that the searchbox API values have been reset. std::string value; - EXPECT_TRUE(GetStringFromJS(preview_tab, + EXPECT_TRUE(GetStringFromJS(overlay, "chrome.embeddedSearch.searchBox.value", &value)); EXPECT_EQ("", value); // However, the page should've correctly received the committed query. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); EXPECT_EQ("search", value_); EXPECT_TRUE(verbatim_); EXPECT_EQ(1, onsubmitcalls_); EXPECT_EQ(1, onvisibilitycalls_); // The ex-active tab should've gotten a visibility change marking it hidden. - EXPECT_NE(active_tab, preview_tab); + EXPECT_NE(active_tab, overlay); EXPECT_TRUE(GetIntFromJS(active_tab, "onvisibilitycalls", &active_tab_onvisibilitycalls)); EXPECT_EQ(1, active_tab_onvisibilitycalls); @@ -942,7 +942,7 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { EXPECT_TRUE(ExecuteScript("suggestion = [ { value: 'instant' } ];" "behavior = 'never';")); - SetOmniboxTextAndWaitForInstantToShow("in"); + SetOmniboxTextAndWaitForOverlayToShow("in"); EXPECT_EQ(ASCIIToUTF16("stant"), omnibox()->GetInstantSuggestion()); SetOmniboxText("ins"); @@ -955,20 +955,20 @@ IN_PROC_BROWSER_TEST_F(InstantTest, SuggestionsAreReusable) { EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); } -// Test that instant overlay is recreated if it gets destroyed. +// Test that the Instant overlay is recreated if it gets destroyed. IN_PROC_BROWSER_TEST_F(InstantTest, InstantRenderViewGone) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); // Type partial query, get suggestion to show. - SetOmniboxTextAndWaitForInstantToShow("q"); + SetOmniboxTextAndWaitForOverlayToShow("q"); EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); - // Kill the instant renderer and wait for instant support again. + // Kill the Instant renderer and wait for Instant support again. KillInstantRenderView(); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("qu"); + SetOmniboxTextAndWaitForOverlayToShow("qu"); EXPECT_EQ(ASCIIToUTF16("query suggestion"), omnibox()->GetText()); } @@ -986,13 +986,13 @@ IN_PROC_BROWSER_TEST_F(InstantTest, ProcessIsolation) { // Now there should be a registered Instant render process. EXPECT_LT(0, instant_service->GetInstantProcessCount()); - // And the Instant preview should live inside it. - content::WebContents* preview = instant()->GetPreviewContents(); + // And the Instant overlay should live inside it. + content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(instant_service->IsInstantProcess( - preview->GetRenderProcessHost()->GetID())); + overlay->GetRenderProcessHost()->GetID())); // Search and commit the search by pressing Alt-Enter. - SetOmniboxTextAndWaitForInstantToShow("tractor"); + SetOmniboxTextAndWaitForOverlayToShow("tractor"); omnibox()->model()->AcceptInput(NEW_FOREGROUND_TAB, false); // The committed search results page should also live inside the diff --git a/chrome/browser/instant/instant_controller.cc b/chrome/browser/instant/instant_controller.cc index 434c622..3cd80f7 100644 --- a/chrome/browser/instant/instant_controller.cc +++ b/chrome/browser/instant/instant_controller.cc @@ -156,7 +156,7 @@ bool IsViewInContents(gfx::NativeView view, content::WebContents* contents) { return false; } -bool IsFullHeight(const InstantModel& model) { +bool IsFullHeight(const InstantOverlayModel& model) { return model.height() == 100 && model.height_units() == INSTANT_SIZE_PERCENT; } @@ -196,14 +196,14 @@ InstantController::InstantController(chrome::BrowserInstantController* browser, : browser_(browser), extended_enabled_(extended_enabled), instant_enabled_(false), - use_local_preview_only_(true), + use_local_overlay_only_(true), model_(ALLOW_THIS_IN_INITIALIZER_LIST(this)), last_omnibox_text_has_inline_autocompletion_(false), last_verbatim_(false), last_transition_type_(content::PAGE_TRANSITION_LINK), last_match_was_search_(false), omnibox_focus_state_(OMNIBOX_FOCUS_NONE), - allow_preview_to_show_search_suggestions_(false), + allow_overlay_to_show_search_suggestions_(false), ALLOW_THIS_IN_INITIALIZER_LIST(weak_ptr_factory_(this)) { } @@ -261,7 +261,7 @@ bool InstantController::Update(const AutocompleteMatch& match, DCHECK(user_input_in_progress || omnibox_popup_is_open || user_text.empty()) << user_text; - // The preview is being clicked and will commit soon. Don't change anything. + // The overlay is being clicked and will commit soon. Don't change anything. // TODO(sreeram): Add a browser test for this. if (overlay_ && overlay_->is_pointer_down_from_activate()) return false; @@ -284,9 +284,9 @@ bool InstantController::Update(const AutocompleteMatch& match, return false; } - // If we have an |instant_tab_| use it, else ensure we have a overlay that is - // current or is using local preview. - if (!instant_tab_ && !(overlay_ && overlay_->IsUsingLocalPreview()) && + // If we have an |instant_tab_| use it, else ensure we have an overlay that is + // current or is using the local overlay. + if (!instant_tab_ && !(overlay_ && overlay_->IsUsingLocalOverlay()) && !EnsureOverlayIsCurrent(false)) { HideOverlay(); return false; @@ -311,7 +311,7 @@ bool InstantController::Update(const AutocompleteMatch& match, instant_tab_->Submit(full_text); } } else if (!full_text.empty()) { - // If |full_text| is empty, the user is on the NTP. The preview may + // If |full_text| is empty, the user is on the NTP. The overlay may // be showing custom NTP content; hide only if that's not the case. HideOverlay(); } @@ -324,8 +324,8 @@ bool InstantController::Update(const AutocompleteMatch& match, // On a search results page, tell it to clear old results. instant_tab_->Update(string16(), 0, 0, true); } else if (search_mode_.is_origin_ntp()) { - // On the NTP, tell the preview to clear old results. Don't hide the - // preview so it can show a blank page or logo if it wants. + // On the NTP, tell the overlay to clear old results. Don't hide the + // overlay so it can show a blank page or logo if it wants. overlay_->Update(string16(), 0, 0, true); } else { HideOverlay(); @@ -357,7 +357,7 @@ bool InstantController::Update(const AutocompleteMatch& match, return false; } } else if (!omnibox_popup_is_open || full_text.empty()) { - // In the non-extended case, hide the preview as long as the user isn't + // In the non-extended case, hide the overlay as long as the user isn't // actively typing a non-empty query. HideOverlay(); return false; @@ -407,12 +407,12 @@ bool InstantController::Update(const AutocompleteMatch& match, } else { if (first_interaction_time_.is_null()) first_interaction_time_ = base::Time::Now(); - allow_preview_to_show_search_suggestions_ = true; + allow_overlay_to_show_search_suggestions_ = true; // For extended mode, if the loader is not ready at this point, switch over // to a backup loader. if (extended_enabled_ && !overlay_->supports_instant() && - !overlay_->IsUsingLocalPreview() && browser_->GetActiveWebContents()) { + !overlay_->IsUsingLocalOverlay() && browser_->GetActiveWebContents()) { CreateOverlay(chrome::search::kLocalOmniboxPopupURL, browser_->GetActiveWebContents()); } @@ -446,7 +446,7 @@ scoped_ptr InstantController::ReleaseNTPContents() { } // TODO(tonyg): This method only fires when the omnibox bounds change. It also -// needs to fire when the preview bounds change (e.g.: open/close info bar). +// needs to fire when the overlay bounds change (e.g.: open/close info bar). void InstantController::SetPopupBounds(const gfx::Rect& bounds) { if (!extended_enabled_ && !instant_enabled_) return; @@ -551,11 +551,11 @@ void InstantController::OnCancel(const AutocompleteMatch& match, overlay_->CancelSelection(full_text); } -content::WebContents* InstantController::GetPreviewContents() const { +content::WebContents* InstantController::GetOverlayContents() const { return overlay_ ? overlay_->contents() : NULL; } -bool InstantController::IsPreviewingSearchResults() const { +bool InstantController::IsOverlayingSearchResults() const { return model_.mode().is_search_suggestions() && IsFullHeight(model_) && (last_match_was_search_ || last_suggestion_.behavior == INSTANT_COMPLETE_NEVER); @@ -585,17 +585,17 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { return false; } - if (!IsPreviewingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) + if (!IsOverlayingSearchResults() && type != INSTANT_COMMIT_NAVIGATED) return false; // There may re-entrance here, from the call to browser_->CommitInstant below, // which can cause a TabDeactivated notification which gets back here. // In this case, overlay_->ReleaseContents() was called already. - if (!GetPreviewContents()) + if (!GetOverlayContents()) return false; - // Never commit the local omnibox. - if (overlay_->IsUsingLocalPreview()) + // Never commit the local overlay. + if (overlay_->IsUsingLocalOverlay()) return false; if (type == INSTANT_COMMIT_FOCUS_LOST) @@ -603,15 +603,15 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { else if (type != INSTANT_COMMIT_NAVIGATED) overlay_->Submit(last_omnibox_text_); - scoped_ptr preview = overlay_->ReleaseContents(); + scoped_ptr overlay = overlay_->ReleaseContents(); - // If the preview page has navigated since the last Update(), we need to add + // If the overlay page has navigated since the last Update(), we need to add // the navigation to history ourselves. Else, the page will navigate after // commit, and it will be added to history in the usual manner. const history::HistoryAddPageArgs& last_navigation = overlay_->last_navigation(); if (!last_navigation.url.is_empty()) { - content::NavigationEntry* entry = preview->GetController().GetActiveEntry(); + content::NavigationEntry* entry = overlay->GetController().GetActiveEntry(); // The last navigation should be the same as the active entry if the overlay // is in search mode. During navigation, the active entry could have @@ -624,7 +624,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { // Add the page to history. HistoryTabHelper* history_tab_helper = - HistoryTabHelper::FromWebContents(preview.get()); + HistoryTabHelper::FromWebContents(overlay.get()); history_tab_helper->UpdateHistoryForNavigation(last_navigation); // Update the page title. @@ -634,7 +634,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { // Add a fake history entry with a non-Instant search URL, so that search // terms extraction (for autocomplete history matches) works. HistoryService* history = HistoryServiceFactory::GetForProfile( - Profile::FromBrowserContext(preview->GetBrowserContext()), + Profile::FromBrowserContext(overlay->GetBrowserContext()), Profile::EXPLICIT_ACCESS); if (history) { history->AddPage(url_for_history_, base::Time::Now(), NULL, 0, GURL(), @@ -643,11 +643,11 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { } if (type == INSTANT_COMMIT_PRESSED_ALT_ENTER) { - preview->GetController().PruneAllButActive(); + overlay->GetController().PruneAllButActive(); } else { content::WebContents* active_tab = browser_->GetActiveWebContents(); - AddSessionStorageHistogram(extended_enabled_, active_tab, preview.get()); - preview->GetController().CopyStateFromAndPrune( + AddSessionStorageHistogram(extended_enabled_, active_tab, overlay.get()); + overlay->GetController().CopyStateFromAndPrune( &active_tab->GetController()); } @@ -663,13 +663,13 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { last_omnibox_text_ += last_suggestion_.text; } - EnsureSearchTermsAreSet(preview.get(), last_omnibox_text_); + EnsureSearchTermsAreSet(overlay.get(), last_omnibox_text_); } - // Save notification source before we release the preview. - content::Source notification_source(preview.get()); + // Save notification source before we release the overlay. + content::Source notification_source(overlay.get()); - browser_->CommitInstant(preview.Pass(), + browser_->CommitInstant(overlay.Pass(), type == INSTANT_COMMIT_PRESSED_ALT_ENTER); content::NotificationService::current()->Notify( @@ -678,7 +678,7 @@ bool InstantController::CommitIfPossible(InstantCommitType type) { content::NotificationService::NoDetails()); // Hide explicitly. See comments in HideOverlay() for why. - model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); + model_.SetOverlayState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); // Delay deletion as we could've gotten here from an InstantOverlay method. MessageLoop::current()->DeleteSoon(FROM_HERE, overlay_.release()); @@ -712,7 +712,7 @@ void InstantController::OmniboxFocusChanged( // onkeycapturechange before the corresponding onchange, and the page would // have no way of telling whether the keycapturechange happened because of // some actual user action or just because they started typing.) - if (extended_enabled_ && GetPreviewContents() && + if (extended_enabled_ && GetOverlayContents() && reason != OMNIBOX_FOCUS_CHANGE_TYPING) { const bool is_key_capture_enabled = omnibox_focus_state_ == OMNIBOX_FOCUS_INVISIBLE; @@ -724,7 +724,7 @@ void InstantController::OmniboxFocusChanged( // If focus went from outside the omnibox to the omnibox, preload the default // search engine, in anticipation of the user typing a query. If the reverse - // happened, commit or discard the preview. + // happened, commit or discard the overlay. if (state != OMNIBOX_FOCUS_NONE && old_focus_state == OMNIBOX_FOCUS_NONE) { // On explicit user actions, ignore the Instant blacklist. EnsureOverlayIsCurrent(reason == OMNIBOX_FOCUS_CHANGE_EXPLICIT); @@ -757,7 +757,7 @@ void InstantController::ActiveTabChanged() { LOG_INSTANT_DEBUG_EVENT(this, "ActiveTabChanged"); - // When switching tabs, always hide the preview. + // When switching tabs, always hide the overlay. HideOverlay(); if (extended_enabled_) @@ -771,20 +771,20 @@ void InstantController::TabDeactivated(content::WebContents* contents) { } void InstantController::SetInstantEnabled(bool instant_enabled, - bool use_local_preview_only) { + bool use_local_overlay_only) { LOG_INSTANT_DEBUG_EVENT(this, base::StringPrintf( - "SetInstantEnabled: instant_enabled=%d, use_local_preview_only=%d", - instant_enabled, use_local_preview_only)); + "SetInstantEnabled: instant_enabled=%d, use_local_overlay_only=%d", + instant_enabled, use_local_overlay_only)); - // Non extended mode does not care about |use_local_preview_only|. + // Non extended mode does not care about |use_local_overlay_only|. if (instant_enabled == instant_enabled_ && (!extended_enabled_ || - use_local_preview_only == use_local_preview_only_)) { + use_local_overlay_only == use_local_overlay_only_)) { return; } instant_enabled_ = instant_enabled; - use_local_preview_only_ = use_local_preview_only; + use_local_overlay_only_ = use_local_overlay_only; HideInternal(); overlay_.reset(); if (extended_enabled_ || instant_enabled_) @@ -808,7 +808,7 @@ void InstantController::ThemeChanged(const ThemeBackgroundInfo& theme_info) { } void InstantController::SwappedOverlayContents() { - model_.SetPreviewContents(GetPreviewContents()); + model_.SetOverlayContents(GetOverlayContents()); } void InstantController::FocusedOverlayContents() { @@ -816,17 +816,17 @@ void InstantController::FocusedOverlayContents() { // On aura the omnibox only receives a focus lost if we initiate the focus // change. This does that. if (!model_.mode().is_default()) - browser_->InstantPreviewFocused(); + browser_->InstantOverlayFocused(); #endif } void InstantController::ReloadOverlayIfStale() { - // The local popup is never stale. - if (overlay_ && overlay_->IsUsingLocalPreview()) + // The local overlay is never stale. + if (overlay_ && overlay_->IsUsingLocalOverlay()) return; - // If the preview is showing or the omnibox has focus, don't delete the - // overlay. It will get refreshed the next time the preview is hidden or the + // If the overlay is showing or the omnibox has focus, don't delete the + // overlay. It will get refreshed the next time the overlay is hidden or the // omnibox loses focus. if ((!overlay_ || overlay_->is_stale()) && omnibox_focus_state_ == OMNIBOX_FOCUS_NONE && @@ -949,22 +949,22 @@ void InstantController::InstantPageAboutToNavigateMainFrame( const GURL& url) { DCHECK(IsContentsFrom(overlay(), contents)); - // If the page does not yet support instant, we allow redirects and other - // navigations to go through since the instant URL can redirect - e.g. to + // If the page does not yet support Instant, we allow redirects and other + // navigations to go through since the Instant URL can redirect - e.g. to // country specific pages. if (!overlay_->supports_instant()) return; GURL instant_url(overlay_->instant_url()); - // If we are navigating to the instant URL, do nothing. + // If we are navigating to the Instant URL, do nothing. if (url == instant_url) return; // Commit the navigation if either: // - The page is in NTP mode (so it could only navigate on a user click) or // - The page is not in NTP mode and we are navigating to a URL with a - // different host or path than the instant URL. This enables the instant + // different host or path than the Instant URL. This enables the instant // page when it is showing search results to change the query parameters // and fragments of the URL without it navigating. if (model_.mode().is_ntp() || @@ -984,7 +984,7 @@ void InstantController::SetSuggestions( if (instant_tab_ && !IsContentsFrom(instant_tab(), contents)) return; if (IsContentsFrom(overlay(), contents) && - !allow_preview_to_show_search_suggestions_) + !allow_overlay_to_show_search_suggestions_) return; InstantSuggestion suggestion; @@ -1010,7 +1010,7 @@ void InstantController::SetSuggestions( if (suggestion.behavior == INSTANT_COMPLETE_REPLACE) { // We don't get an Update() when changing the omnibox due to a REPLACE - // suggestion (so that we don't inadvertently cause the preview to change + // suggestion (so that we don't inadvertently cause the overlay to change // what it's showing, as the user arrows up/down through the page-provided // suggestions). So, update these state variables here. last_omnibox_text_ = suggestion.text; @@ -1118,7 +1118,7 @@ void InstantController::NavigateToURL(const content::WebContents* contents, } void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { - // If the preview is showing custom NTP content, don't hide it, commit it + // If the overlay is showing custom NTP content, don't hide it, commit it // (no matter where the user clicked) or try to recreate it. if (model_.mode().is_ntp()) return; @@ -1138,15 +1138,15 @@ void InstantController::OmniboxLostFocus(gfx::NativeView view_gaining_focus) { last_omnibox_text_ += last_suggestion_.text; last_suggestion_ = InstantSuggestion(); } - // If the preview is not showing at all, recreate it if it's stale. + // If the overlay is not showing at all, recreate it if it's stale. ReloadOverlayIfStale(); MaybeSwitchToRemoteOverlay(); return; } - // The preview is showing search suggestions. If GetPreviewContents() is NULL, + // The overlay is showing search suggestions. If GetOverlayContents() is NULL, // we are in the commit path. Don't do anything. - if (!GetPreviewContents()) + if (!GetOverlayContents()) return; #if defined(OS_MACOSX) @@ -1184,7 +1184,7 @@ bool InstantController::EnsureOverlayIsCurrent(bool ignore_blacklist) { active_tab->GetBrowserContext()); std::string instant_url; if (!GetInstantURL(profile, ignore_blacklist, &instant_url)) { - // If we are in extended mode, fallback to the local popup. + // If we are in extended mode, fallback to the local overlay. if (extended_enabled_) instant_url = chrome::search::kLocalOmniboxPopupURL; else @@ -1216,9 +1216,9 @@ void InstantController::MaybeSwitchToRemoteOverlay() { } void InstantController::ResetInstantTab() { - // Do not wire up the InstantTab if instant should only use local previews, to + // Do not wire up the InstantTab if Instant should only use local overlays, to // prevent it from sending data to the page. - if (!search_mode_.is_origin_default() && !use_local_preview_only_) { + if (!search_mode_.is_origin_default() && !use_local_overlay_only_) { content::WebContents* active_tab = browser_->GetActiveWebContents(); if (!instant_tab_ || active_tab != instant_tab_->contents()) { instant_tab_.reset(new InstantTab(this)); @@ -1249,15 +1249,15 @@ void InstantController::HideOverlay() { void InstantController::HideInternal() { LOG_INSTANT_DEBUG_EVENT(this, "Hide"); - // If GetPreviewContents() returns NULL, either we're already in the desired + // If GetOverlayContents() returns NULL, either we're already in the desired // MODE_DEFAULT state, or we're in the commit path. For the latter, don't - // change the state just yet; else we may hide the preview unnecessarily. + // change the state just yet; else we may hide the overlay unnecessarily. // Instead, the state will be set correctly after the commit is done. - if (GetPreviewContents()) { - model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); - allow_preview_to_show_search_suggestions_ = false; + if (GetOverlayContents()) { + model_.SetOverlayState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); + allow_overlay_to_show_search_suggestions_ = false; - // Send a message asking the preview to clear out old results. + // Send a message asking the overlay to clear out old results. overlay_->Update(string16(), 0, 0, true); } @@ -1282,17 +1282,17 @@ void InstantController::ShowOverlay(InstantShownReason reason, // Must have updated omnibox after the last HideOverlay() to show suggestions. if (reason == INSTANT_SHOWN_QUERY_SUGGESTIONS && - !allow_preview_to_show_search_suggestions_) + !allow_overlay_to_show_search_suggestions_) return; // The page is trying to hide itself. Hide explicitly (i.e., don't use // HideOverlay()) so that it can change its mind. if (height == 0) { - model_.SetPreviewState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); + model_.SetOverlayState(chrome::search::Mode(), 0, INSTANT_SIZE_PERCENT); return; } - // If the preview is being shown for the first time since the user started + // If the overlay is being shown for the first time since the user started // typing, record a histogram value. if (!first_interaction_time_.is_null() && model_.mode().is_default()) { base::TimeDelta delta = base::Time::Now() - first_interaction_time_; @@ -1300,17 +1300,17 @@ void InstantController::ShowOverlay(InstantShownReason reason, } // Show at 100% height except in the following cases: - // - The local omnibox popup is being loaded. + // - The local overlay (omnibox popup) is being loaded. // - Instant is disabled. The page needs to be able to show only a dropdown. // - The page wants to show custom NTP content. // - The page is over a website other than search or an NTP, and is not // already showing at 100% height. - if (overlay_->IsUsingLocalPreview() || !instant_enabled_ || + if (overlay_->IsUsingLocalOverlay() || !instant_enabled_ || reason == INSTANT_SHOWN_CUSTOM_NTP_CONTENT || (search_mode_.is_origin_default() && !IsFullHeight(model_))) - model_.SetPreviewState(search_mode_, height, units); + model_.SetOverlayState(search_mode_, height, units); else - model_.SetPreviewState(search_mode_, 100, INSTANT_SIZE_PERCENT); + model_.SetOverlayState(search_mode_, 100, INSTANT_SIZE_PERCENT); // If the overlay is being shown at full height and the omnibox is not // focused, commit right away. @@ -1324,20 +1324,20 @@ void InstantController::SendPopupBoundsToPage() { return; last_popup_bounds_ = popup_bounds_; - gfx::Rect preview_bounds = browser_->GetInstantBounds(); - gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, preview_bounds); + gfx::Rect overlay_bounds = browser_->GetInstantBounds(); + gfx::Rect intersection = gfx::IntersectRects(popup_bounds_, overlay_bounds); // Translate into window coordinates. if (!intersection.IsEmpty()) { - intersection.Offset(-preview_bounds.origin().x(), - -preview_bounds.origin().y()); + intersection.Offset(-overlay_bounds.origin().x(), + -overlay_bounds.origin().y()); } // In the current Chrome UI, these must always be true so they sanity check // the above operations. In a future UI, these may be removed or adjusted. // There is no point in sanity-checking |intersection.y()| because the omnibox - // can be placed anywhere vertically relative to the preview (for example, in - // Mac fullscreen mode, the omnibox is fully enclosed by the preview bounds). + // can be placed anywhere vertically relative to the overlay (for example, in + // Mac fullscreen mode, the omnibox is fully enclosed by the overlay bounds). DCHECK_LE(0, intersection.x()); DCHECK_LE(0, intersection.width()); DCHECK_LE(0, intersection.height()); @@ -1351,7 +1351,7 @@ bool InstantController::GetInstantURL(Profile* profile, DCHECK(profile); instant_url->clear(); - if (extended_enabled_ && use_local_preview_only_) { + if (extended_enabled_ && use_local_overlay_only_) { *instant_url = chrome::search::kLocalOmniboxPopupURL; return true; } diff --git a/chrome/browser/instant/instant_controller.h b/chrome/browser/instant/instant_controller.h index 562089f..8cdd55d 100644 --- a/chrome/browser/instant/instant_controller.h +++ b/chrome/browser/instant/instant_controller.h @@ -19,7 +19,7 @@ #include "base/timer.h" #include "chrome/browser/history/history_types.h" #include "chrome/browser/instant/instant_commit_type.h" -#include "chrome/browser/instant/instant_model.h" +#include "chrome/browser/instant/instant_overlay_model.h" #include "chrome/browser/instant/instant_page.h" #include "chrome/browser/ui/omnibox/omnibox_edit_model.h" #include "chrome/common/instant_types.h" @@ -104,7 +104,7 @@ class InstantController : public InstantPage::Delegate, // Sets the stored start-edge margin and width of the omnibox. void SetOmniboxBounds(const gfx::Rect& bounds); - // Send autocomplete results from |providers| to the preview page. + // Send autocomplete results from |providers| to the overlay page. void HandleAutocompleteResults( const std::vector& providers); @@ -120,13 +120,14 @@ class InstantController : public InstantPage::Delegate, void OnCancel(const AutocompleteMatch& match, const string16& full_text); - // The preview WebContents. May be NULL. InstantController retains ownership. - content::WebContents* GetPreviewContents() const; + // The overlay WebContents. May be NULL. InstantController retains ownership. + content::WebContents* GetOverlayContents() const; - // Returns true if the Instant overlay is showing a search results preview. - bool IsPreviewingSearchResults() const; + // Returns true if Instant is showing a search results overlay. Returns false + // if the overlay is not showing, or if it's showing only suggestions. + bool IsOverlayingSearchResults() const; - // If the preview is showing search results, commits the preview, calling + // If the overlay is showing search results, commits the overlay, calling // CommitInstant() on the browser, and returns true. Else, returns false. bool CommitIfPossible(InstantCommitType type); @@ -143,19 +144,19 @@ class InstantController : public InstantPage::Delegate, void SearchModeChanged(const chrome::search::Mode& old_mode, const chrome::search::Mode& new_mode); - // The user switched tabs. Hide the preview. Create |instant_tab_| if the + // The user switched tabs. Hide the overlay. Create |instant_tab_| if the // newly active tab is an Instant search results page. void ActiveTabChanged(); - // The user is about to switch tabs. Commit the preview if needed. + // The user is about to switch tabs. Commit the overlay if needed. void TabDeactivated(content::WebContents* contents); - // Sets whether Instant should show result previews. |use_local_preview_only| + // Sets whether Instant should show result overlays. |use_local_overlay_only| // will force the use of kLocalOmniboxPopupURL as the Instant URL and is only // applicable if |extended_enabled_| is true. - void SetInstantEnabled(bool instant_enabled, bool use_local_preview_only); + void SetInstantEnabled(bool instant_enabled, bool use_local_overlay_only); - // The theme has changed. Pass the message to the preview page. + // The theme has changed. Pass the message to the overlay page. void ThemeChanged(const ThemeBackgroundInfo& theme_info); // Called when someone else swapped in a different contents in the |overlay_|. @@ -165,7 +166,7 @@ class InstantController : public InstantPage::Delegate, void FocusedOverlayContents(); // Called when the |overlay_| might be stale. If it's actually stale, and the - // omnibox doesn't have focus, and the preview isn't showing, the |overlay_| + // omnibox doesn't have focus, and the overlay isn't showing, the |overlay_| // is deleted and recreated. Else the refresh is skipped. void ReloadOverlayIfStale(); @@ -185,7 +186,7 @@ class InstantController : public InstantPage::Delegate, // Non-const for Add/RemoveObserver only. Other model changes should only // happen through the InstantController interface. - InstantModel* model() { return &model_; } + InstantOverlayModel* model() { return &model_; } private: FRIEND_TEST_ALL_PREFIXES(InstantTest, OmniboxFocusLoadsInstant); @@ -242,19 +243,19 @@ class InstantController : public InstantPage::Delegate, content::PageTransition transition, WindowOpenDisposition disposition) OVERRIDE; - // Invoked by the InstantLoader when the instant page wants to delete a + // Invoked by the InstantLoader when the Instant page wants to delete a // Most Visited item. virtual void DeleteMostVisitedItem(const GURL& url) OVERRIDE; - // Invoked by the InstantLoader when the instant page wants to undo a + // Invoked by the InstantLoader when the Instant page wants to undo a // Most Visited deletion. virtual void UndoMostVisitedDeletion(const GURL& url) OVERRIDE; - // Invoked by the InstantLoader when the instant page wants to undo all + // Invoked by the InstantLoader when the Instant page wants to undo all // Most Visited deletions. virtual void UndoAllMostVisitedDeletions() OVERRIDE; - // Helper for OmniboxFocusChanged. Commit or discard the preview. + // Helper for OmniboxFocusChanged. Commit or discard the overlay. void OmniboxLostFocus(gfx::NativeView view_gaining_focus); // Creates a new NTP, using the instant_url property of the default @@ -282,15 +283,15 @@ class InstantController : public InstantPage::Delegate, // point to it. Else, deletes any existing |instant_tab_|. void ResetInstantTab(); - // Hide the preview. Also sends an onchange event (with blank query) to the - // preview, telling it to clear out results for any old queries. + // Hide the overlay. Also sends an onchange event (with blank query) to the + // overlay, telling it to clear out results for any old queries. void HideOverlay(); // Like HideOverlay(), but doesn't call OnStaleOverlay(). Use HideOverlay() // unless you are going to call overlay_.reset() yourself subsequently. void HideInternal(); - // Counterpart to HideOverlay(). Asks the |browser_| to display the preview + // Counterpart to HideOverlay(). Asks the |browser_| to display the overlay // with the given |height| in |units|. void ShowOverlay(InstantShownReason reason, int height, @@ -301,7 +302,7 @@ class InstantController : public InstantPage::Delegate, // Determines the Instant URL based on a number of factors: // If |extended_enabled_|: - // - If |use_local_preview_only_| is true return kLocalOmniboxPopupURL, else + // - If |use_local_overlay_only_| is true return kLocalOmniboxPopupURL, else // - If the Instant URL is specified by command line, returns it, else // - If the default Instant URL is present returns it. // If !|extended_enabled_|: @@ -351,12 +352,12 @@ class InstantController : public InstantPage::Delegate, const bool extended_enabled_; bool instant_enabled_; - // If true, the instant URL is set to kLocalOmniboxPopupURL. - bool use_local_preview_only_; + // If true, the Instant URL is set to kLocalOmniboxPopupURL. + bool use_local_overlay_only_; - // The state of the preview page, i.e., the page owned by |overlay_|. Ignored + // The state of the overlay page, i.e., the page owned by |overlay_|. Ignored // if |instant_tab_| is in use. - InstantModel model_; + InstantOverlayModel model_; // The three instances of InstantPage maintained by InstantController as // described above. All three may be non-NULL in extended mode. If @@ -388,7 +389,7 @@ class InstantController : public InstantPage::Delegate, content::PageTransition last_transition_type_; // True if the last match passed to Update() was a search (versus a URL). - // Used to ensure that the preview page is committable. + // Used to ensure that the overlay page is committable. bool last_match_was_search_; // Omnibox focus state. @@ -426,13 +427,13 @@ class InstantController : public InstantPage::Delegate, GURL url_for_history_; // The timestamp at which query editing began. This value is used when the - // preview is showed and cleared when the preview is hidden. + // overlay is showed and cleared when the overlay is hidden. base::Time first_interaction_time_; - // Whether to allow the preview to show search suggestions. In general, the - // preview is allowed to show search suggestions whenever |search_mode_| is + // Whether to allow the overlay to show search suggestions. In general, the + // overlay is allowed to show search suggestions whenever |search_mode_| is // MODE_SEARCH_SUGGESTIONS, except in those cases where this is false. - bool allow_preview_to_show_search_suggestions_; + bool allow_overlay_to_show_search_suggestions_; // List of events and their timestamps, useful in debugging Instant behaviour. mutable std::list > debug_events_; diff --git a/chrome/browser/instant/instant_extended_browsertest.cc b/chrome/browser/instant/instant_extended_browsertest.cc index 2e589c9..f7dc747 100644 --- a/chrome/browser/instant/instant_extended_browsertest.cc +++ b/chrome/browser/instant/instant_extended_browsertest.cc @@ -107,9 +107,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_FALSE(omnibox()->model()->has_focus()); - // Delete any existing preview. + // Delete any existing overlay. instant()->overlay_.reset(); - EXPECT_FALSE(instant()->GetPreviewContents()); + EXPECT_FALSE(instant()->GetOverlayContents()); // Refocus the omnibox. The InstantController should've preloaded Instant. FocusOmniboxAndWaitForInstantSupport(); @@ -117,26 +117,26 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, OmniboxFocusLoadsInstant) { EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); EXPECT_TRUE(omnibox()->model()->has_focus()); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); // Check that the page supports Instant, but it isn't showing. EXPECT_TRUE(instant()->overlay_->supports_instant()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); - // Adding a new tab shouldn't delete or recreate the preview; otherwise, + // Adding a new tab shouldn't delete or recreate the overlay; otherwise, // what's the point of preloading? AddBlankTabAndShow(browser()); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); - // Unfocusing and refocusing the omnibox should also preserve the preview. + // Unfocusing and refocusing the omnibox should also preserve the overlay. ui_test_utils::ClickOnView(browser(), VIEW_ID_TAB_CONTAINER); EXPECT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); FocusOmnibox(); EXPECT_FALSE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_TAB_CONTAINER)); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); } IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { @@ -144,15 +144,15 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputShowsOverlay) { // Focus omnibox and confirm overlay isn't shown. FocusOmniboxAndWaitForInstantSupport(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // Typing in the omnibox should show the overlay. - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_TRUE(instant()->model()->mode().is_search_suggestions()); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); } // Test that middle clicking on a suggestion opens the result in a new tab. @@ -165,8 +165,8 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EXPECT_EQ(1, browser()->tab_strip_model()->count()); // Typing in the omnibox should show the overlay. - SetOmniboxTextAndWaitForInstantToShow("santa"); - EXPECT_TRUE(instant()->IsPreviewingSearchResults()); + SetOmniboxTextAndWaitForOverlayToShow("santa"); + EXPECT_TRUE(instant()->IsOverlayingSearchResults()); // Create an event listener that opens the top suggestion in a new tab. EXPECT_TRUE(ExecuteScript( @@ -205,7 +205,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EXPECT_TRUE(ExecuteScript("suggestion = 'santa claus';")); // Set the text, and wait for suggestions to show up. - SetOmniboxTextAndWaitForInstantToShow("santa"); + SetOmniboxTextAndWaitForOverlayToShow("santa"); EXPECT_EQ(ASCIIToUTF16("santa"), omnibox()->GetText()); // Test that the current suggestion is correctly set. @@ -231,7 +231,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, EXPECT_TRUE(ExecuteScript("suggestion = 'johnny depp';")); // Set the text, and wait for suggestions to show up. - SetOmniboxTextAndWaitForInstantToShow("johnny"); + SetOmniboxTextAndWaitForOverlayToShow("johnny"); EXPECT_EQ(ASCIIToUTF16("johnny"), omnibox()->GetText()); // Test that the current suggestion is correctly set. @@ -255,7 +255,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, FocusOmniboxAndWaitForInstantSupport(); // Do a search and commit it. - SetOmniboxTextAndWaitForInstantToShow("hello k"); + SetOmniboxTextAndWaitForOverlayToShow("hello k"); EXPECT_EQ(ASCIIToUTF16("hello k"), omnibox()->GetText()); browser()->window()->GetLocationBar()->AcceptInput(); @@ -282,7 +282,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("hello"); + SetOmniboxTextAndWaitForOverlayToShow("hello"); EXPECT_EQ("hello", GetOmniboxText()); SendDownArrow(); @@ -296,7 +296,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsWithArrowKeys) { // Ensure that the API's value is set correctly. std::string result; - EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), + EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), "window.chrome.searchBox.value", &result)); EXPECT_EQ("hello", result); @@ -320,7 +320,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - SetOmniboxTextAndWaitForInstantToShow("hello"); + SetOmniboxTextAndWaitForOverlayToShow("hello"); EXPECT_EQ("hello", GetOmniboxText()); SendDownArrow(); @@ -332,7 +332,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, NavigateSuggestionsAndHitEscape) { // Ensure that the API's value is set correctly. std::string result; - EXPECT_TRUE(GetStringFromJS(instant()->GetPreviewContents(), + EXPECT_TRUE(GetStringFromJS(instant()->GetOverlayContents(), "window.chrome.searchBox.value", &result)); EXPECT_EQ("hello", result); @@ -468,9 +468,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) { // Focus omnibox and confirm overlay isn't shown. FocusOmniboxAndWaitForInstantSupport(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); // Navigate to the NTP. @@ -482,7 +482,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, InputOnNTPDoesntShowOverlay) { // Typing in the omnibox should not show the overlay. SetOmniboxText("query"); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); EXPECT_TRUE(instant()->model()->mode().is_default()); } @@ -504,9 +504,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ProcessIsolation) { EXPECT_EQ(1, instant_service->GetInstantProcessCount()); // And the Instant overlay and ntp should live inside it. - content::WebContents* preview = instant()->GetPreviewContents(); + content::WebContents* overlay = instant()->GetOverlayContents(); EXPECT_TRUE(instant_service->IsInstantProcess( - preview->GetRenderProcessHost()->GetID())); + overlay->GetRenderProcessHost()->GetID())); content::WebContents* ntp_contents = instant()->ntp_->contents(); EXPECT_TRUE(instant_service->IsInstantProcess( ntp_contents->GetRenderProcessHost()->GetID())); @@ -537,34 +537,34 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, DISABLED_UnrelatedSiteInstance) { ASSERT_NO_FATAL_FAILURE(SetupInstant()); FocusOmniboxAndWaitForInstantSupport(); - // Check that the uncommited ntp page and uncommited preview have unrelated + // Check that the uncommited ntp page and uncommited overlay have unrelated // site instances. // TODO(sreeram): |ntp_| is going away, so this check can be removed in the // future. - content::WebContents* preview = instant()->GetPreviewContents(); + content::WebContents* overlay = instant()->GetOverlayContents(); content::WebContents* ntp_contents = instant()->ntp_->contents(); - EXPECT_FALSE(preview->GetSiteInstance()->IsRelatedSiteInstance( + EXPECT_FALSE(overlay->GetSiteInstance()->IsRelatedSiteInstance( ntp_contents->GetSiteInstance())); - // Type a query and hit enter to get a results page. The preview becomes the + // Type a query and hit enter to get a results page. The overlay becomes the // active tab. - SetOmniboxTextAndWaitForInstantToShow("hello"); + SetOmniboxTextAndWaitForOverlayToShow("hello"); EXPECT_EQ("hello", GetOmniboxText()); browser()->window()->GetLocationBar()->AcceptInput(); content::WebContents* first_active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(first_active_tab, preview); + EXPECT_EQ(first_active_tab, overlay); scoped_refptr first_site_instance = first_active_tab->GetSiteInstance(); EXPECT_FALSE(first_site_instance->IsRelatedSiteInstance( ntp_contents->GetSiteInstance())); // Navigating elsewhere gets us off of the commited page. The next - // query will give us a new |preview| which we will then commit. + // query will give us a new |overlay| which we will then commit. ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); - // Show and commit the new preview. - SetOmniboxTextAndWaitForInstantToShow("hello again"); + // Show and commit the new overlay. + SetOmniboxTextAndWaitForOverlayToShow("hello again"); EXPECT_EQ("hello again", GetOmniboxText()); browser()->window()->GetLocationBar()->AcceptInput(); content::WebContents* second_active_tab = @@ -585,7 +585,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { // Do not set gray text that is not a suffix of the query. EXPECT_TRUE(ExecuteScript("behavior = 2")); EXPECT_TRUE(ExecuteScript("suggestion = 'potato'")); - SetOmniboxTextAndWaitForInstantToShow("query"); + SetOmniboxTextAndWaitForOverlayToShow("query"); EXPECT_EQ(ASCIIToUTF16("query"), omnibox()->GetText()); EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); @@ -594,7 +594,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { // Do not set blue text that is not a valid URL completion. EXPECT_TRUE(ExecuteScript("behavior = 1")); EXPECT_TRUE(ExecuteScript("suggestion = 'this is not a url!'")); - SetOmniboxTextAndWaitForInstantToShow("this is"); + SetOmniboxTextAndWaitForOverlayToShow("this is"); EXPECT_EQ(ASCIIToUTF16("this is"), omnibox()->GetText()); EXPECT_EQ(ASCIIToUTF16(""), omnibox()->GetInstantSuggestion()); @@ -604,7 +604,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, ValidatesSuggestions) { // First set up some blue text completion. EXPECT_TRUE(ExecuteScript("behavior = 1")); EXPECT_TRUE(ExecuteScript("suggestion = 'www.example.com'")); - SetOmniboxTextAndWaitForInstantToShow("http://www.ex"); + SetOmniboxTextAndWaitForOverlayToShow("http://www.ex"); string16 text = omnibox()->GetText(); EXPECT_EQ(ASCIIToUTF16("http://www.example.com"), text); size_t start = 0, end = 0; @@ -642,14 +642,14 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { // Get a handle to the NTP and the current state of the JS. ASSERT_NE(static_cast(NULL), instant()->ntp()); - content::WebContents* preview_tab = instant()->ntp_->contents(); - EXPECT_TRUE(preview_tab); - EXPECT_TRUE(UpdateSearchState(preview_tab)); + content::WebContents* overlay = instant()->ntp_->contents(); + EXPECT_TRUE(overlay); + EXPECT_TRUE(UpdateSearchState(overlay)); // Wait for most visited data to be ready, if necessary. if (on_most_visited_change_calls_ == 0) { observer.Wait(); - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); } EXPECT_EQ(1, on_most_visited_change_calls_); @@ -669,7 +669,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { observer.Wait(); // Update Most Visited state. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); // Make sure we have one less item in there. EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 1); @@ -681,7 +681,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { observer.Wait(); // Update Most Visited state. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); // Make sure we have the same number of items as before. EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); @@ -694,7 +694,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { observer.Wait(); // Update Most Visited state. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); // Delete the second Most Visited Item. rid = first_most_visited_item_id_; @@ -704,7 +704,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { observer.Wait(); // Update Most Visited state. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); // Make sure we have two less items in there. EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count - 2); @@ -716,7 +716,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MostVisited) { observer.Wait(); // Update Most Visited state. - EXPECT_TRUE(UpdateSearchState(preview_tab)); + EXPECT_TRUE(UpdateSearchState(overlay)); // Make sure we have the same number of items as before. EXPECT_EQ(most_visited_items_count_, old_most_visited_items_count); @@ -736,10 +736,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { // Get the current value of the start-edge margin and width. int start_margin; int width; - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.startMargin", + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin", &start_margin)); - EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.width", &width)); + EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &width)); // Toggle the home button visibility pref. PrefService* profile_prefs = browser()->profile()->GetPrefs(); @@ -749,9 +749,9 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { // Make sure the margin and width changed. int new_start_margin; int new_width; - EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.startMargin", + EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.startMargin", &new_start_margin)); - EXPECT_TRUE(GetIntFromJS(preview_tab, "chrome.searchBox.width", &new_width)); + EXPECT_TRUE(GetIntFromJS(overlay, "chrome.searchBox.width", &new_width)); EXPECT_NE(start_margin, new_start_margin); EXPECT_NE(width, new_width); EXPECT_EQ(new_width - width, start_margin - new_start_margin); @@ -764,7 +764,7 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_HomeButtonAffectsMargin) { #else #define MAYBE_CommitWhenFocusLostInFullHeight CommitWhenFocusLostInFullHeight #endif -// Test that the preview is committed when the omnibox loses focus when it is +// Test that the overlay is committed when the omnibox loses focus when it is // shown at 100% height. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, MAYBE_CommitWhenFocusLostInFullHeight) { @@ -772,15 +772,15 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // Focus omnibox and confirm overlay isn't shown. FocusOmniboxAndWaitForInstantSupport(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); EXPECT_TRUE(instant()->model()->mode().is_default()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); // Typing in the omnibox should show the overlay. - SetOmniboxTextAndWaitForInstantToShow("query"); - EXPECT_TRUE(instant()->IsPreviewingSearchResults()); - EXPECT_EQ(preview_tab, instant()->GetPreviewContents()); + SetOmniboxTextAndWaitForOverlayToShow("query"); + EXPECT_TRUE(instant()->IsOverlayingSearchResults()); + EXPECT_EQ(overlay, instant()->GetOverlayContents()); // Explicitly unfocus the omnibox without triggering a click. Note that this // doesn't actually change the focus state of the omnibox, only what the @@ -791,10 +791,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // Confirm that the overlay has been committed. content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(preview_tab, active_tab); + EXPECT_EQ(overlay, active_tab); } -// Test that the preview is committed when shown at 100% height without focus +// Test that the overlay is committed when shown at 100% height without focus // in the omnibox. IN_PROC_BROWSER_TEST_F(InstantExtendedTest, CommitWhenShownInFullHeightWithoutFocus) { @@ -802,10 +802,10 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // Focus omnibox and confirm overlay isn't shown. FocusOmniboxAndWaitForInstantSupport(); - content::WebContents* preview_tab = instant()->GetPreviewContents(); - EXPECT_TRUE(preview_tab); + content::WebContents* overlay = instant()->GetOverlayContents(); + EXPECT_TRUE(overlay); EXPECT_TRUE(instant()->model()->mode().is_default()); - EXPECT_FALSE(instant()->IsPreviewingSearchResults()); + EXPECT_FALSE(instant()->IsOverlayingSearchResults()); // Create an observer to wait for the commit. content::WindowedNotificationObserver observer( @@ -828,5 +828,5 @@ IN_PROC_BROWSER_TEST_F(InstantExtendedTest, // Confirm that the overlay has been committed. content::WebContents* active_tab = browser()->tab_strip_model()->GetActiveWebContents(); - EXPECT_EQ(preview_tab, active_tab); + EXPECT_EQ(overlay, active_tab); } diff --git a/chrome/browser/instant/instant_loader.cc b/chrome/browser/instant/instant_loader.cc index 629a7a6..4372875 100644 --- a/chrome/browser/instant/instant_loader.cc +++ b/chrome/browser/instant/instant_loader.cc @@ -85,7 +85,7 @@ void InstantLoader::SetContents(scoped_ptr new_contents) { CoreTabHelper::CreateForWebContents(contents()); CoreTabHelper::FromWebContents(contents())->set_delegate(this); - // Tab helpers used when committing a preview. + // Tab helpers used when committing an overlay. chrome::search::SearchTabHelper::CreateForWebContents(contents()); HistoryTabHelper::CreateForWebContents(contents()); diff --git a/chrome/browser/instant/instant_model.cc b/chrome/browser/instant/instant_model.cc deleted file mode 100644 index cf61ae30..0000000 --- a/chrome/browser/instant/instant_model.cc +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2012 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. - -#include "chrome/browser/instant/instant_model.h" - -#include "chrome/browser/instant/instant_controller.h" -#include "chrome/browser/instant/instant_model_observer.h" - -InstantModel::InstantModel(InstantController* controller) - : height_(0), - height_units_(INSTANT_SIZE_PIXELS), - preview_contents_(NULL), - controller_(controller) { -} - -InstantModel::~InstantModel() { -} - -void InstantModel::SetPreviewState(const chrome::search::Mode& mode, - int height, - InstantSizeUnits height_units) { - if (mode_.mode == mode.mode && height_ == height && - height_units_ == height_units) { - // Mode::mode hasn't changed, but perhaps bits that we ignore (such as - // Mode::origin) have. Update |mode_| anyway, so it's consistent with the - // argument (so InstantModel::mode() doesn't return something unexpected). - mode_ = mode; - return; - } - - DVLOG(1) << "SetPreviewState: " << mode_.mode << " to " << mode.mode; - mode_ = mode; - height_ = height; - height_units_ = height_units; - - FOR_EACH_OBSERVER(InstantModelObserver, observers_, - PreviewStateChanged(*this)); -} - -void InstantModel::SetPreviewContents(content::WebContents* preview_contents) { - if (preview_contents_ == preview_contents) - return; - - preview_contents_ = preview_contents; - - FOR_EACH_OBSERVER(InstantModelObserver, observers_, - PreviewStateChanged(*this)); -} - -content::WebContents* InstantModel::GetPreviewContents() const { - // |controller_| maybe NULL durning tests. - if (controller_) - return controller_->GetPreviewContents(); - return preview_contents_; -} - -void InstantModel::AddObserver(InstantModelObserver* observer) { - observers_.AddObserver(observer); -} - -void InstantModel::RemoveObserver(InstantModelObserver* observer) { - observers_.RemoveObserver(observer); -} diff --git a/chrome/browser/instant/instant_model.h b/chrome/browser/instant/instant_model.h deleted file mode 100644 index 42f29c5..0000000 --- a/chrome/browser/instant/instant_model.h +++ /dev/null @@ -1,64 +0,0 @@ -// Copyright 2012 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_MODEL_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_MODEL_H_ - -#include "base/basictypes.h" -#include "base/observer_list.h" -#include "chrome/common/instant_types.h" -#include "chrome/common/search_types.h" - -class InstantController; -class InstantModelObserver; - -namespace content { -class WebContents; -} - -// Holds state that is important to any views concerned with visibility and -// layout of the Instant preview. -class InstantModel { - public: - explicit InstantModel(InstantController* controller); - ~InstantModel(); - - // InstantModel only uses Mode::mode internally. Other parts of Mode, such as - // Mode::origin, may have arbitrary values, and should be ignored. - const chrome::search::Mode& mode() const { return mode_; } - int height() const { return height_; } - InstantSizeUnits height_units() const { return height_units_; } - - void SetPreviewState(const chrome::search::Mode& mode, - int height, - InstantSizeUnits height_units); - - void SetPreviewContents(content::WebContents* preview_contents); - content::WebContents* GetPreviewContents() const; - - // Add and remove observers. - void AddObserver(InstantModelObserver* observer); - void RemoveObserver(InstantModelObserver* observer); - - private: - chrome::search::Mode mode_; - int height_; - InstantSizeUnits height_units_; - - // Weak. Remembers the last set preview contents to detect changes. Actual - // preview contents is fetched from the |controller_| as this may not always - // reflect the actual preview in effect. - content::WebContents* preview_contents_; - - // Weak. The controller currently holds some model state. - // TODO(dhollowa): Remove this, transfer all model state to InstantModel. - InstantController* const controller_; - - // Observers. - ObserverList observers_; - - DISALLOW_COPY_AND_ASSIGN(InstantModel); -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_MODEL_H_ diff --git a/chrome/browser/instant/instant_model_observer.h b/chrome/browser/instant/instant_model_observer.h deleted file mode 100644 index 1985fcc..0000000 --- a/chrome/browser/instant/instant_model_observer.h +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright 2012 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_MODEL_OBSERVER_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_MODEL_OBSERVER_H_ - -class InstantModel; - -// This class defines the observer interface for the |InstantModel|. -class InstantModelObserver { - public: - // Informs the observer that the preview state has changed. This can mean - // either the model state changed or the contents of the preview changed. - virtual void PreviewStateChanged(const InstantModel& model) = 0; - - protected: - ~InstantModelObserver() {} -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_MODEL_OBSERVER_H_ diff --git a/chrome/browser/instant/instant_ntp.h b/chrome/browser/instant/instant_ntp.h index fb72ec9..c93246c 100644 --- a/chrome/browser/instant/instant_ntp.h +++ b/chrome/browser/instant/instant_ntp.h @@ -32,7 +32,7 @@ class InstantNTP : public InstantPage, const content::WebContents* active_tab, const base::Closure& on_stale_callback); - // Releases the WebContents for the instant page. This should be called when + // Releases the WebContents for the Instant page. This should be called when // the page is about to be committed. scoped_ptr ReleaseContents() WARN_UNUSED_RESULT; diff --git a/chrome/browser/instant/instant_overlay.cc b/chrome/browser/instant/instant_overlay.cc index 68029eb..bb48452 100644 --- a/chrome/browser/instant/instant_overlay.cc +++ b/chrome/browser/instant/instant_overlay.cc @@ -71,7 +71,7 @@ void InstantOverlay::DidNavigate( last_navigation_ = add_page_args; } -bool InstantOverlay::IsUsingLocalPreview() const { +bool InstantOverlay::IsUsingLocalOverlay() const { return instant_url_ == chrome::search::kLocalOmniboxPopupURL; } @@ -115,7 +115,7 @@ void InstantOverlay::OnSwappedContents() { } void InstantOverlay::OnFocus() { - // The preview is getting focus. Equivalent to it being clicked. + // The overlay is getting focus. Equivalent to it being clicked. base::AutoReset reset(&is_pointer_down_from_activate_, true); instant_controller()->FocusedOverlayContents(); } diff --git a/chrome/browser/instant/instant_overlay.h b/chrome/browser/instant/instant_overlay.h index 6c17925..b380554 100644 --- a/chrome/browser/instant/instant_overlay.h +++ b/chrome/browser/instant/instant_overlay.h @@ -22,9 +22,9 @@ namespace content { class WebContents; } -// InstantOverlay is used to communicate with a preview WebContents that it owns -// and loads the "Instant URL" into. This preview can appear and disappear at -// will as the user types in the omnibox. +// InstantOverlay is used to communicate with an overlay WebContents that it +// owns and loads the "Instant URL" into. This overlay can appear and disappear +// at will as the user types in the omnibox. class InstantOverlay : public InstantPage, public InstantLoader::Delegate { public: @@ -52,7 +52,7 @@ class InstantOverlay : public InstantPage, bool is_stale() const { return is_stale_; } // Returns true if the mouse or a touch pointer is down due to activating the - // preview contents. + // overlay contents. bool is_pointer_down_from_activate() const { return is_pointer_down_from_activate_; } @@ -69,7 +69,7 @@ class InstantOverlay : public InstantPage, // Returns true if the overlay is using // InstantController::kLocalOmniboxPopupURL as the |instant_url_|. - bool IsUsingLocalPreview() const; + bool IsUsingLocalOverlay() const; // Overridden from InstantPage: virtual void Update(const string16& text, diff --git a/chrome/browser/instant/instant_overlay_controller.cc b/chrome/browser/instant/instant_overlay_controller.cc new file mode 100644 index 0000000..2ecaff9 --- /dev/null +++ b/chrome/browser/instant/instant_overlay_controller.cc @@ -0,0 +1,19 @@ +// Copyright 2012 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. + +#include "chrome/browser/instant/instant_overlay_controller.h" + +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_instant_controller.h" + +InstantOverlayController::InstantOverlayController(Browser* browser) + : browser_(browser) { + if (browser_->instant_controller()) + browser_->instant_controller()->instant()->model()->AddObserver(this); +} + +InstantOverlayController::~InstantOverlayController() { + if (browser_->instant_controller()) + browser_->instant_controller()->instant()->model()->RemoveObserver(this); +} diff --git a/chrome/browser/instant/instant_overlay_controller.h b/chrome/browser/instant/instant_overlay_controller.h new file mode 100644 index 0000000..a2464f1 --- /dev/null +++ b/chrome/browser/instant/instant_overlay_controller.h @@ -0,0 +1,28 @@ +// Copyright 2012 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_OVERLAY_CONTROLLER_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_CONTROLLER_H_ + +#include "base/compiler_specific.h" +#include "chrome/browser/instant/instant_overlay_model_observer.h" + +class Browser; +class InstantOverlayModel; + +// Abstract base class for platform-specific Instant overlay controllers. +class InstantOverlayController : public InstantOverlayModelObserver { + protected: + explicit InstantOverlayController(Browser* browser); + virtual ~InstantOverlayController(); + + Browser* const browser_; + + private: + // Overridden from InstantOverlayModelObserver: + virtual void OverlayStateChanged( + const InstantOverlayModel& model) OVERRIDE = 0; +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_CONTROLLER_H_ diff --git a/chrome/browser/instant/instant_overlay_model.cc b/chrome/browser/instant/instant_overlay_model.cc new file mode 100644 index 0000000..f08b74a --- /dev/null +++ b/chrome/browser/instant/instant_overlay_model.cc @@ -0,0 +1,66 @@ +// Copyright 2012 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. + +#include "chrome/browser/instant/instant_overlay_model.h" + +#include "chrome/browser/instant/instant_controller.h" +#include "chrome/browser/instant/instant_overlay_model_observer.h" + +InstantOverlayModel::InstantOverlayModel(InstantController* controller) + : height_(0), + height_units_(INSTANT_SIZE_PIXELS), + overlay_contents_(NULL), + controller_(controller) { +} + +InstantOverlayModel::~InstantOverlayModel() { +} + +void InstantOverlayModel::SetOverlayState(const chrome::search::Mode& mode, + int height, + InstantSizeUnits height_units) { + if (mode_.mode == mode.mode && height_ == height && + height_units_ == height_units) { + // Mode::mode hasn't changed, but perhaps bits that we ignore (such as + // Mode::origin) have. Update |mode_| anyway, so it's consistent with the + // argument (so mode() doesn't return something unexpected). + mode_ = mode; + return; + } + + DVLOG(1) << "SetOverlayState: " << mode_.mode << " to " << mode.mode; + mode_ = mode; + height_ = height; + height_units_ = height_units; + + FOR_EACH_OBSERVER(InstantOverlayModelObserver, observers_, + OverlayStateChanged(*this)); +} + +void InstantOverlayModel::SetOverlayContents( + content::WebContents* overlay_contents) { + if (overlay_contents_ == overlay_contents) + return; + + overlay_contents_ = overlay_contents; + + FOR_EACH_OBSERVER(InstantOverlayModelObserver, observers_, + OverlayStateChanged(*this)); +} + +content::WebContents* InstantOverlayModel::GetOverlayContents() const { + // |controller_| maybe NULL durning tests. + if (controller_) + return controller_->GetOverlayContents(); + return overlay_contents_; +} + +void InstantOverlayModel::AddObserver(InstantOverlayModelObserver* observer) { + observers_.AddObserver(observer); +} + +void InstantOverlayModel::RemoveObserver( + InstantOverlayModelObserver* observer) { + observers_.RemoveObserver(observer); +} diff --git a/chrome/browser/instant/instant_overlay_model.h b/chrome/browser/instant/instant_overlay_model.h new file mode 100644 index 0000000..d8203be --- /dev/null +++ b/chrome/browser/instant/instant_overlay_model.h @@ -0,0 +1,64 @@ +// Copyright 2012 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_OVERLAY_MODEL_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_MODEL_H_ + +#include "base/basictypes.h" +#include "base/observer_list.h" +#include "chrome/common/instant_types.h" +#include "chrome/common/search_types.h" + +class InstantController; +class InstantOverlayModelObserver; + +namespace content { +class WebContents; +} + +// Holds state that is important to any views concerned with visibility and +// layout of the Instant overlay. +class InstantOverlayModel { + public: + explicit InstantOverlayModel(InstantController* controller); + ~InstantOverlayModel(); + + // InstantOverlayModel only uses Mode::mode internally. Other parts of Mode, + // such as Mode::origin, may have arbitrary values, and should be ignored. + const chrome::search::Mode& mode() const { return mode_; } + int height() const { return height_; } + InstantSizeUnits height_units() const { return height_units_; } + + void SetOverlayState(const chrome::search::Mode& mode, + int height, + InstantSizeUnits height_units); + + void SetOverlayContents(content::WebContents* overlay_contents); + content::WebContents* GetOverlayContents() const; + + // Add and remove observers. + void AddObserver(InstantOverlayModelObserver* observer); + void RemoveObserver(InstantOverlayModelObserver* observer); + + private: + chrome::search::Mode mode_; + int height_; + InstantSizeUnits height_units_; + + // Weak. Remembers the last set overlay contents to detect changes. Actual + // overlay contents is fetched from the |controller_| as this may not always + // reflect the actual overlay in effect. + content::WebContents* overlay_contents_; + + // Weak. The controller currently holds some model state. + // TODO(dhollowa): Remove this, transfer all state to InstantOverlayModel. + InstantController* const controller_; + + // Observers. + ObserverList observers_; + + DISALLOW_COPY_AND_ASSIGN(InstantOverlayModel); +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_MODEL_H_ diff --git a/chrome/browser/instant/instant_overlay_model_observer.h b/chrome/browser/instant/instant_overlay_model_observer.h new file mode 100644 index 0000000..7169ce8 --- /dev/null +++ b/chrome/browser/instant/instant_overlay_model_observer.h @@ -0,0 +1,21 @@ +// Copyright 2012 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_OVERLAY_MODEL_OBSERVER_H_ +#define CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_MODEL_OBSERVER_H_ + +class InstantOverlayModel; + +// This class defines the observer interface for the InstantOverlayModel. +class InstantOverlayModelObserver { + public: + // Informs the observer that the overlay state has changed. This can mean + // either the model state changed or the contents of the overlay changed. + virtual void OverlayStateChanged(const InstantOverlayModel& model) = 0; + + protected: + ~InstantOverlayModelObserver() {} +}; + +#endif // CHROME_BROWSER_INSTANT_INSTANT_OVERLAY_MODEL_OBSERVER_H_ diff --git a/chrome/browser/instant/instant_preview_controller.cc b/chrome/browser/instant/instant_preview_controller.cc deleted file mode 100644 index a728fc81..0000000 --- a/chrome/browser/instant/instant_preview_controller.cc +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2012 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. - -#include "chrome/browser/instant/instant_preview_controller.h" - -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_instant_controller.h" - -InstantPreviewController::InstantPreviewController(Browser* browser) - : browser_(browser) { - if (browser_->instant_controller()) - browser_->instant_controller()->instant()->model()->AddObserver(this); -} - -InstantPreviewController::~InstantPreviewController() { - if (browser_->instant_controller()) - browser_->instant_controller()->instant()->model()->RemoveObserver(this); -} diff --git a/chrome/browser/instant/instant_preview_controller.h b/chrome/browser/instant/instant_preview_controller.h deleted file mode 100644 index e90e2b6..0000000 --- a/chrome/browser/instant/instant_preview_controller.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2012 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_PREVIEW_CONTROLLER_H_ -#define CHROME_BROWSER_INSTANT_INSTANT_PREVIEW_CONTROLLER_H_ - -#include "base/compiler_specific.h" -#include "chrome/browser/instant/instant_model_observer.h" - -class Browser; -class InstantModel; - -// Abstract base class for platform-specific Instant preview controllers. -class InstantPreviewController : public InstantModelObserver { - protected: - explicit InstantPreviewController(Browser* browser); - virtual ~InstantPreviewController(); - - Browser* const browser_; - - private: - // Overridden from InstantModelObserver: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE = 0; -}; - -#endif // CHROME_BROWSER_INSTANT_INSTANT_PREVIEW_CONTROLLER_H_ diff --git a/chrome/browser/instant/instant_test_utils.cc b/chrome/browser/instant/instant_test_utils.cc index eb288bc..242db0b 100644 --- a/chrome/browser/instant/instant_test_utils.cc +++ b/chrome/browser/instant/instant_test_utils.cc @@ -28,7 +28,7 @@ std::string WrapScript(const std::string& script) { // InstantTestModelObserver -------------------------------------------------- InstantTestModelObserver::InstantTestModelObserver( - InstantModel* model, + InstantOverlayModel* model, chrome::search::Mode::Type desired_mode_type) : model_(model), desired_mode_type_(desired_mode_type) { @@ -39,11 +39,12 @@ InstantTestModelObserver::~InstantTestModelObserver() { model_->RemoveObserver(this); } -void InstantTestModelObserver::WaitUntilDesiredPreviewState() { +void InstantTestModelObserver::WaitForDesiredOverlayState() { run_loop_.Run(); } -void InstantTestModelObserver::PreviewStateChanged(const InstantModel& model) { +void InstantTestModelObserver::OverlayStateChanged( + const InstantOverlayModel& model) { if (model.mode().mode == desired_mode_type_) run_loop_.Quit(); } @@ -76,7 +77,7 @@ void InstantTestBase::SetupInstant() { void InstantTestBase::KillInstantRenderView() { base::KillProcess( - instant()->GetPreviewContents()->GetRenderProcessHost()->GetHandle(), + instant()->GetOverlayContents()->GetRenderProcessHost()->GetHandle(), content::RESULT_CODE_KILLED, false); } @@ -96,12 +97,12 @@ void InstantTestBase::SetOmniboxText(const std::string& text) { omnibox()->SetUserText(UTF8ToUTF16(text)); } -void InstantTestBase::SetOmniboxTextAndWaitForInstantToShow( +void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow( const std::string& text) { InstantTestModelObserver observer( instant()->model(), chrome::search::Mode::MODE_SEARCH_SUGGESTIONS); SetOmniboxText(text); - observer.WaitUntilDesiredPreviewState(); + observer.WaitForDesiredOverlayState(); } bool InstantTestBase::GetBoolFromJS(content::WebContents* contents, @@ -126,7 +127,7 @@ bool InstantTestBase::GetStringFromJS(content::WebContents* contents, } bool InstantTestBase::ExecuteScript(const std::string& script) { - return content::ExecuteScript(instant()->GetPreviewContents(), script); + return content::ExecuteScript(instant()->GetOverlayContents(), script); } bool InstantTestBase::CheckVisibilityIs(content::WebContents* contents, diff --git a/chrome/browser/instant/instant_test_utils.h b/chrome/browser/instant/instant_test_utils.h index 7059ed2..60738b7 100644 --- a/chrome/browser/instant/instant_test_utils.h +++ b/chrome/browser/instant/instant_test_utils.h @@ -9,7 +9,7 @@ #include "base/run_loop.h" #include "chrome/browser/instant/instant_controller.h" -#include "chrome/browser/instant/instant_model_observer.h" +#include "chrome/browser/instant/instant_overlay_model_observer.h" #include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser_instant_controller.h" #include "chrome/browser/ui/browser_window.h" @@ -18,19 +18,19 @@ #include "chrome/common/search_types.h" #include "chrome/test/base/in_process_browser_test.h" -class InstantTestModelObserver : public InstantModelObserver { +class InstantTestModelObserver : public InstantOverlayModelObserver { public: - InstantTestModelObserver(InstantModel* model, + InstantTestModelObserver(InstantOverlayModel* model, chrome::search::Mode::Type desired_mode_type); ~InstantTestModelObserver(); - void WaitUntilDesiredPreviewState(); + void WaitForDesiredOverlayState(); - // Overridden from InstantModelObserver: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; + // Overridden from InstantOverlayModelObserver: + virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; private: - InstantModel* const model_; + InstantOverlayModel* const model_; const chrome::search::Mode::Type desired_mode_type_; base::RunLoop run_loop_; @@ -63,7 +63,7 @@ class InstantTestBase : public InProcessBrowserTest { void FocusOmniboxAndWaitForInstantSupport(); void SetOmniboxText(const std::string& text); - void SetOmniboxTextAndWaitForInstantToShow(const std::string& text); + void SetOmniboxTextAndWaitForOverlayToShow(const std::string& text); bool GetBoolFromJS(content::WebContents* contents, const std::string& script, diff --git a/chrome/browser/resources/instant/instant.css b/chrome/browser/resources/instant/instant.css index a975265..4e47245 100644 --- a/chrome/browser/resources/instant/instant.css +++ b/chrome/browser/resources/instant/instant.css @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012 The Chromium Authors. All rights reserved. + * Copyright 2012 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. */ diff --git a/chrome/browser/resources/instant/instant.html b/chrome/browser/resources/instant/instant.html index e0f2aeb..807b906 100644 --- a/chrome/browser/resources/instant/instant.html +++ b/chrome/browser/resources/instant/instant.html @@ -1,7 +1,7 @@ diff --git a/chrome/browser/resources/instant/instant.js b/chrome/browser/resources/instant/instant.js index 407871b..8409290 100644 --- a/chrome/browser/resources/instant/instant.js +++ b/chrome/browser/resources/instant/instant.js @@ -1,4 +1,4 @@ -// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Copyright 2012 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. @@ -64,8 +64,7 @@ var instantConfig = (function() { row.appendChild(input); var units = createElementWithClass('div', 'row-units'); - if (field.units) - units.innerHTML = field.units; + if (field.units) units.innerHTML = field.units; row.appendChild(units); $('instant-form').appendChild(row); @@ -118,9 +117,7 @@ var instantConfig = (function() { value = parseFloat($(prefName).value); else value = $(prefName).value; - chrome.send( - 'setPreferenceValue', - [prefName, value]); + chrome.send('setPreferenceValue', [prefName, value]); } /** diff --git a/chrome/browser/task_manager/task_manager_resource_providers.cc b/chrome/browser/task_manager/task_manager_resource_providers.cc index 89c193a..d6b4dc7 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.cc +++ b/chrome/browser/task_manager/task_manager_resource_providers.cc @@ -91,7 +91,7 @@ int GetMessagePrefixID(bool is_app, bool is_extension, bool is_incognito, bool is_prerender, - bool is_instant_preview, + bool is_instant_overlay, bool is_background) { if (is_app) { if (is_background) { @@ -108,8 +108,8 @@ int GetMessagePrefixID(bool is_app, return IDS_TASK_MANAGER_EXTENSION_PREFIX; } else if (is_prerender) { return IDS_TASK_MANAGER_PRERENDER_PREFIX; - } else if (is_instant_preview) { - return IDS_TASK_MANAGER_INSTANT_PREVIEW_PREFIX; + } else if (is_instant_overlay) { + return IDS_TASK_MANAGER_INSTANT_OVERLAY_PREFIX; } else { return IDS_TASK_MANAGER_TAB_PREFIX; } @@ -161,7 +161,7 @@ bool IsContentsInstant(WebContents* web_contents) { for (chrome::BrowserIterator it; !it.done(); it.Next()) { if (it->instant_controller() && it->instant_controller()->instant()-> - GetPreviewContents() == web_contents) { + GetOverlayContents() == web_contents) { return true; } } @@ -305,7 +305,7 @@ TaskManagerTabContentsResource::TaskManagerTabContentsResource( web_contents->GetRenderViewHost()), web_contents_(web_contents), profile_(Profile::FromBrowserContext(web_contents->GetBrowserContext())), - is_instant_preview_(IsContentsInstant(web_contents)) { + is_instant_overlay_(IsContentsInstant(web_contents)) { if (!prerender_icon_) { ResourceBundle& rb = ResourceBundle::GetSharedInstance(); prerender_icon_ = rb.GetImageSkiaNamed(IDR_PRERENDER); @@ -316,8 +316,8 @@ TaskManagerTabContentsResource::~TaskManagerTabContentsResource() { } void TaskManagerTabContentsResource::InstantCommitted() { - DCHECK(is_instant_preview_); - is_instant_preview_ = false; + DCHECK(is_instant_overlay_); + is_instant_overlay_ = false; } bool TaskManagerTabContentsResource::HostsExtension() const { @@ -346,7 +346,7 @@ string16 TaskManagerTabContentsResource::GetTitle() const { HostsExtension(), profile_->IsOffTheRecord(), IsContentsPrerendering(web_contents_), - is_instant_preview_, + is_instant_overlay_, false); return l10n_util::GetStringFUTF16(message_id, tab_title); } @@ -419,18 +419,18 @@ void TaskManagerTabContentsResourceProvider::StartUpdating() { updating_ = true; // The contents that are tracked by this resource provider are those that - // are tab contents (WebContents serving as a tab in a Browser), instant + // are tab contents (WebContents serving as a tab in a Browser), Instant // pages, prerender pages, and background printed pages. // Add all the existing WebContentses. for (TabContentsIterator iterator; !iterator.done(); iterator.Next()) Add(*iterator); - // Add all the instant pages. + // Add all the Instant pages. for (chrome::BrowserIterator it; !it.done(); it.Next()) { if (it->instant_controller() && - it->instant_controller()->instant()->GetPreviewContents()) { - Add(it->instant_controller()->instant()->GetPreviewContents()); + it->instant_controller()->instant()->GetOverlayContents()) { + Add(it->instant_controller()->instant()->GetOverlayContents()); } } @@ -501,7 +501,7 @@ void TaskManagerTabContentsResourceProvider::Add(WebContents* web_contents) { return; // The contents that are tracked by this resource provider are those that - // are tab contents (WebContents serving as a tab in a Browser), instant + // are tab contents (WebContents serving as a tab in a Browser), Instant // pages, prerender pages, and background printed pages. if (!chrome::FindBrowserWithWebContents(web_contents) && !IsContentsPrerendering(web_contents) && diff --git a/chrome/browser/task_manager/task_manager_resource_providers.h b/chrome/browser/task_manager/task_manager_resource_providers.h index f5cef0e..b59572e 100644 --- a/chrome/browser/task_manager/task_manager_resource_providers.h +++ b/chrome/browser/task_manager/task_manager_resource_providers.h @@ -106,7 +106,7 @@ class TaskManagerRendererResource : public TaskManager::Resource { DISALLOW_COPY_AND_ASSIGN(TaskManagerRendererResource); }; -// Tracks a single tab contents, prerendered page, instant page, or background +// Tracks a single tab contents, prerendered page, Instant page, or background // printing page. class TaskManagerTabContentsResource : public TaskManagerRendererResource { public: @@ -114,7 +114,7 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource { virtual ~TaskManagerTabContentsResource(); // Called when the underlying web_contents has been committed and is no - // longer an Instant preview. + // longer an Instant overlay. void InstantCommitted(); // TaskManager::Resource methods: @@ -132,12 +132,12 @@ class TaskManagerTabContentsResource : public TaskManagerRendererResource { static gfx::ImageSkia* prerender_icon_; content::WebContents* web_contents_; Profile* profile_; - bool is_instant_preview_; + bool is_instant_overlay_; DISALLOW_COPY_AND_ASSIGN(TaskManagerTabContentsResource); }; -// Provides resources for tab contents, prerendered pages, instant pages, and +// Provides resources for tab contents, prerendered pages, Instant pages, and // background printing pages. class TaskManagerTabContentsResourceProvider : public TaskManager::ResourceProvider, @@ -623,7 +623,6 @@ class TaskManagerBrowserProcessResourceProvider DISALLOW_COPY_AND_ASSIGN(TaskManagerBrowserProcessResourceProvider); }; - class TaskManagerGuestResource : public TaskManagerRendererResource { public: explicit TaskManagerGuestResource(content::RenderViewHost* render_view_host); diff --git a/chrome/browser/ui/browser.cc b/chrome/browser/ui/browser.cc index 99122cc..66551f5 100644 --- a/chrome/browser/ui/browser.cc +++ b/chrome/browser/ui/browser.cc @@ -1224,11 +1224,11 @@ void Browser::ShowFirstRunBubble() { window()->GetLocationBar()->ShowFirstRunBubble(); } -void Browser::MaybeUpdateBookmarkBarStateForInstantPreview( +void Browser::MaybeUpdateBookmarkBarStateForInstantOverlay( const chrome::search::Mode& mode) { // This is invoked by a platform-specific implementation of - // |InstantPreviewController| to update bookmark bar state according to - // instant preview state. + // |InstantOverlayController| to update bookmark bar state according to + // Instant overlay state. // ModeChanged() updates bookmark bar state for all mode transitions except // when new mode is |SEARCH_SUGGESTIONS|, because that needs to be done when // the suggestions are ready. @@ -1826,8 +1826,8 @@ void Browser::Observe(int type, void Browser::ModeChanged(const chrome::search::Mode& old_mode, const chrome::search::Mode& new_mode) { // If new mode is |SEARCH_SUGGESTIONS|, don't update bookmark bar state now; - // wait till the instant preview is ready to show suggestions before hiding - // the bookmark bar (in MaybeUpdateBookmarkBarStateForInstantPreview()). + // wait till the Instant overlay is ready to show suggestions before hiding + // the bookmark bar (in MaybeUpdateBookmarkBarStateForInstantOverlay()). // TODO(kuan): but for now, only delay updating bookmark bar state if origin // is |DEFAULT|; other origins require more complex logic to be implemented // to prevent jankiness caused by hiding bookmark bar, so just hide the @@ -1988,7 +1988,6 @@ void Browser::RemoveScheduledUpdatesFor(WebContents* contents) { scheduled_updates_.erase(i); } - /////////////////////////////////////////////////////////////////////////////// // Browser, Getters for UI (private): diff --git a/chrome/browser/ui/browser.h b/chrome/browser/ui/browser.h index ef3f0d5..3ced766 100644 --- a/chrome/browser/ui/browser.h +++ b/chrome/browser/ui/browser.h @@ -456,10 +456,10 @@ class Browser : public TabStripModelObserver, // Show the first run search engine bubble on the location bar. void ShowFirstRunBubble(); - // If necessary, update the bookmark bar state according to the instant - // preview state: when instant preview shows suggestions and bookmark bar is + // If necessary, update the bookmark bar state according to the Instant + // overlay state: when Instant overlay shows suggestions and bookmark bar is // still showing attached, hide it. - void MaybeUpdateBookmarkBarStateForInstantPreview( + void MaybeUpdateBookmarkBarStateForInstantOverlay( const chrome::search::Mode& mode); FullscreenController* fullscreen_controller() const { diff --git a/chrome/browser/ui/browser_instant_controller.cc b/chrome/browser/ui/browser_instant_controller.cc index 0b69d66..0eea71a 100644 --- a/chrome/browser/ui/browser_instant_controller.cc +++ b/chrome/browser/ui/browser_instant_controller.cc @@ -182,20 +182,20 @@ Profile* BrowserInstantController::profile() const { } void BrowserInstantController::CommitInstant( - scoped_ptr preview, + scoped_ptr overlay, bool in_new_tab) { - if (profile()->GetExtensionService()->IsInstalledApp(preview->GetURL())) { + if (profile()->GetExtensionService()->IsInstalledApp(overlay->GetURL())) { AppLauncherHandler::RecordAppLaunchType( extension_misc::APP_LAUNCH_OMNIBOX_INSTANT); } if (in_new_tab) { - // TabStripModel takes ownership of |preview|. - browser_->tab_strip_model()->AddWebContents(preview.release(), -1, + // TabStripModel takes ownership of |overlay|. + browser_->tab_strip_model()->AddWebContents(overlay.release(), -1, instant_.last_transition_type(), TabStripModel::ADD_ACTIVE); } else { ReplaceWebContentsAt( browser_->tab_strip_model()->active_index(), - preview.Pass()); + overlay.Pass()); } } @@ -224,9 +224,9 @@ gfx::Rect BrowserInstantController::GetInstantBounds() { return browser_->window()->GetInstantBounds(); } -void BrowserInstantController::InstantPreviewFocused() { +void BrowserInstantController::InstantOverlayFocused() { // NOTE: This is only invoked on aura. - browser_->window()->WebContentsFocused(instant_.GetPreviewContents()); + browser_->window()->WebContentsFocused(instant_.GetOverlayContents()); } void BrowserInstantController::FocusOmniboxInvisibly() { @@ -274,10 +274,10 @@ void BrowserInstantController::SetOmniboxBounds(const gfx::Rect& bounds) { void BrowserInstantController::ResetInstant() { bool instant_enabled = IsInstantEnabled(profile()); - bool use_local_preview_only = profile()->IsOffTheRecord() || + bool use_local_overlay_only = profile()->IsOffTheRecord() || (!instant_enabled && !profile()->GetPrefs()->GetBoolean(prefs::kSearchSuggestEnabled)); - instant_.SetInstantEnabled(instant_enabled, use_local_preview_only); + instant_.SetInstantEnabled(instant_enabled, use_local_overlay_only); } //////////////////////////////////////////////////////////////////////////////// @@ -285,7 +285,7 @@ void BrowserInstantController::ResetInstant() { void BrowserInstantController::ModeChanged(const search::Mode& old_mode, const search::Mode& new_mode) { - // If mode is now |NTP|, send theme-related information to instant. + // If mode is now |NTP|, send theme-related information to Instant. if (new_mode.is_ntp()) UpdateThemeInfo(false); diff --git a/chrome/browser/ui/browser_instant_controller.h b/chrome/browser/ui/browser_instant_controller.h index aa58261..df53030 100644 --- a/chrome/browser/ui/browser_instant_controller.h +++ b/chrome/browser/ui/browser_instant_controller.h @@ -38,7 +38,7 @@ class BrowserInstantController : public content::NotificationObserver, explicit BrowserInstantController(Browser* browser); virtual ~BrowserInstantController(); - // Returns true if Instant is enabled in a visible, preview-showing mode. + // Returns true if Instant is enabled in a visible, overlay-showing mode. static bool IsInstantEnabled(Profile* profile); // Registers Instant related preferences. @@ -67,9 +67,9 @@ class BrowserInstantController : public content::NotificationObserver, // this BrowserInstantController. InstantController* instant() { return &instant_; } - // Invoked by |instant_| to commit the |preview| by merging it into the active + // Invoked by |instant_| to commit the |overlay| by merging it into the active // tab or adding it as a new tab. - void CommitInstant(scoped_ptr preview, bool in_new_tab); + void CommitInstant(scoped_ptr overlay, bool in_new_tab); // Invoked by |instant_| to autocomplete the |suggestion| into the omnibox. void SetInstantSuggestion(const InstantSuggestion& suggestion); @@ -78,19 +78,19 @@ class BrowserInstantController : public content::NotificationObserver, // Call-through to OmniboxEditModel::CommitSuggestedText. void CommitSuggestedText(bool skip_inline_autocomplete); - // Invoked by |instant_| to get the bounds that the preview is placed at, + // Invoked by |instant_| to get the bounds that the overlay is placed at, // in screen coordinates. gfx::Rect GetInstantBounds(); - // Invoked by |instant_| to notify that the preview gained focus, usually due + // Invoked by |instant_| to notify that the overlay gained focus, usually due // to the user clicking on it. - void InstantPreviewFocused(); + void InstantOverlayFocused(); // Invoked by |instant_| to give the omnibox focus invisibly. void FocusOmniboxInvisibly(); // Invoked by |instant_| to get the currently active tab, over which the - // preview would be shown. + // overlay would be shown. content::WebContents* GetActiveWebContents() const; // Invoked by |browser_| when the active tab changes. @@ -138,7 +138,7 @@ class BrowserInstantController : public content::NotificationObserver, InstantController instant_; InstantUnloadHandler instant_unload_handler_; - // Theme-related data for NTP preview to adopt themes. + // Theme-related data for NTP overlay to adopt themes. bool initialized_theme_info_; // True if theme_info_ has been initialized. ThemeBackgroundInfo theme_info_; diff --git a/chrome/browser/ui/cocoa/browser_window_cocoa.mm b/chrome/browser/ui/cocoa/browser_window_cocoa.mm index 4b85714..6a0f839 100644 --- a/chrome/browser/ui/cocoa/browser_window_cocoa.mm +++ b/chrome/browser/ui/cocoa/browser_window_cocoa.mm @@ -425,7 +425,6 @@ void BrowserWindowCocoa::FocusBookmarksToolbar() { // Not needed on the Mac. } - bool BrowserWindowCocoa::IsBookmarkBarVisible() const { return browser_->profile()->GetPrefs()->GetBoolean(prefs::kShowBookmarkBar); } @@ -669,7 +668,7 @@ extensions::ActiveTabPermissionGranter* void BrowserWindowCocoa::ModeChanged( const chrome::search::Mode& old_mode, const chrome::search::Mode& new_mode) { - [controller_ updateBookmarkBarStateForInstantPreview]; + [controller_ updateBookmarkBarStateForInstantOverlay]; } void BrowserWindowCocoa::DestroyBrowser() { diff --git a/chrome/browser/ui/cocoa/browser_window_controller.h b/chrome/browser/ui/cocoa/browser_window_controller.h index 16556ac..5eee4e4 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.h +++ b/chrome/browser/ui/cocoa/browser_window_controller.h @@ -37,8 +37,8 @@ class ExtensionKeybindingRegistryCocoa; @class FullscreenWindow; @class InfoBarContainerController; class LocationBarViewMac; +@class OverlayableContentsController; @class PresentationModeController; -@class PreviewableContentsController; class StatusBubbleMac; @class TabStripController; @class TabStripView; @@ -69,7 +69,7 @@ class WebContents; scoped_nsobject downloadShelfController_; scoped_nsobject bookmarkBarController_; scoped_nsobject devToolsController_; - scoped_nsobject previewableContentsController_; + scoped_nsobject overlayableContentsController_; scoped_nsobject presentationModeController_; scoped_nsobject fullscreenExitBubbleController_; @@ -216,8 +216,8 @@ class WebContents; // Returns a weak pointer to the floating bar backing view; - (NSView*)floatingBarBackingView; -// Returns a weak pointer to the previewable contents controller. -- (PreviewableContentsController*)previewableContentsController; +// Returns a weak pointer to the overlayable contents controller. +- (OverlayableContentsController*)overlayableContentsController; // Access the Profile object that backs this Browser. - (Profile*)profile; @@ -328,7 +328,7 @@ class WebContents; // coordinates. - (NSPoint)bookmarkBubblePoint; -// Shows or hides the Instant preview contents. +// Shows or hides the Instant overlay contents. - (void)commitInstant; // Returns the frame, in Cocoa (unflipped) screen coordinates, of the area where @@ -341,7 +341,7 @@ class WebContents; returnCode:(NSInteger)code context:(void*)context; -- (void)updateBookmarkBarStateForInstantPreview; +- (void)updateBookmarkBarStateForInstantOverlay; @end // @interface BrowserWindowController diff --git a/chrome/browser/ui/cocoa/browser_window_controller.mm b/chrome/browser/ui/cocoa/browser_window_controller.mm index 58c95ba..efe184f 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller.mm @@ -52,7 +52,7 @@ #import "chrome/browser/ui/cocoa/location_bar/autocomplete_text_field_editor.h" #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" #import "chrome/browser/ui/cocoa/status_bubble_mac.h" -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" #import "chrome/browser/ui/cocoa/tab_contents/sad_tab_controller.h" #import "chrome/browser/ui/cocoa/tab_contents/tab_contents_controller.h" #import "chrome/browser/ui/cocoa/tabpose_window.h" @@ -62,8 +62,6 @@ #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #include "chrome/browser/ui/fullscreen/fullscreen_controller.h" #include "chrome/browser/ui/omnibox/location_bar.h" -#include "chrome/browser/ui/search/search.h" -#include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/tabs/dock_info.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model_delegate.h" @@ -333,15 +331,15 @@ enum { [[devToolsController_ view] setFrame:[[self tabContentArea] bounds]]; [[self tabContentArea] addSubview:[devToolsController_ view]]; - // Create the previewable contents controller. This provides the switch + // Create the overlayable contents controller. This provides the switch // view that TabStripController needs. - previewableContentsController_.reset( - [[PreviewableContentsController alloc] initWithBrowser:browser + overlayableContentsController_.reset( + [[OverlayableContentsController alloc] initWithBrowser:browser windowController:self]); - [[previewableContentsController_ view] + [[overlayableContentsController_ view] setFrame:[[devToolsController_ view] bounds]]; [[devToolsController_ view] - addSubview:[previewableContentsController_ view]]; + addSubview:[overlayableContentsController_ view]]; // Create a controller for the tab strip, giving it the model object for // this window's Browser and the tab strip view. The controller will handle @@ -517,8 +515,8 @@ enum { return floatingBarBackingView_; } -- (PreviewableContentsController*)previewableContentsController { - return previewableContentsController_; +- (OverlayableContentsController*)overlayableContentsController { + return overlayableContentsController_; } - (Profile*)profile { @@ -1200,7 +1198,7 @@ enum { // StatusBubble delegate method: tell the status bubble the frame it should // position itself in. - (NSRect)statusBubbleBaseFrame { - NSView* view = [previewableContentsController_ view]; + NSView* view = [overlayableContentsController_ view]; return [view convertRect:[view bounds] toView:nil]; } @@ -1580,7 +1578,7 @@ enum { [infoBarContainerController_ changeWebContents:contents]; - [previewableContentsController_ onActivateTabWithContents:contents]; + [overlayableContentsController_ onActivateTabWithContents:contents]; } - (void)onTabChanged:(TabStripModelObserver::TabChangeType)change @@ -1934,7 +1932,7 @@ willAnimateFromState:(BookmarkBar::State)oldState // The view's bounds are in its own coordinate system. Convert that to the // window base coordinate system, then translate it into the screen's // coordinate system. - NSView* view = [previewableContentsController_ view]; + NSView* view = [overlayableContentsController_ view]; if (!view) return NSZeroRect; @@ -1957,7 +1955,7 @@ willAnimateFromState:(BookmarkBar::State)oldState [sheet orderOut:self]; } -- (void)updateBookmarkBarStateForInstantPreview { +- (void)updateBookmarkBarStateForInstantOverlay { [toolbarController_ setDividerOpacity:[self toolbarDividerOpacity]]; [self updateContentOffsets]; [self updateSubviewZOrder:[self inPresentationMode]]; diff --git a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm index ce50f3e..a4a084d 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_browsertest.mm @@ -21,7 +21,7 @@ #import "chrome/browser/ui/cocoa/fast_resize_view.h" #import "chrome/browser/ui/cocoa/infobars/infobar_container_controller.h" #import "chrome/browser/ui/cocoa/nsview_additions.h" -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" #include "chrome/browser/ui/search/search.h" #include "chrome/browser/ui/search/search_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h" @@ -254,7 +254,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, EXPECT_LT(NSMaxX(fullscreen_frame), NSMinX(avatar_frame)); } -// Verify that in non-instant normal mode that the find bar and download shelf +// Verify that in non-Instant normal mode that the find bar and download shelf // are above the content area. Everything else should be below it. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) { browser()->GetFindBarController(); // add find bar @@ -269,7 +269,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormal) { VerifyZOrder(view_list); } -// Verify that in non-instant presentation mode that the info bar is below the +// Verify that in non-Instant presentation mode that the info bar is below the // content are and everything else is above it. // DISABLED due to flaky failures on trybots. http://crbug.com/178778 IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, @@ -288,7 +288,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, VerifyZOrder(view_list); } -// Normal mode with instant results showing. Should be same z-order as normal +// Normal mode with Instant results showing. Should be same z-order as normal // mode except find bar is below content area. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) { ShowInstantResults(); @@ -304,8 +304,8 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderNormalInstant) { VerifyZOrder(view_list); } -// Presentation mode with instant results showing. Should be exact same as -// non-instant presentation mode. +// Presentation mode with Instant results showing. Should be exact same as +// non-Instant presentation mode. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ZOrderInstantPresentationMode) { chrome::ToggleFullscreenMode(browser()); @@ -347,106 +347,106 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, VerifyZOrder(view_list); } -// Verify that in non-instant presentation mode the content area is beneath +// Verify that in non-Instant presentation mode the content area is beneath // the bookmark bar and info bar. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffset) { - PreviewableContentsController* preview = - [controller() previewableContentsController]; + OverlayableContentsController* overlay = + [controller() overlayableContentsController]; // Just toolbar. - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus bookmark bar. browser()->window()->ToggleBookmarkBar(); EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), - [preview activeContainerOffset]); + [overlay activeContainerOffset]); // Plus info bar. ShowInfoBar(); EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + GetViewHeight(VIEW_ID_INFO_BAR), - [preview activeContainerOffset]); + [overlay activeContainerOffset]); // Minus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [overlay activeContainerOffset]); } -// Verify that in non-instant presentation mode the content area is beneath +// Verify that in non-Instant presentation mode the content area is beneath // the info bar. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetPresentationMode) { chrome::ToggleFullscreenMode(browser()); - PreviewableContentsController* preview = - [controller() previewableContentsController]; + OverlayableContentsController* overlay = + [controller() overlayableContentsController]; // Just toolbar. - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus info bar. ShowInfoBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Minus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); } -// Verify that when showing instant results the content area overlaps the +// Verify that when showing Instant results the content area overlaps the // bookmark bar and info bar. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstant) { ShowInstantResults(); - PreviewableContentsController* preview = - [controller() previewableContentsController]; + OverlayableContentsController* overlay = + [controller() overlayableContentsController]; // Just toolbar. - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus info bar. ShowInfoBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Minus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); } -// The instant NTP case is same as normal case except that the preview is +// The Instant NTP case is same as normal case except that the overlay is // also shifted down. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, ContentOffsetInstantNPT) { ShowInstantNTP(); - PreviewableContentsController* preview = - [controller() previewableContentsController]; + OverlayableContentsController* overlay = + [controller() overlayableContentsController]; // Just toolbar. - EXPECT_EQ(0, [preview activeContainerOffset]); + EXPECT_EQ(0, [overlay activeContainerOffset]); // Plus bookmark bar. browser()->window()->ToggleBookmarkBar(); EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR), - [preview activeContainerOffset]); + [overlay activeContainerOffset]); // Plus info bar. ShowInfoBar(); EXPECT_EQ(GetViewHeight(VIEW_ID_BOOKMARK_BAR) + GetViewHeight(VIEW_ID_INFO_BAR), - [preview activeContainerOffset]); + [overlay activeContainerOffset]); // Minus bookmark bar. browser()->window()->ToggleBookmarkBar(); - EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [preview activeContainerOffset]); + EXPECT_EQ(GetViewHeight(VIEW_ID_INFO_BAR), [overlay activeContainerOffset]); } -// Verify that if bookmark bar is underneath instant search results then -// clicking on instant search results still works. +// Verify that if bookmark bar is underneath Instant search results then +// clicking on Instant search results still works. IN_PROC_BROWSER_TEST_F(BrowserWindowControllerTest, InstantSearchResultsHitTest) { browser()->window()->ToggleBookmarkBar(); diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.h b/chrome/browser/ui/cocoa/browser_window_controller_private.h index fd06534..b021ee4 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_private.h +++ b/chrome/browser/ui/cocoa/browser_window_controller_private.h @@ -7,7 +7,6 @@ #import "chrome/browser/ui/cocoa/browser_window_controller.h" - // Private methods for the |BrowserWindowController|. This category should // contain the private methods used by different parts of the BWC; private // methods used only by single parts should be declared in their own file. @@ -147,10 +146,10 @@ // The opacity for the toolbar divider; 0 means that it shouldn't be shown. - (CGFloat)toolbarDividerOpacity; -// Returns YES if instant results are being shown under the omnibox. +// Returns YES if Instant results are being shown under the omnibox. - (BOOL)isShowingInstantResults; -// Updates the content offets of the tab strip controller and the previewable +// Updates the content offets of the tab strip controller and the overlayable // contents controller. This is used to adjust the overlap between those views // and the bookmark bar. - (void)updateContentOffsets; diff --git a/chrome/browser/ui/cocoa/browser_window_controller_private.mm b/chrome/browser/ui/cocoa/browser_window_controller_private.mm index 5b658c7..a1090de 100644 --- a/chrome/browser/ui/cocoa/browser_window_controller_private.mm +++ b/chrome/browser/ui/cocoa/browser_window_controller_private.mm @@ -28,7 +28,7 @@ #import "chrome/browser/ui/cocoa/nsview_additions.h" #import "chrome/browser/ui/cocoa/presentation_mode_controller.h" #import "chrome/browser/ui/cocoa/status_bubble_mac.h" -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_controller.h" #import "chrome/browser/ui/cocoa/tabs/tab_strip_view.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" @@ -69,11 +69,11 @@ const CGFloat kLocBarBottomInset = 1; // Create the tab strip controller. - (void)createTabStripController { - DCHECK([previewableContentsController_ activeContainer]); - DCHECK([[previewableContentsController_ activeContainer] window]); + DCHECK([overlayableContentsController_ activeContainer]); + DCHECK([[overlayableContentsController_ activeContainer] window]); tabStripController_.reset([[TabStripController alloc] initWithView:[self tabStripView] - switchView:[previewableContentsController_ activeContainer] + switchView:[overlayableContentsController_ activeContainer] browser:browser_.get() delegate:self]); } @@ -880,9 +880,9 @@ willPositionSheet:(NSWindow*)sheet if (!browser_->search_model()->mode().is_search_suggestions()) return NO; - // If the search suggestions are already being displayed in the preview + // If the search suggestions are already being displayed in the overlay // contents then return YES. - if ([previewableContentsController_ isShowingPreview]) + if ([overlayableContentsController_ isShowingOverlay]) return YES; // Search suggestions might be shown directly in the web contents in some @@ -893,14 +893,14 @@ willPositionSheet:(NSWindow*)sheet - (void)updateContentOffsets { // Normally the tab contents sits below the bookmark bar. This is achieved by // setting the offset to the height of the bookmark bar. The only exception - // is on the search results page where the instant results are shown inside - // the page and not in the preview contents as usual. + // is on the search results page where the Instant results are shown inside + // the page and not in the overlay contents as usual. CGFloat tabContentsOffset = toolbarToWebContentsOffset_; if (browser_->search_model()->mode().is_search_suggestions() && !browser_->search_model()->mode().is_origin_default()) { tabContentsOffset = 0; } - [previewableContentsController_ setActiveContainerOffset:tabContentsOffset]; + [overlayableContentsController_ setActiveContainerOffset:tabContentsOffset]; // Prevent the fast resize view from drawing white over the bookmark bar. [[self tabContentArea] setContentOffset:toolbarToWebContentsOffset_]; @@ -932,7 +932,7 @@ willPositionSheet:(NSWindow*)sheet } // The bookmark bar is always below the toolbar. In normal mode this means - // that it is below tab contents. This allows instant results to be above + // that it is below tab contents. This allows Instant results to be above // the bookmark bar. [contentView cr_ensureSubview:[bookmarkBarController_ view] isPositioned:NSWindowBelow @@ -945,13 +945,13 @@ willPositionSheet:(NSWindow*)sheet relativeTo:[self tabContentArea]]; } else { // Above the toolbar but still below tab contents. Similar to the bookmark - // bar, this allows instant results to be above the info bar. + // bar, this allows Instant results to be above the info bar. [contentView cr_ensureSubview:[infoBarContainerController_ view] isPositioned:NSWindowAbove relativeTo:toolbarView]; } - // The find bar is above everything except instant search results. + // The find bar is above everything except Instant search results. if (findBarCocoaController_) { NSView* relativeView = nil; if (inPresentationMode) diff --git a/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h b/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h new file mode 100644 index 0000000..d989b31 --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h @@ -0,0 +1,33 @@ +// Copyright 2012 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_UI_COCOA_TAB_CONTENTS_INSTANT_OVERLAY_CONTROLLER_MAC_H_ +#define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_INSTANT_OVERLAY_CONTROLLER_MAC_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/instant/instant_overlay_controller.h" + +class Browser; +@class BrowserWindowController; +@class OverlayableContentsController; + +class InstantOverlayControllerMac : public InstantOverlayController { + public: + InstantOverlayControllerMac(Browser* browser, + BrowserWindowController* window, + OverlayableContentsController* overlay); + virtual ~InstantOverlayControllerMac(); + + private: + // Overridden from InstantOverlayController: + virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; + + BrowserWindowController* const window_; + OverlayableContentsController* const overlay_; + + DISALLOW_COPY_AND_ASSIGN(InstantOverlayControllerMac); +}; + +#endif // CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_INSTANT_OVERLAY_CONTROLLER_MAC_H_ diff --git a/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.mm b/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.mm new file mode 100644 index 0000000..059b05d --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.mm @@ -0,0 +1,43 @@ +// Copyright 2012 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. + +#include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" +#include "chrome/browser/instant/instant_overlay_model.h" +#include "chrome/browser/ui/browser.h" +#import "chrome/browser/ui/cocoa/browser_window_controller.h" +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" + +InstantOverlayControllerMac::InstantOverlayControllerMac( + Browser* browser, + BrowserWindowController* window, + OverlayableContentsController* overlay) + : InstantOverlayController(browser), + window_(window), + overlay_(overlay) { +} + +InstantOverlayControllerMac::~InstantOverlayControllerMac() { +} + +void InstantOverlayControllerMac::OverlayStateChanged( + const InstantOverlayModel& model) { + if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { + // Drop shadow is only needed if search mode is not |NTP| and overlay does + // not fill up the entire contents page. + BOOL drawDropShadow = !model.mode().is_ntp() && + !(model.height() == 100 && + model.height_units() == INSTANT_SIZE_PERCENT); + [overlay_ setOverlay:model.GetOverlayContents() + height:model.height() + heightUnits:model.height_units() + drawDropShadow:drawDropShadow]; + } else { + [overlay_ setOverlay:NULL + height:0 + heightUnits:INSTANT_SIZE_PIXELS + drawDropShadow:NO]; + } + browser_->MaybeUpdateBookmarkBarStateForInstantOverlay(model.mode()); + [window_ updateBookmarkBarStateForInstantOverlay]; +} diff --git a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h b/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h deleted file mode 100644 index 69a0bb4..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h +++ /dev/null @@ -1,33 +0,0 @@ -// Copyright 2012 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_UI_COCOA_TAB_CONTENTS_INSTANT_PREVIEW_CONTROLLER_MAC_H_ -#define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_INSTANT_PREVIEW_CONTROLLER_MAC_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chrome/browser/instant/instant_preview_controller.h" - -class Browser; -@class BrowserWindowController; -@class PreviewableContentsController; - -class InstantPreviewControllerMac : public InstantPreviewController { - public: - InstantPreviewControllerMac(Browser* browser, - BrowserWindowController* window, - PreviewableContentsController* preview); - virtual ~InstantPreviewControllerMac(); - - private: - // Overridden from InstantPreviewController: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; - - BrowserWindowController* const window_; - PreviewableContentsController* const preview_; - - DISALLOW_COPY_AND_ASSIGN(InstantPreviewControllerMac); -}; - -#endif // CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_INSTANT_PREVIEW_CONTROLLER_MAC_H_ diff --git a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm b/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm deleted file mode 100644 index 356178d..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.mm +++ /dev/null @@ -1,44 +0,0 @@ -// Copyright 2012 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. - -#include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" - -#include "chrome/browser/instant/instant_model.h" -#include "chrome/browser/ui/browser.h" -#import "chrome/browser/ui/cocoa/browser_window_controller.h" -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" - -InstantPreviewControllerMac::InstantPreviewControllerMac( - Browser* browser, - BrowserWindowController* window, - PreviewableContentsController* preview) - : InstantPreviewController(browser), - window_(window), - preview_(preview) { -} - -InstantPreviewControllerMac::~InstantPreviewControllerMac() { -} - -void InstantPreviewControllerMac::PreviewStateChanged( - const InstantModel& model) { - if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { - // Drop shadow is only needed if search mode is not |NTP| and preview does - // not fill up the entire contents page. - BOOL drawDropShadow = !model.mode().is_ntp() && - !(model.height() == 100 && - model.height_units() == INSTANT_SIZE_PERCENT); - [preview_ setPreview:model.GetPreviewContents() - height:model.height() - heightUnits:model.height_units() - drawDropShadow:drawDropShadow]; - } else { - [preview_ setPreview:NULL - height:0 - heightUnits:INSTANT_SIZE_PIXELS - drawDropShadow:NO]; - } - browser_->MaybeUpdateBookmarkBarStateForInstantPreview(model.mode()); - [window_ updateBookmarkBarStateForInstantPreview]; -} diff --git a/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h new file mode 100644 index 0000000..48a3987 --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h @@ -0,0 +1,13 @@ +// Copyright 2013 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. + +#import + +// A view used to draw a drop shadow beneath the Instant overlay view. +@interface OverlayDropShadowView : NSView { +} + ++ (CGFloat)preferredHeight; + +@end diff --git a/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.mm b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.mm new file mode 100644 index 0000000..b3b92ef --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.mm @@ -0,0 +1,32 @@ +// Copyright 2013 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. + +#import "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" + +#include "grit/theme_resources.h" +#include "ui/base/resource/resource_bundle.h" + +@implementation OverlayDropShadowView + ++ (CGFloat)preferredHeight { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + NSImage* shadowImage = + rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); + return [shadowImage size].height; +} + +- (void)drawRect:(NSRect)rect { + ResourceBundle& rb = ResourceBundle::GetSharedInstance(); + NSRect bounds = [self bounds]; + + // Draw the shadow. + NSImage* shadowImage = + rb.GetNativeImageNamed(IDR_OVERLAY_DROP_SHADOW).ToNSImage(); + [shadowImage drawInRect:bounds + fromRect:NSZeroRect + operation:NSCompositeSourceOver + fraction:1.0]; +} + +@end diff --git a/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view_unittest.mm b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view_unittest.mm new file mode 100644 index 0000000..7240bfe --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view_unittest.mm @@ -0,0 +1,27 @@ +// Copyright 2013 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. + +#import "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" + +#include "base/memory/scoped_nsobject.h" +#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" + +class OverlayDropShadowViewTest : public CocoaTest { + public: + OverlayDropShadowViewTest() { + NSView* contentView = [test_window() contentView]; + view_.reset( + [[OverlayDropShadowView alloc] initWithFrame:[contentView bounds]]); + [contentView addSubview:view_]; + } + + protected: + scoped_nsobject view_; +}; + +TEST_VIEW(OverlayDropShadowViewTest, view_); + +TEST_F(OverlayDropShadowViewTest, PreferredHeight) { + EXPECT_LT(0, [OverlayDropShadowView preferredHeight]); +} diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h new file mode 100644 index 0000000..773b594 --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h @@ -0,0 +1,92 @@ +// Copyright 2012 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_UI_COCOA_TAB_CONTENTS_OVERLAYABLE_CONTENTS_CONTROLLER_H_ +#define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_OVERLAYABLE_CONTENTS_CONTROLLER_H_ + +#import + +#include "base/memory/scoped_nsobject.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/common/instant_types.h" + +class Browser; +@class BrowserWindowController; +class InstantOverlayControllerMac; + +namespace content { +class WebContents; +} + +// OverlayableContentsController manages the display of up to two tab contents +// views. It is primarily for use with Instant results. This class supports the +// notion of an "active" view vs. an "overlay" tab contents view. +// +// The "active" view is a container view that can be retrieved using +// |-activeContainer|. Its contents are meant to be managed by an external +// class. +// +// The "overlay" can be set using |-showOverlay:| and |-hideOverlay|. When an +// overlay is set, the active view is hidden (but stays in the view hierarchy). +// When the overlay is removed, the active view is reshown. +@interface OverlayableContentsController : NSViewController { + @private + // Container view for the "active" contents. + scoped_nsobject activeContainer_; + + // The overlay WebContents. Will be NULL if no overlay is currently showing. + content::WebContents* overlayContents_; // weak + + // C++ bridge to the Instant model change interface. + scoped_ptr instantOverlayController_; + + // The desired height of the overlay and units. + CGFloat overlayHeight_; + InstantSizeUnits overlayHeightUnits_; + + // If true then a shadow is drawn below the overlay. This is used to make the + // overlay "float" over the tab's web contents. + BOOL drawDropShadow_; + + // View responsible for drawing a drop shadow. + scoped_nsobject dropShadowView_; + + BrowserWindowController* windowController_; + + // The vertical offset between the top of the view and the active container. + // This is used to push the active container below the bookmark bar. Normally + // this is set to the height of the bookmark bar so that the bookmark bar is + // not obscured. + CGFloat activeContainerOffset_; +} + +@property(readonly, nonatomic) NSView* activeContainer; +@property(readonly, nonatomic) NSView* dropShadowView; +@property(readonly, nonatomic) BOOL drawDropShadow; +@property(assign, nonatomic) CGFloat activeContainerOffset; + +// Initialization. +- (id)initWithBrowser:(Browser*)browser + windowController:(BrowserWindowController*)windowController; + +// Sets the current overlay and installs its WebContentsView into the view +// hierarchy. Hides the active view. If |overlay| is NULL then closes the +// current overlay and shows the active view. +- (void)setOverlay:(content::WebContents*)overlay + height:(CGFloat)height + heightUnits:(InstantSizeUnits)heightUnits + drawDropShadow:(BOOL)drawDropShadow; + +// Called when a tab with |contents| is activated, so that we can check to see +// if it's the overlay being activated (and adjust internal state accordingly). +- (void)onActivateTabWithContents:(content::WebContents*)contents; + +// Returns YES if the overlay contents is currently showing. +- (BOOL)isShowingOverlay; + +- (InstantOverlayControllerMac*)instantOverlayController; + +@end + +#endif // CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_OVERLAYABLE_CONTENTS_CONTROLLER_H_ diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm new file mode 100644 index 0000000..ab18211 --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.mm @@ -0,0 +1,180 @@ +// Copyright 2011 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. + +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" + +#include "base/mac/bundle_locations.h" +#include "chrome/browser/ui/cocoa/browser_window_controller.h" +#include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" +#include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_view.h" + +@interface OverlayableContentsController() +- (void)viewDidResize:(NSNotification*)note; +- (void)layoutViews; +- (CGFloat)overlayHeightInPixels; +@end + +@implementation OverlayableContentsController + +@synthesize drawDropShadow = drawDropShadow_; +@synthesize activeContainerOffset = activeContainerOffset_; + +- (id)initWithBrowser:(Browser*)browser + windowController:(BrowserWindowController*)windowController { + if ((self = [super init])) { + windowController_ = windowController; + scoped_nsobject view([[NSView alloc] initWithFrame:NSZeroRect]); + [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; + [view setAutoresizesSubviews:NO]; + [[NSNotificationCenter defaultCenter] + addObserver:self + selector:@selector(viewDidResize:) + name:NSViewFrameDidChangeNotification + object:view]; + [self setView:view]; + + activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); + [view addSubview:activeContainer_]; + + instantOverlayController_.reset( + new InstantOverlayControllerMac(browser, windowController, self)); + } + return self; +} + +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + +- (void)setOverlay:(content::WebContents*)overlay + height:(CGFloat)height + heightUnits:(InstantSizeUnits)heightUnits + drawDropShadow:(BOOL)drawDropShadow { + // If drawing drop shadow, clip the bottom 1-px-thick separator out of + // overlay. + // TODO(sail): remove this when GWS gives chrome the height without the + // separator. + if (drawDropShadow && heightUnits != INSTANT_SIZE_PERCENT) + --height; + + if (overlayContents_ == overlay && + overlayHeight_ == height && + overlayHeightUnits_ == heightUnits && + drawDropShadow_ == drawDropShadow) { + return; + } + + // Remove any old overlay contents before showing the new one. + if (overlayContents_) { + [overlayContents_->GetView()->GetNativeView() removeFromSuperview]; + overlayContents_->WasHidden(); + } + + overlayContents_ = overlay; + overlayHeight_ = height; + overlayHeightUnits_ = heightUnits; + drawDropShadow_ = drawDropShadow; + + // Add the overlay contents. + if (overlayContents_) { + [[[self view] window] disableScreenUpdatesUntilFlush]; + overlayContents_->GetView()->SetAllowOverlappingViews(true); + [[self view] addSubview:overlayContents_->GetView()->GetNativeView()]; + } + + if (drawDropShadow_) { + if (!dropShadowView_) { + dropShadowView_.reset( + [[OverlayDropShadowView alloc] initWithFrame:NSZeroRect]); + [[self view] addSubview:dropShadowView_]; + } + } else { + [dropShadowView_ removeFromSuperview]; + dropShadowView_.reset(); + } + + [self layoutViews]; + + if (overlayContents_) + overlayContents_->WasShown(); +} + +- (void)onActivateTabWithContents:(content::WebContents*)contents { + if (overlayContents_ == contents) { + if (overlayContents_) { + [overlayContents_->GetView()->GetNativeView() removeFromSuperview]; + overlayContents_ = NULL; + } + [self setOverlay:NULL + height:0 + heightUnits:INSTANT_SIZE_PIXELS + drawDropShadow:NO]; + } +} + +- (BOOL)isShowingOverlay { + return overlayContents_ != nil; +} + +- (InstantOverlayControllerMac*)instantOverlayController { + return instantOverlayController_.get(); +} + +- (NSView*)activeContainer { + return activeContainer_.get(); +} + +- (NSView*)dropShadowView { + return dropShadowView_.get(); +} + +- (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { + if (activeContainerOffset_ == activeContainerOffset) + return; + + activeContainerOffset_ = activeContainerOffset; + [self layoutViews]; +} + +- (void)viewDidResize:(NSNotification*)note { + [self layoutViews]; +} + +- (void)layoutViews { + NSRect bounds = [[self view] bounds]; + + if (overlayContents_) { + NSRect overlayFrame = bounds; + overlayFrame.size.height = [self overlayHeightInPixels]; + overlayFrame.origin.y = NSMaxY(bounds) - NSHeight(overlayFrame); + [overlayContents_->GetView()->GetNativeView() setFrame:overlayFrame]; + + if (dropShadowView_) { + NSRect dropShadowFrame = bounds; + dropShadowFrame.size.height = [OverlayDropShadowView preferredHeight]; + dropShadowFrame.origin.y = + NSMinY(overlayFrame) - NSHeight(dropShadowFrame); + [dropShadowView_ setFrame:dropShadowFrame]; + } + } + + NSRect activeFrame = bounds; + activeFrame.size.height -= activeContainerOffset_; + [activeContainer_ setFrame:activeFrame]; +} + +- (CGFloat)overlayHeightInPixels { + CGFloat height = NSHeight([[self view] bounds]); + switch (overlayHeightUnits_) { + case INSTANT_SIZE_PERCENT: + return std::min(height, (height * overlayHeight_) / 100); + case INSTANT_SIZE_PIXELS: + return std::min(height, overlayHeight_); + } +} + +@end diff --git a/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm new file mode 100644 index 0000000..11c2711 --- /dev/null +++ b/chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller_browsertest.mm @@ -0,0 +1,144 @@ +// Copyright 2012 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. + +#import "chrome/browser/ui/cocoa/tab_contents/overlayable_contents_controller.h" + +#include "chrome/browser/instant/instant_overlay_model.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/browser_window.h" +#include "chrome/browser/ui/cocoa/browser_window_controller.h" +#include "chrome/browser/ui/cocoa/tab_contents/instant_overlay_controller_mac.h" +#include "chrome/browser/ui/cocoa/tab_contents/overlay_drop_shadow_view.h" +#include "chrome/test/base/in_process_browser_test.h" +#include "content/public/browser/web_contents.h" +#include "content/public/browser/web_contents_view.h" +#import "testing/gtest_mac.h" + +class OverlayableContentsControllerTest : public InProcessBrowserTest { + public: + OverlayableContentsControllerTest() : instant_overlay_model_(NULL) { + } + + virtual void SetUpOnMainThread() OVERRIDE { + web_contents_.reset(content::WebContents::Create( + content::WebContents::CreateParams(browser()->profile()))); + instant_overlay_model_.SetOverlayContents(web_contents_.get()); + + controller_.reset([[OverlayableContentsController alloc] + initWithBrowser:browser() + windowController:nil]); + [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)]; + instant_overlay_model_.AddObserver([controller_ instantOverlayController]); + } + + virtual void CleanUpOnMainThread() OVERRIDE { + instant_overlay_model_.RemoveObserver( + [controller_ instantOverlayController]); + instant_overlay_model_.SetOverlayContents(NULL); + controller_.reset(); + web_contents_.reset(); + } + + void VerifyOverlayFrame(CGFloat expected_height, + InstantSizeUnits units) { + NSRect container_bounds = [[controller_ view] bounds]; + NSRect overlay_frame = + [web_contents_->GetView()->GetNativeView() frame]; + + EXPECT_EQ(NSMinX(container_bounds), NSMinX(overlay_frame)); + EXPECT_EQ(NSWidth(container_bounds), NSWidth(overlay_frame)); + switch (units) { + case INSTANT_SIZE_PIXELS: + EXPECT_EQ(expected_height, NSHeight(overlay_frame)); + EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame)); + break; + case INSTANT_SIZE_PERCENT: + EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100, + NSHeight(overlay_frame)); + EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(overlay_frame)); + } + } + + protected: + InstantOverlayModel instant_overlay_model_; + scoped_ptr web_contents_; + scoped_nsobject controller_; +}; + +// Verify that the view is correctly laid out when size is specified in percent. +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePerecent) { + chrome::search::Mode mode; + mode.mode = chrome::search::Mode::MODE_NTP; + CGFloat expected_height = 30; + InstantSizeUnits units = INSTANT_SIZE_PERCENT; + instant_overlay_model_.SetOverlayState(mode, expected_height, units); + + EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], + [controller_ view]); + VerifyOverlayFrame(expected_height, units); + + // Resize the view and verify that the overlay is also resized. + [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; + VerifyOverlayFrame(expected_height, units); +} + +// Verify that the view is correctly laid out when size is specified in pixels. +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, SizePixels) { + chrome::search::Mode mode; + mode.mode = chrome::search::Mode::MODE_NTP; + CGFloat expected_height = 30; + InstantSizeUnits units = INSTANT_SIZE_PIXELS; + instant_overlay_model_.SetOverlayState(mode, expected_height, units); + + EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], + [controller_ view]); + VerifyOverlayFrame(expected_height, units); + + // Resize the view and verify that the overlay is also resized. + [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; + VerifyOverlayFrame(expected_height, units); +} + +// Verify that a shadow is not shown when the overlay covers the entire page +// or when the overlay is in NTP mode. +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowFullHeight) { + chrome::search::Mode mode; + mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; + instant_overlay_model_.SetOverlayState(mode, 100, INSTANT_SIZE_PERCENT); + EXPECT_FALSE([controller_ dropShadowView]); + EXPECT_FALSE([controller_ drawDropShadow]); + + mode.mode = chrome::search::Mode::MODE_NTP; + instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); + EXPECT_FALSE([controller_ dropShadowView]); + EXPECT_FALSE([controller_ drawDropShadow]); +} + +// Verify that a shadow is shown when the overlay is in search mode. +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, NoShadowNTP) { + chrome::search::Mode mode; + mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; + instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); + EXPECT_TRUE([controller_ dropShadowView]); + EXPECT_TRUE([controller_ drawDropShadow]); + EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]); + + NSRect dropShadowFrame = [[controller_ dropShadowView] frame]; + NSRect controllerBounds = [[controller_ view] bounds]; + EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame)); + EXPECT_EQ([OverlayDropShadowView preferredHeight], + NSHeight(dropShadowFrame)); +} + +// Verify that the shadow is hidden when hiding the overlay. +IN_PROC_BROWSER_TEST_F(OverlayableContentsControllerTest, HideShadow) { + chrome::search::Mode mode; + mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; + instant_overlay_model_.SetOverlayState(mode, 10, INSTANT_SIZE_PERCENT); + EXPECT_TRUE([controller_ dropShadowView]); + + [controller_ onActivateTabWithContents:web_contents_.get()]; + EXPECT_FALSE([controller_ dropShadowView]); +} diff --git a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h b/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h deleted file mode 100644 index d2922c7..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h +++ /dev/null @@ -1,13 +0,0 @@ -// Copyright 2013 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. - -#import - -// A view used to draw a drop shadow beneath the instant preview view. -@interface PreviewDropShadowView : NSView { -} - -+ (CGFloat)preferredHeight; - -@end diff --git a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.mm b/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.mm deleted file mode 100644 index 505a1c0..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.mm +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright 2013 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. - -#import "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" - -#include "grit/theme_resources.h" -#include "ui/base/resource/resource_bundle.h" - -@implementation PreviewDropShadowView - -+ (CGFloat)preferredHeight { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - NSImage* shadowImage = - rb.GetNativeImageNamed(IDR_PREVIEW_DROP_SHADOW).ToNSImage(); - return [shadowImage size].height; -} - -- (void)drawRect:(NSRect)rect { - ResourceBundle& rb = ResourceBundle::GetSharedInstance(); - NSRect bounds = [self bounds]; - - // Draw the shadow. - NSImage* shadowImage = - rb.GetNativeImageNamed(IDR_PREVIEW_DROP_SHADOW).ToNSImage(); - [shadowImage drawInRect:bounds - fromRect:NSZeroRect - operation:NSCompositeSourceOver - fraction:1.0]; -} - -@end diff --git a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view_unittest.mm b/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view_unittest.mm deleted file mode 100644 index 8173375..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view_unittest.mm +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 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. - -#import "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" - -#include "base/memory/scoped_nsobject.h" -#import "chrome/browser/ui/cocoa/cocoa_test_helper.h" - -class PreviewDropShadowViewTest : public CocoaTest { - public: - PreviewDropShadowViewTest() { - NSView* contentView = [test_window() contentView]; - view_.reset( - [[PreviewDropShadowView alloc] initWithFrame:[contentView bounds]]); - [contentView addSubview:view_]; - } - - protected: - scoped_nsobject view_; -}; - -TEST_VIEW(PreviewDropShadowViewTest, view_); - -TEST_F(PreviewDropShadowViewTest, PreferredHeight) { - EXPECT_LT(0, [PreviewDropShadowView preferredHeight]); -} diff --git a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h deleted file mode 100644 index edf243c..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright 2012 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_UI_COCOA_TAB_CONTENTS_PREVIEWABLE_CONTENTS_CONTROLLER_H_ -#define CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_PREVIEWABLE_CONTENTS_CONTROLLER_H_ - -#import - -#include "base/memory/scoped_nsobject.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/common/instant_types.h" - -class Browser; -@class BrowserWindowController; -class InstantPreviewControllerMac; - -namespace content { -class WebContents; -} - -// PreviewableContentsController manages the display of up to two tab contents -// views. It is primarily for use with Instant results. This class supports -// the notion of an "active" view vs. a "preview" tab contents view. -// -// The "active" view is a container view that can be retrieved using -// |-activeContainer|. Its contents are meant to be managed by an external -// class. -// -// The "preview" can be set using |-showPreview:| and |-hidePreview|. When a -// preview is set, the active view is hidden (but stays in the view hierarchy). -// When the preview is removed, the active view is reshown. -@interface PreviewableContentsController : NSViewController { - @private - // Container view for the "active" contents. - scoped_nsobject activeContainer_; - - // The preview WebContents. Will be NULL if no preview is currently showing. - content::WebContents* previewContents_; // weak - - // C++ bridge to the Instant model change interface. - scoped_ptr instantPreviewController_; - - // The desired height of the preview and units. - CGFloat previewHeight_; - InstantSizeUnits previewHeightUnits_; - - // If true then a shadow is drawn below the preview. This is used to make - // instant omnibox "float" over the tab's web contents. - BOOL drawDropShadow_; - - // View responsible for drawing a drop shadow. - scoped_nsobject dropShadowView_; - - BrowserWindowController* windowController_; - - // The vertical offset between the top of the view and the active container. - // This is used to push the active container below the bookmark bar. Normally - // this is set to the height of the bookmark bar so that the bookmark bar is - // not obscured. - CGFloat activeContainerOffset_; -} - -@property(readonly, nonatomic) NSView* activeContainer; -@property(readonly, nonatomic) NSView* dropShadowView; -@property(readonly, nonatomic) BOOL drawDropShadow; -@property(assign, nonatomic) CGFloat activeContainerOffset; - -// Initialization. -- (id)initWithBrowser:(Browser*)browser - windowController:(BrowserWindowController*)windowController; - -// Sets the current preview and installs its WebContentsView into the view -// hierarchy. Hides the active view. If |preview| is NULL then closes the -// current preview and shows the active view. -- (void)setPreview:(content::WebContents*)preview - height:(CGFloat)height - heightUnits:(InstantSizeUnits)heightUnits - drawDropShadow:(BOOL)drawDropShadow; - -// Called when a tab with |contents| is activated, so that we can check to see -// if it's the preview being activated (and adjust internal state accordingly). -- (void)onActivateTabWithContents:(content::WebContents*)contents; - -// Returns YES if the preview contents is currently showing. -- (BOOL)isShowingPreview; - -- (InstantPreviewControllerMac*)instantPreviewController; - -@end - -#endif // CHROME_BROWSER_UI_COCOA_TAB_CONTENTS_PREVIEWABLE_CONTENTS_CONTROLLER_H_ diff --git a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm deleted file mode 100644 index 7cae329..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.mm +++ /dev/null @@ -1,180 +0,0 @@ -// Copyright 2011 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. - -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" - -#include "base/mac/bundle_locations.h" -#include "chrome/browser/ui/cocoa/browser_window_controller.h" -#include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" -#include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" - -@interface PreviewableContentsController() -- (void)viewDidResize:(NSNotification*)note; -- (void)layoutViews; -- (CGFloat)previewHeightInPixels; -@end - -@implementation PreviewableContentsController - -@synthesize drawDropShadow = drawDropShadow_; -@synthesize activeContainerOffset = activeContainerOffset_; - -- (id)initWithBrowser:(Browser*)browser - windowController:(BrowserWindowController*)windowController { - if ((self = [super init])) { - windowController_ = windowController; - scoped_nsobject view([[NSView alloc] initWithFrame:NSZeroRect]); - [view setAutoresizingMask:NSViewHeightSizable | NSViewWidthSizable]; - [view setAutoresizesSubviews:NO]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(viewDidResize:) - name:NSViewFrameDidChangeNotification - object:view]; - [self setView:view]; - - activeContainer_.reset([[NSView alloc] initWithFrame:NSZeroRect]); - [view addSubview:activeContainer_]; - - instantPreviewController_.reset( - new InstantPreviewControllerMac(browser, windowController, self)); - } - return self; -} - -- (void)dealloc { - [[NSNotificationCenter defaultCenter] removeObserver:self]; - [super dealloc]; -} - -- (void)setPreview:(content::WebContents*)preview - height:(CGFloat)height - heightUnits:(InstantSizeUnits)heightUnits - drawDropShadow:(BOOL)drawDropShadow { - // If drawing drop shadow, clip the bottom 1-px-thick separator out of - // preview. - // TODO(sail): remove this when GWS gives chrome the height without the - // separator. - if (drawDropShadow && heightUnits != INSTANT_SIZE_PERCENT) - --height; - - if (previewContents_ == preview && - previewHeight_ == height && - previewHeightUnits_ == heightUnits && - drawDropShadow_ == drawDropShadow) { - return; - } - - // Remove any old preview contents before showing the new one. - if (previewContents_) { - [previewContents_->GetView()->GetNativeView() removeFromSuperview]; - previewContents_->WasHidden(); - } - - previewContents_ = preview; - previewHeight_ = height; - previewHeightUnits_ = heightUnits; - drawDropShadow_ = drawDropShadow; - - // Add the preview contents. - if (previewContents_) { - [[[self view] window] disableScreenUpdatesUntilFlush]; - previewContents_->GetView()->SetAllowOverlappingViews(true); - [[self view] addSubview:previewContents_->GetView()->GetNativeView()]; - } - - if (drawDropShadow_) { - if (!dropShadowView_) { - dropShadowView_.reset( - [[PreviewDropShadowView alloc] initWithFrame:NSZeroRect]); - [[self view] addSubview:dropShadowView_]; - } - } else { - [dropShadowView_ removeFromSuperview]; - dropShadowView_.reset(); - } - - [self layoutViews]; - - if (previewContents_) - previewContents_->WasShown(); -} - -- (void)onActivateTabWithContents:(content::WebContents*)contents { - if (previewContents_ == contents) { - if (previewContents_) { - [previewContents_->GetView()->GetNativeView() removeFromSuperview]; - previewContents_ = NULL; - } - [self setPreview:NULL - height:0 - heightUnits:INSTANT_SIZE_PIXELS - drawDropShadow:NO]; - } -} - -- (BOOL)isShowingPreview { - return previewContents_ != nil; -} - -- (InstantPreviewControllerMac*)instantPreviewController { - return instantPreviewController_.get(); -} - -- (NSView*)activeContainer { - return activeContainer_.get(); -} - -- (NSView*)dropShadowView { - return dropShadowView_.get(); -} - -- (void)setActiveContainerOffset:(CGFloat)activeContainerOffset { - if (activeContainerOffset_ == activeContainerOffset) - return; - - activeContainerOffset_ = activeContainerOffset; - [self layoutViews]; -} - -- (void)viewDidResize:(NSNotification*)note { - [self layoutViews]; -} - -- (void)layoutViews { - NSRect bounds = [[self view] bounds]; - - if (previewContents_) { - NSRect previewFrame = bounds; - previewFrame.size.height = [self previewHeightInPixels]; - previewFrame.origin.y = NSMaxY(bounds) - NSHeight(previewFrame); - [previewContents_->GetView()->GetNativeView() setFrame:previewFrame]; - - if (dropShadowView_) { - NSRect dropShadowFrame = bounds; - dropShadowFrame.size.height = [PreviewDropShadowView preferredHeight]; - dropShadowFrame.origin.y = - NSMinY(previewFrame) - NSHeight(dropShadowFrame); - [dropShadowView_ setFrame:dropShadowFrame]; - } - } - - NSRect activeFrame = bounds; - activeFrame.size.height -= activeContainerOffset_; - [activeContainer_ setFrame:activeFrame]; -} - -- (CGFloat)previewHeightInPixels { - CGFloat height = NSHeight([[self view] bounds]); - switch (previewHeightUnits_) { - case INSTANT_SIZE_PERCENT: - return std::min(height, (height * previewHeight_) / 100); - case INSTANT_SIZE_PIXELS: - return std::min(height, previewHeight_); - } -} - -@end diff --git a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller_browsertest.mm b/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller_browsertest.mm deleted file mode 100644 index 7273d96..0000000 --- a/chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller_browsertest.mm +++ /dev/null @@ -1,143 +0,0 @@ -// Copyright 2012 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. - -#import "chrome/browser/ui/cocoa/tab_contents/previewable_contents_controller.h" - -#include "chrome/browser/instant/instant_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/browser_window.h" -#include "chrome/browser/ui/cocoa/browser_window_controller.h" -#include "chrome/browser/ui/cocoa/tab_contents/instant_preview_controller_mac.h" -#include "chrome/browser/ui/cocoa/tab_contents/preview_drop_shadow_view.h" -#include "chrome/test/base/in_process_browser_test.h" -#include "content/public/browser/web_contents.h" -#include "content/public/browser/web_contents_view.h" -#import "testing/gtest_mac.h" - -class PreviewableContentsControllerTest : public InProcessBrowserTest { - public: - PreviewableContentsControllerTest() : instant_model_(NULL) { - } - - virtual void SetUpOnMainThread() OVERRIDE { - web_contents_.reset(content::WebContents::Create( - content::WebContents::CreateParams(browser()->profile()))); - instant_model_.SetPreviewContents(web_contents_.get()); - - controller_.reset([[PreviewableContentsController alloc] - initWithBrowser:browser() - windowController:nil]); - [[controller_ view] setFrame:NSMakeRect(0, 0, 100, 200)]; - instant_model_.AddObserver([controller_ instantPreviewController]); - } - - virtual void CleanUpOnMainThread() OVERRIDE { - instant_model_.RemoveObserver([controller_ instantPreviewController]); - instant_model_.SetPreviewContents(NULL); - controller_.reset(); - web_contents_.reset(); - } - - void VerifyPreviewFrame(CGFloat expected_height, - InstantSizeUnits units) { - NSRect container_bounds = [[controller_ view] bounds]; - NSRect preview_frame = - [web_contents_->GetView()->GetNativeView() frame]; - - EXPECT_EQ(NSMinX(container_bounds), NSMinX(preview_frame)); - EXPECT_EQ(NSWidth(container_bounds), NSWidth(preview_frame)); - switch (units) { - case INSTANT_SIZE_PIXELS: - EXPECT_EQ(expected_height, NSHeight(preview_frame)); - EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); - break; - case INSTANT_SIZE_PERCENT: - EXPECT_EQ((expected_height * NSHeight(container_bounds)) / 100, - NSHeight(preview_frame)); - EXPECT_EQ(NSMaxY(container_bounds), NSMaxY(preview_frame)); - } - } - - protected: - InstantModel instant_model_; - scoped_ptr web_contents_; - scoped_nsobject controller_; -}; - -// Verify that the view is correctly laid out when size is specified in percent. -IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePerecent) { - chrome::search::Mode mode; - mode.mode = chrome::search::Mode::MODE_NTP; - CGFloat expected_height = 30; - InstantSizeUnits units = INSTANT_SIZE_PERCENT; - instant_model_.SetPreviewState(mode, expected_height, units); - - EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], - [controller_ view]); - VerifyPreviewFrame(expected_height, units); - - // Resize the view and verify that the preview is also resized. - [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; - VerifyPreviewFrame(expected_height, units); -} - -// Verify that the view is correctly laid out when size is specified in pixels. -IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, SizePixels) { - chrome::search::Mode mode; - mode.mode = chrome::search::Mode::MODE_NTP; - CGFloat expected_height = 30; - InstantSizeUnits units = INSTANT_SIZE_PIXELS; - instant_model_.SetPreviewState(mode, expected_height, units); - - EXPECT_NSEQ([web_contents_->GetView()->GetNativeView() superview], - [controller_ view]); - VerifyPreviewFrame(expected_height, units); - - // Resize the view and verify that the preview is also resized. - [[controller_ view] setFrameSize:NSMakeSize(300, 400)]; - VerifyPreviewFrame(expected_height, units); -} - -// Verify that a shadow is not shown when the preview covers the entire page -// or when the preview is in NTP mode. -IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, NoShadowFullHeight) { - chrome::search::Mode mode; - mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; - instant_model_.SetPreviewState(mode, 100, INSTANT_SIZE_PERCENT); - EXPECT_FALSE([controller_ dropShadowView]); - EXPECT_FALSE([controller_ drawDropShadow]); - - mode.mode = chrome::search::Mode::MODE_NTP; - instant_model_.SetPreviewState(mode, 10, INSTANT_SIZE_PERCENT); - EXPECT_FALSE([controller_ dropShadowView]); - EXPECT_FALSE([controller_ drawDropShadow]); -} - -// Verify that a shadow is shown when the preview is in search mode. -IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, NoShadowNTP) { - chrome::search::Mode mode; - mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; - instant_model_.SetPreviewState(mode, 10, INSTANT_SIZE_PERCENT); - EXPECT_TRUE([controller_ dropShadowView]); - EXPECT_TRUE([controller_ drawDropShadow]); - EXPECT_NSEQ([controller_ view], [[controller_ dropShadowView] superview]); - - NSRect dropShadowFrame = [[controller_ dropShadowView] frame]; - NSRect controllerBounds = [[controller_ view] bounds]; - EXPECT_EQ(NSWidth(controllerBounds), NSWidth(dropShadowFrame)); - EXPECT_EQ([PreviewDropShadowView preferredHeight], - NSHeight(dropShadowFrame)); -} - -// Verify that the shadow is hidden when hiding the preview. -IN_PROC_BROWSER_TEST_F(PreviewableContentsControllerTest, HideShadow) { - chrome::search::Mode mode; - mode.mode = chrome::search::Mode::MODE_SEARCH_SUGGESTIONS; - instant_model_.SetPreviewState(mode, 10, INSTANT_SIZE_PERCENT); - EXPECT_TRUE([controller_ dropShadowView]); - - [controller_ onActivateTabWithContents:web_contents_.get()]; - EXPECT_FALSE([controller_ dropShadowView]); -} diff --git a/chrome/browser/ui/gtk/browser_window_gtk.cc b/chrome/browser/ui/gtk/browser_window_gtk.cc index d120d84..63c6941 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.cc +++ b/chrome/browser/ui/gtk/browser_window_gtk.cc @@ -64,7 +64,7 @@ #include "chrome/browser/ui/gtk/gtk_window_util.h" #include "chrome/browser/ui/gtk/infobars/infobar_container_gtk.h" #include "chrome/browser/ui/gtk/infobars/infobar_gtk.h" -#include "chrome/browser/ui/gtk/instant_preview_controller_gtk.h" +#include "chrome/browser/ui/gtk/instant_overlay_controller_gtk.h" #include "chrome/browser/ui/gtk/location_bar_view_gtk.h" #include "chrome/browser/ui/gtk/nine_box.h" #include "chrome/browser/ui/gtk/one_click_signin_bubble_gtk.h" @@ -1664,8 +1664,8 @@ void BrowserWindowGtk::InitWidgets() { gtk_box_pack_end(GTK_BOX(window_vbox_), render_area_event_box_, TRUE, TRUE, 0); - instant_preview_controller_.reset( - new InstantPreviewControllerGtk(this, contents_container_.get())); + instant_overlay_controller_.reset( + new InstantOverlayControllerGtk(this, contents_container_.get())); if (IsBookmarkBarSupported()) { bookmark_bar_.reset(new BookmarkBarGtk(this, @@ -1909,7 +1909,7 @@ void BrowserWindowGtk::MaybeShowBookmarkBar(bool animate) { bookmark_bar_->SetPageNavigator(browser_.get()); BookmarkBar::State state = browser_->bookmark_bar_state(); - if (contents_container_->HasPreview() && state == BookmarkBar::DETACHED) + if (contents_container_->HasOverlay() && state == BookmarkBar::DETACHED) state = BookmarkBar::HIDDEN; toolbar_->UpdateForBookmarkBarVisibility(state == BookmarkBar::DETACHED); diff --git a/chrome/browser/ui/gtk/browser_window_gtk.h b/chrome/browser/ui/gtk/browser_window_gtk.h index d227e23..494b573 100644 --- a/chrome/browser/ui/gtk/browser_window_gtk.h +++ b/chrome/browser/ui/gtk/browser_window_gtk.h @@ -38,7 +38,7 @@ class FindBarGtk; class FullscreenExitBubbleGtk; class GlobalMenuBar; class InfoBarContainerGtk; -class InstantPreviewControllerGtk; +class InstantOverlayControllerGtk; class LocationBar; class PrefRegistrySyncable; class StatusBubbleGtk; @@ -509,8 +509,8 @@ class BrowserWindowGtk // selected tab contents. scoped_ptr devtools_container_; - // A sub-controller that manages the Instant preview visual state. - scoped_ptr instant_preview_controller_; + // A sub-controller that manages the Instant overlay visual state. + scoped_ptr instant_overlay_controller_; // The Extension Keybinding Registry responsible for registering listeners for // accelerators that are sent to the window, that are destined to be turned diff --git a/chrome/browser/ui/gtk/instant_overlay_controller_gtk.cc b/chrome/browser/ui/gtk/instant_overlay_controller_gtk.cc new file mode 100644 index 0000000..95f1d75 --- /dev/null +++ b/chrome/browser/ui/gtk/instant_overlay_controller_gtk.cc @@ -0,0 +1,31 @@ +// Copyright 2012 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. + +#include "chrome/browser/ui/gtk/instant_overlay_controller_gtk.h" + +#include "chrome/browser/instant/instant_overlay_model.h" +#include "chrome/browser/ui/gtk/browser_window_gtk.h" +#include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" + +InstantOverlayControllerGtk::InstantOverlayControllerGtk( + BrowserWindowGtk* window, + TabContentsContainerGtk* contents) + : InstantOverlayController(window->browser()), + window_(window), + contents_(contents) { +} + +InstantOverlayControllerGtk::~InstantOverlayControllerGtk() { +} + +void InstantOverlayControllerGtk::OverlayStateChanged( + const InstantOverlayModel& model) { + if (model.mode().is_search_suggestions()) { + // TODO(jered): Support non-100% height. + contents_->SetOverlay(model.GetOverlayContents()); + } else { + contents_->SetOverlay(NULL); + } + window_->MaybeShowBookmarkBar(false); +} diff --git a/chrome/browser/ui/gtk/instant_overlay_controller_gtk.h b/chrome/browser/ui/gtk/instant_overlay_controller_gtk.h new file mode 100644 index 0000000..771746b --- /dev/null +++ b/chrome/browser/ui/gtk/instant_overlay_controller_gtk.h @@ -0,0 +1,31 @@ +// Copyright 2012 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_UI_GTK_INSTANT_OVERLAY_CONTROLLER_GTK_H_ +#define CHROME_BROWSER_UI_GTK_INSTANT_OVERLAY_CONTROLLER_GTK_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "chrome/browser/instant/instant_overlay_controller.h" + +class BrowserWindowGtk; +class TabContentsContainerGtk; + +class InstantOverlayControllerGtk : public InstantOverlayController { + public: + InstantOverlayControllerGtk(BrowserWindowGtk* window, + TabContentsContainerGtk* contents); + virtual ~InstantOverlayControllerGtk(); + + private: + // Overridden from InstantOverlayController: + virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; + + BrowserWindowGtk* const window_; + TabContentsContainerGtk* const contents_; + + DISALLOW_COPY_AND_ASSIGN(InstantOverlayControllerGtk); +}; + +#endif // CHROME_BROWSER_UI_GTK_INSTANT_OVERLAY_CONTROLLER_GTK_H_ diff --git a/chrome/browser/ui/gtk/instant_preview_controller_gtk.cc b/chrome/browser/ui/gtk/instant_preview_controller_gtk.cc deleted file mode 100644 index 21e6a6d..0000000 --- a/chrome/browser/ui/gtk/instant_preview_controller_gtk.cc +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2012 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. - -#include "chrome/browser/ui/gtk/instant_preview_controller_gtk.h" - -#include "chrome/browser/instant/instant_model.h" -#include "chrome/browser/ui/gtk/browser_window_gtk.h" -#include "chrome/browser/ui/gtk/tab_contents_container_gtk.h" - -InstantPreviewControllerGtk::InstantPreviewControllerGtk( - BrowserWindowGtk* window, - TabContentsContainerGtk* contents) - : InstantPreviewController(window->browser()), - window_(window), - contents_(contents) { -} - -InstantPreviewControllerGtk::~InstantPreviewControllerGtk() { -} - -void InstantPreviewControllerGtk::PreviewStateChanged( - const InstantModel& model) { - if (model.mode().is_search_suggestions()) { - // TODO(jered): Support non-100% height. - contents_->SetPreview(model.GetPreviewContents()); - } else { - contents_->SetPreview(NULL); - } - window_->MaybeShowBookmarkBar(false); -} diff --git a/chrome/browser/ui/gtk/instant_preview_controller_gtk.h b/chrome/browser/ui/gtk/instant_preview_controller_gtk.h deleted file mode 100644 index f0fb71a..0000000 --- a/chrome/browser/ui/gtk/instant_preview_controller_gtk.h +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright 2012 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_UI_GTK_INSTANT_PREVIEW_CONTROLLER_GTK_H_ -#define CHROME_BROWSER_UI_GTK_INSTANT_PREVIEW_CONTROLLER_GTK_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "chrome/browser/instant/instant_preview_controller.h" - -class BrowserWindowGtk; -class TabContentsContainerGtk; - -class InstantPreviewControllerGtk : public InstantPreviewController { - public: - InstantPreviewControllerGtk(BrowserWindowGtk* window, - TabContentsContainerGtk* contents); - virtual ~InstantPreviewControllerGtk(); - - private: - // Overridden from InstantPreviewController: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; - - BrowserWindowGtk* const window_; - TabContentsContainerGtk* const contents_; - - DISALLOW_COPY_AND_ASSIGN(InstantPreviewControllerGtk); -}; - -#endif // CHROME_BROWSER_UI_GTK_INSTANT_PREVIEW_CONTROLLER_GTK_H_ diff --git a/chrome/browser/ui/gtk/tab_contents_container_gtk.cc b/chrome/browser/ui/gtk/tab_contents_container_gtk.cc index a8b5c5c..1927fc5 100644 --- a/chrome/browser/ui/gtk/tab_contents_container_gtk.cc +++ b/chrome/browser/ui/gtk/tab_contents_container_gtk.cc @@ -19,7 +19,7 @@ TabContentsContainerGtk::TabContentsContainerGtk(StatusBubbleGtk* status_bubble) : tab_(NULL), - preview_(NULL), + overlay_(NULL), status_bubble_(status_bubble) { Init(); } @@ -72,10 +72,10 @@ void TabContentsContainerGtk::SetTab(content::WebContents* tab) { tab_ = tab; if (tab_) { - // If the preview is becoming the new permanent tab, we just reassign some + // If the overlay is becoming the new permanent tab, we just reassign some // pointers. Otherwise, we have to actually add it to the widget hierarchy. - if (tab_ == preview_) - preview_ = NULL; + if (tab_ == overlay_) + overlay_ = NULL; else PackTab(tab_); @@ -90,21 +90,21 @@ void TabContentsContainerGtk::SetTab(content::WebContents* tab) { } } -void TabContentsContainerGtk::SetPreview(content::WebContents* preview) { - if (preview_ == preview) +void TabContentsContainerGtk::SetOverlay(content::WebContents* overlay) { + if (overlay_ == overlay) return; - if (preview_) { - HideTab(preview_); - GtkWidget* preview_widget = preview_->GetView()->GetNativeView(); - if (preview_widget) - gtk_container_remove(GTK_CONTAINER(expanded_), preview_widget); + if (overlay_) { + HideTab(overlay_); + GtkWidget* overlay_widget = overlay_->GetView()->GetNativeView(); + if (overlay_widget) + gtk_container_remove(GTK_CONTAINER(expanded_), overlay_widget); } - preview_ = preview; + overlay_ = overlay; - if (preview_) - PackTab(preview_); + if (overlay_) + PackTab(overlay_); } void TabContentsContainerGtk::PackTab(content::WebContents* tab) { @@ -156,25 +156,25 @@ void TabContentsContainerGtk::WebContentsDestroyed( content::WebContents* contents) { // Sometimes, a WebContents is destroyed before we know about it. This allows // us to clean up our state in case this happens. - if (contents == preview_) - SetPreview(NULL); + if (contents == overlay_) + SetOverlay(NULL); else if (contents == tab_) SetTab(NULL); else NOTREACHED(); } -// Prevent |preview_| from getting focus via the tab key. If |tab_| exists, try +// Prevent |overlay_| from getting focus via the tab key. If |tab_| exists, try // to focus that. Otherwise, do nothing, but stop event propagation. See bug // http://crbug.com/63365 gboolean TabContentsContainerGtk::OnFocus(GtkWidget* widget, GtkDirectionType focus) { - if (preview_) { + if (overlay_) { gtk_widget_child_focus(tab_->GetView()->GetContentNativeView(), focus); return TRUE; } - // No preview contents; let the default handler run. + // No overlay contents; let the default handler run. return FALSE; } diff --git a/chrome/browser/ui/gtk/tab_contents_container_gtk.h b/chrome/browser/ui/gtk/tab_contents_container_gtk.h index 9b8cd79..13d647d 100644 --- a/chrome/browser/ui/gtk/tab_contents_container_gtk.h +++ b/chrome/browser/ui/gtk/tab_contents_container_gtk.h @@ -35,12 +35,12 @@ class TabContentsContainerGtk : public content::NotificationObserver, void SetTab(content::WebContents* tab); content::WebContents* tab() const { return tab_; } - void SetPreview(content::WebContents* preview); - bool HasPreview() const { return preview_ != NULL; } + void SetOverlay(content::WebContents* overlay); + bool HasOverlay() const { return overlay_ != NULL; } // Returns the WebContents currently displayed. content::WebContents* GetVisibleTab() const { - return preview_ ? preview_ : tab_; + return overlay_ ? overlay_ : tab_; } // Remove the tab from the hierarchy. @@ -75,19 +75,19 @@ class TabContentsContainerGtk : public content::NotificationObserver, void HideTab(content::WebContents* tab); // Handle focus traversal on the tab contents container. Focus should not - // traverse to the preview contents. + // traverse to the overlay contents. CHROMEGTK_CALLBACK_1(TabContentsContainerGtk, gboolean, OnFocus, GtkDirectionType); content::NotificationRegistrar registrar_; // The WebContents for the currently selected tab. This will be showing - // unless there is a preview contents. + // unless there is an overlay contents. content::WebContents* tab_; - // The current preview contents (for instant). If non-NULL, it will be + // The current overlay contents (for Instant). If non-NULL, it will be // visible. - content::WebContents* preview_; + content::WebContents* overlay_; // The status bubble manager. Always non-NULL. StatusBubbleGtk* status_bubble_; diff --git a/chrome/browser/ui/views/frame/browser_view.cc b/chrome/browser/ui/views/frame/browser_view.cc index f440dfc..960d642 100644 --- a/chrome/browser/ui/views/frame/browser_view.cc +++ b/chrome/browser/ui/views/frame/browser_view.cc @@ -39,7 +39,6 @@ #include "chrome/browser/ui/browser_commands.h" #include "chrome/browser/ui/browser_dialogs.h" #include "chrome/browser/ui/browser_finder.h" -#include "chrome/browser/ui/browser_instant_controller.h" #include "chrome/browser/ui/browser_list.h" #include "chrome/browser/ui/browser_window_state.h" #include "chrome/browser/ui/ntp_background_util.h" @@ -63,7 +62,7 @@ #include "chrome/browser/ui/views/download/download_shelf_view.h" #include "chrome/browser/ui/views/frame/browser_view_layout.h" #include "chrome/browser/ui/views/frame/contents_container.h" -#include "chrome/browser/ui/views/frame/instant_preview_controller_views.h" +#include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" #include "chrome/browser/ui/views/fullscreen_exit_bubble_views.h" #include "chrome/browser/ui/views/immersive_mode_controller.h" #include "chrome/browser/ui/views/infobars/infobar_container_view.h" @@ -478,7 +477,7 @@ BrowserView::~BrowserView() { // Immersive mode may need to reparent views before they are removed/deleted. immersive_mode_controller_.reset(); - preview_controller_.reset(); + overlay_controller_.reset(); browser_->tab_strip_model()->RemoveObserver(this); @@ -792,7 +791,6 @@ void BrowserView::UpdateDevTools() { Layout(); } - void BrowserView::UpdateLoadingAnimations(bool should_animate) { if (should_animate) { if (!loading_animation_timer_.IsRunning()) { @@ -1303,8 +1301,8 @@ int BrowserView::GetExtraRenderViewHeight() const { void BrowserView::WebContentsFocused(WebContents* contents) { if (contents_container_->GetWebContents() == contents) contents_container_->OnWebContentsFocused(contents); - else if (contents_->preview_web_contents() == contents) - preview_controller_->preview()->OnWebContentsFocused(contents); + else if (contents_->overlay_web_contents() == contents) + overlay_controller_->overlay()->OnWebContentsFocused(contents); else devtools_container_->OnWebContentsFocused(contents); } @@ -1447,7 +1445,7 @@ void BrowserView::Paste() { } gfx::Rect BrowserView::GetInstantBounds() { - return contents_->GetPreviewBounds(); + return contents_->GetOverlayBounds(); } WindowOpenDisposition BrowserView::GetDispositionForPopupBounds( @@ -1518,11 +1516,11 @@ void BrowserView::ActiveTabChanged(content::WebContents* old_contents, bool user_gesture) { DCHECK(new_contents); - // See if the Instant preview is being activated (committed). - if (contents_->preview_web_contents() == new_contents) { - contents_->MakePreviewContentsActiveContents(); + // See if the Instant overlay is being activated (committed). + if (contents_->overlay_web_contents() == new_contents) { + contents_->MakeOverlayContentsActiveContents(); views::WebView* old_container = contents_container_; - contents_container_ = preview_controller_->release_preview(); + contents_container_ = overlay_controller_->release_overlay(); old_container->SetWebContents(NULL); delete old_container; } @@ -1557,7 +1555,7 @@ void BrowserView::ActiveTabChanged(content::WebContents* old_contents, if (change_tab_contents) { contents_container_->SetWebContents(new_contents); - contents_->MaybeStackPreviewAtTop(); + contents_->MaybeStackOverlayAtTop(); } if (!browser_->tab_strip_model()->closing_all() && GetWidget()->IsActive() && @@ -1570,7 +1568,7 @@ void BrowserView::ActiveTabChanged(content::WebContents* old_contents, // Update all the UI bits. UpdateTitleBar(); - // Like the preview layer and the bookmark bar layer, the immersive mode + // Like the overlay layer and the bookmark bar layer, the immersive mode // reveal view's layer may need to live above the web contents. MaybeStackImmersiveRevealAtTop(); @@ -2070,8 +2068,8 @@ void BrowserView::Init() { AddChildViewAt(toolbar_, kToolbarIndex); toolbar_->Init(); - preview_controller_.reset( - new InstantPreviewControllerViews(browser(), contents_)); + overlay_controller_.reset( + new InstantOverlayControllerViews(browser(), contents_)); SkColor bg_color = GetWidget()->GetThemeProvider()-> GetColor(ThemeProperties::COLOR_TOOLBAR); diff --git a/chrome/browser/ui/views/frame/browser_view.h b/chrome/browser/ui/views/frame/browser_view.h index dedbba1..c09214f 100644 --- a/chrome/browser/ui/views/frame/browser_view.h +++ b/chrome/browser/ui/views/frame/browser_view.h @@ -47,7 +47,7 @@ class DownloadShelfView; class FullscreenExitBubbleViews; class ImmersiveModeController; class InfoBarContainerView; -class InstantPreviewControllerViews; +class InstantOverlayControllerViews; class LocationBarView; class StatusBubbleViews; class SearchViewController; @@ -619,7 +619,7 @@ class BrowserView : public BrowserWindow, // | | Page content (contents_) | | // | | +------------------------------------------------------+ | | // | | | contents_container_ and/or | | | - // | | | preview_controller_->preview_container_ | | | + // | | | overlay_controller_->overlay_container_ | | | // | | | | | | // | | | | | | // | | +------------------------------------------------------+ | | @@ -638,7 +638,7 @@ class BrowserView : public BrowserWindow, // [2] The bookmark bar and info bar are swapped when on the new tab page. // Additionally contents_ is positioned on top of the bookmark bar when // the bookmark bar is detached. This is done to allow the - // preview_controller_->preview_container_ to appear over the bookmark + // overlay_controller_->overlay_container_ to appear over the bookmark // bar. // Tool/Info bars that we are currently showing. Used for layout. @@ -673,7 +673,7 @@ class BrowserView : public BrowserWindow, views::WebView* devtools_container_; // The view managing both the contents_container_ and - // preview_controller_->preview_container_. + // overlay_controller_->overlay_container_. ContentsContainer* contents_; // Split view containing the contents container and devtools container. @@ -752,7 +752,7 @@ class BrowserView : public BrowserWindow, gfx::ScopedSysColorChangeListener color_change_listener_; - scoped_ptr preview_controller_; + scoped_ptr overlay_controller_; mutable base::WeakPtrFactory activate_modal_dialog_factory_; diff --git a/chrome/browser/ui/views/frame/browser_view_layout.cc b/chrome/browser/ui/views/frame/browser_view_layout.cc index f47f782..c48602c 100644 --- a/chrome/browser/ui/views/frame/browser_view_layout.cc +++ b/chrome/browser/ui/views/frame/browser_view_layout.cc @@ -269,9 +269,9 @@ void BrowserViewLayout::Layout(views::View* host) { // contents to continue to display from that origin. const chrome::search::Mode& mode = browser()->search_model()->mode(); views::WebView* contents = browser_view_->contents_container_; - int preview_height = contents_container_->preview_height(); + int overlay_height = contents_container_->overlay_height(); gfx::Point old_contents_origin; - if (preview_height > 0 && mode.is_search_suggestions() && + if (overlay_height > 0 && mode.is_search_suggestions() && mode.is_origin_default()) { old_contents_origin = contents->bounds().origin(); views::View::ConvertPointToTarget(contents->parent(), browser_view_, @@ -314,7 +314,7 @@ void BrowserViewLayout::Layout(views::View* host) { // fully cover that gap, and leaving the contents at their original height // would leave an odd-looking blank space. In this case, we allow the // contents to go ahead and shift upward. - if (active_top_margin > 0 && active_top_margin < preview_height) + if (active_top_margin > 0 && active_top_margin < overlay_height) contents_container_->SetActiveTopMargin(active_top_margin); } diff --git a/chrome/browser/ui/views/frame/contents_container.cc b/chrome/browser/ui/views/frame/contents_container.cc index 5943a7d..815405c 100644 --- a/chrome/browser/ui/views/frame/contents_container.cc +++ b/chrome/browser/ui/views/frame/contents_container.cc @@ -15,33 +15,33 @@ const char ContentsContainer::kViewClassName[] = namespace { -int PreviewHeightInPixels(int parent_height, int preview_height, - InstantSizeUnits preview_height_units) { - preview_height = std::max(0, preview_height); - switch (preview_height_units) { +int OverlayHeightInPixels(int parent_height, int overlay_height, + InstantSizeUnits overlay_height_units) { + overlay_height = std::max(0, overlay_height); + switch (overlay_height_units) { case INSTANT_SIZE_PERCENT: - return std::min(parent_height, (parent_height * preview_height) / 100); + return std::min(parent_height, (parent_height * overlay_height) / 100); case INSTANT_SIZE_PIXELS: - return std::min(parent_height, preview_height); + return std::min(parent_height, overlay_height); } - NOTREACHED() << "unknown units: " << preview_height_units; + NOTREACHED() << "unknown units: " << overlay_height_units; return 0; } -// This class draws the drop shadow below the preview when the non-NTP preview +// This class draws the drop shadow below the overlay when the non-NTP overlay // doesn't fill up the entire content page. // This class is owned by ContentsContainer, which: // - adds it as child when shadow is needed -// - removes it as child when shadow is not needed or when preview is nuked or -// when preview is removed as child +// - removes it as child when shadow is not needed or when overlay is nuked or +// when overlay is removed as child // - always makes sure it's the 3rd child in the view hierarchy i.e. after -// active and preview. +// active and overlay. class ShadowView : public views::View { public: ShadowView() { drop_shadow_ = *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( - IDR_PREVIEW_DROP_SHADOW); + IDR_OVERLAY_DROP_SHADOW); SetPaintToLayer(true); SetFillsBoundsOpaquely(false); @@ -76,12 +76,12 @@ class ShadowView : public views::View { ContentsContainer::ContentsContainer(views::WebView* active) : active_(active), - preview_(NULL), - preview_web_contents_(NULL), + overlay_(NULL), + overlay_web_contents_(NULL), draw_drop_shadow_(false), active_top_margin_(0), - preview_height_(100), - preview_height_units_(INSTANT_SIZE_PERCENT) { + overlay_height_(100), + overlay_height_units_(INSTANT_SIZE_PERCENT) { AddChildView(active_); } @@ -89,29 +89,29 @@ ContentsContainer::~ContentsContainer() { RemoveShadowView(true); } -void ContentsContainer::MakePreviewContentsActiveContents() { - DCHECK(preview_); +void ContentsContainer::MakeOverlayContentsActiveContents() { + DCHECK(overlay_); - active_ = preview_; - preview_ = NULL; - preview_web_contents_ = NULL; - // Since |preview_| has been nuked, shadow view is not needed anymore. + active_ = overlay_; + overlay_ = NULL; + overlay_web_contents_ = NULL; + // Since |overlay_| has been nuked, shadow view is not needed anymore. // Note that the previous |active_| will be deleted by caller (see // BrowserView::ActiveTabChanged()) after this call, hence removing the old // |active_| as a child, and making the new |active_| (which is the previous - // |preview_|) the first child. + // |overlay_|) the first child. RemoveShadowView(true); Layout(); } -void ContentsContainer::SetPreview(views::WebView* preview, - content::WebContents* preview_web_contents, +void ContentsContainer::SetOverlay(views::WebView* overlay, + content::WebContents* overlay_web_contents, const chrome::search::Mode& search_mode, int height, InstantSizeUnits units, bool draw_drop_shadow) { // If drawing drop shadow, clip the bottom 1-px-thick separator out of - // preview. + // overlay. // TODO(kuan): remove this when GWS gives chrome the height without the // separator. #if !defined(OS_WIN) @@ -119,64 +119,64 @@ void ContentsContainer::SetPreview(views::WebView* preview, --height; #endif // !defined(OS_WIN) - if (preview_ == preview && preview_web_contents_ == preview_web_contents && - search_mode_ == search_mode && preview_height_ == height && - preview_height_units_ == units && draw_drop_shadow_ == draw_drop_shadow) { + if (overlay_ == overlay && overlay_web_contents_ == overlay_web_contents && + search_mode_ == search_mode && overlay_height_ == height && + overlay_height_units_ == units && draw_drop_shadow_ == draw_drop_shadow) { return; } - if (preview_ != preview) { - if (preview_) { + if (overlay_ != overlay) { + if (overlay_) { // Order of children is important: always |active_| first, then - // |preview_|, then shadow view if necessary. To make sure the next view - // is added in the right order, remove shadow view every time |preview_| + // |overlay_|, then shadow view if necessary. To make sure the next view + // is added in the right order, remove shadow view every time |overlay_| // is removed. RemoveShadowView(false); - RemoveChildView(preview_); + RemoveChildView(overlay_); } - preview_ = preview; - if (preview_) - AddChildView(preview_); + overlay_ = overlay; + if (overlay_) + AddChildView(overlay_); } - preview_web_contents_ = preview_web_contents; + overlay_web_contents_ = overlay_web_contents; search_mode_ = search_mode; - preview_height_ = height; - preview_height_units_ = units; + overlay_height_ = height; + overlay_height_units_ = units; draw_drop_shadow_ = draw_drop_shadow; - // Add shadow view if there's preview and drop shadow is needed. - // Remove shadow view if there's no preview. - // If there's preview and drop shadow is not needed, that means the partial- - // height preview is going to be full-height. Don't remove the shadow view - // yet because its layered view will disappear before the non-layered preview - // is repainted at the full height, leaving no separator between the preview - // and active contents. When the preview is repainted at the full height, the + // Add shadow view if there's overlay and drop shadow is needed. + // Remove shadow view if there's no overlay. + // If there's overlay and drop shadow is not needed, that means the partial- + // height overlay is going to be full-height. Don't remove the shadow view + // yet because its layered view will disappear before the non-layered overlay + // is repainted at the full height, leaving no separator between the overlay + // and active contents. When the overlay is repainted at the full height, the // shadow view, which remains at the original position below the partial- - // height preview, will automatically be obscured the full-height preview. - if (preview_ && draw_drop_shadow_) { + // height overlay, will automatically be obscured the full-height overlay. + if (overlay_ && draw_drop_shadow_) { #if !defined(OS_WIN) if (!shadow_view_.get()) // Shadow view has not been created. shadow_view_.reset(new ShadowView()); if (!shadow_view_->parent()) // Shadow view has not been added. AddChildView(shadow_view_.get()); #endif // !defined(OS_WIN) - } else if (!preview_) { + } else if (!overlay_) { RemoveShadowView(true); } Layout(); } -void ContentsContainer::MaybeStackPreviewAtTop() { - if (!preview_) +void ContentsContainer::MaybeStackOverlayAtTop() { + if (!overlay_) return; - // To force |preview_| to the topmost in the z-order, remove it, then add it + // To force |overlay_| to the topmost in the z-order, remove it, then add it // back. - // See comments in SetPreview() for why shadow view is removed. + // See comments in SetOverlay() for why shadow view is removed. bool removed_shadow = RemoveShadowView(false); - RemoveChildView(preview_); - AddChildView(preview_); + RemoveChildView(overlay_); + AddChildView(overlay_); if (removed_shadow) // Add back shadow view if it was removed. AddChildView(shadow_view_.get()); Layout(); @@ -192,17 +192,17 @@ void ContentsContainer::SetActiveTopMargin(int margin) { InvalidateLayout(); } -gfx::Rect ContentsContainer::GetPreviewBounds() const { +gfx::Rect ContentsContainer::GetOverlayBounds() const { gfx::Point screen_loc; ConvertPointToScreen(this, &screen_loc); return gfx::Rect(screen_loc, size()); } -bool ContentsContainer::IsPreviewFullHeight( - int preview_height, - InstantSizeUnits preview_height_units) const { - int height_in_pixels = PreviewHeightInPixels(height(), preview_height, - preview_height_units); +bool ContentsContainer::IsOverlayFullHeight( + int overlay_height, + InstantSizeUnits overlay_height_units) const { + int height_in_pixels = OverlayHeightInPixels(height(), overlay_height, + overlay_height_units); return height_in_pixels == height(); } @@ -212,14 +212,14 @@ void ContentsContainer::Layout() { active_->SetBounds(0, content_y, width(), content_height); - if (preview_) { - preview_->SetBounds(0, 0, width(), - PreviewHeightInPixels(height(), preview_height_, - preview_height_units_)); + if (overlay_) { + overlay_->SetBounds(0, 0, width(), + OverlayHeightInPixels(height(), overlay_height_, + overlay_height_units_)); if (draw_drop_shadow_) { #if !defined(OS_WIN) DCHECK(shadow_view_.get() && shadow_view_->parent()); - shadow_view_->SetBounds(0, preview_->bounds().height(), width(), + shadow_view_->SetBounds(0, overlay_->bounds().height(), width(), shadow_view_->GetPreferredSize().height()); #endif // !defined(OS_WIN) } diff --git a/chrome/browser/ui/views/frame/contents_container.h b/chrome/browser/ui/views/frame/contents_container.h index 49f17df..1d39027 100644 --- a/chrome/browser/ui/views/frame/contents_container.h +++ b/chrome/browser/ui/views/frame/contents_container.h @@ -33,28 +33,28 @@ class ContentsContainer : public views::View { explicit ContentsContainer(views::WebView* active); virtual ~ContentsContainer(); - // Makes the preview view the active view and nulls out the old active view. + // Makes the overlay view the active view and nulls out the old active view. // The caller must delete or remove the old active view separately. - void MakePreviewContentsActiveContents(); + void MakeOverlayContentsActiveContents(); - // Sets the preview view. This does not delete the old. - void SetPreview(views::WebView* preview, - content::WebContents* preview_web_contents, + // Sets the overlay view. This does not delete the old. + void SetOverlay(views::WebView* overlay, + content::WebContents* overlay_web_contents, const chrome::search::Mode& search_mode, int height, InstantSizeUnits units, bool draw_drop_shadow); - // When the active content is reset and we have a visible preview, - // the preview must be stacked back at top. - void MaybeStackPreviewAtTop(); + // When the active content is reset and we have a visible overlay, + // the overlay must be stacked back at top. + void MaybeStackOverlayAtTop(); - content::WebContents* preview_web_contents() const { - return preview_web_contents_; + content::WebContents* overlay_web_contents() const { + return overlay_web_contents_; } - int preview_height() const { - return preview_ ? preview_->bounds().height() : 0; + int overlay_height() const { + return overlay_ ? overlay_->bounds().height() : 0; } // Sets the active top margin; the active WebView's y origin would be @@ -62,12 +62,12 @@ class ContentsContainer : public views::View { // vertically by |margin| pixels in the |ContentsContainer|. void SetActiveTopMargin(int margin); - // Returns the bounds the preview would be shown at. - gfx::Rect GetPreviewBounds() const; + // Returns the bounds the overlay would be shown at. + gfx::Rect GetOverlayBounds() const; - // Returns true if preview occupies full height of content page. - bool IsPreviewFullHeight(int preview_height, - InstantSizeUnits preview_height_units) const; + // Returns true if overlay occupies full height of content page. + bool IsOverlayFullHeight(int overlay_height, + InstantSizeUnits overlay_height_units) const; private: // Returns true if |shadow_view_| was a child of |ContentsContainer| and @@ -81,19 +81,19 @@ class ContentsContainer : public views::View { virtual std::string GetClassName() const OVERRIDE; views::WebView* active_; - views::WebView* preview_; + views::WebView* overlay_; scoped_ptr shadow_view_; - content::WebContents* preview_web_contents_; + content::WebContents* overlay_web_contents_; chrome::search::Mode search_mode_; bool draw_drop_shadow_; // The margin between the top and the active view. This is used to make the - // preview overlap the bookmark bar on the new tab page. + // overlay overlap the bookmark bar on the new tab page. int active_top_margin_; - // The desired height of the preview and units. - int preview_height_; - InstantSizeUnits preview_height_units_; + // The desired height of the overlay and units. + int overlay_height_; + InstantSizeUnits overlay_height_units_; DISALLOW_COPY_AND_ASSIGN(ContentsContainer); }; diff --git a/chrome/browser/ui/views/frame/instant_overlay_controller_views.cc b/chrome/browser/ui/views/frame/instant_overlay_controller_views.cc new file mode 100644 index 0000000..ba6a35f --- /dev/null +++ b/chrome/browser/ui/views/frame/instant_overlay_controller_views.cc @@ -0,0 +1,63 @@ +// Copyright 2012 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. + +#include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" + +#include "chrome/browser/instant/instant_overlay_model.h" +#include "chrome/browser/profiles/profile.h" +#include "chrome/browser/ui/browser.h" +#include "chrome/browser/ui/view_ids.h" +#include "chrome/browser/ui/views/frame/browser_view.h" +#include "chrome/browser/ui/views/frame/contents_container.h" +#include "chrome/browser/ui/views/infobars/infobar_container_view.h" +#include "ui/views/controls/webview/webview.h" + +InstantOverlayControllerViews::InstantOverlayControllerViews( + Browser* browser, + ContentsContainer* contents) + : InstantOverlayController(browser), + contents_(contents) { +} + +InstantOverlayControllerViews::~InstantOverlayControllerViews() { +} + +void InstantOverlayControllerViews::OverlayStateChanged( + const InstantOverlayModel& model) { + if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { + // Show the overlay. + if (!overlay_) { + overlay_.reset(new views::WebView(browser_->profile())); + overlay_->set_id(VIEW_ID_TAB_CONTAINER); + } + // Drop shadow is only needed if search mode is not |NTP| and overlay does + // not fill up the entire contents page. + bool draw_drop_shadow = !model.mode().is_ntp() && + !(contents_->IsOverlayFullHeight(model.height(), model.height_units())); + content::WebContents* web_contents = model.GetOverlayContents(); + contents_->SetOverlay(overlay_.get(), web_contents, model.mode(), + model.height(), model.height_units(), + draw_drop_shadow); + overlay_->SetWebContents(web_contents); + } else if (overlay_) { + // Hide the overlay. SetWebContents() must happen before SetOverlay(). + overlay_->SetWebContents(NULL); + contents_->SetOverlay(NULL, NULL, model.mode(), 100, INSTANT_SIZE_PERCENT, + false); + overlay_.reset(); + } + + browser_->MaybeUpdateBookmarkBarStateForInstantOverlay(model.mode()); + + // If an Instant overlay is added during an immersive mode reveal, the reveal + // view needs to stay on top. + // Notify infobar container of change in overlay state. + if (overlay_) { + BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); + if (browser_view) { + browser_view->MaybeStackImmersiveRevealAtTop(); + browser_view->infobar_container()->OverlayStateChanged(model); + } + } +} diff --git a/chrome/browser/ui/views/frame/instant_overlay_controller_views.h b/chrome/browser/ui/views/frame/instant_overlay_controller_views.h new file mode 100644 index 0000000..f0c79f7 --- /dev/null +++ b/chrome/browser/ui/views/frame/instant_overlay_controller_views.h @@ -0,0 +1,46 @@ +// Copyright 2012 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_UI_VIEWS_FRAME_INSTANT_OVERLAY_CONTROLLER_VIEWS_H_ +#define CHROME_BROWSER_UI_VIEWS_FRAME_INSTANT_OVERLAY_CONTROLLER_VIEWS_H_ + +#include "base/basictypes.h" +#include "base/compiler_specific.h" +#include "base/memory/scoped_ptr.h" +#include "chrome/browser/instant/instant_overlay_controller.h" + +class Browser; +class ContentsContainer; + +namespace views { +class WebView; +} + +// A controller that manages the Views-specific Instant overlay. Its primary +// role is to respond to display-state changes from the Instant model and +// reflect this in the visibility and layout of the overlay. +class InstantOverlayControllerViews : public InstantOverlayController { + public: + InstantOverlayControllerViews(Browser* browser, ContentsContainer* contents); + virtual ~InstantOverlayControllerViews(); + + views::WebView* overlay() { return overlay_.get(); } + + views::WebView* release_overlay() WARN_UNUSED_RESULT { + return overlay_.release(); + } + + private: + // Overridden from InstantOverlayController: + virtual void OverlayStateChanged(const InstantOverlayModel& model) OVERRIDE; + + ContentsContainer* const contents_; + + // The view that contains the Instant overlay web contents. + scoped_ptr overlay_; + + DISALLOW_COPY_AND_ASSIGN(InstantOverlayControllerViews); +}; + +#endif // CHROME_BROWSER_UI_VIEWS_FRAME_INSTANT_OVERLAY_CONTROLLER_VIEWS_H_ diff --git a/chrome/browser/ui/views/frame/instant_preview_controller_views.cc b/chrome/browser/ui/views/frame/instant_preview_controller_views.cc deleted file mode 100644 index 742c4be..0000000 --- a/chrome/browser/ui/views/frame/instant_preview_controller_views.cc +++ /dev/null @@ -1,63 +0,0 @@ -// Copyright 2012 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. - -#include "chrome/browser/ui/views/frame/instant_preview_controller_views.h" - -#include "chrome/browser/instant/instant_model.h" -#include "chrome/browser/profiles/profile.h" -#include "chrome/browser/ui/browser.h" -#include "chrome/browser/ui/view_ids.h" -#include "chrome/browser/ui/views/frame/browser_view.h" -#include "chrome/browser/ui/views/frame/contents_container.h" -#include "chrome/browser/ui/views/infobars/infobar_container_view.h" -#include "ui/views/controls/webview/webview.h" - -InstantPreviewControllerViews::InstantPreviewControllerViews( - Browser* browser, - ContentsContainer* contents) - : InstantPreviewController(browser), - contents_(contents) { -} - -InstantPreviewControllerViews::~InstantPreviewControllerViews() { -} - -void InstantPreviewControllerViews::PreviewStateChanged( - const InstantModel& model) { - if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { - // Show the preview. - if (!preview_) { - preview_.reset(new views::WebView(browser_->profile())); - preview_->set_id(VIEW_ID_TAB_CONTAINER); - } - // Drop shadow is only needed if search mode is not |NTP| and preview does - // not fill up the entire contents page. - bool draw_drop_shadow = !model.mode().is_ntp() && - !(contents_->IsPreviewFullHeight(model.height(), model.height_units())); - content::WebContents* web_contents = model.GetPreviewContents(); - contents_->SetPreview(preview_.get(), web_contents, model.mode(), - model.height(), model.height_units(), - draw_drop_shadow); - preview_->SetWebContents(web_contents); - } else if (preview_) { - // Hide the preview. SetWebContents() must happen before SetPreview(). - preview_->SetWebContents(NULL); - contents_->SetPreview(NULL, NULL, model.mode(), 100, INSTANT_SIZE_PERCENT, - false); - preview_.reset(); - } - - browser_->MaybeUpdateBookmarkBarStateForInstantPreview(model.mode()); - - // If an instant preview is added during an immersive mode reveal, the reveal - // view needs to stay on top. - // Notify infobar container of change in preview state. - if (preview_) { - BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); - if (browser_view) { - browser_view->MaybeStackImmersiveRevealAtTop(); - browser_view->infobar_container()->PreviewStateChanged(model); - } - } -} diff --git a/chrome/browser/ui/views/frame/instant_preview_controller_views.h b/chrome/browser/ui/views/frame/instant_preview_controller_views.h deleted file mode 100644 index d80e5f2..0000000 --- a/chrome/browser/ui/views/frame/instant_preview_controller_views.h +++ /dev/null @@ -1,46 +0,0 @@ -// Copyright 2012 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_UI_VIEWS_FRAME_INSTANT_PREVIEW_CONTROLLER_VIEWS_H_ -#define CHROME_BROWSER_UI_VIEWS_FRAME_INSTANT_PREVIEW_CONTROLLER_VIEWS_H_ - -#include "base/basictypes.h" -#include "base/compiler_specific.h" -#include "base/memory/scoped_ptr.h" -#include "chrome/browser/instant/instant_preview_controller.h" - -class Browser; -class ContentsContainer; - -namespace views { -class WebView; -} - -// A controller that manages the Views-specific Instant preview. Its primary -// role is to respond to display-state changes from the Instant model and -// reflect this in the visibility and layout of the preview. -class InstantPreviewControllerViews : public InstantPreviewController { - public: - InstantPreviewControllerViews(Browser* browser, ContentsContainer* contents); - virtual ~InstantPreviewControllerViews(); - - views::WebView* preview() { return preview_.get(); } - - views::WebView* release_preview() WARN_UNUSED_RESULT { - return preview_.release(); - } - - private: - // Overridden from InstantPreviewController: - virtual void PreviewStateChanged(const InstantModel& model) OVERRIDE; - - ContentsContainer* const contents_; - - // The view that contains the Instant preview web contents. - scoped_ptr preview_; - - DISALLOW_COPY_AND_ASSIGN(InstantPreviewControllerViews); -}; - -#endif // CHROME_BROWSER_UI_VIEWS_FRAME_INSTANT_PREVIEW_CONTROLLER_VIEWS_H_ -- cgit v1.1