Chromium Code Reviews| 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 #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_view.h" | 11 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
| 11 #include "chrome/browser/ui/views/frame/browser_view.h" | 12 #include "chrome/browser/ui/views/frame/browser_view.h" |
| 12 #include "ui/base/animation/slide_animation.h" | 13 #include "ui/base/animation/slide_animation.h" |
| 13 #include "ui/base/keycodes/keyboard_codes.h" | 14 #include "ui/base/keycodes/keyboard_codes.h" |
| 14 #include "ui/gfx/path.h" | 15 #include "ui/gfx/path.h" |
| 15 #include "ui/gfx/scrollbar_size.h" | 16 #include "ui/gfx/scrollbar_size.h" |
| 16 #include "views/focus/external_focus_tracker.h" | 17 #include "views/focus/external_focus_tracker.h" |
| 17 #include "views/focus/view_storage.h" | 18 #include "views/focus/view_storage.h" |
| 18 #include "views/widget/widget.h" | 19 #include "views/widget/widget.h" |
| 19 | 20 |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 37 | 38 |
| 38 // static | 39 // static |
| 39 bool DropdownBarHost::disable_animations_during_testing_ = false; | 40 bool DropdownBarHost::disable_animations_during_testing_ = false; |
| 40 | 41 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 42 //////////////////////////////////////////////////////////////////////////////// |
| 42 // DropdownBarHost, public: | 43 // DropdownBarHost, public: |
| 43 | 44 |
| 44 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) | 45 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) |
| 45 : browser_view_(browser_view), | 46 : browser_view_(browser_view), |
| 46 view_(NULL), | 47 view_(NULL), |
| 48 delegate_(NULL), | |
| 47 animation_offset_(0), | 49 animation_offset_(0), |
| 48 focus_manager_(NULL), | 50 focus_manager_(NULL), |
| 49 esc_accel_target_registered_(false), | 51 esc_accel_target_registered_(false), |
| 50 is_visible_(false) { | 52 is_visible_(false) { |
| 51 } | 53 } |
| 52 | 54 |
| 53 void DropdownBarHost::Init(DropdownBarView* view) { | 55 void DropdownBarHost::Init(views::View* view, |
| 56 DropdownBarHostDelegate* delegate) { | |
| 57 DCHECK(view); | |
| 58 DCHECK(delegate); | |
| 59 | |
| 54 view_ = view; | 60 view_ = view; |
| 61 delegate_ = delegate; | |
| 55 | 62 |
| 56 // Initialize the host. | 63 // Initialize the host. |
| 57 host_.reset(views::Widget::CreateWidget()); | 64 host_.reset(views::Widget::CreateWidget()); |
| 58 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 65 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 59 params.delete_on_destroy = false; | 66 params.delete_on_destroy = false; |
| 60 params.parent_widget = browser_view_->GetWidget(); | 67 params.parent_widget = browser_view_->GetWidget(); |
| 61 host_->Init(params); | 68 host_->Init(params); |
| 62 host_->SetContentsView(view_); | 69 host_->SetContentsView(view_); |
| 63 | 70 |
| 64 // Start listening to focus changes, so we can register and unregister our | 71 // Start listening to focus changes, so we can register and unregister our |
| (...skipping 30 matching lines...) Expand all Loading... | |
| 95 if (!is_visible_) { | 102 if (!is_visible_) { |
| 96 // Don't re-start the animation. | 103 // Don't re-start the animation. |
| 97 is_visible_ = true; | 104 is_visible_ = true; |
| 98 animation_->Reset(); | 105 animation_->Reset(); |
| 99 animation_->Show(); | 106 animation_->Show(); |
| 100 } | 107 } |
| 101 } | 108 } |
| 102 } | 109 } |
| 103 | 110 |
| 104 void DropdownBarHost::SetFocusAndSelection() { | 111 void DropdownBarHost::SetFocusAndSelection() { |
| 105 view_->SetFocusAndSelection(true); | 112 delegate_->SetFocusAndSelection(true); |
| 106 } | 113 } |
| 107 | 114 |
| 108 bool DropdownBarHost::IsAnimating() const { | 115 bool DropdownBarHost::IsAnimating() const { |
| 109 return animation_->is_animating(); | 116 return animation_->is_animating(); |
| 110 } | 117 } |
| 111 | 118 |
| 112 void DropdownBarHost::Hide(bool animate) { | 119 void DropdownBarHost::Hide(bool animate) { |
| 113 if (!IsVisible()) | 120 if (!IsVisible()) |
| 114 return; | 121 return; |
| 115 if (animate && !disable_animations_during_testing_) { | 122 if (animate && !disable_animations_during_testing_) { |
| 116 animation_->Reset(1.0); | 123 if (!animation_->IsClosing()) { |
|
sky
2011/05/09 14:27:22
Do you really need the if?
SteveT
2011/05/09 19:40:04
No - removed.
| |
| 117 animation_->Hide(); | 124 animation_->Hide(); |
| 125 } | |
| 118 } else { | 126 } else { |
| 119 StopAnimation(); | 127 if (animation_->IsClosing()) { |
| 120 is_visible_ = false; | 128 // If we're in the middle of a close animation, skip immediately to the |
| 121 host_->Hide(); | 129 // end of the animation. |
| 130 StopAnimation(); | |
| 131 } else { | |
| 132 // Otherwise we need to set both the animation state to ended and the | |
| 133 // DropdownBarHost state to ended/hidden, otherwise the next time we try | |
| 134 // to show the bar, it might refuse to do so. Note that we call | |
| 135 // AnimationEnded ourselves as Reset does not call it if we are not | |
| 136 // animating here. | |
| 137 animation_->Reset(); | |
| 138 animation_->Hide(); | |
|
sky
2011/05/09 14:27:22
I don't think you need the hide here.
SteveT
2011/05/09 19:40:04
Yes - The reset will put animation_ back in the co
| |
| 139 AnimationEnded(animation_.get()); | |
| 140 } | |
| 122 } | 141 } |
| 123 } | 142 } |
| 124 | 143 |
| 125 void DropdownBarHost::StopAnimation() { | 144 void DropdownBarHost::StopAnimation() { |
| 126 animation_->End(); | 145 animation_->End(); |
| 127 } | 146 } |
| 128 | 147 |
| 129 bool DropdownBarHost::IsVisible() const { | 148 bool DropdownBarHost::IsVisible() const { |
| 130 return is_visible_; | 149 return is_visible_; |
| 131 } | 150 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * | 183 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * |
| 165 pref_size.height()); | 184 pref_size.height()); |
| 166 | 185 |
| 167 // This call makes sure it appears in the right location, the size and shape | 186 // This call makes sure it appears in the right location, the size and shape |
| 168 // is correct and that it slides in the right direction. | 187 // is correct and that it slides in the right direction. |
| 169 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); | 188 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
| 170 SetDialogPosition(dlg_rect, false); | 189 SetDialogPosition(dlg_rect, false); |
| 171 | 190 |
| 172 // Let the view know if we are animating, and at which offset to draw the | 191 // Let the view know if we are animating, and at which offset to draw the |
| 173 // edges. | 192 // edges. |
| 174 view_->set_animation_offset(animation_offset_); | 193 delegate_->SetAnimationOffset(animation_offset_); |
| 175 view_->SchedulePaint(); | 194 view_->SchedulePaint(); |
| 176 } | 195 } |
| 177 | 196 |
| 178 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { | 197 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { |
| 179 // Place the dropdown widget in its fully opened state. | 198 // Place the dropdown widget in its fully opened state. |
| 180 animation_offset_ = 0; | 199 animation_offset_ = 0; |
| 181 | 200 |
| 182 if (!animation_->IsShowing()) { | 201 if (!animation_->IsShowing()) { |
| 183 // Animation has finished closing. | 202 // Animation has finished closing. |
| 184 host_->Hide(); | 203 host_->Hide(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 focus_manager_->RegisterAccelerator(escape, this); | 334 focus_manager_->RegisterAccelerator(escape, this); |
| 316 esc_accel_target_registered_ = true; | 335 esc_accel_target_registered_ = true; |
| 317 } | 336 } |
| 318 | 337 |
| 319 void DropdownBarHost::UnregisterAccelerators() { | 338 void DropdownBarHost::UnregisterAccelerators() { |
| 320 DCHECK(esc_accel_target_registered_); | 339 DCHECK(esc_accel_target_registered_); |
| 321 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); | 340 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); |
| 322 focus_manager_->UnregisterAccelerator(escape, this); | 341 focus_manager_->UnregisterAccelerator(escape, this); |
| 323 esc_accel_target_registered_ = false; | 342 esc_accel_target_registered_ = false; |
| 324 } | 343 } |
| OLD | NEW |