OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 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 | 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_DROPDOWN_BAR_HOST_H_ | 5 #ifndef CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ |
6 #define CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ | 6 #define CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ |
7 | 7 |
8 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "content/public/browser/native_web_keyboard_event.h" | 10 #include "content/public/browser/native_web_keyboard_event.h" |
11 #include "ui/base/animation/animation_delegate.h" | 11 #include "ui/gfx/animation/animation_delegate.h" |
12 #include "ui/gfx/native_widget_types.h" | 12 #include "ui/gfx/native_widget_types.h" |
13 #include "ui/gfx/rect.h" | 13 #include "ui/gfx/rect.h" |
14 #include "ui/views/controls/textfield/textfield.h" | 14 #include "ui/views/controls/textfield/textfield.h" |
15 #include "ui/views/focus/focus_manager.h" | 15 #include "ui/views/focus/focus_manager.h" |
16 | 16 |
17 class BrowserView; | 17 class BrowserView; |
18 class DropdownBarHostDelegate; | 18 class DropdownBarHostDelegate; |
19 class DropdownBarView; | 19 class DropdownBarView; |
20 | 20 |
21 namespace content { | 21 namespace content { |
22 class WebContents; | 22 class WebContents; |
23 } | 23 } |
24 | 24 |
25 namespace ui { | 25 namespace gfx { |
26 class SlideAnimation; | 26 class SlideAnimation; |
27 } // namespace ui | 27 } // namespace gfx |
28 | 28 |
29 namespace views { | 29 namespace views { |
30 class ExternalFocusTracker; | 30 class ExternalFocusTracker; |
31 class View; | 31 class View; |
32 class Widget; | 32 class Widget; |
33 } // namespace views | 33 } // namespace views |
34 | 34 |
35 //////////////////////////////////////////////////////////////////////////////// | 35 //////////////////////////////////////////////////////////////////////////////// |
36 // | 36 // |
37 // The DropdownBarHost implements the container widget for the UI that | 37 // The DropdownBarHost implements the container widget for the UI that |
38 // is shown at the top of browser contents. It uses the appropriate | 38 // is shown at the top of browser contents. It uses the appropriate |
39 // implementation from dropdown_bar_host_win.cc or dropdown_bar_host_aura.cc to | 39 // implementation from dropdown_bar_host_win.cc or dropdown_bar_host_aura.cc to |
40 // draw its content and is responsible for showing, hiding, animating, closing, | 40 // draw its content and is responsible for showing, hiding, animating, closing, |
41 // and moving the bar if needed, for example if the widget is | 41 // and moving the bar if needed, for example if the widget is |
42 // obscuring the selection results in FindBar. | 42 // obscuring the selection results in FindBar. |
43 // | 43 // |
44 //////////////////////////////////////////////////////////////////////////////// | 44 //////////////////////////////////////////////////////////////////////////////// |
45 class DropdownBarHost : public ui::AcceleratorTarget, | 45 class DropdownBarHost : public ui::AcceleratorTarget, |
46 public views::FocusChangeListener, | 46 public views::FocusChangeListener, |
47 public ui::AnimationDelegate { | 47 public gfx::AnimationDelegate { |
48 public: | 48 public: |
49 explicit DropdownBarHost(BrowserView* browser_view); | 49 explicit DropdownBarHost(BrowserView* browser_view); |
50 virtual ~DropdownBarHost(); | 50 virtual ~DropdownBarHost(); |
51 | 51 |
52 // Initializes the DropdownBarHost. This creates the widget that |view| paints | 52 // Initializes the DropdownBarHost. This creates the widget that |view| paints |
53 // into. | 53 // into. |
54 // |host_view| is the view whose position in the |browser_view_| view | 54 // |host_view| is the view whose position in the |browser_view_| view |
55 // hierarchy determines the z-order of the widget relative to views with | 55 // hierarchy determines the z-order of the widget relative to views with |
56 // layers and views with associated NativeViews. | 56 // layers and views with associated NativeViews. |
57 void Init(views::View* host_view, | 57 void Init(views::View* host_view, |
(...skipping 25 matching lines...) Expand all Loading... |
83 // Overridden from views::FocusChangeListener: | 83 // Overridden from views::FocusChangeListener: |
84 virtual void OnWillChangeFocus(views::View* focused_before, | 84 virtual void OnWillChangeFocus(views::View* focused_before, |
85 views::View* focused_now) OVERRIDE; | 85 views::View* focused_now) OVERRIDE; |
86 virtual void OnDidChangeFocus(views::View* focused_before, | 86 virtual void OnDidChangeFocus(views::View* focused_before, |
87 views::View* focused_now) OVERRIDE; | 87 views::View* focused_now) OVERRIDE; |
88 | 88 |
89 // Overridden from ui::AcceleratorTarget: | 89 // Overridden from ui::AcceleratorTarget: |
90 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) = 0; | 90 virtual bool AcceleratorPressed(const ui::Accelerator& accelerator) = 0; |
91 virtual bool CanHandleAccelerators() const = 0; | 91 virtual bool CanHandleAccelerators() const = 0; |
92 | 92 |
93 // ui::AnimationDelegate implementation: | 93 // gfx::AnimationDelegate implementation: |
94 virtual void AnimationProgressed(const ui::Animation* animation) OVERRIDE; | 94 virtual void AnimationProgressed(const gfx::Animation* animation) OVERRIDE; |
95 virtual void AnimationEnded(const ui::Animation* animation) OVERRIDE; | 95 virtual void AnimationEnded(const gfx::Animation* animation) OVERRIDE; |
96 | 96 |
97 // During testing we can disable animations by setting this flag to true, | 97 // During testing we can disable animations by setting this flag to true, |
98 // so that opening and closing the dropdown bar is shown instantly, instead of | 98 // so that opening and closing the dropdown bar is shown instantly, instead of |
99 // having to poll it while it animates to open/closed status. | 99 // having to poll it while it animates to open/closed status. |
100 static bool disable_animations_during_testing_; | 100 static bool disable_animations_during_testing_; |
101 | 101 |
102 // Returns the browser view that the dropdown belongs to. | 102 // Returns the browser view that the dropdown belongs to. |
103 BrowserView* browser_view() const { return browser_view_; } | 103 BrowserView* browser_view() const { return browser_view_; } |
104 | 104 |
105 // Registers this class as the handler for when Escape is pressed. Once we | 105 // Registers this class as the handler for when Escape is pressed. Once we |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 155 |
156 // Allows implementation to tweak widget position. | 156 // Allows implementation to tweak widget position. |
157 void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); | 157 void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); |
158 | 158 |
159 // Returns a keyboard event suitable for forwarding. | 159 // Returns a keyboard event suitable for forwarding. |
160 content::NativeWebKeyboardEvent GetKeyboardEvent( | 160 content::NativeWebKeyboardEvent GetKeyboardEvent( |
161 const content::WebContents* contents, | 161 const content::WebContents* contents, |
162 const ui::KeyEvent& key_event); | 162 const ui::KeyEvent& key_event); |
163 | 163 |
164 // Returns the animation for the dropdown. | 164 // Returns the animation for the dropdown. |
165 ui::SlideAnimation* animation() { | 165 gfx::SlideAnimation* animation() { |
166 return animation_.get(); | 166 return animation_.get(); |
167 } | 167 } |
168 | 168 |
169 private: | 169 private: |
170 // Set the view whose position in the |browser_view_| view hierarchy | 170 // Set the view whose position in the |browser_view_| view hierarchy |
171 // determines the z-order of |host_| relative to views with layers and | 171 // determines the z-order of |host_| relative to views with layers and |
172 // views with associated NativeViews. | 172 // views with associated NativeViews. |
173 void SetHostViewNative(views::View* host_view); | 173 void SetHostViewNative(views::View* host_view); |
174 | 174 |
175 // The BrowserView that created us. | 175 // The BrowserView that created us. |
176 BrowserView* browser_view_; | 176 BrowserView* browser_view_; |
177 | 177 |
178 // Our view, which is responsible for drawing the UI. | 178 // Our view, which is responsible for drawing the UI. |
179 views::View* view_; | 179 views::View* view_; |
180 DropdownBarHostDelegate* delegate_; | 180 DropdownBarHostDelegate* delegate_; |
181 | 181 |
182 // The y position pixel offset of the widget while animating the | 182 // The y position pixel offset of the widget while animating the |
183 // dropdown widget. | 183 // dropdown widget. |
184 int animation_offset_; | 184 int animation_offset_; |
185 | 185 |
186 // The animation class to use when opening the Dropdown widget. | 186 // The animation class to use when opening the Dropdown widget. |
187 scoped_ptr<ui::SlideAnimation> animation_; | 187 scoped_ptr<gfx::SlideAnimation> animation_; |
188 | 188 |
189 // The focus manager we register with to keep track of focus changes. | 189 // The focus manager we register with to keep track of focus changes. |
190 views::FocusManager* focus_manager_; | 190 views::FocusManager* focus_manager_; |
191 | 191 |
192 // True if the accelerator target for Esc key is registered. | 192 // True if the accelerator target for Esc key is registered. |
193 bool esc_accel_target_registered_; | 193 bool esc_accel_target_registered_; |
194 | 194 |
195 // Tracks and stores the last focused view which is not the DropdownBarView | 195 // Tracks and stores the last focused view which is not the DropdownBarView |
196 // or any of its children. Used to restore focus once the DropdownBarView is | 196 // or any of its children. Used to restore focus once the DropdownBarView is |
197 // closed. | 197 // closed. |
198 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; | 198 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; |
199 | 199 |
200 // Host is the Widget implementation that is created and maintained by the | 200 // Host is the Widget implementation that is created and maintained by the |
201 // dropdown bar. It contains the DropdownBarView. | 201 // dropdown bar. It contains the DropdownBarView. |
202 scoped_ptr<views::Widget> host_; | 202 scoped_ptr<views::Widget> host_; |
203 | 203 |
204 // A flag to manually manage visibility. GTK/X11 is asynchronous and | 204 // A flag to manually manage visibility. GTK/X11 is asynchronous and |
205 // the state of the widget can be out of sync. | 205 // the state of the widget can be out of sync. |
206 bool is_visible_; | 206 bool is_visible_; |
207 | 207 |
208 DISALLOW_COPY_AND_ASSIGN(DropdownBarHost); | 208 DISALLOW_COPY_AND_ASSIGN(DropdownBarHost); |
209 }; | 209 }; |
210 | 210 |
211 #endif // CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ | 211 #endif // CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ |
OLD | NEW |