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

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

Issue 10832216: Clicks broken in NTP section of Search overlay (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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/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
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 }
253 251
254 SearchViewController::~SearchViewController() { 252 SearchViewController::~SearchViewController() {
255 if (search_model()) 253 if (search_model())
256 search_model()->RemoveObserver(this); 254 search_model()->RemoveObserver(this);
257 255
258 // If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be 256 // If the |omnibox_popup_view_| isn't parented, delete it. Otherwise it'll be
259 // deleted by its parent. 257 // deleted by its parent.
260 if (!omnibox_popup_view_parent_->parent()) 258 if (!omnibox_popup_view_parent_->parent())
261 delete omnibox_popup_view_parent_; 259 delete omnibox_popup_view_parent_;
262 } 260 }
sky 2012/08/09 00:39:14 Are there any timing issues here if content_view_
dhollowa 2012/08/09 16:07:25 It is certainly true that this has changed the des
263 261
264 views::View* SearchViewController::omnibox_popup_view_parent() { 262 views::View* SearchViewController::omnibox_popup_view_parent() {
265 return omnibox_popup_view_parent_; 263 return omnibox_popup_view_parent_;
266 } 264 }
267 265
268 void SearchViewController::SetTabContents(TabContents* tab_contents) { 266 void SearchViewController::SetTabContents(TabContents* tab_contents) {
269 if (tab_contents_ == tab_contents) 267 if (tab_contents_ == tab_contents)
270 return; 268 return;
271 269
272 if (search_model()) 270 if (search_model())
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
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 contents_container_->SetActive(NULL);
sky 2012/08/09 00:39:14 How about a DCHECK(content_view_) between 431/432.
dhollowa 2012/08/09 16:07:25 Done.
437 433
438 ntp_view_->SetLayoutManager( 434 ntp_view_->SetLayoutManager(
439 new NTPViewLayoutManager(logo_view_, content_view_)); 435 new NTPViewLayoutManager(logo_view_, content_view_));
440 ntp_view_->AddChildView(logo_view_); 436 ntp_view_->AddChildView(logo_view_);
441 ntp_view_->AddChildView(content_view_); 437 ntp_view_->AddChildView(content_view_);
442 438
443 search_container_ = 439 search_container_ =
444 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_); 440 new SearchContainerView(ntp_view_, omnibox_popup_view_parent_);
445 search_container_->SetPaintToLayer(true); 441 search_container_->SetPaintToLayer(true);
446 search_container_->SetLayoutManager(new views::FillLayout); 442 search_container_->SetLayoutManager(new views::FillLayout);
447 search_container_->layer()->SetMasksToBounds(true); 443 search_container_->layer()->SetMasksToBounds(true);
448 444
449 contents_container_->SetOverlay(search_container_); 445 contents_container_->SetOverlay(search_container_);
450 } 446 }
451 447
452 void SearchViewController::DestroyViews() { 448 void SearchViewController::DestroyViews() {
453 if (!search_container_) 449 if (!search_container_)
454 return; 450 return;
455 451
456 // We persist the parent of the omnibox so that we don't have to inject a new 452 // We persist the parent of the omnibox so that we don't have to inject a new
457 // parent into ToolbarView. 453 // parent into ToolbarView.
458 omnibox_popup_view_parent_->parent()->RemoveChildView( 454 omnibox_popup_view_parent_->parent()->RemoveChildView(
459 omnibox_popup_view_parent_); 455 omnibox_popup_view_parent_);
460 456
461 if (content_view_) 457 // Restore control/parenting of the web_contents back to the
462 content_view_->SetWebContents(NULL); 458 // |main_contents_view_|.
459 ntp_view_->SetLayoutManager(NULL);
460 ntp_view_->RemoveChildView(content_view_);
461 if (content_view_->web_contents())
462 content_view_->web_contents()->GetNativeView()->layer()->SetOpacity(1.0f);
463 contents_container_->SetActive(content_view_);
464 contents_container_->SetOverlay(NULL);
463 465
464 contents_container_->SetOverlay(NULL);
465 delete search_container_; 466 delete search_container_;
466 search_container_ = NULL; 467 search_container_ = NULL;
467 ntp_view_ = NULL; 468 ntp_view_ = NULL;
468 logo_view_ = NULL; 469 logo_view_ = NULL;
469 content_view_ = NULL; 470 content_view_ = NULL;
470 471
471 state_ = STATE_NOT_VISIBLE; 472 state_ = STATE_NOT_VISIBLE;
472 } 473 }
473 474
474 void SearchViewController::PopupVisibilityChanged() { 475 void SearchViewController::PopupVisibilityChanged() {
475 // Don't do anything while animating if the child is visible. Otherwise we'll 476 // Don't do anything while animating if the child is visible. Otherwise we'll
476 // prematurely cancel the animation. 477 // prematurely cancel the animation.
477 if (state_ != STATE_ANIMATING || 478 if (state_ != STATE_ANIMATING ||
478 !omnibox_popup_view_parent_->is_child_visible()) { 479 !omnibox_popup_view_parent_->is_child_visible()) {
479 UpdateState(); 480 UpdateState();
480 } 481 }
481 } 482 }
482 483
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() { 484 chrome::search::SearchModel* SearchViewController::search_model() {
492 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; 485 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL;
493 } 486 }
494 487
495 content::WebContents* SearchViewController::web_contents() { 488 content::WebContents* SearchViewController::web_contents() {
496 return tab_contents_ ? tab_contents_->web_contents() : NULL; 489 return tab_contents_ ? tab_contents_->web_contents() : NULL;
497 } 490 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698