Chromium Code Reviews| 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 118d301d6293eb4df8958fd2a0006a9e5648ba3c..aa1626610f1baf38c0c0f73ddfefa2f44e6156c8 100644 |
| --- a/chrome/browser/ui/views/search_view_controller.cc |
| +++ b/chrome/browser/ui/views/search_view_controller.cc |
| @@ -4,6 +4,11 @@ |
| #include "chrome/browser/ui/views/search_view_controller.h" |
| +#include "chrome/browser/profiles/profile.h" |
| +#include "chrome/browser/search_engines/search_engine_type.h" |
| +#include "chrome/browser/search_engines/template_url.h" |
| +#include "chrome/browser/search_engines/template_url_service.h" |
| +#include "chrome/browser/search_engines/template_url_service_factory.h" |
| #include "chrome/browser/ui/search/search_model.h" |
| #include "chrome/browser/ui/search/search_tab_helper.h" |
| #include "chrome/browser/ui/search/search_types.h" |
| @@ -18,6 +23,8 @@ |
| #include "ui/compositor/layer.h" |
| #include "ui/compositor/scoped_layer_animation_settings.h" |
| #include "ui/gfx/canvas.h" |
| +#include "ui/views/controls/label.h" |
|
dhollowa
2012/08/15 22:23:51
nit: sort
msw
2012/08/15 22:32:54
Done.
|
| +#include "ui/views/controls/image_view.h" |
| #include "ui/views/controls/webview/webview.h" |
| #include "ui/views/layout/fill_layout.h" |
| #include "ui/views/layout/layout_manager.h" |
| @@ -96,29 +103,6 @@ class SearchContainerView : public views::View { |
| DISALLOW_COPY_AND_ASSIGN(SearchContainerView); |
| }; |
| -// FixedSizeLayoutManager ------------------------------------------------------ |
| - |
| -// LayoutManager that returns a specific preferred size. |
| - |
| -class FixedSizeLayoutManager : public views::LayoutManager { |
| - public: |
| - explicit FixedSizeLayoutManager(const gfx::Size& size) |
| - : preferred_size_(size) { |
| - } |
| - virtual ~FixedSizeLayoutManager() {} |
| - |
| - // views::LayoutManager overrides: |
| - virtual void Layout(views::View* host) OVERRIDE {} |
| - virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE { |
| - return preferred_size_; |
| - } |
| - |
| - private: |
| - const gfx::Size preferred_size_; |
| - |
| - DISALLOW_COPY_AND_ASSIGN(FixedSizeLayoutManager); |
| -}; |
| - |
| // NTPViewBackground ----------------------------------------------------------- |
| // Background for the NTP view. |
| @@ -243,7 +227,8 @@ SearchViewController::SearchViewController( |
| tab_contents_(NULL), |
| search_container_(NULL), |
| ntp_view_(NULL), |
| - logo_view_(NULL), |
| + logo_label_(NULL), |
| + logo_image_(NULL), |
| content_view_(NULL), |
| omnibox_popup_view_parent_(NULL) { |
| omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this); |
| @@ -281,7 +266,7 @@ void SearchViewController::StackAtTop() { |
| if (search_container_) { |
| StackViewsLayerAtTop(search_container_); |
| StackViewsLayerAtTop(ntp_view_); |
| - StackViewsLayerAtTop(logo_view_); |
| + StackViewsLayerAtTop(GetLogoView()); |
| StackWebViewLayerAtTop(content_view_); |
| } |
| #else |
| @@ -386,7 +371,7 @@ void SearchViewController::StartAnimation() { |
| } |
| { |
| - ui::Layer* logo_layer = logo_view_->layer(); |
| + ui::Layer* logo_layer = GetLogoView()->layer(); |
| ui::ScopedLayerAnimationSettings settings(logo_layer->GetAnimator()); |
| settings.SetTransitionDuration( |
| base::TimeDelta::FromMilliseconds(135 * factor)); |
| @@ -419,13 +404,34 @@ void SearchViewController::CreateViews() { |
| ntp_view_->SetPaintToLayer(true); |
| ntp_view_->layer()->SetMasksToBounds(true); |
| - logo_view_ = new views::View; |
| - logo_view_->SetLayoutManager( |
| - new FixedSizeLayoutManager(gfx::Size(300, 200))); |
| - logo_view_->set_background( |
| - views::Background::CreateSolidBackground(SK_ColorRED)); |
| - logo_view_->SetPaintToLayer(true); |
| - logo_view_->SetFillsBoundsOpaquely(false); |
| + const TemplateURL* default_template_url = |
| + TemplateURLServiceFactory::GetForProfile( |
| + Profile::FromBrowserContext(browser_context_))-> |
| + GetDefaultSearchProvider(); |
| + |
| +#if defined(GOOGLE_CHROME_BUILD) |
| + if (default_template_url->prepopulate_id() == SEARCH_ENGINE_GOOGLE) { |
| + logo_image_ = new views::ImageView(); |
| + logo_image_->SetImage(ui::ResourceBundle::GetSharedInstance(). |
| + GetImageSkiaNamed(IDR_GOOGLE_LOGO_LG)); |
| + logo_image_->SetPaintToLayer(true); |
| + logo_image_->SetFillsBoundsOpaquely(false); |
| + } |
| +#endif |
| + |
| + if (!logo_image_) { |
| + DCHECK(!default_template_url->short_name().empty()); |
| + logo_label_ = new views::Label(default_template_url->short_name()); |
| + // TODO(msw): Use a transparent background color as a workaround to support |
| + // using Labels' view layers via gfx::Canvas::NO_SUBPIXEL_RENDERING. |
| + logo_label_->SetBackgroundColor(0x00000000); |
| + logo_label_->set_background( |
| + views::Background::CreateSolidBackground(SK_ColorRED)); |
| + logo_label_->SetEnabledColor(SK_ColorRED); |
| + logo_label_->SetFont(logo_label_->font().DeriveFont(75, gfx::Font::BOLD)); |
| + logo_label_->SetPaintToLayer(true); |
| + logo_label_->SetFillsBoundsOpaquely(false); |
| + } |
| // Reparent the main web contents view out of |contents_container_| and |
| // in to |ntp_view_| below. Reparent back in destructor. |
| @@ -433,9 +439,10 @@ void SearchViewController::CreateViews() { |
| DCHECK(content_view_); |
| contents_container_->SetActive(NULL); |
| + views::View* logo_view = GetLogoView(); |
| ntp_view_->SetLayoutManager( |
| - new NTPViewLayoutManager(logo_view_, content_view_)); |
| - ntp_view_->AddChildView(logo_view_); |
| + new NTPViewLayoutManager(logo_view, content_view_)); |
| + ntp_view_->AddChildView(logo_view); |
| ntp_view_->AddChildView(content_view_); |
| search_container_ = |
| @@ -447,6 +454,10 @@ void SearchViewController::CreateViews() { |
| contents_container_->SetOverlay(search_container_); |
| } |
| +views::View* SearchViewController::GetLogoView() const { |
| + return logo_image_ ? logo_image_ : static_cast<views::View*>(logo_label_); |
|
dhollowa
2012/08/15 22:23:51
nit: I'd prefer if/else to avoid the cast. Crap c
msw
2012/08/15 22:32:54
Done.
|
| +} |
| + |
| void SearchViewController::DestroyViews() { |
| if (!search_container_) |
| return; |
| @@ -468,7 +479,8 @@ void SearchViewController::DestroyViews() { |
| delete search_container_; |
| search_container_ = NULL; |
| ntp_view_ = NULL; |
| - logo_view_ = NULL; |
| + logo_label_ = NULL; |
| + logo_image_ = NULL; |
| content_view_ = NULL; |
| state_ = STATE_NOT_VISIBLE; |