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 #include "chrome/browser/views/dropdown_bar_host.h" | 5 #include "chrome/browser/views/dropdown_bar_host.h" |
6 | 6 |
7 #include "app/keyboard_codes.h" | 7 #include "app/keyboard_codes.h" |
8 #include "app/slide_animation.h" | |
9 #include "chrome/browser/ui/browser.h" | 8 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
11 #include "chrome/browser/ui/views/dropdown_bar_view.h" | 10 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 11 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "gfx/path.h" | 12 #include "gfx/path.h" |
14 #include "gfx/scrollbar_size.h" | 13 #include "gfx/scrollbar_size.h" |
| 14 #include "ui/base/animation/slide_animation.h" |
15 #include "views/focus/external_focus_tracker.h" | 15 #include "views/focus/external_focus_tracker.h" |
16 #include "views/focus/view_storage.h" | 16 #include "views/focus/view_storage.h" |
17 #include "views/widget/widget.h" | 17 #include "views/widget/widget.h" |
18 | 18 |
19 #if defined(OS_WIN) | 19 #if defined(OS_WIN) |
20 #include "base/win/scoped_gdi_object.h" | 20 #include "base/win/scoped_gdi_object.h" |
21 #elif defined(OS_LINUX) | 21 #elif defined(OS_LINUX) |
22 #include "app/scoped_handle_gtk.h" | 22 #include "app/scoped_handle_gtk.h" |
23 #endif | 23 #endif |
24 | 24 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
61 views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView()); | 61 views::FocusManager::GetFocusManagerForNativeView(host_->GetNativeView()); |
62 if (focus_manager_) { | 62 if (focus_manager_) { |
63 focus_manager_->AddFocusChangeListener(this); | 63 focus_manager_->AddFocusChangeListener(this); |
64 } else { | 64 } else { |
65 // In some cases (see bug http://crbug.com/17056) it seems we may not have | 65 // In some cases (see bug http://crbug.com/17056) it seems we may not have |
66 // a focus manager. Please reopen the bug if you hit this. | 66 // a focus manager. Please reopen the bug if you hit this. |
67 NOTREACHED(); | 67 NOTREACHED(); |
68 } | 68 } |
69 | 69 |
70 // Start the process of animating the opening of the widget. | 70 // Start the process of animating the opening of the widget. |
71 animation_.reset(new SlideAnimation(this)); | 71 animation_.reset(new ui::SlideAnimation(this)); |
72 } | 72 } |
73 | 73 |
74 DropdownBarHost::~DropdownBarHost() { | 74 DropdownBarHost::~DropdownBarHost() { |
75 focus_manager_->RemoveFocusChangeListener(this); | 75 focus_manager_->RemoveFocusChangeListener(this); |
76 focus_tracker_.reset(NULL); | 76 focus_tracker_.reset(NULL); |
77 } | 77 } |
78 | 78 |
79 void DropdownBarHost::Show(bool animate) { | 79 void DropdownBarHost::Show(bool animate) { |
80 // Stores the currently focused view, and tracks focus changes so that we can | 80 // Stores the currently focused view, and tracks focus changes so that we can |
81 // restore focus when the dropdown widget is closed. | 81 // restore focus when the dropdown widget is closed. |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 // a handler for Escape. | 143 // a handler for Escape. |
144 RegisterAccelerators(); | 144 RegisterAccelerators(); |
145 } else if (our_view_before && !our_view_now) { | 145 } else if (our_view_before && !our_view_now) { |
146 // We are losing focus to something outside our widget so we restore the | 146 // We are losing focus to something outside our widget so we restore the |
147 // original handler for Escape. | 147 // original handler for Escape. |
148 UnregisterAccelerators(); | 148 UnregisterAccelerators(); |
149 } | 149 } |
150 } | 150 } |
151 | 151 |
152 //////////////////////////////////////////////////////////////////////////////// | 152 //////////////////////////////////////////////////////////////////////////////// |
153 // DropdownBarHost, AnimationDelegate implementation: | 153 // DropdownBarHost, ui::AnimationDelegate implementation: |
154 | 154 |
155 void DropdownBarHost::AnimationProgressed(const Animation* animation) { | 155 void DropdownBarHost::AnimationProgressed(const ui::Animation* animation) { |
156 // First, we calculate how many pixels to slide the widget. | 156 // First, we calculate how many pixels to slide the widget. |
157 gfx::Size pref_size = view_->GetPreferredSize(); | 157 gfx::Size pref_size = view_->GetPreferredSize(); |
158 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * | 158 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * |
159 pref_size.height()); | 159 pref_size.height()); |
160 | 160 |
161 // This call makes sure it appears in the right location, the size and shape | 161 // This call makes sure it appears in the right location, the size and shape |
162 // is correct and that it slides in the right direction. | 162 // is correct and that it slides in the right direction. |
163 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); | 163 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
164 SetDialogPosition(dlg_rect, false); | 164 SetDialogPosition(dlg_rect, false); |
165 | 165 |
166 // Let the view know if we are animating, and at which offset to draw the | 166 // Let the view know if we are animating, and at which offset to draw the |
167 // edges. | 167 // edges. |
168 view_->set_animation_offset(animation_offset_); | 168 view_->set_animation_offset(animation_offset_); |
169 view_->SchedulePaint(); | 169 view_->SchedulePaint(); |
170 } | 170 } |
171 | 171 |
172 void DropdownBarHost::AnimationEnded(const Animation* animation) { | 172 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { |
173 // Place the dropdown widget in its fully opened state. | 173 // Place the dropdown widget in its fully opened state. |
174 animation_offset_ = 0; | 174 animation_offset_ = 0; |
175 | 175 |
176 if (!animation_->IsShowing()) { | 176 if (!animation_->IsShowing()) { |
177 // Animation has finished closing. | 177 // Animation has finished closing. |
178 host_->Hide(); | 178 host_->Hide(); |
179 is_visible_ = false; | 179 is_visible_ = false; |
180 } else { | 180 } else { |
181 // Animation has finished opening. | 181 // Animation has finished opening. |
182 } | 182 } |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 focus_manager_->RegisterAccelerator(escape, this); | 309 focus_manager_->RegisterAccelerator(escape, this); |
310 esc_accel_target_registered_ = true; | 310 esc_accel_target_registered_ = true; |
311 } | 311 } |
312 | 312 |
313 void DropdownBarHost::UnregisterAccelerators() { | 313 void DropdownBarHost::UnregisterAccelerators() { |
314 DCHECK(esc_accel_target_registered_); | 314 DCHECK(esc_accel_target_registered_); |
315 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); | 315 views::Accelerator escape(app::VKEY_ESCAPE, false, false, false); |
316 focus_manager_->UnregisterAccelerator(escape, this); | 316 focus_manager_->UnregisterAccelerator(escape, this); |
317 esc_accel_target_registered_ = false; | 317 esc_accel_target_registered_ = false; |
318 } | 318 } |
OLD | NEW |