Home | History | Annotate | Download | only in find_bar
      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 // This is an interface for the platform specific FindBar.  It is responsible
      6 // for drawing the FindBar bar on the platform and is owned by the
      7 // FindBarController.
      8 
      9 #ifndef CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_
     10 #define CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_
     11 
     12 #include "base/strings/string16.h"
     13 #include "ui/gfx/rect.h"
     14 
     15 class FindBarController;
     16 class FindBarTesting;
     17 class FindNotificationDetails;
     18 
     19 namespace gfx {
     20 class Range;
     21 }
     22 
     23 class FindBar {
     24  public:
     25   virtual ~FindBar() { }
     26 
     27   // Accessor and setter for the FindBarController.
     28   virtual FindBarController* GetFindBarController() const = 0;
     29   virtual void SetFindBarController(
     30       FindBarController* find_bar_controller) = 0;
     31 
     32   // Shows the find bar. Any previous search string will again be visible.
     33   // If |animate| is true, we try to slide the find bar in.
     34   virtual void Show(bool animate) = 0;
     35 
     36   // Hide the find bar.  If |animate| is true, we try to slide the find bar
     37   // away.
     38   virtual void Hide(bool animate) = 0;
     39 
     40   // Restore the selected text in the find box and focus it.
     41   virtual void SetFocusAndSelection() = 0;
     42 
     43   // Clear the text in the find box.
     44   virtual void ClearResults(const FindNotificationDetails& results) = 0;
     45 
     46   // Stop the animation.
     47   virtual void StopAnimation() = 0;
     48 
     49   // If the find bar obscures the search results we need to move the window. To
     50   // do that we need to know what is selected on the page. We simply calculate
     51   // where it would be if we place it on the left of the selection and if it
     52   // doesn't fit on the screen we try the right side. The parameter
     53   // |selection_rect| is expected to have coordinates relative to the top of
     54   // the web page area. If |no_redraw| is true, the window will be moved without
     55   // redrawing siblings.
     56   virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect,
     57                                      bool no_redraw) = 0;
     58 
     59   // Set the text in the find box.
     60   virtual void SetFindTextAndSelectedRange(
     61       const base::string16& find_text,
     62       const gfx::Range& selected_range) = 0;
     63 
     64   // Gets the search string currently visible in the find box.
     65   virtual base::string16 GetFindText() = 0;
     66 
     67   // Gets the selection.
     68   virtual gfx::Range GetSelectedRange() = 0;
     69 
     70   // Updates the FindBar with the find result details contained within the
     71   // specified |result|.
     72   virtual void UpdateUIForFindResult(const FindNotificationDetails& result,
     73                                      const base::string16& find_text) = 0;
     74 
     75   // No match was found; play an audible alert.
     76   virtual void AudibleAlert() = 0;
     77 
     78   virtual bool IsFindBarVisible() = 0;
     79 
     80   // Upon dismissing the window, restore focus to the last focused view which is
     81   // not FindBarView or any of its children.
     82   virtual void RestoreSavedFocus() = 0;
     83 
     84   // Returns true if all tabs use a single find pasteboard.
     85   virtual bool HasGlobalFindPasteboard() = 0;
     86 
     87   // Called when the web contents associated with the find bar changes.
     88   virtual void UpdateFindBarForChangedWebContents() = 0;
     89 
     90   // Returns a pointer to the testing interface to the FindBar, or NULL
     91   // if there is none.
     92   virtual FindBarTesting* GetFindBarTesting() = 0;
     93 };
     94 
     95 class FindBarTesting {
     96  public:
     97   virtual ~FindBarTesting() { }
     98 
     99   // Computes the location of the find bar and whether it is fully visible in
    100   // its parent window. The return value indicates if the window is visible at
    101   // all. Both out arguments are optional.
    102   //
    103   // This is used for UI tests of the find bar. If the find bar is not currently
    104   // shown (return value of false), the out params will be {(0, 0), false}.
    105   virtual bool GetFindBarWindowInfo(gfx::Point* position,
    106                                     bool* fully_visible) = 0;
    107 
    108   // Gets the search string currently selected in the Find box.
    109   virtual base::string16 GetFindSelectedText() = 0;
    110 
    111   // Gets the match count text (ie. 1 of 3) visible in the Find box.
    112   virtual base::string16 GetMatchCountText() = 0;
    113 
    114   // Gets the pixel width of the FindBar.
    115   virtual int GetWidth() = 0;
    116 };
    117 
    118 #endif  // CHROME_BROWSER_UI_FIND_BAR_FIND_BAR_H_
    119