OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/find_bar_host.h" | 5 #include "chrome/browser/ui/views/find_bar_host.h" |
6 | 6 |
7 #include "app/keyboard_codes.h" | |
8 #include "chrome/browser/renderer_host/render_view_host.h" | 7 #include "chrome/browser/renderer_host/render_view_host.h" |
9 #include "chrome/browser/tab_contents/tab_contents.h" | 8 #include "chrome/browser/tab_contents/tab_contents.h" |
10 #include "chrome/browser/tab_contents/tab_contents_view.h" | 9 #include "chrome/browser/tab_contents/tab_contents_view.h" |
11 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
12 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 11 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
13 #include "chrome/browser/ui/view_ids.h" | 12 #include "chrome/browser/ui/view_ids.h" |
14 #include "chrome/browser/ui/views/find_bar_view.h" | 13 #include "chrome/browser/ui/views/find_bar_view.h" |
15 #include "chrome/browser/ui/views/frame/browser_view.h" | 14 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 15 #include "ui/base/keycodes/keyboard_codes.h" |
16 #include "views/focus/external_focus_tracker.h" | 16 #include "views/focus/external_focus_tracker.h" |
17 #include "views/focus/view_storage.h" | 17 #include "views/focus/view_storage.h" |
18 #include "views/widget/root_view.h" | 18 #include "views/widget/root_view.h" |
19 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
20 | 20 |
21 namespace browser { | 21 namespace browser { |
22 | 22 |
23 // Declared in browser_dialogs.h so others don't have to depend on our header. | 23 // Declared in browser_dialogs.h so others don't have to depend on our header. |
24 FindBar* CreateFindBar(BrowserView* browser_view) { | 24 FindBar* CreateFindBar(BrowserView* browser_view) { |
25 return new FindBarHost(browser_view); | 25 return new FindBarHost(browser_view); |
(...skipping 14 matching lines...) Expand all Loading... |
40 } | 40 } |
41 | 41 |
42 bool FindBarHost::MaybeForwardKeyEventToWebpage( | 42 bool FindBarHost::MaybeForwardKeyEventToWebpage( |
43 const views::KeyEvent& key_event) { | 43 const views::KeyEvent& key_event) { |
44 if (!ShouldForwardKeyEventToWebpageNative(key_event)) { | 44 if (!ShouldForwardKeyEventToWebpageNative(key_event)) { |
45 // Native implementation says not to forward these events. | 45 // Native implementation says not to forward these events. |
46 return false; | 46 return false; |
47 } | 47 } |
48 | 48 |
49 switch (key_event.GetKeyCode()) { | 49 switch (key_event.GetKeyCode()) { |
50 case app::VKEY_DOWN: | 50 case ui::VKEY_DOWN: |
51 case app::VKEY_UP: | 51 case ui::VKEY_UP: |
52 case app::VKEY_PRIOR: | 52 case ui::VKEY_PRIOR: |
53 case app::VKEY_NEXT: | 53 case ui::VKEY_NEXT: |
54 break; | 54 break; |
55 case app::VKEY_HOME: | 55 case ui::VKEY_HOME: |
56 case app::VKEY_END: | 56 case ui::VKEY_END: |
57 if (key_event.IsControlDown()) | 57 if (key_event.IsControlDown()) |
58 break; | 58 break; |
59 // Fall through. | 59 // Fall through. |
60 default: | 60 default: |
61 return false; | 61 return false; |
62 } | 62 } |
63 | 63 |
64 TabContents* contents = find_bar_controller_->tab_contents(); | 64 TabContents* contents = find_bar_controller_->tab_contents(); |
65 if (!contents) | 65 if (!contents) |
66 return false; | 66 return false; |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
157 } | 157 } |
158 | 158 |
159 FindBarTesting* FindBarHost::GetFindBarTesting() { | 159 FindBarTesting* FindBarHost::GetFindBarTesting() { |
160 return this; | 160 return this; |
161 } | 161 } |
162 | 162 |
163 //////////////////////////////////////////////////////////////////////////////// | 163 //////////////////////////////////////////////////////////////////////////////// |
164 // FindBarWin, views::AcceleratorTarget implementation: | 164 // FindBarWin, views::AcceleratorTarget implementation: |
165 | 165 |
166 bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) { | 166 bool FindBarHost::AcceleratorPressed(const views::Accelerator& accelerator) { |
167 app::KeyboardCode key = accelerator.GetKeyCode(); | 167 ui::KeyboardCode key = accelerator.GetKeyCode(); |
168 if (key == app::VKEY_RETURN && accelerator.IsCtrlDown()) { | 168 if (key == ui::VKEY_RETURN && accelerator.IsCtrlDown()) { |
169 // Ctrl+Enter closes the Find session and navigates any link that is active. | 169 // Ctrl+Enter closes the Find session and navigates any link that is active. |
170 find_bar_controller_->EndFindSession(FindBarController::kActivateSelection); | 170 find_bar_controller_->EndFindSession(FindBarController::kActivateSelection); |
171 } else if (key == app::VKEY_ESCAPE) { | 171 } else if (key == ui::VKEY_ESCAPE) { |
172 // This will end the Find session and hide the window, causing it to loose | 172 // This will end the Find session and hide the window, causing it to loose |
173 // focus and in the process unregister us as the handler for the Escape | 173 // focus and in the process unregister us as the handler for the Escape |
174 // accelerator through the FocusWillChange event. | 174 // accelerator through the FocusWillChange event. |
175 find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); | 175 find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); |
176 } else { | 176 } else { |
177 NOTREACHED() << "Unknown accelerator"; | 177 NOTREACHED() << "Unknown accelerator"; |
178 } | 178 } |
179 | 179 |
180 return true; | 180 return true; |
181 } | 181 } |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 DCHECK(bounds); | 281 DCHECK(bounds); |
282 // The BrowserView does Layout for the components that we care about | 282 // The BrowserView does Layout for the components that we care about |
283 // positioning relative to, so we ask it to tell us where we should go. | 283 // positioning relative to, so we ask it to tell us where we should go. |
284 *bounds = browser_view()->GetFindBarBoundingBox(); | 284 *bounds = browser_view()->GetFindBarBoundingBox(); |
285 } | 285 } |
286 | 286 |
287 void FindBarHost::RegisterAccelerators() { | 287 void FindBarHost::RegisterAccelerators() { |
288 DropdownBarHost::RegisterAccelerators(); | 288 DropdownBarHost::RegisterAccelerators(); |
289 | 289 |
290 // Register for Ctrl+Return. | 290 // Register for Ctrl+Return. |
291 views::Accelerator escape(app::VKEY_RETURN, false, true, false); | 291 views::Accelerator escape(ui::VKEY_RETURN, false, true, false); |
292 focus_manager()->RegisterAccelerator(escape, this); | 292 focus_manager()->RegisterAccelerator(escape, this); |
293 } | 293 } |
294 | 294 |
295 void FindBarHost::UnregisterAccelerators() { | 295 void FindBarHost::UnregisterAccelerators() { |
296 // Unregister Ctrl+Return. | 296 // Unregister Ctrl+Return. |
297 views::Accelerator escape(app::VKEY_RETURN, false, true, false); | 297 views::Accelerator escape(ui::VKEY_RETURN, false, true, false); |
298 focus_manager()->UnregisterAccelerator(escape, this); | 298 focus_manager()->UnregisterAccelerator(escape, this); |
299 | 299 |
300 DropdownBarHost::UnregisterAccelerators(); | 300 DropdownBarHost::UnregisterAccelerators(); |
301 } | 301 } |
302 | 302 |
303 //////////////////////////////////////////////////////////////////////////////// | 303 //////////////////////////////////////////////////////////////////////////////// |
304 // private: | 304 // private: |
305 | 305 |
306 FindBarView* FindBarHost::find_bar_view() { | 306 FindBarView* FindBarHost::find_bar_view() { |
307 return static_cast<FindBarView*>(view()); | 307 return static_cast<FindBarView*>(view()); |
308 } | 308 } |
OLD | NEW |