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_view.h" |
| 6 |
| 7 #include "chrome/browser/ui/views/browser_dialogs.h" |
| 8 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 9 #include "chrome/browser/ui/view_ids.h" |
| 10 #include "grit/generated_resources.h" |
| 11 #include "grit/theme_resources_standard.h" |
| 12 #include "ui/base/accessibility/accessible_view_state.h" |
| 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/gfx/size.h" |
| 16 |
| 17 namespace { |
| 18 |
| 19 // The size (in pixels) of a side of the icon. |
| 20 const int kIconSideLength = 19; |
| 21 |
| 22 } |
| 23 |
| 24 ZoomView::ZoomView(ToolbarModel* toolbar_model) |
| 25 : toolbar_model_(toolbar_model), |
| 26 zoom_icon_state_(ZoomController::NONE), |
| 27 zoom_percent_(100) { |
| 28 set_accessibility_focusable(true); |
| 29 |
| 30 gfx::Size size(kIconSideLength, kIconSideLength); |
| 31 SetImageSize(size); |
| 32 } |
| 33 |
| 34 ZoomView::~ZoomView() { |
| 35 } |
| 36 |
| 37 void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { |
| 38 if (zoom_icon_state == zoom_icon_state_) |
| 39 return; |
| 40 |
| 41 zoom_icon_state_ = zoom_icon_state; |
| 42 Update(); |
| 43 } |
| 44 |
| 45 void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) { |
| 46 if (zoom_percent == zoom_percent_) |
| 47 return; |
| 48 |
| 49 zoom_percent_ = zoom_percent; |
| 50 Update(); |
| 51 } |
| 52 |
| 53 void ZoomView::Update() { |
| 54 if (toolbar_model_->input_in_progress() || |
| 55 zoom_icon_state_ == ZoomController::NONE) { |
| 56 SetVisible(false); |
| 57 ZoomBubbleView::CloseBubble(); |
| 58 } else { |
| 59 SetVisible(true); |
| 60 SetTooltipText( |
| 61 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); |
| 62 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 63 zoom_icon_state_ == ZoomController::ZOOM_PLUS_ICON ? |
| 64 IDR_ZOOM_PLUS : IDR_ZOOM_MINUS)); |
| 65 } |
| 66 } |
| 67 |
| 68 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 69 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); |
| 70 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 71 } |
| 72 |
| 73 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { |
| 74 // Don't show tooltip if the zoom bubble is displayed. |
| 75 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); |
| 76 } |
| 77 |
| 78 bool ZoomView::OnMousePressed(const views::MouseEvent& event) { |
| 79 // Do nothing until mouse is released. |
| 80 return true; |
| 81 } |
| 82 |
| 83 void ZoomView::OnMouseReleased(const views::MouseEvent& event) { |
| 84 if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) |
| 85 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); |
| 86 } |
| 87 |
| 88 bool ZoomView::OnKeyPressed(const views::KeyEvent& event) { |
| 89 if (event.key_code() != ui::VKEY_SPACE && |
| 90 event.key_code() != ui::VKEY_RETURN) |
| 91 return false; |
| 92 |
| 93 ZoomBubbleView::ShowBubble(this, zoom_percent_, false); |
| 94 return true; |
| 95 } |
OLD | NEW |