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