Commit b404c01d authored by dhollowa@chromium.org's avatar dhollowa@chromium.org

Converts SearchViewController to use live NTP content instead of placeholder

Converts SearchViewController to use live NTP content using views::WebView
instead of placeholder solid rect views::View.

TEST=Launch CrOS/Aura with --enabled-instant-extended-api, observe interactive "Most Visited" section on NTP
BUG=133529
R=sky@chromium.org


Review URL: https://chromiumcodereview.appspot.com/10787028

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@148438 0039d316-1c4b-4281-b951-d872f2087c98
parent 6574d79e
...@@ -1938,7 +1938,8 @@ void BrowserView::Init() { ...@@ -1938,7 +1938,8 @@ void BrowserView::Init() {
// SearchViewController doesn't work on windows yet. // SearchViewController doesn't work on windows yet.
#if defined(USE_AURA) #if defined(USE_AURA)
if (chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())) { if (chrome::search::IsInstantExtendedAPIEnabled(browser_->profile())) {
search_view_controller_.reset(new SearchViewController(contents_)); search_view_controller_.reset(
new SearchViewController(browser_->profile(), contents_));
omnibox_popup_view_parent = omnibox_popup_view_parent =
search_view_controller_->omnibox_popup_view_parent(); search_view_controller_->omnibox_popup_view_parent();
} }
......
...@@ -12,16 +12,38 @@ ...@@ -12,16 +12,38 @@
#include "chrome/browser/ui/views/frame/contents_container.h" #include "chrome/browser/ui/views/frame/contents_container.h"
#include "chrome/browser/ui/views/location_bar/location_bar_container.h" #include "chrome/browser/ui/views/location_bar/location_bar_container.h"
#include "chrome/browser/ui/webui/instant_ui.h" #include "chrome/browser/ui/webui/instant_ui.h"
#include "chrome/common/url_constants.h"
#include "grit/theme_resources.h" #include "grit/theme_resources.h"
#include "ui/compositor/layer.h" #include "ui/compositor/layer.h"
#include "ui/compositor/scoped_layer_animation_settings.h" #include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/canvas.h" #include "ui/gfx/canvas.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/layout/fill_layout.h" #include "ui/views/layout/fill_layout.h"
#include "ui/views/layout/layout_manager.h" #include "ui/views/layout/layout_manager.h"
#if defined(USE_AURA)
#include "ui/aura/window.h"
#endif
namespace { namespace {
// Stacks view's layer above all its sibling layers.
void StackViewsLayerAtTop(views::View* view) {
DCHECK(view->layer());
DCHECK(view->layer()->parent());
view->layer()->parent()->StackAtTop(view->layer());
}
// Stacks native view's layer above all its sibling layers.
void StackWebViewLayerAtTop(views::WebView* view) {
if (!view->web_contents())
return;
ui::Layer* native_view_layer = view->web_contents()->GetNativeView()->layer();
native_view_layer->parent()->StackAtTop(native_view_layer);
}
// SearchContainerView --------------------------------------------------------- // SearchContainerView ---------------------------------------------------------
// SearchContainerView contains the |ntp_view_| and // SearchContainerView contains the |ntp_view_| and
...@@ -126,7 +148,7 @@ class NTPViewBackground : public views::Background { ...@@ -126,7 +148,7 @@ class NTPViewBackground : public views::Background {
// LayoutManager for the NTPView. // LayoutManager for the NTPView.
class NTPViewLayoutManager : public views::LayoutManager { class NTPViewLayoutManager : public views::LayoutManager {
public: public:
NTPViewLayoutManager(views::View* logo_view, views::View* content_view) NTPViewLayoutManager(views::View* logo_view, views::WebView* content_view)
: logo_view_(logo_view), : logo_view_(logo_view),
content_view_(content_view) { content_view_(content_view) {
} }
...@@ -141,12 +163,17 @@ class NTPViewLayoutManager : public views::LayoutManager { ...@@ -141,12 +163,17 @@ class NTPViewLayoutManager : public views::LayoutManager {
logo_pref.width(), logo_pref.width(),
logo_pref.height()); logo_pref.height());
gfx::Size content_pref(content_view_->GetPreferredSize()); const int kContentTop = chrome::search::kOmniboxYPosition + 50;
int content_y = std::max(chrome::search::kOmniboxYPosition + 50, content_view_->SetBounds(0,
host->height() - content_pref.height() - 50); kContentTop,
content_view_->SetBounds((host->width() - content_pref.width()) / 2, host->width(),
content_y, content_pref.width(), host->height() - kContentTop);
content_pref.height());
// TODO(dhollowa): This is a hack to patch up ordering of native layer.
// Changes to the view hierarchy can |ReorderLayers| which messes with
// layer stacking. Layout typically follows reorderings, so we patch
// things up here.
StackWebViewLayerAtTop(content_view_);
} }
virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE { virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE {
...@@ -156,18 +183,11 @@ class NTPViewLayoutManager : public views::LayoutManager { ...@@ -156,18 +183,11 @@ class NTPViewLayoutManager : public views::LayoutManager {
private: private:
views::View* logo_view_; views::View* logo_view_;
views::View* content_view_; views::WebView* content_view_;
DISALLOW_COPY_AND_ASSIGN(NTPViewLayoutManager); DISALLOW_COPY_AND_ASSIGN(NTPViewLayoutManager);
}; };
// Stacks view's layer above all its sibling layers.
void StackViewsLayerAtTop(views::View* view) {
DCHECK(view->layer());
DCHECK(view->layer()->parent());
view->layer()->parent()->StackAtTop(view->layer());
}
} // namespace } // namespace
// SearchViewController::OmniboxPopupViewParent -------------------------------- // SearchViewController::OmniboxPopupViewParent --------------------------------
...@@ -216,11 +236,13 @@ void SearchViewController::OmniboxPopupViewParent::ChildPreferredSizeChanged( ...@@ -216,11 +236,13 @@ void SearchViewController::OmniboxPopupViewParent::ChildPreferredSizeChanged(
// SearchViewController -------------------------------------------------------- // SearchViewController --------------------------------------------------------
SearchViewController::SearchViewController( SearchViewController::SearchViewController(
content::BrowserContext* browser_context,
ContentsContainer* contents_container) ContentsContainer* contents_container)
: contents_container_(contents_container), : browser_context_(browser_context),
contents_container_(contents_container),
location_bar_container_(NULL), location_bar_container_(NULL),
state_(STATE_NOT_VISIBLE), state_(STATE_NOT_VISIBLE),
tab_(NULL), tab_contents_(NULL),
search_container_(NULL), search_container_(NULL),
ntp_view_(NULL), ntp_view_(NULL),
logo_view_(NULL), logo_view_(NULL),
...@@ -243,13 +265,13 @@ views::View* SearchViewController::omnibox_popup_view_parent() { ...@@ -243,13 +265,13 @@ views::View* SearchViewController::omnibox_popup_view_parent() {
return omnibox_popup_view_parent_; return omnibox_popup_view_parent_;
} }
void SearchViewController::SetTabContents(TabContents* tab) { void SearchViewController::SetTabContents(TabContents* tab_contents) {
if (tab_ == tab) if (tab_contents_ == tab_contents)
return; return;
if (search_model()) if (search_model())
search_model()->RemoveObserver(this); search_model()->RemoveObserver(this);
tab_ = tab; tab_contents_ = tab_contents;
if (search_model()) if (search_model())
search_model()->AddObserver(this); search_model()->AddObserver(this);
...@@ -262,7 +284,7 @@ void SearchViewController::StackAtTop() { ...@@ -262,7 +284,7 @@ void SearchViewController::StackAtTop() {
StackViewsLayerAtTop(search_container_); StackViewsLayerAtTop(search_container_);
StackViewsLayerAtTop(ntp_view_); StackViewsLayerAtTop(ntp_view_);
StackViewsLayerAtTop(logo_view_); StackViewsLayerAtTop(logo_view_);
StackViewsLayerAtTop(content_view_); StackWebViewLayerAtTop(content_view_);
} }
#else #else
NOTIMPLEMENTED(); NOTIMPLEMENTED();
...@@ -334,6 +356,9 @@ void SearchViewController::SetState(State state) { ...@@ -334,6 +356,9 @@ void SearchViewController::SetState(State state) {
case STATE_NTP: case STATE_NTP:
DestroyViews(); DestroyViews();
CreateViews(); CreateViews();
// TODO(dhollowa): This is temporary. The |content_view_| should pull its
// web contents from the current tab's |search_tab_helper|.
content_view_->LoadInitialURL(GURL(chrome::kChromeUINewTabURL));
break; break;
case STATE_ANIMATING: case STATE_ANIMATING:
...@@ -377,7 +402,8 @@ void SearchViewController::StartAnimation() { ...@@ -377,7 +402,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()); ui::ScopedLayerAnimationSettings settings(content_layer->GetAnimator());
settings.SetTransitionDuration( settings.SetTransitionDuration(
base::TimeDelta::FromMilliseconds(180 * factor)); base::TimeDelta::FromMilliseconds(180 * factor));
...@@ -405,17 +431,13 @@ void SearchViewController::CreateViews() { ...@@ -405,17 +431,13 @@ void SearchViewController::CreateViews() {
logo_view_->SetPaintToLayer(true); logo_view_->SetPaintToLayer(true);
logo_view_->SetFillsBoundsOpaquely(false); logo_view_->SetFillsBoundsOpaquely(false);
// TODO: replace with WebContents for NTP. content_view_ = new views::WebView(browser_context_);
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_->SetFillsBoundsOpaquely(false); content_view_->SetFillsBoundsOpaquely(false);
ntp_view_->SetLayoutManager( ntp_view_->SetLayoutManager(
new NTPViewLayoutManager(logo_view_, content_view_)); new NTPViewLayoutManager(logo_view_, content_view_));
ntp_view_->AddChildView(logo_view_);
ntp_view_->AddChildView(content_view_);
search_container_ = search_container_ =
new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); new SearchContainerView(ntp_view_, omnibox_popup_view_parent_);
...@@ -423,9 +445,6 @@ void SearchViewController::CreateViews() { ...@@ -423,9 +445,6 @@ void SearchViewController::CreateViews() {
search_container_->SetLayoutManager(new views::FillLayout); search_container_->SetLayoutManager(new views::FillLayout);
search_container_->layer()->SetMasksToBounds(true); search_container_->layer()->SetMasksToBounds(true);
ntp_view_->AddChildView(logo_view_);
ntp_view_->AddChildView(content_view_);
contents_container_->SetOverlay(search_container_); contents_container_->SetOverlay(search_container_);
} }
...@@ -440,8 +459,10 @@ void SearchViewController::DestroyViews() { ...@@ -440,8 +459,10 @@ void SearchViewController::DestroyViews() {
contents_container_->SetOverlay(NULL); contents_container_->SetOverlay(NULL);
delete search_container_; delete search_container_;
search_container_ = ntp_view_ = NULL; search_container_ = NULL;
content_view_ = logo_view_ = NULL; ntp_view_ = NULL;
logo_view_ = NULL;
content_view_ = NULL;
state_ = STATE_NOT_VISIBLE; state_ = STATE_NOT_VISIBLE;
} }
...@@ -456,5 +477,9 @@ void SearchViewController::PopupVisibilityChanged() { ...@@ -456,5 +477,9 @@ void SearchViewController::PopupVisibilityChanged() {
} }
chrome::search::SearchModel* SearchViewController::search_model() { chrome::search::SearchModel* SearchViewController::search_model() {
return tab_ ? tab_->search_tab_helper()->model() : NULL; return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL;
}
content::WebContents* SearchViewController::web_contents() {
return tab_contents_ ? tab_contents_->web_contents() : NULL;
} }
...@@ -20,8 +20,14 @@ class SearchModel; ...@@ -20,8 +20,14 @@ class SearchModel;
} }
} }
namespace content {
class BrowserContext;
class WebContents;
}
namespace views { namespace views {
class View; class View;
class WebView;
} }
// SearchViewController maintains the search overlay (native new tab page). // SearchViewController maintains the search overlay (native new tab page).
...@@ -32,7 +38,8 @@ class SearchViewController ...@@ -32,7 +38,8 @@ class SearchViewController
: public chrome::search::SearchModelObserver, : public chrome::search::SearchModelObserver,
public ui::ImplicitAnimationObserver { public ui::ImplicitAnimationObserver {
public: public:
explicit SearchViewController(ContentsContainer* contents_container); SearchViewController(content::BrowserContext* browser_context,
ContentsContainer* contents_container);
virtual ~SearchViewController(); virtual ~SearchViewController();
views::View* omnibox_popup_view_parent(); views::View* omnibox_popup_view_parent();
...@@ -43,7 +50,7 @@ class SearchViewController ...@@ -43,7 +50,7 @@ class SearchViewController
} }
// Sets the active tab. // Sets the active tab.
void SetTabContents(TabContents* tab); void SetTabContents(TabContents* tab_contents);
// Stacks the overlay at the top. // Stacks the overlay at the top.
void StackAtTop(); void StackAtTop();
...@@ -95,19 +102,25 @@ class SearchViewController ...@@ -95,19 +102,25 @@ class SearchViewController
// Invoked when the visibility of the omnibox popup changes. // Invoked when the visibility of the omnibox popup changes.
void PopupVisibilityChanged(); void PopupVisibilityChanged();
// Returns the SearchModel for the current tab, or NULL if there // Access active search model.
// is no current tab.
chrome::search::SearchModel* search_model(); chrome::search::SearchModel* search_model();
// Where the overlay is placed. // Access active web contents.
content::WebContents* web_contents();
// The profile. Weak.
content::BrowserContext* browser_context_;
// Where the overlay is placed. Weak.
ContentsContainer* contents_container_; ContentsContainer* contents_container_;
// Weak.
LocationBarContainer* location_bar_container_; LocationBarContainer* location_bar_container_;
State state_; State state_;
// The active TabContents; may be NULL. // The active TabContents. Weak. May be NULL.
TabContents* tab_; TabContents* tab_contents_;
// The following views are created to render the NTP. Visually they look // The following views are created to render the NTP. Visually they look
// something like: // something like:
...@@ -141,7 +154,7 @@ class SearchViewController ...@@ -141,7 +154,7 @@ class SearchViewController
views::View* search_container_; views::View* search_container_;
views::View* ntp_view_; views::View* ntp_view_;
views::View* logo_view_; views::View* logo_view_;
views::View* content_view_; views::WebView* content_view_;
OmniboxPopupViewParent* omnibox_popup_view_parent_; OmniboxPopupViewParent* omnibox_popup_view_parent_;
DISALLOW_COPY_AND_ASSIGN(SearchViewController); DISALLOW_COPY_AND_ASSIGN(SearchViewController);
......
...@@ -23,9 +23,6 @@ namespace { ...@@ -23,9 +23,6 @@ namespace {
void PrintLayerHierarchyImp(const Layer* layer, int indent, void PrintLayerHierarchyImp(const Layer* layer, int indent,
gfx::Point mouse_location) { gfx::Point mouse_location) {
if (!layer->visible())
return;
std::wostringstream buf; std::wostringstream buf;
std::string indent_str(indent, ' '); std::string indent_str(indent, ' ');
std::string content_indent_str(indent+1, ' '); std::string content_indent_str(indent+1, ' ');
...@@ -56,6 +53,9 @@ void PrintLayerHierarchyImp(const Layer* layer, int indent, ...@@ -56,6 +53,9 @@ void PrintLayerHierarchyImp(const Layer* layer, int indent,
break; break;
} }
if (!layer->visible())
buf << L" !visible";
buf << L'\n' << UTF8ToWide(content_indent_str); buf << L'\n' << UTF8ToWide(content_indent_str);
buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y(); buf << L"bounds: " << layer->bounds().x() << L',' << layer->bounds().y();
buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height(); buf << L' ' << layer->bounds().width() << L'x' << layer->bounds().height();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment