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