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

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: Sync and merge. 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
« no previous file with comments | « chrome/browser/ui/views/search_view_controller.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/label.h"
dhollowa 2012/08/15 22:23:51 nit: sort
msw 2012/08/15 22:32:54 Done.
27 #include "ui/views/controls/image_view.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 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 // SearchViewController -------------------------------------------------------- 220 // SearchViewController --------------------------------------------------------
237 221
238 SearchViewController::SearchViewController( 222 SearchViewController::SearchViewController(
239 ContentsContainer* contents_container) 223 ContentsContainer* contents_container)
240 : contents_container_(contents_container), 224 : contents_container_(contents_container),
241 location_bar_container_(NULL), 225 location_bar_container_(NULL),
242 state_(STATE_NOT_VISIBLE), 226 state_(STATE_NOT_VISIBLE),
243 tab_contents_(NULL), 227 tab_contents_(NULL),
244 search_container_(NULL), 228 search_container_(NULL),
245 ntp_view_(NULL), 229 ntp_view_(NULL),
246 logo_view_(NULL), 230 logo_label_(NULL),
231 logo_image_(NULL),
247 content_view_(NULL), 232 content_view_(NULL),
248 omnibox_popup_view_parent_(NULL) { 233 omnibox_popup_view_parent_(NULL) {
249 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this); 234 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this);
250 } 235 }
251 236
252 SearchViewController::~SearchViewController() { 237 SearchViewController::~SearchViewController() {
253 if (search_model()) 238 if (search_model())
254 search_model()->RemoveObserver(this); 239 search_model()->RemoveObserver(this);
255 240
256 // If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be 241 // 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); 259 search_model()->AddObserver(this);
275 260
276 UpdateState(); 261 UpdateState();
277 } 262 }
278 263
279 void SearchViewController::StackAtTop() { 264 void SearchViewController::StackAtTop() {
280 #if defined(USE_AURA) 265 #if defined(USE_AURA)
281 if (search_container_) { 266 if (search_container_) {
282 StackViewsLayerAtTop(search_container_); 267 StackViewsLayerAtTop(search_container_);
283 StackViewsLayerAtTop(ntp_view_); 268 StackViewsLayerAtTop(ntp_view_);
284 StackViewsLayerAtTop(logo_view_); 269 StackViewsLayerAtTop(GetLogoView());
285 StackWebViewLayerAtTop(content_view_); 270 StackWebViewLayerAtTop(content_view_);
286 } 271 }
287 #else 272 #else
288 NOTIMPLEMENTED(); 273 NOTIMPLEMENTED();
289 #endif 274 #endif
290 location_bar_container_->StackAtTop(); 275 location_bar_container_->StackAtTop();
291 } 276 }
292 277
293 void SearchViewController::InstantReady() { 278 void SearchViewController::InstantReady() {
294 } 279 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 settings.AddObserver(this); 364 settings.AddObserver(this);
380 settings.SetTransitionDuration( 365 settings.SetTransitionDuration(
381 base::TimeDelta::FromMilliseconds(180 * factor)); 366 base::TimeDelta::FromMilliseconds(180 * factor));
382 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 367 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
383 gfx::Rect bounds(ntp_layer->bounds()); 368 gfx::Rect bounds(ntp_layer->bounds());
384 bounds.set_height(1); 369 bounds.set_height(1);
385 ntp_layer->SetBounds(bounds); 370 ntp_layer->SetBounds(bounds);
386 } 371 }
387 372
388 { 373 {
389 ui::Layer* logo_layer = logo_view_->layer(); 374 ui::Layer* logo_layer = GetLogoView()->layer();
390 ui::ScopedLayerAnimationSettings settings(logo_layer->GetAnimator()); 375 ui::ScopedLayerAnimationSettings settings(logo_layer->GetAnimator());
391 settings.SetTransitionDuration( 376 settings.SetTransitionDuration(
392 base::TimeDelta::FromMilliseconds(135 * factor)); 377 base::TimeDelta::FromMilliseconds(135 * factor));
393 settings.SetTweenType(ui::Tween::EASE_IN_OUT); 378 settings.SetTweenType(ui::Tween::EASE_IN_OUT);
394 gfx::Rect bounds(logo_layer->bounds()); 379 gfx::Rect bounds(logo_layer->bounds());
395 bounds.set_y(bounds.y() - 100); 380 bounds.set_y(bounds.y() - 100);
396 logo_layer->SetBounds(bounds); 381 logo_layer->SetBounds(bounds);
397 logo_layer->SetOpacity(0.0f); 382 logo_layer->SetOpacity(0.0f);
398 } 383 }
399 384
(...skipping 12 matching lines...) Expand all
412 } 397 }
413 398
414 void SearchViewController::CreateViews() { 399 void SearchViewController::CreateViews() {
415 DCHECK(!ntp_view_); 400 DCHECK(!ntp_view_);
416 401
417 ntp_view_ = new views::View; 402 ntp_view_ = new views::View;
418 ntp_view_->set_background(new NTPViewBackground); 403 ntp_view_->set_background(new NTPViewBackground);
419 ntp_view_->SetPaintToLayer(true); 404 ntp_view_->SetPaintToLayer(true);
420 ntp_view_->layer()->SetMasksToBounds(true); 405 ntp_view_->layer()->SetMasksToBounds(true);
421 406
422 logo_view_ = new views::View; 407 const TemplateURL* default_template_url =
423 logo_view_->SetLayoutManager( 408 TemplateURLServiceFactory::GetForProfile(
424 new FixedSizeLayoutManager(gfx::Size(300, 200))); 409 Profile::FromBrowserContext(browser_context_))->
425 logo_view_->set_background( 410 GetDefaultSearchProvider();
426 views::Background::CreateSolidBackground(SK_ColorRED)); 411
427 logo_view_->SetPaintToLayer(true); 412 #if defined(GOOGLE_CHROME_BUILD)
428 logo_view_->SetFillsBoundsOpaquely(false); 413 if (default_template_url->prepopulate_id() == SEARCH_ENGINE_GOOGLE) {
414 logo_image_ = new views::ImageView();
415 logo_image_->SetImage(ui::ResourceBundle::GetSharedInstance().
416 GetImageSkiaNamed(IDR_GOOGLE_LOGO_LG));
417 logo_image_->SetPaintToLayer(true);
418 logo_image_->SetFillsBoundsOpaquely(false);
419 }
420 #endif
421
422 if (!logo_image_) {
423 DCHECK(!default_template_url->short_name().empty());
424 logo_label_ = new views::Label(default_template_url->short_name());
425 // TODO(msw): Use a transparent background color as a workaround to support
426 // using Labels' view layers via gfx::Canvas::NO_SUBPIXEL_RENDERING.
427 logo_label_->SetBackgroundColor(0x00000000);
428 logo_label_->set_background(
429 views::Background::CreateSolidBackground(SK_ColorRED));
430 logo_label_->SetEnabledColor(SK_ColorRED);
431 logo_label_->SetFont(logo_label_->font().DeriveFont(75, gfx::Font::BOLD));
432 logo_label_->SetPaintToLayer(true);
433 logo_label_->SetFillsBoundsOpaquely(false);
434 }
429 435
430 // Reparent the main web contents view out of |contents_container_| and 436 // Reparent the main web contents view out of |contents_container_| and
431 // in to |ntp_view_| below. Reparent back in destructor. 437 // in to |ntp_view_| below. Reparent back in destructor.
432 content_view_ = contents_container_->active(); 438 content_view_ = contents_container_->active();
433 DCHECK(content_view_); 439 DCHECK(content_view_);
434 contents_container_->SetActive(NULL); 440 contents_container_->SetActive(NULL);
435 441
442 views::View* logo_view = GetLogoView();
436 ntp_view_->SetLayoutManager( 443 ntp_view_->SetLayoutManager(
437 new NTPViewLayoutManager(logo_view_, content_view_)); 444 new NTPViewLayoutManager(logo_view, content_view_));
438 ntp_view_->AddChildView(logo_view_); 445 ntp_view_->AddChildView(logo_view);
439 ntp_view_->AddChildView(content_view_); 446 ntp_view_->AddChildView(content_view_);
440 447
441 search_container_ = 448 search_container_ =
442 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); 449 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_);
443 search_container_->SetPaintToLayer(true); 450 search_container_->SetPaintToLayer(true);
444 search_container_->SetLayoutManager(new views::FillLayout); 451 search_container_->SetLayoutManager(new views::FillLayout);
445 search_container_->layer()->SetMasksToBounds(true); 452 search_container_->layer()->SetMasksToBounds(true);
446 453
447 contents_container_->SetOverlay(search_container_); 454 contents_container_->SetOverlay(search_container_);
448 } 455 }
449 456
457 views::View* SearchViewController::GetLogoView() const {
458 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.
459 }
460
450 void SearchViewController::DestroyViews() { 461 void SearchViewController::DestroyViews() {
451 if (!search_container_) 462 if (!search_container_)
452 return; 463 return;
453 464
454 // We persist the parent of the omnibox so that we don't have to inject a new 465 // We persist the parent of the omnibox so that we don't have to inject a new
455 // parent into ToolbarView. 466 // parent into ToolbarView.
456 omnibox_popup_view_parent_->parent()->RemoveChildView( 467 omnibox_popup_view_parent_->parent()->RemoveChildView(
457 omnibox_popup_view_parent_); 468 omnibox_popup_view_parent_);
458 469
459 // Restore control/parenting of the web_contents back to the 470 // Restore control/parenting of the web_contents back to the
460 // |main_contents_view_|. 471 // |main_contents_view_|.
461 ntp_view_->SetLayoutManager(NULL); 472 ntp_view_->SetLayoutManager(NULL);
462 ntp_view_->RemoveChildView(content_view_); 473 ntp_view_->RemoveChildView(content_view_);
463 if (content_view_->web_contents()) 474 if (content_view_->web_contents())
464 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f); 475 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f);
465 contents_container_->SetActive(content_view_); 476 contents_container_->SetActive(content_view_);
466 contents_container_->SetOverlay(NULL); 477 contents_container_->SetOverlay(NULL);
467 478
468 delete search_container_; 479 delete search_container_;
469 search_container_ = NULL; 480 search_container_ = NULL;
470 ntp_view_ = NULL; 481 ntp_view_ = NULL;
471 logo_view_ = NULL; 482 logo_label_ = NULL;
483 logo_image_ = NULL;
472 content_view_ = NULL; 484 content_view_ = NULL;
473 485
474 state_ = STATE_NOT_VISIBLE; 486 state_ = STATE_NOT_VISIBLE;
475 } 487 }
476 488
477 void SearchViewController::PopupVisibilityChanged() { 489 void SearchViewController::PopupVisibilityChanged() {
478 // Don't do anything while animating if the child is visible. Otherwise we'll 490 // Don't do anything while animating if the child is visible. Otherwise we'll
479 // prematurely cancel the animation. 491 // prematurely cancel the animation.
480 if (state_ != STATE_ANIMATING || 492 if (state_ != STATE_ANIMATING ||
481 !omnibox_popup_view_parent_->is_child_visible()) { 493 !omnibox_popup_view_parent_->is_child_visible()) {
482 UpdateState(); 494 UpdateState();
483 } 495 }
484 } 496 }
485 497
486 chrome::search::SearchModel* SearchViewController::search_model() { 498 chrome::search::SearchModel* SearchViewController::search_model() {
487 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; 499 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL;
488 } 500 }
489 501
490 content::WebContents* SearchViewController::web_contents() { 502 content::WebContents* SearchViewController::web_contents() {
491 return tab_contents_ ? tab_contents_->web_contents() : NULL; 503 return tab_contents_ ? tab_contents_->web_contents() : NULL;
492 } 504 }
OLDNEW
« no previous file with comments | « chrome/browser/ui/views/search_view_controller.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698