| OLD | NEW |
| 1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2009 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/views/find_bar_host.h" | 5 #include "chrome/browser/views/find_bar_host.h" |
| 6 | 6 |
| 7 #include "app/slide_animation.h" | 7 #include "app/slide_animation.h" |
| 8 #include "base/keyboard_codes.h" | 8 #include "base/keyboard_codes.h" |
| 9 #include "chrome/browser/browser.h" | 9 #include "chrome/browser/browser.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 46 host_.reset(CreateHost()); | 46 host_.reset(CreateHost()); |
| 47 host_->Init(GetNativeView(browser_view), gfx::Rect()); | 47 host_->Init(GetNativeView(browser_view), gfx::Rect()); |
| 48 host_->SetContentsView(view_); | 48 host_->SetContentsView(view_); |
| 49 | 49 |
| 50 // Start listening to focus changes, so we can register and unregister our | 50 // Start listening to focus changes, so we can register and unregister our |
| 51 // own handler for Escape. | 51 // own handler for Escape. |
| 52 focus_manager_ = | 52 focus_manager_ = |
| 53 views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView()); | 53 views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView()); |
| 54 if (focus_manager_) { | 54 if (focus_manager_) { |
| 55 focus_manager_->AddFocusChangeListener(this); | 55 focus_manager_->AddFocusChangeListener(this); |
| 56 | |
| 57 // Stores the currently focused view, and tracks focus changes so that we | |
| 58 // can restore focus when the find box is closed. | |
| 59 focus_tracker_.reset(new views::ExternalFocusTracker(view_, | |
| 60 focus_manager_)); | |
| 61 } else { | 56 } else { |
| 62 // In some cases (see bug http://crbug.com/17056) it seems we may not have | 57 // In some cases (see bug http://crbug.com/17056) it seems we may not have |
| 63 // a focus manager. Please reopen the bug if you hit this. | 58 // a focus manager. Please reopen the bug if you hit this. |
| 64 NOTREACHED(); | 59 NOTREACHED(); |
| 65 } | 60 } |
| 66 | 61 |
| 67 // Start the process of animating the opening of the window. | 62 // Start the process of animating the opening of the window. |
| 68 animation_.reset(new SlideAnimation(this)); | 63 animation_.reset(new SlideAnimation(this)); |
| 69 } | 64 } |
| 70 | 65 |
| 71 FindBarHost::~FindBarHost() { | 66 FindBarHost::~FindBarHost() { |
| 72 focus_manager_->RemoveFocusChangeListener(this); | 67 focus_manager_->RemoveFocusChangeListener(this); |
| 73 focus_tracker_.reset(NULL); | 68 focus_tracker_.reset(NULL); |
| 74 } | 69 } |
| 75 | 70 |
| 76 void FindBarHost::Show() { | 71 void FindBarHost::Show() { |
| 72 // Stores the currently focused view, and tracks focus changes so that we can |
| 73 // restore focus when the find box is closed. |
| 74 focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager_)); |
| 75 |
| 77 if (disable_animations_during_testing_) { | 76 if (disable_animations_during_testing_) { |
| 78 animation_->Reset(1); | 77 animation_->Reset(1); |
| 79 MoveWindowIfNecessary(gfx::Rect(), true); | 78 MoveWindowIfNecessary(gfx::Rect(), true); |
| 80 } else { | 79 } else { |
| 81 animation_->Reset(); | 80 animation_->Reset(); |
| 82 animation_->Show(); | 81 animation_->Show(); |
| 83 } | 82 } |
| 84 } | 83 } |
| 85 | 84 |
| 86 void FindBarHost::SetFocusAndSelection() { | 85 void FindBarHost::SetFocusAndSelection() { |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 | 372 |
| 374 RenderViewHost* render_view_host = contents->render_view_host(); | 373 RenderViewHost* render_view_host = contents->render_view_host(); |
| 375 | 374 |
| 376 // Make sure we don't have a text field element interfering with keyboard | 375 // Make sure we don't have a text field element interfering with keyboard |
| 377 // input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom". | 376 // input. Otherwise Up and Down arrow key strokes get eaten. "Nom Nom Nom". |
| 378 render_view_host->ClearFocusedNode(); | 377 render_view_host->ClearFocusedNode(); |
| 379 NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_stroke); | 378 NativeWebKeyboardEvent event = GetKeyboardEvent(contents, key_stroke); |
| 380 render_view_host->ForwardKeyboardEvent(event); | 379 render_view_host->ForwardKeyboardEvent(event); |
| 381 return true; | 380 return true; |
| 382 } | 381 } |
| OLD | NEW |