Chromium Code Reviews| Index: ui/views/bubble/tray_bubble_view.cc |
| diff --git a/ui/views/bubble/tray_bubble_view.cc b/ui/views/bubble/tray_bubble_view.cc |
| index ad3267fe6592c034a1dffd9794ae11e4449b1bb4..6c276349b91b6a4ab3611e318f7c21e4320d24d8 100644 |
| --- a/ui/views/bubble/tray_bubble_view.cc |
| +++ b/ui/views/bubble/tray_bubble_view.cc |
| @@ -281,14 +281,14 @@ TrayBubbleView::InitParams::InitParams(AnchorType anchor_type, |
| max_height(0), |
| can_activate(false), |
| close_on_deactivate(true), |
| + close_via_capture(false), |
| arrow_color(SK_ColorBLACK), |
| first_item_has_no_margin(false), |
| arrow(BubbleBorder::NONE), |
| arrow_offset(kArrowDefaultOffset), |
| arrow_paint_type(BubbleBorder::PAINT_NORMAL), |
| shadow(BubbleBorder::BIG_SHADOW), |
| - arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) { |
| -} |
| + arrow_alignment(BubbleBorder::ALIGN_EDGE_TO_ANCHOR_EDGE) {} |
| TrayBubbleView::InitParams::InitParams(const InitParams& other) = default; |
| @@ -356,6 +356,12 @@ void TrayBubbleView::InitializeAndShowBubble() { |
| GetWidget()->GetNativeWindow()->SetEventTargeter( |
| scoped_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); |
| UpdateBubble(); |
| + |
| + if (params_.close_via_capture) { |
| + GetWidget()->set_auto_release_capture(false); |
| + // Capture events to this view so it will be notified of capture loss. |
| + GetWidget()->SetCapture(this); |
|
sadrul
2016/04/14 20:08:35
This unfortunately breaks clicking in the tray-bub
James Cook
2016/04/14 23:05:12
Unfortunately setting the capture to a nullptr vie
|
| + } |
| } |
| void TrayBubbleView::UpdateBubble() { |
| @@ -448,6 +454,13 @@ int TrayBubbleView::GetHeightForWidth(int width) const { |
| std::min(height, params_.max_height) : height; |
| } |
| +void TrayBubbleView::OnMouseCaptureLost() { |
| + if (params_.close_via_capture && delegate_) { |
| + // Let the delegate destroy the bubble in case it needs to do cleanup. |
| + delegate_->HideBubble(this); |
| + } |
| +} |
| + |
| void TrayBubbleView::OnMouseEntered(const ui::MouseEvent& event) { |
| mouse_watcher_.reset(); |
| if (delegate_ && !(event.flags() & ui::EF_IS_SYNTHESIZED)) { |
| @@ -482,6 +495,17 @@ void TrayBubbleView::OnMouseExited(const ui::MouseEvent& event) { |
| delegate_->OnMouseExitedView(); |
| } |
| +bool TrayBubbleView::OnMousePressed(const ui::MouseEvent& event) { |
| + if (params_.close_via_capture && GetWidget()->HasCapture() && |
| + !bounds().Contains(event.location())) { |
| + // Explicitly releasing capture will close the bubble. |
| + GetWidget()->ReleaseCapture(); |
| + // Don't return that the event was handled because other views may want to |
| + // handle it or the window server may want to repost it. |
| + } |
| + return views::BubbleDelegateView::OnMousePressed(event); |
| +} |
| + |
| void TrayBubbleView::GetAccessibleState(ui::AXViewState* state) { |
| if (delegate_ && params_.can_activate) { |
| state->role = ui::AX_ROLE_WINDOW; |