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 |
| 16 ZoomView::ZoomView() |
| 17 // Initially set the icon state to the plus icon even if it should be |
| 18 // something else so that the location bar's layout can account for the |
| 19 // width needed to display it. |
| 20 : zoom_icon_state_(ZoomController::ZOOM_PLUS_ICON), |
| 21 zoom_percent_(100) { |
| 22 set_id(VIEW_ID_ZOOM_BUTTON); |
| 23 set_accessibility_focusable(true); |
| 24 |
| 25 Update(); |
| 26 } |
| 27 |
| 28 ZoomView::~ZoomView() { |
| 29 } |
| 30 |
| 31 void ZoomView::SetZoomIconState(ZoomController::ZoomIconState zoom_icon_state) { |
| 32 if (zoom_icon_state == zoom_icon_state_) |
| 33 return; |
| 34 |
| 35 zoom_icon_state_ = zoom_icon_state; |
| 36 Update(); |
| 37 } |
| 38 |
| 39 void ZoomView::SetZoomIconTooltipPercent(int zoom_percent) { |
| 40 if (zoom_percent == zoom_percent_) |
| 41 return; |
| 42 |
| 43 zoom_percent_ = zoom_percent; |
| 44 Update(); |
| 45 } |
| 46 |
| 47 void ZoomView::Update() { |
| 48 switch (zoom_icon_state_) { |
| 49 case ZoomController::NONE: |
| 50 SetVisible(false); |
| 51 browser::HideZoomBubbleView(); |
| 52 break; |
| 53 case ZoomController::ZOOM_PLUS_ICON: |
| 54 SetVisible(true); |
| 55 SetTooltipText( |
| 56 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); |
| 57 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 58 IDR_ZOOM_PLUS)); |
| 59 break; |
| 60 case ZoomController::ZOOM_MINUS_ICON: |
| 61 SetVisible(true); |
| 62 SetTooltipText( |
| 63 l10n_util::GetStringFUTF16Int(IDS_TOOLTIP_ZOOM, zoom_percent_)); |
| 64 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 65 IDR_ZOOM_MINUS)); |
| 66 break; |
| 67 default: |
| 68 NOTREACHED(); |
| 69 } |
| 70 } |
| 71 |
| 72 void ZoomView::GetAccessibleState(ui::AccessibleViewState* state) { |
| 73 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); |
| 74 state->role = ui::AccessibilityTypes::ROLE_PUSHBUTTON; |
| 75 } |
| 76 |
| 77 bool ZoomView::GetTooltipText(const gfx::Point& p, string16* tooltip) const { |
| 78 // Don't show tooltip if the zoom bubble is displayed. |
| 79 if (browser::IsZoomBubbleViewShowing()) |
| 80 return false; |
| 81 |
| 82 return ImageView::GetTooltipText(p, tooltip); |
| 83 } |
| 84 |
| 85 bool ZoomView::OnMousePressed(const views::MouseEvent& event) { |
| 86 // Do nothing until mouse is released. |
| 87 return true; |
| 88 } |
| 89 |
| 90 void ZoomView::OnMouseReleased(const views::MouseEvent& event) { |
| 91 if (event.IsOnlyLeftMouseButton() && HitTest(event.location())) |
| 92 browser::ShowZoomBubbleView(this, zoom_percent_, false); |
| 93 } |
| 94 |
| 95 bool ZoomView::OnKeyPressed(const views::KeyEvent& event) { |
| 96 if (event.key_code() == ui::VKEY_SPACE || |
| 97 event.key_code() == ui::VKEY_RETURN) { |
| 98 browser::ShowZoomBubbleView(this, zoom_percent_, false); |
| 99 return true; |
| 100 } |
| 101 return false; |
| 102 } |
OLD | NEW |