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