| 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/find_bar_host.h" | 5 #include "chrome/browser/ui/views/find_bar_host.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" | 9 #include "chrome/browser/ui/find_bar/find_bar_controller.h" |
| 10 #include "chrome/browser/ui/find_bar/find_tab_helper.h" | 10 #include "chrome/browser/ui/find_bar/find_tab_helper.h" |
| (...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 169 } | 169 } |
| 170 | 170 |
| 171 //////////////////////////////////////////////////////////////////////////////// | 171 //////////////////////////////////////////////////////////////////////////////// |
| 172 // FindBarWin, ui::AcceleratorTarget implementation: | 172 // FindBarWin, ui::AcceleratorTarget implementation: |
| 173 | 173 |
| 174 bool FindBarHost::AcceleratorPressed(const ui::Accelerator& accelerator) { | 174 bool FindBarHost::AcceleratorPressed(const ui::Accelerator& accelerator) { |
| 175 ui::KeyboardCode key = accelerator.key_code(); | 175 ui::KeyboardCode key = accelerator.key_code(); |
| 176 if (key == ui::VKEY_RETURN && accelerator.IsCtrlDown()) { | 176 if (key == ui::VKEY_RETURN && accelerator.IsCtrlDown()) { |
| 177 // Ctrl+Enter closes the Find session and navigates any link that is active. | 177 // Ctrl+Enter closes the Find session and navigates any link that is active. |
| 178 find_bar_controller_->EndFindSession(FindBarController::kActivateSelection); | 178 find_bar_controller_->EndFindSession(FindBarController::kActivateSelection); |
| 179 return true; |
| 179 } else if (key == ui::VKEY_ESCAPE) { | 180 } else if (key == ui::VKEY_ESCAPE) { |
| 180 // This will end the Find session and hide the window, causing it to loose | 181 // This will end the Find session and hide the window, causing it to loose |
| 181 // focus and in the process unregister us as the handler for the Escape | 182 // focus and in the process unregister us as the handler for the Escape |
| 182 // accelerator through the OnWillChangeFocus event. | 183 // accelerator through the OnWillChangeFocus event. |
| 183 find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); | 184 find_bar_controller_->EndFindSession(FindBarController::kKeepSelection); |
| 185 return true; |
| 184 } else { | 186 } else { |
| 185 NOTREACHED() << "Unknown accelerator"; | 187 NOTREACHED() << "Unknown accelerator"; |
| 186 } | 188 } |
| 187 | 189 |
| 188 return true; | 190 return false; |
| 189 } | 191 } |
| 190 | 192 |
| 191 bool FindBarHost::CanHandleAccelerators() const { | 193 bool FindBarHost::CanHandleAccelerators() const { |
| 192 return true; | 194 return true; |
| 193 } | 195 } |
| 194 | 196 |
| 195 //////////////////////////////////////////////////////////////////////////////// | 197 //////////////////////////////////////////////////////////////////////////////// |
| 196 // FindBarTesting implementation: | 198 // FindBarTesting implementation: |
| 197 | 199 |
| 198 bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position, | 200 bool FindBarHost::GetFindBarWindowInfo(gfx::Point* position, |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 301 // The BrowserView does Layout for the components that we care about | 303 // The BrowserView does Layout for the components that we care about |
| 302 // positioning relative to, so we ask it to tell us where we should go. | 304 // positioning relative to, so we ask it to tell us where we should go. |
| 303 *bounds = browser_view()->GetFindBarBoundingBox(); | 305 *bounds = browser_view()->GetFindBarBoundingBox(); |
| 304 } | 306 } |
| 305 | 307 |
| 306 void FindBarHost::RegisterAccelerators() { | 308 void FindBarHost::RegisterAccelerators() { |
| 307 DropdownBarHost::RegisterAccelerators(); | 309 DropdownBarHost::RegisterAccelerators(); |
| 308 | 310 |
| 309 // Register for Ctrl+Return. | 311 // Register for Ctrl+Return. |
| 310 ui::Accelerator escape(ui::VKEY_RETURN, false, true, false); | 312 ui::Accelerator escape(ui::VKEY_RETURN, false, true, false); |
| 311 focus_manager()->RegisterAccelerator(escape, this); | 313 focus_manager()->RegisterAccelerator( |
| 314 escape, ui::AcceleratorManager::kNormalPriority, this); |
| 312 } | 315 } |
| 313 | 316 |
| 314 void FindBarHost::UnregisterAccelerators() { | 317 void FindBarHost::UnregisterAccelerators() { |
| 315 // Unregister Ctrl+Return. | 318 // Unregister Ctrl+Return. |
| 316 ui::Accelerator escape(ui::VKEY_RETURN, false, true, false); | 319 ui::Accelerator escape(ui::VKEY_RETURN, false, true, false); |
| 317 focus_manager()->UnregisterAccelerator(escape, this); | 320 focus_manager()->UnregisterAccelerator(escape, this); |
| 318 | 321 |
| 319 DropdownBarHost::UnregisterAccelerators(); | 322 DropdownBarHost::UnregisterAccelerators(); |
| 320 } | 323 } |
| 321 | 324 |
| 322 //////////////////////////////////////////////////////////////////////////////// | 325 //////////////////////////////////////////////////////////////////////////////// |
| 323 // private: | 326 // private: |
| 324 | 327 |
| 325 void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) { | 328 void FindBarHost::GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect) { |
| 326 gfx::Rect frame_rect = host()->GetTopLevelWidget()->GetWindowScreenBounds(); | 329 gfx::Rect frame_rect = host()->GetTopLevelWidget()->GetWindowScreenBounds(); |
| 327 content::WebContentsView* tab_view = | 330 content::WebContentsView* tab_view = |
| 328 find_bar_controller_->tab_contents()->web_contents()->GetView(); | 331 find_bar_controller_->tab_contents()->web_contents()->GetView(); |
| 329 gfx::Rect webcontents_rect; | 332 gfx::Rect webcontents_rect; |
| 330 tab_view->GetViewBounds(&webcontents_rect); | 333 tab_view->GetViewBounds(&webcontents_rect); |
| 331 avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y()); | 334 avoid_overlapping_rect->Offset(0, webcontents_rect.y() - frame_rect.y()); |
| 332 } | 335 } |
| 333 | 336 |
| 334 FindBarView* FindBarHost::find_bar_view() { | 337 FindBarView* FindBarHost::find_bar_view() { |
| 335 return static_cast<FindBarView*>(view()); | 338 return static_cast<FindBarView*>(view()); |
| 336 } | 339 } |
| OLD | NEW |