• 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 #ifndef CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
6 #define CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
7 #pragma once
8 
9 #include "base/logging.h"
10 #include "chrome/browser/ui/find_bar/find_bar.h"
11 
12 class FindBarController;
13 
14 // This class is included by find_bar_host_browsertest.cc, so it has to be
15 // objc-free.
16 #ifdef __OBJC__
17 @class FindBarCocoaController;
18 #else
19 class FindBarCocoaController;
20 #endif
21 
22 // Implementation of FindBar for the Mac.  This class simply passes
23 // each message along to |cocoa_controller_|.
24 //
25 // The initialization here is a bit complicated.  FindBarBridge is
26 // created by a static method in BrowserWindow.  The FindBarBridge
27 // constructor creates a FindBarCocoaController, which in turn loads a
28 // FindBarView from a nib file.  All of this is happening outside of
29 // the main view hierarchy, so the static method also calls
30 // BrowserWindowCocoa::AddFindBar() in order to add its FindBarView to
31 // the cocoa views hierarchy.
32 //
33 // Memory ownership is relatively straightforward.  The FindBarBridge
34 // object is owned by the Browser.  FindBarCocoaController is retained
35 // by bother FindBarBridge and BrowserWindowController, since both use it.
36 
37 class FindBarBridge : public FindBar,
38                       public FindBarTesting {
39  public:
40   FindBarBridge();
41   virtual ~FindBarBridge();
42 
find_bar_cocoa_controller()43   FindBarCocoaController* find_bar_cocoa_controller() {
44     return cocoa_controller_;
45   }
46 
47   virtual void SetFindBarController(FindBarController* find_bar_controller);
48 
49   virtual FindBarController* GetFindBarController() const;
50 
51   virtual FindBarTesting* GetFindBarTesting();
52 
53   // Methods from FindBar.
54   virtual void Show(bool animate);
55   virtual void Hide(bool animate);
56   virtual void SetFocusAndSelection();
57   virtual void ClearResults(const FindNotificationDetails& results);
58   virtual void StopAnimation();
59   virtual void SetFindText(const string16& find_text);
60   virtual void UpdateUIForFindResult(const FindNotificationDetails& result,
61                                      const string16& find_text);
62   virtual void AudibleAlert();
63   virtual bool IsFindBarVisible();
64   virtual void RestoreSavedFocus();
65   virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect,
66                                      bool no_redraw);
67 
68   // Methods from FindBarTesting.
69   virtual bool GetFindBarWindowInfo(gfx::Point* position,
70                                     bool* fully_visible);
71   virtual string16 GetFindText();
72   virtual string16 GetFindSelectedText();
73   virtual string16 GetMatchCountText();
74 
75   // Used to disable find bar animations when testing.
76   static bool disable_animations_during_testing_;
77 
78  private:
79   // Pointer to the cocoa controller which manages the cocoa view.  Is
80   // never nil.
81   FindBarCocoaController* cocoa_controller_;
82 
83   // Pointer back to the owning controller.
84   FindBarController* find_bar_controller_;  // weak, owns us
85 
86   DISALLOW_COPY_AND_ASSIGN(FindBarBridge);
87 };
88 
89 #endif  // CHROME_BROWSER_UI_COCOA_FIND_BAR_FIND_BAR_BRIDGE_H_
90