1 // Copyright (c) 2012 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 #ifndef CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_CONTROLLER_H_
6 #define CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_CONTROLLER_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "content/public/browser/notification_observer.h"
11 #include "content/public/browser/notification_registrar.h"
23 class FindBarController
: public content::NotificationObserver
{
25 // An enum listing the possible actions to take on a find-in-page selection
26 // in the page when ending the find session.
27 enum SelectionAction
{
28 kKeepSelectionOnPage
, // Translate the find selection into a normal
30 kClearSelectionOnPage
, // Clear the find selection.
31 kActivateSelectionOnPage
// Focus and click the selected node (for links).
34 // An enum listing the possible actions to take on a find-in-page results in
35 // the Find box when ending the find session.
37 kClearResultsInFindBox
, // Clear search string, ordinal and match count.
38 kKeepResultsInFindBox
, // Leave the results untouched.
41 // FindBar takes ownership of |find_bar_view|.
42 explicit FindBarController(FindBar
* find_bar
);
44 virtual ~FindBarController();
46 // Shows the find bar. Any previous search string will again be visible.
49 // Ends the current session. |selection_action| specifies what to do with the
50 // selection on the page created by the find operation. |results_action|
51 // specifies what to do with the contents of the Find box (after ending).
52 void EndFindSession(SelectionAction selection_action
,
53 ResultAction results_action
);
55 // Accessor for the attached WebContents.
56 content::WebContents
* web_contents() const { return web_contents_
; }
58 // Changes the WebContents that this FindBar is attached to. This
59 // occurs when the user switches tabs in the Browser window. |contents| can be
61 void ChangeWebContents(content::WebContents
* contents
);
63 // Overridden from content::NotificationObserver:
64 virtual void Observe(int type
,
65 const content::NotificationSource
& source
,
66 const content::NotificationDetails
& details
) OVERRIDE
;
68 FindBar
* find_bar() const { return find_bar_
.get(); }
70 // Reposition |view_location| such that it avoids |avoid_overlapping_rect|,
71 // and return the new location.
72 static gfx::Rect
GetLocationForFindbarView(
73 gfx::Rect view_location
,
74 const gfx::Rect
& dialog_bounds
,
75 const gfx::Rect
& avoid_overlapping_rect
);
78 // Sents an update to the find bar with the tab contents' current result. The
79 // web_contents_ must be non-NULL before this call. Theis handles
80 // de-flickering in addition to just calling the update function.
81 void UpdateFindBarForCurrentResult();
83 // For Windows and Linux this function sets the prepopulate text for the
84 // Find text box. The propopulate value is the last value the user searched
85 // for in the current tab, or (if blank) the last value searched for in any
86 // tab. Mac has a global value for search, so this function does nothing on
88 void MaybeSetPrepopulateText();
90 content::NotificationRegistrar registrar_
;
92 scoped_ptr
<FindBar
> find_bar_
;
94 // The WebContents we are currently associated with. Can be NULL.
95 content::WebContents
* web_contents_
;
97 // The last match count we reported to the user. This is used by
98 // UpdateFindBarForCurrentResult to avoid flickering.
99 int last_reported_matchcount_
;
101 DISALLOW_COPY_AND_ASSIGN(FindBarController
);
104 #endif // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_CONTROLLER_H_