OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | |
6 | |
7 #include "base/bind.h" | |
8 #include "base/message_loop.h" | |
9 #include "grit/generated_resources.h" | |
10 #include "ui/base/l10n/l10n_util.h" | |
11 #include "ui/views/layout/fill_layout.h" | |
12 | |
13 namespace { | |
14 | |
15 // The number of milliseconds the bubble should stay on the screen for if it | |
16 // will automatically close. | |
17 const int kBubbleCloseDelay = 400; | |
18 | |
19 } | |
20 | |
21 // Singleton instance. | |
Ben Goodger (Google)
2012/06/22 19:16:06
// static
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
22 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; | |
Peter Kasting
2012/06/22 20:16:20
Using a singleton for this is wrong. For example,
Kyle Horimoto
2012/06/26 21:55:53
As discussed offline, the bubble is purposely not
| |
23 | |
24 // static | |
25 void ZoomBubbleView::ShowBubble(views::View* anchor_view, | |
26 int zoom_percent, | |
27 bool auto_close) { | |
28 if (IsShowing()) | |
29 CloseBubble(); | |
30 | |
31 zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, auto_close); | |
32 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | |
33 zoom_bubble_->Show(); | |
34 } | |
35 | |
36 // static | |
37 void ZoomBubbleView::CloseBubble() { | |
38 if (IsShowing()) | |
39 zoom_bubble_->Close(); | |
40 } | |
41 | |
42 // static | |
43 bool ZoomBubbleView::IsShowing() { | |
44 return zoom_bubble_ != NULL; | |
45 } | |
46 | |
47 void ZoomBubbleView::WindowClosing() { | |
48 DCHECK(zoom_bubble_ == this); | |
49 zoom_bubble_ = NULL; | |
50 } | |
51 | |
52 void ZoomBubbleView::Init() { | |
53 SetLayoutManager(new views::FillLayout()); | |
54 zoom_percent_label_ = new views::Label( | |
Peter Kasting
2012/06/22 20:16:20
Nit: We don't need a member for this, since we nev
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
55 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); | |
56 AddChildView(zoom_percent_label_); | |
57 | |
58 if (auto_close_) | |
Ben Goodger (Google)
2012/06/22 19:16:06
braces around this one
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
59 MessageLoop::current()->PostDelayedTask( | |
60 FROM_HERE, | |
61 base::Bind(&ZoomBubbleView::Close, factory_.GetWeakPtr()), | |
62 kBubbleCloseDelay); | |
63 } | |
64 | |
65 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, | |
66 int zoom_percent, | |
67 bool auto_close) | |
68 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | |
Ben Goodger (Google)
2012/06/22 19:16:06
4-space indent to the :
Kyle Horimoto
2012/06/26 21:55:53
Done.
| |
69 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), | |
70 zoom_percent_(zoom_percent), | |
71 auto_close_(auto_close), | |
72 zoom_percent_label_(NULL) { | |
73 set_use_focusless(auto_close); | |
74 } | |
75 | |
76 ZoomBubbleView::~ZoomBubbleView() { | |
77 } | |
78 | |
79 void ZoomBubbleView::Close() { | |
Ben Goodger (Google)
2012/06/22 19:16:06
this doesn't look to be used?
Peter Kasting
2012/06/22 20:16:20
CloseBubble() above?
Kyle Horimoto
2012/06/26 21:55:53
It's used in CloseBubble() above.
Kyle Horimoto
2012/06/26 21:55:53
Yep.
| |
80 GetWidget()->Close(); | |
81 } | |
OLD | NEW |