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 autoclose. |
| 17 const int kBubbleCloseDelay = 400; |
| 18 |
| 19 } |
| 20 |
| 21 // Singleton instance. |
| 22 ZoomBubbleView* ZoomBubbleView::zoom_bubble_ = NULL; |
| 23 |
| 24 // Declared in browser_dialogs.h.. |
| 25 namespace browser { |
| 26 |
| 27 void ShowZoomBubbleView(views::View* anchor_view, |
| 28 int zoom_percent, |
| 29 bool autoclose) { |
| 30 ZoomBubbleView::ShowBubble(anchor_view, zoom_percent, autoclose); |
| 31 } |
| 32 |
| 33 void HideZoomBubbleView() { |
| 34 ZoomBubbleView::CloseBubble(); |
| 35 } |
| 36 |
| 37 bool IsZoomBubbleViewShowing() { |
| 38 return ZoomBubbleView::IsShowing(); |
| 39 } |
| 40 |
| 41 } |
| 42 |
| 43 // static |
| 44 void ZoomBubbleView::ShowBubble(views::View* anchor_view, |
| 45 int zoom_percent, |
| 46 bool autoclose) { |
| 47 if (IsShowing()) |
| 48 CloseBubble(); |
| 49 |
| 50 zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, autoclose); |
| 51 views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
| 52 zoom_bubble_->Show(); |
| 53 } |
| 54 |
| 55 // static |
| 56 void ZoomBubbleView::CloseBubble() { |
| 57 if (IsShowing()) |
| 58 zoom_bubble_->Close(); |
| 59 } |
| 60 |
| 61 // static |
| 62 bool ZoomBubbleView::IsShowing() { |
| 63 return zoom_bubble_ != NULL; |
| 64 } |
| 65 |
| 66 void ZoomBubbleView::WindowClosing() { |
| 67 DCHECK(zoom_bubble_ == this); |
| 68 zoom_bubble_ = NULL; |
| 69 } |
| 70 |
| 71 void ZoomBubbleView::Init() { |
| 72 SetLayoutManager(new views::FillLayout()); |
| 73 zoom_percent_label_ = new views::Label( |
| 74 l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); |
| 75 AddChildView(zoom_percent_label_); |
| 76 |
| 77 if (autoclose_) |
| 78 MessageLoop::current()->PostDelayedTask( |
| 79 FROM_HERE, |
| 80 base::Bind(&ZoomBubbleView::Close, factory_.GetWeakPtr()), |
| 81 kBubbleCloseDelay); |
| 82 } |
| 83 |
| 84 ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, |
| 85 int zoom_percent, |
| 86 bool autoclose) |
| 87 : BubbleDelegateView(anchor_view, views::BubbleBorder::TOP_RIGHT), |
| 88 ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), |
| 89 zoom_percent_(zoom_percent), |
| 90 autoclose_(autoclose), |
| 91 zoom_percent_label_(NULL) { |
| 92 set_use_focusless(autoclose); |
| 93 } |
| 94 |
| 95 ZoomBubbleView::~ZoomBubbleView() { |
| 96 } |
| 97 |
| 98 void ZoomBubbleView::Close() { |
| 99 GetWidget()->Close(); |
| 100 } |
OLD | NEW |