OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/views/dropdown_bar_host.h" | 5 #include "chrome/browser/ui/views/dropdown_bar_host.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "chrome/browser/ui/view_ids.h" | 9 #include "chrome/browser/ui/view_ids.h" |
10 #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" | 10 #include "chrome/browser/ui/views/dropdown_bar_host_delegate.h" |
11 #include "chrome/browser/ui/views/dropdown_bar_view.h" | 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
12 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
13 #include "ui/base/animation/slide_animation.h" | |
14 #include "ui/base/keycodes/keyboard_codes.h" | 13 #include "ui/base/keycodes/keyboard_codes.h" |
| 14 #include "ui/gfx/animation/slide_animation.h" |
15 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
16 #include "ui/gfx/scrollbar_size.h" | 16 #include "ui/gfx/scrollbar_size.h" |
17 #include "ui/views/focus/external_focus_tracker.h" | 17 #include "ui/views/focus/external_focus_tracker.h" |
18 #include "ui/views/focus/view_storage.h" | 18 #include "ui/views/focus/view_storage.h" |
19 #include "ui/views/widget/widget.h" | 19 #include "ui/views/widget/widget.h" |
20 | 20 |
21 #if defined(USE_AURA) | 21 #if defined(USE_AURA) |
22 #include "ui/gfx/scoped_sk_region.h" | 22 #include "ui/gfx/scoped_sk_region.h" |
23 #elif defined(OS_WIN) | 23 #elif defined(OS_WIN) |
24 #include "base/win/scoped_gdi_object.h" | 24 #include "base/win/scoped_gdi_object.h" |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 focus_manager_ = host_->GetFocusManager(); | 79 focus_manager_ = host_->GetFocusManager(); |
80 if (focus_manager_) { | 80 if (focus_manager_) { |
81 focus_manager_->AddFocusChangeListener(this); | 81 focus_manager_->AddFocusChangeListener(this); |
82 } else { | 82 } else { |
83 // In some cases (see bug http://crbug.com/17056) it seems we may not have | 83 // In some cases (see bug http://crbug.com/17056) it seems we may not have |
84 // a focus manager. Please reopen the bug if you hit this. | 84 // a focus manager. Please reopen the bug if you hit this. |
85 NOTREACHED(); | 85 NOTREACHED(); |
86 } | 86 } |
87 | 87 |
88 // Start the process of animating the opening of the widget. | 88 // Start the process of animating the opening of the widget. |
89 animation_.reset(new ui::SlideAnimation(this)); | 89 animation_.reset(new gfx::SlideAnimation(this)); |
90 } | 90 } |
91 | 91 |
92 DropdownBarHost::~DropdownBarHost() { | 92 DropdownBarHost::~DropdownBarHost() { |
93 focus_manager_->RemoveFocusChangeListener(this); | 93 focus_manager_->RemoveFocusChangeListener(this); |
94 focus_tracker_.reset(NULL); | 94 focus_tracker_.reset(NULL); |
95 } | 95 } |
96 | 96 |
97 void DropdownBarHost::Show(bool animate) { | 97 void DropdownBarHost::Show(bool animate) { |
98 // Stores the currently focused view, and tracks focus changes so that we can | 98 // Stores the currently focused view, and tracks focus changes so that we can |
99 // restore focus when the dropdown widget is closed. | 99 // restore focus when the dropdown widget is closed. |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 // original handler for Escape. | 176 // original handler for Escape. |
177 UnregisterAccelerators(); | 177 UnregisterAccelerators(); |
178 } | 178 } |
179 } | 179 } |
180 | 180 |
181 void DropdownBarHost::OnDidChangeFocus(views::View* focused_before, | 181 void DropdownBarHost::OnDidChangeFocus(views::View* focused_before, |
182 views::View* focused_now) { | 182 views::View* focused_now) { |
183 } | 183 } |
184 | 184 |
185 //////////////////////////////////////////////////////////////////////////////// | 185 //////////////////////////////////////////////////////////////////////////////// |
186 // DropdownBarHost, ui::AnimationDelegate implementation: | 186 // DropdownBarHost, gfx::AnimationDelegate implementation: |
187 | 187 |
188 void DropdownBarHost::AnimationProgressed(const ui::Animation* animation) { | 188 void DropdownBarHost::AnimationProgressed(const gfx::Animation* animation) { |
189 // First, we calculate how many pixels to slide the widget. | 189 // First, we calculate how many pixels to slide the widget. |
190 gfx::Size pref_size = view_->GetPreferredSize(); | 190 gfx::Size pref_size = view_->GetPreferredSize(); |
191 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * | 191 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * |
192 pref_size.height()); | 192 pref_size.height()); |
193 | 193 |
194 // This call makes sure it appears in the right location, the size and shape | 194 // This call makes sure it appears in the right location, the size and shape |
195 // is correct and that it slides in the right direction. | 195 // is correct and that it slides in the right direction. |
196 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); | 196 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
197 SetDialogPosition(dlg_rect, false); | 197 SetDialogPosition(dlg_rect, false); |
198 | 198 |
199 // Let the view know if we are animating, and at which offset to draw the | 199 // Let the view know if we are animating, and at which offset to draw the |
200 // edges. | 200 // edges. |
201 delegate_->SetAnimationOffset(animation_offset_); | 201 delegate_->SetAnimationOffset(animation_offset_); |
202 view_->SchedulePaint(); | 202 view_->SchedulePaint(); |
203 } | 203 } |
204 | 204 |
205 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { | 205 void DropdownBarHost::AnimationEnded(const gfx::Animation* animation) { |
206 // Place the dropdown widget in its fully opened state. | 206 // Place the dropdown widget in its fully opened state. |
207 animation_offset_ = 0; | 207 animation_offset_ = 0; |
208 | 208 |
209 if (!animation_->IsShowing()) { | 209 if (!animation_->IsShowing()) { |
210 // Animation has finished closing. | 210 // Animation has finished closing. |
211 host_->Hide(); | 211 host_->Hide(); |
212 is_visible_ = false; | 212 is_visible_ = false; |
213 OnVisibilityChanged(); | 213 OnVisibilityChanged(); |
214 } else { | 214 } else { |
215 // Animation has finished opening. | 215 // Animation has finished opening. |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
347 escape, ui::AcceleratorManager::kNormalPriority, this); | 347 escape, ui::AcceleratorManager::kNormalPriority, this); |
348 esc_accel_target_registered_ = true; | 348 esc_accel_target_registered_ = true; |
349 } | 349 } |
350 | 350 |
351 void DropdownBarHost::UnregisterAccelerators() { | 351 void DropdownBarHost::UnregisterAccelerators() { |
352 DCHECK(esc_accel_target_registered_); | 352 DCHECK(esc_accel_target_registered_); |
353 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); | 353 ui::Accelerator escape(ui::VKEY_ESCAPE, ui::EF_NONE); |
354 focus_manager_->UnregisterAccelerator(escape, this); | 354 focus_manager_->UnregisterAccelerator(escape, this); |
355 esc_accel_target_registered_ = false; | 355 esc_accel_target_registered_ = false; |
356 } | 356 } |
OLD | NEW |