Chromium Code Reviews| Index: chrome/browser/ui/views/dropdown_bar_host.cc |
| diff --git a/chrome/browser/ui/views/dropdown_bar_host.cc b/chrome/browser/ui/views/dropdown_bar_host.cc |
| index 6360b5d89ed91022c086324c1d0ff58abb68435d..e8ad0741506b719c38ae3e4b764537f4521370c6 100644 |
| --- a/chrome/browser/ui/views/dropdown_bar_host.cc |
| +++ b/chrome/browser/ui/views/dropdown_bar_host.cc |
| @@ -25,12 +25,17 @@ bool DropdownBarHost::disable_animations_during_testing_ = false; |
| DropdownBarHost::DropdownBarHost(BrowserView* browser_view) |
| : browser_view_(browser_view), |
| + clip_view_(new views::View()), |
| view_(NULL), |
| delegate_(NULL), |
| - animation_offset_(0), |
| focus_manager_(NULL), |
| esc_accel_target_registered_(false), |
| is_visible_(false) { |
| + // The |clip_view_| must paint to a layer so that it can clip descendent Views |
| + // which also paint to a Layer. |
| + clip_view_->SetPaintToLayer(true); |
| + clip_view_->SetFillsBoundsOpaquely(false); |
| + clip_view_->layer()->SetMasksToBounds(true); |
| } |
| void DropdownBarHost::Init(views::View* host_view, |
| @@ -49,7 +54,8 @@ void DropdownBarHost::Init(views::View* host_view, |
| params.parent = browser_view_->GetWidget()->GetNativeView(); |
| params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW; |
| host_->Init(params); |
| - host_->SetContentsView(view_); |
| + host_->SetContentsView(clip_view_); |
| + clip_view_->AddChildView(view_); |
| SetHostViewNative(host_view); |
| @@ -64,8 +70,9 @@ void DropdownBarHost::Init(views::View* host_view, |
| NOTREACHED(); |
| } |
| - // Start the process of animating the opening of the widget. |
| animation_.reset(new gfx::SlideAnimation(this)); |
| + // Update the widget and |view_| bounds to the hidden state. |
| + AnimationProgressed(animation_.get()); |
| } |
| DropdownBarHost::~DropdownBarHost() { |
| @@ -78,6 +85,11 @@ void DropdownBarHost::Show(bool animate) { |
| // restore focus when the dropdown widget is closed. |
| focus_tracker_.reset(new views::ExternalFocusTracker(view_, focus_manager_)); |
| + gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
| + SetDialogPosition(dlg_rect); |
|
Peter Kasting
2015/11/24 22:39:43
Nit: Just: SetDialogPosition(GetDialogPosition(gfx
bruthig
2015/11/25 16:55:06
Done.
|
| + |
| + host_->Show(); |
| + |
| bool was_visible = is_visible_; |
| is_visible_ = true; |
| if (!animate || disable_animations_during_testing_) { |
| @@ -132,6 +144,17 @@ bool DropdownBarHost::IsVisible() const { |
| return is_visible_; |
| } |
| +void DropdownBarHost::SetDialogPosition(const gfx::Rect& new_pos) { |
| + view_->SetSize(new_pos.size()); |
| + |
| + if (new_pos.IsEmpty()) |
| + return; |
|
Peter Kasting
2015/11/24 22:39:43
Should this hide the host if it's currently visibl
bruthig
2015/11/25 16:55:06
No, not from what I can tell anyway. From what I
Peter Kasting
2015/11/25 23:16:54
I don't really know what this code does so I can't
|
| + |
| + if (!host()->IsVisible()) |
| + host()->Show(); |
| + host()->SetBounds(new_pos); |
| +} |
| + |
| //////////////////////////////////////////////////////////////////////////////// |
| // DropdownBarHost, views::FocusChangeListener implementation: |
| void DropdownBarHost::OnWillChangeFocus(views::View* focused_before, |
| @@ -167,24 +190,16 @@ void DropdownBarHost::OnDidChangeFocus(views::View* focused_before, |
| void DropdownBarHost::AnimationProgressed(const gfx::Animation* animation) { |
| // First, we calculate how many pixels to slide the widget. |
| gfx::Size pref_size = view_->GetPreferredSize(); |
| - animation_offset_ = static_cast<int>((1.0 - animation_->GetCurrentValue()) * |
| - pref_size.height()); |
| + int view_offset = static_cast<int>((animation_->GetCurrentValue() - 1.0) * |
| + pref_size.height()); |
| - // This call makes sure it appears in the right location, the size and shape |
| - // is correct and that it slides in the right direction. |
| + // This call makes sure |view_| appears in the right location, the size and |
| + // shape is correct and that it slides in the right direction. |
| gfx::Rect dlg_rect = GetDialogPosition(gfx::Rect()); |
|
Peter Kasting
2015/11/24 22:39:43
This temp is now unused.
bruthig
2015/11/25 16:55:06
Done.
|
| - SetDialogPosition(dlg_rect); |
| - |
| - // Let the view know if we are animating, and at which offset to draw the |
| - // edges. |
| - delegate_->SetAnimationOffset(animation_offset_); |
| - view_->SchedulePaint(); |
| + view_->SetPosition(gfx::Point(0, view_offset)); |
| } |
| void DropdownBarHost::AnimationEnded(const gfx::Animation* animation) { |
| - // Place the dropdown widget in its fully opened state. |
| - animation_offset_ = 0; |
| - |
| if (!animation_->IsShowing()) { |
| // Animation has finished closing. |
| host_->Hide(); |