Chromium Code Reviews| Index: chrome/browser/ui/views/location_bar/zoom_bubble_view.cc |
| diff --git a/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..b42b4e1aec00c92998f40cb7d610377fbf5696b7 |
| --- /dev/null |
| +++ b/chrome/browser/ui/views/location_bar/zoom_bubble_view.cc |
| @@ -0,0 +1,81 @@ |
| +// Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| + |
| +#include "base/bind.h" |
| +#include "base/message_loop.h" |
| +#include "grit/generated_resources.h" |
| +#include "ui/base/l10n/l10n_util.h" |
| +#include "ui/views/layout/fill_layout.h" |
| + |
| +namespace { |
| + |
| +// The number of milliseconds the bubble should stay on the screen for if it |
| +// will automatically close. |
| +const int kBubbleCloseDelay = 400; |
| + |
| +} |
| + |
| +// Singleton instance. |
|
Ben Goodger (Google)
2012/06/22 19:16:06
// static
Kyle Horimoto
2012/06/26 21:55:53
Done.
|
| +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
|
| + |
| +// static |
| +void ZoomBubbleView::ShowBubble(views::View* anchor_view, |
| + int zoom_percent, |
| + bool auto_close) { |
| + if (IsShowing()) |
| + CloseBubble(); |
| + |
| + zoom_bubble_ = new ZoomBubbleView(anchor_view, zoom_percent, auto_close); |
| + views::BubbleDelegateView::CreateBubble(zoom_bubble_); |
| + zoom_bubble_->Show(); |
| +} |
| + |
| +// static |
| +void ZoomBubbleView::CloseBubble() { |
| + if (IsShowing()) |
| + zoom_bubble_->Close(); |
| +} |
| + |
| +// static |
| +bool ZoomBubbleView::IsShowing() { |
| + return zoom_bubble_ != NULL; |
| +} |
| + |
| +void ZoomBubbleView::WindowClosing() { |
| + DCHECK(zoom_bubble_ == this); |
| + zoom_bubble_ = NULL; |
| +} |
| + |
| +void ZoomBubbleView::Init() { |
| + SetLayoutManager(new views::FillLayout()); |
| + 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.
|
| + l10n_util::GetStringFUTF16Int(IDS_ZOOM_PERCENT, zoom_percent_)); |
| + AddChildView(zoom_percent_label_); |
| + |
| + 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.
|
| + MessageLoop::current()->PostDelayedTask( |
| + FROM_HERE, |
| + base::Bind(&ZoomBubbleView::Close, factory_.GetWeakPtr()), |
| + kBubbleCloseDelay); |
| +} |
| + |
| +ZoomBubbleView::ZoomBubbleView(views::View* anchor_view, |
| + int zoom_percent, |
| + bool auto_close) |
| + : 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.
|
| + ALLOW_THIS_IN_INITIALIZER_LIST(factory_(this)), |
| + zoom_percent_(zoom_percent), |
| + auto_close_(auto_close), |
| + zoom_percent_label_(NULL) { |
| + set_use_focusless(auto_close); |
| +} |
| + |
| +ZoomBubbleView::~ZoomBubbleView() { |
| +} |
| + |
| +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.
|
| + GetWidget()->Close(); |
| +} |