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