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
3 // found in the LICENSE file.
5 #import <Cocoa/Cocoa.h>
6 #include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
8 #include "base/strings/sys_string_conversions.h"
9 #import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
12 bool FindBarBridge::disable_animations_during_testing_ = false;
14 FindBarBridge::FindBarBridge(Browser* browser)
15 : find_bar_controller_(NULL) {
16 cocoa_controller_ = [[FindBarCocoaController alloc] initWithBrowser:browser];
17 [cocoa_controller_ setFindBarBridge:this];
20 FindBarBridge::~FindBarBridge() {
21 [cocoa_controller_ release];
24 void FindBarBridge::SetFindBarController(
25 FindBarController* find_bar_controller) {
26 find_bar_controller_ = find_bar_controller;
29 FindBarController* FindBarBridge::GetFindBarController() const {
30 return find_bar_controller_;
33 FindBarTesting* FindBarBridge::GetFindBarTesting() {
37 void FindBarBridge::Show(bool animate) {
38 bool really_animate = animate && !disable_animations_during_testing_;
39 [cocoa_controller_ showFindBar:(really_animate ? YES : NO)];
42 void FindBarBridge::Hide(bool animate) {
43 bool really_animate = animate && !disable_animations_during_testing_;
44 [cocoa_controller_ hideFindBar:(really_animate ? YES : NO)];
47 void FindBarBridge::SetFocusAndSelection() {
48 [cocoa_controller_ setFocusAndSelection];
51 void FindBarBridge::ClearResults(const FindNotificationDetails& results) {
52 [cocoa_controller_ clearResults:results];
55 void FindBarBridge::SetFindText(const string16& find_text) {
56 [cocoa_controller_ setFindText:base::SysUTF16ToNSString(find_text)];
59 string16 FindBarBridge::GetFindText() {
60 return base::SysNSStringToUTF16([cocoa_controller_ findText]);
63 void FindBarBridge::UpdateUIForFindResult(const FindNotificationDetails& result,
64 const string16& find_text) {
65 [cocoa_controller_ updateUIForFindResult:result withText:find_text];
68 void FindBarBridge::AudibleAlert() {
69 // Beep beep, beep beep, Yeah!
73 bool FindBarBridge::IsFindBarVisible() {
74 return [cocoa_controller_ isFindBarVisible] ? true : false;
77 void FindBarBridge::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
79 // See FindBarCocoaController moveFindBarToAvoidRect.
82 void FindBarBridge::StopAnimation() {
83 [cocoa_controller_ stopAnimation];
86 void FindBarBridge::RestoreSavedFocus() {
87 [cocoa_controller_ restoreSavedFocus];
90 bool FindBarBridge::HasGlobalFindPasteboard() {
94 void FindBarBridge::UpdateFindBarForChangedWebContents() {
95 [cocoa_controller_ updateFindBarForChangedWebContents];
98 bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position,
99 bool* fully_visible) {
100 NSWindow* window = [[cocoa_controller_ view] window];
101 bool window_visible = [window isVisible] ? true : false;
104 *position = [cocoa_controller_ findBarWindowPosition];
106 *position = gfx::Point(0, 0);
109 *fully_visible = window_visible &&
110 [cocoa_controller_ isFindBarVisible] &&
111 ![cocoa_controller_ isFindBarAnimating];
113 return window_visible;
116 string16 FindBarBridge::GetFindSelectedText() {
117 // This function is currently only used in Views.
122 string16 FindBarBridge::GetMatchCountText() {
123 return base::SysNSStringToUTF16([cocoa_controller_ matchCountText]);
126 int FindBarBridge::GetWidth() {
127 return [cocoa_controller_ findBarWidth];