| 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/toolbar/toolbar_model.h" | 7 #include "chrome/browser/ui/toolbar/toolbar_model.h" |
| 8 #include "chrome/browser/ui/view_ids.h" | 8 #include "chrome/browser/ui/view_ids.h" |
| 9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" | 9 #include "chrome/browser/ui/views/location_bar/zoom_bubble_view.h" |
| 10 #include "chrome/browser/ui/zoom/zoom_controller.h" | 10 #include "chrome/browser/ui/zoom/zoom_controller.h" |
| 11 #include "chrome/grit/generated_resources.h" | 11 #include "chrome/grit/generated_resources.h" |
| 12 #include "ui/accessibility/ax_view_state.h" | 12 #include "ui/accessibility/ax_view_state.h" |
| 13 #include "ui/base/l10n/l10n_util.h" | 13 #include "ui/base/l10n/l10n_util.h" |
| 14 #include "ui/base/resource/resource_bundle.h" | 14 #include "ui/base/resource/resource_bundle.h" |
| 15 #include "ui/events/event.h" | 15 #include "ui/events/event.h" |
| 16 #include "ui/gfx/size.h" | 16 #include "ui/gfx/size.h" |
| 17 | 17 |
| 18 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) | 18 ZoomView::ZoomView(LocationBarView::Delegate* location_bar_delegate) |
| 19 : location_bar_delegate_(location_bar_delegate) { | 19 : location_bar_delegate_(location_bar_delegate) { |
| 20 SetAccessibilityFocusable(true); | |
| 21 Update(NULL); | 20 Update(NULL); |
| 22 } | 21 } |
| 23 | 22 |
| 24 ZoomView::~ZoomView() { | 23 ZoomView::~ZoomView() { |
| 25 } | 24 } |
| 26 | 25 |
| 27 void ZoomView::Update(ZoomController* zoom_controller) { | 26 void ZoomView::Update(ZoomController* zoom_controller) { |
| 28 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || | 27 if (!zoom_controller || zoom_controller->IsAtDefaultZoom() || |
| 29 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { | 28 location_bar_delegate_->GetToolbarModel()->input_in_progress()) { |
| 30 SetVisible(false); | 29 SetVisible(false); |
| 31 ZoomBubbleView::CloseBubble(); | 30 ZoomBubbleView::CloseBubble(); |
| 32 return; | 31 return; |
| 33 } | 32 } |
| 34 | 33 |
| 35 SetTooltipText(l10n_util::GetStringFUTF16Int( | 34 SetTooltipText(l10n_util::GetStringFUTF16Int( |
| 36 IDS_TOOLTIP_ZOOM, zoom_controller->GetZoomPercent())); | 35 IDS_TOOLTIP_ZOOM, zoom_controller->GetZoomPercent())); |
| 37 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | 36 SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed( |
| 38 zoom_controller->GetResourceForZoomLevel())); | 37 zoom_controller->GetResourceForZoomLevel())); |
| 39 SetVisible(true); | 38 SetVisible(true); |
| 40 } | 39 } |
| 41 | 40 |
| 42 void ZoomView::GetAccessibleState(ui::AXViewState* state) { | 41 void ZoomView::GetAccessibleState(ui::AXViewState* state) { |
| 42 BubbleIconView::GetAccessibleState(state); |
| 43 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); | 43 state->name = l10n_util::GetStringUTF16(IDS_ACCNAME_ZOOM); |
| 44 state->role = ui::AX_ROLE_BUTTON; | |
| 45 } | 44 } |
| 46 | 45 |
| 47 bool ZoomView::GetTooltipText(const gfx::Point& p, | 46 bool ZoomView::IsBubbleShowing() const { |
| 48 base::string16* tooltip) const { | 47 return ZoomBubbleView::IsShowing(); |
| 49 // Don't show tooltip if the zoom bubble is displayed. | |
| 50 return !ZoomBubbleView::IsShowing() && ImageView::GetTooltipText(p, tooltip); | |
| 51 } | 48 } |
| 52 | 49 |
| 53 bool ZoomView::OnMousePressed(const ui::MouseEvent& event) { | 50 void ZoomView::OnExecuting(BubbleIconView::ExecuteSource source) { |
| 54 // Do nothing until mouse is released. | |
| 55 return true; | |
| 56 } | |
| 57 | |
| 58 void ZoomView::OnMouseReleased(const ui::MouseEvent& event) { | |
| 59 if (event.IsOnlyLeftMouseButton() && HitTestPoint(event.location())) | |
| 60 ActivateBubble(); | |
| 61 } | |
| 62 | |
| 63 bool ZoomView::OnKeyPressed(const ui::KeyEvent& event) { | |
| 64 if (event.key_code() != ui::VKEY_SPACE && | |
| 65 event.key_code() != ui::VKEY_RETURN) { | |
| 66 return false; | |
| 67 } | |
| 68 | |
| 69 ActivateBubble(); | |
| 70 return true; | |
| 71 } | |
| 72 | |
| 73 void ZoomView::OnGestureEvent(ui::GestureEvent* event) { | |
| 74 if (event->type() == ui::ET_GESTURE_TAP) { | |
| 75 ActivateBubble(); | |
| 76 event->SetHandled(); | |
| 77 } | |
| 78 } | |
| 79 | |
| 80 void ZoomView::ActivateBubble() { | |
| 81 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); | 51 ZoomBubbleView::ShowBubble(location_bar_delegate_->GetWebContents(), false); |
| 82 } | 52 } |
| OLD | NEW |