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 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
292 | 292 |
293 void SearchViewController::InstantReady() { | 293 void SearchViewController::InstantReady() { |
294 } | 294 } |
295 | 295 |
296 void SearchViewController::ModeChanged(const chrome::search::Mode& old_mode, | 296 void SearchViewController::ModeChanged(const chrome::search::Mode& old_mode, |
297 const chrome::search::Mode& new_mode) { | 297 const chrome::search::Mode& new_mode) { |
298 UpdateState(); | 298 UpdateState(); |
299 } | 299 } |
300 | 300 |
301 void SearchViewController::OnImplicitAnimationsCompleted() { | 301 void SearchViewController::OnImplicitAnimationsCompleted() { |
302 DCHECK_EQ(STATE_ANIMATING, state_); | 302 DCHECK_EQ(STATE_NTP_ANIMATING, state_); |
303 state_ = STATE_SEARCH; | 303 state_ = STATE_SUGGESTIONS; |
304 ntp_view_->SetVisible(false); | 304 ntp_view_->SetVisible(false); |
305 // While |ntp_view_| was fading out, location bar was animating from the | 305 // While |ntp_view_| was fading out, location bar was animating from the |
306 // middle of the NTP page to the top toolbar, at the same rate. | 306 // middle of the NTP page to the top toolbar, at the same rate. |
307 // Suggestions need to be aligned with the final location of the location bar. | 307 // Suggestions need to be aligned with the final location of the location bar. |
308 // So if omnibox popup view (InlineOmniboxPopupView) is visible, force a | 308 // So if omnibox popup view (InlineOmniboxPopupView) is visible, force a |
309 // re-layout of its children (i.e. the suggestions) to align with the location | 309 // re-layout of its children (i.e. the suggestions) to align with the location |
310 // bar's final bounds. | 310 // bar's final bounds. |
311 if (omnibox_popup_view_parent_->is_child_visible()) | 311 if (omnibox_popup_view_parent_->is_child_visible()) |
312 omnibox_popup_view_parent_->child_at(0)->Layout(); | 312 omnibox_popup_view_parent_->child_at(0)->Layout(); |
313 } | 313 } |
314 | 314 |
315 void SearchViewController::UpdateState() { | 315 void SearchViewController::UpdateState() { |
316 if (!search_model()) { | 316 if (!search_model()) { |
317 DestroyViews(); | 317 DestroyViews(); |
318 return; | 318 return; |
319 } | 319 } |
320 State new_state = STATE_NOT_VISIBLE; | 320 State new_state = STATE_NOT_VISIBLE; |
321 switch (search_model()->mode().mode) { | 321 switch (search_model()->mode().mode) { |
322 case chrome::search::Mode::MODE_DEFAULT: | 322 case chrome::search::Mode::MODE_DEFAULT: |
323 break; | 323 break; |
324 | 324 |
325 case chrome::search::Mode::MODE_NTP: | 325 case chrome::search::Mode::MODE_NTP: |
326 new_state = STATE_NTP; | 326 new_state = STATE_NTP; |
327 break; | 327 break; |
328 | 328 |
329 case chrome::search::Mode::MODE_SEARCH: | 329 case chrome::search::Mode::MODE_SEARCH_SUGGESTIONS: |
330 if (search_model()->mode().animate && state_ == STATE_NTP) { | 330 if (search_model()->mode().animate && state_ == STATE_NTP) |
331 new_state = STATE_ANIMATING; | 331 new_state = STATE_NTP_ANIMATING; |
332 } else { | 332 else if (omnibox_popup_view_parent_->is_child_visible()) |
333 // Only enter into MODE_SEARCH if the omnibox is visible. | 333 new_state = STATE_SUGGESTIONS; |
334 if (omnibox_popup_view_parent_->is_child_visible()) | 334 break; |
335 new_state = STATE_SEARCH; | 335 |
336 else | 336 case chrome::search::Mode::MODE_SEARCH_RESULTS: |
337 new_state = STATE_NOT_VISIBLE; | 337 new_state = STATE_NOT_VISIBLE; |
338 } | |
339 break; | 338 break; |
340 } | 339 } |
341 SetState(new_state); | 340 SetState(new_state); |
342 } | 341 } |
343 | 342 |
344 void SearchViewController::SetState(State state) { | 343 void SearchViewController::SetState(State state) { |
345 if (state_ == state) | 344 if (state_ == state) |
346 return; | 345 return; |
347 | 346 |
348 State old_state = state_; | 347 State old_state = state_; |
349 state_ = state; | 348 state_ = state; |
350 switch (state_) { | 349 switch (state_) { |
351 case STATE_NOT_VISIBLE: | 350 case STATE_NOT_VISIBLE: |
352 DestroyViews(); | 351 DestroyViews(); |
353 break; | 352 break; |
354 | 353 |
355 case STATE_NTP: | 354 case STATE_NTP: |
356 DestroyViews(); | 355 DestroyViews(); |
357 CreateViews(); | 356 CreateViews(); |
358 break; | 357 break; |
359 | 358 |
360 case STATE_ANIMATING: | 359 case STATE_NTP_ANIMATING: |
361 // Should only animate from the ntp. | 360 // Should only animate from the ntp. |
362 DCHECK_EQ(STATE_NTP, old_state); | 361 DCHECK_EQ(STATE_NTP, old_state); |
363 StartAnimation(); | 362 StartAnimation(); |
364 break; | 363 break; |
365 | 364 |
366 case STATE_SEARCH: | 365 case STATE_SUGGESTIONS: |
367 DestroyViews(); | 366 DestroyViews(); |
368 CreateViews(); | 367 CreateViews(); |
369 ntp_view_->SetVisible(false); | 368 ntp_view_->SetVisible(false); |
370 break; | 369 break; |
371 } | 370 } |
372 } | 371 } |
373 | 372 |
374 void SearchViewController::StartAnimation() { | 373 void SearchViewController::StartAnimation() { |
375 int factor = InstantUI::GetSlowAnimationScaleFactor(); | 374 int factor = InstantUI::GetSlowAnimationScaleFactor(); |
376 { | 375 { |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 ntp_view_ = NULL; | 469 ntp_view_ = NULL; |
471 logo_view_ = NULL; | 470 logo_view_ = NULL; |
472 content_view_ = NULL; | 471 content_view_ = NULL; |
473 | 472 |
474 state_ = STATE_NOT_VISIBLE; | 473 state_ = STATE_NOT_VISIBLE; |
475 } | 474 } |
476 | 475 |
477 void SearchViewController::PopupVisibilityChanged() { | 476 void SearchViewController::PopupVisibilityChanged() { |
478 // 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 |
479 // prematurely cancel the animation. | 478 // prematurely cancel the animation. |
480 if (state_ != STATE_ANIMATING || | 479 if (state_ != STATE_NTP_ANIMATING || |
481 !omnibox_popup_view_parent_->is_child_visible()) { | 480 !omnibox_popup_view_parent_->is_child_visible()) { |
482 UpdateState(); | 481 UpdateState(); |
483 } | 482 } |
484 } | 483 } |
485 | 484 |
486 chrome::search::SearchModel* SearchViewController::search_model() { | 485 chrome::search::SearchModel* SearchViewController::search_model() { |
487 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; | 486 return tab_contents_ ? tab_contents_->search_tab_helper()->model() : NULL; |
488 } | 487 } |
489 | 488 |
490 content::WebContents* SearchViewController::web_contents() { | 489 content::WebContents* SearchViewController::web_contents() { |
491 return tab_contents_ ? tab_contents_->web_contents() : NULL; | 490 return tab_contents_ ? tab_contents_->web_contents() : NULL; |
492 } | 491 } |
OLD | NEW |