OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 #pragma once | 7 #pragma once |
8 | 8 |
9 #include "app/animation_delegate.h" | |
10 #include "base/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
11 #include "chrome/common/native_web_keyboard_event.h" | 10 #include "chrome/common/native_web_keyboard_event.h" |
12 #include "gfx/native_widget_types.h" | 11 #include "gfx/native_widget_types.h" |
13 #include "gfx/rect.h" | 12 #include "gfx/rect.h" |
| 13 #include "ui/base/animation/animation_delegate.h" |
14 #include "views/controls/textfield/textfield.h" | 14 #include "views/controls/textfield/textfield.h" |
15 #include "views/focus/focus_manager.h" | 15 #include "views/focus/focus_manager.h" |
16 | 16 |
17 class BrowserView; | 17 class BrowserView; |
18 class DropdownBarView; | 18 class DropdownBarView; |
| 19 class TabContents; |
| 20 |
| 21 namespace ui { |
19 class SlideAnimation; | 22 class SlideAnimation; |
20 class TabContents; | 23 } |
21 | 24 |
22 namespace views { | 25 namespace views { |
23 class ExternalFocusTracker; | 26 class ExternalFocusTracker; |
24 class View; | 27 class View; |
25 class Widget; | 28 class Widget; |
26 } | 29 } |
27 | 30 |
28 //////////////////////////////////////////////////////////////////////////////// | 31 //////////////////////////////////////////////////////////////////////////////// |
29 // | 32 // |
30 // The DropdownBarHost implements the container widget for the UI that | 33 // The DropdownBarHost implements the container widget for the UI that |
31 // is shown at the top of browser contents. It uses the appropriate | 34 // is shown at the top of browser contents. It uses the appropriate |
32 // implementation from dropdown_bar_host_win.cc or dropdown_bar_host_gtk.cc to | 35 // implementation from dropdown_bar_host_win.cc or dropdown_bar_host_gtk.cc to |
33 // draw its content and is responsible for showing, hiding, animating, closing, | 36 // draw its content and is responsible for showing, hiding, animating, closing, |
34 // and moving the bar if needed, for example if the widget is | 37 // and moving the bar if needed, for example if the widget is |
35 // obscuring the selection results in FindBar. | 38 // obscuring the selection results in FindBar. |
36 // | 39 // |
37 //////////////////////////////////////////////////////////////////////////////// | 40 //////////////////////////////////////////////////////////////////////////////// |
38 class DropdownBarHost : public views::AcceleratorTarget, | 41 class DropdownBarHost : public views::AcceleratorTarget, |
39 public views::FocusChangeListener, | 42 public views::FocusChangeListener, |
40 public AnimationDelegate { | 43 public ui::AnimationDelegate { |
41 public: | 44 public: |
42 explicit DropdownBarHost(BrowserView* browser_view); | 45 explicit DropdownBarHost(BrowserView* browser_view); |
43 virtual ~DropdownBarHost(); | 46 virtual ~DropdownBarHost(); |
44 | 47 |
45 // Initializes the dropdown bar host with the give view. | 48 // Initializes the dropdown bar host with the give view. |
46 void Init(DropdownBarView* view); | 49 void Init(DropdownBarView* view); |
47 | 50 |
48 // Whether we are animating the position of the dropdown widget. | 51 // Whether we are animating the position of the dropdown widget. |
49 bool IsAnimating() const; | 52 bool IsAnimating() const; |
50 // Returns true if the dropdown bar view is visible, or false otherwise. | 53 // Returns true if the dropdown bar view is visible, or false otherwise. |
(...skipping 16 matching lines...) Expand all Loading... |
67 // the widget (if hidden). | 70 // the widget (if hidden). |
68 virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) = 0; | 71 virtual void SetDialogPosition(const gfx::Rect& new_pos, bool no_redraw) = 0; |
69 | 72 |
70 // Overridden from views::FocusChangeListener: | 73 // Overridden from views::FocusChangeListener: |
71 virtual void FocusWillChange(views::View* focused_before, | 74 virtual void FocusWillChange(views::View* focused_before, |
72 views::View* focused_now); | 75 views::View* focused_now); |
73 | 76 |
74 // Overridden from views::AcceleratorTarget: | 77 // Overridden from views::AcceleratorTarget: |
75 virtual bool AcceleratorPressed(const views::Accelerator& accelerator) = 0; | 78 virtual bool AcceleratorPressed(const views::Accelerator& accelerator) = 0; |
76 | 79 |
77 // AnimationDelegate implementation: | 80 // ui::AnimationDelegate implementation: |
78 virtual void AnimationProgressed(const Animation* animation); | 81 virtual void AnimationProgressed(const ui::Animation* animation); |
79 virtual void AnimationEnded(const Animation* animation); | 82 virtual void AnimationEnded(const ui::Animation* animation); |
80 | 83 |
81 // During testing we can disable animations by setting this flag to true, | 84 // During testing we can disable animations by setting this flag to true, |
82 // so that opening and closing the dropdown bar is shown instantly, instead of | 85 // so that opening and closing the dropdown bar is shown instantly, instead of |
83 // having to poll it while it animates to open/closed status. | 86 // having to poll it while it animates to open/closed status. |
84 static bool disable_animations_during_testing_; | 87 static bool disable_animations_during_testing_; |
85 | 88 |
86 // Returns the browser view that the dropdown belongs to. | 89 // Returns the browser view that the dropdown belongs to. |
87 BrowserView* browser_view() const { return browser_view_; } | 90 BrowserView* browser_view() const { return browser_view_; } |
88 | 91 |
89 // Registers this class as the handler for when Escape is pressed. Once we | 92 // Registers this class as the handler for when Escape is pressed. Once we |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
138 | 141 |
139 // Allows implementation to tweak widget position. | 142 // Allows implementation to tweak widget position. |
140 void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); | 143 void SetWidgetPositionNative(const gfx::Rect& new_pos, bool no_redraw); |
141 | 144 |
142 // Returns a keyboard event suitable for forwarding. | 145 // Returns a keyboard event suitable for forwarding. |
143 NativeWebKeyboardEvent GetKeyboardEvent( | 146 NativeWebKeyboardEvent GetKeyboardEvent( |
144 const TabContents* contents, | 147 const TabContents* contents, |
145 const views::KeyEvent& key_event); | 148 const views::KeyEvent& key_event); |
146 | 149 |
147 // Returns the animation for the dropdown. | 150 // Returns the animation for the dropdown. |
148 SlideAnimation* animation() { | 151 ui::SlideAnimation* animation() { |
149 return animation_.get(); | 152 return animation_.get(); |
150 } | 153 } |
151 | 154 |
152 private: | 155 private: |
153 // The BrowserView that created us. | 156 // The BrowserView that created us. |
154 BrowserView* browser_view_; | 157 BrowserView* browser_view_; |
155 | 158 |
156 // Our view, which is responsible for drawing the UI. | 159 // Our view, which is responsible for drawing the UI. |
157 DropdownBarView* view_; | 160 DropdownBarView* view_; |
158 | 161 |
159 // The y position pixel offset of the widget while animating the | 162 // The y position pixel offset of the widget while animating the |
160 // dropdown widget. | 163 // dropdown widget. |
161 int animation_offset_; | 164 int animation_offset_; |
162 | 165 |
163 // The animation class to use when opening the Dropdown widget. | 166 // The animation class to use when opening the Dropdown widget. |
164 scoped_ptr<SlideAnimation> animation_; | 167 scoped_ptr<ui::SlideAnimation> animation_; |
165 | 168 |
166 // The focus manager we register with to keep track of focus changes. | 169 // The focus manager we register with to keep track of focus changes. |
167 views::FocusManager* focus_manager_; | 170 views::FocusManager* focus_manager_; |
168 | 171 |
169 // True if the accelerator target for Esc key is registered. | 172 // True if the accelerator target for Esc key is registered. |
170 bool esc_accel_target_registered_; | 173 bool esc_accel_target_registered_; |
171 | 174 |
172 // Tracks and stores the last focused view which is not the DropdownBarView | 175 // Tracks and stores the last focused view which is not the DropdownBarView |
173 // or any of its children. Used to restore focus once the DropdownBarView is | 176 // or any of its children. Used to restore focus once the DropdownBarView is |
174 // closed. | 177 // closed. |
175 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; | 178 scoped_ptr<views::ExternalFocusTracker> focus_tracker_; |
176 | 179 |
177 // Host is the Widget implementation that is created and maintained by the | 180 // Host is the Widget implementation that is created and maintained by the |
178 // dropdown bar. It contains the DropdownBarView. | 181 // dropdown bar. It contains the DropdownBarView. |
179 scoped_ptr<views::Widget> host_; | 182 scoped_ptr<views::Widget> host_; |
180 | 183 |
181 // A flag to manually manage visibility. GTK/X11 is asynchronous and | 184 // A flag to manually manage visibility. GTK/X11 is asynchronous and |
182 // the state of the widget can be out of sync. | 185 // the state of the widget can be out of sync. |
183 bool is_visible_; | 186 bool is_visible_; |
184 | 187 |
185 DISALLOW_COPY_AND_ASSIGN(DropdownBarHost); | 188 DISALLOW_COPY_AND_ASSIGN(DropdownBarHost); |
186 }; | 189 }; |
187 | 190 |
188 #endif // CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ | 191 #endif // CHROME_BROWSER_UI_VIEWS_DROPDOWN_BAR_HOST_H_ |
OLD | NEW |