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_preview_controller_views.h" | 5 #include "chrome/browser/ui/views/frame/instant_preview_controller_views.h" |
6 | 6 |
7 #include "chrome/browser/instant/instant_model.h" | 7 #include "chrome/browser/instant/instant_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/tab_contents/tab_contents.h" | |
11 #include "chrome/browser/ui/view_ids.h" | 10 #include "chrome/browser/ui/view_ids.h" |
12 #include "chrome/browser/ui/views/frame/contents_container.h" | 11 #include "chrome/browser/ui/views/frame/contents_container.h" |
13 #include "ui/views/controls/webview/webview.h" | 12 #include "ui/views/controls/webview/webview.h" |
14 | 13 |
15 InstantPreviewControllerViews::InstantPreviewControllerViews( | 14 InstantPreviewControllerViews::InstantPreviewControllerViews( |
16 Browser* browser, | 15 Browser* browser, |
17 ContentsContainer* contents) | 16 ContentsContainer* contents) |
18 : InstantPreviewController(browser), | 17 : InstantPreviewController(browser), |
19 contents_(contents) { | 18 contents_(contents) { |
20 } | 19 } |
21 | 20 |
22 InstantPreviewControllerViews::~InstantPreviewControllerViews() { | 21 InstantPreviewControllerViews::~InstantPreviewControllerViews() { |
23 } | 22 } |
24 | 23 |
25 void InstantPreviewControllerViews::PreviewStateChanged( | 24 void InstantPreviewControllerViews::PreviewStateChanged( |
26 const InstantModel& model) { | 25 const InstantModel& model) { |
27 if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { | 26 if (model.mode().is_ntp() || model.mode().is_search_suggestions()) { |
28 // Show the preview. | 27 // Show the preview. |
29 if (!preview_) { | 28 if (!preview_) { |
30 preview_.reset(new views::WebView(browser_->profile())); | 29 preview_.reset(new views::WebView(browser_->profile())); |
31 preview_->set_id(VIEW_ID_TAB_CONTAINER); | 30 preview_->set_id(VIEW_ID_TAB_CONTAINER); |
32 } | 31 } |
33 content::WebContents* web_contents = | 32 content::WebContents* web_contents = model.GetPreviewContents(); |
34 model.GetPreviewContents()->web_contents(); | |
35 contents_->SetPreview(preview_.get(), web_contents, | 33 contents_->SetPreview(preview_.get(), web_contents, |
36 model.height(), model.height_units()); | 34 model.height(), model.height_units()); |
37 preview_->SetWebContents(web_contents); | 35 preview_->SetWebContents(web_contents); |
38 } else if (preview_) { | 36 } else if (preview_) { |
39 // Hide the preview. SetWebContents() must happen before SetPreview(). | 37 // Hide the preview. SetWebContents() must happen before SetPreview(). |
40 preview_->SetWebContents(NULL); | 38 preview_->SetWebContents(NULL); |
41 contents_->SetPreview(NULL, NULL, 100, INSTANT_SIZE_PERCENT); | 39 contents_->SetPreview(NULL, NULL, 100, INSTANT_SIZE_PERCENT); |
42 preview_.reset(); | 40 preview_.reset(); |
43 } | 41 } |
44 | 42 |
45 browser_->MaybeUpdateBookmarkBarStateForInstantPreview(model.mode()); | 43 browser_->MaybeUpdateBookmarkBarStateForInstantPreview(model.mode()); |
46 } | 44 } |
OLD | NEW |