| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ |
| 6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ |
| 7 | 7 |
| 8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 9 #include "chrome/browser/ui/find_bar/find_bar.h" | 9 #include "chrome/browser/ui/find_bar/find_bar.h" |
| 10 #include "chrome/browser/ui/views/dropdown_bar_host.h" | 10 #include "chrome/browser/ui/views/dropdown_bar_host.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 // There is one FindBarHost per BrowserView, and its state is updated | 29 // There is one FindBarHost per BrowserView, and its state is updated |
| 30 // whenever the selected Tab is changed. The FindBarHost is created when | 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. | 31 // the BrowserView is attached to the frame's Widget for the first time. |
| 32 // | 32 // |
| 33 //////////////////////////////////////////////////////////////////////////////// | 33 //////////////////////////////////////////////////////////////////////////////// |
| 34 class FindBarHost : public DropdownBarHost, | 34 class FindBarHost : public DropdownBarHost, |
| 35 public FindBar, | 35 public FindBar, |
| 36 public FindBarTesting { | 36 public FindBarTesting { |
| 37 public: | 37 public: |
| 38 explicit FindBarHost(BrowserView* browser_view); | 38 explicit FindBarHost(BrowserView* browser_view); |
| 39 virtual ~FindBarHost(); | 39 ~FindBarHost() override; |
| 40 | 40 |
| 41 // Forwards selected key events to the renderer. This is useful to make sure | 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 | 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 | 43 // being eaten because the FindBar has focus. Returns true if the keystroke |
| 44 // was forwarded, false if not. | 44 // was forwarded, false if not. |
| 45 bool MaybeForwardKeyEventToWebpage(const ui::KeyEvent& key_event); | 45 bool MaybeForwardKeyEventToWebpage(const ui::KeyEvent& key_event); |
| 46 | 46 |
| 47 // FindBar implementation: | 47 // FindBar implementation: |
| 48 virtual FindBarController* GetFindBarController() const override; | 48 FindBarController* GetFindBarController() const override; |
| 49 virtual void SetFindBarController( | 49 void SetFindBarController(FindBarController* find_bar_controller) override; |
| 50 FindBarController* find_bar_controller) override; | 50 void Show(bool animate) override; |
| 51 virtual void Show(bool animate) override; | 51 void Hide(bool animate) override; |
| 52 virtual void Hide(bool animate) override; | 52 void SetFocusAndSelection() override; |
| 53 virtual void SetFocusAndSelection() override; | 53 void ClearResults(const FindNotificationDetails& results) override; |
| 54 virtual void ClearResults(const FindNotificationDetails& results) override; | 54 void StopAnimation() override; |
| 55 virtual void StopAnimation() override; | 55 void MoveWindowIfNecessary(const gfx::Rect& selection_rect, |
| 56 virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect, | 56 bool no_redraw) override; |
| 57 bool no_redraw) override; | 57 void SetFindTextAndSelectedRange(const base::string16& find_text, |
| 58 virtual void SetFindTextAndSelectedRange( | 58 const gfx::Range& selected_range) override; |
| 59 const base::string16& find_text, | 59 base::string16 GetFindText() override; |
| 60 const gfx::Range& selected_range) override; | 60 gfx::Range GetSelectedRange() override; |
| 61 virtual base::string16 GetFindText() override; | 61 void UpdateUIForFindResult(const FindNotificationDetails& result, |
| 62 virtual gfx::Range GetSelectedRange() override; | 62 const base::string16& find_text) override; |
| 63 virtual void UpdateUIForFindResult(const FindNotificationDetails& result, | 63 void AudibleAlert() override; |
| 64 const base::string16& find_text) override; | 64 bool IsFindBarVisible() override; |
| 65 virtual void AudibleAlert() override; | 65 void RestoreSavedFocus() override; |
| 66 virtual bool IsFindBarVisible() override; | 66 bool HasGlobalFindPasteboard() override; |
| 67 virtual void RestoreSavedFocus() override; | 67 void UpdateFindBarForChangedWebContents() override; |
| 68 virtual bool HasGlobalFindPasteboard() override; | 68 FindBarTesting* GetFindBarTesting() override; |
| 69 virtual void UpdateFindBarForChangedWebContents() override; | |
| 70 virtual FindBarTesting* GetFindBarTesting() override; | |
| 71 | 69 |
| 72 // Overridden from ui::AcceleratorTarget in DropdownBarHost class: | 70 // Overridden from ui::AcceleratorTarget in DropdownBarHost class: |
| 73 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) override; | 71 bool AcceleratorPressed(const ui::Accelerator& accelerator) override; |
| 74 virtual bool CanHandleAccelerators() const override; | 72 bool CanHandleAccelerators() const override; |
| 75 | 73 |
| 76 // FindBarTesting implementation: | 74 // FindBarTesting implementation: |
| 77 virtual bool GetFindBarWindowInfo(gfx::Point* position, | 75 bool GetFindBarWindowInfo(gfx::Point* position, bool* fully_visible) override; |
| 78 bool* fully_visible) override; | 76 base::string16 GetFindSelectedText() override; |
| 79 virtual base::string16 GetFindSelectedText() override; | 77 base::string16 GetMatchCountText() override; |
| 80 virtual base::string16 GetMatchCountText() override; | 78 int GetWidth() override; |
| 81 virtual int GetWidth() override; | |
| 82 | 79 |
| 83 // Overridden from DropdownBarHost: | 80 // Overridden from DropdownBarHost: |
| 84 // Returns the rectangle representing where to position the find bar. It uses | 81 // Returns the rectangle representing where to position the find bar. It uses |
| 85 // GetDialogBounds and positions itself within that, either to the left (if an | 82 // GetDialogBounds and positions itself within that, either to the left (if an |
| 86 // InfoBar is present) or to the right (no InfoBar). If | 83 // InfoBar is present) or to the right (no InfoBar). If |
| 87 // |avoid_overlapping_rect| is specified, the return value will be a rectangle | 84 // |avoid_overlapping_rect| is specified, the return value will be a rectangle |
| 88 // located immediately to the left of |avoid_overlapping_rect|, as long as | 85 // located immediately to the left of |avoid_overlapping_rect|, as long as |
| 89 // there is enough room for the dialog to draw within the bounds. If not, the | 86 // there is enough room for the dialog to draw within the bounds. If not, the |
| 90 // dialog position returned will overlap |avoid_overlapping_rect|. | 87 // dialog position returned will overlap |avoid_overlapping_rect|. |
| 91 // Note: |avoid_overlapping_rect| is expected to use coordinates relative to | 88 // Note: |avoid_overlapping_rect| is expected to use coordinates relative to |
| 92 // the top of the page area, (it will be converted to coordinates relative to | 89 // the top of the page area, (it will be converted to coordinates relative to |
| 93 // the top of the browser window, when comparing against the dialog | 90 // the top of the browser window, when comparing against the dialog |
| 94 // coordinates). The returned value is relative to the browser window. | 91 // coordinates). The returned value is relative to the browser window. |
| 95 virtual gfx::Rect GetDialogPosition( | 92 gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect) override; |
| 96 gfx::Rect avoid_overlapping_rect) override; | |
| 97 // Moves the dialog window to the provided location, moves it to top in the | 93 // Moves the dialog window to the provided location, moves it to top in the |
| 98 // z-order (HWND_TOP, not HWND_TOPMOST) and shows the window (if hidden). | 94 // z-order (HWND_TOP, not HWND_TOPMOST) and shows the window (if hidden). |
| 99 // It then calls UpdateWindowEdges to make sure we don't overwrite the Chrome | 95 // It then calls UpdateWindowEdges to make sure we don't overwrite the Chrome |
| 100 // window border. If |no_redraw| is set, the window is getting moved but not | 96 // window border. If |no_redraw| is set, the window is getting moved but not |
| 101 // sized, and should not be redrawn to reduce update flicker. | 97 // sized, and should not be redrawn to reduce update flicker. |
| 102 virtual void SetDialogPosition(const gfx::Rect& new_pos, | 98 void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) override; |
| 103 bool no_redraw) override; | |
| 104 | 99 |
| 105 // Retrieves the boundaries that the find bar widget has to work with | 100 // Retrieves the boundaries that the find bar widget has to work with |
| 106 // within the Chrome frame window. The resulting rectangle will be a | 101 // within the Chrome frame window. The resulting rectangle will be a |
| 107 // rectangle that overlaps the bottom of the Chrome toolbar by one | 102 // rectangle that overlaps the bottom of the Chrome toolbar by one |
| 108 // pixel (so we can create the illusion that the dropdown widget is | 103 // pixel (so we can create the illusion that the dropdown widget is |
| 109 // part of the toolbar) and covers the page area, except that we | 104 // part of the toolbar) and covers the page area, except that we |
| 110 // deflate the rect width by subtracting (from both sides) the width | 105 // deflate the rect width by subtracting (from both sides) the width |
| 111 // of the toolbar and some extra pixels to account for the width of | 106 // of the toolbar and some extra pixels to account for the width of |
| 112 // the Chrome window borders. |bounds| is relative to the browser | 107 // the Chrome window borders. |bounds| is relative to the browser |
| 113 // window. If the function fails to determine the browser | 108 // window. If the function fails to determine the browser |
| 114 // window/client area rectangle or the rectangle for the page area | 109 // window/client area rectangle or the rectangle for the page area |
| 115 // then |bounds| will be an empty rectangle. | 110 // then |bounds| will be an empty rectangle. |
| 116 virtual void GetWidgetBounds(gfx::Rect* bounds) override; | 111 void GetWidgetBounds(gfx::Rect* bounds) override; |
| 117 | 112 |
| 118 // Additional accelerator handling (on top of what DropDownBarHost does). | 113 // Additional accelerator handling (on top of what DropDownBarHost does). |
| 119 virtual void RegisterAccelerators() override; | 114 void RegisterAccelerators() override; |
| 120 virtual void UnregisterAccelerators() override; | 115 void UnregisterAccelerators() override; |
| 121 | 116 |
| 122 protected: | 117 protected: |
| 123 // Overridden from DropdownBarHost: | 118 // Overridden from DropdownBarHost: |
| 124 virtual void OnVisibilityChanged() override; | 119 void OnVisibilityChanged() override; |
| 125 | 120 |
| 126 private: | 121 private: |
| 127 // Allows implementation to tweak widget position. | 122 // Allows implementation to tweak widget position. |
| 128 void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect); | 123 void GetWidgetPositionNative(gfx::Rect* avoid_overlapping_rect); |
| 129 | 124 |
| 130 // Returns the FindBarView. | 125 // Returns the FindBarView. |
| 131 FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); } | 126 FindBarView* find_bar_view() { return static_cast<FindBarView*>(view()); } |
| 132 | 127 |
| 133 // A pointer back to the owning controller. | 128 // A pointer back to the owning controller. |
| 134 FindBarController* find_bar_controller_; | 129 FindBarController* find_bar_controller_; |
| 135 | 130 |
| 136 DISALLOW_COPY_AND_ASSIGN(FindBarHost); | 131 DISALLOW_COPY_AND_ASSIGN(FindBarHost); |
| 137 }; | 132 }; |
| 138 | 133 |
| 139 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ | 134 #endif // CHROME_BROWSER_UI_VIEWS_FIND_BAR_HOST_H_ |
| OLD | NEW |