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>
7 #include "base/mac/scoped_nsobject.h"
8 #include "base/strings/string16.h"
9 #import "chrome/browser/ui/cocoa/has_weak_browser_pointer.h"
10 #include "ui/gfx/geometry/point.h"
14 @
class FindBarTextField
;
15 class FindNotificationDetails
;
18 // A controller for the find bar in the browser window. Manages
19 // updating the state of the find bar and provides a target for the
20 // next/previous/close buttons. Certain operations require a pointer
21 // to the cross-platform FindBarController, so be sure to call
22 // setFindBarBridge: after creating this controller.
24 @interface FindBarCocoaController
: NSViewController
<HasWeakBrowserPointer
> {
26 IBOutlet NSView
* findBarView_
;
27 IBOutlet FindBarTextField
* findText_
;
28 IBOutlet NSButton
* nextButton_
;
29 IBOutlet NSButton
* previousButton_
;
30 IBOutlet NSButton
* closeButton_
;
32 // Needed to call methods on FindBarController.
33 FindBarBridge
* findBarBridge_
; // weak
37 base::scoped_nsobject
<FocusTracker
> focusTracker_
;
39 // The show/hide animation. This is defined to be non-nil if the
40 // animation is running, and is always nil otherwise. The
41 // FindBarCocoaController should not be deallocated while an animation is
42 // running (stopAnimation is currently called before the last tab in a
43 // window is removed).
44 base::scoped_nsobject
<NSViewAnimation
> showHideAnimation_
;
46 // The horizontal-moving animation, to avoid occluding find results. This
47 // is nil when the animation is not running, and is also stopped by
49 base::scoped_nsobject
<NSViewAnimation
> moveAnimation_
;
51 // If YES, do nothing as a result of find pasteboard update notifications.
52 BOOL suppressPboardUpdateActions_
;
54 // Vertical point of attachment of the FindBar.
57 // Default width of FindBar.
58 CGFloat defaultWidth_
;
61 @
property (readonly
, nonatomic
) NSView
* findBarView
;
63 // Initializes a new FindBarCocoaController.
64 - (id
)initWithBrowser
:(Browser
*)browser
;
66 - (void)setFindBarBridge
:(FindBarBridge
*)findBar
;
68 - (IBAction
)close
:(id
)sender
;
70 - (IBAction
)nextResult
:(id
)sender
;
72 - (IBAction
)previousResult
:(id
)sender
;
74 // Position the find bar at the given maximum y-coordinate (the min-y of the
75 // bar -- toolbar + possibly bookmark bar, but not including the infobars) with
76 // the given maximum width (i.e., the find bar should fit between 0 and
78 - (void)positionFindBarViewAtMaxY
:(CGFloat
)maxY maxWidth
:(CGFloat
)maxWidth
;
80 // Methods called from FindBarBridge.
81 - (void)showFindBar
:(BOOL
)animate
;
82 - (void)hideFindBar
:(BOOL
)animate
;
83 - (void)stopAnimation
;
84 - (void)setFocusAndSelection
;
85 - (void)restoreSavedFocus
;
86 - (void)setFindText
:(NSString
*)findText
87 selectedRange
:(const NSRange
&)selectedRange
;
88 - (NSString
*)findText
;
89 - (NSRange
)selectedRange
;
90 - (NSString
*)matchCountText
;
91 - (void)updateFindBarForChangedWebContents
;
93 - (void)clearResults
:(const FindNotificationDetails
&)results
;
94 - (void)updateUIForFindResult
:(const FindNotificationDetails
&)results
95 withText
:(const base::string16
&)findText
;
96 - (BOOL
)isFindBarVisible
;
97 - (BOOL
)isFindBarAnimating
;
99 // Returns the FindBar's position in the superview's coordinates, but with
100 // the Y coordinate growing down.
101 - (gfx::Point
)findBarWindowPosition
;
103 // Returns the width of the FindBar.