| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2006-2009 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 #ifndef CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ | |
| 6 #define CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ | |
| 7 | |
| 8 #include "app/animation.h" | |
| 9 #include "base/gfx/rect.h" | |
| 10 #include "base/gfx/native_widget_types.h" | |
| 11 #include "base/scoped_ptr.h" | |
| 12 #include "chrome/browser/find_bar.h" | |
| 13 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | |
| 14 #include "views/focus/focus_manager.h" | |
| 15 | |
| 16 class BrowserView; | |
| 17 class FindBarController; | |
| 18 class FindBarView; | |
| 19 class FindNotificationDetails; | |
| 20 class RenderViewHost; | |
| 21 class SlideAnimation; | |
| 22 | |
| 23 namespace views { | |
| 24 class ExternalFocusTracker; | |
| 25 class View; | |
| 26 } | |
| 27 | |
| 28 // TODO(sky): rename this to FindBarViews. | |
| 29 | |
| 30 //////////////////////////////////////////////////////////////////////////////// | |
| 31 // | |
| 32 // The FindBarWin implements the container window for the Windows find-in-page | |
| 33 // functionality. It uses the FindBarWin implementation to draw its content and | |
| 34 // is responsible for showing, hiding, closing, and moving the window if needed, | |
| 35 // for example if the window is obscuring the selection results. It also | |
| 36 // receives notifications about the search results and communicates that to the | |
| 37 // view. | |
| 38 // | |
| 39 // There is one FindBarWin per BrowserView, and its state is updated whenever | |
| 40 // the selected Tab is changed. The FindBarWin is created when the BrowserView | |
| 41 // is attached to the frame's Widget for the first time. | |
| 42 // | |
| 43 //////////////////////////////////////////////////////////////////////////////// | |
| 44 class FindBarWin : public views::AcceleratorTarget, | |
| 45 public views::FocusChangeListener, | |
| 46 public AnimationDelegate, | |
| 47 public FindBar, | |
| 48 public FindBarTesting { | |
| 49 public: | |
| 50 explicit FindBarWin(BrowserView* browser_view); | |
| 51 virtual ~FindBarWin(); | |
| 52 | |
| 53 // Whether we are animating the position of the Find window. | |
| 54 bool IsAnimating(); | |
| 55 | |
| 56 #if defined(OS_WIN) | |
| 57 // Forwards selected keystrokes to the renderer. This is useful to make sure | |
| 58 // that arrow keys and PageUp and PageDown result in scrolling, instead of | |
| 59 // being eaten because the FindBar has focus. Returns true if the keystroke | |
| 60 // was forwarded, false if not. | |
| 61 bool MaybeForwardKeystrokeToWebpage(UINT message, TCHAR key, UINT flags); | |
| 62 #endif | |
| 63 | |
| 64 void OnFinalMessage(); | |
| 65 | |
| 66 bool IsVisible(); | |
| 67 | |
| 68 // FindBar implementation: | |
| 69 virtual FindBarController* GetFindBarController() const { | |
| 70 return find_bar_controller_; | |
| 71 } | |
| 72 virtual void SetFindBarController(FindBarController* find_bar_controller) { | |
| 73 find_bar_controller_ = find_bar_controller; | |
| 74 } | |
| 75 virtual void Show(); | |
| 76 virtual void Hide(bool animate); | |
| 77 virtual void SetFocusAndSelection(); | |
| 78 virtual void ClearResults(const FindNotificationDetails& results); | |
| 79 virtual void StopAnimation(); | |
| 80 virtual void MoveWindowIfNecessary(const gfx::Rect& selection_rect, | |
| 81 bool no_redraw); | |
| 82 virtual void SetFindText(const string16& find_text); | |
| 83 virtual void UpdateUIForFindResult(const FindNotificationDetails& result, | |
| 84 const string16& find_text); | |
| 85 virtual void AudibleAlert(); | |
| 86 virtual gfx::Rect GetDialogPosition(gfx::Rect avoid_overlapping_rect); | |
| 87 virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw); | |
| 88 virtual bool IsFindBarVisible(); | |
| 89 virtual void RestoreSavedFocus(); | |
| 90 virtual FindBarTesting* GetFindBarTesting(); | |
| 91 | |
| 92 // Overridden from views::FocusChangeListener: | |
| 93 virtual void FocusWillChange(views::View* focused_before, | |
| 94 views::View* focused_now); | |
| 95 | |
| 96 // Overridden from views::AcceleratorTarget: | |
| 97 virtual bool AcceleratorPressed(const views::Accelerator& accelerator); | |
| 98 | |
| 99 // AnimationDelegate implementation: | |
| 100 virtual void AnimationProgressed(const Animation* animation); | |
| 101 virtual void AnimationEnded(const Animation* animation); | |
| 102 | |
| 103 // FindBarTesting implementation: | |
| 104 virtual bool GetFindBarWindowInfo(gfx::Point* position, | |
| 105 bool* fully_visible); | |
| 106 | |
| 107 // Get the offset with which to paint the theme image. | |
| 108 void GetThemePosition(gfx::Rect* bounds); | |
| 109 | |
| 110 // During testing we can disable animations by setting this flag to true, | |
| 111 // so that opening and closing the Find box happens instantly, instead of | |
| 112 // having to poll it while it animates to open/closed status. | |
| 113 static bool disable_animations_during_testing_; | |
| 114 | |
| 115 private: | |
| 116 class Host; | |
| 117 | |
| 118 // Retrieves the boundaries that the find bar has to work with within the | |
| 119 // Chrome frame window. The resulting rectangle will be a rectangle that | |
| 120 // overlaps the bottom of the Chrome toolbar by one pixel (so we can create | |
| 121 // the illusion that the find bar is part of the toolbar) and covers the page | |
| 122 // area, except that we deflate the rect width by subtracting (from both | |
| 123 // sides) the width of the toolbar and some extra pixels to account for the | |
| 124 // width of the Chrome window borders. |bounds| is relative to the browser | |
| 125 // window. If the function fails to determine the browser window/client area | |
| 126 // rectangle or the rectangle for the page area then |bounds| will | |
| 127 // be an empty rectangle. | |
| 128 void GetDialogBounds(gfx::Rect* bounds); | |
| 129 | |
| 130 // The dialog needs rounded edges, so we create a polygon that corresponds to | |
| 131 // the background images for this window (and make the polygon only contain | |
| 132 // the pixels that we want to draw). The polygon is then given to SetWindowRgn | |
| 133 // which changes the window from being a rectangle in shape, to being a rect | |
| 134 // with curved edges. We also check to see if the region should be truncated | |
| 135 // to prevent from drawing onto Chrome's window border. | |
| 136 void UpdateWindowEdges(const gfx::Rect& new_pos); | |
| 137 | |
| 138 | |
| 139 // Registers this class as the handler for when Escape is pressed. We will | |
| 140 // unregister once we loose focus. See also: SetFocusChangeListener(). | |
| 141 void RegisterEscAccelerator(); | |
| 142 | |
| 143 // When we loose focus, we unregister the handler for Escape. See | |
| 144 // also: SetFocusChangeListener(). | |
| 145 void UnregisterEscAccelerator(); | |
| 146 | |
| 147 // The BrowserView that created us. | |
| 148 BrowserView* browser_view_; | |
| 149 | |
| 150 // Our view, which is responsible for drawing the UI. | |
| 151 FindBarView* view_; | |
| 152 | |
| 153 // The y position pixel offset of the window while animating the Find dialog. | |
| 154 int find_dialog_animation_offset_; | |
| 155 | |
| 156 // The animation class to use when opening the Find window. | |
| 157 scoped_ptr<SlideAnimation> animation_; | |
| 158 | |
| 159 // The focus manager we register with to keep track of focus changes. | |
| 160 views::FocusManager* focus_manager_; | |
| 161 | |
| 162 // True if the accelerator target for Esc key is registered. | |
| 163 bool esc_accel_target_registered_; | |
| 164 | |
| 165 // Tracks and stores the last focused view which is not the FindBarView | |
| 166 // or any of its children. Used to restore focus once the FindBarView is | |
| 167 // closed. | |
| 168 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; | |
| 169 | |
| 170 // A pointer back to the owning controller. | |
| 171 FindBarController* find_bar_controller_; | |
| 172 | |
| 173 // Host is the Widget implementation that is created and maintained by the | |
| 174 // find bar. It contains the FindBarView. | |
| 175 scoped_ptr<Host> host_; | |
| 176 | |
| 177 DISALLOW_COPY_AND_ASSIGN(FindBarWin); | |
| 178 }; | |
| 179 | |
| 180 #endif // CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ | |
| OLD | NEW |