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"
10 #include "ui/gfx/range/range.h"
13 bool FindBarBridge::disable_animations_during_testing_ = false;
15 FindBarBridge::FindBarBridge(Browser* browser)
16 : find_bar_controller_(NULL) {
17 cocoa_controller_ = [[FindBarCocoaController alloc] initWithBrowser:browser];
18 [cocoa_controller_ setFindBarBridge:this];
21 FindBarBridge::~FindBarBridge() {
22 [cocoa_controller_ release];
25 void FindBarBridge::SetFindBarController(
26 FindBarController* find_bar_controller) {
27 find_bar_controller_ = find_bar_controller;
30 FindBarController* FindBarBridge::GetFindBarController() const {
31 return find_bar_controller_;
34 FindBarTesting* FindBarBridge::GetFindBarTesting() {
38 void FindBarBridge::Show(bool animate) {
39 bool really_animate = animate && !disable_animations_during_testing_;
40 [cocoa_controller_ showFindBar:(really_animate ? YES : NO)];
43 void FindBarBridge::Hide(bool animate) {
44 bool really_animate = animate && !disable_animations_during_testing_;
45 [cocoa_controller_ hideFindBar:(really_animate ? YES : NO)];
48 void FindBarBridge::SetFocusAndSelection() {
49 [cocoa_controller_ setFocusAndSelection];
52 void FindBarBridge::ClearResults(const FindNotificationDetails& results) {
53 [cocoa_controller_ clearResults:results];
56 void FindBarBridge::SetFindTextAndSelectedRange(
57 const base::string16& find_text,
58 const gfx::Range& selected_range) {
59 [cocoa_controller_ setFindText:base::SysUTF16ToNSString(find_text)
60 selectedRange:selected_range.ToNSRange()];
63 base::string16 FindBarBridge::GetFindText() {
64 return base::SysNSStringToUTF16([cocoa_controller_ findText]);
67 gfx::Range FindBarBridge::GetSelectedRange() {
68 return gfx::Range([cocoa_controller_ selectedRange]);
71 void FindBarBridge::UpdateUIForFindResult(const FindNotificationDetails& result,
72 const base::string16& find_text) {
73 [cocoa_controller_ updateUIForFindResult:result withText:find_text];
76 void FindBarBridge::AudibleAlert() {
77 // Beep beep, beep beep, Yeah!
81 bool FindBarBridge::IsFindBarVisible() {
82 return [cocoa_controller_ isFindBarVisible] ? true : false;
85 void FindBarBridge::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
87 // See FindBarCocoaController moveFindBarToAvoidRect.
90 void FindBarBridge::StopAnimation() {
91 [cocoa_controller_ stopAnimation];
94 void FindBarBridge::RestoreSavedFocus() {
95 [cocoa_controller_ restoreSavedFocus];
98 bool FindBarBridge::HasGlobalFindPasteboard() {
102 void FindBarBridge::UpdateFindBarForChangedWebContents() {
103 [cocoa_controller_ updateFindBarForChangedWebContents];
106 bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position,
107 bool* fully_visible) {
108 NSWindow* window = [[cocoa_controller_ view] window];
109 bool window_visible = [window isVisible] ? true : false;
112 *position = [cocoa_controller_ findBarWindowPosition];
114 *position = gfx::Point(0, 0);
117 *fully_visible = window_visible &&
118 [cocoa_controller_ isFindBarVisible] &&
119 ![cocoa_controller_ isFindBarAnimating];
121 return window_visible;
124 base::string16 FindBarBridge::GetFindSelectedText() {
125 // This function is currently only used in Views.
127 return base::string16();
130 base::string16 FindBarBridge::GetMatchCountText() {
131 return base::SysNSStringToUTF16([cocoa_controller_ matchCountText]);
134 int FindBarBridge::GetWidth() {
135 return [cocoa_controller_ findBarWidth];