• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright (c) 2010 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.
4
5#import <Cocoa/Cocoa.h>
6#include "chrome/browser/ui/cocoa/find_bar/find_bar_bridge.h"
7
8#include "base/sys_string_conversions.h"
9#import "chrome/browser/ui/cocoa/find_bar/find_bar_cocoa_controller.h"
10
11// static
12bool FindBarBridge::disable_animations_during_testing_ = false;
13
14FindBarBridge::FindBarBridge()
15    : find_bar_controller_(NULL) {
16  cocoa_controller_ = [[FindBarCocoaController alloc] init];
17  [cocoa_controller_ setFindBarBridge:this];
18}
19
20FindBarBridge::~FindBarBridge() {
21  [cocoa_controller_ release];
22}
23
24void FindBarBridge::SetFindBarController(
25    FindBarController* find_bar_controller) {
26  find_bar_controller_ = find_bar_controller;
27}
28
29FindBarController* FindBarBridge::GetFindBarController() const {
30  return find_bar_controller_;
31}
32
33FindBarTesting* FindBarBridge::GetFindBarTesting() {
34  return this;
35}
36
37void FindBarBridge::Show(bool animate) {
38  bool really_animate = animate && !disable_animations_during_testing_;
39  [cocoa_controller_ showFindBar:(really_animate ? YES : NO)];
40}
41
42void FindBarBridge::Hide(bool animate) {
43  bool really_animate = animate && !disable_animations_during_testing_;
44  [cocoa_controller_ hideFindBar:(really_animate ? YES : NO)];
45}
46
47void FindBarBridge::SetFocusAndSelection() {
48  [cocoa_controller_ setFocusAndSelection];
49}
50
51void FindBarBridge::ClearResults(const FindNotificationDetails& results) {
52  [cocoa_controller_ clearResults:results];
53}
54
55void FindBarBridge::SetFindText(const string16& find_text) {
56  [cocoa_controller_ setFindText:base::SysUTF16ToNSString(find_text)];
57}
58
59void FindBarBridge::UpdateUIForFindResult(const FindNotificationDetails& result,
60                                          const string16& find_text) {
61  [cocoa_controller_ updateUIForFindResult:result withText:find_text];
62}
63
64void FindBarBridge::AudibleAlert() {
65  // Beep beep, beep beep, Yeah!
66  NSBeep();
67}
68
69bool FindBarBridge::IsFindBarVisible() {
70  return [cocoa_controller_ isFindBarVisible] ? true : false;
71}
72
73void FindBarBridge::MoveWindowIfNecessary(const gfx::Rect& selection_rect,
74                                          bool no_redraw) {
75  // See FindBarCocoaController moveFindBarToAvoidRect.
76}
77
78void FindBarBridge::StopAnimation() {
79  [cocoa_controller_ stopAnimation];
80}
81
82void FindBarBridge::RestoreSavedFocus() {
83  [cocoa_controller_ restoreSavedFocus];
84}
85
86bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position,
87                                         bool* fully_visible) {
88  NSWindow* window = [[cocoa_controller_ view] window];
89  bool window_visible = [window isVisible] ? true : false;
90  if (position) {
91    if (window_visible)
92      *position = [cocoa_controller_ findBarWindowPosition];
93    else
94      *position = gfx::Point(0, 0);
95  }
96  if (fully_visible) {
97    *fully_visible = window_visible &&
98        [cocoa_controller_ isFindBarVisible] &&
99        ![cocoa_controller_ isFindBarAnimating];
100  }
101  return window_visible;
102}
103
104string16 FindBarBridge::GetFindText() {
105  // This function is currently only used in Windows and Linux specific browser
106  // tests (testing prepopulate values that Mac's don't rely on), but if we add
107  // more tests that are non-platform specific, we need to flesh out this
108  // function.
109  NOTIMPLEMENTED();
110  return string16();
111}
112
113string16 FindBarBridge::GetFindSelectedText() {
114  // This function is currently only used in Windows and Linux specific browser
115  // tests (testing prepopulate values that Mac's don't rely on), but if we add
116  // more tests that are non-platform specific, we need to flesh out this
117  // function.
118  NOTIMPLEMENTED();
119  return string16();
120}
121
122string16 FindBarBridge::GetMatchCountText() {
123  // This function is currently only used in Windows and Linux specific browser
124  // tests (testing prepopulate values that Mac's don't rely on), but if we add
125  // more tests that are non-platform specific, we need to flesh out this
126  // function.
127  NOTIMPLEMENTED();
128  return string16();
129}
130