Upstream version 11.40.277.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / views / location_bar / zoom_view.cc
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_view.h"
6
7 #include "chrome/browser/ui/toolbar/toolbar_model.h"
8 #include "chrome/browser/ui/view_ids.h"
9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h"
10 #include "chrome/browser/ui/zoom/zoom_controller.h"
11 #include "chrome/grit/generated_resources.h"
12 #include "ui/accessibility/ax_view_state.h"
13 #include "ui/base/l10n/l10n_util.h"
14 #include "ui/base/resource/resource_bundle.h"
15 #include "ui/events/event.h"
16 #include "ui/gfx/size.h"
17
18 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate)
19     : BubbleIconView(nullptr, 0),
20       location_bar_delegate_(location_bar_delegate) {
21   Update(NULL);
22 }
23
24 ZoomView::~ZoomView() {
25 }
26
27 void ZoomView::Update(ZoomController* zoom_controller) {
28   if (!zoom_controller || zoom_controller->IsAtDefaultZoom() ||
29       location_bar_delegate_->GetToolbarModel()->input_in_progress()) {
30     SetVisible(false);
31     ZoomBubbleView::CloseBubble();
32     return;
33   }
34
35   SetTooltipText(l10n_util::GetStringFUTF16Int(
36       IDS_TOOLTIP_ZOOM, zoom_controller->GetZoomPercent()));
37   SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
38       zoom_controller->GetResourceForZoomLevel()));
39   SetVisible(true);
40 }
41
42 bool ZoomView::IsBubbleShowing() const {
43   return ZoomBubbleView::IsShowing();
44 }
45
46 void ZoomView::OnExecuting(BubbleIconView::ExecuteSource source) {
47   ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false);
48 }
49
50 void ZoomView::GetAccessibleState(ui::AXViewState* state) {
51   BubbleIconView::GetAccessibleState(state);
52   state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM);
53 }