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_view.h" | 10 #include "chrome/browser/ui/views/dropdown_bar_view.h" |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 37 | 37 |
| 38 // static | 38 // static |
| 39 bool DropdownBarHost::disable_animations_during_testing_ = false; | 39 bool DropdownBarHost::disable_animations_during_testing_ = false; |
| 40 | 40 |
| 41 //////////////////////////////////////////////////////////////////////////////// | 41 //////////////////////////////////////////////////////////////////////////////// |
| 42 // DropdownBarHost, public: | 42 // DropdownBarHost, public: |
| 43 | 43 |
| 44 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) | 44 DropdownBarHost::DropdownBarHost(BrowserView* browser_view) |
| 45 : browser_view_(browser_view), | 45 : browser_view_(browser_view), |
| 46 view_(NULL), | 46 view_(NULL), |
| 47 delegate_(NULL), | |
| 47 animation_offset_(0), | 48 animation_offset_(0), |
| 48 focus_manager_(NULL), | 49 focus_manager_(NULL), |
| 49 esc_accel_target_registered_(false), | 50 esc_accel_target_registered_(false), |
| 50 is_visible_(false) { | 51 is_visible_(false) { |
| 51 } | 52 } |
| 52 | 53 |
| 53 void DropdownBarHost::Init(DropdownBarView* view) { | 54 void DropdownBarHost::Init(views::View* view, Delegate* delegate) { |
| 55 delegate_ = delegate; | |
| 54 view_ = view; | 56 view_ = view; |
| 55 | 57 |
| 56 // Initialize the host. | 58 // Initialize the host. |
| 57 host_.reset(views::Widget::CreateWidget()); | 59 host_.reset(views::Widget::CreateWidget()); |
| 58 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); | 60 views::Widget::InitParams params(views::Widget::InitParams::TYPE_CONTROL); |
| 59 params.delete_on_destroy = false; | 61 params.delete_on_destroy = false; |
| 60 params.parent_widget = browser_view_->GetWidget(); | 62 params.parent_widget = browser_view_->GetWidget(); |
| 61 host_->Init(params); | 63 host_->Init(params); |
| 62 host_->SetContentsView(view_); | 64 host_->SetContentsView(view_); |
| 63 | 65 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 95 if (!is_visible_) { | 97 if (!is_visible_) { |
| 96 // Don't re-start the animation. | 98 // Don't re-start the animation. |
| 97 is_visible_ = true; | 99 is_visible_ = true; |
| 98 animation_->Reset(); | 100 animation_->Reset(); |
| 99 animation_->Show(); | 101 animation_->Show(); |
| 100 } | 102 } |
| 101 } | 103 } |
| 102 } | 104 } |
| 103 | 105 |
| 104 void DropdownBarHost::SetFocusAndSelection() { | 106 void DropdownBarHost::SetFocusAndSelection() { |
| 105 view_->SetFocusAndSelection(true); | 107 delegate_->SetFocusAndSelection(true); |
|
sky
2011/05/03 18:38:32
If delegate_ must be non-null, add a DCHECK to tha
SteveT
2011/05/06 18:48:43
Ah, yes. Done in Init() (and for view, too).
| |
| 106 } | 108 } |
| 107 | 109 |
| 108 bool DropdownBarHost::IsAnimating() const { | 110 bool DropdownBarHost::IsAnimating() const { |
| 109 return animation_->is_animating(); | 111 return animation_->is_animating(); |
| 110 } | 112 } |
| 111 | 113 |
| 112 void DropdownBarHost::Hide(bool animate) { | 114 void DropdownBarHost::Hide(bool animate) { |
| 113 if (!IsVisible()) | 115 if (!IsVisible()) |
| 114 return; | 116 return; |
| 115 if (animate && !disable_animations_during_testing_) { | 117 if (animate && !disable_animations_during_testing_) { |
| 116 animation_->Reset(1.0); | 118 if (!animation_->IsClosing()) { |
|
sky
2011/05/03 18:38:32
Doesn't slideanimation take care of this for you?
SteveT
2011/05/06 18:48:43
Right, that's true. Removed the Reset call.
| |
| 117 animation_->Hide(); | 119 animation_->Reset(1.0); |
| 120 animation_->Hide(); | |
| 121 } | |
| 118 } else { | 122 } else { |
| 119 StopAnimation(); | 123 if (animation_->IsClosing()) { |
|
sky
2011/05/03 18:38:32
I don't understand this code. This is the !animate
SteveT
2011/05/06 18:48:43
Sorry - I think my weak comment confused things a
| |
| 120 is_visible_ = false; | 124 StopAnimation(); |
| 121 host_->Hide(); | 125 } else { |
| 126 animation_->Reset(); | |
| 127 animation_->Hide(); | |
| 128 // When we call Reset, our AnimationEnded is called when we're not | |
| 129 // showing, so our widget is not correctly hidden. Explicitly hide it. | |
| 130 is_visible_ = false; | |
| 131 host_->Hide(); | |
| 132 } | |
| 122 } | 133 } |
| 123 } | 134 } |
| 124 | 135 |
| 125 void DropdownBarHost::StopAnimation() { | 136 void DropdownBarHost::StopAnimation() { |
| 126 animation_->End(); | 137 animation_->End(); |
| 127 } | 138 } |
| 128 | 139 |
| 129 bool DropdownBarHost::IsVisible() const { | 140 bool DropdownBarHost::IsVisible() const { |
| 130 return is_visible_; | 141 return is_visible_; |
| 131 } | 142 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 164 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * | 175 animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * |
| 165 pref_size.height()); | 176 pref_size.height()); |
| 166 | 177 |
| 167 // This call makes sure it appears in the right location, the size and shape | 178 // 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. | 179 // is correct and that it slides in the right direction. |
| 169 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); | 180 gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
| 170 SetDialogPosition(dlg_rect, false); | 181 SetDialogPosition(dlg_rect, false); |
| 171 | 182 |
| 172 // Let the view know if we are animating, and at which offset to draw the | 183 // Let the view know if we are animating, and at which offset to draw the |
| 173 // edges. | 184 // edges. |
| 174 view_->set_animation_offset(animation_offset_); | 185 delegate_->set_animation_offset(animation_offset_); |
| 175 view_->SchedulePaint(); | 186 view_->SchedulePaint(); |
| 176 } | 187 } |
| 177 | 188 |
| 178 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { | 189 void DropdownBarHost::AnimationEnded(const ui::Animation* animation) { |
| 179 // Place the dropdown widget in its fully opened state. | 190 // Place the dropdown widget in its fully opened state. |
| 180 animation_offset_ = 0; | 191 animation_offset_ = 0; |
| 181 | 192 |
| 182 if (!animation_->IsShowing()) { | 193 if (!animation_->IsShowing()) { |
| 183 // Animation has finished closing. | 194 // Animation has finished closing. |
| 184 host_->Hide(); | 195 host_->Hide(); |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 focus_manager_->RegisterAccelerator(escape, this); | 326 focus_manager_->RegisterAccelerator(escape, this); |
| 316 esc_accel_target_registered_ = true; | 327 esc_accel_target_registered_ = true; |
| 317 } | 328 } |
| 318 | 329 |
| 319 void DropdownBarHost::UnregisterAccelerators() { | 330 void DropdownBarHost::UnregisterAccelerators() { |
| 320 DCHECK(esc_accel_target_registered_); | 331 DCHECK(esc_accel_target_registered_); |
| 321 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); | 332 views::Accelerator escape(ui::VKEY_ESCAPE, false, false, false); |
| 322 focus_manager_->UnregisterAccelerator(escape, this); | 333 focus_manager_->UnregisterAccelerator(escape, this); |
| 323 esc_accel_target_registered_ = false; | 334 esc_accel_target_registered_ = false; |
| 324 } | 335 } |
| OLD | NEW |