Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(960)

Unified Diff: chrome/browser/ui/views/search_view_controller.cc

Issue 10787028: Converts SearchViewController to use live NTP content instead of placeholder (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/views/search_view_controller.cc
diff --git a/chrome/browser/ui/views/search_view_controller.cc b/chrome/browser/ui/views/search_view_controller.cc
index ac457f27e2c7ac86cf0579d09fe9e5720adfa52c..8e97b025fa2f55ac707b4992a936db7e27c69f9f 100644
--- a/chrome/browser/ui/views/search_view_controller.cc
+++ b/chrome/browser/ui/views/search_view_controller.cc
@@ -12,14 +12,23 @@
#include "chrome/browser/ui/views/frame/contents_container.h"
#include "chrome/browser/ui/views/location_bar/location_bar_container.h"
#include "chrome/browser/ui/webui/instant_ui.h"
+#include "chrome/common/url_constants.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/notification_source.h"
+#include "content/public/browser/notification_types.h"
#include "grit/theme_resources.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h"
+#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_manager.h"
+#if defined(USE_AURA)
+#include "ui/aura/window.h"
+#endif
+
namespace {
// SearchContainerView ---------------------------------------------------------
@@ -141,12 +150,11 @@ class NTPViewLayoutManager : public views::LayoutManager {
logo_pref.width(),
logo_pref.height());
- gfx::Size content_pref(content_view_->GetPreferredSize());
- int content_y = std::max(chrome::search::kOmniboxYPosition + 50,
- host->height() - content_pref.height() - 50);
- content_view_->SetBounds((host->width() - content_pref.width()) / 2,
- content_y, content_pref.width(),
- content_pref.height());
+ int content_y = chrome::search::kOmniboxYPosition + 50;
+ content_view_->SetBounds(0,
+ content_y,
+ host->width(),
+ host->height() - content_y);
}
virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE {
@@ -216,22 +224,28 @@ void SearchViewController::OmniboxPopupViewParent::ChildPreferredSizeChanged(
// SearchViewController --------------------------------------------------------
SearchViewController::SearchViewController(
+ chrome::search::SearchModel* search_model,
+ content::BrowserContext* browser_context,
ContentsContainer* contents_container)
- : contents_container_(contents_container),
+ : search_model_(search_model),
+ browser_context_(browser_context),
+ contents_container_(contents_container),
location_bar_container_(NULL),
state_(STATE_NOT_VISIBLE),
- tab_(NULL),
search_container_(NULL),
ntp_view_(NULL),
logo_view_(NULL),
content_view_(NULL),
omnibox_popup_view_parent_(NULL) {
+ search_model_->AddObserver(this);
omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this);
+ registrar_.Add(this,
+ content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
+ content::NotificationService::AllSources());
}
SearchViewController::~SearchViewController() {
- if (search_model())
- search_model()->RemoveObserver(this);
+ search_model_->RemoveObserver(this);
// If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be
// deleted by its parent.
@@ -243,17 +257,7 @@ views::View* SearchViewController::omnibox_popup_view_parent() {
return omnibox_popup_view_parent_;
}
-void SearchViewController::SetTabContents(TabContents* tab) {
- if (tab_ == tab)
dhollowa 2012/07/20 00:34:09 I pulled this logic out because this class should
sky 2012/07/20 15:58:13 This code needs to run at a specific time. The ord
- return;
-
- if (search_model())
- search_model()->RemoveObserver(this);
- tab_ = tab;
- if (search_model())
- search_model()->AddObserver(this);
-
- UpdateState();
+void SearchViewController::SetTabContents(TabContents* tab_contents) {
}
void SearchViewController::StackAtTop() {
@@ -262,7 +266,10 @@ void SearchViewController::StackAtTop() {
StackViewsLayerAtTop(search_container_);
StackViewsLayerAtTop(ntp_view_);
StackViewsLayerAtTop(logo_view_);
- StackViewsLayerAtTop(content_view_);
+ if (content_view_ && content_view_->web_contents()) {
+ ntp_view_->layer()->StackAtTop(
+ content_view_->web_contents()->GetNativeView()->layer());
+ }
}
#else
NOTIMPLEMENTED();
@@ -292,12 +299,8 @@ void SearchViewController::OnImplicitAnimationsCompleted() {
}
void SearchViewController::UpdateState() {
- if (!search_model()) {
- DestroyViews();
- return;
- }
State new_state = STATE_NOT_VISIBLE;
- switch (search_model()->mode().mode) {
+ switch (search_model_->mode().mode) {
case chrome::search::Mode::MODE_DEFAULT:
break;
@@ -306,7 +309,7 @@ void SearchViewController::UpdateState() {
break;
case chrome::search::Mode::MODE_SEARCH:
- if (search_model()->mode().animate && state_ == STATE_NTP) {
+ if (search_model_->mode().animate && state_ == STATE_NTP) {
new_state = STATE_ANIMATING;
} else {
// Only enter into MODE_SEARCH if the omnibox is visible.
@@ -334,6 +337,7 @@ void SearchViewController::SetState(State state) {
case STATE_NTP:
DestroyViews();
CreateViews();
+ content_view_->LoadInitialURL(GURL(chrome::kChromeUINewTabURL));
break;
case STATE_ANIMATING:
@@ -377,7 +381,8 @@ void SearchViewController::StartAnimation() {
}
{
- ui::Layer* content_layer = content_view_->layer();
+ ui::Layer* content_layer =
+ content_view_->web_contents()->GetNativeView()->layer();
ui::ScopedLayerAnimationSettings settings(content_layer->GetAnimator());
settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(180 * factor));
@@ -405,17 +410,13 @@ void SearchViewController::CreateViews() {
logo_view_->SetPaintToLayer(true);
logo_view_->SetFillsBoundsOpaquely(false);
- // TODO: replace with WebContents for NTP.
- content_view_ = new views::View;
- content_view_->SetLayoutManager(
- new FixedSizeLayoutManager(gfx::Size(400, 200)));
- content_view_->set_background(
- views::Background::CreateSolidBackground(SK_ColorBLUE));
- content_view_->SetPaintToLayer(true);
+ content_view_ = new views::WebView(browser_context_);
content_view_->SetFillsBoundsOpaquely(false);
ntp_view_->SetLayoutManager(
new NTPViewLayoutManager(logo_view_, content_view_));
+ ntp_view_->AddChildView(logo_view_);
+ ntp_view_->AddChildView(content_view_);
search_container_ =
new SearchContainerView(ntp_view_, omnibox_popup_view_parent_);
@@ -423,9 +424,6 @@ void SearchViewController::CreateViews() {
search_container_->SetLayoutManager(new views::FillLayout);
search_container_->layer()->SetMasksToBounds(true);
- ntp_view_->AddChildView(logo_view_);
- ntp_view_->AddChildView(content_view_);
-
contents_container_->SetOverlay(search_container_);
}
@@ -440,8 +438,10 @@ void SearchViewController::DestroyViews() {
contents_container_->SetOverlay(NULL);
delete search_container_;
- search_container_ = ntp_view_ = NULL;
- content_view_ = logo_view_ = NULL;
+ search_container_ = NULL;
+ ntp_view_ = NULL;
+ logo_view_ = NULL;
+ content_view_ = NULL;
state_ = STATE_NOT_VISIBLE;
}
@@ -455,6 +455,17 @@ void SearchViewController::PopupVisibilityChanged() {
}
}
-chrome::search::SearchModel* SearchViewController::search_model() {
- return tab_ ? tab_->search_tab_helper()->model() : NULL;
-}
+void SearchViewController::Observe(
+ int type,
+ const content::NotificationSource& source,
+ const content::NotificationDetails& details) {
+ DCHECK_EQ(type, content::NOTIFICATION_WEB_CONTENTS_CONNECTED);
dhollowa 2012/07/20 00:34:09 sky, what I'm seeing is that during launch, when t
sky 2012/07/20 15:58:13 At the time this class is created everything shoul
+ if (!content_view_)
+ return;
+
+ registrar_.Remove(this,
+ content::NOTIFICATION_WEB_CONTENTS_CONNECTED,
+ content::NotificationService::AllSources());
+ content_view_->SetWebContents(NULL);
+ content_view_->LoadInitialURL(GURL(chrome::kChromeUINewTabURL));
+ }

Powered by Google App Engine
This is Rietveld 408576698