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

Side by Side Diff: chrome/browser/ui/views/search_view_controller.cc

Issue 10854173: Use a placeholder logo image/label in SearchViewController. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Address comments. Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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/search_view_controller.h" 5 #include "chrome/browser/ui/views/search_view_controller.h"
6 6
7 #include "chrome/browser/profiles/profile.h"
8 #include "chrome/browser/search_engines/search_engine_type.h"
9 #include "chrome/browser/search_engines/template_url.h"
10 #include "chrome/browser/search_engines/template_url_service.h"
11 #include "chrome/browser/search_engines/template_url_service_factory.h"
7 #include "chrome/browser/ui/search/search_model.h" 12 #include "chrome/browser/ui/search/search_model.h"
8 #include "chrome/browser/ui/search/search_tab_helper.h" 13 #include "chrome/browser/ui/search/search_tab_helper.h"
9 #include "chrome/browser/ui/search/search_types.h" 14 #include "chrome/browser/ui/search/search_types.h"
10 #include "chrome/browser/ui/search/search_ui.h" 15 #include "chrome/browser/ui/search/search_ui.h"
11 #include "chrome/browser/ui/tab_contents/tab_contents.h" 16 #include "chrome/browser/ui/tab_contents/tab_contents.h"
12 #include "chrome/browser/ui/views/frame/contents_container.h" 17 #include "chrome/browser/ui/views/frame/contents_container.h"
13 #include "chrome/browser/ui/views/location_bar/location_bar_container.h" 18 #include "chrome/browser/ui/views/location_bar/location_bar_container.h"
14 #include "chrome/browser/ui/webui/instant_ui.h" 19 #include "chrome/browser/ui/webui/instant_ui.h"
15 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
16 #include "grit/theme_resources.h" 21 #include "grit/theme_resources.h"
17 #include "ui/base/resource/resource_bundle.h" 22 #include "ui/base/resource/resource_bundle.h"
18 #include "ui/compositor/layer.h" 23 #include "ui/compositor/layer.h"
19 #include "ui/compositor/scoped_layer_animation_settings.h" 24 #include "ui/compositor/scoped_layer_animation_settings.h"
20 #include "ui/gfx/canvas.h" 25 #include "ui/gfx/canvas.h"
26 #include "ui/views/controls/image_view.h"
27 #include "ui/views/controls/label.h"
21 #include "ui/views/controls/webview/webview.h" 28 #include "ui/views/controls/webview/webview.h"
22 #include "ui/views/layout/fill_layout.h" 29 #include "ui/views/layout/fill_layout.h"
23 #include "ui/views/layout/layout_manager.h" 30 #include "ui/views/layout/layout_manager.h"
24 31
25 #if defined(USE_AURA) 32 #if defined(USE_AURA)
26 #include "ui/aura/window.h" 33 #include "ui/aura/window.h"
27 #endif 34 #endif
28 35
29 namespace { 36 namespace {
30 37
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
89 chrome::search::kResultsSeparatorColor); 96 chrome::search::kResultsSeparatorColor);
90 } 97 }
91 98
92 private: 99 private:
93 views::View* ntp_view_; 100 views::View* ntp_view_;
94 views::View* omnibox_popup_view_parent_; 101 views::View* omnibox_popup_view_parent_;
95 102
96 DISALLOW_COPY_AND_ASSIGN(SearchContainerView); 103 DISALLOW_COPY_AND_ASSIGN(SearchContainerView);
97 }; 104 };
98 105
99 // FixedSizeLayoutManager ------------------------------------------------------
100
101 // LayoutManager that returns a specific preferred size.
102
103 class FixedSizeLayoutManager : public views::LayoutManager {
104 public:
105 explicit FixedSizeLayoutManager(const gfx::Size& size)
106 : preferred_size_(size) {
107 }
108 virtual ~FixedSizeLayoutManager() {}
109
110 // views::LayoutManager overrides:
111 virtual void Layout(views::View* host) OVERRIDE {}
112 virtual gfx::Size GetPreferredSize(views::View* host) OVERRIDE {
113 return preferred_size_;
114 }
115
116 private:
117 const gfx::Size preferred_size_;
118
119 DISALLOW_COPY_AND_ASSIGN(FixedSizeLayoutManager);
120 };
121
122 // NTPViewBackground ----------------------------------------------------------- 106 // NTPViewBackground -----------------------------------------------------------
123 107
124 // Background for the NTP view. 108 // Background for the NTP view.
125 class NTPViewBackground : public views::Background { 109 class NTPViewBackground : public views::Background {
126 public: 110 public:
127 NTPViewBackground() {} 111 NTPViewBackground() {}
128 virtual ~NTPViewBackground() {} 112 virtual ~NTPViewBackground() {}
129 113
130 // views::Background overrides: 114 // views::Background overrides:
131 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE { 115 virtual void Paint(gfx::Canvas* canvas, views::View* view) const OVERRIDE {
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 parent()->Layout(); 213 parent()->Layout();
230 if (child_visible_ != child->visible()) { 214 if (child_visible_ != child->visible()) {
231 child_visible_ = child->visible(); 215 child_visible_ = child->visible();
232 search_view_controller_->PopupVisibilityChanged(); 216 search_view_controller_->PopupVisibilityChanged();
233 } 217 }
234 } 218 }
235 219
236 // SearchViewController -------------------------------------------------------- 220 // SearchViewController --------------------------------------------------------
237 221
238 SearchViewController::SearchViewController( 222 SearchViewController::SearchViewController(
223 content::BrowserContext* browser_context,
239 ContentsContainer* contents_container) 224 ContentsContainer* contents_container)
240 : contents_container_(contents_container), 225 : browser_context_(browser_context),
226 contents_container_(contents_container),
241 location_bar_container_(NULL), 227 location_bar_container_(NULL),
242 state_(STATE_NOT_VISIBLE), 228 state_(STATE_NOT_VISIBLE),
243 tab_contents_(NULL), 229 tab_contents_(NULL),
244 search_container_(NULL), 230 search_container_(NULL),
245 ntp_view_(NULL), 231 ntp_view_(NULL),
246 logo_view_(NULL), 232 logo_label_(NULL),
233 logo_image_(NULL),
247 content_view_(NULL), 234 content_view_(NULL),
248 omnibox_popup_view_parent_(NULL) { 235 omnibox_popup_view_parent_(NULL) {
249 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this); 236 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this);
250 } 237 }
251 238
252 SearchViewController::~SearchViewController() { 239 SearchViewController::~SearchViewController() {
253 if (search_model()) 240 if (search_model())
254 search_model()->RemoveObserver(this); 241 search_model()->RemoveObserver(this);
255 242
256 // If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be 243 // If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be
(...skipping 17 matching lines...) Expand all
274 search_model()->AddObserver(this); 261 search_model()->AddObserver(this);
275 262
276 UpdateState(); 263 UpdateState();
277 } 264 }
278 265
279 void SearchViewController::StackAtTop() { 266 void SearchViewController::StackAtTop() {
280 #if defined(USE_AURA) 267 #if defined(USE_AURA)
281 if (search_container_) { 268 if (search_container_) {
282 StackViewsLayerAtTop(search_container_); 269 StackViewsLayerAtTop(search_container_);
283 StackViewsLayerAtTop(ntp_view_); 270 StackViewsLayerAtTop(ntp_view_);
284 StackViewsLayerAtTop(logo_view_); 271 StackViewsLayerAtTop(GetLogoView());
285 StackWebViewLayerAtTop(content_view_); 272 StackWebViewLayerAtTop(content_view_);
286 } 273 }
287 #else 274 #else
288 NOTIMPLEMENTED(); 275 NOTIMPLEMENTED();
289 #endif 276 #endif
290 location_bar_container_->StackAtTop(); 277 location_bar_container_->StackAtTop();
291 } 278 }
292 279
293 void SearchViewController::InstantReady() { 280 void SearchViewController::InstantReady() {
294 } 281 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 settings.AddObserver(this); 366 settings.AddObserver(this);
380 settings.SetTransitionDuration( 367 settings.SetTransitionDuration(
381 base::TimeDelta::FromMilliseconds(180 * factor)); 368 base::TimeDelta::FromMilliseconds(180 * factor));
382 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 369 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
383 gfx::Rect bounds(ntp_layer->bounds()); 370 gfx::Rect bounds(ntp_layer->bounds());
384 bounds.set_height(1); 371 bounds.set_height(1);
385 ntp_layer->SetBounds(bounds); 372 ntp_layer->SetBounds(bounds);
386 } 373 }
387 374
388 { 375 {
389 ui::Layer* logo_layer = logo_view_->layer(); 376 ui::Layer* logo_layer = GetLogoView()->layer();
390 ui::ScopedLayerAnimationSettings settings(logo_layer->GetAnimator()); 377 ui::ScopedLayerAnimationSettings settings(logo_layer->GetAnimator());
391 settings.SetTransitionDuration( 378 settings.SetTransitionDuration(
392 base::TimeDelta::FromMilliseconds(135 * factor)); 379 base::TimeDelta::FromMilliseconds(135 * factor));
393 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 380 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
394 gfx::Rect bounds(logo_layer->bounds()); 381 gfx::Rect bounds(logo_layer->bounds());
395 bounds.set_y(bounds.y() - 100); 382 bounds.set_y(bounds.y() - 100);
396 logo_layer->SetBounds(bounds); 383 logo_layer->SetBounds(bounds);
397 logo_layer->SetOpacity(0.0f); 384 logo_layer->SetOpacity(0.0f);
398 } 385 }
399 386
(...skipping 12 matching lines...) Expand all
412 } 399 }
413 400
414 void SearchViewController::CreateViews() { 401 void SearchViewController::CreateViews() {
415 DCHECK(!ntp_view_); 402 DCHECK(!ntp_view_);
416 403
417 ntp_view_ = new views::View; 404 ntp_view_ = new views::View;
418 ntp_view_->set_background(new NTPViewBackground); 405 ntp_view_->set_background(new NTPViewBackground);
419 ntp_view_->SetPaintToLayer(true); 406 ntp_view_->SetPaintToLayer(true);
420 ntp_view_->layer()->SetMasksToBounds(true); 407 ntp_view_->layer()->SetMasksToBounds(true);
421 408
422 logo_view_ = new views::View; 409 const TemplateURL* default_template_url =
Peter Kasting 2012/08/16 03:52:41 This may be NULL. You must NULL-check before dere
msw 2012/08/16 08:29:08 Done. Checking and having a blank Label with no DS
423 logo_view_->SetLayoutManager( 410 TemplateURLServiceFactory::GetForProfile(
424 new FixedSizeLayoutManager(gfx::Size(300, 200))); 411 Profile::FromBrowserContext(browser_context_))->
425 logo_view_->set_background( 412 GetDefaultSearchProvider();
426 views::Background::CreateSolidBackground(SK_ColorRED)); 413
427 logo_view_->SetPaintToLayer(true); 414 #if defined(GOOGLE_CHROME_BUILD)
428 logo_view_->SetFillsBoundsOpaquely(false); 415 if (default_template_url->prepopulate_id() == SEARCH_ENGINE_GOOGLE) {
Peter Kasting 2012/08/16 03:52:41 prepopulate_id() is not a SearchEngineType. You n
msw 2012/08/16 08:29:08 Done. I'll fix the basis for this code (in SearchP
416 logo_image_ = new views::ImageView();
Peter Kasting 2012/08/16 03:52:41 Given how you're creating these, it might be bette
msw 2012/08/16 08:29:08 Done.
417 logo_image_->SetImage(ui::ResourceBundle::GetSharedInstance().
418 GetImageSkiaNamed(IDR_GOOGLE_LOGO_LG));
419 logo_image_->SetPaintToLayer(true);
420 logo_image_->SetFillsBoundsOpaquely(false);
421 }
422 #endif
423
424 if (!logo_image_) {
425 DCHECK(!default_template_url->short_name().empty());
426 logo_label_ = new views::Label(default_template_url->short_name());
427 // TODO(msw): Use a transparent background color as a workaround to support
428 // using Labels' view layers via gfx::Canvas::NO_SUBPIXEL_RENDERING.
429 logo_label_->SetBackgroundColor(0x00000000);
430 logo_label_->set_background(
431 views::Background::CreateSolidBackground(SK_ColorRED));
432 logo_label_->SetEnabledColor(SK_ColorRED);
433 logo_label_->SetFont(logo_label_->font().DeriveFont(75, gfx::Font::BOLD));
434 logo_label_->SetPaintToLayer(true);
435 logo_label_->SetFillsBoundsOpaquely(false);
436 }
429 437
430 // Reparent the main web contents view out of |contents_container_| and 438 // Reparent the main web contents view out of |contents_container_| and
431 // in to |ntp_view_| below. Reparent back in destructor. 439 // in to |ntp_view_| below. Reparent back in destructor.
432 content_view_ = contents_container_->active(); 440 content_view_ = contents_container_->active();
433 DCHECK(content_view_); 441 DCHECK(content_view_);
434 contents_container_->SetActive(NULL); 442 contents_container_->SetActive(NULL);
435 443
444 views::View* logo_view = GetLogoView();
436 ntp_view_->SetLayoutManager( 445 ntp_view_->SetLayoutManager(
437 new NTPViewLayoutManager(logo_view_, content_view_)); 446 new NTPViewLayoutManager(logo_view, content_view_));
438 ntp_view_->AddChildView(logo_view_); 447 ntp_view_->AddChildView(logo_view);
439 ntp_view_->AddChildView(content_view_); 448 ntp_view_->AddChildView(content_view_);
440 449
441 search_container_ = 450 search_container_ =
442 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); 451 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_);
443 search_container_->SetPaintToLayer(true); 452 search_container_->SetPaintToLayer(true);
444 search_container_->SetLayoutManager(new views::FillLayout); 453 search_container_->SetLayoutManager(new views::FillLayout);
445 search_container_->layer()->SetMasksToBounds(true); 454 search_container_->layer()->SetMasksToBounds(true);
446 455
447 contents_container_->SetOverlay(search_container_); 456 contents_container_->SetOverlay(search_container_);
448 } 457 }
449 458
459 views::View* SearchViewController::GetLogoView() const {
460 if (logo_image_)
Peter Kasting 2012/08/16 03:52:41 Nit: Shorter: return logo_image_ ? logo_image_
msw 2012/08/16 08:29:08 That'd require a cast (Label/ImageView), which Dav
461 return logo_image_;
462 return logo_label_;
463 }
464
450 void SearchViewController::DestroyViews() { 465 void SearchViewController::DestroyViews() {
451 if (!search_container_) 466 if (!search_container_)
452 return; 467 return;
453 468
454 // We persist the parent of the omnibox so that we don't have to inject a new 469 // We persist the parent of the omnibox so that we don't have to inject a new
455 // parent into ToolbarView. 470 // parent into ToolbarView.
456 omnibox_popup_view_parent_->parent()->RemoveChildView( 471 omnibox_popup_view_parent_->parent()->RemoveChildView(
457 omnibox_popup_view_parent_); 472 omnibox_popup_view_parent_);
458 473
459 // Restore control/parenting of the web_contents back to the 474 // Restore control/parenting of the web_contents back to the
460 // |main_contents_view_|. 475 // |main_contents_view_|.
461 ntp_view_->SetLayoutManager(NULL); 476 ntp_view_->SetLayoutManager(NULL);
462 ntp_view_->RemoveChildView(content_view_); 477 ntp_view_->RemoveChildView(content_view_);
463 if (content_view_->web_contents()) 478 if (content_view_->web_contents())
464 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f); 479 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f);
465 contents_container_->SetActive(content_view_); 480 contents_container_->SetActive(content_view_);
466 contents_container_->SetOverlay(NULL); 481 contents_container_->SetOverlay(NULL);
467 482
468 delete search_container_; 483 delete search_container_;
469 search_container_ = NULL; 484 search_container_ = NULL;
470 ntp_view_ = NULL; 485 ntp_view_ = NULL;
471 logo_view_ = NULL; 486 logo_label_ = NULL;
487 logo_image_ = NULL;
472 content_view_ = NULL; 488 content_view_ = NULL;
473 489
474 state_ = STATE_NOT_VISIBLE; 490 state_ = STATE_NOT_VISIBLE;
475 } 491 }
476 492
477 void SearchViewController::PopupVisibilityChanged() { 493 void SearchViewController::PopupVisibilityChanged() {
478 // Don't do anything while animating if the child is visible. Otherwise we'll 494 // Don't do anything while animating if the child is visible. Otherwise we'll
479 // prematurely cancel the animation. 495 // prematurely cancel the animation.
480 if (state_ != STATE_ANIMATING || 496 if (state_ != STATE_ANIMATING ||
481 !omnibox_popup_view_parent_->is_child_visible()) { 497 !omnibox_popup_view_parent_->is_child_visible()) {
482 UpdateState(); 498 UpdateState();
483 } 499 }
484 } 500 }
485 501
486 chrome::search::SearchModel* SearchViewController::search_model() { 502 chrome::search::SearchModel* SearchViewController::search_model() {
487 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; 503 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL;
488 } 504 }
489 505
490 content::WebContents* SearchViewController::web_contents() { 506 content::WebContents* SearchViewController::web_contents() {
491 return tab_contents_ ? tab_contents_->web_contents() : NULL; 507 return tab_contents_ ? tab_contents_->web_contents() : NULL;
492 } 508 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698