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