Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(237)

Side by Side Diff: ui/views/bubble/tray_bubble_view.cc

Issue 2831233003: Remove ShouldBlockShelfAutoHide(). (Closed)
Patch Set: bubble lifetimes Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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_view_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 112 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 min_width(min_width), 178 min_width(min_width),
175 max_width(max_width), 179 max_width(max_width),
176 max_height(0), 180 max_height(0),
177 can_activate(false), 181 can_activate(false),
178 close_on_deactivate(true), 182 close_on_deactivate(true),
179 bg_color(gfx::kPlaceholderColor) {} 183 bg_color(gfx::kPlaceholderColor) {}
180 184
181 TrayBubbleView::InitParams::InitParams(const InitParams& other) = default; 185 TrayBubbleView::InitParams::InitParams(const InitParams& other) = default;
182 186
183 // static 187 // static
188 bool TrayBubbleView::IsATrayBubbleOpen() {
189 return g_current_tray_bubble_view_count_ > 0;
190 }
191
192 // static
184 TrayBubbleView* TrayBubbleView::Create(View* anchor, 193 TrayBubbleView* TrayBubbleView::Create(View* anchor,
185 Delegate* delegate, 194 Delegate* delegate,
186 InitParams* init_params) { 195 InitParams* init_params) {
187 return new TrayBubbleView(anchor, delegate, *init_params); 196 return new TrayBubbleView(anchor, delegate, *init_params);
188 } 197 }
189 198
190 TrayBubbleView::TrayBubbleView(View* anchor, 199 TrayBubbleView::TrayBubbleView(View* anchor,
191 Delegate* delegate, 200 Delegate* delegate,
192 const InitParams& init_params) 201 const InitParams& init_params)
193 : BubbleDialogDelegateView(anchor, 202 : BubbleDialogDelegateView(anchor,
(...skipping 18 matching lines...) Expand all
212 SetPaintToLayer(); 221 SetPaintToLayer();
213 222
214 bubble_content_mask_.reset( 223 bubble_content_mask_.reset(
215 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius())); 224 new TrayBubbleContentMask(bubble_border_->GetBorderCornerRadius()));
216 225
217 layout_->SetDefaultFlex(1); 226 layout_->SetDefaultFlex(1);
218 SetLayoutManager(layout_); 227 SetLayoutManager(layout_);
219 } 228 }
220 229
221 TrayBubbleView::~TrayBubbleView() { 230 TrayBubbleView::~TrayBubbleView() {
231 --g_current_tray_bubble_view_count_;
232 DCHECK_GE(g_current_tray_bubble_view_count_, 0);
233
222 mouse_watcher_.reset(); 234 mouse_watcher_.reset();
223 // Inform host items (models) that their views are being destroyed. 235 // Inform host items (models) that their views are being destroyed.
224 if (delegate_) 236 if (delegate_)
225 delegate_->BubbleViewDestroyed(); 237 delegate_->BubbleViewDestroyed();
226 } 238 }
227 239
228 void TrayBubbleView::InitializeAndShowBubble() { 240 void TrayBubbleView::InitializeAndShowBubble() {
229 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer()); 241 layer()->parent()->SetMaskLayer(bubble_content_mask_->layer());
230 242
231 GetWidget()->Show(); 243 GetWidget()->Show();
232 GetWidget()->GetNativeWindow()->SetEventTargeter( 244 GetWidget()->GetNativeWindow()->SetEventTargeter(
233 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this))); 245 std::unique_ptr<ui::EventTargeter>(new BubbleWindowTargeter(this)));
234 UpdateBubble(); 246 UpdateBubble();
247
248 ++g_current_tray_bubble_view_count_;
sky 2017/04/21 20:43:49 Is there a reason you like this here rather than t
Evan Stade 2017/04/22 00:10:25 yes. In fact the decrement needs to come earlier,
235 } 249 }
236 250
237 void TrayBubbleView::UpdateBubble() { 251 void TrayBubbleView::UpdateBubble() {
238 if (GetWidget()) { 252 if (GetWidget()) {
239 SizeToContents(); 253 SizeToContents();
240 bubble_content_mask_->layer()->SetBounds(layer()->bounds()); 254 bubble_content_mask_->layer()->SetBounds(layer()->bounds());
241 GetWidget()->GetRootView()->SchedulePaint(); 255 GetWidget()->GetRootView()->SchedulePaint();
242 } 256 }
243 } 257 }
244 258
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
377 391
378 void TrayBubbleView::ViewHierarchyChanged( 392 void TrayBubbleView::ViewHierarchyChanged(
379 const ViewHierarchyChangedDetails& details) { 393 const ViewHierarchyChangedDetails& details) {
380 if (details.is_add && details.child == this) { 394 if (details.is_add && details.child == this) {
381 details.parent->SetPaintToLayer(); 395 details.parent->SetPaintToLayer();
382 details.parent->layer()->SetMasksToBounds(true); 396 details.parent->layer()->SetMasksToBounds(true);
383 } 397 }
384 } 398 }
385 399
386 } // namespace views 400 } // namespace views
OLDNEW
« ui/views/bubble/tray_bubble_view.h ('K') | « ui/views/bubble/tray_bubble_view.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698