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 // static | |
22 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; | |
23 | |
24 // static | |
25 void ZoomBubbleView::ShowBubble(views::View* anchor_view, | |
26 int zoom_percent, | |
27 bool auto_close) { | |
28 // If the bubble is already showing and its |auto_close_| value is equal to | |
29 // |auto_close|, the bubble can be reused and only the label text needs to | |
30 // be updated. | |
Peter Kasting
2012/06/26 23:23:39
Not necessarily true. The bubble could be shown w
Kyle Horimoto
2012/06/30 00:22:50
Done.
| |
31 if (zoom_bubble_ && zoom_bubble_->auto_close_ == auto_close) { | |
32 zoom_bubble_->label_->SetText( | |
33 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent)); | |
34 | |
35 if (auto_close) { | |
36 // If the bubble should be closed automatically, reset the timer so that | |
37 // it will show for the full amount of time instead of only what remained | |
38 // from the previous time. | |
39 zoom_bubble_->timer_.Reset(); | |
40 } | |
41 } else { | |
42 // If the bubble is already showing but its |auto_close_| value is not equal | |
43 // to |auto_close|, the bubble's focus properties must change, so the | |
44 // current bubble must be closed and a new one created. | |
45 if (zoom_bubble_) | |
46 zoom_bubble_->Close(); | |
47 | |
48 zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, auto_close); | |
49 views::BubbleDelegateView::CreateBubble(zoom_bubble_); | |
50 zoom_bubble_->Show(); | |
51 } | |
52 } | |
53 | |
54 // static | |
55 void ZoomBubbleView::CloseBubble() { | |
56 if (zoom_bubble_) | |
57 zoom_bubble_->Close(); | |
58 } | |
59 | |
60 // static | |
61 bool ZoomBubbleView::IsShowing() { | |
62 return zoom_bubble_ != NULL; | |
63 } | |
64 | |
65 void ZoomBubbleView::WindowClosing() { | |
66 DCHECK(zoom_bubble_ == this); | |
67 zoom_bubble_ = NULL; | |
68 } | |
69 | |
70 void ZoomBubbleView::Init() { | |
71 SetLayoutManager(new views::FillLayout()); | |
72 label_ = new views::Label( | |
73 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); | |
74 AddChildView(label_); | |
75 | |
76 if (auto_close_) { | |
77 timer_.Start( | |
78 FROM_HERE, | |
79 base::TimeDelta::FromMilliseconds(kBubbleCloseDelay), | |
80 this, | |
81 &ZoomBubbleView::Close); | |
82 } | |
83 } | |
84 | |
85 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, | |
86 int zoom_percent, | |
87 bool auto_close) | |
88 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), | |
89 zoom_percent_(zoom_percent), | |
90 auto_close_(auto_close) { | |
91 set_use_focusless(auto_close); | |
92 } | |
93 | |
94 ZoomBubbleView::~ZoomBubbleView() { | |
95 } | |
96 | |
97 void ZoomBubbleView::Close() { | |
98 GetWidget()->Close(); | |
99 } | |
OLD | NEW |