| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" | 5 #include "chrome/browser/ui/views/frame/instant_overlay_controller_views.h" |
| 6 | 6 |
| 7 #include "chrome/browser/profiles/profile.h" | 7 #include "chrome/browser/profiles/profile.h" |
| 8 #include "chrome/browser/search/search.h" |
| 8 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 9 #include "chrome/browser/ui/search/instant_overlay_model.h" | 10 #include "chrome/browser/ui/search/instant_overlay_model.h" |
| 11 #include "chrome/browser/ui/search/search_model.h" |
| 12 #include "chrome/browser/ui/search/search_tab_helper.h" |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 10 #include "chrome/browser/ui/view_ids.h" | 14 #include "chrome/browser/ui/view_ids.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 15 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/browser/ui/views/frame/contents_container.h" | 16 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 13 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 17 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 14 #include "ui/views/controls/webview/webview.h" | 18 #include "ui/views/controls/webview/webview.h" |
| 15 | 19 |
| 16 InstantOverlayControllerViews::InstantOverlayControllerViews( | 20 InstantOverlayControllerViews::InstantOverlayControllerViews( |
| 17 Browser* browser, | 21 Browser* browser, |
| 18 ContentsContainer* contents) | 22 ContentsContainer* contents) |
| 19 : InstantOverlayController(browser), | 23 : InstantOverlayController(browser), |
| 20 contents_(contents) { | 24 contents_(contents) { |
| 21 } | 25 } |
| 22 | 26 |
| 23 InstantOverlayControllerViews::~InstantOverlayControllerViews() { | 27 InstantOverlayControllerViews::~InstantOverlayControllerViews() { |
| 24 } | 28 } |
| 25 | 29 |
| 26 void InstantOverlayControllerViews::OverlayStateChanged( | 30 void InstantOverlayControllerViews::OverlayStateChanged( |
| 27 const InstantOverlayModel& model) { | 31 const InstantOverlayModel& model) { |
| 32 // Set top bars (bookmark and info bars) visibility if Instant Extended API |
| 33 // is enabled. |
| 34 bool set_top_bars_visibility = chrome::search::IsInstantExtendedAPIEnabled(); |
| 35 |
| 28 if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { | 36 if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { |
| 29 // Show the overlay. | 37 // Show the overlay. |
| 30 if (!overlay_) { | 38 if (!overlay_) { |
| 31 overlay_.reset(new views::WebView(browser_->profile())); | 39 overlay_.reset(new views::WebView(browser_->profile())); |
| 32 overlay_->set_id(VIEW_ID_TAB_CONTAINER); | 40 overlay_->set_id(VIEW_ID_TAB_CONTAINER); |
| 33 } | 41 } |
| 34 // Drop shadow is only needed if search mode is not |NTP| and overlay does | 42 // Drop shadow is only needed if search mode is not |NTP| and overlay does |
| 35 // not fill up the entire contents page. | 43 // not fill up the entire contents page. |
| 36 bool draw_drop_shadow = !model.mode().is_ntp() && | 44 bool draw_drop_shadow = !model.mode().is_ntp() && |
| 37 !(contents_->IsOverlayFullHeight(model.height(), model.height_units())); | 45 !(contents_->IsOverlayFullHeight(model.height(), model.height_units())); |
| 38 content::WebContents* web_contents = model.GetOverlayContents(); | 46 content::WebContents* web_contents = model.GetOverlayContents(); |
| 39 contents_->SetOverlay(overlay_.get(), web_contents, model.height(), | 47 contents_->SetOverlay(overlay_.get(), web_contents, model.height(), |
| 40 model.height_units(), draw_drop_shadow); | 48 model.height_units(), draw_drop_shadow); |
| 41 overlay_->SetWebContents(web_contents); | 49 overlay_->SetWebContents(web_contents); |
| 42 } else if (overlay_) { | 50 } else if (overlay_) { |
| 43 // Hide the overlay. SetWebContents() must happen before SetOverlay(). | 51 // Hide the overlay. SetWebContents() must happen before SetOverlay(). |
| 44 overlay_->SetWebContents(NULL); | 52 overlay_->SetWebContents(NULL); |
| 45 contents_->SetOverlay(NULL, NULL, 100, INSTANT_SIZE_PERCENT, false); | 53 contents_->SetOverlay(NULL, NULL, 100, INSTANT_SIZE_PERCENT, false); |
| 46 overlay_.reset(); | 54 overlay_.reset(); |
| 55 } else { |
| 56 // Don't set top bars visiblility if nothing was done with overlay. |
| 57 set_top_bars_visibility = false; |
| 47 } | 58 } |
| 48 | 59 |
| 49 browser_->MaybeUpdateBookmarkBarStateForInstantOverlay(model.mode()); | 60 if (set_top_bars_visibility) { |
| 61 // Set top bars visibility for current tab via |SearchTabHelper| of current |
| 62 // active web contents: top bars are hidden if there's overlay. |
| 63 chrome::search::SearchTabHelper* search_tab_helper = |
| 64 chrome::search::SearchTabHelper::FromWebContents( |
| 65 browser_->tab_strip_model()->GetActiveWebContents()); |
| 66 if (search_tab_helper) |
| 67 search_tab_helper->model()->SetTopBarsVisible(!overlay_); |
| 68 } |
| 50 | 69 |
| 51 // If an Instant overlay is added during an immersive mode reveal, the reveal | 70 // If an Instant overlay is added during an immersive mode reveal, the reveal |
| 52 // view needs to stay on top. | 71 // view needs to stay on top. |
| 53 // Notify infobar container of change in overlay state. | |
| 54 if (overlay_) { | 72 if (overlay_) { |
| 55 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 73 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 56 if (browser_view) { | 74 if (browser_view) |
| 57 browser_view->MaybeStackImmersiveRevealAtTop(); | 75 browser_view->MaybeStackImmersiveRevealAtTop(); |
| 58 browser_view->infobar_container()->OverlayStateChanged(model); | |
| 59 } | |
| 60 } | 76 } |
| 61 } | 77 } |
| OLD | NEW |