| 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 "ui/views/bubble/tray_bubble_view.h" | 5 #include "ui/views/bubble/tray_bubble_view.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/macros.h" | 9 #include "base/macros.h" |
| 10 #include "cc/paint/paint_flags.h" | 10 #include "cc/paint/paint_flags.h" |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 42 TrayBubbleView::AnchorAlignment alignment) { | 42 TrayBubbleView::AnchorAlignment alignment) { |
| 43 if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { | 43 if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_BOTTOM) { |
| 44 return base::i18n::IsRTL() ? BubbleBorder::BOTTOM_LEFT | 44 return base::i18n::IsRTL() ? BubbleBorder::BOTTOM_LEFT |
| 45 : BubbleBorder::BOTTOM_RIGHT; | 45 : BubbleBorder::BOTTOM_RIGHT; |
| 46 } | 46 } |
| 47 if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) | 47 if (alignment == TrayBubbleView::ANCHOR_ALIGNMENT_LEFT) |
| 48 return BubbleBorder::LEFT_BOTTOM; | 48 return BubbleBorder::LEFT_BOTTOM; |
| 49 return BubbleBorder::RIGHT_BOTTOM; | 49 return BubbleBorder::RIGHT_BOTTOM; |
| 50 } | 50 } |
| 51 | 51 |
| 52 // Only one TrayBubbleView is visible at a time, but there are cases where the |
| 53 // lifetimes of two different bubbles can overlap briefly. |
| 54 int g_current_tray_bubble_showing_count_ = 0; |
| 55 |
| 52 } // namespace | 56 } // namespace |
| 53 | 57 |
| 54 namespace internal { | 58 namespace internal { |
| 55 | 59 |
| 56 // Detects any mouse movement. This is needed to detect mouse movements by the | 60 // Detects any mouse movement. This is needed to detect mouse movements by the |
| 57 // user over the bubble if the bubble got created underneath the cursor. | 61 // user over the bubble if the bubble got created underneath the cursor. |
| 58 class MouseMoveDetectorHost : public MouseWatcherHost { | 62 class MouseMoveDetectorHost : public MouseWatcherHost { |
| 59 public: | 63 public: |
| 60 MouseMoveDetectorHost(); | 64 MouseMoveDetectorHost(); |
| 61 ~MouseMoveDetectorHost() override; | 65 ~MouseMoveDetectorHost() override; |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 SetLayoutManager(layout_); | 222 SetLayoutManager(layout_); |
| 219 } | 223 } |
| 220 | 224 |
| 221 TrayBubbleView::~TrayBubbleView() { | 225 TrayBubbleView::~TrayBubbleView() { |
| 222 mouse_watcher_.reset(); | 226 mouse_watcher_.reset(); |
| 223 // Inform host items (models) that their views are being destroyed. | 227 // Inform host items (models) that their views are being destroyed. |
| 224 if (delegate_) | 228 if (delegate_) |
| 225 delegate_->BubbleViewDestroyed(); | 229 delegate_->BubbleViewDestroyed(); |
| 226 } | 230 } |
| 227 | 231 |
| 232 // static |
| 233 bool TrayBubbleView::IsATrayBubbleOpen() { |
| 234 return g_current_tray_bubble_showing_count_ > 0; |
| 235 } |
| 236 |
| 228 void TrayBubbleView::InitializeAndShowBubble() { | 237 void TrayBubbleView::InitializeAndShowBubble() { |
| 229 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); | 238 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); |
| 230 | 239 |
| 231 GetWidget()->Show(); | 240 GetWidget()->Show(); |
| 232 GetWidget()->GetNativeWindow()->SetEventTargeter( | 241 GetWidget()->GetNativeWindow()->SetEventTargeter( |
| 233 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); | 242 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); |
| 234 UpdateBubble(); | 243 UpdateBubble(); |
| 244 |
| 245 ++g_current_tray_bubble_showing_count_; |
| 235 } | 246 } |
| 236 | 247 |
| 237 void TrayBubbleView::UpdateBubble() { | 248 void TrayBubbleView::UpdateBubble() { |
| 238 if (GetWidget()) { | 249 if (GetWidget()) { |
| 239 SizeToContents(); | 250 SizeToContents(); |
| 240 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); | 251 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); |
| 241 GetWidget()->GetRootView()->SchedulePaint(); | 252 GetWidget()->GetRootView()->SchedulePaint(); |
| 242 } | 253 } |
| 243 } | 254 } |
| 244 | 255 |
| (...skipping 26 matching lines...) Expand all Loading... |
| 271 | 282 |
| 272 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, | 283 void TrayBubbleView::OnBeforeBubbleWidgetInit(Widget::InitParams* params, |
| 273 Widget* bubble_widget) const { | 284 Widget* bubble_widget) const { |
| 274 if (delegate_) | 285 if (delegate_) |
| 275 delegate_->OnBeforeBubbleWidgetInit(anchor_widget(), bubble_widget, params); | 286 delegate_->OnBeforeBubbleWidgetInit(anchor_widget(), bubble_widget, params); |
| 276 // Apply a WM-provided shadow (see ui/wm/core/). | 287 // Apply a WM-provided shadow (see ui/wm/core/). |
| 277 params->shadow_type = Widget::InitParams::SHADOW_TYPE_DROP; | 288 params->shadow_type = Widget::InitParams::SHADOW_TYPE_DROP; |
| 278 params->shadow_elevation = wm::ShadowElevation::LARGE; | 289 params->shadow_elevation = wm::ShadowElevation::LARGE; |
| 279 } | 290 } |
| 280 | 291 |
| 292 void TrayBubbleView::OnWidgetClosing(Widget* widget) { |
| 293 BubbleDialogDelegateView::OnWidgetClosing(widget); |
| 294 --g_current_tray_bubble_showing_count_; |
| 295 DCHECK_GE(g_current_tray_bubble_showing_count_, 0); |
| 296 } |
| 297 |
| 281 NonClientFrameView* TrayBubbleView::CreateNonClientFrameView(Widget* widget) { | 298 NonClientFrameView* TrayBubbleView::CreateNonClientFrameView(Widget* widget) { |
| 282 BubbleFrameView* frame = static_cast<BubbleFrameView*>( | 299 BubbleFrameView* frame = static_cast<BubbleFrameView*>( |
| 283 BubbleDialogDelegateView::CreateNonClientFrameView(widget)); | 300 BubbleDialogDelegateView::CreateNonClientFrameView(widget)); |
| 284 frame->SetBubbleBorder(std::move(owned_bubble_border_)); | 301 frame->SetBubbleBorder(std::move(owned_bubble_border_)); |
| 285 return frame; | 302 return frame; |
| 286 } | 303 } |
| 287 | 304 |
| 288 bool TrayBubbleView::WidgetHasHitTestMask() const { | 305 bool TrayBubbleView::WidgetHasHitTestMask() const { |
| 289 return true; | 306 return true; |
| 290 } | 307 } |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 377 | 394 |
| 378 void TrayBubbleView::ViewHierarchyChanged( | 395 void TrayBubbleView::ViewHierarchyChanged( |
| 379 const ViewHierarchyChangedDetails& details) { | 396 const ViewHierarchyChangedDetails& details) { |
| 380 if (details.is_add && details.child == this) { | 397 if (details.is_add && details.child == this) { |
| 381 details.parent->SetPaintToLayer(); | 398 details.parent->SetPaintToLayer(); |
| 382 details.parent->layer()->SetMasksToBounds(true); | 399 details.parent->layer()->SetMasksToBounds(true); |
| 383 } | 400 } |
| 384 } | 401 } |
| 385 | 402 |
| 386 } // namespace views | 403 } // namespace views |
| OLD | NEW |