| OLD | NEW |
| 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "views/focus/focus_manager.h" | 5 #include "views/focus/focus_manager.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "build/build_config.h" | 9 #include "build/build_config.h" |
| 10 | 10 |
| (...skipping 342 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 353 View* FocusManager::GetNextFocusableView(View* original_starting_view, | 353 View* FocusManager::GetNextFocusableView(View* original_starting_view, |
| 354 bool reverse, | 354 bool reverse, |
| 355 bool dont_loop) { | 355 bool dont_loop) { |
| 356 FocusTraversable* focus_traversable = NULL; | 356 FocusTraversable* focus_traversable = NULL; |
| 357 | 357 |
| 358 // Let's revalidate the focused view. | 358 // Let's revalidate the focused view. |
| 359 ValidateFocusedView(); | 359 ValidateFocusedView(); |
| 360 | 360 |
| 361 View* starting_view = NULL; | 361 View* starting_view = NULL; |
| 362 if (original_starting_view) { | 362 if (original_starting_view) { |
| 363 // If the starting view has a focus traversable, use it. | 363 if (!reverse) { |
| 364 // This is the case with WidgetWins for example. | 364 // If the starting view has a focus traversable, use it. |
| 365 focus_traversable = original_starting_view->GetFocusTraversable(); | 365 // This is the case with WidgetWins for example. |
| 366 focus_traversable = original_starting_view->GetFocusTraversable(); |
| 366 | 367 |
| 367 // Otherwise default to the root view. | 368 // Otherwise default to the root view. |
| 368 if (!focus_traversable) { | 369 if (!focus_traversable) { |
| 370 focus_traversable = original_starting_view->GetRootView(); |
| 371 starting_view = original_starting_view; |
| 372 } |
| 373 } else { |
| 374 // When you are going back, starting view's FocusTraversable should not be |
| 375 // used. |
| 369 focus_traversable = original_starting_view->GetRootView(); | 376 focus_traversable = original_starting_view->GetRootView(); |
| 370 starting_view = original_starting_view; | 377 starting_view = original_starting_view; |
| 371 } | 378 } |
| 372 } else { | 379 } else { |
| 373 focus_traversable = top_root_view_; | 380 focus_traversable = top_root_view_; |
| 374 } | 381 } |
| 375 | 382 |
| 376 // Traverse the FocusTraversable tree down to find the focusable view. | 383 // Traverse the FocusTraversable tree down to find the focusable view. |
| 377 View* v = FindFocusableView(focus_traversable, starting_view, | 384 View* v = FindFocusableView(focus_traversable, starting_view, reverse); |
| 378 reverse, dont_loop); | |
| 379 if (v) { | 385 if (v) { |
| 380 return v; | 386 return v; |
| 381 } else { | 387 } else { |
| 382 // Let's go up in the FocusTraversable tree. | 388 // Let's go up in the FocusTraversable tree. |
| 383 FocusTraversable* parent_focus_traversable = | 389 FocusTraversable* parent_focus_traversable = |
| 384 focus_traversable->GetFocusTraversableParent(); | 390 focus_traversable->GetFocusTraversableParent(); |
| 385 starting_view = focus_traversable->GetFocusTraversableParentView(); | 391 starting_view = focus_traversable->GetFocusTraversableParentView(); |
| 386 while (parent_focus_traversable) { | 392 while (parent_focus_traversable) { |
| 387 FocusTraversable* new_focus_traversable = NULL; | 393 FocusTraversable* new_focus_traversable = NULL; |
| 388 View* new_starting_view = NULL; | 394 View* new_starting_view = NULL; |
| 389 v = parent_focus_traversable ->FindNextFocusableView( | 395 // When we are going backward, the parent view might gain the next focus. |
| 390 starting_view, reverse, FocusTraversable::UP, dont_loop, | 396 bool check_starting_view = reverse; |
| 391 &new_focus_traversable, &new_starting_view); | 397 v = parent_focus_traversable->FindNextFocusableView( |
| 398 starting_view, reverse, FocusTraversable::UP, |
| 399 check_starting_view, &new_focus_traversable, &new_starting_view); |
| 392 | 400 |
| 393 if (new_focus_traversable) { | 401 if (new_focus_traversable) { |
| 394 DCHECK(!v); | 402 DCHECK(!v); |
| 395 | 403 |
| 396 // There is a FocusTraversable, traverse it down. | 404 // There is a FocusTraversable, traverse it down. |
| 397 v = FindFocusableView(new_focus_traversable, NULL, reverse, dont_loop); | 405 v = FindFocusableView(new_focus_traversable, NULL, reverse); |
| 398 } | 406 } |
| 399 | 407 |
| 400 if (v) | 408 if (v) |
| 401 return v; | 409 return v; |
| 402 | 410 |
| 403 starting_view = focus_traversable->GetFocusTraversableParentView(); | 411 starting_view = focus_traversable->GetFocusTraversableParentView(); |
| 404 parent_focus_traversable = | 412 parent_focus_traversable = |
| 405 parent_focus_traversable->GetFocusTraversableParent(); | 413 parent_focus_traversable->GetFocusTraversableParent(); |
| 406 } | 414 } |
| 407 | 415 |
| (...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 556 return NULL; | 564 return NULL; |
| 557 | 565 |
| 558 return GetFocusManager(parent); | 566 return GetFocusManager(parent); |
| 559 } | 567 } |
| 560 | 568 |
| 561 // Find the next (previous if reverse is true) focusable view for the specified | 569 // Find the next (previous if reverse is true) focusable view for the specified |
| 562 // FocusTraversable, starting at the specified view, traversing down the | 570 // FocusTraversable, starting at the specified view, traversing down the |
| 563 // FocusTraversable hierarchy. | 571 // FocusTraversable hierarchy. |
| 564 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable, | 572 View* FocusManager::FindFocusableView(FocusTraversable* focus_traversable, |
| 565 View* starting_view, | 573 View* starting_view, |
| 566 bool reverse, | 574 bool reverse) { |
| 567 bool dont_loop) { | |
| 568 FocusTraversable* new_focus_traversable = NULL; | 575 FocusTraversable* new_focus_traversable = NULL; |
| 569 View* new_starting_view = NULL; | 576 View* new_starting_view = NULL; |
| 570 View* v = focus_traversable->FindNextFocusableView(starting_view, | 577 View* v = focus_traversable->FindNextFocusableView(starting_view, |
| 571 reverse, | 578 reverse, |
| 572 FocusTraversable::DOWN, | 579 FocusTraversable::DOWN, |
| 573 dont_loop, | 580 false, |
| 574 &new_focus_traversable, | 581 &new_focus_traversable, |
| 575 &new_starting_view); | 582 &new_starting_view); |
| 576 | 583 |
| 577 // Let's go down the FocusTraversable tree as much as we can. | 584 // Let's go down the FocusTraversable tree as much as we can. |
| 578 while (new_focus_traversable) { | 585 while (new_focus_traversable) { |
| 579 DCHECK(!v); | 586 DCHECK(!v); |
| 580 focus_traversable = new_focus_traversable; | 587 focus_traversable = new_focus_traversable; |
| 581 starting_view = new_starting_view; | 588 starting_view = new_starting_view; |
| 582 new_focus_traversable = NULL; | 589 new_focus_traversable = NULL; |
| 583 starting_view = NULL; | 590 starting_view = NULL; |
| 584 v = focus_traversable->FindNextFocusableView(starting_view, | 591 v = focus_traversable->FindNextFocusableView(starting_view, |
| 585 reverse, | 592 reverse, |
| 586 FocusTraversable::DOWN, | 593 FocusTraversable::DOWN, |
| 587 dont_loop, | 594 false, |
| 588 &new_focus_traversable, | 595 &new_focus_traversable, |
| 589 &new_starting_view); | 596 &new_starting_view); |
| 590 } | 597 } |
| 591 return v; | 598 return v; |
| 592 } | 599 } |
| 593 | 600 |
| 594 void FocusManager::RegisterAccelerator( | 601 void FocusManager::RegisterAccelerator( |
| 595 const Accelerator& accelerator, | 602 const Accelerator& accelerator, |
| 596 AcceleratorTarget* target) { | 603 AcceleratorTarget* target) { |
| 597 AcceleratorTargetList& targets = accelerators_[accelerator]; | 604 AcceleratorTargetList& targets = accelerators_[accelerator]; |
| (...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 703 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), | 710 std::find(focus_change_listeners_.begin(), focus_change_listeners_.end(), |
| 704 listener); | 711 listener); |
| 705 if (place == focus_change_listeners_.end()) { | 712 if (place == focus_change_listeners_.end()) { |
| 706 NOTREACHED() << "Removing a listener that isn't registered."; | 713 NOTREACHED() << "Removing a listener that isn't registered."; |
| 707 return; | 714 return; |
| 708 } | 715 } |
| 709 focus_change_listeners_.erase(place); | 716 focus_change_listeners_.erase(place); |
| 710 } | 717 } |
| 711 | 718 |
| 712 } // namespace views | 719 } // namespace views |
| OLD | NEW |