OLD | NEW |
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/ui/search/search_model.h" | 7 #include "chrome/browser/ui/search/search_model.h" |
8 #include "chrome/browser/ui/search/search_tab_helper.h" | 8 #include "chrome/browser/ui/search/search_tab_helper.h" |
9 #include "chrome/browser/ui/search/search_types.h" | 9 #include "chrome/browser/ui/search/search_types.h" |
10 #include "chrome/browser/ui/search/search_ui.h" | 10 #include "chrome/browser/ui/search/search_ui.h" |
(...skipping 218 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
229 parent()->Layout(); | 229 parent()->Layout(); |
230 if (child_visible_ != child->visible()) { | 230 if (child_visible_ != child->visible()) { |
231 child_visible_ = child->visible(); | 231 child_visible_ = child->visible(); |
232 search_view_controller_->PopupVisibilityChanged(); | 232 search_view_controller_->PopupVisibilityChanged(); |
233 } | 233 } |
234 } | 234 } |
235 | 235 |
236 // SearchViewController -------------------------------------------------------- | 236 // SearchViewController -------------------------------------------------------- |
237 | 237 |
238 SearchViewController::SearchViewController( | 238 SearchViewController::SearchViewController( |
239 content::BrowserContext* browser_context, | |
240 ContentsContainer* contents_container) | 239 ContentsContainer* contents_container) |
241 : browser_context_(browser_context), | 240 : contents_container_(contents_container), |
242 contents_container_(contents_container), | |
243 location_bar_container_(NULL), | 241 location_bar_container_(NULL), |
244 state_(STATE_NOT_VISIBLE), | 242 state_(STATE_NOT_VISIBLE), |
245 tab_contents_(NULL), | 243 tab_contents_(NULL), |
246 search_container_(NULL), | 244 search_container_(NULL), |
247 ntp_view_(NULL), | 245 ntp_view_(NULL), |
248 logo_view_(NULL), | 246 logo_view_(NULL), |
249 content_view_(NULL), | 247 content_view_(NULL), |
250 omnibox_popup_view_parent_(NULL) { | 248 omnibox_popup_view_parent_(NULL) { |
251 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this); | 249 omnibox_popup_view_parent_ = new OmniboxPopupViewParent(this); |
252 } | 250 } |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 } else { | 331 } else { |
334 // Only enter into MODE_SEARCH if the omnibox is visible. | 332 // Only enter into MODE_SEARCH if the omnibox is visible. |
335 if (omnibox_popup_view_parent_->is_child_visible()) | 333 if (omnibox_popup_view_parent_->is_child_visible()) |
336 new_state = STATE_SEARCH; | 334 new_state = STATE_SEARCH; |
337 else | 335 else |
338 new_state = STATE_NOT_VISIBLE; | 336 new_state = STATE_NOT_VISIBLE; |
339 } | 337 } |
340 break; | 338 break; |
341 } | 339 } |
342 SetState(new_state); | 340 SetState(new_state); |
343 MaybeLoadNTP(); | |
344 } | 341 } |
345 | 342 |
346 void SearchViewController::SetState(State state) { | 343 void SearchViewController::SetState(State state) { |
347 if (state_ == state) | 344 if (state_ == state) |
348 return; | 345 return; |
349 | 346 |
350 State old_state = state_; | 347 State old_state = state_; |
351 state_ = state; | 348 state_ = state; |
352 switch (state_) { | 349 switch (state_) { |
353 case STATE_NOT_VISIBLE: | 350 case STATE_NOT_VISIBLE: |
354 DestroyViews(); | 351 DestroyViews(); |
355 break; | 352 break; |
356 | 353 |
357 case STATE_NTP: | 354 case STATE_NTP: |
358 DestroyViews(); | 355 DestroyViews(); |
359 CreateViews(); | 356 CreateViews(); |
360 // TODO(dhollowa): This is temporary. The |content_view_| should pull its | |
361 // web contents from the current tab's |search_tab_helper|. | |
362 content_view_->LoadInitialURL(GURL(chrome::kChromeUINewTabURL)); | |
363 break; | 357 break; |
364 | 358 |
365 case STATE_ANIMATING: | 359 case STATE_ANIMATING: |
366 // Should only animate from the ntp. | 360 // Should only animate from the ntp. |
367 DCHECK_EQ(STATE_NTP, old_state); | 361 DCHECK_EQ(STATE_NTP, old_state); |
368 StartAnimation(); | 362 StartAnimation(); |
369 break; | 363 break; |
370 | 364 |
371 case STATE_SEARCH: | 365 case STATE_SEARCH: |
372 DestroyViews(); | 366 DestroyViews(); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
425 ntp_view_->layer()->SetMasksToBounds(true); | 419 ntp_view_->layer()->SetMasksToBounds(true); |
426 | 420 |
427 logo_view_ = new views::View; | 421 logo_view_ = new views::View; |
428 logo_view_->SetLayoutManager( | 422 logo_view_->SetLayoutManager( |
429 new FixedSizeLayoutManager(gfx::Size(300, 200))); | 423 new FixedSizeLayoutManager(gfx::Size(300, 200))); |
430 logo_view_->set_background( | 424 logo_view_->set_background( |
431 views::Background::CreateSolidBackground(SK_ColorRED)); | 425 views::Background::CreateSolidBackground(SK_ColorRED)); |
432 logo_view_->SetPaintToLayer(true); | 426 logo_view_->SetPaintToLayer(true); |
433 logo_view_->SetFillsBoundsOpaquely(false); | 427 logo_view_->SetFillsBoundsOpaquely(false); |
434 | 428 |
435 content_view_ = new views::WebView(browser_context_); | 429 // Reparent the main web contents view out of |contents_container_| and |
436 content_view_->SetFillsBoundsOpaquely(false); | 430 // in to |ntp_view_| below. Reparent back in destructor. |
| 431 content_view_ = contents_container_->active(); |
| 432 DCHECK(content_view_); |
| 433 contents_container_->SetActive(NULL); |
437 | 434 |
438 ntp_view_->SetLayoutManager( | 435 ntp_view_->SetLayoutManager( |
439 new NTPViewLayoutManager(logo_view_, content_view_)); | 436 new NTPViewLayoutManager(logo_view_, content_view_)); |
440 ntp_view_->AddChildView(logo_view_); | 437 ntp_view_->AddChildView(logo_view_); |
441 ntp_view_->AddChildView(content_view_); | 438 ntp_view_->AddChildView(content_view_); |
442 | 439 |
443 search_container_ = | 440 search_container_ = |
444 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); | 441 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); |
445 search_container_->SetPaintToLayer(true); | 442 search_container_->SetPaintToLayer(true); |
446 search_container_->SetLayoutManager(new views::FillLayout); | 443 search_container_->SetLayoutManager(new views::FillLayout); |
447 search_container_->layer()->SetMasksToBounds(true); | 444 search_container_->layer()->SetMasksToBounds(true); |
448 | 445 |
449 contents_container_->SetOverlay(search_container_); | 446 contents_container_->SetOverlay(search_container_); |
450 } | 447 } |
451 | 448 |
452 void SearchViewController::DestroyViews() { | 449 void SearchViewController::DestroyViews() { |
453 if (!search_container_) | 450 if (!search_container_) |
454 return; | 451 return; |
455 | 452 |
456 // We persist the parent of the omnibox so that we don't have to inject a new | 453 // We persist the parent of the omnibox so that we don't have to inject a new |
457 // parent into ToolbarView. | 454 // parent into ToolbarView. |
458 omnibox_popup_view_parent_->parent()->RemoveChildView( | 455 omnibox_popup_view_parent_->parent()->RemoveChildView( |
459 omnibox_popup_view_parent_); | 456 omnibox_popup_view_parent_); |
460 | 457 |
461 if (content_view_) | 458 // Restore control/parenting of the web_contents back to the |
462 content_view_->SetWebContents(NULL); | 459 // |main_contents_view_|. |
| 460 ntp_view_->SetLayoutManager(NULL); |
| 461 ntp_view_->RemoveChildView(content_view_); |
| 462 if (content_view_->web_contents()) |
| 463 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f); |
| 464 contents_container_->SetActive(content_view_); |
| 465 contents_container_->SetOverlay(NULL); |
463 | 466 |
464 contents_container_->SetOverlay(NULL); | |
465 delete search_container_; | 467 delete search_container_; |
466 search_container_ = NULL; | 468 search_container_ = NULL; |
467 ntp_view_ = NULL; | 469 ntp_view_ = NULL; |
468 logo_view_ = NULL; | 470 logo_view_ = NULL; |
469 content_view_ = NULL; | 471 content_view_ = NULL; |
470 | 472 |
471 state_ = STATE_NOT_VISIBLE; | 473 state_ = STATE_NOT_VISIBLE; |
472 } | 474 } |
473 | 475 |
474 void SearchViewController::PopupVisibilityChanged() { | 476 void SearchViewController::PopupVisibilityChanged() { |
475 // Don't do anything while animating if the child is visible. Otherwise we'll | 477 // Don't do anything while animating if the child is visible. Otherwise we'll |
476 // prematurely cancel the animation. | 478 // prematurely cancel the animation. |
477 if (state_ != STATE_ANIMATING || | 479 if (state_ != STATE_ANIMATING || |
478 !omnibox_popup_view_parent_->is_child_visible()) { | 480 !omnibox_popup_view_parent_->is_child_visible()) { |
479 UpdateState(); | 481 UpdateState(); |
480 } | 482 } |
481 } | 483 } |
482 | 484 |
483 void SearchViewController::MaybeLoadNTP() { | |
484 if (state_ != STATE_NTP || !content_view_) | |
485 return; | |
486 | |
487 content_view_->SetWebContents( | |
488 tab_contents_->search_tab_helper()->GetNTPWebContents()); | |
489 } | |
490 | |
491 chrome::search::SearchModel* SearchViewController::search_model() { | 485 chrome::search::SearchModel* SearchViewController::search_model() { |
492 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; | 486 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; |
493 } | 487 } |
494 | 488 |
495 content::WebContents* SearchViewController::web_contents() { | 489 content::WebContents* SearchViewController::web_contents() { |
496 return tab_contents_ ? tab_contents_->web_contents() : NULL; | 490 return tab_contents_ ? tab_contents_->web_contents() : NULL; |
497 } | 491 } |
OLD | NEW |