OLD | NEW |
---|---|
1 // Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. | 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 | 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_VIEWS_FIND_BAR_WIN_H_ | 5 #ifndef CHROME_BROWSER_VIEWS_FIND_BAR_HOST_H_ |
6 #define CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ | 6 #define CHROME_BROWSER_VIEWS_FIND_BAR_HOST_H_ |
7 | 7 |
8 #include "app/animation.h" | 8 #include "app/animation.h" |
9 #include "base/gfx/rect.h" | 9 #include "base/gfx/rect.h" |
10 #include "base/gfx/native_widget_types.h" | 10 #include "base/gfx/native_widget_types.h" |
11 #include "base/scoped_ptr.h" | 11 #include "base/scoped_ptr.h" |
12 #include "chrome/browser/find_bar.h" | 12 #include "chrome/browser/find_bar.h" |
13 #include "chrome/browser/renderer_host/render_view_host_delegate.h" | 13 #include "chrome/browser/renderer_host/render_view_host_delegate.h" |
14 #include "views/controls/textfield/textfield.h" | |
14 #include "views/focus/focus_manager.h" | 15 #include "views/focus/focus_manager.h" |
16 #include "views/widget/widget.h" | |
15 | 17 |
16 class BrowserView; | 18 class BrowserView; |
17 class FindBarController; | 19 class FindBarController; |
18 class FindBarView; | 20 class FindBarView; |
19 class FindNotificationDetails; | 21 class FindNotificationDetails; |
20 class RenderViewHost; | 22 class RenderViewHost; |
21 class SlideAnimation; | 23 class SlideAnimation; |
22 | 24 |
23 namespace views { | 25 namespace views { |
24 class ExternalFocusTracker; | 26 class ExternalFocusTracker; |
25 class View; | 27 class View; |
26 } | 28 } |
27 | 29 |
28 // TODO(sky): rename this to FindBarViews. | |
29 | 30 |
30 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
31 // | 32 // |
32 // The FindBarWin implements the container window for the Windows find-in-page | 33 // The FindBarHost implements the container window for the |
33 // functionality. It uses the FindBarWin implementation to draw its content and | 34 // find-in-page functionality. It uses the appropriate implementation from |
34 // is responsible for showing, hiding, closing, and moving the window if needed, | 35 // find_bar_host_win.cc or find_bar_host_gtk.cc to draw its content and is |
36 // responsible for showing, hiding, closing, and moving the window if needed, | |
35 // for example if the window is obscuring the selection results. It also | 37 // for example if the window is obscuring the selection results. It also |
36 // receives notifications about the search results and communicates that to the | 38 // receives notifications about the search results and communicates that to |
37 // view. | 39 // the view. |
38 // | 40 // |
39 // There is one FindBarWin per BrowserView, and its state is updated whenever | 41 // There is one FindBarHost per BrowserView, and its state is updated |
40 // the selected Tab is changed. The FindBarWin is created when the BrowserView | 42 // whenever the selected Tab is changed. The FindBarHost is created when |
41 // is attached to the frame's Widget for the first time. | 43 // the BrowserView is attached to the frame's Widget for the first time. |
42 // | 44 // |
43 //////////////////////////////////////////////////////////////////////////////// | 45 //////////////////////////////////////////////////////////////////////////////// |
44 class FindBarWin : public views::AcceleratorTarget, | 46 class FindBarHost : public views::AcceleratorTarget, |
45 public views::FocusChangeListener, | 47 public views::FocusChangeListener, |
46 public AnimationDelegate, | 48 public AnimationDelegate, |
47 public FindBar, | 49 public FindBar, |
48 public FindBarTesting { | 50 public FindBarTesting { |
49 public: | 51 public: |
50 explicit FindBarWin(BrowserView* browser_view); | 52 explicit FindBarHost(BrowserView* browser_view); |
51 virtual ~FindBarWin(); | 53 virtual ~FindBarHost(); |
52 | 54 |
53 // Whether we are animating the position of the Find window. | 55 // Whether we are animating the position of the Find window. |
54 bool IsAnimating(); | 56 bool IsAnimating(); |
55 | 57 |
56 #if defined(OS_WIN) | |
57 // Forwards selected keystrokes to the renderer. This is useful to make sure | 58 // 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 // 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 // being eaten because the FindBar has focus. Returns true if the keystroke |
60 // was forwarded, false if not. | 61 // was forwarded, false if not. |
61 bool MaybeForwardKeystrokeToWebpage(UINT message, TCHAR key, UINT flags); | 62 bool MaybeForwardKeystrokeToWebpage( |
62 #endif | 63 const views::Textfield::Keystroke& key_stroke); |
63 | 64 |
64 void OnFinalMessage(); | 65 void OnFinalMessage(); |
65 | 66 |
66 bool IsVisible(); | 67 bool IsVisible(); |
67 | 68 |
68 // FindBar implementation: | 69 // FindBar implementation: |
69 virtual FindBarController* GetFindBarController() const { | 70 virtual FindBarController* GetFindBarController() const { |
70 return find_bar_controller_; | 71 return find_bar_controller_; |
71 } | 72 } |
72 virtual void SetFindBarController(FindBarController* find_bar_controller) { | 73 virtual void SetFindBarController(FindBarController* find_bar_controller) { |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 | 107 |
107 // Get the offset with which to paint the theme image. | 108 // Get the offset with which to paint the theme image. |
108 void GetThemePosition(gfx::Rect* bounds); | 109 void GetThemePosition(gfx::Rect* bounds); |
109 | 110 |
110 // During testing we can disable animations by setting this flag to true, | 111 // 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 // 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 // having to poll it while it animates to open/closed status. |
113 static bool disable_animations_during_testing_; | 114 static bool disable_animations_during_testing_; |
114 | 115 |
115 private: | 116 private: |
116 class Host; | |
117 | |
118 // Retrieves the boundaries that the find bar has to work with within the | 117 // 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 | 118 // 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 | 119 // 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 | 120 // 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 | 121 // 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 | 122 // 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 | 123 // 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 | 124 // window. If the function fails to determine the browser window/client area |
126 // rectangle or the rectangle for the page area then |bounds| will | 125 // rectangle or the rectangle for the page area then |bounds| will |
127 // be an empty rectangle. | 126 // be an empty rectangle. |
128 void GetDialogBounds(gfx::Rect* bounds); | 127 void GetDialogBounds(gfx::Rect* bounds); |
129 | 128 |
130 // The dialog needs rounded edges, so we create a polygon that corresponds to | 129 // 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 | 130 // 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 | 131 // 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 | 132 // 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 | 133 // with curved edges. We also check to see if the region should be truncated |
135 // to prevent from drawing onto Chrome's window border. | 134 // to prevent from drawing onto Chrome's window border. |
136 void UpdateWindowEdges(const gfx::Rect& new_pos); | 135 void UpdateWindowEdges(const gfx::Rect& new_pos); |
137 | 136 |
138 | 137 |
139 // Registers this class as the handler for when Escape is pressed. We will | 138 // Registers this class as the handler for when Escape is pressed. We will |
140 // unregister once we loose focus. See also: SetFocusChangeListener(). | 139 // unregister once we loose focus. See also: SetFocusChangeListener(). |
141 void RegisterEscAccelerator(); | 140 void RegisterEscAccelerator(); |
142 | 141 |
143 // When we loose focus, we unregister the handler for Escape. See | 142 // When we loose focus, we unregister the handler for Escape. See |
144 // also: SetFocusChangeListener(). | 143 // also: SetFocusChangeListener(). |
145 void UnregisterEscAccelerator(); | 144 void UnregisterEscAccelerator(); |
146 | 145 |
146 // Creates and returns the native Widget. | |
147 views::Widget* CreateHost(); | |
148 // Allows implementation to tweak dialog position. | |
149 void SetDialogPositionNative(const gfx::Rect& new_pos, bool no_redraw); | |
150 // Allows implementation to tweak dialog position. | |
151 void GetDialogPositionNative(gfx::Rect* avoid_overlapping_rect); | |
152 // Returns the native view (is a child of the window widget in gtk). | |
153 gfx::NativeView GetNativeView(BrowserView* browser_view); | |
154 // Returns a keyboard event suitable for fowarding. | |
155 NativeWebKeyboardEvent GetKeyboardEvent( | |
156 const TabContents* contents, | |
sky
2009/09/09 22:49:41
It looks like you're at 5 now.
| |
157 const views::Textfield::Keystroke& key_stroke); | |
158 | |
147 // The BrowserView that created us. | 159 // The BrowserView that created us. |
148 BrowserView* browser_view_; | 160 BrowserView* browser_view_; |
149 | 161 |
150 // Our view, which is responsible for drawing the UI. | 162 // Our view, which is responsible for drawing the UI. |
151 FindBarView* view_; | 163 FindBarView* view_; |
152 | 164 |
153 // The y position pixel offset of the window while animating the Find dialog. | 165 // The y position pixel offset of the window while animating the Find dialog. |
154 int find_dialog_animation_offset_; | 166 int find_dialog_animation_offset_; |
155 | 167 |
156 // The animation class to use when opening the Find window. | 168 // The animation class to use when opening the Find window. |
157 scoped_ptr<SlideAnimation> animation_; | 169 scoped_ptr<SlideAnimation> animation_; |
158 | 170 |
159 // The focus manager we register with to keep track of focus changes. | 171 // The focus manager we register with to keep track of focus changes. |
160 views::FocusManager* focus_manager_; | 172 views::FocusManager* focus_manager_; |
161 | 173 |
162 // True if the accelerator target for Esc key is registered. | 174 // True if the accelerator target for Esc key is registered. |
163 bool esc_accel_target_registered_; | 175 bool esc_accel_target_registered_; |
164 | 176 |
165 // Tracks and stores the last focused view which is not the FindBarView | 177 // 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 | 178 // or any of its children. Used to restore focus once the FindBarView is |
167 // closed. | 179 // closed. |
168 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; | 180 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; |
169 | 181 |
170 // A pointer back to the owning controller. | 182 // A pointer back to the owning controller. |
171 FindBarController* find_bar_controller_; | 183 FindBarController* find_bar_controller_; |
172 | 184 |
173 // Host is the Widget implementation that is created and maintained by the | 185 // Host is the Widget implementation that is created and maintained by the |
174 // find bar. It contains the FindBarView. | 186 // find bar. It contains the FindBarView. |
175 scoped_ptr<Host> host_; | 187 scoped_ptr<views::Widget> host_; |
176 | 188 |
177 DISALLOW_COPY_AND_ASSIGN(FindBarWin); | 189 DISALLOW_COPY_AND_ASSIGN(FindBarHost); |
178 }; | 190 }; |
179 | 191 |
180 #endif // CHROME_BROWSER_VIEWS_FIND_BAR_WIN_H_ | 192 #endif // CHROME_BROWSER_VIEWS_FIND_BAR_HOST_H_ |
193 | |
OLD | NEW |