NaCl docs: add sanitizers to GSoC ideas
[chromium-blink-merge.git] / chrome / browser / ui / views / find_bar_host.h
blobf0b5de39d0b9709edb0bb345ec937bf9efc093e3
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_VIEWS_FIND_BAR_HOST_H_
6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_
8 #include "base/compiler_specific.h"
9 #include "chrome/browser/ui/find_bar/find_bar.h"
10 #include "chrome/browser/ui/views/dropdown_bar_host.h"
11 #include "chrome/browser/ui/views/find_bar_view.h"
12 #include "ui/gfx/geometry/rect.h"
13 #include "ui/gfx/native_widget_types.h"
14 #include "ui/views/controls/textfield/textfield.h"
16 class BrowserView;
17 class FindBarController;
18 class FindNotificationDetails;
20 ////////////////////////////////////////////////////////////////////////////////
22 // The FindBarHost implements the container widget for the
23 // find-in-page functionality. It uses the implementation from
24 // find_bar_host_aura.cc to draw its content and is responsible for showing,
25 // hiding, closing, and moving the widget if needed, for example if the widget
26 // is obscuring the selection results. It also receives notifications about the
27 // search results and communicates that to the view.
29 // There is one FindBarHost per BrowserView, and its state is updated
30 // whenever the selected Tab is changed. The FindBarHost is created when
31 // the BrowserView is attached to the frame's Widget for the first time.
33 ////////////////////////////////////////////////////////////////////////////////
34 class FindBarHost : public DropdownBarHost,
35 public FindBar,
36 public FindBarTesting {
37 public:
38 explicit FindBarHost(BrowserView* browser_view);
39 ~FindBarHost() override;
41 // Forwards selected key events to the renderer. This is useful to make sure
42 // that arrow keys and PageUp and PageDown result in scrolling, instead of
43 // being eaten because the FindBar has focus. Returns true if the keystroke
44 // was forwarded, false if not.
45 bool MaybeForwardKeyEventToWebpage(const ui::KeyEvent& key_event);
47 // FindBar implementation:
48 FindBarController* GetFindBarController() const override;
49 void SetFindBarController(FindBarController* find_bar_controller) override;
50 void Show(bool animate) override;
51 void Hide(bool animate) override;
52 void SetFocusAndSelection() override;
53 void ClearResults(const FindNotificationDetails& results) override;
54 void StopAnimation() override;
55 void MoveWindowIfNecessary(const gfx::Rect& selection_rect) override;
56 void SetFindTextAndSelectedRange(const base::string16& find_text,
57 const gfx::Range& selected_range) override;
58 base::string16 GetFindText() override;
59 gfx::Range GetSelectedRange() override;
60 void UpdateUIForFindResult(const FindNotificationDetails& result,
61 const base::string16& find_text) override;
62 void AudibleAlert() override;
63 bool IsFindBarVisible() override;
64 void RestoreSavedFocus() override;
65 bool HasGlobalFindPasteboard() override;
66 void UpdateFindBarForChangedWebContents() override;
67 FindBarTesting* GetFindBarTesting() override;
69 // Overridden from ui::AcceleratorTarget in DropdownBarHost class:
70 bool AcceleratorPressed(const ui::Accelerator& accelerator) override;
71 bool CanHandleAccelerators() const override;
73 // FindBarTesting implementation:
74 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) override;
75 base::string16 GetFindSelectedText() override;
76 base::string16 GetMatchCountText() override;
77 int GetWidth() override;
79 // Overridden from DropdownBarHost:
80 // Returns the rectangle representing where to position the find bar. It uses
81 // GetDialogBounds and positions itself within that, either to the left (if an
82 // InfoBar is present) or to the right (no InfoBar). If
83 // |avoid_overlapping_rect| is specified, the return value will be a rectangle
84 // located immediately to the left of |avoid_overlapping_rect|, as long as
85 // there is enough room for the dialog to draw within the bounds. If not, the
86 // dialog position returned will overlap |avoid_overlapping_rect|.
87 // Note: |avoid_overlapping_rect| is expected to use coordinates relative to
88 // the top of the page area, (it will be converted to coordinates relative to
89 // the top of the browser window, when comparing against the dialog
90 // coordinates). The returned value is relative to the browser window.
91 gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect) override;
92 // Moves the dialog window to the provided location, moves it to top in the
93 // z-order (HWND_TOP, not HWND_TOPMOST) and shows the window (if hidden).
94 // It then calls UpdateWindowEdges to make sure we don't overwrite the Chrome
95 // window border.
96 void SetDialogPosition(const gfx::Rect& new_pos) override;
98 // Retrieves the boundaries that the find bar widget has to work with
99 // within the Chrome frame window. The resulting rectangle will be a
100 // rectangle that overlaps the bottom of the Chrome toolbar by one
101 // pixel (so we can create the illusion that the dropdown widget is
102 // part of the toolbar) and covers the page area, except that we
103 // deflate the rect width by subtracting (from both sides) the width
104 // of the toolbar and some extra pixels to account for the width of
105 // the Chrome window borders. |bounds| is relative to the browser
106 // window. If the function fails to determine the browser
107 // window/client area rectangle or the rectangle for the page area
108 // then |bounds| will be an empty rectangle.
109 void GetWidgetBounds(gfx::Rect* bounds) override;
111 // Additional accelerator handling (on top of what DropDownBarHost does).
112 void RegisterAccelerators() override;
113 void UnregisterAccelerators() override;
115 protected:
116 // Overridden from DropdownBarHost:
117 void OnVisibilityChanged() override;
119 private:
120 // Allows implementation to tweak widget position.
121 void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect);
123 // Returns the FindBarView.
124 FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); }
126 // A pointer back to the owning controller.
127 FindBarController* find_bar_controller_;
129 DISALLOW_COPY_AND_ASSIGN(FindBarHost);
132 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_