Add new certificateProvider extension API.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / find_bar / find_bar_bridge.mm
blobd3123e71e5a461d48f6aa61ce1e75e145fcd7a3b
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"
12 // static
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() {
35   return this;
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!
78   NSBeep();
81 bool FindBarBridge::IsFindBarVisible() {
82   return [cocoa_controller_ isFindBarVisible] ? true : false;
85 void FindBarBridge::MoveWindowIfNecessary(const gfx::Rect& selection_rect) {
86   // See FindBarCocoaController moveFindBarToAvoidRect.
89 void FindBarBridge::StopAnimation() {
90   [cocoa_controller_ stopAnimation];
93 void FindBarBridge::RestoreSavedFocus() {
94   [cocoa_controller_ restoreSavedFocus];
97 bool FindBarBridge::HasGlobalFindPasteboard() {
98   return true;
101 void FindBarBridge::UpdateFindBarForChangedWebContents() {
102   [cocoa_controller_ updateFindBarForChangedWebContents];
105 bool FindBarBridge::GetFindBarWindowInfo(gfx::Point* position,
106                                          bool* fully_visible) {
107   NSWindow* window = [[cocoa_controller_ view] window];
108   bool window_visible = [window isVisible] ? true : false;
109   if (position) {
110     if (window_visible)
111       *position = [cocoa_controller_ findBarWindowPosition];
112     else
113       *position = gfx::Point(0, 0);
114   }
115   if (fully_visible) {
116     *fully_visible = window_visible &&
117         [cocoa_controller_ isFindBarVisible] &&
118         ![cocoa_controller_ isFindBarAnimating];
119   }
120   return window_visible;
123 base::string16 FindBarBridge::GetFindSelectedText() {
124   // This function is currently only used in Views.
125   NOTIMPLEMENTED();
126   return base::string16();
129 base::string16 FindBarBridge::GetMatchCountText() {
130   return base::SysNSStringToUTF16([cocoa_controller_ matchCountText]);
133 int FindBarBridge::GetWidth() {
134   return [cocoa_controller_ findBarWidth];