| 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/instant/instant_overlay_model.h" | 7 #include "chrome/browser/instant/instant_overlay_model.h" |
| 8 #include "chrome/browser/profiles/profile.h" | 8 #include "chrome/browser/profiles/profile.h" |
| 9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
| 10 #include "chrome/browser/ui/view_ids.h" | 10 #include "chrome/browser/ui/view_ids.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "chrome/browser/ui/views/frame/contents_container.h" | 12 #include "chrome/browser/ui/views/frame/contents_container.h" |
| 13 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" | 13 #include "chrome/browser/ui/views/infobars/infobar_container_view.h" |
| 14 #include "ui/views/controls/webview/webview.h" | 14 #include "ui/views/controls/webview/webview.h" |
| 15 | 15 |
| 16 InstantOverlayControllerViews::InstantOverlayControllerViews( | 16 InstantOverlayControllerViews::InstantOverlayControllerViews( |
| 17 Browser* browser, | 17 Browser* browser, |
| 18 ContentsContainer* contents) | 18 ContentsContainer* contents) |
| 19 : InstantOverlayController(browser), | 19 : InstantOverlayController(browser), |
| 20 contents_(contents) { | 20 contents_(contents) { |
| 21 } | 21 } |
| 22 | 22 |
| 23 InstantOverlayControllerViews::~InstantOverlayControllerViews() { | 23 InstantOverlayControllerViews::~InstantOverlayControllerViews() { |
| 24 } | 24 } |
| 25 | 25 |
| 26 void InstantOverlayControllerViews::OverlayStateChanged( | 26 void InstantOverlayControllerViews::OverlayStateChanged( |
| 27 const InstantOverlayModel& model) { | 27 const InstantOverlayModel& model) { |
| 28 if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { | 28 if (!model.contents()) { |
| 29 // Show the overlay. | 29 // Hide the overlay. SetWebContents() must happen before SetOverlay(). |
| 30 if (!overlay_) { | 30 if (overlay_) { |
| 31 overlay_.reset(new views::WebView(browser_->profile())); | 31 overlay_->SetWebContents(NULL); |
| 32 overlay_->set_id(VIEW_ID_TAB_CONTAINER); | 32 contents_->SetOverlay(NULL, NULL, 0, INSTANT_SIZE_PIXELS, false); |
| 33 overlay_.reset(); |
| 33 } | 34 } |
| 34 // Drop shadow is only needed if search mode is not |NTP| and overlay does | 35 return; |
| 35 // not fill up the entire contents page. | |
| 36 bool draw_drop_shadow = !model.mode().is_ntp() && | |
| 37 !(contents_->IsOverlayFullHeight(model.height(), model.height_units())); | |
| 38 content::WebContents* web_contents = model.GetOverlayContents(); | |
| 39 contents_->SetOverlay(overlay_.get(), web_contents, model.height(), | |
| 40 model.height_units(), draw_drop_shadow); | |
| 41 overlay_->SetWebContents(web_contents); | |
| 42 } else if (overlay_) { | |
| 43 // Hide the overlay. SetWebContents() must happen before SetOverlay(). | |
| 44 overlay_->SetWebContents(NULL); | |
| 45 contents_->SetOverlay(NULL, NULL, 100, INSTANT_SIZE_PERCENT, false); | |
| 46 overlay_.reset(); | |
| 47 } | 36 } |
| 48 | 37 |
| 49 browser_->MaybeUpdateBookmarkBarStateForInstantOverlay(model.mode()); | 38 // Show the overlay. |
| 39 if (!overlay_) { |
| 40 overlay_.reset(new views::WebView(browser_->profile())); |
| 41 overlay_->set_id(VIEW_ID_TAB_CONTAINER); |
| 42 } |
| 43 |
| 44 // Drop shadow is only needed if the overlay does not fill up the entire |
| 45 // contents page. |
| 46 bool draw_drop_shadow = |
| 47 !contents_->IsOverlayFullHeight(model.height(), model.height_units()); |
| 48 contents_->SetOverlay(overlay_.get(), model.contents(), model.height(), |
| 49 model.height_units(), draw_drop_shadow); |
| 50 overlay_->SetWebContents(model.contents()); |
| 51 |
| 52 browser_->MaybeUpdateBookmarkBarStateForInstantOverlay(); |
| 50 | 53 |
| 51 // If an Instant overlay is added during an immersive mode reveal, the reveal | 54 // If an Instant overlay is added during an immersive mode reveal, the reveal |
| 52 // view needs to stay on top. | 55 // view needs to stay on top. |
| 53 // Notify infobar container of change in overlay state. | 56 // Notify infobar container of change in overlay state. |
| 54 if (overlay_) { | 57 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); |
| 55 BrowserView* browser_view = BrowserView::GetBrowserViewForBrowser(browser_); | 58 if (browser_view) { |
| 56 if (browser_view) { | 59 browser_view->MaybeStackImmersiveRevealAtTop(); |
| 57 browser_view->MaybeStackImmersiveRevealAtTop(); | 60 browser_view->infobar_container()->InstantOverlayShown(); |
| 58 browser_view->infobar_container()->OverlayStateChanged(model); | |
| 59 } | |
| 60 } | 61 } |
| 61 } | 62 } |
| OLD | NEW |